public float getLineHeight(CssContext ctx) { if (! _lineHeightResolved) { if (isIdent(CSSName.LINE_HEIGHT, IdentValue.NORMAL)) { float lineHeight1 = getFont(ctx).size * 1.1f; // Make sure rasterized characters will (probably) fit inside // the line box FSFontMetrics metrics = getFSFontMetrics(ctx); float lineHeight2 = (float)Math.ceil(metrics.getDescent() + Math.round(metrics.getAscent())); _lineHeight = Math.max(lineHeight1, lineHeight2); } else if (isLength(CSSName.LINE_HEIGHT)) { //could be more elegant, I suppose _lineHeight = getFloatPropertyProportionalHeight(CSSName.LINE_HEIGHT, 0, ctx); } else { //must be a number _lineHeight = getFont(ctx).size * valueByName(CSSName.LINE_HEIGHT).asFloat(); } _lineHeightResolved = true; } return _lineHeight; }
public float getLineHeight(CssContext ctx) { if (! _lineHeightResolved) { if (isIdent(CSSName.LINE_HEIGHT, IdentValue.NORMAL)) { float lineHeight1 = getFont(ctx).size * 1.1f; // Make sure rasterized characters will (probably) fit inside // the line box FSFontMetrics metrics = getFSFontMetrics(ctx); float lineHeight2 = (float)Math.ceil(metrics.getDescent() + Math.round(metrics.getAscent())); _lineHeight = Math.max(lineHeight1, lineHeight2); } else if (isLength(CSSName.LINE_HEIGHT)) { //could be more elegant, I suppose _lineHeight = getFloatPropertyProportionalHeight(CSSName.LINE_HEIGHT, 0, ctx); } else { //must be a number _lineHeight = getFont(ctx).size * valueByName(CSSName.LINE_HEIGHT).asFloat(); } _lineHeightResolved = true; } return _lineHeight; }
private static InlineBoxMeasurements getInitialMeasurements( LayoutContext c, Box container, FSFontMetrics strutM) { float lineHeight = container.getStyle().getLineHeight(c); int halfLeading = Math.round((lineHeight - container.getStyle().getFont(c).size) / 2); if (halfLeading > 0) { halfLeading = Math.round((lineHeight - (strutM.getDescent() + strutM.getAscent())) / 2); } InlineBoxMeasurements measurements = new InlineBoxMeasurements(); measurements.setBaseline((int) (halfLeading + strutM.getAscent())); measurements.setTextTop((int) halfLeading); measurements.setTextBottom((int) (measurements.getBaseline() + strutM.getDescent())); measurements.setInlineTop((int) halfLeading); measurements.setInlineBottom((int) (halfLeading + lineHeight)); return measurements; }
private static InlineBoxMeasurements getInitialMeasurements( LayoutContext c, Box container, FSFontMetrics strutM) { float lineHeight = container.getStyle().getLineHeight(c); int halfLeading = Math.round((lineHeight - container.getStyle().getFont(c).size) / 2); if (halfLeading > 0) { halfLeading = Math.round((lineHeight - (strutM.getDescent() + strutM.getAscent())) / 2); } InlineBoxMeasurements measurements = new InlineBoxMeasurements(); measurements.setBaseline((int) (halfLeading + strutM.getAscent())); measurements.setTextTop(halfLeading); measurements.setTextBottom((int) (measurements.getBaseline() + strutM.getDescent())); measurements.setInlineTop(halfLeading); measurements.setInlineBottom((int) (halfLeading + lineHeight)); return measurements; }
public static StrutMetrics createDefaultStrutMetrics(LayoutContext c, Box container) { FSFontMetrics strutM = container.getStyle().getFSFontMetrics(c); InlineBoxMeasurements measurements = getInitialMeasurements(c, container, strutM); return new StrutMetrics( strutM.getAscent(), measurements.getBaseline(), strutM.getDescent()); }
public static StrutMetrics createDefaultStrutMetrics(LayoutContext c, Box container) { FSFontMetrics strutM = container.getStyle().getFSFontMetrics(c); InlineBoxMeasurements measurements = getInitialMeasurements(c, container, strutM); return new StrutMetrics( strutM.getAscent(), measurements.getBaseline(), strutM.getDescent()); }
baseline + (int)fm.getDescent() - decoration.getThickness(); if (decoration.getOffset() > maxOffset) { decoration.setOffset(maxOffset);
baseline + (int)fm.getDescent() - decoration.getThickness(); if (decoration.getOffset() > maxOffset) { decoration.setOffset(maxOffset);
public void calculateHeight(LayoutContext c) { BorderPropertySet border = getBorder(c); RectPropertySet padding = getPadding(c); FSFontMetrics metrics = getStyle().getFSFontMetrics(c); setHeight((int)Math.ceil(border.top() + padding.top() + metrics.getAscent() + metrics.getDescent() + padding.bottom() + border.bottom())); }
public void calculateHeight(LayoutContext c) { BorderPropertySet border = getBorder(c); RectPropertySet padding = getPadding(c); FSFontMetrics metrics = getStyle().getFSFontMetrics(c); setHeight((int)Math.ceil(border.top() + padding.top() + metrics.getAscent() + metrics.getDescent() + padding.bottom() + border.bottom())); }
private void drawFontMetrics(RenderingContext c, InlineText inlineText) { InlineLayoutBox iB = inlineText.getParent(); String text = inlineText.getSubstring(); setColor(new FSRGBColor(0xFF, 0x33, 0xFF)); FSFontMetrics fm = iB.getStyle().getFSFontMetrics(null); int width = c.getTextRenderer().getWidth( c.getFontContext(), iB.getStyle().getFSFont(c), text); int x = iB.getAbsX() + inlineText.getX(); int y = iB.getAbsY() + iB.getBaseline(); drawLine(x, y, x + width, y); y += (int) Math.ceil(fm.getDescent()); drawLine(x, y, x + width, y); y -= (int) Math.ceil(fm.getDescent()); y -= (int) Math.ceil(fm.getAscent()); drawLine(x, y, x + width, y); }
private void drawFontMetrics(RenderingContext c, InlineText inlineText) { InlineLayoutBox iB = inlineText.getParent(); String text = inlineText.getSubstring(); setColor(new FSRGBColor(0xFF, 0x33, 0xFF)); FSFontMetrics fm = iB.getStyle().getFSFontMetrics(null); int width = c.getTextRenderer().getWidth( c.getFontContext(), iB.getStyle().getFSFont(c), text); int x = iB.getAbsX() + inlineText.getX(); int y = iB.getAbsY() + iB.getBaseline(); drawLine(x, y, x + width, y); y += (int) Math.ceil(fm.getDescent()); drawLine(x, y, x + width, y); y -= (int) Math.ceil(fm.getDescent()); y -= (int) Math.ceil(fm.getAscent()); drawLine(x, y, x + width, y); }
private static InlineBoxMeasurements calculateInlineMeasurements(LayoutContext c, InlineLayoutBox iB, VerticalAlignContext vaContext) { FSFontMetrics fm = iB.getStyle().getFSFontMetrics(c); CalculatedStyle style = iB.getStyle(); float lineHeight = style.getLineHeight(c); int halfLeading = Math.round((lineHeight - iB.getStyle().getFont(c).size) / 2); if (halfLeading > 0) { halfLeading = Math.round((lineHeight - (fm.getDescent() + fm.getAscent())) / 2); } iB.setBaseline(Math.round(fm.getAscent())); alignInlineContent(c, iB, fm.getAscent(), fm.getDescent(), vaContext); List decorations = calculateTextDecorations(iB, iB.getBaseline(), fm); if (decorations != null) { iB.setTextDecorations(decorations); } InlineBoxMeasurements result = new InlineBoxMeasurements(); result.setBaseline(iB.getY() + iB.getBaseline()); result.setInlineTop(iB.getY() - halfLeading); result.setInlineBottom(Math.round(result.getInlineTop() + lineHeight)); result.setTextTop(iB.getY()); result.setTextBottom((int) (result.getBaseline() + fm.getDescent())); RectPropertySet padding = iB.getPadding(c); BorderPropertySet border = iB.getBorder(c); result.setPaintingTop((int)Math.floor(iB.getY() - border.top() - padding.top())); result.setPaintingBottom((int)Math.ceil(iB.getY() + fm.getAscent() + fm.getDescent() + border.bottom() + padding.bottom())); return result; }
if (halfLeading > 0) { halfLeading = Math.round((lineHeight - (fm.getDescent() + fm.getAscent())) / 2); alignInlineContent(c, iB, fm.getAscent(), fm.getDescent(), vaContext); List decorations = calculateTextDecorations(iB, iB.getBaseline(), fm); if (decorations != null) { result.setInlineBottom(Math.round(result.getInlineTop() + lineHeight)); result.setTextTop(iB.getY()); result.setTextBottom((int) (result.getBaseline() + fm.getDescent())); fm.getAscent() + fm.getDescent() + border.bottom() + padding.bottom()));