[reportlab-users] Built-in versus embedded fonts
v+python at g.nevcal.com
Wed Jun 24 15:05:39 EDT 2015
On 6/24/2015 3:14 AM, Robin Becker wrote:
> If I add these lines immediately prior to the final for loop in your
> print myPDF.canv._fontname
> print myPDF.rlfonts.keys()
> for txt in ('012', 'abc', 'ABC'):
> then I see this in the output
>> ['Times-BoldItalic', 'Times-Italic', 'Times-Bold', 'Times']
>> ('thiswid:', 30.0)
>> Traceback (most recent call last):
>> File "C:\Users\rptlab\Downloads\rl-test.py", line 82, in <module>
> so perhaps you should consider making the font set up code a bit more
OK, something clicked, but something is _VERY_ unclear.
I changed my code to pass "Times-New-Roman" to Canvas.stringWidth, and
Before, I had only tried "Times", "times", and "Times New Roman".
Of course the font name is actually "Times New Roman" in the font file.
Somewhere along the line I had felt a need to register it as
"Times-New-Roman". And when doing the font-family to and -Bold etc.
So by the time I needed stringWidth, I had forgotton about the hyphens.
Interestingly, taking all the hyphens out, also works, then passing
"Times New Roman" to the stringWidth.
So either something changed and example code I found is old, or hyphens
were never needed but allowed, but should be used or not used consistently.
So, either consistently using or consistently not using hyphens instead
of spaces in the font names works fine with pdfmetrics.stringWidth. But
mixing them causes the problem.
I guess that is a user code error, but it is _VERY_ unclear, why both
forms work.... and if both forms work, why they must be used so
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the reportlab-users