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

Renderer crash with checklist when using non-default font #651

Closed
branic opened this issue Nov 1, 2016 · 12 comments
Closed

Renderer crash with checklist when using non-default font #651

branic opened this issue Nov 1, 2016 · 12 comments
Assignees
Labels

Comments

@branic
Copy link

branic commented Nov 1, 2016

When using a base: font_family that is not a built-in default font rendering a file with a checklist will cause the renderer to die with a CannotFit error.

# asciidoctor-pdf test.adoc 
Prawn::Errors::CannotFit
  Use --trace for backtrace

The theme I am using is based on the default theme and add additional fonts (such as Google Noto that I downloaded from the Git repo).

font:
  heading_margin_top: 1
  catalog:
    # Noto Serif supports Latin, Latin-1 Supplement, Latin Extended-A, Greek, Cyrillic, Vietnamese & an assortment of symbols
    Noto Serif:
      normal: notoserif-regular-subset.ttf
      bold: notoserif-bold-subset.ttf
      italic: notoserif-italic-subset.ttf
      bold_italic: notoserif-bold_italic-subset.ttf
    # M+ 1mn supports ASCII and the circled numbers used for conums
    M+ 1mn:
      normal: mplus1mn-regular-ascii-conums.ttf
      bold: mplus1mn-bold-ascii.ttf
      italic: mplus1mn-italic-ascii.ttf
      bold_italic: mplus1mn-bold_italic-ascii.ttf
    # M+ 1p supports Latin, Latin-1 Supplement, Latin Extended, Greek, Cyrillic, Vietnamese, Japanese & an assortment of symbols
    # It also provides arrows for ->, <-, => and <= replacements in case these glyphs are missing from font
    M+ 1p Fallback:
      normal: mplus1p-regular-fallback.ttf
      bold: mplus1p-regular-fallback.ttf
      italic: mplus1p-regular-fallback.ttf
      bold_italic: mplus1p-regular-fallback.ttf
    Google Noto Serif:
      normal: /fonts/google-noto/NotoSerif-Regular.ttf
      italic: /fonts/google-noto/NotoSerif-Italic.ttf
      bold: /fonts/google-noto/NotoSerif-Bold.ttf
      bold_italic: /fonts/google-noto/NotoSerif-BoldItalic.ttf
  fallbacks:
    - M+ 1p Fallback

The same error is generated if the asciidoctor file contains source code callouts.

This may be related to issue #609 and/or #619.

@mojavelinux
Copy link
Member

It's true that if the glyph is missing from the primary font and it uses the glyph from the fallback font, and the glyph has a different size, then it won't have reserved enough space and will fail to write. I think there's a setting in Prawn to tell it to try anyway or truncate.

The immediate solution to this problem is to either pick a font that has the bullet glyph or to modify the font using fontforge and add it.

@mojavelinux
Copy link
Member

I think we also talked about being able to customize the bullet glyphs. In other words, allow the character to be set per named glyph (circle, disc, square).

@mojavelinux mojavelinux changed the title Rederer crash with checklist when using non-default font Renderer crash with checklist when using non-default font Nov 1, 2016
@branic
Copy link
Author

branic commented Nov 3, 2016

Thanks @mojavelinux. By removing the fallback font I was able to get past the renderer failure and get the square box icon (i.e. glyph not found). I found in the code where the glyphs to use for checkboxes are defined, but I haven't been able to find where the glyphs that are used for source code callouts are defined.

Can you point me to where the source code callout glyphs are defined?

@branic
Copy link
Author

branic commented Nov 3, 2016

In addition to being able to customize the character for the bullet gyphs it would be nice to be able to set the font. For example to use the FontAwesome font for some/all glyphs.

@branic
Copy link
Author

branic commented Nov 3, 2016

I've done a bit more testing (hopefully its valid testing).

I'm using the Liberation Sans font installed on Fedora 24. In a LibreOffice document I'm able to insert the Unicode characters 2610 and 2611 (ctrl+shift+u+2610+enter) and the correct ballot box glyphs are inserted. However, when the same font is used in the asciidoctor-pdf theme the ballot boxes glyphs are not found.

I opened the font in fontforge and the glyphs at unicode 2610 and 2611 are not defined.

This leads me to think that LibreOffice is doing some kind of glyph merging?? (I'm definitely not a font expert).

Any ideas are welcome. I've tried the same test in a few different fonts as well (such as Overpass) with the same result.

@gxurma
Copy link

gxurma commented Mar 10, 2017

Have the same problem. Trying to use DejaVu fonts gives me the "CannotFit" error when using:

  • bulletted lists that are deeper than 1 level,
  • Checkboxes
  • callout numbers.

Cant we just tell Prawn to autoshrink into the space available? that would make all the troubles go away...

@mojavelinux
Copy link
Member

mojavelinux commented Mar 10, 2017

It's not quite that simple, but it is possible to make this work for any font.

The space has to be pre-calculated to ensure that the glyph gets placed in the correct location, and on the correct page. There's just some sort of error in that calculation atm (it's entirely possible this is a rounding error). I'm confident it can be fixed.

@mojavelinux mojavelinux added this to the v1.5.0.alpha.15 milestone Mar 10, 2017
@mojavelinux mojavelinux self-assigned this Mar 10, 2017
@mojavelinux
Copy link
Member

We'll find a solution for alpha.15.

@gxurma
Copy link

gxurma commented Mar 11, 2017

To achieve this, how can I help? I would like to use asciidoctor-pdf sooo badly...

@mojavelinux
Copy link
Member

See my explanation here: #619 (comment)

Simply put, it's a bug in the code.

mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Mar 27, 2017
…ting width of string

- introduce rendered_width_of_string and rendered_width_of_char methods
- take width of char from fallback font into account if not glyph not present in font
- calculate width of conum using correct font
@mojavelinux
Copy link
Member

A fix is now available. If you have time, please test.

#788

@mojavelinux
Copy link
Member

Long story short, the width_of_string method in Prawn does not check whether the font provides the glyph. Therefore, the return value is invalid when the font does not contain the width. If fallback fonts are being used, we now continue looking through the fonts to find which font will be used to render the char before taking the width.

mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Mar 27, 2017
…ting width of string

- introduce rendered_width_of_string and rendered_width_of_char methods
- take width of char from fallback font into account if not glyph not present in font
- calculate width of conum using correct font
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants