asciidoctor-pdf: Break non-breaking hyphen
My test code:
Aaaa bbbbbb ccccccccc ddddd eeeeeeeee ffffffffffffff gggggggggggg hhhhhhh iiiiiii RFC{nbsp}P{nbsp}IEC{nbsp}60870‑5‑104
Render:
> asciidoctor --version
Asciidoctor 1.5.4 [http://asciidoctor.org]
Runtime Environment (ruby 2.2.3p173 (2015-08-18 revision 51636) [i386-mingw32]) (lc:IBM866 fs:Windows-1251 in:- ex:IBM866)
> asciidoctor-pdf --version
Asciidoctor PDF 1.5.0.alpha.11 using Asciidoctor 1.5.4 [http://asciidoctor.org]
Runtime Environment (ruby 2.2.3p173 (2015-08-18 revision 51636) [i386-mingw32]) (lc:IBM866 fs:Windows-1251 in:- ex:IBM866)
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 16 (16 by maintainers)
Commits related to this issue
- resolves #462 add non-breaking hyphen to built-in fonts - non-breaking hyphen must be included in font or else arranger inadvertently introduces line break opportunity when partitioning glyph int... — committed to mojavelinux/asciidoctor-pdf by mojavelinux 10 years ago
- resolves #462 add non-breaking hyphen to built-in fonts - non-breaking hyphen must be included in font or else arranger inadvertently introduces line break opportunity when partitioning glyph int... — committed to mojavelinux/asciidoctor-pdf by mojavelinux 10 years ago
- resolves #462 add non-breaking hyphen to built-in fonts - The non-breaking hyphen glyph must be included in font or else Prawn's text arranger inadvertently introduces a line break opportunity when... — committed to mojavelinux/asciidoctor-pdf by mojavelinux 10 years ago
- resolves #462 add non-breaking hyphen to built-in fonts (PR #550) - The non-breaking hyphen glyph must be included in font or else Prawn's text arranger inadvertently introduces a line break oppor... — committed to vogellacompany/asciidoctor-pdf by mojavelinux 10 years ago
\o/ 🍻
This is a permanent solution, but very specific to this use case. If something causes the hyphen to be isolated in a fragment by itself (for instance, if you try to bold it), then the line will break there. The general solution is to figure out why Prawn is allowing breaks at the boundaries of fragments, since fragments are merely an internal data structure that should have no bearing on line wrapping behavior. In other words, it’s a bug in Prawn.
This happens because the non-breaking hyphen is not in the Noto Serif font shipped with Asciidoctor PDF. The reason that matters actually has to do with an internal quirk in Prawn. When Prawn can’t find the character in the specified font, and a fallback font is in use, it splits off that fragment from the rest of the string to mark it as having a different font.
The line wrap permits a break between any two fragments in this array. Hence, it’s allowing a break not because it allows a non-breaking hyphens to be a break opportunity, but because the non-breaking hyphen is missing from the font (and gets split off from the rest of the string).
I’ll go ahead and add the non-breaking hyphen to the Noto Serif font…but this problem is going to come up anytime the main font is missing the character in use.
Btw, as a workaround, you can use an en-dash instead. Here’s how that same string gets represented when the en-dash is used (which is in the Noto Serif font):
We should file an issue upstream that Prawn should not break between fragments if the fragment is isolated just to change the font. But I’ll admit, this gets complicated very quickly.