Skip to content

Commit

Permalink
font-patcher: Correct overlap
Browse files Browse the repository at this point in the history
[why]
The overlap formula seems to be off sometimes. Although the shift is
correct (and thus the number of 'pixels' that overlap), but the non
overlapping part of the glyph is often not as wide as expected, off by
up to some percent.

[how]
The formula is too simple. It just calculates an additional scale factor
on top of the already existing factor. To get it 'pixel perfect' we need
to calculate first how much the glyph fills the cell - because we want
the overlap to be in 'cell percent' and not 'glyph percent'. That might
be sometimes the same (if the cell is filled completely), but usually it
is not completely full, and that means the overlap will be smaller than
intended.

[note]
To get the current glyph bounding box we pull some lines up in the code
that get the 'dim' variable.

Also use float constants to calculate with float variables.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
  • Loading branch information
Finii committed Jan 12, 2023
1 parent 95f2926 commit b3c079d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions font-patcher
Original file line number Diff line number Diff line change
Expand Up @@ -1116,17 +1116,18 @@ class font_patcher:

overlap = sym_attr['params'].get('overlap')

if scale_ratio_x != 1 or scale_ratio_y != 1:
if scale_ratio_x != 1.0 or scale_ratio_y != 1.0:
if glyph_scale_data is not None and glyph_scale_data[1] is not None:
dim = glyph_scale_data[1]
else:
dim = sym_dim
if overlap:
scale_ratio_x *= 1 + overlap
scale_ratio_y *= 1 + overlap
scale_ratio_x *= 1.0 + (self.font_dim['width'] / (dim['width'] * scale_ratio_x)) * overlap
scale_ratio_y *= 1.0 + (self.font_dim['width'] / (dim['width'] * scale_ratio_y)) * overlap

# Size in x to size in y ratio limit (to prevent over-wide glyphs)
xy_ratio_max = sym_attr['params'].get('xy-ratio')
if (xy_ratio_max):
if glyph_scale_data is not None and glyph_scale_data[1] is not None:
dim = glyph_scale_data[1]
else:
dim = sym_dim
xy_ratio = dim['width'] * scale_ratio_x / (dim['height'] * scale_ratio_y)
if xy_ratio > xy_ratio_max:
scale_ratio_x = scale_ratio_x * xy_ratio_max / xy_ratio
Expand Down

0 comments on commit b3c079d

Please sign in to comment.