@@ -29,6 +29,7 @@ This file is part of the iText (R) project.
29
29
import com .itextpdf .kernel .colors .ColorConstants ;
30
30
import com .itextpdf .kernel .font .PdfFont ;
31
31
import com .itextpdf .kernel .font .PdfFontFactory ;
32
+ import com .itextpdf .kernel .geom .PageSize ;
32
33
import com .itextpdf .kernel .geom .Rectangle ;
33
34
import com .itextpdf .kernel .pdf .PdfDocument ;
34
35
import com .itextpdf .kernel .pdf .PdfWriter ;
@@ -774,6 +775,94 @@ public IRenderer getNextRenderer() {
774
775
Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder ));
775
776
}
776
777
778
+ @ Test
779
+ public void nbspCannotBeFitAndIsTheOnlySymbolTest () throws IOException , InterruptedException {
780
+ String outFileName = destinationFolder + "nbspCannotBeFitAndIsTheOnlySymbolTest.pdf" ;
781
+ String cmpFileName = sourceFolder + "cmp_nbspCannotBeFitAndIsTheOnlySymbolTest.pdf" ;
782
+
783
+ PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFileName ));
784
+ // No place for any symbol (page width is fully occupied by margins)
785
+ Document doc = new Document (pdfDocument , new PageSize (72 , 1000 ));
786
+
787
+ Paragraph paragraph = new Paragraph ()
788
+ .add (new Text ("\u00A0 " ));
789
+
790
+ paragraph .setProperty (Property .RENDERING_MODE , RenderingMode .HTML_MODE );
791
+ doc .add (paragraph );
792
+
793
+ doc .close ();
794
+
795
+ Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder ));
796
+ }
797
+
798
+ @ Test
799
+ @ LogMessages (messages = {
800
+ @ LogMessage (messageTemplate = LogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA )
801
+ })
802
+ public void nbspCannotBeFitAndMakesTheFirstChunkTest () throws IOException , InterruptedException {
803
+ String outFileName = destinationFolder + "nbspCannotBeFitAndMakesTheFirstChunkTest.pdf" ;
804
+ String cmpFileName = sourceFolder + "cmp_nbspCannotBeFitAndMakesTheFirstChunkTest.pdf" ;
805
+
806
+ PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFileName ));
807
+ // No place for any symbol (page width is fully occupied by margins)
808
+ Document doc = new Document (pdfDocument , new PageSize (72 , 1000 ));
809
+
810
+ Paragraph paragraph = new Paragraph ()
811
+ .add (new Text ("\u00A0 " ))
812
+ .add (new Text ("SecondChunk" ));
813
+
814
+ paragraph .setProperty (Property .RENDERING_MODE , RenderingMode .HTML_MODE );
815
+ doc .add (paragraph );
816
+
817
+ doc .close ();
818
+
819
+ Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder ));
820
+ }
821
+
822
+ @ Test
823
+ @ LogMessages (messages = {
824
+ @ LogMessage (messageTemplate = LogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA )
825
+ })
826
+ public void nbspCannotBeFitAndIsTheFirstSymbolOfChunkTest () throws IOException , InterruptedException {
827
+ String outFileName = destinationFolder + "nbspCannotBeFitAndIsTheFirstSymbolOfChunkTest.pdf" ;
828
+ String cmpFileName = sourceFolder + "cmp_nbspCannotBeFitAndIsTheFirstSymbolOfChunkTest.pdf" ;
829
+
830
+ PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFileName ));
831
+ // No place for any symbol (page width is fully occupied by margins)
832
+ Document doc = new Document (pdfDocument , new PageSize (72 , 1000 ));
833
+
834
+ Paragraph paragraph = new Paragraph ()
835
+ .add (new Text ("\u00A0 First" ));
836
+
837
+ paragraph .setProperty (Property .RENDERING_MODE , RenderingMode .HTML_MODE );
838
+ doc .add (paragraph );
839
+
840
+ doc .close ();
841
+
842
+ Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder ));
843
+ }
844
+
845
+ @ Test
846
+ public void nbspCannotBeFitAndIsTheLastSymbolOfFirstChunkTest () throws IOException , InterruptedException {
847
+ String outFileName = destinationFolder + "nbspCannotBeFitAndIsTheLastSymbolOfFirstChunkTest.pdf" ;
848
+ String cmpFileName = sourceFolder + "cmp_nbspCannotBeFitAndIsTheLastSymbolOfFirstChunkTest.pdf" ;
849
+
850
+ PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFileName ));
851
+ // No place for the second symbol
852
+ Document doc = new Document (pdfDocument , new PageSize (81 , 1000 ));
853
+
854
+ Paragraph paragraph = new Paragraph ()
855
+ .add (new Text ("H\u00A0 " ))
856
+ .add (new Text ("ello" ));
857
+
858
+ paragraph .setProperty (Property .RENDERING_MODE , RenderingMode .HTML_MODE );
859
+ doc .add (paragraph );
860
+
861
+ doc .close ();
862
+
863
+ Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder ));
864
+ }
865
+
777
866
@ Test
778
867
@ LogMessages (messages = {
779
868
@ LogMessage (messageTemplate = LogMessageConstant .CREATE_COPY_SHOULD_BE_OVERRIDDEN , count = 8 )
0 commit comments