[reportlab-users] WordCount in reportlab paragraph

Robin Becker robin at reportlab.com
Fri Feb 27 10:56:25 EST 2009


Andy Robinson wrote:

> 2009/2/27 Robin Becker <robin at reportlab.com>:

>>> This kind of problem is eminently suited to unit tests, when

>> when the unit test framework can look at our pdfs and see that a word is not

>> properly aligned then I'll give in. We could try saving images of these

>> problems (say using ghost script) and then compare images.

>

> Surely we can assume a built-in font (Courier, always 0.6em wide),

> construct a paragraph, call wrap(), and then assert that certain

> text appears in line 1, line 2 and so on, and that the amount of

> extra space on each line is 'as expected'?

>

......
the problem here was not in the breaking, but in some attributes that were
collected alongside the break and that then affected the layout. A test could be
devised that required the broken paragraph to have a specific structure and then
compare all the properties against future outputs.

Of course that won't protect against changes in the later layout layer and makes
changing the overall algorithm harder since each change requires measuring the
properties again etc etc. Perhaps we could just record the expected output of
the paragraph rendering rather than converting the pdf to pixels.
--
Robin Becker


More information about the reportlab-users mailing list