MCPcopy
hub / github.com/rsms/inter / genCSS

Function genCSS

misc/tools/subset.py:371–411  ·  view source on GitHub ↗
(fontinfo, subsets)

Source from the content-addressed store, hash-verified

369
370
371def genCSS(fontinfo, subsets):
372 outfileTemplate = pjoin(BASEDIR, fontinfo['outfile'])
373
374 css_family = fontinfo.get('css_family', 'Inter')
375 css_style = fontinfo.get('css_style', 'normal')
376 css_weight = fontinfo.get('css_weight', '400')
377 css_extra = fontinfo.get('css_extra', '')
378 if len(css_extra) > 0:
379 css_extra = '\n ' + css_extra
380 css = []
381
382 for subset in list(subsets) + [{ 'name':'extra' }]:
383 outfile = outfileTemplate.format(subset=subset['name'])
384 # Read effective codepoint coverage. This may be greater than requested
385 # in case of OT features. For example, the Latin subset includes some common arrow
386 # glyphs since "->" is a ligature for "→".
387 font = ttLib.TTFont(outfile)
388 unicodes = set(getUnicodeMap(font))
389 if min(unicodes) < 0x30:
390 # the "base" (latin) subset. extend it to include control codepoints
391 controlCodepoints, _ = genUnicodeRange([range(0x0000, 0x001F)])
392 unicodes = unicodes.union(controlCodepoints)
393 _, unicodeRange = genUnicodeRange(genCompactIntRanges(unicodes))
394 css.append(CSS_TEMPLATE.format(
395 comment=subset['name'],
396 filename=basename(outfile),
397 unicode_range=unicodeRange,
398 family=css_family,
399 style=css_style,
400 weight=css_weight,
401 extra=css_extra,
402 ).strip())
403
404 # From the CSS spec on unicode-range descriptor:
405 # "If the Unicode ranges overlap for a set of @font-face rules with the same family
406 # and style descriptor values, the rules are ordered in the reverse order they were
407 # defined; the last rule defined is the first to be checked for a given character."
408 # https://www.w3.org/TR/css-fonts-4/#unicode-range-desc
409 css.reverse()
410
411 return '\n'.join(css)
412
413
414def relpath(path):

Callers 1

mainFunction · 0.85

Calls 4

getUnicodeMapFunction · 0.85
genUnicodeRangeFunction · 0.85
genCompactIntRangesFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…