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?
When I attempted to convert SVGs that use a
.ttcfont, I get theUnable to find a suitable font for 'font-family:...error.Here's a sample SVG:
The font file is
圓體W3寬注音.ttc. Here's a simplified example of what I run:I traced the issue to
svglib/svglib/svglib.py
Line 87 in 4ad421b
.ttffiles and not also.ttcfiles. 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.ttffiles with ReportLab and then, if not found, to attempt.ttcfiles?