Skip to content

Commit

Permalink
packager: add stroke and classifications fields (#723)
Browse files Browse the repository at this point in the history
* packager: add stroke and classifications fields

* Change MONOTYPE to MONOSPACE and other small edits

---------

Co-authored-by: Eli Heuer <elih@protonmail.com>
  • Loading branch information
m4rc1e and eliheuer committed Sep 13, 2023
1 parent fdb4c8b commit ca7ae7b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Lib/gftools/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@

CATEGORIES = ['DISPLAY', 'SERIF', 'SANS_SERIF', 'HANDWRITING', 'MONOSPACE']

CLASSIFICATIONS = ['DISPLAY', 'HANDWRITING', 'MONOSPACE', 'SYMBOLS']

from pkg_resources import resource_filename
with open(resource_filename('gftools', 'template.upstream.yaml')) as f:
upstream_yaml_template = f.read()
Expand Down Expand Up @@ -208,6 +210,8 @@ def _shallow_clone_git(target_dir, git_url, branch_or_tag='main'):
'repository_url': Str(), # TODO: custom validation please
'branch': Str(),
Optional('archive', default=''): EmptyNone() | Str(),
Optional('classifications', default=None): EmptyNone() | UniqueSeq(Enum(CLASSIFICATIONS)),
Optional('stroke', default=None): EmptyNone() | Str(),
'category': UniqueSeq(Enum(CATEGORIES)),
'designer': Str(),
Optional('build', default=''): EmptyNone() | Str(),
Expand All @@ -228,6 +232,8 @@ def _shallow_clone_git(target_dir, git_url, branch_or_tag='main'):
'branch': EmptyNone() | Str(),
Optional('archive', default=''): EmptyNone() | Str(),
Optional('category', default=None): EmptyNone() | UniqueSeq(Enum(CATEGORIES)),
Optional('classifications', default=None): EmptyNone() | UniqueSeq(Enum(CLASSIFICATIONS)),
Optional('stroke', default=None): EmptyNone() | Str(),
Optional('designer', default=''): EmptyNone() |Str(),
Optional('build', default=''): EmptyNone() | Str(),
'files': EmptyDict() | MapPattern(Str(), Str())
Expand All @@ -237,6 +243,8 @@ def _shallow_clone_git(target_dir, git_url, branch_or_tag='main'):
# Only optional until it can be in METADATA.pb
Optional('repository_url', default=''): Str(),
'branch': EmptyNone() | Str(),
Optional('classifications', default=None): EmptyNone() | UniqueSeq(Enum(CLASSIFICATIONS)),
Optional('stroke', default=None): EmptyNone() | Str(),
Optional('archive', default=''): EmptyNone() | Str(),
Optional('build', default=''): EmptyNone() | Str(),
'files': EmptyDict() | MapPattern(Str(), Str())
Expand Down Expand Up @@ -619,7 +627,9 @@ def _upstream_conf_from_yaml_metadata(
upstream_conf.update({
'designer': metadata.designer or None,
'category': list(metadata.category) or None,
'name': metadata.name or None,
'classifications': list(metadata.classifications) or None,
'stroke': metadata.stroke or None,
'name': metadata.name or None,
# we won't get this just now in most cases!
'repository_url': metadata.source.repository_url or None,
})
Expand Down Expand Up @@ -895,6 +905,12 @@ def _create_or_update_metadata_pb(upstream_conf: YAML,

metadata.category[:] = upstream_conf['category']

if "classifications" in upstream_conf and upstream_conf['classifications']:
metadata.classifications[:] = upstream_conf["classifications"]

if "stroke" in upstream_conf and upstream_conf["stroke"]:
metadata.stroke = upstream_conf["stroke"]

# metadata.date_added # is handled well

metadata.source.repository_url = upstream_conf['repository_url']
Expand Down Expand Up @@ -1036,7 +1052,7 @@ def _create_package_content(package_target_dir: str, repos_dir: str,
# create/update upstream.yaml
# Remove keys that are also in METADATA.pb googlefonts/gftools#233
# and also clear all comments.
redundant_keys = {'name', 'category', 'designer', 'repository_url'}
redundant_keys = {'name', 'category', 'designer', 'repository_url', 'stroke', 'classifications'}
upstream_conf_stripped = OrderedDict((k, v) for k, v in upstream_conf.items() \
if k not in redundant_keys)
# Don't keep an empty build key.
Expand Down
4 changes: 4 additions & 0 deletions Lib/gftools/scripts/add_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ def _MakeMetadata(args, is_new):
subsets = set(old_metadata.subsets) | set(subsets_in_font)
metadata.languages[:] = old_metadata.languages
metadata.fallbacks.extend(old_metadata.fallbacks)
if old_metadata.classifications:
metadata.classifications[:] = old_metadata.classifications
if old_metadata.stroke:
metadata.stroke = old_metadata.stroke
if old_metadata.is_noto:
metadata.is_noto = True
if old_metadata.display_name:
Expand Down
17 changes: 17 additions & 0 deletions Lib/gftools/template.upstream.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ category:
# - MONOSPACE
# - HANDWRITING

# A family's broad classifications: display, handwriting, monospace, and
# symbols (not text). Use multiple classifications if appropriate.
# The values are in all uppercase:
classifications:
# - DISPLAY
# - HANDWRITING
# - MONOSPACE
# - SYMBOLS

# Stroke of the letter forms: serif, sans serif, or slab serif. A family
# has a single stroke and may have none at all. The values are strings that
# in all uppercase with spaces replaced by underscores:
stroke:
# SERIF
# SANS_SERIF
# SLAB_SERIF

# Full name of the type designer(s) or foundry who designed the fonts.
designer:

Expand Down

0 comments on commit ca7ae7b

Please sign in to comment.