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.
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.
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
Well, I am really sorry ;)
I can reproduce your error with the level 3 unordered list items.
And fallback font doesn't help it.
I guess it is better to use gogle Noto font then ...
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
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.
I'm pursuing a fix in #651.
Resolved by 21a3bcf53a125273f2fbf9e3ba20f16fcdacc2fe.
Is it possible we're missing calculating the height as well? (#798)
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.
@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.
@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
Most helpful comment
Resolved by 21a3bcf53a125273f2fbf9e3ba20f16fcdacc2fe.