Changeset 1058


Ignore:
Timestamp:
12/15/11 18:45:03 (17 months ago)
Author:
tal
Message:
Load the Unicode data object lazily. This speeds things up a good bit.
Location:
packages/defcon/branches/ufo3/Lib/defcon/objects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • packages/defcon/branches/ufo3/Lib/defcon/objects/font.py

    r1050 r1058  
    561561 
    562562    def _get_unicodeData(self): 
    563         return self._glyphSet._unicodeData 
     563        return self._glyphSet.unicodeData 
    564564 
    565565    unicodeData = property(_get_unicodeData, doc="The font's :class:`UnicodeData` object.") 
     
    16231623    >>> glyph.unicodes = [65] 
    16241624    >>> font.unicodeData[65] 
    1625     ['A', 'test'] 
     1625    ['test', 'A'] 
    16261626    """ 
    16271627 
  • packages/defcon/branches/ufo3/Lib/defcon/objects/layer.py

    r1054 r1058  
    8585        self._color = None 
    8686        self._lib = None 
    87         self._unicodeData = self.instantiateUnicodeData() 
    88         self.beginSelfUnicodeDataNotificationObservation() 
     87        self._unicodeData = None 
    8988 
    9089        self._directory = None 
     
    9897 
    9998        if glyphSet is not None: 
    100             self._unicodeData.disableNotifications() 
    10199            self._keys = set(self._glyphSet.keys()) 
    102             cmap = {} 
    103             for glyphName, unicodes in glyphSet.getUnicodes().items(): 
    104                 for code in unicodes: 
    105                     if code in cmap: 
    106                         cmap[code].append(glyphName) 
    107                     else: 
    108                         cmap[code] = [glyphName] 
    109             self._unicodeData.update(cmap) 
    110             self._unicodeData.enableNotifications() 
    111100 
    112101    def __del__(self): 
     
    243232        if beginObservations: 
    244233            self.beginSelfGlyphNotificationObservation(glyph) 
    245         if glyph.unicodes: 
     234        if glyph.unicodes and self._unicodeData is not None: 
    246235            self._unicodeData.addGlyphData(name, glyph.unicodes) 
    247236 
     
    271260 
    272261    def _deleteGlyph(self, name, endObservations=True): 
    273         self._unicodeData.removeGlyphData(name, self[name].unicodes) 
     262        if self._unicodeData is not None: 
     263            self._unicodeData.removeGlyphData(name, self[name].unicodes) 
    274264        dataOnDiskTimeStamp = None 
    275265        dataOnDisk = None 
     
    546536 
    547537    def endSelfUnicodeDataNotificationObservation(self): 
    548         if self._unicodeData.dispatcher is None: 
     538        if self._unicodeData is None or self._unicodeData.dispatcher is None: 
    549539            return 
    550540        self._unicodeData.endSelfNotificationObservation() 
    551541 
    552542    def _get_unicodeData(self): 
     543        if self._unicodeData is None: 
     544            cmap = {} 
     545            for glyphName, glyph in self._glyphs.items(): 
     546                if glyphName in self._scheduledForDeletion: 
     547                    continue 
     548                if not glyph.unicodes: 
     549                    continue 
     550                for code in glyph.unicodes: 
     551                    if code in cmap: 
     552                        cmap[code].append(glyphName) 
     553                    else: 
     554                        cmap[code] = [glyphName] 
     555            if self._glyphSet is not None: 
     556                glyphNames = set(self._glyphSet.keys()) - set(self._glyphs.keys()) 
     557                for glyphName, unicodes in self._glyphSet.getUnicodes(glyphNames=glyphNames).items(): 
     558                    for code in unicodes: 
     559                        if code in cmap: 
     560                            cmap[code].append(glyphName) 
     561                        else: 
     562                            cmap[code] = [glyphName] 
     563 
     564            self._unicodeData = self.instantiateUnicodeData() 
     565            self._unicodeData.disableNotifications()         
     566            self._unicodeData.update(cmap) 
     567            self._unicodeData.enableNotifications() 
     568            self.beginSelfUnicodeDataNotificationObservation() 
    553569        return self._unicodeData 
    554570 
     
    722738        glyph = self._glyphs[oldName] 
    723739        self._deleteGlyph(oldName, endObservations=False) 
    724         self._unicodeData.removeGlyphData(oldName, glyph.unicodes) 
     740        if self._unicodeData is not None: 
     741            self._unicodeData.removeGlyphData(oldName, glyph.unicodes) 
    725742        self._insertGlyph(glyph, beginObservations=False) 
    726743        self.postNotification("Layer.GlyphNameChanged", data=dict(oldValue=oldName, newValue=newName)) 
     
    731748        oldValues = data["oldValue"] 
    732749        newValues = data["newValue"] 
    733         self._unicodeData.removeGlyphData(glyphName, oldValues) 
    734         self._unicodeData.addGlyphData(glyphName, newValues) 
     750        if self._unicodeData is not None: 
     751            self._unicodeData.removeGlyphData(glyphName, oldValues) 
     752            self._unicodeData.addGlyphData(glyphName, newValues) 
    735753 
    736754 
     
    12241242    >>> glyph.unicodes = [65] 
    12251243    >>> layer.unicodeData[65] 
    1226     ['A', 'test'] 
     1244    ['test', 'A'] 
    12271245    """ 
    12281246 
Note: See TracChangeset for help on using the changeset viewer.