FontLab Forum
2012-05-23, 23:45:36 *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to the FontLab forum, read how to use it! Update: Archives from old MSN forums are now available on our forum.
 
   Home   Help Search Calendar Downloads Tags Login Register  
Del.icio.us Digg FURL FaceBook Stumble Upon Reddit SlashDot

Pages: [1]
  Print  
Author Topic: Clearing and Copying to mask—where is the doc for working with masks?  (Read 1095 times)
jamespuckett
Beta: FontLab Studio Mac
Hero Member
***

Karma: +2/-0
Posts: 139


Email
« on: 2011-08-03, 17:02:49 »

Part of a macro I am working on clears existing guides and then copied glyph outlines to the mask. I am doing this with the following code:

#Clear all masks
def newMasks(font):
   for g in font:
      gname = g.name
      fl.Select(gname)
      fl.CallCommand(32907) #10145 is the command code for mask clear
   fl.CallCommand(32904) #10145 is the command code for mask copy
   font.update()

This seems like a messy way to do this. Is there a better way to do this? And where is some documentation for working with masks? The unofficial Fontlab Python docs do not cover working with masks beyond what can be accomplished with CallCommand.
Logged
nanife
Full Member
***

Karma: +0/-0
Korea, Republic of Korea, Republic of

Posts: 2


Email
« Reply #1 on: 2011-08-09, 21:19:58 »

Usually, mask worked well with using like this..

fl.iglyph = gIndex => gIndex : glyph index

so, your script can be work like this..
===========
f = fl.font

for i in range(len(f.glyphs)):
  fl.iglyph = i
  fl.CallCommand(32907)  # MaskClear
  fl.CallCommand(32904)  # MaskCopy
fl.UpdateFont()
===========
« Last Edit: 2011-08-15, 20:31:11 by nanife » Logged
Eigi
Beta: FontLab Studio Mac
Hero Member
***

Karma: +7/-0
Germany Germany

Posts: 57



WWW
« Reply #2 on: 2011-08-28, 05:51:30 »

Hello,

sorry for being so late.
The samples from the posts above can be made more readable by importing fl_cmd. Then you can write something like this:
import fl_cmd

fl.CallCommand(fl_cmd.MaskClear)
fl.CallCommand(fl_cmd.MaskCopy)

You can print a list of available command constants like this:
import fl_cmd

for name in dir(fl_cmd):
    print name

It is also possible to access the mask of a glyph directly. The following little function replaces the glyph mask with a copy of the glyph itself.
def replaceMaskWithGlyphCopy(glyph):
    glyph.mask = Glyph(glyph)

Modification of the mask is a bit more complicated because 'in place' modification of the mask is not possible. You have to do it in three steps:
  • create a reference to the glyph in the mask layer
  • modify this mask glyph
  • assign the modified glyph back to the mask
A function to add a copy of the glyph itself to the mask may look like this:
def addGlyphCopyToMask(glyph):
    if glyph.mask is None:
        maskGlyph = Glyph()
    else:
        maskGlyph = glyph.mask
    maskGlyph.Add(Glyph(glyph))
    glyph.mask = maskGlyph

A function to shift the mask follows the same pattern:
def shiftMask(glyph, dx=0, dy=0):
    if glyph.mask is not None:
        maskGlyph = glyph.mask
        maskGlyph.Shift(Point(dx, dy))
        glyph.mask = maskGlyph

It is not possible to clear the mask by using the mask attribute of a glyph object. For a glyph without mask the mask attribute is None. If you try to assign None to the glyph attribute an exception is raised. The only thing you can do is to assign an empty glyph to the mask, but this is not the same.
That's all I can contribute as doc for the glyph mask.
Best
Eigi
Logged
medflights
Guest
« Reply #3 on: 2011-09-11, 14:40:08 »

Hello everyone!

Is there anybody who try this formula by Eigi? Is it working in yours? Because in mine doesn't.
« Last Edit: 2011-09-12, 10:58:22 by Alex Petrov (FontLab) » Logged
Eigi
Beta: FontLab Studio Mac
Hero Member
***

Karma: +7/-0
Germany Germany

Posts: 57



WWW
« Reply #4 on: 2011-09-11, 15:39:30 »

Hello,

What happens? Any error message? How looks your script that uses the function?

Eigi
Logged
Tags:
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!