Symbols in DynaPDFMBS

On screen, if I set the font for a text field to be Courier new, I can insert into that symbols and even emojis (on a Mac)
They display on screen correctly.

Here is one: ⦿

If I create a PDF using DynaPDFMBS and set the font in this fashion:

Call pdf.SetFontAnsi ("Courier New", pdf.kfsNormal, 10 , True, pdf.kcpunicode)

Then inserting a character which is symbolic (unicode, has 3 bytes eg E2A6 BF when viewed in the debugger)
…generates a PDF Exception : Glyph not available.

Is there a way to make the onscreen symbol appear in the PDF?

If you paste the symbol into Text Edit you should see that a different font is chosen as it isn’t available in the font. This is a built in feature of the OS called font fallback which automatically chooses a different font when the character isn’t available in the specified font.

Trying to make the PDF exactly the same as on-screen could be tricky.

You would first have to check each character to see if it is in the chosen font. I imagine the DynaPDF function GetGlyphIndex would help here. The difficult part is choosing the alternative (fallback) font which matches the operating system.

A quick Google indicates that the Core Text function CTFontCopyDefaultCascadeListForLanguages() could be used to get the list of fallback fonts.

so… This is what you might have to do:

  1. Identify that the glyph isn’t available via GetGlyphIndex.
  2. Create a CTFontMBS object for the font / size you will be styling the character with.
  3. Call DefaultCascadeListForLanguages on the CTFontMBS instance you created.
  4. Iterate the result of DefaultCascadeListForLanguages and check for the character in each item of the result. This might mean creating a CTFontMBS for that font and then calling its GlyphsForCharacters method or maybe loading the font into DynaPDF and calling GetGlyphIndex to see if it exists.
2 Likes

An excellent and comprehensive reply.
Thank you.

In practice,since that would require embedding fonts in the distributed PDF, I need to restrict the possible input characters.
Disappointing, but this is for a simple little app - dont want to complicate matters.

Font Substitution is difficult.
DynaPDF 5 later this year should bring it, but well, it’s more work than expected.

Anyway, you can simply use a font with a lot of characters like Arial Unicode MS.
And you can pre-check with TestGlyphs function and switch font to get one containing characters.

1 Like

This isnt one of the ‘PDF 14’ fonts.
Is it ‘safe’ to use this in a distributed PDF?

The PDF safe fonts could also be used. Of course.
DynaPDF got upgraded a couple of months ago to have the right tables included.
So please try that.