Skip to content

Commit c048abe

Browse files
ar3emiText-CI
authored andcommitted
Add html mode check for LineRenderer childs
DEVSIX-3837 Autoported commit. Original commit hash: [42962d3e7]
1 parent 429a648 commit c048abe

File tree

3 files changed

+87
-3
lines changed

3 files changed

+87
-3
lines changed

itext.tests/itext.layout.tests/itext/layout/renderer/LineRendererUnitTest.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,80 @@ public virtual void AdjustChildrenYLineImageChildHtmlModeTest() {
153153
NUnit.Framework.Assert.AreEqual(50f, lineRenderer.GetOccupiedAreaBBox().GetBottom(), EPS);
154154
NUnit.Framework.Assert.AreEqual(150.0, childImageRenderer.GetOccupiedAreaBBox().GetBottom(), EPS);
155155
}
156+
157+
[NUnit.Framework.Test]
158+
public virtual void HasChildRendererInHtmlModeTest() {
159+
LineRenderer lineRenderer = new LineRenderer();
160+
TextRenderer textRenderer1 = new TextRenderer(new Text("text1"));
161+
TextRenderer textRenderer2 = new TextRenderer(new Text("text2"));
162+
textRenderer2.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE);
163+
lineRenderer.AddChild(textRenderer1);
164+
lineRenderer.AddChild(textRenderer2);
165+
NUnit.Framework.Assert.IsTrue(lineRenderer.HasChildRendererInHtmlMode());
166+
}
167+
168+
[NUnit.Framework.Test]
169+
public virtual void ChildRendererInDefaultModeTest() {
170+
LineRenderer lineRenderer = new LineRenderer();
171+
TextRenderer textRenderer1 = new TextRenderer(new Text("text1"));
172+
TextRenderer textRenderer2 = new TextRenderer(new Text("text2"));
173+
textRenderer2.SetProperty(Property.RENDERING_MODE, RenderingMode.DEFAULT_LAYOUT_MODE);
174+
lineRenderer.AddChild(textRenderer1);
175+
lineRenderer.AddChild(textRenderer2);
176+
NUnit.Framework.Assert.IsFalse(lineRenderer.HasChildRendererInHtmlMode());
177+
}
178+
179+
[NUnit.Framework.Test]
180+
public virtual void HasChildRendererInHtmlModeNoChildrenTest() {
181+
LineRenderer lineRenderer = new LineRenderer();
182+
NUnit.Framework.Assert.IsFalse(lineRenderer.HasChildRendererInHtmlMode());
183+
}
184+
185+
[NUnit.Framework.Test]
186+
public virtual void LineRendererLayoutInHtmlModeWithLineHeightAndNoChildrenTest() {
187+
Document document = CreateDocument();
188+
LineRenderer lineRenderer = new LineRenderer();
189+
lineRenderer.SetParent(document.GetRenderer());
190+
lineRenderer.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE);
191+
lineRenderer.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateNormalValue());
192+
lineRenderer.Layout(new LayoutContext(CreateLayoutArea(1000, 1000)));
193+
NUnit.Framework.Assert.AreEqual(0f, lineRenderer.maxAscent, 0f);
194+
NUnit.Framework.Assert.AreEqual(0f, lineRenderer.maxDescent, 0f);
195+
}
196+
197+
[NUnit.Framework.Test]
198+
public virtual void LineRendererLayoutInHtmlModeWithLineHeightAndChildrenInDefaultModeTest() {
199+
Document document = CreateDocument();
200+
LineRenderer lineRenderer = new LineRenderer();
201+
lineRenderer.SetParent(document.GetRenderer());
202+
lineRenderer.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE);
203+
lineRenderer.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateFixedValue(50));
204+
TextRenderer textRenderer1 = new TextRenderer(new Text("text"));
205+
textRenderer1.SetProperty(Property.RENDERING_MODE, RenderingMode.DEFAULT_LAYOUT_MODE);
206+
TextRenderer textRenderer2 = new TextRenderer(new Text("text"));
207+
textRenderer2.SetProperty(Property.RENDERING_MODE, RenderingMode.DEFAULT_LAYOUT_MODE);
208+
lineRenderer.AddChild(textRenderer1);
209+
lineRenderer.AddChild(textRenderer2);
210+
lineRenderer.Layout(new LayoutContext(CreateLayoutArea(1000, 1000)));
211+
NUnit.Framework.Assert.AreEqual(10.3392f, lineRenderer.maxAscent, EPS);
212+
NUnit.Framework.Assert.AreEqual(-2.98079f, lineRenderer.maxDescent, EPS);
213+
}
214+
215+
[NUnit.Framework.Test]
216+
public virtual void LineRendererLayoutInHtmlModeWithLineHeightAndChildInHtmlModeTest() {
217+
Document document = CreateDocument();
218+
LineRenderer lineRenderer = new LineRenderer();
219+
lineRenderer.SetParent(document.GetRenderer());
220+
lineRenderer.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE);
221+
lineRenderer.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateFixedValue(50));
222+
TextRenderer textRenderer1 = new TextRenderer(new Text("text"));
223+
textRenderer1.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE);
224+
TextRenderer textRenderer2 = new TextRenderer(new Text("text"));
225+
lineRenderer.AddChild(textRenderer1);
226+
lineRenderer.AddChild(textRenderer2);
227+
lineRenderer.Layout(new LayoutContext(CreateLayoutArea(1000, 1000)));
228+
NUnit.Framework.Assert.AreEqual(28.67920f, lineRenderer.maxAscent, EPS);
229+
NUnit.Framework.Assert.AreEqual(-21.32080f, lineRenderer.maxDescent, EPS);
230+
}
156231
}
157232
}

itext/itext.layout/itext/layout/renderer/LineRenderer.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
9999
}
100100
occupiedArea = new LayoutArea(layoutContext.GetArea().GetPageNumber(), layoutBox.Clone().MoveUp(layoutBox.
101101
GetHeight()).SetHeight(0).SetWidth(0));
102+
UpdateChildrenParent();
102103
float curWidth = 0;
103104
if (RenderingMode.HTML_MODE.Equals(this.GetProperty<RenderingMode?>(Property.RENDERING_MODE)) && HasProperty
104-
(Property.LINE_HEIGHT)) {
105+
(Property.LINE_HEIGHT) && HasChildRendererInHtmlMode()) {
105106
float[] ascenderDescender = LineHeightHelper.GetActualAscenderDescender(this);
106107
maxAscent = ascenderDescender[0];
107108
maxDescent = ascenderDescender[1];
@@ -123,7 +124,6 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
123124
else {
124125
widthHandler = new MaxSumWidthHandler(minMaxWidth);
125126
}
126-
UpdateChildrenParent();
127127
ResolveChildrenFonts();
128128
int totalNumberOfTrimmedGlyphs = TrimFirst();
129129
BaseDirection? baseDirection = ApplyOtf();
@@ -919,6 +919,15 @@ public override MinMaxWidth GetMinMaxWidth() {
919919
return result.GetMinMaxWidth();
920920
}
921921

922+
internal virtual bool HasChildRendererInHtmlMode() {
923+
foreach (IRenderer childRenderer in childRenderers) {
924+
if (RenderingMode.HTML_MODE.Equals(childRenderer.GetProperty<RenderingMode?>(Property.RENDERING_MODE))) {
925+
return true;
926+
}
927+
}
928+
return false;
929+
}
930+
922931
internal virtual float GetTopLeadingIndent(Leading leading) {
923932
switch (leading.GetLeadingType()) {
924933
case Leading.FIXED: {

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9946d7d113c033e1df6c213230c42ff7ad140c5d
1+
42962d3e7cb76c51101448397741cc467b1d4d2f

0 commit comments

Comments
 (0)