java.awt.geom.AffineTransform Java Examples
The following examples show how to use
java.awt.geom.AffineTransform.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GraphicComponent.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Create a new GraphicComponent. start and limit are indices * into charLtoV and levels. charsLtoV and levels may be adopted. */ public GraphicComponent(GraphicAttribute graphic, Decoration decorator, int[] charsLtoV, byte[] levels, int start, int limit, AffineTransform baseTx) { if (limit <= start) { throw new IllegalArgumentException("0 or negative length in GraphicComponent"); } this.graphic = graphic; this.graphicAdvance = graphic.getAdvance(); this.decorator = decorator; this.cm = createCoreMetrics(graphic); this.baseTx = baseTx; initLocalOrdering(charsLtoV, levels, start, limit); }
Example #2
Source File: DrawRotatedStringUsingRotatedFont.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * Creates an BufferedImage and draws a text, using two transformations, * one for graphics and one for font. */ private static BufferedImage createImage(final boolean aa, final AffineTransform gtx, final AffineTransform ftx) { final BufferedImage bi = new BufferedImage(SIZE, SIZE, TYPE_INT_RGB); final Graphics2D bg = bi.createGraphics(); bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aa ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); bg.setColor(Color.RED); bg.fillRect(0, 0, SIZE, SIZE); bg.translate(100, 100); bg.transform(gtx); bg.setColor(Color.BLACK); bg.setFont(bg.getFont().deriveFont(20.0f).deriveFont(ftx)); bg.drawString(STR, 0, 0); bg.dispose(); return bi; }
Example #3
Source File: Font2D.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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; } }
Example #4
Source File: TouchableTransformerTests.java From workcraft with MIT License | 6 votes |
@Test public void testTranslateHitTest() { TouchableTransformer toucher = new TouchableTransformer( new Dummy() { @Override public boolean hitTest(Point2D point) { return point.distanceSq(0, 0) < 1.0; } }, AffineTransform.getTranslateInstance(10, 1)); Assertions.assertTrue(toucher.hitTest(new Point2D.Double(10, 1))); Assertions.assertTrue(toucher.hitTest(new Point2D.Double(10.9, 1))); Assertions.assertTrue(toucher.hitTest(new Point2D.Double(9.1, 1))); Assertions.assertFalse(toucher.hitTest(new Point2D.Double(11.1, 1))); Assertions.assertFalse(toucher.hitTest(new Point2D.Double(8.9, 1))); Assertions.assertTrue(toucher.hitTest(new Point2D.Double(10.6, 1.6))); Assertions.assertFalse(toucher.hitTest(new Point2D.Double(10.8, 1.8))); Assertions.assertTrue(toucher.hitTest(new Point2D.Double(9.4, 0.4))); Assertions.assertFalse(toucher.hitTest(new Point2D.Double(9.2, 0.2))); }
Example #5
Source File: AttributeValues.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private static AffineTransform extractRotation(Point2D.Double pt, AffineTransform tx, boolean andTranslation) { tx.deltaTransform(pt, pt); AffineTransform rtx = AffineTransform.getRotateInstance(pt.x, pt.y); try { AffineTransform rtxi = rtx.createInverse(); double dx = tx.getTranslateX(); double dy = tx.getTranslateY(); tx.preConcatenate(rtxi); if (andTranslation) { if (dx != 0 || dy != 0) { tx.setTransform(tx.getScaleX(), tx.getShearY(), tx.getShearX(), tx.getScaleY(), 0, 0); rtx.setTransform(rtx.getScaleX(), rtx.getShearY(), rtx.getShearX(), rtx.getScaleY(), dx, dy); } } } catch (NoninvertibleTransformException e) { return null; } return rtx; }
Example #6
Source File: NPEfix_00174_t.java From coming with MIT License | 6 votes |
/** Build an affine line transform from a n {@code AffineTransform}. * @param transform transform to use (must be invertible otherwise * the {@link LineTransform#apply(Hyperplane)} method would work * only for some lines, and fail for other ones) * @exception MathIllegalArgumentException if the transform is non invertible */ public LineTransform(final AffineTransform transform) throws MathIllegalArgumentException { final double[] m = new double[6]; transform.getMatrix(m); cXX = m[0]; cXY = m[2]; cX1 = m[4]; cYX = m[1]; cYY = m[3]; cY1 = m[5]; c1Y = cXY * cY1 - cYY * cX1; c1X = cXX * cY1 - cYX * cX1; c11 = cXX * cYY - cYX * cXY; if (FastMath.abs(c11) < 1.0e-20) { throw new MathIllegalArgumentException(LocalizedFormats.NON_INVERTIBLE_TRANSFORM); } }
Example #7
Source File: SurfacePlot3D.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
@Override public JComponent getPlotter() { DataTable table = getDataTable(); if (table != null && table.getNumberOfRows() > MAX_NUMBER_OF_ROWS) { LogService.getRoot().log(Level.INFO, "com.rapidminer.gui.plotter.mathplot.SurfacePlot2D.too_many_examples", new Object[] { table.getNumberOfRows(), MAX_NUMBER_OF_ROWS }); // Display Label with error message because Plot3DPanel can not handle such a lot of // data points JLabel label = new JLabel(I18N.getGUILabel("surface3DPlot.too_many_examples", MAX_NUMBER_OF_ROWS)); label.setHorizontalAlignment(SwingConstants.CENTER); Font originalFont = label.getFont(); label.setFont(originalFont.deriveFont((float) (originalFont.getSize() * 1.25))); originalFont.deriveFont(new AffineTransform()); return label; } else { return super.getPlotter(); } }
Example #8
Source File: StandardGlyphVector.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public void setGlyphTransform(int ix, AffineTransform newTX) { if (ix < 0 || ix >= glyphs.length) { throw new IndexOutOfBoundsException("ix = " + ix); } if (gti == null) { if (newTX == null || newTX.isIdentity()) { return; } gti = new GlyphTransformInfo(this); } gti.setGlyphTransform(ix, newTX); // sets flags if (gti.transformCount() == 0) { gti = null; } }
Example #9
Source File: TransformingPathConsumer2D.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public static PathConsumer2D deltaTransformConsumer(PathConsumer2D out, AffineTransform at) { if (at == null) { return out; } float Mxx = (float) at.getScaleX(); float Mxy = (float) at.getShearX(); float Myx = (float) at.getShearY(); float Myy = (float) at.getScaleY(); if (Mxy == 0f && Myx == 0f) { if (Mxx == 1f && Myy == 1f) { return out; } else { return new DeltaScaleFilter(out, Mxx, Myy); } } else { return new DeltaTransformFilter(out, Mxx, Mxy, Myx, Myy); } }
Example #10
Source File: PathGraphics.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Draws the outline of the specified rectangle. * The left and right edges of the rectangle are at * {@code x} and <code>x + width</code>. * The top and bottom edges are at * {@code y} and <code>y + height</code>. * The rectangle is drawn using the graphics context's current color. * @param x the <i>x</i> coordinate * of the rectangle to be drawn. * @param y the <i>y</i> coordinate * of the rectangle to be drawn. * @param width the width of the rectangle to be drawn. * @param height the height of the rectangle to be drawn. * @see java.awt.Graphics#fillRect * @see java.awt.Graphics#clearRect */ public void drawRect(int x, int y, int width, int height) { Paint paint = getPaint(); try { AffineTransform deviceTransform = getTransform(); if (getClip() != null) { deviceClip(getClip().getPathIterator(deviceTransform)); } deviceFrameRect(x, y, width, height, (Color) paint); } catch (ClassCastException e) { throw new IllegalArgumentException("Expected a Color instance"); } }
Example #11
Source File: PrintItemBarcode.java From nordpos with GNU General Public License v3.0 | 6 votes |
@Override public void draw(Graphics2D g, int x, int y, int width) { Graphics2D g2d = (Graphics2D) g; AffineTransform oldt = g2d.getTransform(); g2d.translate(x - 10 + (width - (int) (m_iWidth * scale)) / 2, y + 10); g2d.scale(scale, scale); try { if (m_qrMatrix != null) { com.google.zxing.Writer writer = new QRCodeWriter(); m_qrMatrix = writer.encode(m_sCode, com.google.zxing.BarcodeFormat.QR_CODE, m_iWidth, m_iHeight); g2d.drawImage(MatrixToImageWriter.toBufferedImage(m_qrMatrix), null, 0, 0); } else if (m_barcode != null) { m_barcode.generateBarcode(new Java2DCanvasProvider(g2d, 0), m_sCode); } } catch (IllegalArgumentException | WriterException ex) { g2d.drawRect(0, 0, m_iWidth, m_iHeight); g2d.drawLine(0, 0, m_iWidth, m_iHeight); g2d.drawLine(m_iWidth, 0, 0, m_iHeight); } g2d.setTransform(oldt); }
Example #12
Source File: DrawImage.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
protected void transformImage(SunGraphics2D sg, Image img, AffineTransform tx, int interpType, int sx1, int sy1, int sx2, int sy2, Color bgColor) { // Transform 3 source corners by tx and analyze them // for simplified operations (Copy or Scale). Using // 3 points lets us analyze any kind of transform, // even transforms that involve very tiny amounts of // rotation or skew to see if they degenerate to a // simple scale or copy operation within the allowable // error bounds. // Note that we use (0,0,w,h) instead of (sx1,sy1,sx2,sy2) // because the transform is already translated such that // the origin is where sx1, sy1 should go. double coords[] = new double[6]; /* index: 0 1 2 3 4 5 */ /* coord: (0, 0), (w, h), (0, h) */ coords[2] = sx2 - sx1; coords[3] = coords[5] = sy2 - sy1; tx.transform(coords, 0, coords, 0, 3); // First test if the X coords of the transformed UL // and LL points match and that the Y coords of the // transformed LR and LL points also match. // If they do then it is a "rectilinear" transform and // tryCopyOrScale will make sure it is upright and // integer-based. if (Math.abs(coords[0] - coords[4]) < MAX_TX_ERROR && Math.abs(coords[3] - coords[5]) < MAX_TX_ERROR && tryCopyOrScale(sg, img, sx1, sy1, sx2, sy2, bgColor, interpType, coords)) { return; } renderImageXform(sg, img, tx, interpType, sx1, sy1, sx2, sy2, bgColor); }
Example #13
Source File: SVGElement.java From gama with GNU General Public License v3.0 | 5 votes |
static protected AffineTransform parseTransform(final String val) throws SVGException { final Matcher matchExpression = Pattern.compile("\\w+\\([^)]*\\)").matcher(""); final AffineTransform retXform = new AffineTransform(); matchExpression.reset(val); while (matchExpression.find()) { retXform.concatenate(parseSingleTransform(matchExpression.group())); } return retXform; }
Example #14
Source File: RadialGradientPaint.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
private static AffineTransform createGradientTransform(Rectangle2D r) { double cx = r.getCenterX(); double cy = r.getCenterY(); AffineTransform xform = AffineTransform.getTranslateInstance(cx, cy); xform.scale(r.getWidth()/2, r.getHeight()/2); xform.translate(-cx, -cy); return xform; }
Example #15
Source File: DrawShape.java From lams with GNU General Public License v2.0 | 5 votes |
public static Rectangle2D getAnchor(Graphics2D graphics, Rectangle2D anchor) { if(graphics == null) { return anchor; } AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM); if(tx != null && !tx.isIdentity()) { anchor = tx.createTransformedShape(anchor).getBounds2D(); } return anchor; }
Example #16
Source File: D3DBlitLoops.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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); }
Example #17
Source File: BasicProgressBarUI.java From Java8CN with Apache License 2.0 | 5 votes |
/** * Paints the progress string. * * @param g Graphics used for drawing. * @param x x location of bounding box * @param y y location of bounding box * @param width width of bounding box * @param height height of bounding box * @param fillStart start location, in x or y depending on orientation, * of the filled portion of the progress bar. * @param amountFull size of the fill region, either width or height * depending upon orientation. * @param b Insets of the progress bar. */ private void paintString(Graphics g, int x, int y, int width, int height, int fillStart, int amountFull, Insets b) { if (!(g instanceof Graphics2D)) { return; } Graphics2D g2 = (Graphics2D)g; String progressString = progressBar.getString(); g2.setFont(progressBar.getFont()); Point renderLocation = getStringPlacement(g2, progressString, x, y, width, height); Rectangle oldClip = g2.getClipBounds(); if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { g2.setColor(getSelectionBackground()); SwingUtilities2.drawString(progressBar, g2, progressString, renderLocation.x, renderLocation.y); g2.setColor(getSelectionForeground()); g2.clipRect(fillStart, y, amountFull, height); SwingUtilities2.drawString(progressBar, g2, progressString, renderLocation.x, renderLocation.y); } else { // VERTICAL g2.setColor(getSelectionBackground()); AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI/2); g2.setFont(progressBar.getFont().deriveFont(rotate)); renderLocation = getStringPlacement(g2, progressString, x, y, width, height); SwingUtilities2.drawString(progressBar, g2, progressString, renderLocation.x, renderLocation.y); g2.setColor(getSelectionForeground()); g2.clipRect(x, fillStart, width, amountFull); SwingUtilities2.drawString(progressBar, g2, progressString, renderLocation.x, renderLocation.y); } g2.setClip(oldClip); }
Example #18
Source File: TexturePaintContext.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public Byte(ByteInterleavedRaster srcRas, ColorModel cm, AffineTransform xform, int maxw) { super(cm, xform, srcRas.getWidth(), srcRas.getHeight(), maxw); this.srcRas = srcRas; this.inData = srcRas.getDataStorage(); this.inSpan = srcRas.getScanlineStride(); this.inOff = srcRas.getDataOffset(0); }
Example #19
Source File: SynthPainterImpl.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Paints the border 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 paintTextFieldBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { if (context.getComponent().getComponentOrientation().isLeftToRight()){ paintBorder(context, g, x, y, w, h, null); } else { AffineTransform transform = new AffineTransform(); transform.translate(x,y); transform.scale(-1, 1); transform.translate(-w,0); paintBorder(context, g, 0, 0, w, h, transform); } }
Example #20
Source File: StandardGlyphVector.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Ensure that the positions array exists and holds position data. * If the array is null, this allocates it and sets default positions. */ private void initPositions() { if (positions == null) { setFRCTX(); positions = new float[glyphs.length * 2 + 2]; Point2D.Float trackPt = null; float track = getTracking(font); if (track != 0) { track *= font.getSize2D(); trackPt = new Point2D.Float(track, 0); // advance delta } Point2D.Float pt = new Point2D.Float(0, 0); if (font.isTransformed()) { AffineTransform at = font.getTransform(); at.transform(pt, pt); positions[0] = pt.x; positions[1] = pt.y; if (trackPt != null) { at.deltaTransform(trackPt, trackPt); } } for (int i = 0, n = 2; i < glyphs.length; ++i, n += 2) { getGlyphStrike(i).addDefaultGlyphAdvance(glyphs[i], pt); if (trackPt != null) { pt.x += trackPt.x; pt.y += trackPt.y; } positions[n] = pt.x; positions[n+1] = pt.y; } } }
Example #21
Source File: SynthPainterImpl.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private void paintBackground(SynthContext ctx, Graphics g, int x, int y, int w, int h, AffineTransform transform) { // if the background color of the component is 100% transparent // then we should not paint any background graphics. This is a solution // for there being no way of turning off Nimbus background painting as // basic components are all non-opaque by default. Component c = ctx.getComponent(); Color bg = (c != null) ? c.getBackground() : null; if (bg == null || bg.getAlpha() > 0){ Painter backgroundPainter = style.getBackgroundPainter(ctx); if (backgroundPainter != null) { paint(backgroundPainter, ctx, g, x, y, w, h,transform); } } }
Example #22
Source File: TransformHelper.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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);
Example #23
Source File: AffineTransformOp.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Constructs an <CODE>AffineTransformOp</CODE> given an affine transform * and the interpolation type. * * @param xform The <CODE>AffineTransform</CODE> to use for the operation. * @param interpolationType One of the integer * interpolation type constants defined by this class: * {@link #TYPE_NEAREST_NEIGHBOR TYPE_NEAREST_NEIGHBOR}, * {@link #TYPE_BILINEAR TYPE_BILINEAR}, * {@link #TYPE_BICUBIC TYPE_BICUBIC}. * @throws ImagingOpException if the transform is non-invertible. */ public AffineTransformOp(AffineTransform xform, int interpolationType) { validateTransform(xform); this.xform = (AffineTransform)xform.clone(); switch(interpolationType) { case TYPE_NEAREST_NEIGHBOR: case TYPE_BILINEAR: case TYPE_BICUBIC: break; default: throw new IllegalArgumentException("Unknown interpolation type: "+ interpolationType); } this.interpolationType = interpolationType; }
Example #24
Source File: GraphicsTests.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void init(Graphics2D g2d, Context ctx, Dimension dim) { int w = dim.width; int h = dim.height; AffineTransform at = new AffineTransform(); at.translate(1.5, 1.5); g2d.transform(at); dim.setSize(w-3, h-3); }
Example #25
Source File: TextSourceLabel.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public AffineTransform getBaselineTransform() { Font font = source.getFont(); if (font.hasLayoutAttributes()) { return AttributeValues.getBaselineTransform(font.getAttributes()); } return null; }
Example #26
Source File: TextMeasureTests.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { GVContext gvctx = (GVContext)ctx; GlyphVector gv = gvctx.gv; AffineTransform tx; do { for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) { tx = gv.getGlyphTransform(i); } } while (--numReps >= 0); }
Example #27
Source File: ShapeUtilities.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Creates and returns a translated shape. * * @param shape the shape (<code>null</code> not permitted). * @param transX the x translation (in Java2D space). * @param transY the y translation (in Java2D space). * * @return The translated shape. */ public static Shape createTranslatedShape(final Shape shape, final double transX, final double transY) { if (shape == null) { throw new IllegalArgumentException("Null 'shape' argument."); } final AffineTransform transform = AffineTransform.getTranslateInstance( transX, transY); return transform.createTransformedShape(shape); }
Example #28
Source File: SunGraphics2D.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Sets the Transform in the current graphics state. * @param Tx The Transform object to be used in the rendering process. * @see #transform * @see TransformChain * @see AffineTransform */ @Override public void setTransform(AffineTransform Tx) { if ((constrainX | constrainY) == 0 && devScale == 1) { transform.setTransform(Tx); } else { transform.setTransform(devScale, 0, 0, devScale, constrainX, constrainY); transform.concatenate(Tx); } invalidateTransform(); }
Example #29
Source File: RasterPrinterJob.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * save graphics state of a PathGraphics for later redrawing * of part of page represented by the region in that state */ public void saveState(AffineTransform at, Shape clip, Rectangle2D region, double sx, double sy) { GraphicsState gstate = new GraphicsState(); gstate.theTransform = at; gstate.theClip = clip; gstate.region = region; gstate.sx = sx; gstate.sy = sy; redrawList.add(gstate); }
Example #30
Source File: TexturePaintContext.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public static PaintContext getContext(BufferedImage bufImg, AffineTransform xform, RenderingHints hints, Rectangle devBounds) { WritableRaster raster = bufImg.getRaster(); ColorModel cm = bufImg.getColorModel(); int maxw = devBounds.width; Object val = hints.get(RenderingHints.KEY_INTERPOLATION); boolean filter = (val == null ? (hints.get(RenderingHints.KEY_RENDERING) == RenderingHints.VALUE_RENDER_QUALITY) : (val != RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)); if (raster instanceof IntegerInterleavedRaster && (!filter || isFilterableDCM(cm))) { IntegerInterleavedRaster iir = (IntegerInterleavedRaster) raster; if (iir.getNumDataElements() == 1 && iir.getPixelStride() == 1) { return new Int(iir, cm, xform, maxw, filter); } } else if (raster instanceof ByteInterleavedRaster) { ByteInterleavedRaster bir = (ByteInterleavedRaster) raster; if (bir.getNumDataElements() == 1 && bir.getPixelStride() == 1) { if (filter) { if (isFilterableICM(cm)) { return new ByteFilter(bir, cm, xform, maxw); } } else { return new Byte(bir, cm, xform, maxw); } } } return new Any(raster, cm, xform, maxw, filter); }