Skip to content

Commit 617d1ef

Browse files
Snipxitext-teamcity
authored andcommitted
Generalize logic of bidi reordering for non-text elements. Minor refactoring
DEVSIX-1053 Autoported commit. Original commit hash: [8f20ec7]
1 parent e98b952 commit 617d1ef

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

itext/itext.layout/itext/layout/renderer/AbstractRenderer.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,9 +713,6 @@ protected internal virtual void AddAllProperties(IDictionary<int, Object> proper
713713
}
714714

715715
protected internal virtual float? GetLastYLineRecursively() {
716-
if (childRenderers.Count == 0) {
717-
return null;
718-
}
719716
for (int i = childRenderers.Count - 1; i >= 0; i--) {
720717
IRenderer child = childRenderers[i];
721718
if (child is iText.Layout.Renderer.AbstractRenderer) {

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -237,24 +237,21 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
237237
bool isInlineBlockChild = IsInlineBlockChild(childRenderer);
238238
if (!childWidthWasReplaced) {
239239
if (isInlineBlockChild && childRenderer is AbstractRenderer) {
240-
childBlockMinMaxWidth = ((AbstractRenderer)childRenderer).GetMinMaxWidth(layoutContext.GetArea().GetBBox()
241-
.GetWidth());
240+
childBlockMinMaxWidth = ((AbstractRenderer)childRenderer).GetMinMaxWidth(MinMaxWidthUtils.GetMax());
242241
float childMaxWidth = childBlockMinMaxWidth.GetMaxWidth() + MIN_MAX_WIDTH_CORRECTION_EPS;
243242
// Decrease the calculated width by margins, paddings and borders so that even for 100% width the content definitely fits
244243
// TODO DEVSIX-1174 fix depending on box-sizing
245-
if (childBlockMinMaxWidth != null) {
246-
if (childMaxWidth > bbox.GetWidth() && bbox.GetWidth() != layoutContext.GetArea().GetBBox().GetWidth()) {
247-
childResult = new LineLayoutResult(LayoutResult.NOTHING, null, null, childRenderer, childRenderer);
248-
}
249-
else {
250-
if (bbox.GetWidth() == layoutContext.GetArea().GetBBox().GetWidth() && childBlockMinMaxWidth.GetMinWidth()
251-
> layoutContext.GetArea().GetBBox().GetWidth()) {
252-
LoggerFactory.GetLogger(typeof(LineRenderer)).Warn(iText.IO.LogMessageConstant.INLINE_BLOCK_ELEMENT_WILL_BE_CLIPPED
253-
);
254-
childRenderer.SetProperty(Property.FORCED_PLACEMENT, true);
255-
}
256-
bbox.SetWidth(childMaxWidth);
244+
if (childMaxWidth > bbox.GetWidth() && bbox.GetWidth() != layoutContext.GetArea().GetBBox().GetWidth()) {
245+
childResult = new LineLayoutResult(LayoutResult.NOTHING, null, null, childRenderer, childRenderer);
246+
}
247+
else {
248+
if (bbox.GetWidth() == layoutContext.GetArea().GetBBox().GetWidth() && childBlockMinMaxWidth.GetMinWidth()
249+
> layoutContext.GetArea().GetBBox().GetWidth()) {
250+
LoggerFactory.GetLogger(typeof(LineRenderer)).Warn(iText.IO.LogMessageConstant.INLINE_BLOCK_ELEMENT_WILL_BE_CLIPPED
251+
);
252+
childRenderer.SetProperty(Property.FORCED_PLACEMENT, true);
257253
}
254+
bbox.SetWidth(Math.Min(childMaxWidth, layoutContext.GetArea().GetBBox().GetWidth()));
258255
}
259256
}
260257
}
@@ -480,7 +477,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
480477
IList<LineRenderer.RendererGlyph> lineGlyphs = new List<LineRenderer.RendererGlyph>();
481478
// We shouldn't forget about images, float, inline-blocks that has to be inserted somewhere.
482479
// TODO determine correct place to insert this content. Probably consider inline floats separately.
483-
IDictionary<TextRenderer, IRenderer> insertAfter = new Dictionary<TextRenderer, IRenderer>();
480+
IDictionary<TextRenderer, IList<IRenderer>> insertAfter = new Dictionary<TextRenderer, IList<IRenderer>>();
484481
IList<IRenderer> starterNonTextRenderers = new List<IRenderer>();
485482
TextRenderer lastTextRenderer = null;
486483
foreach (IRenderer child in children) {
@@ -500,7 +497,10 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
500497
}
501498
else {
502499
if (lastTextRenderer != null) {
503-
insertAfter.Put(lastTextRenderer, child);
500+
if (!insertAfter.ContainsKey(lastTextRenderer)) {
501+
insertAfter.Put(lastTextRenderer, new List<IRenderer>());
502+
}
503+
insertAfter.Get(lastTextRenderer).Add(child);
504504
}
505505
else {
506506
starterNonTextRenderers.Add(child);
@@ -528,7 +528,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
528528
children.Add(newRenderer);
529529
// Insert non-text renderers
530530
if (insertAfter.ContainsKey((TextRenderer)renderer)) {
531-
children.Add(insertAfter.Get((TextRenderer)renderer));
531+
children.AddAll(insertAfter.Get((TextRenderer)renderer));
532532
insertAfter.JRemove((TextRenderer)renderer);
533533
}
534534
newRenderer.line = new GlyphLine(newRenderer.line);

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d8ad5373ea5e46537543a246ee837dc1a00e662f
1+
8f20ec717f5590d6e03e8a39c277ad2fd5d3de85

0 commit comments

Comments
 (0)