Java Code Examples for java.awt.geom.AffineTransform#inverseTransform()
The following examples show how to use
java.awt.geom.AffineTransform#inverseTransform() .
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: StandardGlyphVector.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * !!! not used currently, but might be by getPixelbounds? */ public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) { if (renderFRC == null) { renderFRC = frc; } // it is a total pain that you have to copy the transform. AffineTransform at = renderFRC.getTransform(); at.transform(loc, loc); pxResult.x = (int)loc.getX(); // but must not behave oddly around zero pxResult.y = (int)loc.getY(); loc.setLocation(pxResult.x, pxResult.y); try { at.inverseTransform(loc, loc); } catch (NoninvertibleTransformException e) { throw new IllegalArgumentException("must be able to invert frc transform"); } }
Example 2
Source File: StandardGlyphVector.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * !!! not used currently, but might be by getPixelbounds? */ public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) { if (renderFRC == null) { renderFRC = frc; } // it is a total pain that you have to copy the transform. AffineTransform at = renderFRC.getTransform(); at.transform(loc, loc); pxResult.x = (int)loc.getX(); // but must not behave oddly around zero pxResult.y = (int)loc.getY(); loc.setLocation(pxResult.x, pxResult.y); try { at.inverseTransform(loc, loc); } catch (NoninvertibleTransformException e) { throw new IllegalArgumentException("must be able to invert frc transform"); } }
Example 3
Source File: StandardGlyphVector.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * !!! not used currently, but might be by getPixelbounds? */ public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) { if (renderFRC == null) { renderFRC = frc; } // it is a total pain that you have to copy the transform. AffineTransform at = renderFRC.getTransform(); at.transform(loc, loc); pxResult.x = (int)loc.getX(); // but must not behave oddly around zero pxResult.y = (int)loc.getY(); loc.setLocation(pxResult.x, pxResult.y); try { at.inverseTransform(loc, loc); } catch (NoninvertibleTransformException e) { throw new IllegalArgumentException("must be able to invert frc transform"); } }
Example 4
Source File: MagicWandInteractor.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
Point getPixelPos(Product product, MouseEvent event) { final Point2D mp = toModelPoint(event); final Point2D ip; if (product.getSceneGeoCoding() != null) { AffineTransform transform = Product.findImageToModelTransform(product.getSceneGeoCoding()); try { ip = transform.inverseTransform(mp, null); } catch (NoninvertibleTransformException e) { Dialogs.showError(DIALOG_TITLE, "A geographic transformation problem occurred:\n" + e.getMessage()); return null; } } else { ip = mp; } final int pixelX = (int) ip.getX(); final int pixelY = (int) ip.getY(); if (pixelX < 0 || pixelY < 0 || pixelX >= product.getSceneRasterWidth() || pixelY >= product.getSceneRasterHeight()) { return null; } return new Point(pixelX, pixelY); }
Example 5
Source File: StandardGlyphVector.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * !!! not used currently, but might be by getPixelbounds? */ public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) { if (renderFRC == null) { renderFRC = frc; } // it is a total pain that you have to copy the transform. AffineTransform at = renderFRC.getTransform(); at.transform(loc, loc); pxResult.x = (int)loc.getX(); // but must not behave oddly around zero pxResult.y = (int)loc.getY(); loc.setLocation(pxResult.x, pxResult.y); try { at.inverseTransform(loc, loc); } catch (NoninvertibleTransformException e) { throw new IllegalArgumentException("must be able to invert frc transform"); } }
Example 6
Source File: StandardGlyphVector.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * !!! not used currently, but might be by getPixelbounds? */ public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) { if (renderFRC == null) { renderFRC = frc; } // it is a total pain that you have to copy the transform. AffineTransform at = renderFRC.getTransform(); at.transform(loc, loc); pxResult.x = (int)loc.getX(); // but must not behave oddly around zero pxResult.y = (int)loc.getY(); loc.setLocation(pxResult.x, pxResult.y); try { at.inverseTransform(loc, loc); } catch (NoninvertibleTransformException e) { throw new IllegalArgumentException("must be able to invert frc transform"); } }
Example 7
Source File: StandardGlyphVector.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * !!! not used currently, but might be by getPixelbounds? */ public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) { if (renderFRC == null) { renderFRC = frc; } // it is a total pain that you have to copy the transform. AffineTransform at = renderFRC.getTransform(); at.transform(loc, loc); pxResult.x = (int)loc.getX(); // but must not behave oddly around zero pxResult.y = (int)loc.getY(); loc.setLocation(pxResult.x, pxResult.y); try { at.inverseTransform(loc, loc); } catch (NoninvertibleTransformException e) { throw new IllegalArgumentException("must be able to invert frc transform"); } }
Example 8
Source File: SunGraphics2D.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Returns a rectangle in image coordinates that may be required * in order to draw the given image into the given clipping region * through a pair of AffineTransforms. In addition, horizontal and * vertical padding factors for antialising and interpolation may * be used. */ private static Rectangle getImageRegion(RenderedImage img, Region compClip, AffineTransform transform, AffineTransform xform, int padX, int padY) { Rectangle imageRect = new Rectangle(img.getMinX(), img.getMinY(), img.getWidth(), img.getHeight()); Rectangle result = null; try { double p[] = new double[8]; p[0] = p[2] = compClip.getLoX(); p[4] = p[6] = compClip.getHiX(); p[1] = p[5] = compClip.getLoY(); p[3] = p[7] = compClip.getHiY(); // Inverse transform the output bounding rect transform.inverseTransform(p, 0, p, 0, 4); xform.inverseTransform(p, 0, p, 0, 4); // Determine a bounding box for the inverse transformed region double x0,x1,y0,y1; x0 = x1 = p[0]; y0 = y1 = p[1]; for (int i = 2; i < 8; ) { double pt = p[i++]; if (pt < x0) { x0 = pt; } else if (pt > x1) { x1 = pt; } pt = p[i++]; if (pt < y0) { y0 = pt; } else if (pt > y1) { y1 = pt; } } // This is padding for anti-aliasing and such. It may // be more than is needed. int x = (int)x0 - padX; int w = (int)(x1 - x0 + 2*padX); int y = (int)y0 - padY; int h = (int)(y1 - y0 + 2*padY); Rectangle clipRect = new Rectangle(x,y,w,h); result = clipRect.intersection(imageRect); } catch (NoninvertibleTransformException nte) { // Worst case bounds are the bounds of the image. result = imageRect; } return result; }
Example 9
Source File: SunGraphics2D.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Returns a rectangle in image coordinates that may be required * in order to draw the given image into the given clipping region * through a pair of AffineTransforms. In addition, horizontal and * vertical padding factors for antialising and interpolation may * be used. */ private static Rectangle getImageRegion(RenderedImage img, Region compClip, AffineTransform transform, AffineTransform xform, int padX, int padY) { Rectangle imageRect = new Rectangle(img.getMinX(), img.getMinY(), img.getWidth(), img.getHeight()); Rectangle result = null; try { double p[] = new double[8]; p[0] = p[2] = compClip.getLoX(); p[4] = p[6] = compClip.getHiX(); p[1] = p[5] = compClip.getLoY(); p[3] = p[7] = compClip.getHiY(); // Inverse transform the output bounding rect transform.inverseTransform(p, 0, p, 0, 4); xform.inverseTransform(p, 0, p, 0, 4); // Determine a bounding box for the inverse transformed region double x0,x1,y0,y1; x0 = x1 = p[0]; y0 = y1 = p[1]; for (int i = 2; i < 8; ) { double pt = p[i++]; if (pt < x0) { x0 = pt; } else if (pt > x1) { x1 = pt; } pt = p[i++]; if (pt < y0) { y0 = pt; } else if (pt > y1) { y1 = pt; } } // This is padding for anti-aliasing and such. It may // be more than is needed. int x = (int)x0 - padX; int w = (int)(x1 - x0 + 2*padX); int y = (int)y0 - padY; int h = (int)(y1 - y0 + 2*padY); Rectangle clipRect = new Rectangle(x,y,w,h); result = clipRect.intersection(imageRect); } catch (NoninvertibleTransformException nte) { // Worst case bounds are the bounds of the image. result = imageRect; } return result; }
Example 10
Source File: SunGraphics2D.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Returns a rectangle in image coordinates that may be required * in order to draw the given image into the given clipping region * through a pair of AffineTransforms. In addition, horizontal and * vertical padding factors for antialising and interpolation may * be used. */ private static Rectangle getImageRegion(RenderedImage img, Region compClip, AffineTransform transform, AffineTransform xform, int padX, int padY) { Rectangle imageRect = new Rectangle(img.getMinX(), img.getMinY(), img.getWidth(), img.getHeight()); Rectangle result = null; try { double[] p = new double[8]; p[0] = p[2] = compClip.getLoX(); p[4] = p[6] = compClip.getHiX(); p[1] = p[5] = compClip.getLoY(); p[3] = p[7] = compClip.getHiY(); // Inverse transform the output bounding rect transform.inverseTransform(p, 0, p, 0, 4); xform.inverseTransform(p, 0, p, 0, 4); // Determine a bounding box for the inverse transformed region double x0,x1,y0,y1; x0 = x1 = p[0]; y0 = y1 = p[1]; for (int i = 2; i < 8; ) { double pt = p[i++]; if (pt < x0) { x0 = pt; } else if (pt > x1) { x1 = pt; } pt = p[i++]; if (pt < y0) { y0 = pt; } else if (pt > y1) { y1 = pt; } } // This is padding for anti-aliasing and such. It may // be more than is needed. int x = (int)x0 - padX; int w = (int)(x1 - x0 + 2*padX); int y = (int)y0 - padY; int h = (int)(y1 - y0 + 2*padY); Rectangle clipRect = new Rectangle(x,y,w,h); result = clipRect.intersection(imageRect); } catch (NoninvertibleTransformException nte) { // Worst case bounds are the bounds of the image. result = imageRect; } return result; }
Example 11
Source File: SunGraphics2D.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Returns a rectangle in image coordinates that may be required * in order to draw the given image into the given clipping region * through a pair of AffineTransforms. In addition, horizontal and * vertical padding factors for antialising and interpolation may * be used. */ private static Rectangle getImageRegion(RenderedImage img, Region compClip, AffineTransform transform, AffineTransform xform, int padX, int padY) { Rectangle imageRect = new Rectangle(img.getMinX(), img.getMinY(), img.getWidth(), img.getHeight()); Rectangle result = null; try { double p[] = new double[8]; p[0] = p[2] = compClip.getLoX(); p[4] = p[6] = compClip.getHiX(); p[1] = p[5] = compClip.getLoY(); p[3] = p[7] = compClip.getHiY(); // Inverse transform the output bounding rect transform.inverseTransform(p, 0, p, 0, 4); xform.inverseTransform(p, 0, p, 0, 4); // Determine a bounding box for the inverse transformed region double x0,x1,y0,y1; x0 = x1 = p[0]; y0 = y1 = p[1]; for (int i = 2; i < 8; ) { double pt = p[i++]; if (pt < x0) { x0 = pt; } else if (pt > x1) { x1 = pt; } pt = p[i++]; if (pt < y0) { y0 = pt; } else if (pt > y1) { y1 = pt; } } // This is padding for anti-aliasing and such. It may // be more than is needed. int x = (int)x0 - padX; int w = (int)(x1 - x0 + 2*padX); int y = (int)y0 - padY; int h = (int)(y1 - y0 + 2*padY); Rectangle clipRect = new Rectangle(x,y,w,h); result = clipRect.intersection(imageRect); } catch (NoninvertibleTransformException nte) { // Worst case bounds are the bounds of the image. result = imageRect; } return result; }
Example 12
Source File: SunGraphics2D.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** * Returns a rectangle in image coordinates that may be required * in order to draw the given image into the given clipping region * through a pair of AffineTransforms. In addition, horizontal and * vertical padding factors for antialising and interpolation may * be used. */ private static Rectangle getImageRegion(RenderedImage img, Region compClip, AffineTransform transform, AffineTransform xform, int padX, int padY) { Rectangle imageRect = new Rectangle(img.getMinX(), img.getMinY(), img.getWidth(), img.getHeight()); Rectangle result = null; try { double p[] = new double[8]; p[0] = p[2] = compClip.getLoX(); p[4] = p[6] = compClip.getHiX(); p[1] = p[5] = compClip.getLoY(); p[3] = p[7] = compClip.getHiY(); // Inverse transform the output bounding rect transform.inverseTransform(p, 0, p, 0, 4); xform.inverseTransform(p, 0, p, 0, 4); // Determine a bounding box for the inverse transformed region double x0,x1,y0,y1; x0 = x1 = p[0]; y0 = y1 = p[1]; for (int i = 2; i < 8; ) { double pt = p[i++]; if (pt < x0) { x0 = pt; } else if (pt > x1) { x1 = pt; } pt = p[i++]; if (pt < y0) { y0 = pt; } else if (pt > y1) { y1 = pt; } } // This is padding for anti-aliasing and such. It may // be more than is needed. int x = (int)x0 - padX; int w = (int)(x1 - x0 + 2*padX); int y = (int)y0 - padY; int h = (int)(y1 - y0 + 2*padY); Rectangle clipRect = new Rectangle(x,y,w,h); result = clipRect.intersection(imageRect); } catch (NoninvertibleTransformException nte) { // Worst case bounds are the bounds of the image. result = imageRect; } return result; }
Example 13
Source File: FontPanel.java From hottub with GNU General Public License v2.0 | 4 votes |
public void modeSpecificDrawChar( Graphics2D g2, int charCode, int baseX, int baseY ) { GlyphVector gv; int oneGlyph[] = { charCode }; char charArray[] = Character.toChars( charCode ); FontRenderContext frc = g2.getFontRenderContext(); AffineTransform oldTX = g2.getTransform(); /// Create GlyphVector to measure the exact visual advance /// Using that number, adjust the position of the character drawn if ( textToUse == ALL_GLYPHS ) gv = testFont.createGlyphVector( frc, oneGlyph ); else gv = testFont.createGlyphVector( frc, charArray ); Rectangle2D r2d2 = gv.getPixelBounds(frc, 0, 0); int shiftedX = baseX; // getPixelBounds returns a result in device space. // we need to convert back to user space to be able to // calculate the shift as baseX is in user space. try { double pt[] = new double[4]; pt[0] = r2d2.getX(); pt[1] = r2d2.getY(); pt[2] = r2d2.getX()+r2d2.getWidth(); pt[3] = r2d2.getY()+r2d2.getHeight(); oldTX.inverseTransform(pt,0,pt,0,2); shiftedX = baseX - (int) ( pt[2] / 2 + pt[0] ); } catch (NoninvertibleTransformException e) { } /// ABP - keep track of old tform, restore it later g2.translate( shiftedX, baseY ); g2.transform( getAffineTransform( g2Transform ) ); if ( textToUse == ALL_GLYPHS ) g2.drawGlyphVector( gv, 0f, 0f ); else { if ( testFont.canDisplay( charCode )) g2.setColor( Color.black ); else { g2.setColor( Color.lightGray ); } switch ( drawMethod ) { case DRAW_STRING: g2.drawString( new String( charArray ), 0, 0 ); break; case DRAW_CHARS: g2.drawChars( charArray, 0, 1, 0, 0 ); break; case DRAW_BYTES: if ( charCode > 0xff ) throw new CannotDrawException( DRAW_BYTES_ERROR ); byte oneByte[] = { (byte) charCode }; g2.drawBytes( oneByte, 0, 1, 0, 0 ); break; case DRAW_GLYPHV: g2.drawGlyphVector( gv, 0f, 0f ); break; case TL_DRAW: TextLayout tl = new TextLayout( new String( charArray ), testFont, frc ); tl.draw( g2, 0f, 0f ); break; case GV_OUTLINE: r2d2 = gv.getVisualBounds(); shiftedX = baseX - (int) ( r2d2.getWidth() / 2 + r2d2.getX() ); g2.draw( gv.getOutline( 0f, 0f )); break; case TL_OUTLINE: r2d2 = gv.getVisualBounds(); shiftedX = baseX - (int) ( r2d2.getWidth() / 2 + r2d2.getX() ); TextLayout tlo = new TextLayout( new String( charArray ), testFont, g2.getFontRenderContext() ); g2.draw( tlo.getOutline( null )); } } /// ABP - restore old tform g2.setTransform ( oldTX ); }
Example 14
Source File: SunGraphics2D.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Returns a rectangle in image coordinates that may be required * in order to draw the given image into the given clipping region * through a pair of AffineTransforms. In addition, horizontal and * vertical padding factors for antialising and interpolation may * be used. */ private static Rectangle getImageRegion(RenderedImage img, Region compClip, AffineTransform transform, AffineTransform xform, int padX, int padY) { Rectangle imageRect = new Rectangle(img.getMinX(), img.getMinY(), img.getWidth(), img.getHeight()); Rectangle result = null; try { double p[] = new double[8]; p[0] = p[2] = compClip.getLoX(); p[4] = p[6] = compClip.getHiX(); p[1] = p[5] = compClip.getLoY(); p[3] = p[7] = compClip.getHiY(); // Inverse transform the output bounding rect transform.inverseTransform(p, 0, p, 0, 4); xform.inverseTransform(p, 0, p, 0, 4); // Determine a bounding box for the inverse transformed region double x0,x1,y0,y1; x0 = x1 = p[0]; y0 = y1 = p[1]; for (int i = 2; i < 8; ) { double pt = p[i++]; if (pt < x0) { x0 = pt; } else if (pt > x1) { x1 = pt; } pt = p[i++]; if (pt < y0) { y0 = pt; } else if (pt > y1) { y1 = pt; } } // This is padding for anti-aliasing and such. It may // be more than is needed. int x = (int)x0 - padX; int w = (int)(x1 - x0 + 2*padX); int y = (int)y0 - padY; int h = (int)(y1 - y0 + 2*padY); Rectangle clipRect = new Rectangle(x,y,w,h); result = clipRect.intersection(imageRect); } catch (NoninvertibleTransformException nte) { // Worst case bounds are the bounds of the image. result = imageRect; } return result; }
Example 15
Source File: FontPanel.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void modeSpecificDrawChar( Graphics2D g2, int charCode, int baseX, int baseY ) { GlyphVector gv; int oneGlyph[] = { charCode }; char charArray[] = Character.toChars( charCode ); FontRenderContext frc = g2.getFontRenderContext(); AffineTransform oldTX = g2.getTransform(); /// Create GlyphVector to measure the exact visual advance /// Using that number, adjust the position of the character drawn if ( textToUse == ALL_GLYPHS ) gv = testFont.createGlyphVector( frc, oneGlyph ); else gv = testFont.createGlyphVector( frc, charArray ); Rectangle2D r2d2 = gv.getPixelBounds(frc, 0, 0); int shiftedX = baseX; // getPixelBounds returns a result in device space. // we need to convert back to user space to be able to // calculate the shift as baseX is in user space. try { double pt[] = new double[4]; pt[0] = r2d2.getX(); pt[1] = r2d2.getY(); pt[2] = r2d2.getX()+r2d2.getWidth(); pt[3] = r2d2.getY()+r2d2.getHeight(); oldTX.inverseTransform(pt,0,pt,0,2); shiftedX = baseX - (int) ( pt[2] / 2 + pt[0] ); } catch (NoninvertibleTransformException e) { } /// ABP - keep track of old tform, restore it later g2.translate( shiftedX, baseY ); g2.transform( getAffineTransform( g2Transform ) ); if ( textToUse == ALL_GLYPHS ) g2.drawGlyphVector( gv, 0f, 0f ); else { if ( testFont.canDisplay( charCode )) g2.setColor( Color.black ); else { g2.setColor( Color.lightGray ); } switch ( drawMethod ) { case DRAW_STRING: g2.drawString( new String( charArray ), 0, 0 ); break; case DRAW_CHARS: g2.drawChars( charArray, 0, 1, 0, 0 ); break; case DRAW_BYTES: if ( charCode > 0xff ) throw new CannotDrawException( DRAW_BYTES_ERROR ); byte oneByte[] = { (byte) charCode }; g2.drawBytes( oneByte, 0, 1, 0, 0 ); break; case DRAW_GLYPHV: g2.drawGlyphVector( gv, 0f, 0f ); break; case TL_DRAW: TextLayout tl = new TextLayout( new String( charArray ), testFont, frc ); tl.draw( g2, 0f, 0f ); break; case GV_OUTLINE: r2d2 = gv.getVisualBounds(); shiftedX = baseX - (int) ( r2d2.getWidth() / 2 + r2d2.getX() ); g2.draw( gv.getOutline( 0f, 0f )); break; case TL_OUTLINE: r2d2 = gv.getVisualBounds(); shiftedX = baseX - (int) ( r2d2.getWidth() / 2 + r2d2.getX() ); TextLayout tlo = new TextLayout( new String( charArray ), testFont, g2.getFontRenderContext() ); g2.draw( tlo.getOutline( null )); } } /// ABP - restore old tform g2.setTransform ( oldTX ); }
Example 16
Source File: SunGraphics2D.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * Returns a rectangle in image coordinates that may be required * in order to draw the given image into the given clipping region * through a pair of AffineTransforms. In addition, horizontal and * vertical padding factors for antialising and interpolation may * be used. */ private static Rectangle getImageRegion(RenderedImage img, Region compClip, AffineTransform transform, AffineTransform xform, int padX, int padY) { Rectangle imageRect = new Rectangle(img.getMinX(), img.getMinY(), img.getWidth(), img.getHeight()); Rectangle result = null; try { double p[] = new double[8]; p[0] = p[2] = compClip.getLoX(); p[4] = p[6] = compClip.getHiX(); p[1] = p[5] = compClip.getLoY(); p[3] = p[7] = compClip.getHiY(); // Inverse transform the output bounding rect transform.inverseTransform(p, 0, p, 0, 4); xform.inverseTransform(p, 0, p, 0, 4); // Determine a bounding box for the inverse transformed region double x0,x1,y0,y1; x0 = x1 = p[0]; y0 = y1 = p[1]; for (int i = 2; i < 8; ) { double pt = p[i++]; if (pt < x0) { x0 = pt; } else if (pt > x1) { x1 = pt; } pt = p[i++]; if (pt < y0) { y0 = pt; } else if (pt > y1) { y1 = pt; } } // This is padding for anti-aliasing and such. It may // be more than is needed. int x = (int)x0 - padX; int w = (int)(x1 - x0 + 2*padX); int y = (int)y0 - padY; int h = (int)(y1 - y0 + 2*padY); Rectangle clipRect = new Rectangle(x,y,w,h); result = clipRect.intersection(imageRect); } catch (NoninvertibleTransformException nte) { // Worst case bounds are the bounds of the image. result = imageRect; } return result; }
Example 17
Source File: SunGraphics2D.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Returns a rectangle in image coordinates that may be required * in order to draw the given image into the given clipping region * through a pair of AffineTransforms. In addition, horizontal and * vertical padding factors for antialising and interpolation may * be used. */ private static Rectangle getImageRegion(RenderedImage img, Region compClip, AffineTransform transform, AffineTransform xform, int padX, int padY) { Rectangle imageRect = new Rectangle(img.getMinX(), img.getMinY(), img.getWidth(), img.getHeight()); Rectangle result = null; try { double p[] = new double[8]; p[0] = p[2] = compClip.getLoX(); p[4] = p[6] = compClip.getHiX(); p[1] = p[5] = compClip.getLoY(); p[3] = p[7] = compClip.getHiY(); // Inverse transform the output bounding rect transform.inverseTransform(p, 0, p, 0, 4); xform.inverseTransform(p, 0, p, 0, 4); // Determine a bounding box for the inverse transformed region double x0,x1,y0,y1; x0 = x1 = p[0]; y0 = y1 = p[1]; for (int i = 2; i < 8; ) { double pt = p[i++]; if (pt < x0) { x0 = pt; } else if (pt > x1) { x1 = pt; } pt = p[i++]; if (pt < y0) { y0 = pt; } else if (pt > y1) { y1 = pt; } } // This is padding for anti-aliasing and such. It may // be more than is needed. int x = (int)x0 - padX; int w = (int)(x1 - x0 + 2*padX); int y = (int)y0 - padY; int h = (int)(y1 - y0 + 2*padY); Rectangle clipRect = new Rectangle(x,y,w,h); result = clipRect.intersection(imageRect); } catch (NoninvertibleTransformException nte) { // Worst case bounds are the bounds of the image. result = imageRect; } return result; }
Example 18
Source File: FontPanel.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public void modeSpecificDrawChar( Graphics2D g2, int charCode, int baseX, int baseY ) { GlyphVector gv; int oneGlyph[] = { charCode }; char charArray[] = Character.toChars( charCode ); FontRenderContext frc = g2.getFontRenderContext(); AffineTransform oldTX = g2.getTransform(); /// Create GlyphVector to measure the exact visual advance /// Using that number, adjust the position of the character drawn if ( textToUse == ALL_GLYPHS ) gv = testFont.createGlyphVector( frc, oneGlyph ); else gv = testFont.createGlyphVector( frc, charArray ); Rectangle2D r2d2 = gv.getPixelBounds(frc, 0, 0); int shiftedX = baseX; // getPixelBounds returns a result in device space. // we need to convert back to user space to be able to // calculate the shift as baseX is in user space. try { double pt[] = new double[4]; pt[0] = r2d2.getX(); pt[1] = r2d2.getY(); pt[2] = r2d2.getX()+r2d2.getWidth(); pt[3] = r2d2.getY()+r2d2.getHeight(); oldTX.inverseTransform(pt,0,pt,0,2); shiftedX = baseX - (int) ( pt[2] / 2 + pt[0] ); } catch (NoninvertibleTransformException e) { } /// ABP - keep track of old tform, restore it later g2.translate( shiftedX, baseY ); g2.transform( getAffineTransform( g2Transform ) ); if ( textToUse == ALL_GLYPHS ) g2.drawGlyphVector( gv, 0f, 0f ); else { if ( testFont.canDisplay( charCode )) g2.setColor( Color.black ); else { g2.setColor( Color.lightGray ); } switch ( drawMethod ) { case DRAW_STRING: g2.drawString( new String( charArray ), 0, 0 ); break; case DRAW_CHARS: g2.drawChars( charArray, 0, 1, 0, 0 ); break; case DRAW_BYTES: if ( charCode > 0xff ) throw new CannotDrawException( DRAW_BYTES_ERROR ); byte oneByte[] = { (byte) charCode }; g2.drawBytes( oneByte, 0, 1, 0, 0 ); break; case DRAW_GLYPHV: g2.drawGlyphVector( gv, 0f, 0f ); break; case TL_DRAW: TextLayout tl = new TextLayout( new String( charArray ), testFont, frc ); tl.draw( g2, 0f, 0f ); break; case GV_OUTLINE: r2d2 = gv.getVisualBounds(); shiftedX = baseX - (int) ( r2d2.getWidth() / 2 + r2d2.getX() ); g2.draw( gv.getOutline( 0f, 0f )); break; case TL_OUTLINE: r2d2 = gv.getVisualBounds(); shiftedX = baseX - (int) ( r2d2.getWidth() / 2 + r2d2.getX() ); TextLayout tlo = new TextLayout( new String( charArray ), testFont, g2.getFontRenderContext() ); g2.draw( tlo.getOutline( null )); } } /// ABP - restore old tform g2.setTransform ( oldTX ); }
Example 19
Source File: FontPanel.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public void modeSpecificDrawChar( Graphics2D g2, int charCode, int baseX, int baseY ) { GlyphVector gv; int oneGlyph[] = { charCode }; char charArray[] = Character.toChars( charCode ); FontRenderContext frc = g2.getFontRenderContext(); AffineTransform oldTX = g2.getTransform(); /// Create GlyphVector to measure the exact visual advance /// Using that number, adjust the position of the character drawn if ( textToUse == ALL_GLYPHS ) gv = testFont.createGlyphVector( frc, oneGlyph ); else gv = testFont.createGlyphVector( frc, charArray ); Rectangle2D r2d2 = gv.getPixelBounds(frc, 0, 0); int shiftedX = baseX; // getPixelBounds returns a result in device space. // we need to convert back to user space to be able to // calculate the shift as baseX is in user space. try { double pt[] = new double[4]; pt[0] = r2d2.getX(); pt[1] = r2d2.getY(); pt[2] = r2d2.getX()+r2d2.getWidth(); pt[3] = r2d2.getY()+r2d2.getHeight(); oldTX.inverseTransform(pt,0,pt,0,2); shiftedX = baseX - (int) ( pt[2] / 2 + pt[0] ); } catch (NoninvertibleTransformException e) { } /// ABP - keep track of old tform, restore it later g2.translate( shiftedX, baseY ); g2.transform( getAffineTransform( g2Transform ) ); if ( textToUse == ALL_GLYPHS ) g2.drawGlyphVector( gv, 0f, 0f ); else { if ( testFont.canDisplay( charCode )) g2.setColor( Color.black ); else { g2.setColor( Color.lightGray ); } switch ( drawMethod ) { case DRAW_STRING: g2.drawString( new String( charArray ), 0, 0 ); break; case DRAW_CHARS: g2.drawChars( charArray, 0, 1, 0, 0 ); break; case DRAW_BYTES: if ( charCode > 0xff ) throw new CannotDrawException( DRAW_BYTES_ERROR ); byte oneByte[] = { (byte) charCode }; g2.drawBytes( oneByte, 0, 1, 0, 0 ); break; case DRAW_GLYPHV: g2.drawGlyphVector( gv, 0f, 0f ); break; case TL_DRAW: TextLayout tl = new TextLayout( new String( charArray ), testFont, frc ); tl.draw( g2, 0f, 0f ); break; case GV_OUTLINE: r2d2 = gv.getVisualBounds(); shiftedX = baseX - (int) ( r2d2.getWidth() / 2 + r2d2.getX() ); g2.draw( gv.getOutline( 0f, 0f )); break; case TL_OUTLINE: r2d2 = gv.getVisualBounds(); shiftedX = baseX - (int) ( r2d2.getWidth() / 2 + r2d2.getX() ); TextLayout tlo = new TextLayout( new String( charArray ), testFont, g2.getFontRenderContext() ); g2.draw( tlo.getOutline( null )); } } /// ABP - restore old tform g2.setTransform ( oldTX ); }
Example 20
Source File: FontPanel.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public void modeSpecificDrawChar( Graphics2D g2, int charCode, int baseX, int baseY ) { GlyphVector gv; int oneGlyph[] = { charCode }; char charArray[] = Character.toChars( charCode ); FontRenderContext frc = g2.getFontRenderContext(); AffineTransform oldTX = g2.getTransform(); /// Create GlyphVector to measure the exact visual advance /// Using that number, adjust the position of the character drawn if ( textToUse == ALL_GLYPHS ) gv = testFont.createGlyphVector( frc, oneGlyph ); else gv = testFont.createGlyphVector( frc, charArray ); Rectangle2D r2d2 = gv.getPixelBounds(frc, 0, 0); int shiftedX = baseX; // getPixelBounds returns a result in device space. // we need to convert back to user space to be able to // calculate the shift as baseX is in user space. try { double pt[] = new double[4]; pt[0] = r2d2.getX(); pt[1] = r2d2.getY(); pt[2] = r2d2.getX()+r2d2.getWidth(); pt[3] = r2d2.getY()+r2d2.getHeight(); oldTX.inverseTransform(pt,0,pt,0,2); shiftedX = baseX - (int) ( pt[2] / 2 + pt[0] ); } catch (NoninvertibleTransformException e) { } /// ABP - keep track of old tform, restore it later g2.translate( shiftedX, baseY ); g2.transform( getAffineTransform( g2Transform ) ); if ( textToUse == ALL_GLYPHS ) g2.drawGlyphVector( gv, 0f, 0f ); else { if ( testFont.canDisplay( charCode )) g2.setColor( Color.black ); else { g2.setColor( Color.lightGray ); } switch ( drawMethod ) { case DRAW_STRING: g2.drawString( new String( charArray ), 0, 0 ); break; case DRAW_CHARS: g2.drawChars( charArray, 0, 1, 0, 0 ); break; case DRAW_BYTES: if ( charCode > 0xff ) throw new CannotDrawException( DRAW_BYTES_ERROR ); byte oneByte[] = { (byte) charCode }; g2.drawBytes( oneByte, 0, 1, 0, 0 ); break; case DRAW_GLYPHV: g2.drawGlyphVector( gv, 0f, 0f ); break; case TL_DRAW: TextLayout tl = new TextLayout( new String( charArray ), testFont, frc ); tl.draw( g2, 0f, 0f ); break; case GV_OUTLINE: r2d2 = gv.getVisualBounds(); shiftedX = baseX - (int) ( r2d2.getWidth() / 2 + r2d2.getX() ); g2.draw( gv.getOutline( 0f, 0f )); break; case TL_OUTLINE: r2d2 = gv.getVisualBounds(); shiftedX = baseX - (int) ( r2d2.getWidth() / 2 + r2d2.getX() ); TextLayout tlo = new TextLayout( new String( charArray ), testFont, g2.getFontRenderContext() ); g2.draw( tlo.getOutline( null )); } } /// ABP - restore old tform g2.setTransform ( oldTX ); }