prawnpdf/prawn

How to render UTF-8 characters

cyrusstoller opened this issue · 5 comments

Thank you so much for creating this great tool!

I see in the documentation that: "If the current font is a built-in one, although the string must be encoded as UTF-8, only characters that are available in WinAnsi are allowed."

Is this a limitation of the built-in fonts, or is this a limitation of prawn itself. In other words, if I manually load a font can I render all UTF-8 characters?

I see how the wording can be unclear. WinANSI is a limitation of the built-in fonts. They only provide a limited set of glyphs.

Likewise, with external fonts you have to make sure that the font provides all the glyphs you'd like to use. Generally the range is wider than in the built-in fonts but it's quite uncommon for a font to cover full range of Unicode characters.

To answer your question: you can render Unicode characters if you have a font that provides glyphs for them.

However, note that Prawn doesn't support all font features. For example, Prawn can't handle raster fonts at the moment. Most Emoji is implemented that way and so can't be rendered with Prawn.

Thanks for the quick reply.

Got it. Are there any plans to support raster fonts?

I'm trying to create a PDF export of some user generated content. Based on what you've shared it seems like I'll need to do some parsing to render glyphs in a font that supports my users' languages and separately render emoji using something like https://github.com/hidakatsuya/prawn-emoji. Is that right?

No plans as such but a contribution would be welcome.

Got it. Are there any plans to support raster fonts?

PDF only supports the most common font programs: Type1 (not really used anymore), TrueType, and CFF (used in OpenType).

The newer CFF2 version of OpenType is not supported directly, as are raster/bitmap fonts.

There is, however, support for so called Type3 fonts in PDF the glyphs of which are defined as PDF XObjects. So one could create a custom Type3 font from an emoji font and use that.

@cyrusstoller I will close this issue since I think it is resolved. If not, please let us know.