Hello, We are having an issue with non-break spaces. I'll attach a test case and provide a description.
The issue occurs when a Paragraph of Chunks is added to a document. If the Chunks have all the same attributes, there is no problem. However, if the Chunks have different attributes (such as varying font size or bold vs plain), unexpected behaviour occurs with regard to non-breaking spaces. Specifically, itext will break between Chunks with varying attributes even if they are separated by non-breaking spaces. A quick glance at the source code for Paragraph and its superclass, Phrase, indicates that if all Chunks have the same attributes, it will simply append all the Chunks together, but if there are varying attributes, itext will handle the Chunks separately. Here is a synopsis of the test case: // create two Font objects with different attributes Font fontNormal = new Font(); fontNormal.setStyle(Font.NORMAL); Font fontBold = new Font(); fontBold.setStyle(Font.BOLD); // assemble some words, separated by nbsp chars String text[] = new String[]{ "This is a very purposely long sentence with no breaking spaces to demonstrate that " + "chunks with ", "different attributes within the same paragraph do not behave as expected." }; for (int i=0; i<text.length; i++) text[i] = text[i].replace(' ', '\u00a0'); // control case (everything works as expected): Paragraph paragraph = new Paragraph(); Chunk chunk = new Chunk(text[0], fontNormal); paragraph.add(chunk); chunk = new Chunk(text[1], fontNormal); paragraph.add(chunk); document.add(paragraph); // test case (breaking occurs at bolded chunk): paragraph = new Paragraph(); chunk = new Chunk(text[0], fontNormal); paragraph.add(chunk); chunk = new Chunk(text[1], fontBold); paragraph.add(chunk); document.add(paragraph); I'll also attach a screen shot of the output. [cid:image001.png@01CE9E59.D55C3170] Can you confirm if this is expected behaviour or a bug? Thanks, Rob
<<inline: image001.png>>
NonBreakingSpacesTest.java
Description: NonBreakingSpacesTest.java
------------------------------------------------------------------------------ Introducing Performance Central, a new site from SourceForge and AppDynamics. Performance Central is your source for news, insights, analysis and resources for efficient Application Performance Management. Visit us today! http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php