Exemple #1
0
def _glyphmappings(svg_files: Sequence[str]) -> Tuple[GlyphMapping]:
    return tuple(
        GlyphMapping(Path(svg_file), cps, glyph_name(cps))
        for svg_file, cps in zip(
            svg_files, tuple(codepoints.from_filename(Path(f).name) for f in svg_files)
        )
    )
Exemple #2
0
def _ensure_codepoints_will_have_glyphs(ufo, glyph_inputs):
    """Ensure all codepoints we use will have a glyph.

    Single codepoint sequences will directly mapped to their glyphs.
    We need to add a glyph for any codepoint that is only used in a multi-codepoint sequence.

    """
    all_codepoints = set()
    direct_mapped_codepoints = set()
    for glyph_input in glyph_inputs:
        if not glyph_input.codepoints:
            continue
        if len(glyph_input.codepoints) == 1:
            direct_mapped_codepoints.update(glyph_input.codepoints)
        all_codepoints.update(glyph_input.codepoints)

    need_blanks = all_codepoints - direct_mapped_codepoints
    logging.debug("%d codepoints require blanks", len(need_blanks))
    glyph_names = []
    for codepoint in need_blanks:
        # Any layer is fine; we aren't going to draw
        glyph = ufo.newGlyph(glyph_name(codepoint))
        glyph.unicode = codepoint
        glyph_names.append(glyph.name)

    ufo.glyphOrder = ufo.glyphOrder + sorted(glyph_names)
Exemple #3
0
def color_font_config(config_overrides, svgs, tmp_dir=None):
    if tmp_dir is None:
        tmp_dir = tempfile.gettempdir()
    svgs = tuple(locate_test_file(s) for s in svgs)
    fea_file = os.path.join(tmp_dir, "test.fea")
    rgi_seqs = tuple(codepoints.from_filename(str(f)) for f in svgs)
    with open(fea_file, "w") as f:
        f.write(features.generate_fea(rgi_seqs))

    return (
        config.load(config_file=None, additional_srcs=svgs)
        ._replace(
            family="UnitTest",
            upem=100,
            ascender=100,
            descender=0,
            width=100,
            keep_glyph_names=True,
            fea_file=fea_file,
        )
        ._replace(**config_overrides),
        [
            write_font.InputGlyph(
                os.path.relpath(svg),
                (0xE000 + idx,),
                glyph_name((0xE000 + idx,)),
                picosvg(svg),
            )
            for idx, svg in enumerate(svgs)
        ],
    )
Exemple #4
0
def _generate_fea(rgi_sequences):
    rules = []
    rules.append("languagesystem DFLT dflt;")
    rules.append("languagesystem latn dflt;")
    rules.append("")

    rules.append("feature rlig {")
    for rgi in sorted(rgi_sequences):
        if len(rgi) == 1:
            continue
        glyphs = [glyph_name(cp) for cp in rgi]
        target = glyph_name(rgi)
        rules.append("  sub %s by %s;" % (" ".join(glyphs), target))

    rules.append("} rlig;")
    rules.append("")
    return "\n".join(rules)
Exemple #5
0
def generate_fea(rgi_sequences, feature_tag=DEFAULT_GSUB_FEATURE_TAG):
    # Generate feature with ligature lookup for multi-codepoint RGIs
    rules = []
    rules.append("languagesystem DFLT dflt;")
    rules.append("languagesystem latn dflt;")
    rules.append("")

    rules.append(f"feature {feature_tag} {{")
    for rgi in sorted(rgi_sequences):
        if len(rgi) == 1:
            continue
        glyphs = [glyph_name(cp) for cp in rgi]
        target = glyph_name(rgi)
        rules.append("  sub %s by %s;" % (" ".join(glyphs), target))

    rules.append(f"}} {feature_tag};")
    rules.append("")
    return "\n".join(rules)
Exemple #6
0
    def create(ufo, filename, glyph_id, codepoints, picosvg):
        logging.debug(" ColorGlyph for %s (%s)", filename, codepoints)
        glyph_name = glyph.glyph_name(codepoints)
        base_glyph = ufo.newGlyph(glyph_name)
        base_glyph.width = ufo.info.unitsPerEm

        # Setup direct access to the glyph if possible
        if len(codepoints) == 1:
            base_glyph.unicode = next(iter(codepoints))

        # Grab the transform + (color, glyph) layers for COLR
        return ColorGlyph(ufo, filename, glyph_name, glyph_id, codepoints,
                          picosvg)
Exemple #7
0
def _generate_fea(rgi_sequences):
    # TODO if this is a qualified sequence create the unqualified version and vice versa
    rules = []
    rules.append("languagesystem DFLT dflt;")
    rules.append("languagesystem latn dflt;")

    rules.append("feature rlig {")
    for rgi, target in sorted(rgi_sequences):
        if len(rgi) == 1:
            continue
        glyphs = [glyph_name(cp) for cp in rgi]
        rules.append("  sub %s by %s;" % (" ".join(glyphs), target))

    rules.append("} rlig;")
    return "\n".join(rules)