下面列出了怎么用sun.awt.SunHints的API类实例代码及写法,或者点击链接到github查看源代码。
public void renderPath(SunGraphics2D sg, Shape s, BasicStroke bs) {
boolean adjust = (bs != null &&
sg.strokeHint != SunHints.INTVAL_STROKE_PURE);
boolean thin = (sg.strokeState <= SunGraphics2D.STROKE_THINDASHED);
Region clip = sg.getCompClip();
int abox[] = new int[4];
AATileGenerator aatg =
renderengine.getAATileGenerator(s, sg.transform, clip,
bs, thin, adjust, abox);
if (aatg == null) {
// Nothing to render
return;
}
renderTiles(sg, s, aatg, abox);
}
protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl,
int aaHint) {
switch (aaHint) {
case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
sg2d.loops.drawGlyphListLoop.
DrawGlyphList(sg2d, sg2d.surfaceData, gl);
return;
case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
sg2d.loops.drawGlyphListAALoop.
DrawGlyphListAA(sg2d, sg2d.surfaceData, gl);
return;
case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB:
case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB:
sg2d.loops.drawGlyphListLCDLoop.
DrawGlyphListLCD(sg2d,sg2d.surfaceData, gl);
return;
}
}
public void drawGlyphVector(SunGraphics2D sg2d, GlyphVector g,
float x, float y)
{
FontRenderContext frc = g.getFontRenderContext();
FontInfo info = sg2d.getGVFontInfo(g.getFont(), frc);
switch (info.aaHint) {
case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
super.drawGlyphVector(sg2d, g, x, y);
return;
case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
sg2d.surfaceData.aaTextRenderer.drawGlyphVector(sg2d, g, x, y);
return;
case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB:
case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB:
sg2d.surfaceData.lcdTextRenderer.drawGlyphVector(sg2d, g, x, y);
return;
default:
}
}
public void renderPath(SunGraphics2D sg, Shape s, BasicStroke bs) {
boolean adjust = (bs != null &&
sg.strokeHint != SunHints.INTVAL_STROKE_PURE);
boolean thin = (sg.strokeState <= SunGraphics2D.STROKE_THINDASHED);
Region clip = sg.getCompClip();
int abox[] = new int[4];
AATileGenerator aatg =
renderengine.getAATileGenerator(s, sg.transform, clip,
bs, thin, adjust, abox);
if (aatg == null) {
// Nothing to render
return;
}
renderTiles(sg, s, aatg, abox);
}
public void drawGlyphVector(SunGraphics2D sg2d, GlyphVector g,
float x, float y)
{
FontRenderContext frc = g.getFontRenderContext();
FontInfo info = sg2d.getGVFontInfo(g.getFont(), frc);
switch (info.aaHint) {
case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
super.drawGlyphVector(sg2d, g, x, y);
return;
case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
SurfaceData.aaTextRenderer.drawGlyphVector(sg2d, g, x, y);
return;
case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB:
case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB:
SurfaceData.lcdTextRenderer.drawGlyphVector(sg2d, g, x, y);
return;
default:
}
}
protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl,
int aaHint) {
switch (aaHint) {
case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
sg2d.loops.drawGlyphListLoop.
DrawGlyphList(sg2d, sg2d.surfaceData, gl);
return;
case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
sg2d.loops.drawGlyphListAALoop.
DrawGlyphListAA(sg2d, sg2d.surfaceData, gl);
return;
case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB:
case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB:
sg2d.loops.drawGlyphListLCDLoop.
DrawGlyphListLCD(sg2d,sg2d.surfaceData, gl);
return;
}
}
public void renderPath(SunGraphics2D sg, Shape s, BasicStroke bs) {
final boolean adjust = (bs != null &&
sg.strokeHint != SunHints.INTVAL_STROKE_PURE);
final boolean thin = (sg.strokeState <= SunGraphics2D.STROKE_THINDASHED);
final TileState ts = TILE_STATE_PROVIDER.acquire();
try {
final int[] abox = ts.abox;
final AATileGenerator aatg =
RDR_ENGINE.getAATileGenerator(s, sg.transform, sg.getCompClip(),
bs, thin, adjust, abox);
if (aatg != null) {
renderTiles(sg, s, aatg, abox, ts);
}
} finally {
TILE_STATE_PROVIDER.release(ts);
}
}
public static ShapeSpanIterator getStrokeSpans(SunGraphics2D sg2d,
Shape s)
{
ShapeSpanIterator sr = new ShapeSpanIterator(false);
try {
sr.setOutputArea(sg2d.getCompClip());
sr.setRule(PathIterator.WIND_NON_ZERO);
BasicStroke bs = (BasicStroke) sg2d.stroke;
boolean thin = (sg2d.strokeState <= SunGraphics2D.STROKE_THINDASHED);
boolean normalize =
(sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE);
RenderEngine.strokeTo(s,
sg2d.transform, bs,
thin, normalize, false, sr);
} catch (Throwable t) {
sr.dispose();
sr = null;
throw new InternalError("Unable to Stroke shape ("+
t.getMessage()+")", t);
}
return sr;
}
public void renderPath(SunGraphics2D sg, Shape s, BasicStroke bs) {
final boolean adjust = (bs != null &&
sg.strokeHint != SunHints.INTVAL_STROKE_PURE);
final boolean thin = (sg.strokeState <= SunGraphics2D.STROKE_THINDASHED);
final TileState ts = TILE_STATE_PROVIDER.acquire();
try {
final int[] abox = ts.abox;
final AATileGenerator aatg =
RDR_ENGINE.getAATileGenerator(s, sg.transform, sg.getCompClip(),
bs, thin, adjust, abox);
if (aatg != null) {
renderTiles(sg, s, aatg, abox, ts);
}
} finally {
TILE_STATE_PROVIDER.release(ts);
}
}
public void drawGlyphVector(SunGraphics2D sg2d, GlyphVector g,
float x, float y)
{
FontRenderContext frc = g.getFontRenderContext();
FontInfo info = sg2d.getGVFontInfo(g.getFont(), frc);
switch (info.aaHint) {
case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
super.drawGlyphVector(sg2d, g, x, y);
return;
case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
sg2d.surfaceData.aaTextRenderer.drawGlyphVector(sg2d, g, x, y);
return;
case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB:
case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB:
sg2d.surfaceData.lcdTextRenderer.drawGlyphVector(sg2d, g, x, y);
return;
default:
}
}
public void renderPath(SunGraphics2D sg, Shape s, BasicStroke bs) {
final boolean adjust = (bs != null &&
sg.strokeHint != SunHints.INTVAL_STROKE_PURE);
final boolean thin = (sg.strokeState <= SunGraphics2D.STROKE_THINDASHED);
final TileState ts = tileStateProvider.acquire();
try {
final int[] abox = ts.abox;
final AATileGenerator aatg =
renderengine.getAATileGenerator(s, sg.transform, sg.getCompClip(),
bs, thin, adjust, abox);
if (aatg != null) {
renderTiles(sg, s, aatg, abox, ts);
}
} finally {
tileStateProvider.release(ts);
}
}
public void renderPath(SunGraphics2D sg, Shape s, BasicStroke bs) {
boolean adjust = (bs != null &&
sg.strokeHint != SunHints.INTVAL_STROKE_PURE);
boolean thin = (sg.strokeState <= SunGraphics2D.STROKE_THINDASHED);
Region clip = sg.getCompClip();
int abox[] = new int[4];
AATileGenerator aatg =
renderengine.getAATileGenerator(s, sg.transform, clip,
bs, thin, adjust, abox);
if (aatg == null) {
// Nothing to render
return;
}
renderTiles(sg, s, aatg, abox);
}
public void renderPath(SunGraphics2D sg, Shape s, BasicStroke bs) {
final boolean adjust = (bs != null &&
sg.strokeHint != SunHints.INTVAL_STROKE_PURE);
final boolean thin = (sg.strokeState <= SunGraphics2D.STROKE_THINDASHED);
final TileState ts = TILE_STATE_PROVIDER.acquire();
try {
final int[] abox = ts.abox;
final AATileGenerator aatg =
RDR_ENGINE.getAATileGenerator(s, sg.transform, sg.getCompClip(),
bs, thin, adjust, abox);
if (aatg != null) {
renderTiles(sg, s, aatg, abox, ts);
}
} finally {
TILE_STATE_PROVIDER.release(ts);
}
}
public static Object getFontConfigAAHint(String fcFamily) {
if (FontUtilities.isWindows) {
return null;
} else {
int hint = getFontConfigAASettings(getFCLocaleStr(), fcFamily);
if (hint < 0) {
return null;
} else {
return SunHints.Value.get(SunHints.INTKEY_TEXT_ANTIALIASING,
hint);
}
}
}
public void setFont(Font font) {
/* replacing the reference equality test font != this.font with
* !font.equals(this.font) did not yield any measurable difference
* in testing, but there may be yet to be identified cases where it
* is beneficial.
*/
if (font != null && font!=this.font/*!font.equals(this.font)*/) {
/* In the GASP AA case the textpipe depends on the glyph size
* as determined by graphics and font transforms as well as the
* font size, and information in the font. But we may invalidate
* the pipe only to find that it made no difference.
* Deferring pipe invalidation to checkFontInfo won't work because
* when called we may already be rendering to the wrong pipe.
* So, if the font is transformed, or the graphics has more than
* a simple scale, we'll take that as enough of a hint to
* revalidate everything. But if they aren't we will
* use the font's point size to query the gasp table and see if
* what it says matches what's currently being used, in which
* case there's no need to invalidate the textpipe.
* This should be sufficient for all typical uses cases.
*/
if (textAntialiasHint == SunHints.INTVAL_TEXT_ANTIALIAS_GASP &&
textpipe != invalidpipe &&
(transformState > TRANSFORM_ANY_TRANSLATE ||
font.isTransformed() ||
fontInfo == null || // Precaution, if true shouldn't get here
(fontInfo.aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_ON) !=
FontUtilities.getFont2D(font).
useAAForPtSize(font.getSize()))) {
textpipe = invalidpipe;
}
this.font = font;
this.fontMetrics = null;
this.validFontInfo = false;
}
}
public void drawString(SunGraphics2D g2d, String str, double x, double y) {
if ("".equals(str)) {
return; // TextLayout constructor throws IAE on "".
}
TextLayout tl = new TextLayout(str, g2d.getFont(),
g2d.getFontRenderContext());
Shape s = tl.getOutline(AffineTransform.getTranslateInstance(x, y));
int textAAHint = g2d.getFontInfo().aaHint;
int prevaaHint = - 1;
if (textAAHint != SunHints.INTVAL_TEXT_ANTIALIAS_OFF &&
g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
prevaaHint = g2d.antialiasHint;
g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON;
g2d.validatePipe();
} else if (textAAHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF
&& g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) {
prevaaHint = g2d.antialiasHint;
g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
g2d.validatePipe();
}
g2d.fill(s);
if (prevaaHint != -1) {
g2d.antialiasHint = prevaaHint;
g2d.validatePipe();
}
}
public void drawString(SunGraphics2D g2d, String str, double x, double y) {
if ("".equals(str)) {
return; // TextLayout constructor throws IAE on "".
}
TextLayout tl = new TextLayout(str, g2d.getFont(),
g2d.getFontRenderContext());
Shape s = tl.getOutline(AffineTransform.getTranslateInstance(x, y));
int textAAHint = g2d.getFontInfo().aaHint;
int prevaaHint = - 1;
if (textAAHint != SunHints.INTVAL_TEXT_ANTIALIAS_OFF &&
g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
prevaaHint = g2d.antialiasHint;
g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON;
g2d.validatePipe();
} else if (textAAHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF
&& g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) {
prevaaHint = g2d.antialiasHint;
g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
g2d.validatePipe();
}
g2d.fill(s);
if (prevaaHint != -1) {
g2d.antialiasHint = prevaaHint;
g2d.validatePipe();
}
}
/**
* Sets the preferences for the rendering algorithms.
* Hint categories include controls for rendering quality and
* overall time/quality trade-off in the rendering process.
* @param hints The rendering hints to be set
* @see RenderingHints
*/
public void setRenderingHints(Map<?,?> hints) {
this.hints = null;
renderHint = SunHints.INTVAL_RENDER_DEFAULT;
antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
textAntialiasHint = SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT;
fractionalMetricsHint = SunHints.INTVAL_FRACTIONALMETRICS_OFF;
lcdTextContrast = lcdTextContrastDefaultValue;
interpolationHint = -1;
interpolationType = AffineTransformOp.TYPE_NEAREST_NEIGHBOR;
boolean customHintPresent = false;
Iterator<?> iter = hints.keySet().iterator();
while (iter.hasNext()) {
Object key = iter.next();
if (key == SunHints.KEY_RENDERING ||
key == SunHints.KEY_ANTIALIASING ||
key == SunHints.KEY_TEXT_ANTIALIASING ||
key == SunHints.KEY_FRACTIONALMETRICS ||
key == SunHints.KEY_TEXT_ANTIALIAS_LCD_CONTRAST ||
key == SunHints.KEY_STROKE_CONTROL ||
key == SunHints.KEY_INTERPOLATION)
{
setRenderingHint((Key) key, hints.get(key));
} else {
customHintPresent = true;
}
}
if (customHintPresent) {
this.hints = makeHints(hints);
}
invalidatePipe();
}
public void setFont(Font font) {
/* replacing the reference equality test font != this.font with
* !font.equals(this.font) did not yield any measurable difference
* in testing, but there may be yet to be identified cases where it
* is beneficial.
*/
if (font != null && font!=this.font/*!font.equals(this.font)*/) {
/* In the GASP AA case the textpipe depends on the glyph size
* as determined by graphics and font transforms as well as the
* font size, and information in the font. But we may invalidate
* the pipe only to find that it made no difference.
* Deferring pipe invalidation to checkFontInfo won't work because
* when called we may already be rendering to the wrong pipe.
* So, if the font is transformed, or the graphics has more than
* a simple scale, we'll take that as enough of a hint to
* revalidate everything. But if they aren't we will
* use the font's point size to query the gasp table and see if
* what it says matches what's currently being used, in which
* case there's no need to invalidate the textpipe.
* This should be sufficient for all typical uses cases.
*/
if (textAntialiasHint == SunHints.INTVAL_TEXT_ANTIALIAS_GASP &&
textpipe != invalidpipe &&
(transformState > TRANSFORM_ANY_TRANSLATE ||
font.isTransformed() ||
fontInfo == null || // Precaution, if true shouldn't get here
(fontInfo.aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_ON) !=
FontUtilities.getFont2D(font).
useAAForPtSize(font.getSize()))) {
textpipe = invalidpipe;
}
this.font = font;
this.fontMetrics = null;
this.validFontInfo = false;
}
}
/**
* Adds a number of preferences for the rendering algorithms.
* Hint categories include controls for rendering quality and
* overall time/quality trade-off in the rendering process.
* @param hints The rendering hints to be set
* @see RenderingHints
*/
public void addRenderingHints(Map<?,?> hints) {
boolean customHintPresent = false;
Iterator<?> iter = hints.keySet().iterator();
while (iter.hasNext()) {
Object key = iter.next();
if (key == SunHints.KEY_RENDERING ||
key == SunHints.KEY_ANTIALIASING ||
key == SunHints.KEY_TEXT_ANTIALIASING ||
key == SunHints.KEY_FRACTIONALMETRICS ||
key == SunHints.KEY_TEXT_ANTIALIAS_LCD_CONTRAST ||
key == SunHints.KEY_STROKE_CONTROL ||
key == SunHints.KEY_INTERPOLATION)
{
setRenderingHint((Key) key, hints.get(key));
} else {
customHintPresent = true;
}
}
if (customHintPresent) {
if (this.hints == null) {
this.hints = makeHints(hints);
} else {
this.hints.putAll(hints);
}
}
}
public static Object getFontConfigAAHint(String fcFamily) {
if (FontUtilities.isWindows) {
return null;
} else {
int hint = getFontConfigAASettings(getFCLocaleStr(), fcFamily);
if (hint < 0) {
return null;
} else {
return SunHints.Value.get(SunHints.INTKEY_TEXT_ANTIALIASING,
hint);
}
}
}
public void drawString(SunGraphics2D g2d, String str, double x, double y) {
if ("".equals(str)) {
return; // TextLayout constructor throws IAE on "".
}
TextLayout tl = new TextLayout(str, g2d.getFont(),
g2d.getFontRenderContext());
Shape s = tl.getOutline(AffineTransform.getTranslateInstance(x, y));
int textAAHint = g2d.getFontInfo().aaHint;
int prevaaHint = - 1;
if (textAAHint != SunHints.INTVAL_TEXT_ANTIALIAS_OFF &&
g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
prevaaHint = g2d.antialiasHint;
g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON;
g2d.validatePipe();
} else if (textAAHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF
&& g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) {
prevaaHint = g2d.antialiasHint;
g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
g2d.validatePipe();
}
g2d.fill(s);
if (prevaaHint != -1) {
g2d.antialiasHint = prevaaHint;
g2d.validatePipe();
}
}
/**
* Adds a number of preferences for the rendering algorithms.
* Hint categories include controls for rendering quality and
* overall time/quality trade-off in the rendering process.
* @param hints The rendering hints to be set
* @see RenderingHints
*/
public void addRenderingHints(Map<?,?> hints) {
boolean customHintPresent = false;
Iterator<?> iter = hints.keySet().iterator();
while (iter.hasNext()) {
Object key = iter.next();
if (key == SunHints.KEY_RENDERING ||
key == SunHints.KEY_ANTIALIASING ||
key == SunHints.KEY_TEXT_ANTIALIASING ||
key == SunHints.KEY_FRACTIONALMETRICS ||
key == SunHints.KEY_TEXT_ANTIALIAS_LCD_CONTRAST ||
key == SunHints.KEY_STROKE_CONTROL ||
key == SunHints.KEY_INTERPOLATION)
{
setRenderingHint((Key) key, hints.get(key));
} else {
customHintPresent = true;
}
}
if (customHintPresent) {
if (this.hints == null) {
this.hints = makeHints(hints);
} else {
this.hints.putAll(hints);
}
}
}
public void fillRectangle(SunGraphics2D sg2d,
double rx, double ry,
double rw, double rh)
{
double px, py;
double dx1, dy1, dx2, dy2;
AffineTransform txform = sg2d.transform;
dx1 = txform.getScaleX();
dy1 = txform.getShearY();
dx2 = txform.getShearX();
dy2 = txform.getScaleY();
px = rx * dx1 + ry * dx2 + txform.getTranslateX();
py = rx * dy1 + ry * dy2 + txform.getTranslateY();
dx1 *= rw;
dy1 *= rw;
dx2 *= rh;
dy2 *= rh;
if (adjustfill &&
sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM &&
sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE)
{
double newx = normalize(px);
double newy = normalize(py);
dx1 = normalize(px + dx1) - newx;
dy1 = normalize(py + dy1) - newy;
dx2 = normalize(px + dx2) - newx;
dy2 = normalize(py + dy2) - newy;
px = newx;
py = newy;
}
outrenderer.fillParallelogram(sg2d, rx, ry, rx+rw, ry+rh,
px, py, dx1, dy1, dx2, dy2);
}
public void fillRectangle(SunGraphics2D sg2d,
double rx, double ry,
double rw, double rh)
{
double px, py;
double dx1, dy1, dx2, dy2;
AffineTransform txform = sg2d.transform;
dx1 = txform.getScaleX();
dy1 = txform.getShearY();
dx2 = txform.getShearX();
dy2 = txform.getScaleY();
px = rx * dx1 + ry * dx2 + txform.getTranslateX();
py = rx * dy1 + ry * dy2 + txform.getTranslateY();
dx1 *= rw;
dy1 *= rw;
dx2 *= rh;
dy2 *= rh;
if (adjustfill &&
sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM &&
sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE)
{
double newx = normalize(px);
double newy = normalize(py);
dx1 = normalize(px + dx1) - newx;
dy1 = normalize(py + dy1) - newy;
dx2 = normalize(px + dx2) - newx;
dy2 = normalize(py + dy2) - newy;
px = newx;
py = newy;
}
outrenderer.fillParallelogram(sg2d, rx, ry, rx+rw, ry+rh,
px, py, dx1, dy1, dx2, dy2);
}
public SunGraphics2D(SurfaceData sd, Color fg, Color bg, Font f) {
surfaceData = sd;
foregroundColor = fg;
backgroundColor = bg;
transform = new AffineTransform();
stroke = defaultStroke;
composite = defaultComposite;
paint = foregroundColor;
imageComp = CompositeType.SrcOverNoEa;
renderHint = SunHints.INTVAL_RENDER_DEFAULT;
antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
textAntialiasHint = SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT;
fractionalMetricsHint = SunHints.INTVAL_FRACTIONALMETRICS_OFF;
lcdTextContrast = lcdTextContrastDefaultValue;
interpolationHint = -1;
strokeHint = SunHints.INTVAL_STROKE_DEFAULT;
resolutionVariantHint = SunHints.INTVAL_RESOLUTION_VARIANT_DEFAULT;
interpolationType = AffineTransformOp.TYPE_NEAREST_NEIGHBOR;
validateColor();
devScale = sd.getDefaultScale();
if (devScale != 1) {
transform.setToScale(devScale, devScale);
invalidateTransform();
}
font = f;
if (font == null) {
font = defaultFont;
}
setDevClip(sd.getBounds());
invalidatePipe();
}
public void setFont(Font font) {
/* replacing the reference equality test font != this.font with
* !font.equals(this.font) did not yield any measurable difference
* in testing, but there may be yet to be identified cases where it
* is beneficial.
*/
if (font != null && font!=this.font/*!font.equals(this.font)*/) {
/* In the GASP AA case the textpipe depends on the glyph size
* as determined by graphics and font transforms as well as the
* font size, and information in the font. But we may invalidate
* the pipe only to find that it made no difference.
* Deferring pipe invalidation to checkFontInfo won't work because
* when called we may already be rendering to the wrong pipe.
* So, if the font is transformed, or the graphics has more than
* a simple scale, we'll take that as enough of a hint to
* revalidate everything. But if they aren't we will
* use the font's point size to query the gasp table and see if
* what it says matches what's currently being used, in which
* case there's no need to invalidate the textpipe.
* This should be sufficient for all typical uses cases.
*/
if (textAntialiasHint == SunHints.INTVAL_TEXT_ANTIALIAS_GASP &&
textpipe != invalidpipe &&
(transformState > TRANSFORM_ANY_TRANSLATE ||
font.isTransformed() ||
fontInfo == null || // Precaution, if true shouldn't get here
(fontInfo.aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_ON) !=
FontUtilities.getFont2D(font).
useAAForPtSize(font.getSize()))) {
textpipe = invalidpipe;
}
this.font = font;
this.fontMetrics = null;
this.validFontInfo = false;
}
}
/**
* Adds a number of preferences for the rendering algorithms.
* Hint categories include controls for rendering quality and
* overall time/quality trade-off in the rendering process.
* @param hints The rendering hints to be set
* @see RenderingHints
*/
public void addRenderingHints(Map<?,?> hints) {
boolean customHintPresent = false;
Iterator<?> iter = hints.keySet().iterator();
while (iter.hasNext()) {
Object key = iter.next();
if (key == SunHints.KEY_RENDERING ||
key == SunHints.KEY_ANTIALIASING ||
key == SunHints.KEY_TEXT_ANTIALIASING ||
key == SunHints.KEY_FRACTIONALMETRICS ||
key == SunHints.KEY_TEXT_ANTIALIAS_LCD_CONTRAST ||
key == SunHints.KEY_STROKE_CONTROL ||
key == SunHints.KEY_INTERPOLATION)
{
setRenderingHint((Key) key, hints.get(key));
} else {
customHintPresent = true;
}
}
if (customHintPresent) {
if (this.hints == null) {
this.hints = makeHints(hints);
} else {
this.hints.putAll(hints);
}
}
}
public void setFont(Font font) {
/* replacing the reference equality test font != this.font with
* !font.equals(this.font) did not yield any measurable difference
* in testing, but there may be yet to be identified cases where it
* is beneficial.
*/
if (font != null && font!=this.font/*!font.equals(this.font)*/) {
/* In the GASP AA case the textpipe depends on the glyph size
* as determined by graphics and font transforms as well as the
* font size, and information in the font. But we may invalidate
* the pipe only to find that it made no difference.
* Deferring pipe invalidation to checkFontInfo won't work because
* when called we may already be rendering to the wrong pipe.
* So, if the font is transformed, or the graphics has more than
* a simple scale, we'll take that as enough of a hint to
* revalidate everything. But if they aren't we will
* use the font's point size to query the gasp table and see if
* what it says matches what's currently being used, in which
* case there's no need to invalidate the textpipe.
* This should be sufficient for all typical uses cases.
*/
if (textAntialiasHint == SunHints.INTVAL_TEXT_ANTIALIAS_GASP &&
textpipe != invalidpipe &&
(transformState > TRANSFORM_ANY_TRANSLATE ||
font.isTransformed() ||
fontInfo == null || // Precaution, if true shouldn't get here
(fontInfo.aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_ON) !=
FontUtilities.getFont2D(font).
useAAForPtSize(font.getSize()))) {
textpipe = invalidpipe;
}
this.font = font;
this.fontMetrics = null;
this.validFontInfo = false;
}
}
/**
* Adds a number of preferences for the rendering algorithms.
* Hint categories include controls for rendering quality and
* overall time/quality trade-off in the rendering process.
* @param hints The rendering hints to be set
* @see RenderingHints
*/
public void addRenderingHints(Map<?,?> hints) {
boolean customHintPresent = false;
Iterator<?> iter = hints.keySet().iterator();
while (iter.hasNext()) {
Object key = iter.next();
if (key == SunHints.KEY_RENDERING ||
key == SunHints.KEY_ANTIALIASING ||
key == SunHints.KEY_TEXT_ANTIALIASING ||
key == SunHints.KEY_FRACTIONALMETRICS ||
key == SunHints.KEY_TEXT_ANTIALIAS_LCD_CONTRAST ||
key == SunHints.KEY_STROKE_CONTROL ||
key == SunHints.KEY_INTERPOLATION)
{
setRenderingHint((Key) key, hints.get(key));
} else {
customHintPresent = true;
}
}
if (customHintPresent) {
if (this.hints == null) {
this.hints = makeHints(hints);
} else {
this.hints.putAll(hints);
}
}
}