This file is indexed.

/usr/lib/python3/dist-packages/defcon/objects/image.py is in python3-defcon 0.3.5-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
from __future__ import absolute_import
import weakref
from defcon.objects.base import BaseDictObject
from defcon.objects.color import Color

_defaultTransformation = {
    "xScale"  : 1,
    "xyScale" : 0,
    "yxScale" : 0,
    "yScale"  : 1,
    "xOffset" : 0,
    "yOffset" : 0
}


class Image(BaseDictObject):

    """
    This object represents an image reference in a glyph.

    **This object posts the following notifications:**

    ===========================
    Name
    ===========================
    Image.Changed
    Image.FileNameChanged
    Image.TransformationChanged
    Image.ColorChanged
    Image.ImageDataChanged
    ===========================

    During initialization an image dictionary, following the format defined
    in the UFO spec, can be passed. If so, the new object will be populated
    with the data from the dictionary.
    """

    changeNotificationName = "Image.Changed"
    representationFactories = {}

    def __init__(self, glyph=None, imageDict=None):
        self._font = None
        self._layerSet = None
        self._layer = None
        self._glyph = None
        self.glyph = glyph
        super(Image, self).__init__()
        self.beginSelfNotificationObservation()
        self["fileName"] = None
        self["color"] = None
        if imageDict is not None:
            self.update(imageDict)
        for key, value in _defaultTransformation.items():
            if self.get(key) is None:
                self[key] = value
        self._dirty = False

    def __len__(self):
        # this is a little hack for glifLib writing.
        # when a GLIF is written, glyph.image is chekced with:
        #     if glyph.image:
        # fileName is required, so if that isn't defined
        # return 0. this tells glifLib to skip the image.
        if self["fileName"] is None:
            return 0
        return super(Image, self).__len__()

    # --------------
    # Parent Objects
    # --------------

    def getParent(self):
        return self.glyph

    def _get_font(self):
        font = None
        if self._font is None:
            glyph = self.glyph
            if glyph is not None:
                font = glyph.font
                if font is not None:
                    self._font = weakref.ref(font)
        else:
            font = self._font()
        return font

    font = property(_get_font, doc="The :class:`Font` that this image belongs to.")

    def _get_layerSet(self):
        layerSet = None
        if self._layerSet is None:
            glyph = self.glyph
            if glyph is not None:
                layerSet = glyph.layerSet
                if layerSet is not None:
                    self._layerSet = weakref.ref(layerSet)
        else:
            layerSet = self._layerSet()
        return layerSet

    layerSet = property(_get_layerSet, doc="The :class:`LayerSet` that this image belongs to.")

    def _get_layer(self):
        layer = None
        if self._layer is None:
            glyph = self.glyph
            if glyph is not None:
                layer = glyph.layer
                if layer is not None:
                    self._layer = weakref.ref(layer)
        else:
            layer = self._layer()
        return layer

    layer = property(_get_layer, doc="The :class:`Layer` that this image belongs to.")

    def _get_glyph(self):
        if self._glyph is None:
            return None
        return self._glyph()

    def _set_glyph(self, glyph):
        assert self._glyph is None
        if glyph is not None:
            glyph = weakref.ref(glyph)
        self._font = None
        self._layerSet = None
        self._layer = None
        self._glyph = glyph

    glyph = property(_get_glyph, _set_glyph, doc="The :class:`Glyph` that this image belongs to. This should not be set externally.")

    # ----------
    # Attributes
    # ----------

    # file name

    def _get_fileName(self):
        return self["fileName"]

    def _set_fileName(self, fileName):
        oldFileName = self.get("fileName")
        if fileName == oldFileName:
            return
        self["fileName"] = fileName
        self.postNotification("Image.FileNameChanged", data=dict(oldValue=oldFileName, newValue=fileName))

    fileName = property(_get_fileName, _set_fileName, doc="The file name the image. Setting this will posts *Image.Changed* and *Image.FileNameChanged* notifications.")

    # transformation

    def _get_transformation(self):
        if "xScale" not in self:
            return
        return (self["xScale"], self["xyScale"], self["yxScale"], self["yScale"], self["xOffset"], self["yOffset"])

    def _set_transformation(self, transformation):
        oldTransformation = self.transformation
        if oldTransformation == transformation:
            return
        xScale, xyScale, yxScale, yScale, xOffset, yOffset = transformation
        # hold the notifications so that only one is sent out
        self.holdNotifications()
        self["xScale"] = xScale
        self["xyScale"] = xyScale
        self["yxScale"] = yxScale
        self["yScale"] = yScale
        self["xOffset"] = xOffset
        self["yOffset"] = yOffset
        self.releaseHeldNotifications()
        self.postNotification("Image.TransformationChanged", data=dict(oldValue=oldTransformation, newValue=transformation))

    transformation = property(_get_transformation, _set_transformation, doc="The transformation matrix for the image. Setting this will posts *Image.Changed* and *Image.TransformationChanged* notifications.")

    # color

    def _get_color(self):
        return self.get("color")

    def _set_color(self, color):
        if color is None:
            newColor = None
        else:
            newColor = Color(color)
        oldColor = self.get("color")
        if newColor == oldColor:
            return
        self["color"] = newColor
        self.postNotification("Image.ColorChanged", data=dict(oldValue=oldColor, newValue=newColor))

    color = property(_get_color, _set_color, doc="The image's :class:`Color` object. When setting, the value can be a UFO color string, a sequence of (r, g, b, a) or a :class:`Color` object. Setting this posts *Image.ColorChanged* and *Image.Changed* notifications.")

    # ----
    # Move
    # ----

    def move(self, values):
        """
        Move the image by **(x, y)**.

        This posts *Image.Changed* and *Image.TransformationChanged* notifications.
        """
        xOffset, yOffset = values
        if not (xOffset or yOffset):
            return
        oldTransformation = self.transformation
        self.holdNotifications()
        self["xOffset"] += xOffset
        self["yOffset"] += yOffset
        self.releaseHeldNotifications()
        self.postNotification("Image.TransformationChanged", data=dict(oldValue=oldTransformation, newValue=self.transformation))

    # ------------------------
    # Notification Observation
    # ------------------------

    def beginSelfNotificationObservation(self):
        super(Image, self).beginSelfNotificationObservation()
        self.beginSelfImageSetNotificationObservation()

    def endSelfNotificationObservation(self):
        self.endImageSetNotificationObservation()
        super(Image, self).endSelfNotificationObservation()
        self._font = None
        self._layerSet = None
        self._layer = None
        self._glyph = None

    def beginSelfImageSetNotificationObservation(self):
        font = self.font
        if font is None:
            return
        imageSet = font.images
        imageSet.addObserver(self, "imageSetImageAddedNotificationCallback", "ImageSet.ImageAdded")
        imageSet.addObserver(self, "imageSetImageDeletedNotificationCallback", "ImageSet.ImageDeleted")
        imageSet.addObserver(self, "imageSetImageChangedNotificationCallback", "ImageSet.ImageChanged")
        layer = self.layer
        layer.addObserver(self, "layerColorChangedNotificationCallback", "Layer.ColorChanged")

    def endImageSetNotificationObservation(self):
        font = self.font
        if font is None:
            return
        imageSet = font.images
        imageSet.removeObserver(self, "ImageSet.ImageAdded")
        imageSet.removeObserver(self, "ImageSet.ImageDeleted")
        imageSet.removeObserver(self, "ImageSet.ImageChanged")
        layer = self.layer
        layer.removeObserver(self, "Layer.ColorChanged")

    def imageSetImageAddedNotificationCallback(self, notification):
        name = notification.data["name"]
        if name != self.fileName:
            return
        self.postNotification("Image.ImageDataChanged")

    def imageSetImageDeletedNotificationCallback(self, notification):
        name = notification.data["name"]
        if name != self.fileName:
            return
        self.postNotification("Image.ImageDataChanged")

    def imageSetImageChangedNotificationCallback(self, notification):
        name = notification.data["name"]
        if name != self.fileName:
            return
        self.postNotification("Image.ImageDataChanged")

    def layerColorChangedNotificationCallback(self, notification):
        if self.color is not None:
            self.postNotification("Image.ColorChanged", data=notification.data)


if __name__ == "__main__":
    import doctest
    doctest.testmod()