Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This can also be enabled programmatically with `warnings.simplefilter('default',
* Chinese translation of the [Tuto 7 - Creating PDF/A Documents](https://py-pdf.github.io/fpdf2/Tutorial-zh.html#-pdfa) tutorial section - _cf._ [issue #267](https://github.com/py-pdf/fpdf2/issues/267) - _cf._ [PR #2138](https://github.com/py-pdf/fpdf2/pull/2138) - thanks to @zheng-guannan577*
* `FPDF.write_html()` makes the `id` of an element, and the `name` of an `<a>`, a named destination, so that `<a href="#...">` links within the document work, like in browsers, instead of raising `FPDFException: Named destination ... was referenced but never set` - thanks to @RavSinghChandan
### Fixed
* `FPDF.output()` no longer fails with `struct.error: unpack requires a buffer of 2 bytes` for a font with Apple bitmap tables, such as the `Geneva.ttf` and `Cochin.ttc` of macOS: their `bdat` and `bloc` tables are now dropped when subsetting, like the `EBDT` and `EBLC` tables they correspond to - thanks to @RavSinghChandan
* the generic font families of CSS Fonts 4, `system-ui`, `ui-sans-serif`, `ui-rounded`, `ui-serif` and `ui-monospace`, are now rendered with the matching core font in SVG text and `FPDF.write_html()`, as in the `og.svg` images of react-window, instead of failing with `KeyError: No suitable font for family='system-ui'` - thanks to @RavSinghChandan
* SVG: a root `<svg>` with `width="auto"` or `height="auto"`, as Figma writes it, for instance in the country flags of the ProtonVPN apps, is now sized as if it had no `width` or `height`, from its `viewBox`, instead of failing with `ValueError: Unable to parse 'auto' as a length` - thanks to @RavSinghChandan
* SVG: `hsl()` and `hsla()` colors are now read, with commas or space-separated, with a hue that may have an angle unit (`deg`, `grad`, `rad`, `turn`) and an alpha, as Mermaid diagrams and many stylesheets write them, instead of failing with `ValueError: unsupported color specification` - thanks to @RavSinghChandan
Expand Down
2 changes: 2 additions & 0 deletions fpdf/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,8 @@ def _add_fonts(
"EBDT", # Embedded Bitmap Data Table
"EBLC", # Embedded Bitmap Location Table
"EBSC", # Embedded Bitmap Scaling Table
"bdat", # Apple's Bitmap Data table, the EBDT of Apple fonts
"bloc", # Apple's Bitmap Location table, the EBLC of Apple fonts
"SVG ", # SVG table
"CPAL", # Color Palette table
"COLR", # Color table
Expand Down
19 changes: 18 additions & 1 deletion test/fonts/test_add_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import pytest

from fpdf import FPDF
from fontTools.ttLib import TTCollection, woff2
from fontTools.ttLib import TTCollection, TTFont, woff2
from fontTools.ttLib.tables.DefaultTable import DefaultTable
from test.conftest import LOREM_IPSUM, assert_pdf_equal, assert_same_file

HERE = Path(__file__).resolve().parent
Expand Down Expand Up @@ -166,6 +167,22 @@ def test_add_font_missing_notdef_glyph(caplog):
) in caplog.text


def test_add_font_with_apple_bitmap_tables(tmp_path):
# Like the Geneva.ttf of macOS, whose 'bloc' table fontTools cannot read:
# bitmap glyphs are not used in a PDF, so they are dropped like EBLC and EBDT
font = TTFont(HERE / "DejaVuSans.ttf")
for tag in ("bloc", "bdat"):
font[tag] = DefaultTable(tag)
font[tag].data = b"\x00\x02\x00\x00\x00\x00\x00\x01" + b"\xff" * 8
font.save(tmp_path / "DejaVuSans-bitmaps.ttf")
pdf = FPDF()
pdf.add_page()
pdf.add_font(family="DejaVu", fname=tmp_path / "DejaVuSans-bitmaps.ttf")
pdf.set_font("DejaVu", size=12)
pdf.cell(text="Hello world")
pdf.output()


def test_font_missing_glyphs(caplog):
pdf = FPDF()
pdf.add_page()
Expand Down
Loading