Beispiel #1
0
def doit(args):
    font = OpenFont(args.ifont)
    logger = args.logger

    constructions = ParseGlyphConstructionListFromString(args.cdfile)

    for construction in constructions:
        # Create a new constructed glyph object
        constructionGlyph = GlyphConstructionBuilder(construction, font)
        # Make a new glyph in target font with the new glyph name
        glyph = font.newGlyph(constructionGlyph.name)
        # Draw the constructed object onto the new glyph
        # This is rather odd in how it works
        constructionGlyph.draw(glyph.getPen())
        # Copy glyph metadata from constructed object
        glyph.name = constructionGlyph.name
        glyph.unicode = constructionGlyph.unicode
        glyph.note = constructionGlyph.note
        #glyph.markColor = constructionGlyph.mark
        glyph.width = constructionGlyph.width

    # Write the changes to a font directly rather than returning an object
    font.save()

    return
Beispiel #2
0
def reloadConstruction():
    """
    throw away custom Constructions and load default
    """
    path = "/Users/thom/Library/Application Support/RoboFont/scripts/*DiacriticsWorkflow/_glyphContructionsRF3.py"
    bc = imp.load_source('txt', path)
    asList = ParseGlyphConstructionListFromString(bc.basics)
    asDict = []
    for i in asList:
        if i.find("+") != i.rfind("+"):
            continue
        compo = i.split("=")[0][:-1]
        base = i.split("=")[1][1:].split("+")[0].strip()
        accent = i.split("=")[1][1:].split("+")[1].strip().split("@")[0]
        anchor = i.split("=")[1][1:].split("+")[1].strip().split("@")[1]
        # for now only one accent@anchor pair!
        construction = i.split("+")[1].strip()
        asDict.append(dict(
            active=True,
            compo=compo,
            base=base,
            accent=accent,
            anchor=anchor,
            construction=construction,

        ))

    f.lib['nl.hallotype.glyphConstructions'] = asDict
Beispiel #3
0
def loadConstructions(layer):
    text = getVariables(layer)
    text += defaultConstructions
    # text += getExtensionDefault(defaultsKey)
    constructions = {}
    for construction in ParseGlyphConstructionListFromString(text):
        name, construction = parseGlyphName(construction)
        if name is None:
            continue
        name = name.strip()
        construction = construction.strip()
        decompose = False
        if name.startswith("*"):
            name = name[1:]
            decompose = True
        constructions[name] = (construction, decompose)
    return constructions
Beispiel #4
0
# iogonek.italic = dotlessi.italic + ogonekcomb@ogonek + [email protected]:top
# txt = '''\
# apple=.notdef|F8FF
# '''

txt = ""
recipeFile = "/Users/stephennixon/type-repos/recursive/src/00-recursive-scripts-for-robofont/diacritics-and-glyph_construction-recipes/diacritic-recipes-for-recursive-generated-with_alts.txt"
with open(recipeFile, 'r') as recipe:
    for line in recipe:
        line = line.replace(' ', '')
        if len(line) > 1:
            txt += line

print(txt)
# get the actual glyph constructions from text
constructions = ParseGlyphConstructionListFromString(txt)

files = getFile("Select files to build glyphs in",
                allowsMultipleSelection=True,
                fileTypes=["ufo"])

# collect glyphs to ignore if they already exist in the font
ignoreExisting = [
    L.split('=')[0].strip()[1:] for L in txt.split('\n') if L.startswith('?')
]

for file in files:
    font = OpenFont(file, showInterface=False)
    # iterate over all glyph constructions
    for construction in constructions:
Beispiel #5
0
    def constructionsCallback(self, sender, update=True):
        if self.font is None:
            return

        font = self.font.naked()

        self.glyphConstructorFont = GlyphConstructorFont(font)

        self._glyphs = []
        errors = []

        try:
            constructions = ParseGlyphConstructionListFromString(
                sender.get(), font)
        except GlyphBuilderError as err:
            constructions = []
            errors.append(str(err))

        for construction in constructions:
            if not construction:
                glyph = self.preview.createNewLineGlyph()
            elif construction in self.glyphConstructorFont.glyphsDone:
                glyph = self.glyphConstructorFont.glyphsDone[construction]
            else:
                try:
                    constructionGlyph = GlyphConstructionBuilder(
                        construction,
                        self.glyphConstructorFont,
                        characterMap=None)
                except GlyphBuilderError as err:
                    errors.append(str(err))
                    continue

                if constructionGlyph.name is None:
                    errors.append(construction)
                    continue

                if RoboFontVersion < "2.0":
                    glyph = font._instantiateGlyphObject()
                else:
                    glyph = font.layers.defaultLayer.instantiateGlyphObject()
                glyph.name = constructionGlyph.name
                glyph.unicode = constructionGlyph.unicode
                glyph.note = constructionGlyph.note
                glyph.markColor = constructionGlyph.markColor
                if RoboFontVersion < "2.0":
                    glyph.setParent(self.glyphConstructorFont)
                    glyph.dispatcher = font.dispatcher
                else:
                    glyph._font = weakref.ref(self.glyphConstructorFont)
                    # glyph._dispatcher = font._dispatcher

                glyph.width = constructionGlyph.width
                constructionGlyph.draw(glyph.getPen())

                self.glyphConstructorFont.glyphsDone[glyph.name] = glyph

            self._glyphs.append(glyph)

        if errors:
            print("Errors:")
            print("\n".join(errors))

        if update:
            self.preview.set(self._glyphs)

        self.analyser.set(analyseConstructions(font, self._glyphs))
    def setup(self):
        self.settingsWindow = None

        self.glyph_constructor = self.SettingsWindow.constructions
        self.constructions = ParseGlyphConstructionListFromString(
            self.SettingsWindow.constructions)
    for a in glyph.anchors:
        if a.name == anchor:
            return (True, a.y)
        if a.name == "_"+anchor:
            return (True, a.y)
    return (False, None)


# try to load font constructions
if 'nl.hallotype.glyphConstructions' in f.lib:
    batchConstructions = f.lib['nl.hallotype.glyphConstructions']
else:
    # load default set
    path = "_glyphContructionsRF3.py"
    bc = imp.load_source('txt', path)
    asList = ParseGlyphConstructionListFromString(bc.basics)
    asDict = []
    for i in asList:
        if i.find("+") != i.rfind("+"):
            continue
        compo = i.split("=")[0][:-1]
        base = i.split("=")[1][1:].split("+")[0].strip()
        accent = i.split("=")[1][1:].split("+")[1].strip().split("@")[0]
        anchor = i.split("=")[1][1:].split("+")[1].strip().split("@")[1]
        # for now only one accent@anchor pair!
        construction = i.split("+")[1].strip()
        asDict.append(dict(
            active=True,
            compo=compo,
            base=base,
            accent=accent,