Forum Bugs

Line Breaks Different Results Then Browser

scott_w
Our content is previewed in a browser for approval prior to the same file and CSS being shuttled off to Prince for a PDF. We have noticed that the line breaks vary between the two. I have prepared an example that illustrates this problem. In this example I have added "br" tags, which we do need to be able to do from time to time to control the line endings in titles. Of course my example has them on every line to help illustrate the point.

What I can't figure out is why the lines break differently. I thought it at first might be the inch to pixel math on the width of the "p" but I have opened the file in multiple browsers and I am seeing widths in pixels that vary as much as 0.2045 pixels but of course I am still not seeing the text re-wrap until I create the PDF.

  1. browser.png153.0 kB
  2. line-break-bug.pdf404.4 kB
  3. line-break-bug.xhtml1.8 kB
  4. prince-output.png89.0 kB
mikeday
Prince is not guaranteed to break lines at the exact same point as browsers, nor are different browsers guaranteed to break lines at the exact same point as each other, or even different versions of the same browser, or the same version of the same browser but running on different computers.

You can get close by making sure you are using the exact same fonts and text rendering settings, this is a vital first step.

However even with these precautions there may still be some occasions where tiny discrepancies in rounding behaviour mean that text just fails to fit in a box of the same width.

How much work you wish to do to overcome these discrepancies depends upon your requirements for the use case in question.
wangp
Note there is a problem with 'white-space:pre-wrap' where trailing spaces are not treated specially, and continue to take up non-zero width.
scott_w
I adjusted my test files and can now see that it is the how trailing spaces are treated when 'white-space:pre-wrap' is applied. It looks like the browsers are making an exception for the trailing space and treating them differently.

Are you currently handling trailing spaces, when 'white-space:pre-wrap' is NOT applied, by not including them when you break a line to text, thereby allowing the text to come right up to its frame without being pushed off by trailing space(s), much like InDesign does?