public float getAscent() { return _fm.getAscent() + _fm.getLeading(); }
/** * @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; } }
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); }
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); }
/** * 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; }
private void layoutWithoutWrapping(GC gc, int width, Locator locator, boolean selected, FontMetrics fm, int lineHeight, int descent) { Point extent = gc.textExtent(text); int ewidth = extent.x; if (isSelectable()) ewidth += 1; if (locator.x + ewidth > width-locator.marginWidth) { // new line locator.resetCaret(); locator.y += locator.rowHeight; locator.rowHeight = 0; locator.rowCounter++; } int ly = locator.getBaseline(fm.getHeight() - fm.getLeading()); //int lineY = ly + lineHeight - descent + 1; Rectangle br = new Rectangle(locator.x, ly, ewidth, lineHeight - descent + 3); areaRectangles.add(new AreaRectangle(br, 0, -1)); locator.x += ewidth; locator.width = ewidth; locator.rowHeight = Math.max(locator.rowHeight, extent.y); }
private void layoutWithoutWrapping(GC gc, int width, Locator locator, boolean selected, FontMetrics fm, int lineHeight, int descent) { Point extent = gc.textExtent(text); int ewidth = extent.x; if (isSelectable()) ewidth += 1; if (locator.x + ewidth > width-locator.marginWidth) { // new line locator.resetCaret(); locator.y += locator.rowHeight; locator.rowHeight = 0; locator.rowCounter++; } int ly = locator.getBaseline(fm.getHeight() - fm.getLeading()); //int lineY = ly + lineHeight - descent + 1; Rectangle br = new Rectangle(locator.x, ly, ewidth, lineHeight - descent + 3); areaRectangles.add(new AreaRectangle(br, 0, -1)); locator.x += ewidth; locator.width = ewidth; locator.rowHeight = Math.max(locator.rowHeight, extent.y); }
/** * 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); }
public void startContainerLayout( Composite container, SwtMetawidget metawidget ) { container.setData( MigLayout.class.getName(), null ); State state = getState( container ); // The entire layout should fill both horizontally and vertically, // with no insets. This allows us to be properly nested, as well as // embedded within existing UIs, without alignment problems LC layoutConstraints = new LC().insets( "0" ); // Debug Info (draws the red and blue lines) if ( mDebugMode ) { layoutConstraints.debug( 500 ); } // Create the Layout // // Note: we don't use column/row constraints, because we don't know // what the controls will be in advance. Rather, we use 'cell' and 'push' org.eclipse.swt.widgets.Layout layout = new net.miginfocom.swt.MigLayout( layoutConstraints ); container.setLayout( layout ); // Calculate default label inset // // We top align all our labels, not just those belonging to 'tall' controls, // so that tall controls, regular controls and nested Metawidget controls all line up. // However, we still want the Labels to be middle aligned for one-line controls (such as // Text boxes), so we top inset them a bit state.defaultLabelVerticalPadding = new GC( container ).getFontMetrics().getLeading(); }
/** * 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); }
public void paintFigure(Graphics g, org.eclipse.draw2d.geometry.Rectangle rect) { g.fillRectangle(rect); g.setClip(rect); int imageAreaWidth = Math.min(rect.width, _imageWidth); int imageAreaHeight = Math.min(rect.height, _imageHeight); if (_image != null && !_image.isDisposed()) { g.drawImage(_image, 0, 0, _imageWidth, _imageHeight, rect.x, rect.y + (rect.height - imageAreaHeight) / 2, imageAreaWidth, imageAreaHeight); } if (_label != null && _labelVisible) { int leading = 0; if (_fontMetrics != null) { leading = _fontMetrics.getLeading(); } // TODO: adapt to bg: go lighter on colors that darker() would make black // TODO: color registry Color fg = FigureUtilities.darker(g.getBackgroundColor()); g.setForegroundColor(fg); g.drawString(_label, imageAreaWidth + GAP, rect.y + (rect.height - getLabelHeight()) / 2 + leading); fg.dispose(); } }
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();
/** * Draw square of the given rgb. * * @param rgb the rgb color * @param gc the graphic context * @param textWidget the text widget * @param x the location y * @param y the location y * @return the square width. */ private int drawSquare(RGB rgb, GC gc, StyledText textWidget, int x, int y) { FontMetrics fontMetrics = gc.getFontMetrics(); int size = getSquareSize(fontMetrics); x += fontMetrics.getLeading(); y += fontMetrics.getDescent(); Rectangle rect = new Rectangle(x, y, size, size); // Fill square gc.setBackground(getColor(rgb, textWidget.getDisplay())); gc.fillRectangle(rect); // Draw square box gc.setForeground(textWidget.getForeground()); gc.drawRectangle(rect); return getSquareWidth(gc.getFontMetrics()); }