<commit_before>"""Create an emoji font from a set of SVGs.

UFO handling informed by Cosimo's
https://gist.github.com/anthrotype/2acbc67c75d6fa5833789ec01366a517

For COLR:
    Each SVG file represent one base glyph in the COLR font.
    For each glyph, we get the list of layers associated with it.
    For each layer we have a tuple (Paint, SVGPath).
    To convert to font format we  use the UFO Glyph pen.

Sample usage:
make_emoji_font.py -v 1 $(find ~/oss/noto-emoji/svg -name '*.svg')
make_emoji_font.py $(find ~/oss/twemoji/assets/svg -name '*.svg')
"""
from absl import app
from absl import flags
from absl import logging
import collections
from color_glyph import ColorGlyph
from fontTools import ttLib
from fontTools.pens.transformPen import TransformPen
from itertools import chain
from nanosvg.svg import SVG
from nanosvg.svg_pathops import skia_path
import os
import regex
import sys

import ufoLib2
import ufo2ft


# A color font generator.
#   apply_ufo(ufo, color_glyphs) is called first, to update a generated UFO
#   apply_ttfont(ufo, color_glyphs, ttfont) is called second, to allow fixups after ufo2ft
# Ideally we delete the ttfont stp in future. Blocking issues:
#   https://sites.google.com/corp/google.com/novelcoronavirus/travel
# If the output file is .ufo then apply_ttfont is not called.
# Where possible code to the ufo and let apply_ttfont be a nop.
ColorGenerator = collections.namedtuple('ColorGenerator', ['apply_ufo', 'apply_ttfont'])

_COLOR_FORMAT_GENERATORS = {
    'colr_0': ColorGenerator(lambda *args: _colr_v0_ufo(*args),
                             lambda *_: None),
    'colr_1': ColorGenerator(lambda *args: _not_impl('ufo', *args),
                             lambda *args: _not_impl('TTFont', *args)),
    'svg': ColorGenerator(lambda *_: None,
                          lambda *args: _svg_ttfont(*args)),
    'cbdt': ColorGenerator(lambda *args: _not_impl('ufo', *args),
                           lambda *args: _not_impl('TTFont', *args)),
    'sbix': ColorGenerator(lambda *args: _not_impl('ufo', *args),
                           lambda *args: _not_impl('TTFont', *args)),
}
<commit_msg>fix bad link<commit_after>"""Create an emoji font from a set of SVGs.

UFO handling informed by Cosimo's
https://gist.github.com/anthrotype/2acbc67c75d6fa5833789ec01366a517

For COLR:
    Each SVG file represent one base glyph in the COLR font.
    For each glyph, we get the list of layers associated with it.
    For each layer we have a tuple (Paint, SVGPath).
    To convert to font format we  use the UFO Glyph pen.

Sample usage:
make_emoji_font.py -v 1 $(find ~/oss/noto-emoji/svg -name '*.svg')
make_emoji_font.py $(find ~/oss/twemoji/assets/svg -name '*.svg')
"""
from absl import app
from absl import flags
from absl import logging
import collections
from color_glyph import ColorGlyph
from fontTools import ttLib
from fontTools.pens.transformPen import TransformPen
from itertools import chain
from nanosvg.svg import SVG
from nanosvg.svg_pathops import skia_path
import os
import regex
import sys

import ufoLib2
import ufo2ft


# A color font generator.
#   apply_ufo(ufo, color_glyphs) is called first, to update a generated UFO
#   apply_ttfont(ufo, color_glyphs, ttfont) is called second, to allow fixups after ufo2ft
# Ideally we delete the ttfont stp in future. Blocking issues:
#   https://github.com/unified-font-object/ufo-spec/issues/104
# If the output file is .ufo then apply_ttfont is not called.
# Where possible code to the ufo and let apply_ttfont be a nop.
ColorGenerator = collections.namedtuple('ColorGenerator', ['apply_ufo', 'apply_ttfont'])

_COLOR_FORMAT_GENERATORS = {
    'colr_0': ColorGenerator(lambda *args: _colr_v0_ufo(*args),
                             lambda *_: None),
    'colr_1': ColorGenerator(lambda *args: _not_impl('ufo', *args),
                             lambda *args: _not_impl('TTFont', *args)),
    'svg': ColorGenerator(lambda *_: None,
                          lambda *args: _svg_ttfont(*args)),
    'cbdt': ColorGenerator(lambda *args: _not_impl('ufo', *args),
                           lambda *args: _not_impl('TTFont', *args)),
    'sbix': ColorGenerator(lambda *args: _not_impl('ufo', *args),
                           lambda *args: _not_impl('TTFont', *args)),
}

{'fraction_non_alphanumeric': 0.09707602339181287, 'fraction_numerical': 0.013801169590643274, 'mean_word_length': 3.5105485232067513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5242605', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1358, 'n_words': 452}