Skip to content

Commit d8ad537

Browse files
committed
Add meaningful comments and remove TODOs
1 parent e71ea19 commit d8ad537

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

layout/src/main/java/com/itextpdf/layout/renderer/LineRenderer.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,18 @@ public class LineRenderer extends AbstractRenderer {
7676

7777
protected float maxAscent;
7878
protected float maxDescent;
79+
80+
// bidi levels
81+
protected byte[] levels;
82+
83+
// AbstractRenderer.EPS is not enough here
84+
private static final float MIN_MAX_WIDTH_CORRECTION_EPS = 0.001f;
85+
7986
private float maxTextAscent;
8087
private float maxTextDescent;
8188
private float maxBlockAscent;
8289
private float maxBlockDescent;
8390

84-
// bidi levels
85-
protected byte[] levels;
86-
8791
@Override
8892
public LineLayoutResult layout(LayoutContext layoutContext) {
8993
Rectangle layoutBox = layoutContext.getArea().getBBox().clone();
@@ -256,9 +260,7 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
256260
if (!childWidthWasReplaced) {
257261
if (isInlineBlockChild && childRenderer instanceof AbstractRenderer) {
258262
childBlockMinMaxWidth = ((AbstractRenderer)childRenderer).getMinMaxWidth(layoutContext.getArea().getBBox().getWidth());
259-
// TODO fix eps?
260-
float eps = 0.001f;
261-
float childMaxWidth = childBlockMinMaxWidth.getMaxWidth() + eps;
263+
float childMaxWidth = childBlockMinMaxWidth.getMaxWidth() + MIN_MAX_WIDTH_CORRECTION_EPS;
262264
// Decrease the calculated width by margins, paddings and borders so that even for 100% width the content definitely fits
263265
// TODO DEVSIX-1174 fix depending on box-sizing
264266
if (childBlockMinMaxWidth != null) {
@@ -320,14 +322,12 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
320322
}
321323

322324
maxAscent = Math.max(maxAscent, childAscent);
323-
// TODO treat images as blocks
324325
if (childRenderer instanceof TextRenderer) {
325326
maxTextAscent = Math.max(maxTextAscent, childAscent);
326327
} else if (!isChildFloating) {
327328
maxBlockAscent = Math.max(maxBlockAscent, childAscent);
328329
}
329330
maxDescent = Math.min(maxDescent, childDescent);
330-
// TODO treat images as blocks
331331
if (childRenderer instanceof TextRenderer) {
332332
maxTextDescent = Math.min(maxTextDescent, childDescent);
333333
} else if (!isChildFloating) {
@@ -464,7 +464,6 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
464464
}
465465

466466
if (baseDirection != null && baseDirection != BaseDirection.NO_BIDI) {
467-
// TODO what about float inlines?
468467
List<IRenderer> children = null;
469468
if (result.getStatus() == LayoutResult.PARTIAL) {
470469
children = result.getSplitRenderer().getChildRenderers();
@@ -477,7 +476,7 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
477476
List<RendererGlyph> lineGlyphs = new ArrayList<>();
478477

479478
// We shouldn't forget about images, float, inline-blocks that has to be inserted somewhere.
480-
// TODO determine correct place to insert this content
479+
// TODO determine correct place to insert this content. Probably consider inline floats separately.
481480
Map<TextRenderer, IRenderer> insertAfter = new HashMap<>();
482481
List<IRenderer> starterNonTextRenderers = new ArrayList<>();
483482
TextRenderer lastTextRenderer = null;
@@ -811,7 +810,10 @@ float getTopLeadingIndent(Leading leading) {
811810
return (Math.max(leading.getValue(), maxBlockAscent - maxBlockDescent) - occupiedArea.getBBox().getHeight()) / 2;
812811
case Leading.MULTIPLIED:
813812
float fontSize = (float)this.getPropertyAsFloat(Property.FONT_SIZE, 0f);
814-
// TODO contains image to be removed
813+
// In HTML, depending on whether <!DOCTYPE html> is present or not, and if present then depending on the version,
814+
// the behavior id different. In one case, bottom leading indent is added for images, in the other it is not added.
815+
// This is why !containsImage() is present below. Depending on the presence of this !containsImage() condition, the behavior changes
816+
// between the two possible scenarios in HTML.
815817
float textAscent = maxTextAscent == 0 && maxTextDescent == 0 && Math.abs(maxAscent) + Math.abs(maxDescent) != 0 && !containsImage() ? fontSize * 0.8f : maxTextAscent;
816818
float textDescent = maxTextAscent == 0 && maxTextDescent == 0 && Math.abs(maxAscent) + Math.abs(maxDescent) != 0 && !containsImage() ? -fontSize * 0.2f : maxTextDescent;
817819
return Math.max(textAscent + ((textAscent - textDescent) * (leading.getValue() - 1)) / 2, maxBlockAscent) - maxAscent;
@@ -826,7 +828,10 @@ float getBottomLeadingIndent(Leading leading) {
826828
return (Math.max(leading.getValue(), maxBlockAscent - maxBlockDescent) - occupiedArea.getBBox().getHeight()) / 2;
827829
case Leading.MULTIPLIED:
828830
float fontSize = (float)this.getPropertyAsFloat(Property.FONT_SIZE, 0f);
829-
// TODO contains image to be removed
831+
// In HTML, depending on whether <!DOCTYPE html> is present or not, and if present then depending on the version,
832+
// the behavior id different. In one case, bottom leading indent is added for images, in the other it is not added.
833+
// This is why !containsImage() is present below. Depending on the presence of this !containsImage() condition, the behavior changes
834+
// between the two possible scenarios in HTML.
830835
float textAscent = maxTextAscent == 0 && maxTextDescent == 0 && !containsImage() ? fontSize * 0.8f : maxTextAscent;
831836
float textDescent = maxTextAscent == 0 && maxTextDescent == 0 && !containsImage() ? -fontSize * 0.2f : maxTextDescent;
832837
return Math.max(-textDescent + ((textAscent - textDescent) * (leading.getValue() - 1)) / 2, -maxBlockDescent) + maxDescent;

0 commit comments

Comments
 (0)