Changeset 163

Show
Ignore:
Timestamp:
02/17/09 02:43:08 (3 years ago)
Author:
erik
Message:

This fixes a issue in importing ps zone information. I missed a bug in FL and fixed it in the wrong place.
The FL attribute font.blue_values_num can't be set to the highest number required to store 7 zones. Adam was asked about t his in september 2008, but didn't answer.
While this can't fix the FL bug, it can properly import all values up to the last one. A warning is printed when the last value is dropped.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Lib/robofab/objects/objectsFL.py

    r91 r163  
    106106        stem_snap_v_num(integer) 
    107107        stem_snap_v 
     108         
     109                 
     110         
    108111 """ 
    109112 
     
    151154        def _asPairs(self, l): 
    152155                """Split a list of numbers into a list of pairs""" 
    153                 assert len(l)%2 == 0, "Even number of values required: %s"%(`l`) 
     156                if not len(l)%2 == 0: 
     157                        l = l[:-1] 
    154158                n = [[l[i], l[i+1]] for i in range(0, len(l), 2)] 
    155159                n.sort() 
     
    166170                return n 
    167171         
     172        def _checkForFontLabSanity(self, attribute, values): 
     173                """Function to handle problems with FontLab not allowing the max number of  
     174                alignment zones to be set to the max number. 
     175                Input:  the name of the zones and the values to be set 
     176                Output: a warning when there are too many values to be set 
     177                                and the max values which FontLab will allow. 
     178                """ 
     179                warn = False 
     180                if attribute in ['vStems', 'hStems']: 
     181                        # the number of items to drop from the list if the list is too long, 
     182                        # stems are single values, but the zones are pairs. 
     183                        skip = 1 
     184                        total = min(self._attributeNames[attribute]['max'], len(values)) 
     185                        if total == self._attributeNames[attribute]['max']: 
     186                                total = self._attributeNames[attribute]['max'] - skip 
     187                                warn = True 
     188                else: 
     189                        skip = 2 
     190                        values = self._flattenPairs(values) 
     191                        total = min(self._attributeNames[attribute]['max']*2, len(values)) 
     192                        if total == self._attributeNames[attribute]['max']*2: 
     193                                total = self._attributeNames[attribute]['max']*2 - skip 
     194                                warn = True 
     195                if warn: 
     196                        print "* * * WARNING: FontLab will only accept %d %s items maximum from Python. Dropping values: %s."%(self._attributeNames[attribute]['max']-1, attribute, `values[total:]`) 
     197                return total, values[:total] 
     198                 
     199                 
    168200        def _getBlueValues(self): 
    169201                        return self._asPairs(self._object.blue_values[self._masterIndex]) 
    170202        def _setBlueValues(self, values): 
    171                 values = self._flattenPairs(values) 
    172                 self._object.blue_values_num = min(self._attributeNames['blueValues']['max']*2, len(values))-1 
    173                 for i in range(self._object.blue_values_num+1): 
     203                total, values = self._checkForFontLabSanity('blueValues', values) 
     204                self._object.blue_values_num = total 
     205                for i in range(self._object.blue_values_num): 
    174206                        self._object.blue_values[self._masterIndex][i] = values[i] 
    175207 
     
    177209                        return self._asPairs(self._object.other_blues[self._masterIndex]) 
    178210        def _setOtherBlues(self, values): 
    179                 values = self._flattenPairs(values) 
    180                 self._object.other_blues_num = min(self._attributeNames['otherBlues']['max']*2, len(values))-1 
    181                 for i in range(self._object.other_blues_num+1): 
     211                total, values = self._checkForFontLabSanity('otherBlues', values) 
     212                self._object.other_blues_num = total 
     213                for i in range(self._object.other_blues_num): 
    182214                        self._object.other_blues[self._masterIndex][i] = values[i] 
    183215 
     
    185217                        return self._asPairs(self._object.family_blues[self._masterIndex]) 
    186218        def _setFamilyBlues(self, values): 
    187                 values = self._flattenPairs(values) 
    188                 self._object.family_blues_num = min(self._attributeNames['familyBlues']['max']*2, len(values))-1 
    189                 for i in range(self._object.family_blues_num+1): 
     219                total, values = self._checkForFontLabSanity('familyBlues', values) 
     220                self._object.family_blues_num = total 
     221                for i in range(self._object.family_blues_num): 
    190222                        self._object.family_blues[self._masterIndex][i] = values[i] 
    191223 
     
    193225                        return self._asPairs(self._object.family_other_blues[self._masterIndex]) 
    194226        def _setFamilyOtherBlues(self, values): 
    195                 values = self._flattenPairs(values) 
    196                 self._object.family_other_blues_num = min(self._attributeNames['familyOtherBlues']['max']*2, len(values))-1 
    197                 for i in range(self._object.family_other_blues_num+1): 
     227                total, values = self._checkForFontLabSanity('familyOtherBlues', values) 
     228                self._object.family_other_blues_num = total 
     229                for i in range(self._object.family_other_blues_num): 
    198230                        self._object.family_other_blues[self._masterIndex][i] = values[i] 
    199231 
     
    201233                        return list(self._object.stem_snap_v[self._masterIndex]) 
    202234        def _setVStems(self, values): 
    203                 self._object.stem_snap_v_num = min(self._attributeNames['vStems']['max'], len(values))-1 
    204                 for i in range(self._object.stem_snap_v_num+1): 
     235                total, values = self._checkForFontLabSanity('vStems', values) 
     236                self._object.stem_snap_v_num = total 
     237                for i in range(self._object.stem_snap_v_num): 
    205238                        self._object.stem_snap_v[self._masterIndex][i] = values[i] 
    206239 
     
    208241                        return list(self._object.stem_snap_h[self._masterIndex]) 
    209242        def _setHStems(self, values): 
    210                 self._object.stem_snap_h_num = min(self._attributeNames['hStems']['max'], len(values))-1 
    211                 for i in range(self._object.stem_snap_h_num+1): 
     243                total, values = self._checkForFontLabSanity('hStems', values) 
     244                self._object.stem_snap_h_num = total 
     245                for i in range(self._object.stem_snap_h_num): 
    212246                        self._object.stem_snap_h[self._masterIndex][i] = values[i] 
    213247