Skip to content

Commit c25ffdd

Browse files
yulian-gaponenkoiText-CI
authored andcommitted
Fix margin-border-padding widths for floating Text min-max-width calculation
DEVSIX-3958 Autoported commit. Original commit hash: [a009bcd11]
1 parent 918cc99 commit c25ffdd

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

itext.tests/itext.layout.tests/itext/layout/renderer/TextRendererTest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,5 +324,23 @@ public virtual void OverflowWrapAnywhereItalicSimulationMinWidth() {
324324
float minWidthAndItalicSimulation = textRenderer.GetMinMaxWidth().GetMinWidth();
325325
NUnit.Framework.Assert.IsTrue(minWidthAndItalicSimulation > minWidthNoItalicSimulation);
326326
}
327+
328+
[NUnit.Framework.Test]
329+
public virtual void FloatingRightMinMaxWidth() {
330+
String longestWord = "float:right";
331+
String wholeText = "text with " + longestWord;
332+
TextRenderer textRenderer = new TextRenderer(new Text(wholeText));
333+
textRenderer.SetProperty(Property.FLOAT, FloatPropertyValue.RIGHT);
334+
textRenderer.SetParent(CreateDummyDocument().GetRenderer());
335+
PdfFont font = PdfFontFactory.CreateFont();
336+
int fontSize = 12;
337+
textRenderer.SetProperty(Property.FONT, font);
338+
textRenderer.SetProperty(Property.FONT_SIZE, UnitValue.CreatePointValue(fontSize));
339+
float expectedMaxWidth = font.GetWidth(wholeText, fontSize);
340+
float expectedMinWidth = font.GetWidth(longestWord, fontSize);
341+
MinMaxWidth minMaxWidth = textRenderer.GetMinMaxWidth();
342+
NUnit.Framework.Assert.AreEqual(expectedMinWidth, minMaxWidth.GetMinWidth(), 0.01f);
343+
NUnit.Framework.Assert.AreEqual(expectedMaxWidth, minMaxWidth.GetMaxWidth(), 0.01f);
344+
}
327345
}
328346
}

itext/itext.layout/itext/layout/renderer/TextRenderer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,14 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
178178
FloatingHelper.AdjustFloatedBlockLayoutBox(this, layoutBox, null, floatRendererAreas, floatPropertyValue,
179179
overflowX);
180180
}
181+
float preMarginBorderPaddingWidth = layoutBox.GetWidth();
181182
UnitValue[] margins = GetMargins();
182183
ApplyMargins(layoutBox, margins, false);
183184
Border[] borders = GetBorders();
184185
ApplyBorderBox(layoutBox, borders, false);
185186
UnitValue[] paddings = GetPaddings();
186187
ApplyPaddings(layoutBox, paddings, false);
187-
MinMaxWidth countedMinMaxWidth = new MinMaxWidth(area.GetBBox().GetWidth() - layoutBox.GetWidth());
188+
MinMaxWidth countedMinMaxWidth = new MinMaxWidth(preMarginBorderPaddingWidth - layoutBox.GetWidth());
188189
AbstractWidthHandler widthHandler;
189190
if (noSoftWrap) {
190191
widthHandler = new SumSumWidthHandler(countedMinMaxWidth);
@@ -888,7 +889,7 @@ public override void Draw(DrawContext drawContext) {
888889
if (horizontalScaling != null && horizontalScaling != 1) {
889890
canvas.SetHorizontalScaling((float)horizontalScaling * 100);
890891
}
891-
GlyphLine.IGlyphLineFilter filter = new _IGlyphLineFilter_953();
892+
GlyphLine.IGlyphLineFilter filter = new _IGlyphLineFilter_954();
892893
bool appearanceStreamLayout = true.Equals(GetPropertyAsBoolean(Property.APPEARANCE_STREAM_LAYOUT));
893894
if (GetReversedRanges() != null) {
894895
bool writeReversedChars = !appearanceStreamLayout;
@@ -950,8 +951,8 @@ public override void Draw(DrawContext drawContext) {
950951
}
951952
}
952953

953-
private sealed class _IGlyphLineFilter_953 : GlyphLine.IGlyphLineFilter {
954-
public _IGlyphLineFilter_953() {
954+
private sealed class _IGlyphLineFilter_954 : GlyphLine.IGlyphLineFilter {
955+
public _IGlyphLineFilter_954() {
955956
}
956957

957958
public bool Accept(Glyph glyph) {

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d3b3998013941ca7d12e5e1596f03edd9cbd2a5f
1+
a009bcd1103b8b23197dc80b02686acbe3fc9c0e

0 commit comments

Comments
 (0)