@@ -76,14 +76,18 @@ public class LineRenderer extends AbstractRenderer {
76
76
77
77
protected float maxAscent ;
78
78
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
+
79
86
private float maxTextAscent ;
80
87
private float maxTextDescent ;
81
88
private float maxBlockAscent ;
82
89
private float maxBlockDescent ;
83
90
84
- // bidi levels
85
- protected byte [] levels ;
86
-
87
91
@ Override
88
92
public LineLayoutResult layout (LayoutContext layoutContext ) {
89
93
Rectangle layoutBox = layoutContext .getArea ().getBBox ().clone ();
@@ -256,9 +260,7 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
256
260
if (!childWidthWasReplaced ) {
257
261
if (isInlineBlockChild && childRenderer instanceof AbstractRenderer ) {
258
262
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 ;
262
264
// Decrease the calculated width by margins, paddings and borders so that even for 100% width the content definitely fits
263
265
// TODO DEVSIX-1174 fix depending on box-sizing
264
266
if (childBlockMinMaxWidth != null ) {
@@ -320,14 +322,12 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
320
322
}
321
323
322
324
maxAscent = Math .max (maxAscent , childAscent );
323
- // TODO treat images as blocks
324
325
if (childRenderer instanceof TextRenderer ) {
325
326
maxTextAscent = Math .max (maxTextAscent , childAscent );
326
327
} else if (!isChildFloating ) {
327
328
maxBlockAscent = Math .max (maxBlockAscent , childAscent );
328
329
}
329
330
maxDescent = Math .min (maxDescent , childDescent );
330
- // TODO treat images as blocks
331
331
if (childRenderer instanceof TextRenderer ) {
332
332
maxTextDescent = Math .min (maxTextDescent , childDescent );
333
333
} else if (!isChildFloating ) {
@@ -464,7 +464,6 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
464
464
}
465
465
466
466
if (baseDirection != null && baseDirection != BaseDirection .NO_BIDI ) {
467
- // TODO what about float inlines?
468
467
List <IRenderer > children = null ;
469
468
if (result .getStatus () == LayoutResult .PARTIAL ) {
470
469
children = result .getSplitRenderer ().getChildRenderers ();
@@ -477,7 +476,7 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
477
476
List <RendererGlyph > lineGlyphs = new ArrayList <>();
478
477
479
478
// 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.
481
480
Map <TextRenderer , IRenderer > insertAfter = new HashMap <>();
482
481
List <IRenderer > starterNonTextRenderers = new ArrayList <>();
483
482
TextRenderer lastTextRenderer = null ;
@@ -811,7 +810,10 @@ float getTopLeadingIndent(Leading leading) {
811
810
return (Math .max (leading .getValue (), maxBlockAscent - maxBlockDescent ) - occupiedArea .getBBox ().getHeight ()) / 2 ;
812
811
case Leading .MULTIPLIED :
813
812
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.
815
817
float textAscent = maxTextAscent == 0 && maxTextDescent == 0 && Math .abs (maxAscent ) + Math .abs (maxDescent ) != 0 && !containsImage () ? fontSize * 0.8f : maxTextAscent ;
816
818
float textDescent = maxTextAscent == 0 && maxTextDescent == 0 && Math .abs (maxAscent ) + Math .abs (maxDescent ) != 0 && !containsImage () ? -fontSize * 0.2f : maxTextDescent ;
817
819
return Math .max (textAscent + ((textAscent - textDescent ) * (leading .getValue () - 1 )) / 2 , maxBlockAscent ) - maxAscent ;
@@ -826,7 +828,10 @@ float getBottomLeadingIndent(Leading leading) {
826
828
return (Math .max (leading .getValue (), maxBlockAscent - maxBlockDescent ) - occupiedArea .getBBox ().getHeight ()) / 2 ;
827
829
case Leading .MULTIPLIED :
828
830
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.
830
835
float textAscent = maxTextAscent == 0 && maxTextDescent == 0 && !containsImage () ? fontSize * 0.8f : maxTextAscent ;
831
836
float textDescent = maxTextAscent == 0 && maxTextDescent == 0 && !containsImage () ? -fontSize * 0.2f : maxTextDescent ;
832
837
return Math .max (-textDescent + ((textAscent - textDescent ) * (leading .getValue () - 1 )) / 2 , -maxBlockDescent ) + maxDescent ;
0 commit comments