Use WinAnsiEncoding for built-in fonts #68
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, PdfLayerReference::write_text would use the UTF-8 encoding
for built-in fonts. But the built-in fonts only support a very limited
set of encodings, see Appendix D of the PDF Reference [0]. When adding
the font to the PDF document, printpdf already selects the
WinAnsiEncoding (Windows-1252, see the Into implementation
for BuiltinFont). This would lead to encoding issues for all non-ASCII
characters, see also issue #30.
With this patch, we use lopdf::Document::encode_text to encode the text
for built-in fonts with the WinAnsiEncoding. This fixes the encoding
issues for built-in fonts. Note that that function just drops
characters that are not supported by the encoding.
This patch also adds notes about this behaviour to the documentation of
the add_builtin_font, use_text and write_text methods.
Fixes #30.
[0] https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/pdf_reference_archives/PDFReference.pdf