Java Graphics Settings setTextRenderingHints(Graphics2D g2d)

Here you can find the source of setTextRenderingHints(Graphics2D g2d)

Description

set Text Rendering Hints

License

Apache License

Declaration

public static void setTextRenderingHints(Graphics2D g2d) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.Graphics2D;

import java.awt.RenderingHints;

public class Main {
    public static void setTextRenderingHints(Graphics2D g2d) {
        // This time, we want to use anti-aliasing if possible to avoid the
        // jagged edges
        // With the Java 2D rendering engine (Graphics2D) to do this using a
        // "rendering hint".
        // RenderingHints rh = g2d.getRenderingHints();
        // Initially set to VALUE_TEXT_ANTIALIAS_GASP
        RenderingHints rh = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        rh.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
        rh.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
        rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        rh.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
        rh.put(RenderingHints.KEY_TEXT_LCD_CONTRAST, new Integer(140));
        rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT);
        // rh.put(RenderingHints.KEY_COLOR_RENDERING,
        // RenderingHints.VALUE_COLOR_RENDER_QUALITY);
        // rh.put(RenderingHints.KEY_STROKE_CONTROL,
        // RenderingHints.VALUE_STROKE_NORMALIZE);
        // rh.put(RenderingHints.KEY_TEXT_ANTIALIASING,
        // RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
        // System.out.println("\n\nRendering Hints:\n" + rh.toString());
        g2d.setRenderingHints(rh);/*from ww w . j  a v  a  2  s.c o m*/
    }

    public static void setRenderingHints(Graphics2D g2d) {
        // This time, we want to use anti-aliasing if possible to avoid the
        // jagged edges
        // With the Java 2D rendering engine (Graphics2D) to do this using a
        // "rendering hint".
        RenderingHints rh = g2d.getRenderingHints();
        rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        // rh.put(RenderingHints.KEY_COLOR_RENDERING,
        // RenderingHints.VALUE_COLOR_RENDER_QUALITY);
        // rh.put(RenderingHints.KEY_ALPHA_INTERPOLATION,
        // RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
        // rh.put(RenderingHints.KEY_TEXT_ANTIALIASING,
        // RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        // rh.put(RenderingHints.KEY_FRACTIONALMETRICS,
        // RenderingHints.VALUE_FRACTIONALMETRICS_ON);
        g2d.setRenderingHints(rh);
    }
}

Related

  1. gradientFillShape(Graphics2D g, Color startColor, Color endColor, Shape shape)
  2. gradientPaint(Graphics2D g2d, Point2D startPosition, Color startColor, Point2D endPosition, Color endColor, int sx, int sy, int ex, int ey)
  3. setClip(Graphics g, Rectangle clipBounds)
  4. setRenderingHints(Graphics2D g)
  5. setRenderingHints(Graphics2D g2d)
  6. setupGraphics(Graphics2D pG2d)