Skip to content

Commit

Permalink
font-patcher: Store combined BB in ScaleGlyph
Browse files Browse the repository at this point in the history
[why]
If we use a ScaleGlyph range (i.e. use the same scaling on a range of
glyphs; the scaling is determined by the combined bounding box of all
that glyphs), we probably want to shift the glyphs identically as well
to preserve relative positions not only sizes of the glyphs within the
range.

This will be used in a following commit.

[how]
Store the 'virtual' bounding box along with the scale.

[note]
With combined (virtual) bounding box we mean the bounding box that a
glyph would have where all the individual glyphs would be stamped over
each other without shifting scaling beforehand.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
  • Loading branch information
Finii committed Sep 7, 2022
1 parent ce78ccb commit 112c7bd
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions font-patcher
Original file line number Diff line number Diff line change
Expand Up @@ -1176,12 +1176,16 @@ class font_patcher:
# The GlyphData is a dict with these (possible) entries:
# 'GlyphsToScale': List of ((lists of glyph codes) or (ranges of glyph codes)) that shall be scaled
# 'scales': List of associated scale factors, one for each entry in 'GlyphsToScale' (generated by this function)
# 'bbdims': List of associated sym_dim dicts, one for each entry in 'GlyphsToScale' (generated by this function)
# Each sym_dim dict describes the combined bounding box of all glyphs in GlyphsToScale
# Example:
# { 'GlyphsToScale': [ range(1, 3), [ 7, 10 ], ],
# 'scales': [ 1.23, 1.33, ] }
# 'scales': [ 1.23, 1.33, ],
# 'bbdims': [ dim_dict1, dim_dict2, ] }
#
# Each item in 'GlyphsToScale' (a range or an explicit list) forms a group of glyphs that shall be
# as rescaled all with the same and maximum possible (for the included glyphs) factor.
# If the 'bbdims' is present they all shall be shifted in the same way.
#
# Previously this structure has been used:
# 'ScaleGlyph' Lead glyph, which scaling factor is taken
Expand All @@ -1202,12 +1206,18 @@ class font_patcher:
flat_list.append(i)
scaleGlyph['GlyphsToScale'] = [ flat_list ]
sym_dim = get_glyph_dimensions(symbolFont[scaleGlyph['ScaleGlyph']])
scaleGlyph['scales'] = [ self.get_scale_factor(sym_dim) ]
scale = self.get_scale_factor(sym_dim)
scaleGlyph['scales'] = [ scale ]
# The 'old' style keeps just the scale, not the positioning
scaleGlyph['bbdims'] = [ None ]
else:
scaleGlyph['scales'] = []
scaleGlyph['bbdims'] = []
for group in scaleGlyph['GlyphsToScale']:
sym_dim = get_multiglyph_boundingBox([ symbolFont[g] if g in symbolFont else None for g in group ])
scaleGlyph['scales'].append(self.get_scale_factor(sym_dim))
scale = self.get_scale_factor(sym_dim)
scaleGlyph['scales'].append(scale)
scaleGlyph['bbdims'].append(sym_dim)

def get_glyph_scale(self, unicode_value, scaleGlyph, symbolFont):
""" Determines whether or not to use scaled glyphs for glyphs in passed glyph_list """
Expand Down

0 comments on commit 112c7bd

Please sign in to comment.