Changeset 51 for trunk/robofab/Lib/robofab
- Timestamp:
- 02/25/08 11:35:12 (5 years ago)
- File:
-
- 1 edited
-
trunk/robofab/Lib/robofab/objects/objectsFL.py (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/robofab/Lib/robofab/objects/objectsFL.py
r42 r51 10 10 MOVE, LINE, CORNER, CURVE, QCURVE, OFFCURVE,\ 11 11 relativeBCPIn, relativeBCPOut, absoluteBCPIn, absoluteBCPOut,\ 12 BasePostScriptFontHintValues, postScriptHintDataLibKey 12 BasePostScriptFontHintValues, postScriptHintDataLibKey, BasePostScriptGlyphHintValues 13 13 from fontTools.misc import arrayTools 14 14 from robofab.pens.flPen import FLPointPen … … 67 67 """ 68 68 69 FontLab implementation of psHints object 69 FontLab implementation of psHints objects 70 70 71 71 Most of the FL methods relating to ps hints return a list of 16 items. … … 223 223 hStems = property(_getHStems, _setHStems, doc="postscript hints: horizontal stem values") 224 224 225 226 227 def getPostScriptHintDataFromLib(aFont, fontLib): 225 226 def getPostScriptFontHintDataFromLib(aFont, fontLib): 228 227 hintData = fontLib.get(postScriptHintDataLibKey) 229 228 psh = PostScriptFontHintValues(aFont) 230 229 psh.fromDict(hintData) 230 231 232 class PostScriptGlyphHintValues(BasePostScriptGlyphHintValues): 233 """ Wrapper for glyph-level PostScript hinting information for FontLab. 234 vStems, hStems 235 """ 236 def __init__(self, glyph=None): 237 self._object = glyph.naked() 238 239 def copy(self): 240 from robofab.objects.objectsRF import PostScriptGlyphHintValues as _PostScriptGlyphHintValues 241 return _PostScriptGlyphHintValues(data=self.asDict()) 242 243 def _hintObjectsToList(self, item): 244 data = [] 245 done = [] 246 for hint in item: 247 p = (hint.position, hint.width) 248 if p in done: 249 continue 250 data.append(p) 251 done.append(p) 252 data.sort() 253 return data 254 255 def _listToHintObjects(self, item): 256 hints = [] 257 done = [] 258 for pos, width in item: 259 if (pos, width) in done: 260 # we don't want to set duplicates 261 continue 262 hints.append(Hint(pos, width)) 263 done.append((pos,width)) 264 return hints 265 266 def _getVHints(self): 267 return self._hintObjectsToList(self._object.vhints) 268 269 def _setVHints(self, values): 270 # 1 = horizontal hints and links, 271 # 2 = vertical hints and links 272 # 3 = all hints and links 273 self._object.RemoveHints(2) 274 values.sort() 275 for hint in self._listToHintObjects(values): 276 self._object.vhints.append(hint) 277 278 def _getHHints(self): 279 return self._hintObjectsToList(self._object.hhints) 280 281 def _setHHints(self, values): 282 # 1 = horizontal hints and links, 283 # 2 = vertical hints and links 284 # 3 = all hints and links 285 self._object.RemoveHints(1) 286 values.sort() 287 for hint in self._listToHintObjects(values): 288 self._object.hhints.append(hint) 289 290 vHints = property(_getVHints, _setVHints, doc="postscript hints: vertical hint zones") 291 hHints = property(_getHHints, _setHHints, doc="postscript hints: horizontal hint zones") 292 231 293 232 294 … … 238 300 # glyph.hhints and glyph.vhints returns a list of Hint objects. 239 301 # Hint objects have position and width attributes. 240 data['h hints'] = []302 data['hHints'] = [] 241 303 for index in xrange(len(glyph.hhints)): 242 304 hint = glyph.hhints[index] 243 d = { 'position' : hint.position, 244 'width' : hint.width, 245 } 246 data['hhints'].append(d) 247 if not data['hhints']: 248 del data['hhints'] 249 data['vhints'] = [] 305 data['hHints'].append((hint.position, hint.width)) 306 if not data['hHints']: 307 del data['hHints'] 308 data['vHints'] = [] 250 309 for index in xrange(len(glyph.vhints)): 251 310 hint = glyph.vhints[index] 252 d = { 'position' : hint.position, 253 'width' : hint.width, 254 } 255 data['vhints'].append(d) 256 if not data['vhints']: 257 del data['vhints'] 311 data['vHints'].append((hint.position, hint.width)) 312 if not data['vHints']: 313 del data['vHints'] 258 314 ## 259 315 ## horizontal and vertical links … … 261 317 # glyph.hlinks and glyph.vlinks returns a list of Link objects. 262 318 # Link objects have node1 and node2 attributes. 263 data['h links'] = []319 data['hLinks'] = [] 264 320 for index in xrange(len(glyph.hlinks)): 265 321 link = glyph.hlinks[index] … … 267 323 'node2' : link.node2, 268 324 } 269 data['h links'].append(d)270 if not data['h links']:271 del data['h links']272 data['v links'] = []325 data['hLinks'].append(d) 326 if not data['hLinks']: 327 del data['hLinks'] 328 data['vLinks'] = [] 273 329 for index in xrange(len(glyph.vlinks)): 274 330 link = glyph.vlinks[index] … … 276 332 'node2' : link.node2, 277 333 } 278 data['v links'].append(d)279 if not data['v links']:280 del data['v links']334 data['vLinks'].append(d) 335 if not data['vLinks']: 336 del data['vLinks'] 281 337 ## 282 338 ## replacement table … … 284 340 # glyph.replace_table returns a list of Replace objects. 285 341 # Replace objects have type and index attributes. 286 data['replace _table'] = []342 data['replaceTable'] = [] 287 343 for index in xrange(len(glyph.replace_table)): 288 344 replace = glyph.replace_table[index] … … 290 346 'index' : replace.index, 291 347 } 292 data['replace _table'].append(d)293 if not data['replace _table']:294 del data['replace _table']348 data['replaceTable'].append(d) 349 if not data['replaceTable']: 350 del data['replaceTable'] 295 351 # XXX 296 352 # need to support glyph.instructions and glyph.hdmx? … … 310 366 ## horizontal and vertical hints 311 367 ## 312 if aDict.has_key('h hints'):313 for d in aDict['h hints']:368 if aDict.has_key('hHints'): 369 for d in aDict['hHints']: 314 370 glyph.hhints.append(Hint(d['position'], d['width'])) 315 if aDict.has_key('v hints'):316 for d in aDict['v hints']:371 if aDict.has_key('vHints'): 372 for d in aDict['vHints']: 317 373 glyph.vhints.append(Hint(d['position'], d['width'])) 318 374 ## 319 375 ## horizontal and vertical links 320 376 ## 321 if aDict.has_key('h links'):322 for d in aDict['h links']:377 if aDict.has_key('hLinks'): 378 for d in aDict['hLinks']: 323 379 glyph.hlinks.append(Link(d['node1'], d['node2'])) 324 if aDict.has_key('v links'):325 for d in aDict['v links']:380 if aDict.has_key('vLinks'): 381 for d in aDict['vLinks']: 326 382 glyph.vlinks.append(Link(d['node1'], d['node2'])) 327 383 ## 328 384 ## replacement table 329 385 ## 330 if aDict.has_key('replace _table'):331 for d in aDict['replace _table']:386 if aDict.has_key('replaceTable'): 387 for d in aDict['replaceTable']: 332 388 glyph.replace_table.append(Replace(d['type'], d['index'])) 333 389 … … 1113 1169 count = count + 1 1114 1170 # import postscript font hint data 1115 getPostScript HintDataFromLib(self, fontLib)1171 getPostScriptFontHintDataFromLib(self, fontLib) 1116 1172 self.kerning.clear() 1117 1173 self.kerning.update(u.readKerning()) … … 1260 1316 note = property(_get_note, _set_note, doc="note") 1261 1317 1262 #def _get_psHints(self): 1263 # # get an object representing the postscript zone information 1264 # # thes 1265 # raise NotImplementedError 1266 1267 #psHints = property(_get_psHints, doc="postscript hint data") 1318 def _get_psHints(self): 1319 # get an object representing the postscript zone information 1320 return PostScriptGlyphHintValues(self) 1321 1322 psHints = property(_get_psHints, doc="postscript hint data") 1268 1323 1269 1324 #
Note: See TracChangeset
for help on using the changeset viewer.
