Ejemplo n.º 1
0
def test_max_ctx_calc_features_ttx(file_name, max_context):
    ttx_path = os.path.join(os.path.dirname(__file__),
                            'data', '{}.ttx'.format(file_name))
    font = TTFont()
    font.importXML(ttx_path)

    assert maxCtxFont(font) == max_context
Ejemplo n.º 2
0
def main():
    font = TTFont(sys.argv[1])

    name = font["name"]
    head = font["head"]
    OS_2 = font["OS/2"]
    family = name.getName(1, 3, 1)
    if str(family).endswith(" Italic"):
        family.string = str(family).replace(" Italic", "")
        name.setName("Italic", 2, family.platformID, family.platEncID,
                     family.langID)

        # Set italic bits
        head.macStyle |= 1 << 1
        OS_2.fsSelection |= 1 << 0

        # Clear regular bit
        OS_2.fsSelection &= ~(1 << 6)

    # Force ppem to integer values, since the fonts are hinted.
    head.flags |= 1 << 3

    OS_2.usMaxContext = maxCtxFont(font)

    font["DSIG"] = DSIG = newTable("DSIG")
    DSIG.ulVersion = 1
    DSIG.usFlag = 0
    DSIG.usNumSigs = 0
    DSIG.signatureRecords = []

    font.save(sys.argv[1])
Ejemplo n.º 3
0
def test_max_ctx_calc_features_ttx(file_name, max_context):
    ttx_path = os.path.join(os.path.dirname(__file__), 'data',
                            '{}.ttx'.format(file_name))
    font = TTFont()
    font.importXML(ttx_path)

    assert maxCtxFont(font) == max_context
Ejemplo n.º 4
0
def main():
    font = TTFont(sys.argv[1])

    # Drop VOLT table
    if "TSIV" in font:
        del font["TSIV"]

    # Add STAT table
    os2 = font["OS/2"]
    italic = bool(os2.fsSelection & (1 << 0))

    fvar = font["fvar"]
    axes = [dict(tag=a.axisTag, name=a.axisNameID) for a in fvar.axes]

    if italic:
        value = dict(value=italic, name="Italic")
    else:
        value = dict(value=italic, name="Roman", flags=0x0002, linkedValue=1)
    axes.append(dict(tag="ital", name="Italic", values=[value]))

    buildStatTable(font, axes)

    # Prune name table
    names = [n for n in font["name"].names if n.platformID == 3]

    # Drop Regular from Roman font names
    if not italic:
        for name in names:
            if name.nameID in (3, 6):
                name.string = str(name).replace("-Regular", "")
            if name.nameID == 4:
                name.string = str(name).replace(" Regular", "")

    font["name"].names = names
    font["OS/2"].usMaxContext = maxCtxFont(font)

    font["DSIG"] = DSIG = newTable("DSIG")
    DSIG.ulVersion = 1
    DSIG.usFlag = 0
    DSIG.usNumSigs = 0
    DSIG.signatureRecords = []

    if "glyf" in font and "prep" not in font:
        # Google Fonts “smart dropout control”
        font["prep"] = prep = newTable("prep")
        prep.program = ttProgram.Program()
        prep.program.fromAssembly(
            ["PUSHW[]", "511", "SCANCTRL[]", "PUSHB[]", "4", "SCANTYPE[]"]
        )

    if "MVAR" in font:
        del font["MVAR"]

    font.save(sys.argv[1])
Ejemplo n.º 5
0
    def _postprocess(self, otf, otl, fmt):
        if otl is not None:
            otl.setGlyphOrder(otf.getGlyphOrder())
            for tag in self.ttf.get("tables", []):
                logger.info(f"Copying {tag} table to {self.name}.{fmt.value}")
                otf[tag] = deepcopy(otl[tag])
            otf["OS/2"].usMaxContext = maxCtxFont(otf)

        if self.names:
            logger.info(f"Adding name entries to {self.name}.{fmt.value}")
            self._setnames(otf, self.names)

        return otf
Ejemplo n.º 6
0
def test_max_ctx_calc_features():
    glyphs = '.notdef space A B C a b c'.split()
    features = """
    lookup GSUB_EXT useExtension {
        sub a by b;
    } GSUB_EXT;

    lookup GPOS_EXT useExtension {
        pos a b -10;
    } GPOS_EXT;

    feature sub1 {
        sub A by a;
        sub A B by b;
        sub A B C by c;
        sub [A B] C by c;
        sub [A B] C [A B] by c;
        sub A by A B;
        sub A' C by A B;
        sub a' by b;
        sub a' b by c;
        sub a from [A B C];
        rsub a by b;
        rsub a' by b;
        rsub a b' by c;
        rsub a b' c by A;
        rsub [a b] c' by A;
        rsub [a b] c' [a b] by B;
        lookup GSUB_EXT;
    } sub1;

    feature pos1 {
        pos A 20;
        pos A B -50;
        pos A B' 10 C;
        lookup GPOS_EXT;
    } pos1;
    """
    font = TTFont()
    font.setGlyphOrder(glyphs)
    addOpenTypeFeaturesFromString(font, features)

    assert maxCtxFont(font) == 3
Ejemplo n.º 7
0
def test_max_ctx_calc_features():
    glyphs = '.notdef space A B C a b c'.split()
    features = """
    lookup GSUB_EXT useExtension {
        sub a by b;
    } GSUB_EXT;

    lookup GPOS_EXT useExtension {
        pos a b -10;
    } GPOS_EXT;

    feature sub1 {
        sub A by a;
        sub A B by b;
        sub A B C by c;
        sub [A B] C by c;
        sub [A B] C [A B] by c;
        sub A by A B;
        sub A' C by A B;
        sub a' by b;
        sub a' b by c;
        sub a from [A B C];
        rsub a by b;
        rsub a' by b;
        rsub a b' by c;
        rsub a b' c by A;
        rsub [a b] c' by A;
        rsub [a b] c' [a b] by B;
        lookup GSUB_EXT;
    } sub1;

    feature pos1 {
        pos A 20;
        pos A B -50;
        pos A B' 10 C;
        lookup GPOS_EXT;
    } pos1;
    """
    font = TTFont()
    font.setGlyphOrder(glyphs)
    addOpenTypeFeaturesFromString(font, features)

    assert maxCtxFont(font) == 3
Ejemplo n.º 8
0
    def _postprocess(self, otf, otl, fmt):
        if otl is not None:
            otl.setGlyphOrder(otf.getGlyphOrder())
            for tag in self.ttf.get("tables", []):
                logger.info(f"Copying {tag} table to {self.name}.{fmt.value}")
                otf[tag] = deepcopy(otl[tag])
            otf["OS/2"].usMaxContext = maxCtxFont(otf)

        if self.names:
            logger.info(f"Adding name entries to {self.name}.{fmt.value}")
            self._setnames(otf, self.names)

        if self.DSIG:
            otf["DSIG"] = DSIG = newTable("DSIG")
            DSIG.ulVersion = 1
            DSIG.usFlag = 0
            DSIG.usNumSigs = 0
            DSIG.signatureRecords = []

        return otf
Ejemplo n.º 9
0
def test_max_ctx_calc_no_features():
    font = TTFont()
    assert maxCtxFont(font) == 0
    font.setGlyphOrder(['.notdef'])
    addOpenTypeFeaturesFromString(font, '')
    assert maxCtxFont(font) == 0
Ejemplo n.º 10
0
def test_max_ctx_calc_no_features():
    font = TTFont()
    assert maxCtxFont(font) == 0
    font.setGlyphOrder(['.notdef'])
    addOpenTypeFeaturesFromString(font, '')
    assert maxCtxFont(font) == 0