@Override public void renderFogOfWar(final Graphics2D g) { if (this.fogOfWar == null) { return; } final AffineTransform oldTransform = g.getTransform(); final AffineTransform at = new AffineTransform(); at.scale(Game.getCamera().getRenderScale(), Game.getCamera().getRenderScale()); at.translate(Game.getCamera().getPixelOffsetX(), Game.getCamera().getPixelOffsetY()); g.setTransform(at); g.setColor(FogOfWarColor); g.fill(this.fogOfWar); g.setTransform(oldTransform); }
protected void deviceFill(PathIterator pathIter, Color color, AffineTransform tx, Shape clip) { setTransform(tx); setClip(clip); setColor(color); convertToPSPath(pathIter); /* Specify the path to fill as the clip, this ensures that only * pixels which are inside the path will be filled, which is * what the Java 2D APIs specify */ mPSStream.println(GSAVE_STR); selectClipPath(); fillPath(); mPSStream.println(GRESTORE_STR + " " + NEWPATH_STR); }
public static boolean compare(AffineTransform at1, AffineTransform at2) { maxulps = Math.max(maxulps, ulps(at1.getScaleX(), at2.getScaleX())); maxulps = Math.max(maxulps, ulps(at1.getScaleY(), at2.getScaleY())); maxulps = Math.max(maxulps, ulps(at1.getShearX(), at2.getShearX())); maxulps = Math.max(maxulps, ulps(at1.getShearY(), at2.getShearY())); maxtxulps = Math.max(maxtxulps, ulps(at1.getTranslateX(), at2.getTranslateX())); maxtxulps = Math.max(maxtxulps, ulps(at1.getTranslateY(), at2.getTranslateY())); return (getModifiedType(at1) == getModifiedType(at2) && (compare(at1.getScaleX(), at2.getScaleX(), MAX_ULPS)) && (compare(at1.getScaleY(), at2.getScaleY(), MAX_ULPS)) && (compare(at1.getShearX(), at2.getShearX(), MAX_ULPS)) && (compare(at1.getShearY(), at2.getShearY(), MAX_ULPS)) && (compare(at1.getTranslateX(), at2.getTranslateX(), MAX_TX_ULPS)) && (compare(at1.getTranslateY(), at2.getTranslateY(), MAX_TX_ULPS))); }
/** * Construct AffineTransformOp with the given xform and rendering hints. * * @param xform AffineTransform that will applied to the source image * @param hints rendering hints that will be used during transformation * @throws ImagingOpException if the transform matrix is noninvertible */ public AffineTransformOp (AffineTransform xform, RenderingHints hints) { this.transform = xform; this.hints = hints; if (xform.getDeterminant() == 0) throw new ImagingOpException(null); }
private void drawFrame(GraphicsDecorator g, Shape shape, Color color, Point2D.Float pos) { Shape old_clip = g.getClip(); AffineTransform old = g.getTransform(); AffineTransform t = g.getTransform(); t.concatenate(AffineTransform.getTranslateInstance(pos.x, pos.y)); g.setTransform(t); g.setColor(color); Stroke old_stroke = g.getStroke(); g.setStroke(new BasicStroke(10.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); Area a = new Area(g.getClip()); a.subtract(new Area(shape)); g.setClip(a); g.draw(shape); g.setTransform(old); g.setStroke(old_stroke); g.setClip(old_clip); }
/** * Modify the GeometricLayer so the layer coordinate system matches the image coordinate system ("pixel" projection). */ public static GeometryImage createImageProjected(GeometryImage layer, AffineTransform geoTransform) { for(Geometry geom:layer.geoms){ for(Coordinate pos:geom.getCoordinates()){ Point2D.Double temp=new Point2D.Double(); try { geoTransform.inverseTransform(new Point2D.Double(pos.x, pos.y),temp); } catch (NoninvertibleTransformException e) { e.printStackTrace(); } pos.x=temp.x; pos.y=temp.y; } } return layer; }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; AffineTransform origXform = g2d.getTransform(); AffineTransform newXform = (AffineTransform) (origXform.clone()); //center of rotation is center of the panel int xRot = this.getWidth() / 2; int yRot = this.getHeight() / 2; newXform.rotate((2 * Math.PI) - currentAngle, xRot, yRot); g2d.setTransform(newXform); //draw image centered in panel int x = (getWidth() - image.getWidth(this)) / 2; int y = (getHeight() - image.getHeight(this)) / 2; g2d.drawImage(image, x, y, this); g2d.setTransform(origXform); }
public AATileGenerator getAATileGenerator(Shape s, AffineTransform at, Region clip, BasicStroke bs, boolean thin, boolean normalize, int bbox[]) { System.out.println(name+".getAATileGenerator("+ s.getClass().getName()+", "+ at+", "+ clip+", "+ bs+", "+ (thin ? "thin" : "wide")+", "+ (normalize ? "normalized" : "pure")+")"); return target.getAATileGenerator(s, at, clip, bs, thin, normalize, bbox); }
public void draw(Graphics2D g) { arc = null;; arc2 = null;; if( path==null)return; AffineTransform at = g.getTransform(); if( !enabled || line==null) return; g.setStroke( new BasicStroke(4.f/(float)map.getZoom()) ); g.setColor(Color.white); g.draw( path ); double wrap = map.getWrap(); if( wrap>0.) { g.translate(wrap, 0.); g.draw( path ); } g.setTransform(at); }
public void strokeTo(Shape src, AffineTransform at, BasicStroke bs, boolean thin, boolean normalize, boolean antialias, PathConsumer2D consumer) { System.out.println(name+".strokeTo("+ src.getClass().getName()+", "+ at+", "+ bs+", "+ (thin ? "thin" : "wide")+", "+ (normalize ? "normalized" : "pure")+", "+ (antialias ? "AA" : "non-AA")+", "+ consumer.getClass().getName()+")"); target.strokeTo(src, at, bs, thin, normalize, antialias, consumer); }
@Override protected void paintComponent(Graphics g) { atualizar(); 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.setFont(FONT); FontRenderContext frc = g2.getFontRenderContext(); TextLayout textLayout = new TextLayout(Integer.toString(value), FONT, frc); g2.setPaint(textColor); AffineTransform at = AffineTransform.getTranslateInstance(20, 30); Shape outline = textLayout.getOutline(at); g2.fill(outline); g2.setPaint(BLACK); g2.draw(outline); }
public void draw(Graphics g, Map map) { if (drawGhost) { final Point p = map.componentCoordinates(getGhostPosition()); final Graphics2D g2d = (Graphics2D) g.create(); g2d.transform( AffineTransform.getRotateInstance(-PI_180 * tempAngle, p.x + centerX(), p.y + centerY())); g2d.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); piece.draw(g2d, p.x, p.y, map.getView(), map.getZoom()); g2d.dispose(); } }
public void draw(Graphics g, int x, int y, Component obs, double zoom) { if (invisibleToMe()) { return; } else if (invisibleToOthers()) { final Graphics2D g2d = (Graphics2D) g; if (bgColor != null) { g.setColor(bgColor); final AffineTransform t = AffineTransform.getScaleInstance(zoom, zoom); t.translate(x / zoom, y / zoom); g2d.fill(t.createTransformedShape(piece.getShape())); } final Composite oldComposite = g2d.getComposite(); g2d.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transparency) ); piece.draw(g, x, y, obs, zoom); g2d.setComposite(oldComposite); } else { piece.draw(g, x, y, obs, zoom); } }
private void drawYLabel(Graphics2D chartGraphics) { if (yAxisLabel != null) { // Strings are drawn from the baseline position of the leftmost char. int yPosYAxisLabel = heatMapC.y + (yAxisLabelSize.width / 2); int xPosYAxisLabel = (margin / 2) + yAxisLabelAscent; chartGraphics.setFont(axisLabelsFont); chartGraphics.setColor(axisLabelColour); // Create 270 degree rotated transform. AffineTransform transform = chartGraphics.getTransform(); AffineTransform originalTransform = (AffineTransform) transform.clone(); transform.rotate(Math.toRadians(270), xPosYAxisLabel, yPosYAxisLabel); chartGraphics.setTransform(transform); // Draw string. chartGraphics.drawString(yAxisLabel, xPosYAxisLabel, yPosYAxisLabel); // Revert to original transform before rotation. chartGraphics.setTransform(originalTransform); } }
public float getItalicAngle(Font font, AffineTransform at, Object aaHint, Object fmHint) { /* hardwire psz=12 as that's typical and AA vs non-AA for 'gasp' mode * isn't important for the caret slope of this rarely used API. */ int aa = FontStrikeDesc.getAAHintIntVal(aaHint, this, 12); int fm = FontStrikeDesc.getFMHintIntVal(fmHint); FontStrike strike = getStrike(font, at, aa, fm); StrikeMetrics metrics = strike.getFontMetrics(); if (metrics.ascentY == 0 || metrics.ascentX == 0) { return 0f; } else { /* ascent is "up" from the baseline so its typically * a negative value, so we need to compensate */ return metrics.ascentX/-metrics.ascentY; } }
public ImageUtils reverse(boolean isVertical){ int width = this.dealedImage.getWidth(); int height = this.dealedImage.getHeight(); double[] matrix; if(isVertical){ matrix = new double[]{1, 0, 0, -1, 0,height}; }else { matrix = new double[]{-1, 0, 0, 1,width,0}; } AffineTransform affineTransform = new AffineTransform(matrix); BufferedImage newImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = newImg.createGraphics(); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.drawRenderedImage(this.dealedImage, affineTransform); g.dispose(); this.dealedImage = newImg; return this; }
/** * Applies an AffineTransform the current image. * @param transform The transform to apply. */ default void applyTransform(AffineTransform transform) { if (hasSelection()) { setDirty(); // Get the original location of the selection Point originalLocation = getSelectionLocation(); // Transform the selected image setSelectedImage(Transform.transform(getSelectedImage(), transform)); // Relocate the image to its original location Rectangle newBounds = getSelectedImage().getRaster().getBounds(); newBounds.setLocation(originalLocation); setSelectionOutline(newBounds); redrawSelection(); } }
public void Transform(SurfaceData src, SurfaceData dst, Composite comp, Region clip, AffineTransform at, int hint, int srcx, int srcy, int dstx, int dsty, int width, int height) { tracePrimitive(target); target.Transform(src, dst, comp, clip, at, hint, srcx, srcy, dstx, dsty, width, height); }
/** * Paints the background of an arrow button. Arrow buttons are created by * some components, such as <code>JScrollBar</code>. * * @param context SynthContext identifying the <code>JComponent</code> and * <code>Region</code> to paint to * @param g <code>Graphics</code> to paint to * @param x X coordinate of the area to paint to * @param y Y coordinate of the area to paint to * @param w Width of the area to paint to * @param h Height of the area to paint to */ public void paintArrowButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { if (context.getComponent().getComponentOrientation().isLeftToRight()){ paintBackground(context, g, x, y, w, h, null); } else { AffineTransform transform = new AffineTransform(); transform.translate(x,y); transform.scale(-1, 1); transform.translate(-w,0); paintBackground(context, g, 0, 0, w, h, transform); } }
public void Transform(SurfaceData src, SurfaceData dst, Composite comp, Region clip, AffineTransform at, int hint, int sx, int sy, int dx, int dy, int w, int h) { OGLBlitLoops.Blit(src, dst, comp, clip, at, hint, sx, sy, sx+w, sy+h, dx, dy, dx+w, dy+h, typeval, false); }
public static AffineTransform getCharTransform(Map<?, ?> map) { if (map != null) { AttributeValues av = null; if (map instanceof AttributeMap && ((AttributeMap) map).getValues() != null) { av = ((AttributeMap)map).getValues(); } else if (map.get(TextAttribute.TRANSFORM) != null) { av = AttributeValues.fromMap((Map<Attribute, ?>)map); // yuck } if (av != null) { return av.charTransform; } } return null; }
/** * Resize image using Java 2D * * @param artwork * @param size * @throws java.io.IOException */ public void makeSmaller(Artwork artwork, int size) throws IOException { Image srcImage = (Image) artwork.getImage(); int w = srcImage.getWidth(null); int h = srcImage.getHeight(null); // Determine the scaling required to get desired result. float scaleW = (float) size / (float) w; float scaleH = (float) size / (float) h; //Create an image buffer in which to paint on, create as an opaque Rgb type image, it doesnt matter what type //the original image is we want to convert to the best type for displaying on screen regardless BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); // Set the scale. AffineTransform tx = new AffineTransform(); tx.scale(scaleW, scaleH); // Paint image. Graphics2D g2d = bi.createGraphics(); g2d.drawImage(srcImage, tx, null); g2d.dispose(); if (artwork.getMimeType() != null && isMimeTypeWritable(artwork.getMimeType())) { artwork.setBinaryData(writeImage(bi, artwork.getMimeType())); } else { artwork.setBinaryData(writeImageAsPng(bi)); } }
public void Transform(SurfaceData src, SurfaceData dst, Composite comp, Region clip, AffineTransform at, int hint, int sx, int sy, int dx, int dy, int w, int h) { D3DBlitLoops.Blit(src, dst, comp, clip, at, hint, sx, sy, sx+w, sy+h, dx, dy, dx+w, dy+h, typeval, false); }
AffineTransform getGlyphTransform(int ix) { int index = indices[ix]; if (index == 0) { return null; } int x = (index - 1) * 6; return new AffineTransform(transforms[x + 0], transforms[x + 1], transforms[x + 2], transforms[x + 3], transforms[x + 4], transforms[x + 5]); }
public static void main(String[] args) { GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); AffineTransform normTransform = gc.getNormalizingTransform(); int dpiX = Toolkit.getDefaultToolkit().getScreenResolution(); int normDpiX = (int)(normTransform.getScaleX() * 72.0); if (dpiX != normDpiX) { throw new RuntimeException( "Test FAILED. Toolkit.getScreenResolution()=" + dpiX + " GraphicsConfiguration.getNormalizingTransform()="+normDpiX); } System.out.println("Test PASSED. DPI="+normDpiX); }
private static FontRenderContext getFRCFromCache(AffineTransform tx, Object aaHint) { if (tx == null && aaHint == null) { return null; } @SuppressWarnings("unchecked") Map<Object, FontRenderContext> cache = (Map<Object, FontRenderContext>) AppContext.getAppContext().get(APP_CONTEXT_FRC_CACHE_KEY); if (cache == null) { cache = new HashMap<>(); AppContext.getAppContext().put(APP_CONTEXT_FRC_CACHE_KEY, cache); } Object key = (tx == null) ? aaHint : (aaHint == null ? tx : new KeyPair(tx, aaHint)); FontRenderContext frc = cache.get(key); if (frc == null) { aaHint = (aaHint == null) ? VALUE_TEXT_ANTIALIAS_OFF : aaHint; frc = new FontRenderContext(tx, aaHint, VALUE_FRACTIONALMETRICS_DEFAULT); cache.put(key, frc); } return frc; }
synchronized void updateNativeImage(Image image) { if (isDisposed()) return; boolean autosize = ((TrayIcon)target).isImageAutoSize(); AffineTransform tx = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(). getDefaultTransform(); int w = Region.clipScale(TRAY_ICON_WIDTH, tx.getScaleX()); int h = Region.clipScale(TRAY_ICON_HEIGHT, tx.getScaleY()); int imgWidth = Region.clipScale(image.getWidth(observer), tx.getScaleX()); int imgHeight = Region.clipScale(image.getHeight(observer), tx.getScaleY()); BufferedImage bufImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D gr = bufImage.createGraphics(); if (gr != null) { try { gr.setPaintMode(); gr.drawImage(image, 0, 0, (autosize ? w : imgWidth), (autosize ? h : imgHeight), observer); createNativeImage(bufImage); updateNativeIcon(!firstUpdate); if (firstUpdate) firstUpdate = false; } finally { gr.dispose(); } } }
public boolean transformImage(SunGraphics2D sg, Image img, AffineTransform atfm, ImageObserver observer) { if (!(img instanceof ToolkitImage)) { transformImage(sg, img, 0, 0, atfm, sg.interpolationType); return true; } else { ToolkitImage sunimg = (ToolkitImage)img; if (!imageReady(sunimg, observer)) { return false; } ImageRepresentation ir = sunimg.getImageRep(); return ir.drawToBufImage(sg, sunimg, atfm, observer); } }
/** * Return the union of the visual bounds of all the components. * This incorporates the path. It does not include logical * bounds (used by carets). */ public Rectangle2D getVisualBounds() { Rectangle2D result = null; for (int i = 0, n = 0; i < fComponents.length; i++, n += 2) { TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)]; Rectangle2D r = tlc.getVisualBounds(); Point2D.Float pt = new Point2D.Float(locs[n], locs[n+1]); if (lp == null) { r.setRect(r.getMinX() + pt.x, r.getMinY() + pt.y, r.getWidth(), r.getHeight()); } else { lp.pathToPoint(pt, false, pt); AffineTransform at = tlc.getBaselineTransform(); if (at != null) { AffineTransform tx = AffineTransform.getTranslateInstance (pt.x - at.getTranslateX(), pt.y - at.getTranslateY()); tx.concatenate(at); r = tx.createTransformedShape(r).getBounds2D(); } else { r.setRect(r.getMinX() + pt.x, r.getMinY() + pt.y, r.getWidth(), r.getHeight()); } } if (result == null) { result = r; } else { result.add(r); } } if (result == null) { result = new Rectangle2D.Float(Float.MAX_VALUE, Float.MAX_VALUE, Float.MIN_VALUE, Float.MIN_VALUE); } return result; }
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(); }
private void drawFittingString(int x, int y, String text, Graphics2D gr, FontMetrics fm) { AffineTransform originalTransform = gr.getTransform(); gr.translate(x, y); String fittingText = getFittingString(text, fm, ShedWidget.width); gr.drawString(fittingText, 0, 0); gr.setTransform(originalTransform); }
protected void setCurrentSegment(GeneralPath path) { if (currentSegment != null) trackLayer.removeRenderable( currentSegment ); if (path == null) { currentSegment = null; return; } PathIterator pi = path.getPathIterator(new AffineTransform()); List<LatLon> pos = new LinkedList<LatLon>(); float [] coords = new float[6]; int t = pi.currentSegment(coords); pos.add( LatLon.fromDegrees(coords[1], coords[0])); while (!pi.isDone()) { t = pi.currentSegment(coords); if (t == PathIterator.SEG_LINETO && !(coords[1] == 0 && coords[0]==0)) pos.add( LatLon.fromDegrees(coords[1], coords[0])); pi.next(); } Polyline line = new Polyline(pos, 0); line.setLineWidth(4); line.setFollowTerrain(true); line.setColor( Color.red ); trackLayer.addRenderable(line); currentSegment = line; }
public void drawRenderableImage(RenderableImage img, AffineTransform xform) { if (img == null) { return; } mPrintMetrics.drawImage(this, img); mDrawingArea.addInfinite(); }
public AffineTransform getBaselineTransform() { Font font = source.getFont(); if (font.hasLayoutAttributes()) { return AttributeValues.getBaselineTransform(font.getAttributes()); } return null; }
public native void Transform(MaskBlit output, SurfaceData src, SurfaceData dst, Composite comp, Region clip, AffineTransform itx, int txtype, int sx1, int sy1, int sx2, int sy2, int dx1, int dy1, int dx2, int dy2, int edges[], int dxoff, int dyoff);
public static void main(final String[] args) throws IOException { for (final AffineTransform tx2 : txs) { for (final AffineTransform tx1 : txs) { for (final boolean aa : new boolean[]{true, false}) { final BufferedImage bi1 = createImage(aa, tx1, tx2); final BufferedImage bi2 = createImage(aa, tx2, tx1); compareImage(bi1, bi2); fillTextArea(bi1, tx1, tx2); fillTextArea(bi2, tx2, tx1); checkColors(bi1, bi2); } } } System.out.println("Passed"); }
/** * Paints the background of a text field. * * @param context SynthContext identifying the <code>JComponent</code> and * <code>Region</code> to paint to * @param g <code>Graphics</code> to paint to * @param x X coordinate of the area to paint to * @param y Y coordinate of the area to paint to * @param w Width of the area to paint to * @param h Height of the area to paint to */ public void paintTextFieldBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { if (context.getComponent().getComponentOrientation().isLeftToRight()){ paintBackground(context, g, x, y, w, h, null); } else { AffineTransform transform = new AffineTransform(); transform.translate(x,y); transform.scale(-1, 1); transform.translate(-w,0); paintBackground(context, g, 0, 0, w, h, transform); } }
@Override protected int platformFontCount(Font font, String str) { AffineTransform deviceTransform = getTransform(); AffineTransform fontTransform = new AffineTransform(deviceTransform); fontTransform.concatenate(getFont().getTransform()); int transformType = fontTransform.getType(); /* Test if GDI can handle the transform */ boolean directToGDI = ((transformType != AffineTransform.TYPE_GENERAL_TRANSFORM) && ((transformType & AffineTransform.TYPE_FLIP) == 0)); if (!directToGDI) { return 0; } /* Since all windows fonts are available, and the JRE fonts * are also registered. Only the Font.createFont() case is presently * unknown to GDI. Those can be registered too, although that * code does not exist yet, it can be added too, so we should not * fail that case. Just do a quick check whether its a TrueTypeFont * - ie not a Type1 font etc, and let drawString() resolve the rest. */ Font2D font2D = FontUtilities.getFont2D(font); if (font2D instanceof CompositeFont || font2D instanceof TrueTypeFont) { return 1; } else { return 0; } }
public void rotate( Point2D center, double angle ) { BufferedImage im = new BufferedImage( width, height, image.TYPE_INT_RGB); Graphics2D g = im.createGraphics(); AffineTransform at = new AffineTransform(); at.rotate( -angle, center.getX(), center.getY() ); g.drawRenderedImage( image, at); image = im; repaint(); }