public float getAscent() { return _fm.getAscent() + _fm.getLeading(); }
/** * Draws a string at the specified position. * * @param text the string. * @param x the x-coordinate. * @param y the y-coordinate. */ @Override public void drawString(String text, float x, float y) { if (text == null) { throw new NullPointerException("Null 'text' argument."); } float fm = this.gc.getFontMetrics().getAscent(); this.gc.drawString(text, (int) x, (int) (y - fm), true); }
public int getBaselinePosition() { checkInitialized(); return SwtDeviceComponent.getFontMetrics(font).getAscent(); }
/** * @param fontMetrics */ public void setFontMetrics(FontMetrics fontMetrics) { if (fontMetrics != null) { _fontAscent = fontMetrics.getAscent(); _fontDescent = fontMetrics.getDescent(); _fontLeading = fontMetrics.getLeading(); // if (_fragments == null || _fragments.isEmpty()) // { // this._ascent = _fontAscent + _fontLeading; // this._descent = _fontDescent; // if (this._height < this._ascent + this._descent) // { // this._height = this._ascent + this._descent; // } // } } else { _fontAscent = 0; _fontDescent = 0; _fontLeading = 0; } }
/** * Returns the leading area of the font described by the * receiver. A font's <em>leading area</em> is the space * above its ascent which may include accents or other marks. * * @return the leading space of the font */ public int getLeading() { /* * HiHPI rounding problem (bug 490743 comment 17): * * API clients expect this invariant: * getHeight() == getLeading() + getAscent() + getDescent() * * Separate rounding of each RHS term can break the invariant. * * An additional problem is that ascent and descent are more important to * be as close as possible to the real value. Any necessary rounding * adjustment should go into leading, that's why compute this as a derived * value here: */ return getHeight() - getAscent() - getDescent(); }
public void drawString(OutputDevice outputDevice, String string, float x, float y) { GC gc = ((SWTOutputDevice) outputDevice).getGC(); FontMetrics metrics = gc.getFontMetrics(); y -= (metrics.getAscent() + metrics.getLeading()); gc.drawText(string, (int) x, (int) y, SWT.DRAW_TRANSPARENT); }
/** * Returns the difference between the baseline of the widget and the * baseline as specified by the font for <code>gc</code>. When drawing * line numbers, the returned bias should be added to obtain text lined up * on the correct base line of the text widget. * * @param gc the <code>GC</code> to get the font metrics from * @param widgetLine the widget line * @return the baseline bias to use when drawing text that is lined up with * <code>fCachedTextWidget</code> * @since 3.2 */ private int getBaselineBias(GC gc, int widgetLine) { /* * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62951 * widget line height may be more than the font height used for the * line numbers, since font styles (bold, italics...) can have larger * font metrics than the simple font used for the numbers. */ int offset= fCachedTextWidget.getOffsetAtLine(widgetLine); int widgetBaseline= fCachedTextWidget.getBaseline(offset); FontMetrics fm= gc.getFontMetrics(); int fontBaseline= fm.getAscent() + fm.getLeading(); int baselineBias= widgetBaseline - fontBaseline; return Math.max(0, baselineBias); }
static void setupFragment(TextFragmentBox frag, Font f, String s) { // if (frag.length != s.length()) // we don't skip whitespace here. since already truncated in // CSSTextLayout // while (frag.length > 0 && // Character.isElementContentWhitespace(s.charAt(frag.length - 1))) // frag.length--; frag.setTextData(s.substring(0, frag._length)); Dimension d = getStringExtents2(s.substring(0, frag._length), f); FontMetrics fm = getFontMetrics(f); frag.setHeight(fm.getHeight()); frag.setAscent(fm.getAscent() + fm.getLeading()); if (frag._length > 0 && Character.isWhitespace(s.charAt(frag._length - 1))) { frag._isLastCharWhitespace = true; } else { frag._isLastCharWhitespace = false; } frag.setWidth(d.width); }
/** * Returns the difference between the baseline of the widget and the * baseline as specified by the font for <code>gc</code>. When drawing * line numbers, the returned bias should be added to obtain text lined up * on the correct base line of the text widget. * * @param gc the <code>GC</code> to get the font metrics from * @param widgetLine the widget line * @return the baseline bias to use when drawing text that is lined up with * <code>fCachedTextWidget</code> * @since 3.2 */ private int getBaselineBias(GC gc, int widgetLine) { /* * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62951 * widget line height may be more than the font height used for the * line numbers, since font styles (bold, italics...) can have larger * font metrics than the simple font used for the numbers. */ int offset= fCachedTextWidget.getOffsetAtLine(widgetLine); int widgetBaseline= fCachedTextWidget.getBaseline(offset); FontMetrics fm= gc.getFontMetrics(); int fontBaseline= fm.getAscent() + fm.getLeading(); int baselineBias= widgetBaseline - fontBaseline; return Math.max(0, baselineBias); }
/** * Calculates the bounds of the text in the box as measured by the given * graphics context and font metrics. * * @param gc graphics context from which the measurements are done * @return point representing the dimensions of the text's bounds */ private Point calculateTextBounds(final GC gc) { final SWTGraphics2D g2 = new SWTGraphics2D(gc, Display.getDefault()); g2.setFont(font); final FontMetrics fm = g2.getSWTFontMetrics(); final Point textBounds = new Point(0, 0); boolean firstLine = true; final Iterator lineIterator = lines.iterator(); while (lineIterator.hasNext()) { String line = (String) lineIterator.next(); Point lineBounds = gc.stringExtent(line); if (firstLine) { textBounds.x = lineBounds.x; textBounds.y += fm.getAscent() + fm.getDescent() + fm.getLeading(); firstLine = false; } else { textBounds.x = Math.max(lineBounds.x, textBounds.x); textBounds.y += fm.getHeight(); } } return textBounds; }
/** * Returns the difference between the baseline of the widget and the * baseline as specified by the font for <code>gc</code>. When drawing * line numbers, the returned bias should be added to obtain text lined up * on the correct base line of the text widget. * * @param gc the <code>GC</code> to get the font metrics from * @param widgetLine the widget line * @return the baseline bias to use when drawing text that is lined up with * <code>fCachedTextWidget</code> * @since 3.3 */ private int getBaselineBias(GC gc, int widgetLine) { if (widgetLine == fWidget.getLineCount()) widgetLine--; /* * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62951 * widget line height may be more than the font height used for the * line numbers, since font styles (bold, italics...) can have larger * font metrics than the simple font used for the numbers. */ int offset= fWidget.getOffsetAtLine(widgetLine); int widgetBaseline= fWidget.getBaseline(offset); FontMetrics fm = gc.getFontMetrics(); int fontBaseline = fm.getAscent() + fm.getLeading(); int baselineBias= widgetBaseline - fontBaseline; return Math.max(0, baselineBias); }
/** * Returns the difference between the baseline of the widget and the * baseline as specified by the font for <code>gc</code>. When drawing * line numbers, the returned bias should be added to obtain text lined up * on the correct base line of the text widget. * * @param gc the <code>GC</code> to get the font metrics from * @param widgetLine the widget line * @return the baseline bias to use when drawing text that is lined up with * <code>fCachedTextWidget</code> * @since 3.3 */ private int getBaselineBias(GC gc, int widgetLine) { if (widgetLine == fWidget.getLineCount()) widgetLine--; /* * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62951 * widget line height may be more than the font height used for the * line numbers, since font styles (bold, italics...) can have larger * font metrics than the simple font used for the numbers. */ int offset= fWidget.getOffsetAtLine(widgetLine); int widgetBaseline= fWidget.getBaseline(offset); FontMetrics fm = gc.getFontMetrics(); int fontBaseline = fm.getAscent() + fm.getLeading(); int baselineBias= widgetBaseline - fontBaseline; return Math.max(0, baselineBias); }
/** * Draw string at widget offset. * * @param gc the GC * @param offset the widget offset * @param s the string to be drawn * @param fg the foreground color */ private void draw(GC gc, int offset, String s, Color fg) { // Compute baseline delta (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=165640) int baseline= fTextWidget.getBaseline(offset); FontMetrics fontMetrics= gc.getFontMetrics(); int fontBaseline= fontMetrics.getAscent() + fontMetrics.getLeading(); int baslineDelta= baseline - fontBaseline; Point pos= fTextWidget.getLocationAtOffset(offset); gc.setForeground(fg); gc.drawString(s, pos.x, pos.y + baslineDelta, true); }
/** * Draw string at widget offset. * * @param gc the GC * @param offset the widget offset * @param s the string to be drawn * @param fg the foreground color */ private void draw(GC gc, int offset, String s, Color fg) { // Compute baseline delta (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=165640) int baseline= fTextWidget.getBaseline(offset); FontMetrics fontMetrics= gc.getFontMetrics(); int fontBaseline= fontMetrics.getAscent() + fontMetrics.getLeading(); int baslineDelta= baseline - fontBaseline; Point pos= fTextWidget.getLocationAtOffset(offset); gc.setForeground(fg); gc.drawString(s, pos.x, pos.y + baslineDelta, true); }
FontMetrics metrics = layout.getLineMetrics(lineInParagraph); renderer.disposeTextLayout(layout); return metrics.getAscent() + metrics.getLeading();
FontMetrics metrics = layout.getLineMetrics(lineInParagraph); renderer.disposeTextLayout(layout); return metrics.getAscent() + metrics.getLeading();
FontMetrics metrics = layout.getLineMetrics(lineInParagraph); renderer.disposeTextLayout(layout); return metrics.getAscent() + metrics.getLeading();
FontMetrics metrics = layout.getLineMetrics(lineInParagraph); renderer.disposeTextLayout(layout); return metrics.getAscent() + metrics.getLeading();
printLayout.setAscent(metrics.getAscent() + metrics.getLeading()); printLayout.setDescent(metrics.getDescent()); String[] lineLabels = printOptions.lineLabels;
newy -= g.getFontMetrics().getAscent(); } else if ((anchor & javax.microedition.lcdui.Graphics.BOTTOM) != 0) { newy -= g.getFontMetrics().getHeight();