Java Code Examples for org.eclipse.swt.graphics.GC#setTextAntialias()

The following examples show how to use org.eclipse.swt.graphics.GC#setTextAntialias() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdvancedGC.java    From swt-bling with MIT License 6 votes vote down vote up
public static void setAdvanced(GC gc, boolean targetSetting) {
    if (targetSetting) {
        try {
            gc.setAdvanced(true);
            gc.setAntialias(SWT.ON);
            gc.setTextAntialias(SWT.ON);
            gc.setInterpolation(SWT.HIGH);
        } catch (SWTException e) {
            if (!loggedAdvanced) {
                log.log(Level.WARNING, "Unable to set advanced drawing", e);
                loggedAdvanced = true;
            }
        }
    } else {
        gc.setAdvanced(false);
    }

}
 
Example 2
Source File: Stepbar.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private List<Point> computeTextSizes() {
	final int count = steps.size();
	final List<Point> list = new ArrayList<>(count);
	final GC gc = new GC(this);
	gc.setTextAntialias(SWT.ON);
	gc.setFont(getFont());
	for (int i = 0; i < count; i++) {
		final Point textSize = gc.textExtent(steps.get(i), SWT.DRAW_TRANSPARENT);
		list.add(textSize);
	}

	gc.dispose();
	return list;
}
 
Example 3
Source File: PShelf.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void onPaint(GC gc) {

		gc.setAdvanced(true);
		if (gc.getAdvanced())
			gc.setTextAntialias(SWT.ON);

		Color back = getBackground();
		Color fore = getForeground();

		int index = 0;

		for (Iterator<PShelfItem> iter = items.iterator(); iter.hasNext();) {
			PShelfItem item = iter.next();

			gc.setBackground(back);
			gc.setForeground(fore);

            Integer y = yCoordinates.get(index);

            renderer.setBounds(0,y.intValue(),getClientArea().width,itemHeight);
            renderer.setSelected(item == openItem);
            renderer.setFocus(this.isFocusControl() && focusItem == item);
            renderer.setHover(item == hoverItem);
            renderer.paint(gc,item);

			index ++;
		}

	}
 
Example 4
Source File: TextPainterWithPadding.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void setupGCFromConfig(GC gc, IStyle cellStyle) {
	Color fg = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);
	Color bg = cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);

	gc.setAntialias(GUIHelper.DEFAULT_ANTIALIAS);
	gc.setTextAntialias(GUIHelper.DEFAULT_TEXT_ANTIALIAS);
	gc.setFont(font);
	gc.setForeground(fg != null ? fg : GUIHelper.COLOR_LIST_FOREGROUND);
	gc.setBackground(bg != null ? bg : GUIHelper.COLOR_LIST_BACKGROUND);
}
 
Example 5
Source File: TextPainter.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void setupGCFromConfig(GC gc, IStyle cellStyle) {
	Color fg = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);
	Color bg = cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);
	Font font = cellStyle.getAttributeValue(CellStyleAttributes.FONT);

	gc.setAntialias(GUIHelper.DEFAULT_ANTIALIAS);
	gc.setTextAntialias(GUIHelper.DEFAULT_TEXT_ANTIALIAS);
	gc.setFont(font);
	gc.setForeground(fg != null ? fg : GUIHelper.COLOR_LIST_FOREGROUND);
	gc.setBackground(bg != null ? bg : GUIHelper.COLOR_LIST_BACKGROUND);
}
 
Example 6
Source File: AttributePainter.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void setupGCFromConfig(GC gc, IStyle cellStyle) {
	Color fg = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);
	Color bg = cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);

	gc.setAntialias(GUIHelper.DEFAULT_ANTIALIAS);
	gc.setTextAntialias(GUIHelper.DEFAULT_TEXT_ANTIALIAS);
	gc.setFont(font);
	gc.setForeground(fg != null ? fg : GUIHelper.COLOR_LIST_FOREGROUND);
	gc.setBackground(bg != null ? bg : GUIHelper.COLOR_LIST_BACKGROUND);
}
 
Example 7
Source File: TmxEditorTextPainter.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void setupGCFromConfig(GC gc, IStyle cellStyle) {
	Color fg = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);
	Color bg = cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);

	gc.setAntialias(GUIHelper.DEFAULT_ANTIALIAS);
	gc.setTextAntialias(GUIHelper.DEFAULT_TEXT_ANTIALIAS);
	gc.setFont(font);
	gc.setForeground(fg != null ? fg : GUIHelper.COLOR_LIST_FOREGROUND);
	gc.setBackground(bg != null ? bg : GUIHelper.COLOR_LIST_BACKGROUND);
}
 
Example 8
Source File: TextPainterWithPadding.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void setupGCFromConfig(GC gc, IStyle cellStyle) {
	Color fg = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);
	Color bg = cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);

	gc.setAntialias(GUIHelper.DEFAULT_ANTIALIAS);
	gc.setTextAntialias(GUIHelper.DEFAULT_TEXT_ANTIALIAS);
	gc.setFont(font);
	gc.setForeground(fg != null ? fg : GUIHelper.COLOR_LIST_FOREGROUND);
	gc.setBackground(bg != null ? bg : GUIHelper.COLOR_LIST_BACKGROUND);
}
 
Example 9
Source File: TextPainter.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void setupGCFromConfig(GC gc, IStyle cellStyle) {
	Color fg = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);
	Color bg = cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);
	Font font = cellStyle.getAttributeValue(CellStyleAttributes.FONT);

	gc.setAntialias(GUIHelper.DEFAULT_ANTIALIAS);
	gc.setTextAntialias(GUIHelper.DEFAULT_TEXT_ANTIALIAS);
	gc.setFont(font);
	gc.setForeground(fg != null ? fg : GUIHelper.COLOR_LIST_FOREGROUND);
	gc.setBackground(bg != null ? bg : GUIHelper.COLOR_LIST_BACKGROUND);
}
 
Example 10
Source File: R31Enhance.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Equivalent to <code><b>GC.setTextAntialias()</b></code> in r3.1.
 * 
 * @param gc
 * @param value
 */
static void setTextAntialias( GC gc, int value )
{
	if ( R31_AVAILABLE )
	{
		gc.setTextAntialias( value );
	}
}
 
Example 11
Source File: NavigationPageGraphics.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void onPaint(GC gc) {
	gc.setAdvanced(true);
	if (gc.getAdvanced())
		gc.setTextAntialias(SWT.ON);
	if (items == null) {
		return;
	}
	computeBoundsIfNeeded(gc);

	Color fg = getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND);
	Color bg = getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);

	boolean separator = false;
	int x, y, width, height = 0;
	boolean selected = false;
	boolean enabled = false;

	for (NavigationPageGraphicsItem pageItem : items) {
		selected = pageItem.equals(selectedItem);
		enabled = pageItem.isEnabled();
		separator = pageItem.isSeparator();

		x = pageItem.getBounds().x;
		y = pageItem.getBounds().y;
		width = pageItem.getBounds().width;
		height = pageItem.getBounds().height;

		// Fill rectangle
		Color filledRectangleColor = getFilledRectangleColor(selected,
				!separator ? enabled : true, bg);
		if (filledRectangleColor != null) {
			gc.setBackground(filledRectangleColor);
			if (round != null) {
				gc.fillRoundRectangle(x, y, width, height, round, round);
			} else {
				gc.fillRectangle(x, y, width, height);
			}
		}

		// Border rectangle
		if (!separator) {
			Color borderRectangleColor = getBorderRectangleColor(selected,
					enabled, bg);
			if (borderRectangleColor != null) {
				gc.setForeground(borderRectangleColor);
				if (round != null) {
					gc.drawRoundRectangle(x, y, width, height, round, round);
				} else {
					gc.drawRectangle(x, y, width, height);
				}
			}
		}

		// Foreground text
		Color textColor = getTextColor(selected, enabled);
		if (textColor != null) {
			gc.setForeground(textColor);
		} else {
			gc.setForeground(fg);
		}
		gc.drawString(pageItem.getText(), x + 3, y, true);
	}
}
 
Example 12
Source File: PrintPreview.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void configureAntialiasing(GC printerGC) {
	printerGC.setAdvanced(true);
	printerGC.setAntialias(SWT.ON);
	printerGC.setTextAntialias(SWT.ON);
	printerGC.setInterpolation(SWT.HIGH);
}
 
Example 13
Source File: ViewLattice.java    From arx with Apache License 2.0 4 votes vote down vote up
/**
 * Draws a node.
 *
 * @param g
 */
private void drawNodes(final GC g) {

    // Prepare
    Rectangle bounds = new Rectangle(0, 0, (int)nodeWidth, (int)nodeHeight);
    Transform transform = new Transform(g.getDevice());
    
    // Set style
    g.setLineWidth(STROKE_WIDTH_NODE);
    g.setFont(font);

    // Draw nodes
    for (List<ARXNode> level : lattice) {
        for (ARXNode node : level) {
            
            // Obtain coordinates
            double[] center = (double[]) node.getAttributes().get(ATTRIBUTE_CENTER);
            bounds.x = (int)(center[0] - nodeWidth / 2d);
            bounds.y = (int)(center[1] - nodeHeight / 2d);
            
            // Clipping
            if (bounds.intersects(new Rectangle(0, 0, screen.x, screen.y))) { 
                
                // Retrieve/compute text rendering data
                SerializablePath path = (SerializablePath) node.getAttributes().get(ATTRIBUTE_PATH);
                Point extent = (Point) node.getAttributes().get(ATTRIBUTE_EXTENT);
                if (path == null || path.getPath() == null) {
                    String text = (String) node.getAttributes().get(ATTRIBUTE_LABEL);
                    path = new SerializablePath(new Path(canvas.getDisplay()));
                    path.getPath().addString(text, 0, 0, font);
                    node.getAttributes().put(ATTRIBUTE_PATH, path);
                    extent = g.textExtent(text);
                    node.getAttributes().put(ATTRIBUTE_EXTENT, extent);
                }
        
                // Degrade if too far away
                if (bounds.width <= 4) {
                    g.setBackground(getInnerColor(node));
                    g.setAntialias(SWT.OFF);
                    g.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
        
                    // Draw real node
                } else {
                    
                    // Fill background
                    g.setBackground(getInnerColor(node));
                    g.setAntialias(SWT.OFF);
                    if (node != getSelectedNode()) {
                        g.fillOval(bounds.x, bounds.y, bounds.width, bounds.height);
                    } else {
                        g.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
                    }
                    
                    // Draw line
                    g.setLineWidth(getOuterStrokeWidth(node, bounds.width));
                    g.setForeground(getOuterColor(node));
                    g.setAntialias(SWT.ON);
                    if (node != getSelectedNode()) {
                        g.drawOval(bounds.x, bounds.y, bounds.width, bounds.height);
                    } else {
                        g.drawRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
                    }
                    
                    // Draw text
                    if (bounds.width >= 20) {
                        
                        // Enable anti-aliasing
                        g.setTextAntialias(SWT.ON);
                        
                        // Compute position and factor
                        float factor1 = (bounds.width * 0.7f) / (float)extent.x;
                        float factor2 = (bounds.height * 0.7f) / (float)extent.y;
                        float factor = Math.min(factor1, factor2);
                        int positionX = bounds.x + (int)(((float)bounds.width - (float)extent.x * factor) / 2f); 
                        int positionY = bounds.y + (int)(((float)bounds.height - (float)extent.y * factor) / 2f);
                        
                        // Initialize transformation
                        transform.identity();
                        transform.translate(positionX, positionY);
                        transform.scale(factor, factor);
                        g.setTransform(transform);
                        
                        // Draw and reset
                        g.setBackground(COLOR_BLACK);
                        g.fillPath(path.getPath());
                        g.setTransform(null);
                        g.setTextAntialias(SWT.OFF);
                    }
                }
            }
        }
    }
    
    // Clean up
    transform.dispose();
}