List of usage examples for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_OFF
Object VALUE_TEXT_ANTIALIAS_OFF
To view the source code for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_OFF.
Click Source Link
From source file:lucee.runtime.img.Image.java
public void setAntiAliasing(boolean antiAlias) throws ExpressionException { this.antiAlias = antiAlias ? ANTI_ALIAS_ON : ANTI_ALIAS_OFF; Graphics2D graphics = getGraphics(); if (antiAlias) { graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } else {/*ww w. j a v a 2 s .c o m*/ graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } }
From source file:freemind.controller.Controller.java
public void setTextRenderingHint(Graphics2D g) { g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, (getAntialiasAll()) ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, (getAntialiasAll()) ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); }
From source file:DefaultGraphics2D.java
/** * Get the rendering context of the <code>Font</code> within this * <code>Graphics2D</code> context. The {@link FontRenderContext} * encapsulates application hints such as anti-aliasing and fractional * metrics, as well as target device specific information such as * dots-per-inch. This information should be provided by the application when * using objects that perform typographical formatting, such as * <code>Font</code> and <code>TextLayout</code>. This information should * also be provided by applications that perform their own layout and need * accurate measurements of various characteristics of glyphs such as advance * and line height when various rendering hints have been applied to the text * rendering./*from w w w .j av a 2s . c o m*/ * * @return a reference to an instance of FontRenderContext. * @see java.awt.font.FontRenderContext * @see java.awt.Font#createGlyphVector(FontRenderContext,char[]) * @see java.awt.font.TextLayout * @since JDK1.2 */ public FontRenderContext getFontRenderContext() { // // Find if antialiasing should be used. // Object antialiasingHint = hints.get(RenderingHints.KEY_TEXT_ANTIALIASING); boolean isAntialiased = true; if (antialiasingHint != RenderingHints.VALUE_TEXT_ANTIALIAS_ON && antialiasingHint != RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT) { // If antialias was not turned off, then use the general rendering // hint. if (antialiasingHint != RenderingHints.VALUE_TEXT_ANTIALIAS_OFF) { antialiasingHint = hints.get(RenderingHints.KEY_ANTIALIASING); // Test general hint if (antialiasingHint != RenderingHints.VALUE_ANTIALIAS_ON && antialiasingHint != RenderingHints.VALUE_ANTIALIAS_DEFAULT) { // Antialiasing was not requested. However, if it was not turned // off explicitly, use it. if (antialiasingHint == RenderingHints.VALUE_ANTIALIAS_OFF) isAntialiased = false; } } else isAntialiased = false; } // // Find out whether fractional metrics should be used. // boolean useFractionalMetrics = true; if (hints.get(RenderingHints.KEY_FRACTIONALMETRICS) == RenderingHints.VALUE_FRACTIONALMETRICS_OFF) useFractionalMetrics = false; FontRenderContext frc = new FontRenderContext(defaultTransform, isAntialiased, useFractionalMetrics); return frc; }
From source file:org.forester.archaeopteryx.TreePanel.java
final void setTextAntialias() { if ((_phylogeny != null) && !_phylogeny.isEmpty()) { if (_phylogeny.getNumberOfExternalNodes() <= LIMIT_FOR_HQ_RENDERING) { _rendering_hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); } else {//from ww w . j ava2s. c o m _rendering_hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); } } if (getMainPanel().getOptions().isAntialiasScreen()) { if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR) { _rendering_hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } else { _rendering_hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } try { _rendering_hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); } catch (final Throwable e) { _rendering_hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } } else { _rendering_hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); _rendering_hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } }
From source file:org.apache.fop.render.bitmap.AbstractBitmapDocumentHandler.java
/** {@inheritDoc} */ public IFPainter startPageContent() throws IFException { int bitmapWidth; int bitmapHeight; double scale; Point2D offset = null;/*w w w.j ava 2s. co m*/ if (targetBitmapSize != null) { //Fit the generated page proportionally into the given rectangle (in pixels) double scale2w = 1000 * targetBitmapSize.width / this.currentPageDimensions.getWidth(); double scale2h = 1000 * targetBitmapSize.height / this.currentPageDimensions.getHeight(); bitmapWidth = targetBitmapSize.width; bitmapHeight = targetBitmapSize.height; //Centering the page in the given bitmap offset = new Point2D.Double(); if (scale2w < scale2h) { scale = scale2w; double h = this.currentPageDimensions.height * scale / 1000; offset.setLocation(0, (bitmapHeight - h) / 2.0); } else { scale = scale2h; double w = this.currentPageDimensions.width * scale / 1000; offset.setLocation((bitmapWidth - w) / 2.0, 0); } } else { //Normal case: just scale according to the target resolution scale = scaleFactor * getUserAgent().getTargetResolution() / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION; bitmapWidth = (int) ((this.currentPageDimensions.width * scale / 1000f) + 0.5f); bitmapHeight = (int) ((this.currentPageDimensions.height * scale / 1000f) + 0.5f); } //Set up bitmap to paint on this.currentImage = createBufferedImage(bitmapWidth, bitmapHeight); Graphics2D graphics2D = this.currentImage.createGraphics(); // draw page background if (!getSettings().hasTransparentPageBackground()) { graphics2D.setBackground(getSettings().getPageBackgroundColor()); graphics2D.setPaint(getSettings().getPageBackgroundColor()); graphics2D.fillRect(0, 0, bitmapWidth, bitmapHeight); } //Set rendering hints graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); if (getSettings().isAntiAliasingEnabled() && this.currentImage.getColorModel().getPixelSize() > 1) { graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } if (getSettings().isQualityRenderingEnabled()) { graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); } else { graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); } graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); //Set up initial coordinate system for the page if (offset != null) { graphics2D.translate(offset.getX(), offset.getY()); } graphics2D.scale(scale / 1000f, scale / 1000f); return new Java2DPainter(graphics2D, getContext(), getFontInfo()); }
From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java
protected String getRenderingStyle(Object key) { Object value = renderingHints.get(key); if (key.equals(RenderingHints.KEY_TEXT_ANTIALIASING)) { if (value.equals(RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)) { // Adobe SVG viewer 3 bug. Rotated text with optimizelegibility // disappears. Replace // with optimizespeed for rotated text. if (transforms.getType() != AffineTransform.TYPE_IDENTITY) return "text-rendering:optimizeSpeed;";//$NON-NLS-1$ else/*www . java 2 s.com*/ return "text-rendering:optimizeLegibility;";//$NON-NLS-1$ } else // SVG always turns on antialias return ""; //$NON-NLS-1$ } return "";//$NON-NLS-1$ }
From source file:org.pentaho.reporting.engine.classic.core.layout.output.RenderUtility.java
public static DefaultImageReference createImageFromDrawable(final DrawableWrapper drawable, final StrictBounds rect, final StyleSheet box, final OutputProcessorMetaData metaData) { final int imageWidth = (int) StrictGeomUtility.toExternalValue(rect.getWidth()); final int imageHeight = (int) StrictGeomUtility.toExternalValue(rect.getHeight()); if (imageWidth == 0 || imageHeight == 0) { return null; }/* w ww . j a va2s . c o m*/ final double scale = RenderUtility.getNormalizationScale(metaData); final Image image = ImageUtils.createTransparentImage((int) (imageWidth * scale), (int) (imageHeight * scale)); final Graphics2D g2 = (Graphics2D) image.getGraphics(); final Object attribute = box.getStyleProperty(ElementStyleKeys.ANTI_ALIASING); if (attribute != null) { if (Boolean.TRUE.equals(attribute)) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } else if (Boolean.FALSE.equals(attribute)) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } } if (RenderUtility.isFontSmooth(box, metaData)) { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } g2.scale(scale, scale); // the clipping bounds are a sub-area of the whole drawable // we only want to print a certain area ... final String fontName = (String) box.getStyleProperty(TextStyleKeys.FONT); final int fontSize = box.getIntStyleProperty(TextStyleKeys.FONTSIZE, 8); final boolean bold = box.getBooleanStyleProperty(TextStyleKeys.BOLD); final boolean italics = box.getBooleanStyleProperty(TextStyleKeys.ITALIC); if (bold && italics) { g2.setFont(new Font(fontName, Font.BOLD | Font.ITALIC, fontSize)); } else if (bold) { g2.setFont(new Font(fontName, Font.BOLD, fontSize)); } else if (italics) { g2.setFont(new Font(fontName, Font.ITALIC, fontSize)); } else { g2.setFont(new Font(fontName, Font.PLAIN, fontSize)); } g2.setStroke((Stroke) box.getStyleProperty(ElementStyleKeys.STROKE)); g2.setPaint((Paint) box.getStyleProperty(ElementStyleKeys.PAINT)); drawable.draw(g2, new Rectangle2D.Double(0, 0, imageWidth, imageHeight)); g2.dispose(); try { return new DefaultImageReference(image); } catch (final IOException e1) { logger.warn("Unable to fully load a given image. (It should not happen here.)", e1); return null; } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java
protected void processOtherNode(final RenderNode node) { if (node.isNodeVisible(drawArea) == false) { return;//from w w w . j a v a2 s. c o m } final int type = node.getNodeType(); if (isTextLineOverflow()) { if (node.isVirtualNode()) { if (ellipseDrawn == false) { if (isClipOnWordBoundary() == false && type == LayoutNodeTypes.TYPE_NODE_TEXT) { final RenderableText text = (RenderableText) node; final long ellipseSize = extractEllipseSize(node); final long x1 = text.getX(); final long effectiveAreaX2 = (contentAreaX2 - ellipseSize); if (x1 < contentAreaX2) { // The text node that is printed will overlap with the ellipse we need to print. drawText(text, effectiveAreaX2); } } else if (isClipOnWordBoundary() == false && type == LayoutNodeTypes.TYPE_NODE_COMPLEX_TEXT) { final RenderableComplexText text = (RenderableComplexText) node; // final long ellipseSize = extractEllipseSize(node); final long x1 = text.getX(); // final long effectiveAreaX2 = (contentAreaX2 - ellipseSize); if (x1 < contentAreaX2) { // The text node that is printed will overlap with the ellipse we need to print. final Graphics2D g2; if (getTextSpec() == null) { g2 = (Graphics2D) getGraphics().create(); final StyleSheet layoutContext = text.getStyleSheet(); configureGraphics(layoutContext, g2); g2.setStroke(LogicalPageDrawable.DEFAULT_STROKE); if (RenderUtility.isFontSmooth(layoutContext, metaData)) { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } } else { g2 = getTextSpec().getGraphics(); } drawComplexText(text, g2); } } ellipseDrawn = true; final RenderBox parent = node.getParent(); if (parent != null) { final RenderBox textEllipseBox = parent.getTextEllipseBox(); if (textEllipseBox != null) { processBoxChilds(textEllipseBox); } } return; } } } if (type == LayoutNodeTypes.TYPE_NODE_TEXT) { final RenderableText text = (RenderableText) node; if (underline != null) { final ExtendedBaselineInfo baselineInfo = text.getBaselineInfo(); final long underlinePos = text.getY() + baselineInfo.getUnderlinePosition(); underline.updateVerticalPosition(StrictGeomUtility.toExternalValue(underlinePos)); underline.updateStart(StrictGeomUtility.toExternalValue(text.getX())); underline.updateEnd(StrictGeomUtility.toExternalValue(text.getX() + text.getWidth())); } if (strikeThrough != null) { final ExtendedBaselineInfo baselineInfo = text.getBaselineInfo(); final long strikethroughPos = text.getY() + baselineInfo.getStrikethroughPosition(); strikeThrough.updateVerticalPosition(StrictGeomUtility.toExternalValue(strikethroughPos)); strikeThrough.updateStart(StrictGeomUtility.toExternalValue(text.getX())); strikeThrough.updateEnd(StrictGeomUtility.toExternalValue(text.getX() + text.getWidth())); } if (isTextLineOverflow()) { final long ellipseSize = extractEllipseSize(node); final long x1 = text.getX(); final long x2 = x1 + text.getWidth(); final long effectiveAreaX2 = (contentAreaX2 - ellipseSize); if (x2 <= effectiveAreaX2) { // the text will be fully visible. drawText(text); } else { if (x1 < contentAreaX2) { // The text node that is printed will overlap with the ellipse we need to print. drawText(text, effectiveAreaX2); } final RenderBox parent = node.getParent(); if (parent != null) { final RenderBox textEllipseBox = parent.getTextEllipseBox(); if (textEllipseBox != null) { processBoxChilds(textEllipseBox); } } ellipseDrawn = true; } } else { drawText(text); } } else if (type == LayoutNodeTypes.TYPE_NODE_COMPLEX_TEXT) { final RenderableComplexText text = (RenderableComplexText) node; final long x1 = text.getX(); if (x1 < contentAreaX2) { // The text node that is printed will overlap with the ellipse we need to print. final Graphics2D g2; if (getTextSpec() == null) { g2 = (Graphics2D) getGraphics().create(); final StyleSheet layoutContext = text.getStyleSheet(); configureGraphics(layoutContext, g2); g2.setStroke(LogicalPageDrawable.DEFAULT_STROKE); if (RenderUtility.isFontSmooth(layoutContext, metaData)) { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } } else { g2 = getTextSpec().getGraphics(); } drawComplexText(text, g2); } } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java
protected boolean drawDrawable(final RenderableReplacedContentBox content, final Graphics2D g2, final DrawableWrapper d) { final double x = StrictGeomUtility.toExternalValue(content.getX()); final double y = StrictGeomUtility.toExternalValue(content.getY()); final double width = StrictGeomUtility.toExternalValue(content.getWidth()); final double height = StrictGeomUtility.toExternalValue(content.getHeight()); if ((width < 0 || height < 0) || (width == 0 && height == 0)) { return false; }//from w ww .j a v a 2s .c o m final Graphics2D clone = (Graphics2D) g2.create(); final StyleSheet styleSheet = content.getStyleSheet(); final Object attribute = styleSheet.getStyleProperty(ElementStyleKeys.ANTI_ALIASING); if (attribute != null) { if (Boolean.TRUE.equals(attribute)) { clone.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } else if (Boolean.FALSE.equals(attribute)) { clone.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } } if (RenderUtility.isFontSmooth(styleSheet, metaData)) { clone.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { clone.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } if (strictClipping == false) { final double extraPadding; final Object o = styleSheet.getStyleProperty(ElementStyleKeys.STROKE); if (o instanceof BasicStroke) { final BasicStroke stroke = (BasicStroke) o; extraPadding = stroke.getLineWidth() / 2.0; } else { extraPadding = 0.5; } final Rectangle2D.Double clipBounds = new Rectangle2D.Double(x - extraPadding, y - extraPadding, width + 2 * extraPadding, height + 2 * extraPadding); clone.clip(clipBounds); clone.translate(x, y); } else { final Rectangle2D.Double clipBounds = new Rectangle2D.Double(x, y, width + 1, height + 1); clone.clip(clipBounds); clone.translate(x, y); } configureGraphics(styleSheet, clone); configureStroke(styleSheet, clone); final Rectangle2D.Double bounds = new Rectangle2D.Double(0, 0, width, height); d.draw(clone, bounds); clone.dispose(); return true; }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java
/** * Renders the glyphs stored in the text node. * * @param renderableText//www.j av a 2 s. c om * the text node that should be rendered. * @param contentX2 */ protected void drawText(final RenderableText renderableText, final long contentX2) { if (renderableText.getLength() == 0) { // This text is empty. return; } final long posX = renderableText.getX(); final long posY = renderableText.getY(); final Graphics2D g2; if (getTextSpec() == null) { g2 = (Graphics2D) getGraphics().create(); final StyleSheet layoutContext = renderableText.getStyleSheet(); configureGraphics(layoutContext, g2); g2.setStroke(LogicalPageDrawable.DEFAULT_STROKE); if (RenderUtility.isFontSmooth(layoutContext, metaData)) { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } } else { g2 = getTextSpec().getGraphics(); } // This shifting is necessary to make sure that all text is rendered like in the previous versions. // In the earlier versions, we did not really obey to the baselines of the text, we just hoped and prayed. // Therefore, all text was printed at the bottom of the text elements. With the introduction of the full // font metrics setting, this situation got a little bit better, for the price that text-elements became // nearly unpredictable .. // // The code below may be weird, but at least it is predictable weird. final FontMetrics fm = g2.getFontMetrics(); final Rectangle2D rect = fm.getMaxCharBounds(g2); final long awtBaseLine = StrictGeomUtility.toInternalValue(-rect.getY()); final GlyphList gs = renderableText.getGlyphs(); if (metaData.isFeatureSupported(OutputProcessorFeature.FAST_FONTRENDERING) && isNormalTextSpacing(renderableText)) { final int maxLength = renderableText.computeMaximumTextSize(contentX2); final String text = gs.getText(renderableText.getOffset(), maxLength, codePointBuffer); final float y = (float) StrictGeomUtility.toExternalValue(posY + awtBaseLine); g2.drawString(text, (float) StrictGeomUtility.toExternalValue(posX), y); } else { final ExtendedBaselineInfo baselineInfo = renderableText.getBaselineInfo(); final int maxPos = renderableText.getOffset() + renderableText.computeMaximumTextSize(contentX2); long runningPos = posX; final long baseline = baselineInfo.getBaseline(baselineInfo.getDominantBaseline()); final long baselineDelta = awtBaseLine - baseline; final float y = (float) (StrictGeomUtility.toExternalValue(posY + awtBaseLine + baselineDelta)); for (int i = renderableText.getOffset(); i < maxPos; i++) { final Glyph g = gs.getGlyph(i); g2.drawString(gs.getGlyphAsString(i, codePointBuffer), (float) StrictGeomUtility.toExternalValue(runningPos), y); runningPos += RenderableText.convert(g.getWidth()) + g.getSpacing().getMinimum(); } } g2.dispose(); }