private static void alignInlineContent(LayoutContext c, Box box, float ascent, float descent, VerticalAlignContext vaContext) { InlineBoxMeasurements measurements = vaContext.getParentMeasurements(); CalculatedStyle style = box.getStyle(); if (style.isLength(CSSName.VERTICAL_ALIGN)) { box.setY((int) (measurements.getBaseline() - ascent - style.getFloatPropertyProportionalTo(CSSName.VERTICAL_ALIGN, style.getLineHeight(c), c))); } else { IdentValue vAlign = style.getIdent(CSSName.VERTICAL_ALIGN); if (vAlign == IdentValue.BASELINE) { box.setY(Math.round(measurements.getBaseline() - ascent)); } else if (vAlign == IdentValue.TEXT_TOP) { box.setY(measurements.getTextTop()); } else if (vAlign == IdentValue.TEXT_BOTTOM) { box.setY(Math.round(measurements.getTextBottom() - descent - ascent)); } else if (vAlign == IdentValue.MIDDLE) { box.setY(Math.round((measurements.getBaseline() - measurements.getTextTop()) / 2 - (ascent + descent) / 2)); } else if (vAlign == IdentValue.SUPER) { box.setY(Math.round(measurements.getBaseline() - (3*ascent/2))); } else if (vAlign == IdentValue.SUB) { box.setY(Math.round(measurements.getBaseline() - ascent / 2)); } else { box.setY(Math.round(measurements.getBaseline() - ascent)); } } }
private static void alignInlineContent(LayoutContext c, Box box, float ascent, float descent, VerticalAlignContext vaContext) { InlineBoxMeasurements measurements = vaContext.getParentMeasurements(); CalculatedStyle style = box.getStyle(); if (style.isLength(CSSName.VERTICAL_ALIGN)) { box.setY((int) (measurements.getBaseline() - ascent - style.getFloatPropertyProportionalTo(CSSName.VERTICAL_ALIGN, style.getLineHeight(c), c))); } else { IdentValue vAlign = style.getIdent(CSSName.VERTICAL_ALIGN); if (vAlign == IdentValue.BASELINE) { box.setY(Math.round(measurements.getBaseline() - ascent)); } else if (vAlign == IdentValue.TEXT_TOP) { box.setY(measurements.getTextTop()); } else if (vAlign == IdentValue.TEXT_BOTTOM) { box.setY(Math.round(measurements.getTextBottom() - descent - ascent)); } else if (vAlign == IdentValue.MIDDLE) { // FIXME: findbugs, loss of precision, try / (float)2 box.setY(Math.round((measurements.getBaseline() - measurements.getTextTop()) / 2 - (ascent + descent) / 2)); } else if (vAlign == IdentValue.SUPER) { box.setY(Math.round(measurements.getBaseline() - (3*ascent/2))); } else if (vAlign == IdentValue.SUB) { box.setY(Math.round(measurements.getBaseline() - ascent / 2)); } else { box.setY(Math.round(measurements.getBaseline() - ascent)); } } }