Re: Embedded font problems

Robin Becker <[email protected]>
Newsgroups gmane.comp.python.reportlab.user
Message-ID <[email protected]>
On 13/03/2017 12:09, jsmith4332--- via reportlab-users wrote:
> Hello,
> Does anyone have troubleshooting tips for figuring out why an embedded TTF font does not work in reportlab (just shows rectangles)? I'm trying to use https://grandzebu.net/informatique/codbar/code128.ttf (yes, I would like to use a barcode font instead of the built in barcode generator due to quality issues when printing on a low DPI printer)
> The relevant code is:
> stylesheet = StyleSheet1()
>
> stylesheet.add(
>     ParagraphStyle(
>         name='Normal',
>         fontName='Helvetica',
>         fontSize=12,
>         leading=16,
>         spaceBefore=8,
>         spaceAfter=8,
>     )
> )
>
> stylesheet.add(
>     ParagraphStyle(
>         name='Barcode',
>         fontName='128',
>         fontSize=12,
>     )
> )
> pdfmetrics.registerFont(TTFont('128', os.path.join(os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))), 'code128.ttf')))# story definition omitted...story.append(Paragraph('helloworld'), stylesheet['Barcode']))
> Unfortunately, the resulting PDF has a bunch of squares instead of using the barcode font. When I switch to a different ttf, things seem to work. Furthermore, the code128 font referenced above seems to work fine in applications like Microsoft Word/Excel.
>
> Any ideas?
> Thanks!


I've never used a codabar font, so would have difficutly in knowing much about 
them. I think the assumption that we make for ttf fonts is that we use the glyph 
mapping that's present in the font and then we need to pass either unicode 
strings or utf8 into the drawing functions.

If you see black squares coming out that is an indication that we didn't get the 
bytes or unicode mapped into glyphs so the default missing glyph is shown 
(normally a black square).

If you are able to send the trivial test + a sample font to me 
([email protected] not the list) I will certainly be able to have a look and 
see if I can figure out what the problem is.

My suspicion is that these fonts need a special encoding.
-- 
Robin Becker
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.