Glyph mask and mark data not imported from FLS+UFOCentral-generated UFOs

RoboFont Forums Enhancements Glyph mask and mark data not imported from FLS+UFOCentral-generated UFOs

Tagged: 

This topic contains 9 replies, has 4 voices, and was last updated by  Mathieu Christe 7 years, 10 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1037

    JBL
    Participant

    Glyph layer and mark not imported from UFOCentral

    for layers/masks:
    UFOCentral generates this markup:
    org.robofab.fontlab.maskData
    RoFo generates this markup:
    com.typemytype.robofont.layerData

    for marks:
    UFOCentral generates this markup:
    org.robofab.fontlab.mark
    RoFo generates this markup:
    com.typemytype.robofont.mark

    A quick hack of the UFO replacing those entries crashes RoFo on opening.
    (I did not reorder the tags but this should not matter in XML, right?)

    #1049

    frederik
    Keymaster

    RoboFont is already using the color scheme of UFO3 which stated that colors are a tuple of (r, g, b, a)

    You could convert the font lab HSV color to rgba with this tiny script:

    import colorsys
    f = CurrentFont()
    
    
    for g in f:
        fontLabMarkColor = g.lib.get("org.robofab.fontlab.maskData")
        
        if fontLabMarkColor is None:
            continue
        
        r, g, b = colorsys.hsv_to_rgb(fontLabMarkColor/256., 1., 1.)
        
        g.mark = (r, g, b, 1)
    #1050

    JBL
    Participant

    Thank you!

    #4643

    Bruno
    Participant

    Does this still work? I have the same problem; org.robofab.fontlab.maskData exist in the UFO, but I can’t get it visible in RoboFont

    #4644

    frederik
    Keymaster

    This script should work to convert FL mark colors to UFO mark colors

    #4645

    Bruno
    Participant

    Because com.typemytype.robofont.layerData & org.robofab.fontlab.maskData are not in the same format, replacing these will not make the layers appear in RoboFont as mentioned (As I understood it) above. From that I conclude that either UFOcentral or RoboFont have been updated in how they write layerdata?

    Updated code below will port the colour:

    import colorsys
    f = CurrentFont()
    for glyph in f:
        fontLabMarkColor = glyph.lib.get("org.robofab.fontlab.mark")
        if fontLabMarkColor is None:
            continue
        r, g, b = colorsys.hsv_to_rgb(fontLabMarkColor/256., 1., 1.)
        glyph.mark = (r, g, b, 1)
    
    #5279

    Mathieu Christe
    Participant

    Tonight I’ve decided to switch from FLS to RF. As I was testing the conversion, I noticed that Masks didn’t end up in RF. I searched the forum and found this post, unfortunately even after running your script, before using UFO Central to export as UFO, I can’t manage to see my Masks. “Format 2” and “Glyph Masks” boxes are checked.
    I’ve noticed that running the above script doesn’t seem to modify the .vfb file, or FLS doesn’t notice it, because I can close my font file without being prompted to Save.

    Version 1.3.1b (built 1211021533)
    OS 10.7.5

    #5280

    Bruno
    Participant

    Hey Mathieu,

    1) Run UFO central in FontLab to export your font to ufo (make sure export layers is ticked) (http://code.typesupply.com/browser/applicationScripts/FontLab/UFO/UFOCentral.py)
    2) Open the UFO in Robofont
    3) Run the following code in RoboFont to get your lay­er­data drawn:

    import colorsys
    
    f = CurrentFont()
    
    MASK_LIB_KEY = "org.robofab.fontlab.maskData"
    MARK_LIB_KEY = "org.robofab.fontlab.mark"
    
    def portFLmark(glyph):
        fontLabMarkColor = glyph.lib.get("org.robofab.fontlab.mark")
        if fontLabMarkColor is not None:
            r, g, b = colorsys.hsv_to_rgb(fontLabMarkColor/256., 1., 1.)
            glyph.mark = (r, g, b, 1)
    
    def portFLmaskData(glyph):
        #get pendata
        # filter out any single point contours (anchors)
        instructions = []
        pointStack = []
        lib = glyph.lib
        
        if lib.has_key(MASK_LIB_KEY):
            instructions = lib[MASK_LIB_KEY]
            pen = glyph.getPointPen()
            instructionsDrawPoints(instructions, pen)
            # clear the mask data from the glyph lib
            del lib[MASK_LIB_KEY]
        glyph.update()
    
    def instructionsDrawPoints(instructions, pointPen):
        """draw instructions created by InstructionPointPen"""
        # filter out single point contours (anchors)
        pointStack = []
        for instruction in instructions:
            pointStack.append(instruction)
            meth = instruction["method"]
            if meth == "endPath":
                if len(pointStack) > 3:
                    _drawPointStack(pointStack, pointPen)
                pointStack = []
                
    def _drawPointStack(stack, pointPen):
        for instruction in stack:
            meth = instruction["method"]
            if meth == "beginPath":
                pointPen.beginPath()
            elif meth == "endPath":
                pointPen.endPath()
            elif meth == "addPoint":
                pt = instruction["pt"]
                smooth = instruction.get("smooth")
                segmentType = instruction.get("segmentType")
                name = instruction.get("name")
                pointPen.addPoint(pt, segmentType, smooth, name)
            elif meth == "addComponent":
                baseGlyphName = instruction["baseGlyphName"]
                transformation = instruction["transformation"]
                pointPen.addComponent(baseGlyphName, transformation)
            else:
                raise NotImplementedError, meth
    
    for glyph in f:
        #port the colour marks
        portFLmark(glyph)
        #create/get the layer for the mask data
        glyph.getLayer("FontLab Mask")
        #flip it so we draw on a clean layer
        glyph.flipLayers("FontLab Mask", "foreground")
        portFLmaskData(glyph)
        #flip back we’re done
        glyph.flipLayers("FontLab Mask", "foreground")
    
    
    print "Done"
    

    Hope that helps.

    #5281

    Mathieu Christe
    Participant

    Hi Bruno,

    Many thanks for kindly sharing your script, which works very well. The Mask layer and its content are back into RoboFont.
    Looking at my translated file, I’ve just realised that the anchors (accents) are gone. I was expecting the anchors to fall into the category of “Glyphs Marks” when exporting to UFO. It seems again that RoboFont can’t see or display them. I’m guessing it because if I export to UFO from FLS and then import the very same UFO file, the anchors are there.

    Did you manage to get your FLS accent anchors into RoboFont?

    All the best,

    Mathieu

    #5282

    Mathieu Christe
    Participant

    Damn, without switching on Display Anchors, it’s hard to see them ;-)
    I think I’m set to switch and work mostly in RoboFont, thank you for your help Bruno.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.