Skip to content

Commit

Permalink
remove .char_width()
Browse files Browse the repository at this point in the history
  • Loading branch information
RedShy committed Sep 7, 2022
1 parent 7a2d102 commit bdd5172
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
5 changes: 5 additions & 0 deletions fpdf/fpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1895,6 +1895,11 @@ def add_font(self, family, style="", fname=None, uni="DEPRECATED"):

# take width associated to glyph
w = font["hmtx"].metrics[glyph][0]

# probably this check could be deleted
if w == 65535:
w = 0

char_widths[char] = round(scale * w + 0.001) # ROUND_HALF_UP

# include numbers in the subset! (if alias present)
Expand Down
13 changes: 2 additions & 11 deletions fpdf/line_break.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,12 @@ def get_width(
precedence over the start/end arguments.
"""

def char_width(char):
try:
width = self.font["cw"][char]
except (IndexError, KeyError):
width = self.font.get("desc", {}).get("MissingWidth") or 500
if width == 65535:
return 0
return width

if chars is None:
chars = self.characters[start:end]
if self.is_ttf_font:
w = sum(char_width(ord(c)) for c in chars)
w = sum(self.font["cw"][ord(c)] for c in chars)
else:
w = sum(char_width(c) for c in chars)
w = sum(self.font["cw"][c] for c in chars)
char_spacing = self.char_spacing
if self.font_stretching != 100:
w *= self.font_stretching * 0.01
Expand Down

0 comments on commit bdd5172

Please sign in to comment.