Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font Embedding: Subset enabled by default and breaking font #1361

Open
2 tasks
MrSerth opened this issue Sep 18, 2024 · 3 comments
Open
2 tasks

Font Embedding: Subset enabled by default and breaking font #1361

MrSerth opened this issue Sep 18, 2024 · 3 comments

Comments

@MrSerth
Copy link

MrSerth commented Sep 18, 2024

Since updating to prawn 2.5.0, we face issues with font embedding and incorrectly or missing glyphs.

Reproduction example:

This reproduction example assumes that the file Arial Unicode MS.TTF is present in the local working directory. While the font is shipped with Microsoft Office by default and can be licensed by Microsoft, it is also available on GitHub (for example here). With the file being available, a simple irb can be started and the following script can be executed:

require 'prawn'
@pdf = Prawn::Document.new()

@pdf.font_families.update("ArialUnicodeMS" => {normal: {file: "Arial Unicode MS.TTF"}})

@pdf.font "ArialUnicodeMS", style: :normal
@pdf.text_rendering_mode :fill_stroke do
  @pdf.draw_text "Demo Text @ Draw Text", size: 22.0, style: :normal, text_anchor: "middle", at: [0, 500], offset: [0, 0]
end

@pdf.render_file('prawn.pdf')
puts "Done"

Issues noticed:

  • The @ character included in the text is not shown in Acrobat. Instead (after a few seconds), an error is shown: Cannot extract the embedded font 'e23202+ArialUnicodeMS'. Some characters may not display or print correctly.

    Bildschirmfoto 2024-09-18 um 20 38 57
  • The documentation for font_families indicates that the default for subset is false. However, this doesn't seem to be the case and it rather appears that subset: true is the default since 528a37d. Given the above example, explicitly specifying subset: true doesn't change anything (with regard to showing the @ or the file size of the resulting PDF`)

    # Bug still occurs
    @pdf.font_families.update("ArialUnicodeMS" => {normal: {file: "Arial Unicode MS.TTF", subset: true}})

    However, changing the option to subset: false, the full TTF file is embedded and the PDF file size dramatically increases (due to the large TTF):

    # Bug doesn't occur any longer, `@` is shown correctly and the resulting PDF is huge
    @pdf.font_families.update("ArialUnicodeMS" => {normal: {file: "Arial Unicode MS.TTF", subset: false}})

After reducing the issue to the above-given minimal reproduction example, we are pretty confident to face a bug in Prawn. Otherwise, we probably misunderstood the subsetting and font-embedding and would be grateful about some advice - Thank you!

--

prawn: 2.5.0
Ruby: 3.3.5
Adobe Acrobat Pro: 2024.003.20121

@gettalong
Copy link
Member

Have you looked at #1346? It seems that this is the same problem.

@MrSerth
Copy link
Author

MrSerth commented Sep 18, 2024

Yes, we've looked at #1346. From the various comments, we also got the idea of explicitly setting subset: false (despite being advertised as the default in the docs). As mentioned, subset: false resolves the issue with the missing glyph, but at some drawbacks (including the larger file size). The previous version of Prawn didn't had the same issue, and reverting also avoids the issue mentioned here. Since #1346 is closed, and we also have found a potential issue with the documentation, I decided to open a new issue. On a technical note, prawnpdf/ttfunk#102 is probably related, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants
@gettalong @MrSerth and others