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

Nested unordered lists crash the renderer when a non-default font is in use #619

Closed
tkfu opened this issue Oct 10, 2016 · 13 comments
Closed
Assignees

Comments

@tkfu
Copy link

tkfu commented Oct 10, 2016

If I create an asciidoc file that has an unordered list in it with nested items, it yields the following error when trying to render it using my custom stylesheet:

$ asciidoctor-pdf -a pdf-style=my-theme.yml -a pdf-fontsdir=fonts simple.adoc 
Prawn::Errors::CannotFit
  Use --trace for backtrace

This appears to happen when the font is missing the bullet glyphs that asciidoctor uses for specific nested levels.

The simplest examples of failing files I can produce are as follows:

Modify default-theme.yml to add Roboto:

(note: I chose Roboto arbitrarily; the one I'm actually trying to use isn't freely licensed. I've reproduced this with a number of different fonts, however. The difference is in how many of the glyphs the font has. Helvetica Neue, for example, works up until the 2nd nesting level, but fails beyond that.)

my-theme.yml

font:
  catalog:
    Roboto:
      normal: Roboto-Light.ttf
      bold: Roboto-Bold.ttf
      italic: Roboto-LightItalic.ttf
      bold_italic: Roboto-BoldItalic.ttf
[...]
base:
[...]
  font_family: Roboto

simple.adoc

= Test Document

test

== Heading 1

* item
** item
*** item

If I remove the fallback font from the stylesheet, the document will render, but without bullets for the 2nd and 3rd levels of nesting.

@habamax
Copy link
Contributor

habamax commented Oct 10, 2016

you have to use 'good' fallback font to avoid that problem (not the one documentation states -- it is quite hard to download correctly)

I for myself copied M+ fallback font which default theme uses, added to the theme and this error had gone away.

@habamax
Copy link
Contributor

habamax commented Oct 10, 2016

My theme setup regarding fonts:

font:
  catalog:
    Main:
      normal: roboto-regular.ttf
      bold: roboto-bold.ttf
      italic: roboto-italic.ttf
      bold_italic: roboto-bolditalic.ttf
    Mono:
      normal: roboto-mono-regular.ttf
      bold: roboto-mono-bold.ttf
      italic: roboto-mono-italic.ttf
      bold_italic: roboto-mono-bolditalic.ttf
    Heading:
      normal: cuprum-regular.ttf
      bold: cuprum-bold.ttf
      italic: cuprum-italic.ttf
      bold_italic: cuprum-bolditalic.ttf
    Fallback:
      normal: mplus1p-regular-fallback.ttf
      bold: mplus1p-regular-fallback.ttf
      italic: mplus1p-regular-fallback.ttf
      bold_italic: mplus1p-regular-fallback.ttf
  fallbacks:
    - Fallback

@habamax
Copy link
Contributor

habamax commented Oct 10, 2016

#609

@habamax
Copy link
Contributor

habamax commented Oct 10, 2016

Well, I am really sorry ;)

I can reproduce your error with the level 3 unordered list items.

And fallback font doesn't help it.

@habamax
Copy link
Contributor

habamax commented Oct 10, 2016

I guess it is better to use gogle Noto font then ...

@kku39
Copy link

kku39 commented Mar 15, 2017

I have the probably same issue when I use M+ 1mn fonts with full glyphs (get from here), instead of built-in ones.

I have just set base_font_family as M+ 1mn in default-theme.yml, and replaced those ttf files.

Used command:

$ asciidoctor-pdf test.adoc --trace

test.adoc:

= a

* a
** b

Traces: traces.txt

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

Okay, I understand what the bug is now. The problem is, we are calculating the width of the glyph from the current font, even if the glyph is missing. Then, Prawn uses the fallback font to render the missing glyph, which almost always has a different width. We need to calculate the width based on the glyph Prawn is actually going to use. In theory, it's simple enough to solve.

@mojavelinux
Copy link
Member

I'm pursuing a fix in #651.

@mojavelinux
Copy link
Member

Resolved by 21a3bcf.

@astubbs
Copy link

astubbs commented Sep 27, 2018

Is it possible we're missing calculating the height as well? (#798)

@mojavelinux
Copy link
Member

That's a possibility. But once #798 is resolved, you'll have a lot more control over the marker and will have the power to customize it if you run into something like this again.

@hanna-del-rae
Copy link

@mojavelinux I am experiencing a crash when there is any nested UL list, but I am not getting any error when building the PDF, which is leaving me wondering if there is any issue with the glyph actually fitting, or the issue is something else.

@mojavelinux
Copy link
Member

@hanna-del-rae Have you tried the unreleased version? You can find instructions for how to test here: https://github.com/asciidoctor/asciidoctor-pdf#development

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

No branches or pull requests

6 participants