Skip to content

Commit f4ba0a8

Browse files
Snipxitext-teamcity
authored andcommitted
Initial implementation for restoring non-text inline element during bidi reordering
DEVSIX-1053 Autoported commit. Original commit hash: [6992094]
1 parent 9881912 commit f4ba0a8

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

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

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
381381
if (children != null) {
382382
bool newLineFound = false;
383383
IList<LineRenderer.RendererGlyph> lineGlyphs = new List<LineRenderer.RendererGlyph>();
384+
// We shouldn't forget about images, float, inline-blocks that has to be inserted somewhere.
385+
// TODO determine correct place to insert this content
386+
IDictionary<TextRenderer, IRenderer> insertAfter = new Dictionary<TextRenderer, IRenderer>();
387+
IList<IRenderer> starterNonTextRenderers = new List<IRenderer>();
388+
TextRenderer lastTextRenderer = null;
384389
foreach (IRenderer child in children) {
385390
if (newLineFound) {
386391
break;
@@ -394,6 +399,15 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
394399
}
395400
lineGlyphs.Add(new LineRenderer.RendererGlyph(childLine.Get(i), (TextRenderer)child));
396401
}
402+
lastTextRenderer = (TextRenderer)child;
403+
}
404+
else {
405+
if (lastTextRenderer != null) {
406+
insertAfter.Put(lastTextRenderer, child);
407+
}
408+
else {
409+
starterNonTextRenderers.Add(child);
410+
}
397411
}
398412
}
399413
byte[] lineLevels = new byte[lineGlyphs.Count];
@@ -407,10 +421,20 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
407421
int initialPos = 0;
408422
bool reversed = false;
409423
int offset = 0;
424+
// Insert non-text renderers
425+
foreach (IRenderer child in starterNonTextRenderers) {
426+
children.Add(child);
427+
}
410428
while (pos < lineGlyphs.Count) {
411429
IRenderer renderer = lineGlyphs[pos].renderer;
412430
TextRenderer newRenderer = new TextRenderer((TextRenderer)renderer).RemoveReversedRanges();
413431
children.Add(newRenderer);
432+
// Insert non-text renderers
433+
if ((pos == lineGlyphs.Count - 1 || lineGlyphs[pos + 1].renderer != renderer) && insertAfter.ContainsKey((
434+
TextRenderer)renderer)) {
435+
children.Add(insertAfter.Get((TextRenderer)renderer));
436+
insertAfter.JRemove((TextRenderer)renderer);
437+
}
414438
newRenderer.line = new GlyphLine(newRenderer.line);
415439
IList<Glyph> replacementGlyphs = new List<Glyph>();
416440
while (pos < lineGlyphs.Count && lineGlyphs[pos].renderer == renderer) {
@@ -442,10 +466,17 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
442466
}
443467
float currentXPos = occupiedArea.GetBBox().GetLeft();
444468
foreach (IRenderer child in children) {
445-
float currentWidth = ((TextRenderer)child).CalculateLineWidth();
446-
float[] margins = ((TextRenderer)child).GetMargins();
447-
currentWidth += margins[1] + margins[3];
448-
((TextRenderer)child).occupiedArea.GetBBox().SetX(currentXPos).SetWidth(currentWidth);
469+
float currentWidth;
470+
if (child is TextRenderer) {
471+
currentWidth = ((TextRenderer)child).CalculateLineWidth();
472+
float[] margins = ((TextRenderer)child).GetMargins();
473+
currentWidth += margins[1] + margins[3];
474+
((TextRenderer)child).occupiedArea.GetBBox().SetX(currentXPos).SetWidth(currentWidth);
475+
}
476+
else {
477+
currentWidth = child.GetOccupiedArea().GetBBox().GetWidth();
478+
child.GetOccupiedArea().GetBBox().SetX(currentXPos);
479+
}
449480
currentXPos += currentWidth;
450481
}
451482
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6b9816bbd26a6da2577d741c9e4f7f8cdaf7e249
1+
69920942204fdf9be8055cb6381af0d11e5c56e4

0 commit comments

Comments
 (0)