mirror of
https://github.com/ryanoasis/nerd-fonts.git
synced 2024-09-12 09:41:47 +02:00
font-patcher: Store combined BB in ScaleGlyph
[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. But the data is stored nowhere. [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>
This commit is contained in:
parent
cd026579c5
commit
e4780ad65d
1 changed files with 17 additions and 7 deletions
24
font-patcher
24
font-patcher
|
@ -1017,9 +1017,9 @@ class font_patcher:
|
|||
# to fit in both the x and y directions
|
||||
if sym_attr['stretch'] == 'pa':
|
||||
scale_ratio_x = False
|
||||
if scaleGlyph:
|
||||
if scale_glyph_data:
|
||||
# We want to preserve the relative size of each glyph in a glyph group
|
||||
scale_ratio_x = scale_glyph_data
|
||||
scale_ratio_x = scale_glyph_data[0]
|
||||
if scale_ratio_x is False:
|
||||
# In the remaining cases, each glyph is sized independently to each other
|
||||
scale_ratio_x = self.get_scale_factor(sym_dim)
|
||||
|
@ -1158,12 +1158,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
|
||||
|
@ -1184,12 +1188,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 ], destGlyph)
|
||||
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, symbol_unicode, scaleGlyph, symbolFont, dest_unicode):
|
||||
""" Determines whether or not to use scaled glyphs for glyphs in passed glyph_list """
|
||||
|
@ -1198,9 +1208,9 @@ class font_patcher:
|
|||
if not dest_unicode in self.sourceFont:
|
||||
self.sourceFont.createChar(dest_unicode)
|
||||
self.prepareScaleGlyph(scaleGlyph, symbolFont, self.sourceFont[dest_unicode])
|
||||
for glyph_list, scale in zip(scaleGlyph['GlyphsToScale'], scaleGlyph['scales']):
|
||||
for glyph_list, scale, box in zip(scaleGlyph['GlyphsToScale'], scaleGlyph['scales'], scaleGlyph['bbdims']):
|
||||
if symbol_unicode in glyph_list:
|
||||
return scale
|
||||
return (scale, box)
|
||||
return False
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue