List of usage examples for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_ON
Object VALUE_TEXT_ANTIALIAS_ON
To view the source code for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_ON.
Click Source Link
From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphPanel.java
/** * Paints the panel component//from w w w. j av a 2s. c o m * * @param g The Graphics */ @Override protected void paintComponent(java.awt.Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); DrawGraph(g2, graphEx.GetGraphNodes()); }
From source file:org.geoserver.wms.legendgraphic.ColorMapLegendCreator.java
private Queue<BufferedImage> createBody() { final Queue<BufferedImage> queue = new LinkedList<BufferedImage>(); ///*from ww w .j a v a 2 s .com*/ // draw the various elements // // create the boxes for drawing later final int rowHeight = (int) Math.round(rowH); final int colorWidth = (int) Math.round(colorW); final int ruleWidth = (int) Math.round(ruleW); final int labelWidth = (int) Math.round(labelW); final Rectangle clipboxA = new Rectangle(0, 0, colorWidth, rowHeight); final Rectangle clipboxB = new Rectangle(0, 0, ruleWidth, rowHeight); final Rectangle clipboxC = new Rectangle(0, 0, labelWidth, rowHeight); // // Body // // // draw the various bodyCells for (ColorMapEntryLegendBuilder row : bodyRows) { // // row number i // // get element for color default behavior final Cell colorCell = row.getColorManager(); // draw it final BufferedImage colorCellLegend = new BufferedImage(colorWidth, rowHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D rlg = colorCellLegend.createGraphics(); rlg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rlg.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); colorCell.draw(rlg, clipboxA, border); rlg.dispose(); BufferedImage ruleCellLegend = null; if (forceRule) { // get element for rule final Cell ruleCell = row.getRuleManager(); // draw it ruleCellLegend = new BufferedImage(ruleWidth, rowHeight, BufferedImage.TYPE_INT_ARGB); rlg = ruleCellLegend.createGraphics(); rlg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rlg.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); ruleCell.draw(rlg, clipboxB, borderRule); rlg.dispose(); } // draw it if it is present if (labelWidth > 0) { // get element for label final Cell labelCell = row.getLabelManager(); if (labelCell != null) { final BufferedImage labelCellLegend = new BufferedImage(labelWidth, rowHeight, BufferedImage.TYPE_INT_ARGB); rlg = labelCellLegend.createGraphics(); rlg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rlg.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); labelCell.draw(rlg, clipboxC, borderLabel); rlg.dispose(); // // merge the bodyCells for this row // // final Map<Key, Object> hintsMap = new HashMap<Key, Object>(); queue.add(LegendUtils.hMergeBufferedImages(colorCellLegend, ruleCellLegend, labelCellLegend, hintsMap, transparent, backgroundColor, dx)); } else { final Map<Key, Object> hintsMap = new HashMap<Key, Object>(); queue.add(LegendUtils.hMergeBufferedImages(colorCellLegend, ruleCellLegend, null, hintsMap, transparent, backgroundColor, dx)); } } else { // // merge the bodyCells for this row // // final Map<Key, Object> hintsMap = new HashMap<Key, Object>(); queue.add(LegendUtils.hMergeBufferedImages(colorCellLegend, ruleCellLegend, null, hintsMap, transparent, backgroundColor, dx)); } } // return the list of legends return queue;// mergeRows(queue); }
From source file:org.jcurl.core.swing.RockLocationDisplayBase.java
public void exportPng(File dst) throws IOException { final BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = (Graphics2D) img.getGraphics(); {// w ww . j a v a2s.c o m final Map hints = new HashMap(); hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); hints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); hints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.addRenderingHints(hints); } this.paintComponent(g2); g2.dispose(); if (!dst.getName().endsWith(".png")) dst = new File(dst.getName() + ".png"); ImageIO.write(img, "png", dst); }
From source file:org.jcurl.core.swing.WCComponent.java
private BufferedImage renderPng(final String watermark) { final BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = (Graphics2D) img.getGraphics(); {//from www. j a v a2 s . c om final Map<Key, Object> hints = new HashMap<Key, Object>(); hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); hints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); hints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.addRenderingHints(hints); } final Font f0 = g2.getFont(); paint(g2); g2.setTransform(new AffineTransform()); if (watermark != null) { if (log.isDebugEnabled()) log.debug(f0); g2.setFont(f0); g2.setColor(new Color(0, 0, 0, 128)); g2.drawString(watermark, 10, 20); } g2.dispose(); return img; }
From source file:org.kalypso.contribs.eclipse.jobs.BufferPaintJob.java
/** * Configures the graphics-context before actual painting is started (i.e. {@link IPaintable#paint(Graphics2D, IProgressMonitor)} is called).<br> * Default behaviour is to set activate anti-aliasing (normal and text).<br> * Overwrite to change./* w ww . j a va2 s .c o m*/ */ private void configureGraphics(final Graphics2D gr) { gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); gr.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); }
From source file:org.kalypso.ogc.gml.map.MapPanel.java
/** * Paints contents of the map in the following order: * <ul>//from w w w.j av a 2 s . c o m * <li>the buffered image containing the layers</li> * <li>the status, if not OK</li> * <li>all 'paint-listeners'</li> * <li>the current widget</li> * </ul> * * @see java.awt.Component#paint(java.awt.Graphics) */ @Override public void paint(final Graphics g) { final int width = getWidth(); final int height = getHeight(); if (height == 0 || width == 0) return; // only recreate buffered image if size has changed if (m_imageBuffer == null || m_imageBuffer.getWidth() != width || m_imageBuffer.getHeight() != height) m_imageBuffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); else // this seems to be enough for clearing the image here m_imageBuffer.flush(); Graphics2D bufferGraphics = null; try { bufferGraphics = m_imageBuffer.createGraphics(); bufferGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); bufferGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); final BufferPaintJob bufferPaintJob = m_bufferPaintJob; // get copy (for more thread safety) if (bufferPaintJob != null) { paintBufferedMap(bufferGraphics, bufferPaintJob); } // TODO: at the moment, we paint the status just on top of the map, if we change this component to SWT, we should // show the statusComposite in a title bar, if the status is non-OK (with details button for a stack trace) paintStatus(bufferGraphics); final IMapPanelPaintListener[] pls = m_paintListeners.toArray(new IMapPanelPaintListener[] {}); for (final IMapPanelPaintListener pl : pls) pl.paint(bufferGraphics); paintWidget(bufferGraphics); } finally { if (bufferGraphics != null) bufferGraphics.dispose(); } if (m_isMultitouchEnabled) { final IMapPanelMTPaintListener[] postls = m_postPaintListeners .toArray(new IMapPanelMTPaintListener[] {}); for (final IMapPanelMTPaintListener pl : postls) pl.paint(m_imageBuffer); } else { g.drawImage(m_imageBuffer, 0, 0, null); } }
From source file:org.pentaho.di.core.gui.SwingDirectGC.java
public void setAntialias(boolean antiAlias) { if (antiAlias) { RenderingHints hints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY)); hints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)); // hints.add(new RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION, // RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)); gc.setRenderingHints(hints);/* ww w .jav a2s .c om*/ } }
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; }/* ww w . j ava 2s .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;// w w w . j av a2 s .co 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 w w. j a v a 2 s. co 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; }