Skip to content

Errors when attempting to load TrueType Collection fonts #226

Description

@rocketnova

When I attempted to convert SVGs that use a .ttc font, I get the Unable to find a suitable font for 'font-family:... error.

Here's a sample SVG:

<svg viewBox="0 0 400 100" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg">
  <text fill="black" font-family="圓體W3寬注音" font-size="80px" x="200" y="70" text-anchor="middle">上個月</text>
</svg>

The font file is 圓體W3寬注音.ttc. Here's a simplified example of what I run:

>>> from svglib.svglib import svg2rlg
>>> drawing = svg2rlg("svgs/上個月.svg")
Unable to find a suitable font for 'font-family:圓體W3寬注音'

I traced the issue to

registerFont(TTFont(font_name, '%s.ttf' % font_name))
which only searches for .ttf files and not also .ttc files. TrueType Collections are described on Wikipedia as an extension of the TrueType format.

This might be related to or explain the issue seen in #107. When I change the code on line 87, I was able to successfully register the font with ReportLab through svg2rlg. Perhaps it would be possible to attempt to register/find .ttf files with ReportLab and then, if not found, to attempt .ttc files?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions