Changeset 174

Show
Ignore:
Timestamp:
03/22/09 06:09:56 (3 years ago)
Author:
erik
Message:

Remove AllFonts? import, as it is defined in this file. Add functions for getting the data in the mask as a fab glyph, and setting the mask data with a fab glyph.

Files:

Legend:

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

    r173 r174  
    33from FL import *         
    44 
    5 from robofab.tools.toolsFL import GlyphIndexTable,\ 
    6                 AllFonts, NewGlyph 
     5from robofab.tools.toolsFL import GlyphIndexTable, NewGlyph 
    76from robofab.objects.objectsBase import BaseFont, BaseGlyph, BaseContour, BaseSegment,\ 
    87                BasePoint, BaseBPoint, BaseAnchor, BaseGuide, BaseComponent, BaseKerning, BaseInfo, BaseFeatures, BaseGroups, BaseLib,\ 
     
    344343def CurrentGlyph(): 
    345344        """Return a RoboFab glyph object for the currently selected glyph.""" 
    346         from robofab.world import AllFonts 
    347345        currentPath = fl.font.file_name 
    348346        if fl.glyph is None: 
     
    392390                all.append(RFont(naked)) 
    393391        return all 
     392         
     393        from robofab.world import CurrentGlyph 
     394 
     395def getGlyphFromMask(g): 
     396        """Get a Fab glyph object for the data in the mask layer.""" 
     397        from robofab.objects.objectsFL import RGlyph as FL_RGlyph 
     398        from robofab.objects.objectsRF import RGlyph as RF_RGlyph 
     399        n = g.naked() 
     400        mask = n.mask 
     401        fg = FL_RGlyph(mask) 
     402        rf = RF_RGlyph() 
     403        pen = rf.getPointPen() 
     404        fg.drawPoints(pen) 
     405        rf.width = g.width      # can we get to the mask glyph width without flipping the UI? 
     406        return rf 
     407 
     408def setMaskToGlyph(maskGlyph, targetGlyph, clear=True): 
     409        """Set the maskGlyph as a mask layer in targetGlyph. 
     410        maskGlyph is a FontLab or RoboFab RGlyph, orphaned or not. 
     411        targetGlyph is a FontLab RGLyph. 
     412        clear is a bool. False: keep the existing mask data, True: clear the existing mask data. 
     413        """ 
     414        from robofab.objects.objectsFL import RGlyph as FL_RGlyph 
     415        from FL import Glyph as FL_NakedGlyph 
     416        flGlyph = FL_NakedGlyph()               # new, orphaned FL glyph 
     417        wrapped = FL_RGlyph(flGlyph)    # rf wrapper for FL glyph 
     418        if not clear: 
     419                        # copy the existing mask data first 
     420                        existingMask = getGlyphFromMask(targetGlyph) 
     421                        pen = wrapped.getPointPen()             # get a pen for the wrapper 
     422                        existingMask.drawPoints(pen) 
     423        pen = wrapped.getPointPen()             # get a pen for the wrapper 
     424        maskGlyph.drawPoints(pen)               # draw the data 
     425        targetGlyph.naked().mask = wrapped .naked()      
     426        targetGlyph.update() 
    394427 
    395428# the lib getter and setter are shared by RFont and RGlyph