font-patcher: Allow ScaleGroups and ScaleGlyph in one ScaleRules

[why]
If a ScaleGlyph is defined that ScaleRules will just be that one rule,
even if in parallel the user specified some ScaleGroups.

So it is either ScaleGroups or ScaleGlyph but not both.
If someone specifies both there is no warning or check.

[how]
Just allow both. Rewrite the ScaleGlyph to an additional (last) entry in
the ScaleGroups.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2023-01-04 16:06:54 +01:00
parent 122672b56b
commit 69ccea2ff5

View file

@ -1226,6 +1226,17 @@ class font_patcher:
if 'scales' in scaleRules: if 'scales' in scaleRules:
# Already prepared... must not happen, ignore call # Already prepared... must not happen, ignore call
return return
scaleRules['scales'] = []
scaleRules['bbdims'] = []
if 'ScaleGroups' not in scaleRules:
scaleRules['ScaleGroups'] = []
for group in scaleRules['ScaleGroups']:
sym_dim = get_multiglyph_boundingBox([ symbolFont[g] if g in symbolFont else None for g in group ], destGlyph)
scale = self.get_scale_factor(sym_dim)
scaleRules['scales'].append(scale)
scaleRules['bbdims'].append(sym_dim)
if 'ScaleGlyph' in scaleRules: if 'ScaleGlyph' in scaleRules:
# old method. Rewrite to new. # old method. Rewrite to new.
flat_list = [] flat_list = []
@ -1234,20 +1245,11 @@ class font_patcher:
flat_list += list(range(i[0], i[1] + 1)) flat_list += list(range(i[0], i[1] + 1))
else: else:
flat_list.append(i) flat_list.append(i)
scaleRules['ScaleGroups'] = [ flat_list ]
sym_dim = get_glyph_dimensions(symbolFont[scaleRules['ScaleGlyph']]) sym_dim = get_glyph_dimensions(symbolFont[scaleRules['ScaleGlyph']])
scale = self.get_scale_factor(sym_dim) scale = self.get_scale_factor(sym_dim)
scaleRules['scales'] = [ scale ] scaleRules['ScaleGroups'].append(flat_list)
# The 'old' style keeps just the scale, not the positioning scaleRules['scales'].append(scale)
scaleRules['bbdims'] = [ None ] scaleRules['bbdims'].append(None) # The 'old' style keeps just the scale, not the positioning
else:
scaleRules['scales'] = []
scaleRules['bbdims'] = []
for group in scaleRules['ScaleGroups']:
sym_dim = get_multiglyph_boundingBox([ symbolFont[g] if g in symbolFont else None for g in group ], destGlyph)
scale = self.get_scale_factor(sym_dim)
scaleRules['scales'].append(scale)
scaleRules['bbdims'].append(sym_dim)
def get_glyph_scale(self, symbol_unicode, scaleRules, symbolFont, dest_unicode): def get_glyph_scale(self, symbol_unicode, scaleRules, symbolFont, dest_unicode):
""" Determines whether or not to use scaled glyphs for glyph in passed symbol_unicode """ """ Determines whether or not to use scaled glyphs for glyph in passed symbol_unicode """