Search code examples
unicodeencodingcharacter-encodingpdflib

avoidbreak is not correctly working in pdflib 8


I have a text, the word "Versicherungs-Lebenslagen" should only break at the hyphen. This works, but the world Lebenslagen should stay in the same line, if there is enough space.
In my picture, there word is in the next line.

avoid linebreaking with pdflib

My pdflib code which i read in the API DOC, page 86 is:

haben wir Services für alle <avoidbreak=true>„Versicherungs<avoidbreak=false>-<avoidbreak=true>Lebenslagen“<avoidbreak=false> eingerichtet:

i also used the tags <avoidbreak> and <noavoidbreak> as i have read it in the java examples for pdflib 9

haben wir Services für alle <avoidbreak>„Versicherungs<noavoidbreak>-<avoidbreak>Lebenslagen“<noavoidbreak> eingerichtet:

Anyone know this issue?


Solution

  • I guess, this is related to the special quotation marks you use. The “ (Unicode U+201C ) is defined as an opening/left character. As result, the textflow line break algorithm do not break directly afterwards.

    You can workaround this, when you re-define the character class of this characters.

    tf = p.create_textflow("haben wir Services f&uuml;r alle 
            <avoidbreak=true>&#x201E;Versicherungs<avoidbreak=false>-
            <avoidbreak=true>Lebenslagen&#x201c;<avoidbreak=false> eingerichtet:", 
        "fontname Arial encoding=unicode fontsize=20 charref 
            charclass={ close U+201C open U+201E}");
    p.fit_textflow(tf, 50, 500, 350, 700, "showborder");
    

    (you should use this code directly in the hello.java sample or so)

    Please see also PDFlib 8 Tutorial, chapter 8.2.8 "Controlling the standard Linebreak Algorithm" for further details on this.