Пример #1
0
def copyglyph(font, infont, g, u, args) :
    extras = set()
    if args.scale is None :
        scale = psMat.identity()
    else :
        scale = psMat.scale(args.scale)
    o = font.findEncodingSlot(u)
    if o == -1 :
        glyph = font.createChar(u, g.glyphname)
    else :
        glyph = font[o]
    if len(g.references) == 0 :
        font.selection.select(glyph)
        pen = glyph.glyphPen()
        g.draw(pen)
        glyph.transform(scale)
    else :
        for r in g.references :
            t = psMat.compose(r[1], scale)
            newt = psMat.compose(psMat.identity(), psMat.translate(t[4], t[5]))
            glyph.addReference(r[0], newt)
            extras.add(r[0])
    glyph.width = g.width * scale[0]
    if args.anchors :
        for a in g.anchorPoints :
            try :
                l = font.getSubtableOfAnchor(a[1])
            except EnvironmentError :
                font.addAnchorClass("", a[0]*scale[0], a[1]*scale[3])
        glyph.anchorPoints = g.anchorPoints
    return list(extras)
def copyGlyphs(font,
               sourceGlyphs,
               newGlyphs=None,
               transform=psMat.identity(),
               suffix=''):
    for i, sourceGlyphName in enumerate(sourceGlyphs):
        sourceGlyph = font[sourceGlyphName]
        newGlyphUnicode = -1
        newGlyphName = ''
        if newGlyphs:
            newGlyphItem = newGlyphs[i]
            if type(newGlyphItem) is tuple:
                newGlyphUnicode = newGlyphItem[0]
                newGlyphName = newGlyphItem[1]
                newGlyphId = newGlyphName
            else:
                if type(newGlyphItem) is str:
                    newGlyphName = newGlyphItem
                    newGlyphId = newGlyphName
                else:
                    if type(newGlyphItem) is int:
                        newGlyphUnicode = newGlyphItem
                        newGlyphId = newGlyphUnicode
        else:
            newGlyphName = sourceGlyph.glyphname + suffix
            newGlyphId = newGlyphName
        if newGlyphId not in font:
            newGlyph = font.createChar(newGlyphUnicode, newGlyphName)
            if suffix:
                newGlyph.glyphname = sourceGlyph.glyphname + suffix
            else:
                newGlyph.glyphname = newGlyphName
            newGlyph.width = sourceGlyph.width
            newGlyph.addReference(sourceGlyph.glyphname)
            newGlyph.transform(transform)
Пример #3
0
 def resolveGlyph(self, allowScaled=False):
     if len(self.children) == 1 and len(self.children[0].children) == 0:
         child = self.children[0]
         if not child.font.temporary['names'][child.name] and (
                 not allowScaled or child.scale == psMat.identity()):
             self.glyph = child.font[child.name]
             child.font.temporary['names'][child.name] = self
             self.scale = child.scale
Пример #4
0
def removenestedrefs(char):
    if outfont[char].references == ():
        return [(char, psMat.identity())]
    else:
        newrefs = []
        for (refglyph, transform) in outfont[char].references:
            subrefs = removenestedrefs(refglyph)
            for (newglyph, newtrans) in subrefs:
                newrefs.append((newglyph, psMat.compose(newtrans, transform)))
        return newrefs
Пример #5
0
 def __init__(self, name, uid):
     self.name = name  # name by which we are known
     self.uid = uid
     self.glyph = None  # concrete ff glyph object that we are a copy of
     self.children = []  # bases that constitute us
     self.scale = psMat.identity()  # scaling of concrete ff glyph points
     self.advance = -1
     self.rsb = -1
     self.lsb = -1
     self.props = {}
     self.notes = ""
     self.realGlyphs = []
     self.points = {}
Пример #6
0
 def resolveReferences(self, anchorMap):
     for p, v in self.points.items():  # sort out config defined points
         anchorMap[p][0] == "basemark"
         self.points[p] = (None, v[1], v[0])
     scale = psMat.identity()
     for c in self.children:
         adv = c.resolveReferences(self, scale, anchorMap)
         scale = psMat.compose(scale, psMat.translate(adv, 0))
     if self.advance < 0:
         if self.glyph:
             self.advance = pointMult((self.glyph.width, 0), self.scale)[0]
         else:
             self.advance = adv
         if self.advance < 0: self.advance = 0
Пример #7
0
 def __init__(self, font, name, parent=None, at=None, withap=None):
     self.font = font  # font we are from
     self.name = name  # our name in the font
     self.parent = parent  # what we are attached to
     self.at = at
     self.withap = re.sub("^_", "", withap) if withap else None
     self.children = []  # what is attached to us
     self.advance = None
     self.lsb = None
     self.rsb = None
     self.glyph = None  # Glyph that carries our concrete glyph which we reference
     self.scale = psMat.identity()  # scaling of glyph reference
     self.anchors = {}
     if parent:
         parent.addChild(self)
Пример #8
0
 def fixGlyphWidth(self, glyph, glyphName):
     modifiedWidth = self.fixedWidth
     while modifiedWidth < glyph.width:
         modifiedWidth += self.fixedWidth
     deltaWidth = modifiedWidth - glyph.width
     if self.isBase(glyphName):
         # right align
         matrix = psMat.translate(deltaWidth)
         # print "base " + glyphName + " translate by " + str(deltaWidth)
     else:
         if self.isMark(glyphName):
             # left align
             matrix = psMat.identity()
         else:
             # centre
             matrix = psMat.translate(.5 * deltaWidth)
     glyph.transform(matrix)
     glyph.width = modifiedWidth
Пример #9
0
def reference_transform(ref, glyph, deg):
    thatglyphname = ref[0]
    thisglyphname = glyph.glyphname
    r = ref[1]

    column_a = "%s's reference to %s:" % (thisglyphname, thatglyphname)
    column_b = str(r)

    ri = psMat.inverse(r)

    result = psMat.identity()
    result = psMat.compose(result, italic_shift_right(deg))
    result = psMat.compose(result, italic_unskew(deg))
    result = psMat.compose(result, r)
    result = psMat.compose(result, italic_skew(deg))
    result = psMat.compose(result, italic_shift_left(deg))

    return (ref[0], result)
Пример #10
0
 def fixGlyphWidth(self, glyph, glyphName):
     modifiedWidth = self.fixedWidth
     while modifiedWidth < glyph.width :
         modifiedWidth += self.fixedWidth
     deltaWidth = modifiedWidth - glyph.width
     if self.isBase(glyphName):
         # right align
         matrix = psMat.translate(deltaWidth)
         # print "base " + glyphName + " translate by " + str(deltaWidth)
     else :
         if self.isMark(glyphName):
             # left align
             matrix = psMat.identity()
         else:
             # centre
             matrix = psMat.translate(.5 * deltaWidth)
     glyph.transform(matrix)
     glyph.width = modifiedWidth
Пример #11
0
def referenceTransform(ref, glyph, deg):
    thatglyphname = ref[0]
    thisglyphname = glyph.glyphname
    r = ref[1]

    columnA = "%s's reference to %s:" % (thisglyphname, thatglyphname)
    columnB = str(r)

    ri = psMat.inverse(r)

    result = psMat.identity()
    result = psMat.compose(result, italicShiftRight(deg))
    result = psMat.compose(result, italicUnskew(deg))
    result = psMat.compose(result, r)
    result = psMat.compose(result, italicSkew(deg))
    result = psMat.compose(result, italicShiftLeft(deg))

    return (ref[0], result)
Пример #12
0
for e in etree.getroot().iterfind("glyphs/glyph"):
    g = Glyph(e.get("PSName"), e.get("UID"))
    g.readXml(e)
    glyphs.append(g)
    # identify output Glyph for each referenced glyph
    g.resolveGlyph()

for g in glyphs:
    g.resolveGlyph(True)
count = 0
for f in fonts:
    for k, v in f.temporary['names'].items():
        if not v:
            v = Glyph(f"_temp{count!s}", "")
            v.glyph = f[k]
            v.scale = psMat.identity()
            glyphs.append(v)
            f.temporary['names'][k] = v
            count += 1
# analyse anchors to find relations
        analyseAnchorRelations(point_relations, v)

# fill in anchors for each glyph

# do attachment, concrete glyph resolution and absolute positioning
for g in glyphs:
    g.resolveReferences(point_relations)

if opts.append:
    f = fonts[0]
else:
Пример #13
0
        'tehtaS.swashhyarmenalt': 'tehtaS.swashhyarmenalt',
        'tehtaGrave_tehtaGrave.shift1': 'tehtaGrave_tehtaGrave.shift1',
        'tehtaGrave_tehtaGrave.shift2': 'tehtaGrave_tehtaGrave.shift2',
        'tehtaGrave_tehtaGrave.shift3': 'tehtaGrave_tehtaGrave.shift3',
        'tehtaGrave_tehtaGrave.shift4': 'tehtaGrave_tehtaGrave.shift4',
        'tehtaYB.lambe': 'tehtaYB.lambe',
        'tehtaIB.lambe': 'tehtaIB.lambe',
        'tengwarExclamationB': 'tengwarExclamationB',
    }
}

## Apart from all the glyphs above, we also define some new ones by referencing other glyphs:
## Format: (new glyph, original glyph, transformation, width)
## The function that deals with this list later on sets a width < 0 to the width of the original glyph.
references = [
    ('tehtaA', 'tehtaA.shift2', psMat.identity(), 0),
    ('tehtaAB', 'tehtaAB.shift2', psMat.identity(), 0),
    ('tehtaY', 'tehtaY.shift2', psMat.identity(), 0),
    ('tehtaYB', 'tehtaYB.shift2', psMat.identity(), 0),
    ('tehtaI', 'tehtaI.shift2', psMat.identity(), 0),
    ('tehtaIB', 'tehtaIB.shift2', psMat.identity(), 0),
    ('tehtaE', 'tehtaE.shift2', psMat.identity(), 0),
    ('tehtaEB', 'tehtaEB.shift2', psMat.identity(), 0),
    ('tehtaEEB', 'tehtaEEB.shift2', psMat.identity(), 0),
    ('tehtaO', 'tehtaO.shift2', psMat.identity(), 0),
    ('tehtaOB', 'tehtaOB.shift2', psMat.identity(), 0),
    ('tehtaU', 'tehtaU.shift2', psMat.identity(), 0),
    ('tehtaUB', 'tehtaUB.shift2', psMat.identity(), 0),
    ('tehtaN', 'tehtaN.narrow', psMat.identity(), 0),
    ('tehtaB', 'tehtaB.narrow', psMat.identity(), 0),
    ('tehtaW', 'tehtaW.shift2', psMat.identity(), 0),