@@ -44,8 +44,10 @@ This file is part of the iText (R) project.
44
44
45
45
46
46
import com .itextpdf .io .LogMessageConstant ;
47
+ import com .itextpdf .io .image .ImageData ;
47
48
import com .itextpdf .io .image .ImageDataFactory ;
48
49
import com .itextpdf .kernel .color .Color ;
50
+ import com .itextpdf .kernel .geom .PageSize ;
49
51
import com .itextpdf .kernel .geom .Rectangle ;
50
52
import com .itextpdf .kernel .pdf .PdfDocument ;
51
53
import com .itextpdf .kernel .pdf .PdfPage ;
@@ -56,10 +58,12 @@ This file is part of the iText (R) project.
56
58
import com .itextpdf .layout .element .Cell ;
57
59
import com .itextpdf .layout .element .Div ;
58
60
import com .itextpdf .layout .element .Image ;
61
+ import com .itextpdf .layout .element .List ;
59
62
import com .itextpdf .layout .element .Paragraph ;
60
63
import com .itextpdf .layout .element .Table ;
61
64
import com .itextpdf .layout .property .ClearPropertyValue ;
62
65
import com .itextpdf .layout .property .FloatPropertyValue ;
66
+ import com .itextpdf .layout .property .ListNumberingType ;
63
67
import com .itextpdf .layout .property .Property ;
64
68
import com .itextpdf .layout .property .UnitValue ;
65
69
import com .itextpdf .test .ExtendedITextTest ;
@@ -1074,7 +1078,6 @@ public void floatsOnPageSplit13() throws IOException, InterruptedException {
1074
1078
Assert .assertNull (new CompareTool ().compareByContent (outFile , cmpFileName , destinationFolder , "diff32_" ));
1075
1079
}
1076
1080
1077
-
1078
1081
@ Test
1079
1082
public void floatInlineBlockTest01 () throws IOException , InterruptedException {
1080
1083
String cmpFileName = sourceFolder + "cmp_floatInlineBlockTest01.pdf" ;
@@ -1096,4 +1099,102 @@ public void floatInlineBlockTest01() throws IOException, InterruptedException {
1096
1099
doc .close ();
1097
1100
Assert .assertNull (new CompareTool ().compareByContent (outFile , cmpFileName , destinationFolder , "diff14_" ));
1098
1101
}
1102
+
1103
+ /**
1104
+ * Suggested by Richard Cohn.
1105
+ */
1106
+ @ Test
1107
+ public void floatRootElementNotFitPage01 () throws IOException , InterruptedException {
1108
+ String cmpFileName = sourceFolder + "cmp_floatRootElementNotFitPage01.pdf" ;
1109
+ String outFile = destinationFolder + "floatRootElementNotFitPage01.pdf" ;
1110
+
1111
+ //Initialize PDF writer
1112
+ PdfWriter writer = new PdfWriter (outFile );
1113
+
1114
+ //Initialize PDF document
1115
+ PdfDocument pdf = new PdfDocument (writer );
1116
+ pdf .setDefaultPageSize (new PageSize (600 , 350 ));
1117
+ pdf .setTagged ();
1118
+
1119
+ // Initialize document
1120
+ Document document = new Document (pdf );
1121
+
1122
+ // Document layout is correct if COLLAPSING_MARGINS is not true
1123
+ document .setProperty (Property .COLLAPSING_MARGINS , true );
1124
+
1125
+ document .add (new Paragraph ("Some text\n Some text\n Some text\n Some text\n Some text\n Some text" ));
1126
+ byte data [] = new byte [1 ];
1127
+ ImageData raw = ImageDataFactory .create (1 , 1 , 1 , 8 , data , null );
1128
+ Image image = new Image (raw ).setHeight (200 );
1129
+ Div div = new Div ();
1130
+ div .add (image );
1131
+ Div captionDiv = new Div ();
1132
+ captionDiv .add (new Paragraph ("Caption line 1\n " ).add ("line 2" ));
1133
+ div .add (captionDiv );
1134
+ div .setProperty (Property .FLOAT , FloatPropertyValue .RIGHT );
1135
+ //div.setKeepTogether(true);
1136
+ document .add (div );
1137
+ document .add (new Paragraph ("After float" ));
1138
+ document .add (new List (ListNumberingType .DECIMAL )
1139
+ .add ("Some text\n Some text\n Some text\n Some text" )
1140
+ .add ("Some text\n Some text\n Some text" )
1141
+ .add ("Some text\n Some text" )
1142
+ .add ("Some text\n Some text" ));
1143
+
1144
+ document .close ();
1145
+ Assert .assertNull (new CompareTool ().compareByContent (outFile , cmpFileName , destinationFolder , "diff15_" ));
1146
+ }
1147
+
1148
+ /**
1149
+ * Suggested by Richard Cohn.
1150
+ */
1151
+ @ Test
1152
+ public void floatRootElementNotFitPage02 () throws IOException , InterruptedException {
1153
+ String cmpFileName = sourceFolder + "cmp_floatRootElementNotFitPage02.pdf" ;
1154
+ String outFile = destinationFolder + "floatRootElementNotFitPage02.pdf" ;
1155
+
1156
+ //Initialize PDF writer
1157
+ PdfWriter writer = new PdfWriter (outFile );
1158
+
1159
+ //Initialize PDF document
1160
+ PdfDocument pdf = new PdfDocument (writer );
1161
+ pdf .setDefaultPageSize (new PageSize (600 , 350 ));
1162
+ pdf .setTagged ();
1163
+
1164
+ // Initialize document
1165
+ Document document = new Document (pdf );
1166
+
1167
+ // Document layout is correct if COLLAPSING_MARGINS is not true
1168
+ document .setProperty (Property .COLLAPSING_MARGINS , true );
1169
+
1170
+ document .add (new Paragraph ("Some text\n Some text\n Some text\n Some text\n Some text\n Some text\n Some text" ));
1171
+ byte data [] = new byte [1 ];
1172
+ ImageData raw = ImageDataFactory .create (1 , 1 , 1 , 8 , data , null );
1173
+ Image image = new Image (raw ).setHeight (200 );
1174
+ Div div = new Div ();
1175
+ div .add (image );
1176
+ Div captionDiv = new Div ();
1177
+ captionDiv .add (new Paragraph ("Caption line 1\n " ).add ("line 2" ));
1178
+ div .add (captionDiv );
1179
+ div .setProperty (Property .FLOAT , FloatPropertyValue .RIGHT );
1180
+ div .setKeepTogether (true );
1181
+ //document.add(div);
1182
+ div = new Div ();
1183
+ image = new Image (raw ).setHeight (200 );
1184
+ div .add (image );
1185
+ div .add (captionDiv );
1186
+ div .setProperty (Property .FLOAT , FloatPropertyValue .LEFT );
1187
+ div .setKeepTogether (true );
1188
+ document .add (div );
1189
+ document .add (new Paragraph ("After float" ).setKeepWithNext (true ));
1190
+ document .add (new List (ListNumberingType .DECIMAL )
1191
+ .add ("List text\n List text\n List text\n List text" )
1192
+ .add ("List text\n List text\n List text" )
1193
+ .add ("List text\n List text" )
1194
+ .add ("List text\n List text" ));
1195
+
1196
+ document .close ();
1197
+
1198
+ Assert .assertNull (new CompareTool ().compareByContent (outFile , cmpFileName , destinationFolder , "diff16_" ));
1199
+ }
1099
1200
}
0 commit comments