Java Code Examples for org.eclipse.draw2d.Graphics#getAbsoluteScale()
The following examples show how to use
org.eclipse.draw2d.Graphics#getAbsoluteScale() .
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: GraphicsUtil.java From nebula with Eclipse Public License 2.0 | 5 votes |
public static Pattern createScaledPattern(Graphics graphics, Device device, float x1, float y1, float x2, float y2, Color color1, int alpha1, Color color2, int alpha2) { double scale = graphics.getAbsoluteScale(); return new Pattern(device, (float) (x1 * scale), (float) (y1 * scale), (float) (x2 * scale), (float) (y2 * scale), color1, alpha1, color2, alpha2); }
Example 2
Source File: GraphicsUtil.java From nebula with Eclipse Public License 2.0 | 4 votes |
public static Pattern createScaledPattern(Graphics graphics, Device device, float x1, float y1, float x2, float y2, Color color1, Color color2) { double scale = graphics.getAbsoluteScale(); return new Pattern(device, (float) (x1 * scale), (float) (y1 * scale), (float) (x2 * scale), (float) (y2 * scale), color1, color2); }
Example 3
Source File: VerticalLabel.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
/** * Fix the issues in the ImageUtilities where the size of the image is the * ascent of the font instead of being its height. * * Also uses the GC for the rotation. * * The biggest issue is the very idea of using an image. The size of the * font should be given by the mapmode, not in absolute device pixel as it * does look ugly when zooming in. * * * @param string * the String to be rendered * @param font * the font * @param foreground * the text's color * @param background * the background color * @param useGCTransform * true to use the Transform on the GC object. * false to rely on the homemade algorithm. Transform seems to * not be supported in eclipse-3.2 except on windows. * It is working on macos-3.3M3. * @return an Image which must be disposed */ public Image createRotatedImageOfString(Graphics g, String string, Font font, Color foreground, Color background, boolean useGCTransform) { Display display = Display.getCurrent(); if (display == null) { SWT.error(SWT.ERROR_THREAD_INVALID_ACCESS); } List<FontData> fontDatas = new ArrayList<FontData>(); // take all font datas, mac and linux specific for (FontData data : font.getFontData()) { FontData data2 = new FontData(data.getName(), (int) (data.getHeight() * g.getAbsoluteScale()), data.getStyle()); fontDatas.add(data2); } // create the new font Font zoomedFont = new Font(display, fontDatas.toArray(new FontData[fontDatas.size()])); // get the dimension in this font Dimension strDim = FigureUtilities .getTextExtents(string, zoomedFont); if (strDim.width == 0 || strDim.height == 0) { strDim = FigureUtilities .getTextExtents(string, font); } Image srcImage = useGCTransform ? new Image(display, strDim.height, strDim.width) : new Image(display, strDim.width, strDim.height); GC gc = new GC(srcImage); if (useGCTransform) { Transform transform = new Transform(display); transform.rotate(-90); gc.setTransform(transform); } gc.setFont(zoomedFont); gc.setForeground(foreground); gc.setBackground(background); gc.fillRectangle(gc.getClipping()); gc.drawText(string, gc.getClipping().x, gc.getClipping().y // - metrics.getLeading() ); gc.dispose(); if (useGCTransform) { srcImage.dispose(); zoomedFont.dispose(); return srcImage; } disposeImage(); Image rotated = ImageUtilities.createRotatedImage(srcImage); srcImage.dispose(); zoomedFont.dispose(); return rotated; }