Issue in PDFDocument with the font Avenir

Hi all, I have an issue in PDFDocument where the Avenir and AvenirHeavy fonts are rendered incorrectly. A customer reported that Acrobat Reader for Windows reports that “The font ‘AvenirHeavy’ contains a bad /BBox.”

The attached screenshot shows how it is rendered on macOS.

This is the code used to generate the PDF:

var pdf As new PDFDocument(600, 800)

var g As Graphics = pdf.Graphics

g.FontName = "Avenir"
g.FontSize = 20
g.DrawText("Avenir", 10, 50)

var file As FolderItem = SpecialFolder.Desktop.Child("PDF_BadBBox.pdf")

Try
  pdf.Save(file)
  
  file.Open
  
Catch e As IOException
  MessageBox(e.Message)
End Try

Adding pdf.EmbeddedFonts = True does not help, it only changes the position of the capital letter A.

Is it an issue in my code, in Xojo, and do you know of any workaround?

Edit: using Xojo 2024.4.2 on macOS 14.7.1

Is the Avenir font a paid one or free?

Looks like the font has a problem that may not show on other tools but in Xojo.

Maybe you can open an Issue (privately if needed), attach the font for Xojo team to reproduce. Not sure if they can fix something to match behavior on other software or they think the font needs fixing.

Using g.FontName = "Avenir Heavy" gives me a better result. The font Avenir has couple of styles, so you need to use the exact name.

In addition for comparison:

g.FontName = "Avenir Heavy"
g.FontSize = 20
g.DrawText("Avenir Heavy", 10, 50)

g.FontName = "Avenir Black"
g.DrawText("Avenir Black", 10, 80)

g.FontName = "Avenir Thin"
g.DrawText("Avenir Thin", 10, 110)

I think Avenir and Avenir Next come preinstalled on macOS and MS Office.

1 Like

Thanks. Fired up Word and I see this:

If I select ‘Avenir’ (the top option) and then see the font list again, is changed to ‘Book’

Can you try “Avenir Book” as your font instead?

There are 14 “base fonts” that are supported by all PDF readers (or else they may not claim they read PDFs). You should use one of those.

https://developer.adobe.com/experience-manager/reference-materials/cloud-service/javadoc/com/adobe/fontengine/font/Base14.html

The problem seems to be in the “Book” style.
These are the results using all the fonts in the “Avenir” family, and for comparison how the same fonts are exported by Affinity Designer.

The updated source code, paste it in the Pressed event of a PushButton or in Window.Opening:

var pdf As new PDFDocument(600, 800)
pdf.EmbeddedFonts = true

var g As Graphics = pdf.Graphics
g.FontSize = 20

g.FontName = "Avenir Light"
g.DrawText("Avenir Light", 10, 50)

g.FontName = "Avenir Light Oblique"
g.DrawText("Avenir Light Oblique", 10, 80)

g.FontName = "Avenir Book"
g.DrawText("Avenir Book", 10, 110)

g.FontName = "Avenir Roman"
g.DrawText("Avenir Roman", 10, 140)

g.FontName = "Avenir Book Oblique"
g.DrawText("Avenir Book Oblique", 10, 170)

g.FontName = "Avenir Oblique"
g.DrawText("Avenir Oblique", 10, 200)


g.FontName = "Avenir Medium"
g.DrawText("Avenir Medium", 310, 50)

g.FontName = "Avenir Medium Oblique"
g.DrawText("Avenir Medium Oblique", 310, 80)

g.FontName = "Avenir Heavy"
g.DrawText("Avenir Heavy", 310, 110)

g.FontName = "Avenir Heavy Oblique"
g.DrawText("Avenir Heavy Oblique", 310, 140)

g.FontName = "Avenir Black"
g.DrawText("Avenir Black", 310, 170)

g.FontName = "Avenir Black Oblique"
g.DrawText("Avenir Black Oblique", 310, 200)

var file As FolderItem = SpecialFolder.Desktop.Child("PDF_BadBBox.pdf")

Try
  pdf.Save(file)
  
  file.Open
  
Catch e As IOException
  MessageBox(e.Message)
End Try

I also tried using the PostScript name, no change.

Thanks, but that is not possible. It is a design software and supporting more than 14 base fonts is crucial.

Oh okay, that’s understandable. Well, it’s very likely an issue with the Xojo PDF engine because it’s entirely custom. You’ll probably want to open a ticket, attach a sample project and the font file privately.

1 Like

Have-you tried to use the Avenir Book file from the Mac on your windows machine ?

Doh ! The problem occured reading on WIndows, a macOS created PDF ?

So, have-you tried to create that PDF on another macOS Computer ? On Windows ?

That is what I got with Sequoia 15.1.1 (24B91) Xojo 2024r4.1. running in the IDE.

MacBook Pro m1 8GB with some running apps… (Firefow JDownloader, Preview, TextEdit…)

1 Like

I just tested it on Windows 11 using the installed “Avenir LT” and Acrobat complained about the bad BBox. Look:

To be sure I pass the exact font name, I used a popup menu with the list of system fonts returned by System.FontAt()

Sorry, I didn’t answer your other questions: no, AFAIK the customer uses only a Windows machine.

I meant “on your end” (for the tests).

Sorry.

1 Like

I just verified that on Windows 11 Acrobat complains about “Cambria” too.

Upload a zip with some sample of those broken Xojo PDFs here for inspection.

This sample seems interesting:

I added two times the Avenir Book lines at the code end, sameresult (and I cleared the 202’r4.2 caches)
In the IDE, I removed the space and add a brand new one with the space bar (in case it was a non breaking space)…

“Bbox” is a shorthand for “bounding box”, and each glyph in a font must have one that is valid. Looks like this version of the font has been damaged in some way – Acrobat is actually incredibly tolerant of oddball data in PDFs and if IT is throwing an error, you know it’s serious. :slight_smile: I’d say install a newer version of the font if you can find it.

The font rendering system uses the bounding box to properly position letters, and you can do all manner of strange things with it if you manipulate the values. Such as … overlapping letters, just like this.

I filed an issue report at https://tracker.xojo.com/xojoinc/xojo/-/issues/78308

Still want your PDF, to inspect its guts, because your sample app works here, but all fonts are changed to some kind of Helvetica. I want to see if I can find and understand (no guarantees) the specific bounding box problem that Adobe just mentions.

Thanks Rick! here is the zip file with four tests.
Bad_BBox_Fonts_PDF.zip (817.6 KB)