Skip to content

Crashes when adding fonts with no Unicode cmap subtable, like Window's symbol.ttf #1396

@jasonfevangsafe

Description

@jasonfevangsafe

When adding C:/windows/fonts/symbol.ttf, fpdf throws as it assumes all fonts have a cmap, but symbol.ttf doesn't. Perhaps there are other fonts without cmap subtables, I'm not sure.

I'm not allowed to attach .ttf files to the issue, also may be legal issues with that? A quick google search brought up this site(lol) with a font exhibiting the same issue

Error details

Traceback (most recent call last):
  File "C:\code\fpdf2_fork\test.py", line 2, in <module>
    FPDF().add_font(
  File "C:\code\fpdf2_fork\fpdf\fpdf.py", line 2144, in add_font
    self.fonts[fontkey] = TTFFont(self, font_file_path, fontkey, style)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\code\fpdf2_fork\fpdf\fonts.py", line 363, in __init__
    for char in self.cmap:
TypeError: 'NoneType' object is not iterable

Minimal code
Please include some minimal Python code reproducing your issue:

from fpdf import FPDF
FPDF().add_font(
    family="symbol_notcore",
    fname="C:/Windows/fonts/symbol.ttf",
)

Environment
Please provide the following information:

  • Operating System: Windows
  • Python version: 3.12.2
    • fpdf2 version used: 2.8.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions