Esempio n. 1
0
def replace(match, factor):
    pos = Parser(StringIO(match.group(0))).parse_pos_()

    if not any(pos):
        return match.group(0)

    adv, dx, dy, adv_adjust_by, dx_adjust_by, dy_adjust_by = pos

    ret = ""
    if adv is not None:
        adv = otRound(adv * factor)
        ret += f" ADV {adv:g}"
        for at, adjust_by in adv_adjust_by.items():
            at, adjust_by = otRound(at * factor), otRound(adjust_by * factor)
            ret += f" ADJUST_BY {adjust_by} AT {at}"

    if dx is not None:
        dx = otRound(dx * factor)
        ret += f" DX {dx:g}"
        for at, adjust_by in dx_adjust_by.items():
            at, adjust_by = otRound(at * factor), otRound(adjust_by * factor)
            ret += f" ADJUST_BY {adjust_by} AT {at}"

    if dy is not None:
        dy = otRound(dy * factor)
        ret += f" DY {dy:g}"
        for at, adjust_by in dy_adjust_by.items():
            at, adjust_by = otRound(at * factor), otRound(adjust_by * factor)
            ret += f" ADJUST_BY {adjust_by} AT {at}"

    return f"POS{ret} END_POS"
Esempio n. 2
0
def replace(match, transform):
    volt = Parser(StringIO(match.group(0))).parse()
    anchor = volt.statements[0]
    adv, dx, dy, adv_adjust_by, dx_adjust_by, dy_adjust_by = anchor.pos
    if dy:
        dx, dy = transform.transformPoint((dx or 0, dy))

        pos = ""
        if adv is not None:
            pos += " ADV %g" % otRound(adv)
            for at, adjust_by in adv_adjust_by.items():
                pos += f" ADJUST_BY {adjust_by} AT {at}"
        if dx is not None:
            pos += " DX %g" % otRound(dx)
            for at, adjust_by in dx_adjust_by.items():
                pos += f" ADJUST_BY {adjust_by} AT {at}"
        if dy is not None:
            pos += " DY %g" % otRound(dy)
            for at, adjust_by in dy_adjust_by.items():
                pos += f" ADJUST_BY {adjust_by} AT {at}"

        return (f'DEF_ANCHOR "{anchor.name}" '
                f"ON {anchor.gid} "
                f"GLYPH {anchor.glyph_name} "
                f"COMPONENT {anchor.component} "
                f'{anchor.locked and "LOCKED " or ""}'
                f"AT  "
                f"POS{pos} END_POS "
                f"END_ANCHOR")
    return match.group(0)
Esempio n. 3
0
 def parse(self, text):
     if not self.tempdir:
         self.tempdir = tempfile.mkdtemp()
     self.num_tempfiles += 1
     path = os.path.join(self.tempdir, "tmp%d.vtp" % self.num_tempfiles)
     with open(path, "w") as outfile:
         outfile.write(text)
     return Parser(path).parse()
Esempio n. 4
0
    def convert(self):
        doc = Parser(self._file_or_path).parse()
        if self._font is not None:
            self._glyph_order = self._font.getGlyphOrder()

        self.ff = FontFeatures()
        self._collectStatements(doc)
        return self.ff
Esempio n. 5
0
 def parse(self, text):
     return Parser(UnicodeIO(text)).parse()
Esempio n. 6
0
def parse_vtp(vtp_path):
    parser = Parser(vtp_path)
    parser.parse()
Esempio n. 7
0
 def parse(self, text):
     doc = self.parse_(text)
     self.assertEqual('\n'.join(str(s) for s in doc.statements), text)
     return Parser(StringIO(text)).parse()
Esempio n. 8
0
 def parse_(self, text):
     return Parser(StringIO(text)).parse()