Refine search
int getBandHeight () { if (font == null) return ExpandItem.CHEVRON_SIZE; GC gc = new GC (this); FontMetrics metrics = gc.getFontMetrics (); gc.dispose (); return Math.max (ExpandItem.CHEVRON_SIZE, metrics.getHeight ()); }
/** * Compute width of square * * @param styledText * @return the width of square */ private static int getSquareWidth(FontMetrics fontMetrics) { // width = 2 spaces + size width of square int width = 2 * fontMetrics.getAverageCharWidth() + getSquareSize(fontMetrics); return width; }
/** * 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); }
/** * Returns the colorized square size. * * @param fontMetrics * @return the colorized square size. */ public static int getSquareSize(FontMetrics fontMetrics) { return fontMetrics.getHeight() - 2 * fontMetrics.getDescent(); }
public float getAscent() { return _fm.getAscent() + _fm.getLeading(); }
/** * 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(); }
layout.setStyle(new TextStyle(getFont(SWT.BOLD | SWT.ITALIC), null, null), 3, 3); FontMetrics metrics = layout.getLineMetrics(0); ascent = metrics.getAscent() + metrics.getLeading(); descent = metrics.getDescent(); boldFont.dispose(); italicFont.dispose(); layout.dispose(); if (styledText != null) { GC gc = new GC(styledText); averageCharWidth = gc.getFontMetrics().getAverageCharWidth(); fixedPitch = gc.stringExtent("l").x == gc.stringExtent("W").x; //$NON-NLS-1$ //$NON-NLS-2$ gc.dispose();
private void paintStep(int startX, int endX) { GC gc = new GC(this); setStatusColor(gc); Rectangle rect = getClientArea(); startX = Math.max(1, startX); gc.fillRectangle(startX, 1, endX - startX, rect.height - 2); String string = getCurrentMessage(); m_currentMessage = string; gc.setFont(JFaceResources.getDefaultFont()); FontMetrics fontMetrics = gc.getFontMetrics(); int stringWidth = fontMetrics.getAverageCharWidth() * string.length(); int stringHeight = fontMetrics.getHeight(); gc.setForeground(m_messageColor); gc.drawString(string, (rect.width - stringWidth) / 2, (rect.height - stringHeight) / 2, true); gc.dispose(); }
oldFont = gc.getFont(); Font newFont = (Font) resourceTable.get(fontId); if (newFont != null) gc.setFont(newFont); oldColor = gc.getForeground(); Color newColor = (Color) resourceTable.get(colorId); if (newColor != null) FontMetrics fm = gc.getFontMetrics(); int lineHeight = fm.getHeight(); int descent = fm.getDescent();
void printLine(int x, int y, GC gc, Color foreground, Color background, TextLayout layout, TextLayout printLayout, int index) { if (background != null) { Rectangle rect = layout.getBounds(); gc.setBackground(background); gc.fillRectangle(x, y, rect.width, rect.height); printLayout.setAscent(metrics.getAscent() + metrics.getLeading()); printLayout.setDescent(metrics.getDescent()); String[] lineLabels = printOptions.lineLabels; if (lineLabels != null) { printLayout.setDescent(-1); gc.setForeground(foreground); layout.draw(gc, x, y);
gc.setFont(getFont()); Color fg = isEnabled() ? getForeground() : new Color(gc.getDevice(),FormColors.blend(getBackground().getRGB(), getForeground().getRGB(), 70)); try { gc.setForeground(fg); if ((getStyle() & SWT.WRAP) != 0) { FormUtil.paintWrapText(gc, text, bounds, underlined); gc.drawText(textToDraw, bounds.x, bounds.y, true); if (underlined) { int descent = gc.getFontMetrics().getDescent(); int lineY = bounds.y + textHeight - descent + 1; gc.drawLine(bounds.x, lineY, bounds.x + textWidth, lineY);
BreakIterator wb = BreakIterator.getWordInstance(); wb.setText(text); FontMetrics fm = gc.getFontMetrics(); int lineHeight = fm.getHeight(); int descent = fm.getDescent(); Point extent = gc.textExtent(line); gc.drawText(prevLine, bounds.x, y, true); if (underline) { Point prevExtent = gc.textExtent(prevLine);
/** * 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()); }
protected void addEmptyTreeMessage(GC gc) { // here we print a message when the document is empty just to give the // user a visual cue // so that they know how to proceed to edit the blank view gc.setForeground(fTree.getDisplay().getSystemColor(SWT.COLOR_BLACK)); gc.setBackground(fTree.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); gc.drawString(XMLEditorMessages.XMLTreeExtension_3, 10, 10); gc.drawString(XMLEditorMessages.XMLTreeExtension_4, 10, 10 + gc.getFontMetrics().getHeight()); }
@Override public void handleEvent(Event event) { Color old = event.gc.getForeground(); event.gc.setForeground(Colors.black); int char_width = event.gc.getFontMetrics().getAverageCharWidth(); String pb_text = pbt.convert(result.getSelection()); event.gc.drawText(pb_text, (result.getSize().x - pb_text.length() * char_width )/2, -1, true); event.gc.setForeground(old); } });
@Override public void layout(GC gc, int width, Locator locator, Hashtable<String, Object> ResourceTable, boolean selected) { locator.resetCaret(); if (locator.rowHeight==0) { FontMetrics fm = gc.getFontMetrics(); locator.rowHeight = fm.getHeight(); } locator.y += locator.rowHeight; locator.rowHeight = 0; locator.rowCounter++; }
/** * 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); }
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(); }
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); }
@Override public Point draw(GC gc, StyledText textWidget, Color color, int x, int y) { Image image = getImage(); gc.drawImage(image, x, y + gc.getFontMetrics().getDescent()); Rectangle bounds = image.getBounds(); return new Point(bounds.width, bounds.height); }