Skip to content

Commit

Permalink
Modify test to use a test font instead of a commercial font
Browse files Browse the repository at this point in the history
  • Loading branch information
spacegaori committed Jan 27, 2025
1 parent d9a247f commit 1f82b86
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Binary file added test/fonts/Roboto-Regular-without-notdef.ttf
Binary file not shown.
18 changes: 14 additions & 4 deletions test/fonts/test_add_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path

import pytest
from fontTools.ttLib import TTFont

from fpdf import FPDF
from test.conftest import assert_pdf_equal
Expand Down Expand Up @@ -146,12 +147,21 @@ def test_add_font_uppercase():

def test_add_font_missing_notdef_glyph(caplog):
pdf = FPDF()
pdf.add_font(
family="Times New Roman", style="B", fname=HERE / "TimesNewRoman-Bold.ttf"
)

# configure Roboto as a test font missing .notdef glyph
pdf.add_font(fname=HERE / "Roboto-Regular.ttf")
font = TTFont(HERE / "Roboto-Regular.ttf")
glyphnames = font.getGlyphOrder()
glyphnames[0] = "dummy"
font = TTFont(HERE / "Roboto-Regular.ttf")
font.setGlyphOrder(glyphnames)
font["post"]
font.save(HERE / "Roboto-Regular-without-notdef.ttf")

pdf.add_font(family="Roboto", fname=HERE / "Roboto-Regular-without-notdef.ttf")
assert pdf.fonts is not None and len(pdf.fonts) != 0 # fonts add successful
assert (
"TrueType Font 'times new romanB' is missing the '.notdef' glyph. "
"TrueType Font 'roboto' is missing the '.notdef' glyph. "
"Fallback glyph will be provided."
) in caplog.text

Expand Down

0 comments on commit 1f82b86

Please sign in to comment.