Search in sources :

Example 1 with RenderingHints

use of java.awt.RenderingHints in project openblocks by mikaelhg.

the class RBHighlightHandler method updateImage.

public void updateImage() {
    if (GraphicsEnvironment.isHeadless()) {
        return;
    }
    // cache the focus so it'll know when it needs to redraw later.
    hasFocus = rb.getBlock().hasFocus();
    Color color = null;
    if (hColor != null) {
        color = hColor;
    } else if (rb.getBlock().hasFocus()) {
        //Color.BLUE);
        color = new Color(200, 200, 255);
    } else if (isSearchResult) {
        //Color.YELLOW);
        color = new Color(255, 255, 120);
    } else if (rb.getBlock().isBad()) {
        //Color.RED);
        color = new Color(255, 100, 100);
    } else {
        GraphicsManager.recycleGCCompatibleImage(hImage);
        hImage = null;
        // if we're not highlighting, destroy the image and just return
        return;
    }
    if (!rb.isVisible()) {
        GraphicsManager.recycleGCCompatibleImage(hImage);
        hImage = null;
        // if we're not highlighting, destroy the image and just return
        return;
    }
    hImage = GraphicsManager.getGCCompatibleImage(rb.getBlockWidth() + HIGHLIGHT_STROKE_WIDTH, rb.getBlockHeight() + HIGHLIGHT_STROKE_WIDTH);
    Graphics2D hg = (Graphics2D) hImage.getGraphics();
    hg.addRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
    hg.setColor(color);
    hg.translate(HIGHLIGHT_STROKE_WIDTH / 2, HIGHLIGHT_STROKE_WIDTH / 2);
    hg.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .2f));
    for (int i = 0; i < HIGHLIGHT_STROKE_WIDTH; i++) {
        hg.setStroke(new BasicStroke(i));
        hg.draw(rb.getBlockArea());
    }
    hg.setColor(new Color(0, 0, 0, 0));
    hg.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 1));
    hg.fill(rb.getBlockArea());
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) RenderingHints(java.awt.RenderingHints) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Example 2 with RenderingHints

use of java.awt.RenderingHints in project jdk8u_jdk by JetBrains.

the class Bug7049339 method main.

public static void main(String[] argv) {
    int x = 100, y = 100;
    BufferedImage src = new BufferedImage(x, y, BufferedImage.TYPE_INT_ARGB);
    BufferedImage dst = new BufferedImage(x, y, BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D dstg2d = dst.createGraphics();
    dstg2d.setComposite(new Composite() {

        @Override
        public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) {
            return new CompositeContext() {

                @Override
                public void compose(Raster src, Raster dstIn, WritableRaster dstOut) {
                // do nothing
                }

                @Override
                public void dispose() {
                }
            };
        }
    });
    Shape clip = new Ellipse2D.Double(x / 4, y / 4, x / 2, y / 2);
    dstg2d.setClip(clip);
    // This will throw a RasterFormatException if the bug is present.
    dstg2d.drawImage(src, 0, 0, null);
}
Also used : Shape(java.awt.Shape) Composite(java.awt.Composite) CompositeContext(java.awt.CompositeContext) ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) BufferedImage(java.awt.image.BufferedImage) RenderingHints(java.awt.RenderingHints) Graphics2D(java.awt.Graphics2D)

Example 3 with RenderingHints

use of java.awt.RenderingHints in project poi by apache.

the class SLGraphics method setRenderingHints.

/**
     * Replaces the values of all preferences for the rendering
     * algorithms with the specified <code>hints</code>.
     * The existing values for all rendering hints are discarded and
     * the new set of known hints and values are initialized from the
     * specified {@link Map} object.
     * Hint categories include controls for rendering quality and
     * overall time/quality trade-off in the rendering process.
     * Refer to the <code>RenderingHints</code> class for definitions of
     * some common keys and values.
     * @param hints the rendering hints to be set
     * @see RenderingHints
     */
public void setRenderingHints(Map<?, ?> hints) {
    this._hints = new RenderingHints(null);
    this._hints.putAll(hints);
}
Also used : RenderingHints(java.awt.RenderingHints)

Example 4 with RenderingHints

use of java.awt.RenderingHints in project jdk8u_jdk by JetBrains.

the class SunGraphics2D method makeHints.

RenderingHints makeHints(Map hints) {
    RenderingHints model = new RenderingHints(hints);
    model.put(SunHints.KEY_RENDERING, SunHints.Value.get(SunHints.INTKEY_RENDERING, renderHint));
    model.put(SunHints.KEY_ANTIALIASING, SunHints.Value.get(SunHints.INTKEY_ANTIALIASING, antialiasHint));
    model.put(SunHints.KEY_TEXT_ANTIALIASING, SunHints.Value.get(SunHints.INTKEY_TEXT_ANTIALIASING, textAntialiasHint));
    model.put(SunHints.KEY_FRACTIONALMETRICS, SunHints.Value.get(SunHints.INTKEY_FRACTIONALMETRICS, fractionalMetricsHint));
    model.put(SunHints.KEY_TEXT_ANTIALIAS_LCD_CONTRAST, Integer.valueOf(lcdTextContrast));
    Object value;
    switch(interpolationHint) {
        case SunHints.INTVAL_INTERPOLATION_NEAREST_NEIGHBOR:
            value = SunHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
            break;
        case SunHints.INTVAL_INTERPOLATION_BILINEAR:
            value = SunHints.VALUE_INTERPOLATION_BILINEAR;
            break;
        case SunHints.INTVAL_INTERPOLATION_BICUBIC:
            value = SunHints.VALUE_INTERPOLATION_BICUBIC;
            break;
        default:
            value = null;
            break;
    }
    if (value != null) {
        model.put(SunHints.KEY_INTERPOLATION, value);
    }
    model.put(SunHints.KEY_STROKE_CONTROL, SunHints.Value.get(SunHints.INTKEY_STROKE_CONTROL, strokeHint));
    return model;
}
Also used : RenderingHints(java.awt.RenderingHints)

Example 5 with RenderingHints

use of java.awt.RenderingHints in project jdk8u_jdk by JetBrains.

the class WDesktopProperties method getDesktopAAHints.

/*
     * This returns the value for the desktop property "awt.font.desktophints"
     * It builds this using the Windows desktop properties to return
     * them as platform independent hints.
     * This requires that the Windows properties have already been gathered
     * and placed in "map"
     */
synchronized RenderingHints getDesktopAAHints() {
    /* Equate "DEFAULT" to "OFF", which it is in our implementation.
         * Doing this prevents unnecessary pipeline revalidation where
         * the value OFF is detected as a distinct value by SunGraphics2D
         */
    Object fontSmoothingHint = VALUE_TEXT_ANTIALIAS_DEFAULT;
    Integer fontSmoothingContrast = null;
    Boolean smoothingOn = (Boolean) map.get("win.text.fontSmoothingOn");
    if (smoothingOn != null && smoothingOn.equals(Boolean.TRUE)) {
        Integer typeID = (Integer) map.get("win.text.fontSmoothingType");
        /* "1" is GASP/Standard but we'll also use that if the return
             * value is anything other than "2" for LCD.
             */
        if (typeID == null || typeID.intValue() <= 1 || typeID.intValue() > 2) {
            fontSmoothingHint = VALUE_TEXT_ANTIALIAS_GASP;
        } else {
            /* Recognise 0 as BGR and everything else as RGB - note
                 * that 1 is the expected value for RGB.
                 */
            Integer orientID = (Integer) map.get("win.text.fontSmoothingOrientation");
            /* 0 is BGR, 1 is RGB. Other values, assume RGB */
            if (orientID == null || orientID.intValue() != 0) {
                fontSmoothingHint = VALUE_TEXT_ANTIALIAS_LCD_HRGB;
            } else {
                fontSmoothingHint = VALUE_TEXT_ANTIALIAS_LCD_HBGR;
            }
            fontSmoothingContrast = (Integer) map.get("win.text.fontSmoothingContrast");
            if (fontSmoothingContrast == null) {
                fontSmoothingContrast = Integer.valueOf(140);
            } else {
                /* Windows values are scaled 10x those of Java 2D */
                fontSmoothingContrast = Integer.valueOf(fontSmoothingContrast.intValue() / 10);
            }
        }
    }
    RenderingHints hints = new RenderingHints(null);
    hints.put(KEY_TEXT_ANTIALIASING, fontSmoothingHint);
    if (fontSmoothingContrast != null) {
        hints.put(KEY_TEXT_LCD_CONTRAST, fontSmoothingContrast);
    }
    return hints;
}
Also used : RenderingHints(java.awt.RenderingHints)

Aggregations

RenderingHints (java.awt.RenderingHints)14 Graphics2D (java.awt.Graphics2D)6 Color (java.awt.Color)4 Font (java.awt.Font)3 CompositeContext (java.awt.CompositeContext)2 BufferedImage (java.awt.image.BufferedImage)2 ColorModel (java.awt.image.ColorModel)2 BasicStroke (java.awt.BasicStroke)1 Composite (java.awt.Composite)1 PaintContext (java.awt.PaintContext)1 Point (java.awt.Point)1 Shape (java.awt.Shape)1 AffineTransform (java.awt.geom.AffineTransform)1 ConvolveOp (java.awt.image.ConvolveOp)1 Kernel (java.awt.image.Kernel)1 Raster (java.awt.image.Raster)1 WritableRaster (java.awt.image.WritableRaster)1