| 7 | 6 | from robofab.objects.objectsBase import BaseFont, BaseGlyph, BaseContour, BaseSegment,\ |
|---|
| 8 | 7 | BasePoint, BaseBPoint, BaseAnchor, BaseGuide, BaseComponent, BaseKerning, BaseInfo, BaseFeatures, BaseGroups, BaseLib,\ |
|---|
| | 392 | |
|---|
| | 393 | from robofab.world import CurrentGlyph |
|---|
| | 394 | |
|---|
| | 395 | def 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 | |
|---|
| | 408 | def 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() |
|---|