Skip to content

Commit 14cb2eb

Browse files
Remove floats skipping logic in span-wrapping: now floats break text sequence
DEVSIX-1448 Autoported commit. Original commit hash: [7645d539db]
1 parent 6c8ab95 commit 14cb2eb

9 files changed

+176
-155
lines changed

itext.tests/itext.layout.tests/itext/layout/renderer/TextRendererIntegrationTest.cs

Lines changed: 97 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -231,37 +231,34 @@ public virtual void WordSplitAcrossMultipleRenderersOverflowXVisible() {
231231
}
232232

233233
[NUnit.Framework.Test]
234-
public virtual void WordSplitAcrossMutipleTextRenderersWithinFloatingContainer() {
235-
String outFileName = destinationFolder + "wordSplitAcrossMutipleTextRenderersWithinFloatingContainer.pdf";
236-
String cmpFileName = sourceFolder + "cmp_wordSplitAcrossMutipleTextRenderersWithinFloatingContainer.pdf";
234+
public virtual void WordSplitRenderersWithFittingFloatingElementInBetween() {
235+
String outFileName = destinationFolder + "wordSplitRenderersWithFittingFloatingElementInBetween.pdf";
236+
String cmpFileName = sourceFolder + "cmp_wordSplitRenderersWithFittingFloatingElementInBetween.pdf";
237237
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
238238
Document doc = new Document(pdfDocument);
239239
doc.SetFontSize(20);
240-
Text oooooooooover = new Text("oooooooooover").SetFontColor(ColorConstants.LIGHT_GRAY);
241-
Text flooooo = new Text("flooooo").SetFontColor(ColorConstants.GRAY);
242-
Text ooooowNextWords = new Text("ooooow next words").SetFontColor(ColorConstants.DARK_GRAY);
243-
Paragraph floatingParagraph = new Paragraph().Add(oooooooooover).Add(flooooo).Add(ooooowNextWords).SetBackgroundColor
244-
(ColorConstants.CYAN).SetWidth(150).SetBorder(new SolidBorder(1));
245-
// TODO DEVSIX-1438 bring reviewer's attention: if overflow is set on the div, then forced split occurs.
246-
// is it expected?
247-
floatingParagraph.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE);
248-
floatingParagraph.SetProperty(Property.FLOAT, FloatPropertyValue.RIGHT);
249-
Text regularText = new Text("regular words regular words regular words regular words regular words regular "
250-
+ "words regular words regular words regular words");
251-
Paragraph regularParagraph = new Paragraph(regularText).SetBackgroundColor(ColorConstants.MAGENTA);
252-
Div div = new Div().Add(floatingParagraph).Add(regularParagraph).SetMaxWidth(300).SetHeight(300).SetBackgroundColor
253-
(ColorConstants.YELLOW);
254-
div.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE);
255-
doc.Add(div);
240+
Text reg = new Text("reg").SetFontColor(ColorConstants.LIGHT_GRAY);
241+
Text ul = new Text("ul").SetFontColor(ColorConstants.DARK_GRAY);
242+
Text aaaaaaaaaaaaaaaaaaaaaaati = new Text("aaaaaaaaaaaaaaaaaaaaaaati").SetFontColor(ColorConstants.GRAY);
243+
Text ngAndRestOfText = new Text("ng overflow text renderers with floating elements between them").SetFontColor
244+
(ColorConstants.RED);
245+
Div floatDiv = new Div().SetWidth(20).SetHeight(60).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetBorder
246+
(new SolidBorder(2));
247+
floatDiv.SetProperty(Property.FLOAT, FloatPropertyValue.RIGHT);
248+
Paragraph p = new Paragraph().Add(reg).Add(ul).Add(floatDiv).Add(aaaaaaaaaaaaaaaaaaaaaaati).Add(ngAndRestOfText
249+
).SetBackgroundColor(ColorConstants.CYAN).SetWidth(150).SetBorder(new SolidBorder(1));
250+
p.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE);
251+
doc.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE);
252+
doc.Add(p);
256253
doc.Close();
257254
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
258255
));
259256
}
260257

261258
[NUnit.Framework.Test]
262-
public virtual void WordSplitRenderersWithFloatingElementInsertedInBetween() {
263-
String outFileName = destinationFolder + "wordSplitRenderersWithFloatingElementInsertedInBetween.pdf";
264-
String cmpFileName = sourceFolder + "cmp_wordSplitRenderersWithFloatingElementInsertedInBetween.pdf";
259+
public virtual void WordSplitRenderersWithNotFittingFloatingElementInBetween() {
260+
String outFileName = destinationFolder + "wordSplitRenderersWithNotFittingFloatingElementInBetween.pdf";
261+
String cmpFileName = sourceFolder + "cmp_wordSplitRenderersWithNotFittingFloatingElementInBetween.pdf";
265262
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
266263
Document doc = new Document(pdfDocument);
267264
doc.SetFontSize(20);
@@ -271,7 +268,6 @@ public virtual void WordSplitRenderersWithFloatingElementInsertedInBetween() {
271268
floating.SetProperty(Property.FLOAT, FloatPropertyValue.RIGHT);
272269
Paragraph paragraph = new Paragraph().Add(loooooooooooo).Add(floating).Add(oooongWords).SetBackgroundColor
273270
(ColorConstants.YELLOW).SetWidth(150).SetBorder(new SolidBorder(1));
274-
// todo mention that it's crucial to set both overflow and rendering_mode!!!
275271
paragraph.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE);
276272
paragraph.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE);
277273
doc.Add(paragraph);
@@ -280,6 +276,84 @@ public virtual void WordSplitRenderersWithFloatingElementInsertedInBetween() {
280276
));
281277
}
282278

279+
[NUnit.Framework.Test]
280+
public virtual void WordSplitRenderersWithFittingFloatingInBetweenInSecondWord() {
281+
String outFileName = destinationFolder + "wordSplitRenderersWithFittingFloatingInBetweenInSecondWord.pdf";
282+
String cmpFileName = sourceFolder + "cmp_wordSplitRenderersWithFittingFloatingInBetweenInSecondWord.pdf";
283+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
284+
Document doc = new Document(pdfDocument);
285+
doc.SetFontSize(20);
286+
Text itsAndSpace = new Text("It's ");
287+
Text reg = new Text("reg").SetFontColor(ColorConstants.LIGHT_GRAY);
288+
Text ul = new Text("ul").SetFontColor(ColorConstants.DARK_GRAY);
289+
Text aaaaaaaaaaaaaaaaaaaaaaati = new Text("aaaaaaaaaaaaaaaaaaaaaaati").SetFontColor(ColorConstants.GRAY);
290+
Text ngAndRestOfText = new Text("ng overflow text renderers with floating elements between them").SetFontColor
291+
(ColorConstants.RED);
292+
Div floatDiv = new Div().SetWidth(20).SetHeight(60).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetBorder
293+
(new SolidBorder(2));
294+
floatDiv.SetProperty(Property.FLOAT, FloatPropertyValue.RIGHT);
295+
Paragraph p = new Paragraph().Add(itsAndSpace).Add(reg).Add(ul).Add(floatDiv).Add(aaaaaaaaaaaaaaaaaaaaaaati
296+
).Add(ngAndRestOfText).SetBackgroundColor(ColorConstants.CYAN).SetWidth(150).SetBorder(new SolidBorder
297+
(1));
298+
p.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE);
299+
doc.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE);
300+
doc.Add(p);
301+
doc.Close();
302+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
303+
));
304+
}
305+
306+
[NUnit.Framework.Test]
307+
public virtual void WordSplitRenderersWithOverflowedFloatingElementInBetween() {
308+
String outFileName = destinationFolder + "wordSplitRenderersWithOverflowedFloatingElementInBetween.pdf";
309+
String cmpFileName = sourceFolder + "cmp_wordSplitRenderersWithOverflowedFloatingElementInBetween.pdf";
310+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
311+
Document doc = new Document(pdfDocument);
312+
doc.SetFontSize(20);
313+
Text reg = new Text("reg").SetFontColor(ColorConstants.LIGHT_GRAY);
314+
Text ul = new Text("ul").SetFontColor(ColorConstants.DARK_GRAY);
315+
Text aaaaaaaaaaaaaaaaaaaaaaati = new Text("aaaaaaaaaaaaaaaaaaaaaaati").SetFontColor(ColorConstants.GRAY);
316+
Text ngAndRestOfText = new Text("ng overflow text renderers with floating elements between them").SetFontColor
317+
(ColorConstants.RED);
318+
Div floatDiv = new Div().SetWidth(20).SetHeight(60).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetBorder
319+
(new SolidBorder(2));
320+
floatDiv.SetProperty(Property.FLOAT, FloatPropertyValue.RIGHT);
321+
Paragraph p = new Paragraph().Add(reg).Add(ul).Add(aaaaaaaaaaaaaaaaaaaaaaati).Add(floatDiv).Add(ngAndRestOfText
322+
).SetBackgroundColor(ColorConstants.CYAN).SetWidth(150).SetBorder(new SolidBorder(1));
323+
p.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE);
324+
doc.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE);
325+
doc.Add(p);
326+
doc.Close();
327+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
328+
));
329+
}
330+
331+
[NUnit.Framework.Test]
332+
public virtual void WordSplitAcrossMutipleTextRenderersWithinFloatingContainer() {
333+
String outFileName = destinationFolder + "wordSplitAcrossMutipleTextRenderersWithinFloatingContainer.pdf";
334+
String cmpFileName = sourceFolder + "cmp_wordSplitAcrossMutipleTextRenderersWithinFloatingContainer.pdf";
335+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
336+
Document doc = new Document(pdfDocument);
337+
doc.SetFontSize(20);
338+
Text oooooooooover = new Text("oooooooooover").SetFontColor(ColorConstants.LIGHT_GRAY);
339+
Text flooooo = new Text("flooooo").SetFontColor(ColorConstants.GRAY);
340+
Text ooooowNextWords = new Text("ooooow next words").SetFontColor(ColorConstants.DARK_GRAY);
341+
Paragraph floatingParagraph = new Paragraph().Add(oooooooooover).Add(flooooo).Add(ooooowNextWords).SetBackgroundColor
342+
(ColorConstants.CYAN).SetWidth(150).SetBorder(new SolidBorder(1));
343+
floatingParagraph.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE);
344+
floatingParagraph.SetProperty(Property.FLOAT, FloatPropertyValue.RIGHT);
345+
Text regularText = new Text("regular words regular words regular words regular words regular words regular "
346+
+ "words regular words regular words regular words");
347+
Paragraph regularParagraph = new Paragraph(regularText).SetBackgroundColor(ColorConstants.MAGENTA);
348+
Div div = new Div().Add(floatingParagraph).Add(regularParagraph).SetMaxWidth(300).SetHeight(300).SetBackgroundColor
349+
(ColorConstants.YELLOW);
350+
div.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE);
351+
doc.Add(div);
352+
doc.Close();
353+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
354+
));
355+
}
356+
283357
[NUnit.Framework.Test]
284358
public virtual void WordSplitAcrossRenderersWithPrecedingImageRenderer() {
285359
String outFileName = destinationFolder + "wordSplitAcrossRenderersWithPrecedingImageRenderer.pdf";

itext.tests/itext.layout.tests/itext/layout/renderer/WordWrapUnitTest.cs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public virtual void OneThaiWordSplitAcrossMultipleRenderersGetIndexAndLayoutResu
282282
}
283283
}
284284
LineRenderer.LastFittingChildRendererData lastFittingChildRendererData = lineRenderer.GetIndexAndLayoutResultOfTheLastTextRendererContainingSpecialScripts
285-
(THAI_WORD.Length + 1, specialScriptLayoutResults, false, new List<IRenderer>(), true);
285+
(THAI_WORD.Length + 1, specialScriptLayoutResults, false, true);
286286
NUnit.Framework.Assert.AreEqual(5, lastFittingChildRendererData.childIndex);
287287
NUnit.Framework.Assert.AreEqual(LayoutResult.NOTHING, lastFittingChildRendererData.childLayoutResult.GetStatus
288288
());
@@ -312,7 +312,7 @@ public virtual void MultipleFloatsFollowedByUnfittingThaiRenderer() {
312312
specialScriptLayoutResults.Put(indexOfThaiRenderer, new LayoutResult(LayoutResult.NOTHING, layoutArea, null
313313
, null));
314314
LineRenderer.LastFittingChildRendererData lastFittingChildRendererData = lineRenderer.GetIndexAndLayoutResultOfTheLastTextRendererContainingSpecialScripts
315-
(indexOfThaiRenderer, specialScriptLayoutResults, false, new List<IRenderer>(), true);
315+
(indexOfThaiRenderer, specialScriptLayoutResults, false, true);
316316
NUnit.Framework.Assert.AreEqual(indexOfThaiRenderer, lastFittingChildRendererData.childIndex);
317317
NUnit.Framework.Assert.AreEqual(LayoutResult.NOTHING, lastFittingChildRendererData.childLayoutResult.GetStatus
318318
());
@@ -349,7 +349,7 @@ public virtual void TrailingRightSideSpacesGetIndexAndLayoutResult() {
349349
}
350350
}
351351
LineRenderer.LastFittingChildRendererData lastFittingChildRendererData = lineRenderer.GetIndexAndLayoutResultOfTheLastTextRendererContainingSpecialScripts
352-
(THAI_WORD.Length - 1, specialScriptLayoutResults, false, new List<IRenderer>(), true);
352+
(THAI_WORD.Length - 1, specialScriptLayoutResults, false, true);
353353
NUnit.Framework.Assert.AreEqual(THAI_WORD.Length - 1, lastFittingChildRendererData.childIndex);
354354
NUnit.Framework.Assert.AreEqual(specialScriptLayoutResults.Get(THAI_WORD.Length - 1), lastFittingChildRendererData
355355
.childLayoutResult);
@@ -666,29 +666,6 @@ public virtual void CurWidthLayoutResultPartial() {
666666
NUnit.Framework.Assert.AreEqual(widthOfNewPartialResult + simpleWidth, decrement, 0.00001);
667667
}
668668

669-
[NUnit.Framework.Test]
670-
public virtual void UpdateFloatsOverflowedToNextLine() {
671-
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new MemoryStream()));
672-
Document document = new Document(pdfDocument);
673-
LineRenderer lineRenderer = new LineRenderer();
674-
lineRenderer.SetParent(document.GetRenderer());
675-
IList<IRenderer> floatsOverflowedToNextLineIRenderers = new List<IRenderer>();
676-
ICollection<int> indicesOfFloats = new HashSet<int>();
677-
IRenderer onlyFloatToRemain;
678-
for (int i = 0; i < 6; i++) {
679-
TextRenderer textRenderer = new TextRenderer(new iText.Layout.Element.Text("text"));
680-
if (i % 2 == 0) {
681-
floatsOverflowedToNextLineIRenderers.Add(textRenderer);
682-
indicesOfFloats.Add(i);
683-
}
684-
lineRenderer.AddChild(textRenderer);
685-
}
686-
onlyFloatToRemain = lineRenderer.GetChildRenderers()[0];
687-
lineRenderer.UpdateFloatsOverflowedToNextLine(floatsOverflowedToNextLineIRenderers, indicesOfFloats, 1);
688-
NUnit.Framework.Assert.AreEqual(1, floatsOverflowedToNextLineIRenderers.Count);
689-
NUnit.Framework.Assert.AreEqual(onlyFloatToRemain, floatsOverflowedToNextLineIRenderers[0]);
690-
}
691-
692669
[NUnit.Framework.Test]
693670
public virtual void PossibleBreakWithinActualText() {
694671
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new MemoryStream()));

0 commit comments

Comments
 (0)