Пример #1
0
def buildExtraGlyphs(ufo):
    """Builds some necessary glyphs at runtime that are derived from other
    glyphs, instead of having to update them manually."""

    # Build fallback glyphs, these are the base glyph that cmap maps to. We
    # decompose them immediately in the layout code, so they shouldn’t be used
    # for anything and we could just keep them blank, but then FontConfig will
    # think the font does not support these characters.
    buildEncoded(ufo)

    # Build Arabic comma and semicolon glyphs, by rotating the Latin 180°, so
    # that they are similar in design.
    for code, name in [(ord(u'،'), "comma"), (ord(u'؛'), "semicolon")]:
        glyph = ufo.newGlyph("uni%04X" % code)
        glyph.unicode = code
        enGlyph = ufo[name]
        colon = ufo["colon"]
        component = Component()
        component.transformation = tuple(Transform().rotate(math.radians(180)))
        component.baseGlyph = enGlyph.name
        glyph.appendComponent(component)
        glyph.move((0, colon.bounds[1] - glyph.bounds[1]))
        glyph.leftMargin = enGlyph.rightMargin
        glyph.rightMargin = enGlyph.leftMargin

    # Ditto for question mark, but here we flip.
    for code, name in [(ord(u'؟'), "question")]:
        glyph = ufo.newGlyph("uni%04X" % code)
        glyph.unicode = code
        enGlyph = ufo[name]
        component = Component()
        component.transformation = tuple(Transform().scale(-1, 1))
        component.baseGlyph = enGlyph.name
        glyph.appendComponent(component)
        glyph.leftMargin = enGlyph.rightMargin
        glyph.rightMargin = enGlyph.leftMargin
Пример #2
0
def buildExtraGlyphs(ufo):
    """Builds some necessary glyphs at runtime that are derived from other
    glyphs, instead of having to update them manually."""

    # Build fallback glyphs, these are the base glyph that cmap maps to. We
    # decompose them immediately in the layout code, so they shouldn’t be used
    # for anything and we could just keep them blank, but then FontConfig will
    # think the font does not support these characters.
    buildEncoded(ufo)

    # Build Arabic comma and semicolon glyphs, by rotating the Latin 180°, so
    # that they are similar in design.
    for code, name in [(ord(u'،'), "comma"), (ord(u'؛'), "semicolon")]:
        glyph = ufo.newGlyph("uni%04X" % code)
        glyph.unicode = code
        enGlyph = ufo[name]
        colon = ufo["colon"]
        component = Component()
        component.transformation = tuple(Transform().rotate(math.radians(180)))
        component.baseGlyph = enGlyph.name
        glyph.appendComponent(component)
        glyph.move((0, colon.bounds[1] - glyph.bounds[1]))
        glyph.leftMargin = enGlyph.rightMargin
        glyph.rightMargin = enGlyph.leftMargin

    # Ditto for question mark, but here we flip.
    for code, name in [(ord(u'؟'), "question")]:
        glyph = ufo.newGlyph("uni%04X" % code)
        glyph.unicode = code
        enGlyph = ufo[name]
        component = Component()
        component.transformation = tuple(Transform().scale(-1, 1))
        component.baseGlyph = enGlyph.name
        glyph.appendComponent(component)
        glyph.leftMargin = enGlyph.rightMargin
        glyph.rightMargin = enGlyph.leftMargin
Пример #3
0
def getGlyphFromDict(glyph_dict):
    g = Glyph()
    
    # Set attributes
    
    g.height = glyph_dict.get('height', 0)
    g.lib = glyph_dict.get('lib', {})
    g.name = glyph_dict.get('name', '')
    g.note = glyph_dict.get('note', None)
    g.unicode = glyph_dict.get('unicode', None)
    g.unicodes = glyph_dict.get('unicodes', [])
    g.width = glyph_dict.get('width', 0)
    
    # Draw the outlines with a pen
    pen = g.getPointPen()
    
    for contour in glyph_dict.get('contours', []):
        pen.beginPath()
        for point in contour:
            pen.addPoint(
                (
                    point.get('x'),
                    point.get('y')
                ),
                segmentType = point.get('type', None),
                name = point.get('name', None),
                smooth = point.get('smooth', None),
            )
        pen.endPath()
    
    # Add components
    
    for component in glyph_dict.get('components', []):
        c = Component()
        c.baseGlyph = component.get('ref', '')
        c.transformation = component.get('transformation', (1, 0, 0, 1, 0, 0))
        g.appendComponent(c)
    
    # Add anchors
    
    for anchor in glyph_dict.get('anchors', []):
        a = Anchor(anchorDict = anchor)
        g.appendAnchor(a)
    
    # Return the completed glyph object
    
    return g
Пример #4
0
def recomponet(path_to_orignal, path_to_new=None):
    assert os.path.exists(path_to_orignal)
    font = Font(path_to_orignal)
    if path_to_new is not None:
        assert os.path.exists(path_to_new)
        font.save(path_to_new)
        font = Font(path_to_new)
    else:
        new_path = _findAvailablePathName(path_to_orignal)
        font.save(new_path)
        font = Font(new_path)

    ordered_glyphs = {}
    clean_up = []
    for key in font.keys():
        parts = key.split('.')
        if len(parts) == 1:
            part = key
            if key.endswith('comb'):
                part = key[:-4]
                clean_up.append(key)
            if part not in ordered_glyphs:
                ordered_glyphs[part] = [
                    key,
                ]
            else:
                glyphs = ordered_glyphs[part]
                if key not in glyphs:
                    glyphs.append(key)
                    ordered_glyphs[part] = glyphs
        else:
            part = parts[0]
            if part.endswith('comb'):
                part = parts[0][:-4]
                clean_up.append(key)
            if part not in ordered_glyphs:
                ordered_glyphs[part] = [
                    key,
                ]
            else:
                glyphs = ordered_glyphs[part]
                if key not in glyphs:
                    glyphs.append(key)
                    ordered_glyphs[part] = glyphs
    for i in clean_up:
        if i not in ordered_glyphs:
            part = i[:-4]
            if part in ordered_glyphs:
                glyphs = ordered_glyphs[part]
                ordered_glyphs[i] = glyphs

    # Cleanup for the i
    i = ordered_glyphs['i']
    i.append('dotlessi')
    ordered_glyphs['i'] = i

    # Additional cleanup for the pesky commaaccent
    if 'uni0327' not in ordered_glyphs:
        ordered_glyphs['uni0327'] = [
            'uni0326',
        ]
    else:
        if 'uni0326' not in ordered_glyphs['uni0327']:
            glyphs = ordered_glyphs['uni0327']
            glyphs.append('uni0326')
            ordered_glyphs['uni0327'] = glyphs
    found = []
    for glyph in font:
        if len(glyph) is not 0:
            parts = decompose_glyph(font.unicodeData, glyph.name,
                                    ordered_glyphs)
            if len(parts) > 1:
                print 'normal'
                print glyph.name
                for part in parts:
                    if part in font.keys() and compare_glyph(
                            font, glyph, font[part]) is not -1:
                        orgin, delete = compare_glyph(font, glyph, font[part])
                        if len(font[part]) is 0 and len(
                                font[part].components) is not 0:
                            part = font[part].components[0].baseGlyph
                        found.append(glyph.name)
                        for x in [glyph[x] for x in delete]:
                            glyph.removeContour(x)
                        component = Component()
                        component.baseGlyph = part
                        glyph.appendComponent(component)
                        xMin, yMin, xMax, yMax = component.bounds
                        moveX = orgin[0] - xMin
                        moveY = orgin[1] - yMin
                        component.move((moveX, moveY))
            elif glyph.name in double_check.keys():
                parts = double_check[glyph.name]
                print glyph.name
                print 'double check'
                print parts
                for part in parts:
                    print part
                    if part in font.keys() and compare_glyph(
                            font, glyph, font[part]) is not -1:
                        orgin, delete = compare_glyph(font, glyph, font[part])
                        if len(font[part]) is 0 and len(
                                font[part].components) is not 0:
                            part = font[part].components[0].baseGlyph
                        found.append(glyph.name)
                        for x in [glyph[x] for x in delete]:
                            glyph.removeContour(x)
                        component = Component()
                        component.baseGlyph = part
                        glyph.appendComponent(component)
                        xMin, yMin, xMax, yMax = component.bounds
                        moveX = orgin[0] - xMin
                        moveY = orgin[1] - yMin
                        component.move((moveX, moveY))
                        print 'done'
                        break
                    else:
                        print part
                        print 'did not check out'
            elif glyph.name in composites.keys():
                preparts = composites[glyph.name]
                parts = []
                for p in preparts:
                    parts.append(p)
                    if p in ordered_glyphs:
                        for x in ordered_glyphs[p]:
                            parts.append(x)
                print glyph.name
                print 'composite'
                print parts
                for part in parts:
                    if compare_glyph(font, glyph, font[part]) is not -1:
                        orgin, delete = compare_glyph(font, glyph, font[part])
                        if len(font[part]) is 0 and len(
                                font[part].components) is not 0:
                            part = font[part].components[0].baseGlyph
                        found.append(glyph.name)
                        for x in [glyph[x] for x in delete]:
                            glyph.removeContour(x)
                        component = Component()
                        component.baseGlyph = part
                        glyph.appendComponent(component)
                        xMin, yMin, xMax, yMax = component.bounds
                        moveX = orgin[0] - xMin
                        moveY = orgin[1] - yMin
                        component.move((moveX, moveY))
    font.save()
    print 'Found:'
    print ' '
    for x in found:
        print x
    print '----------------'
    print str(len(found)) + ' Glyphs'
Пример #5
0
def merge(args):
    arabic = Font(args.arabicfile)

    latin = Font(args.latinfile)

    addPlaceHolders(arabic)

    unicodes = parseSubset(args.latin_subset)
    for glyph in arabic:
        unicodes.extend(glyph.unicodes)

    latin_locl = ""
    for name in latin.glyphOrder:
        glyph = latin[name]
        if name in arabic:
            glyph.unicode = None
            glyph.name = name + ".latn"
            latin_locl += "sub %s by %s;" % (name, glyph.name)
        arabic.insertGlyph(glyph)

    for attr in ("xHeight", "capHeight"):
        value = getattr(latin.info, attr)
        if value is not None:
            setattr(arabic.info, attr, getattr(latin.info, attr))

    arabic.features.text += latin.features.text

    if latin_locl:
        arabic.features.text += """
feature locl {
  lookupflag IgnoreMarks;
  script latn;
  %s
} locl;
""" % latin_locl

    for ch in [(ord(u'؟'), "question")]:
        arGlyph = arabic.newGlyph("uni%04X" % ch[0])
        arGlyph.unicode = ch[0]
        enGlyph = arabic[ch[1]]
        component = Component()
        component.transformation = tuple(Transform().scale(-1, 1))
        component.baseGlyph = enGlyph.name
        arGlyph.appendComponent(component)
        arGlyph.leftMargin = enGlyph.rightMargin
        arGlyph.rightMargin = enGlyph.leftMargin
        unicodes.append(arGlyph.unicode)

    arabic.lib[MADA_UNICODES] = unicodes

    # Set metadata
    arabic.info.versionMajor, arabic.info.versionMinor = map(
        int, args.version.split("."))

    copyright = u"Copyright © 2015-%s The Reem Kufi Project Authors." % datetime.now(
    ).year

    arabic.info.copyright = copyright

    arabic.info.openTypeNameDesigner = u"Khaled Hosny"
    arabic.info.openTypeNameLicenseURL = u"http://scripts.sil.org/OFL"
    arabic.info.openTypeNameLicense = u"This Font Software is licensed under the SIL Open Font License, Version 1.1. This license is available with a FAQ at: http://scripts.sil.org/OFL"
    arabic.info.openTypeNameDescription = u"Reem Kufi is a Fatimid-style decorative Kufic typeface as seen in the historical mosques of Cairo. Reem Kufi is based on the Kufic designs of the great Arabic calligrapher Mohammed Abdul Qadir who revived this art in the 20th century and formalised its rules."
    arabic.info.openTypeNameSampleText = u"ريم على القاع بين البان و العلم   أحل سفك دمي في الأشهر الحرم"

    return arabic