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: 1

> 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

Most upvoted comments

\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.

[{:text=>"Aaaa bbbbbb ccccccccc ddddd eeeeeeeee ffffffffffffff gggggggggggg hhhhhhh iiiiiii RFC P IEC 60870", :color=>"333333"}, {:text=>"‑", :color=>"333333", :font=>"M+ 1p Fallback"}, {:text=>"5", :color=>"333333"}, {:text=>"‑", :color=>"333333", :font=>"M+ 1p Fallback"}, {:text=>"104", :color=>"333333"}]

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):

[{:text=>"Aaaa bbbbbb ccccccccc ddddd eeeeeeeee ffffffffffffff gggggggggggg hhhhhhh iiiiiii RFC P IEC 60870–5–104", :color=>"333333"}]

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.