本文整理汇总了Java中java.awt.geom.AffineTransform.transform方法的典型用法代码示例。如果您正苦于以下问题:Java AffineTransform.transform方法的具体用法?Java AffineTransform.transform怎么用?Java AffineTransform.transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.geom.AffineTransform
的用法示例。
在下文中一共展示了AffineTransform.transform方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pixellate
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
* !!! 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");
}
}
示例2: scaleForTransform
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public static Dimension scaleForTransform(AffineTransform at,
Dimension dim)
{
int w = dim.width;
int h = dim.height;
Point2D.Double ptd = new Point2D.Double(0, 0);
at.transform(ptd, ptd);
double ox = ptd.getX();
double oy = ptd.getY();
if (ox < 0 || ox > w || oy < 0 || oy > h) {
throw new InternalError("origin outside destination");
}
double scalex = scaleForPoint(at, ox, oy, w, h, w, h);
double scaley = scalex;
scalex = Math.min(scaleForPoint(at, ox, oy, w, 0, w, h), scalex);
scaley = Math.min(scaleForPoint(at, ox, oy, 0, h, w, h), scaley);
if (scalex < 0 || scaley < 0) {
throw new InternalError("could not fit dims to transform");
}
return new Dimension((int) Math.floor(w * scalex),
(int) Math.floor(h * scaley));
}
示例3: scaleForPoint
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public static double scaleForPoint(AffineTransform at,
double xorig, double yorig,
double x, double y,
int w, int h)
{
Point2D.Double ptd = new Point2D.Double(x, y);
at.transform(ptd, ptd);
x = ptd.getX();
y = ptd.getY();
double scale = 1.0;
if (x < 0) {
scale = Math.min(scale, xorig / (xorig - x));
} else if (x > w) {
scale = Math.min(scale, (w - xorig) / (x - xorig));
}
if (y < 0) {
scale = Math.min(scale, yorig / (yorig - y));
} else if (y > h) {
scale = Math.min(scale, (h - yorig) / (y - yorig));
}
return scale;
}
示例4: setGraphicsConfigInfo
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
synchronized void setGraphicsConfigInfo(AffineTransform at,
double pw, double ph) {
Point2D.Double pt = new Point2D.Double(pw, ph);
at.transform(pt, pt);
if (pgConfig == null ||
defaultDeviceTransform == null ||
!at.equals(defaultDeviceTransform) ||
deviceWidth != (int)pt.getX() ||
deviceHeight != (int)pt.getY()) {
deviceWidth = (int)pt.getX();
deviceHeight = (int)pt.getY();
defaultDeviceTransform = at;
pgConfig = null;
}
}
示例5: getClipRect2D
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
* Gets the region currently displayed in Projection coordinates.
* @return the region currently displayed in Projection coordinates.
*/
public Rectangle2D getClipRect2D() {
Rectangle r = getVisibleRect();
Dimension dim = getPreferredSize();
r.width = Math.min(r.width, dim.width);
r.height = Math.min(r.height, dim.height);
AffineTransform at = new AffineTransform();
if(rotation==1) {
at.translate( 0., dim.getHeight() );
at.rotate(-.5*Math.PI);
} else if( rotation==2 ) {
at.translate( dim.getWidth(), dim.getHeight() );
at.rotate( Math.PI );
} else if( rotation == 3) {
at.translate( dim.getWidth(), 0. );
at.rotate( .5*Math.PI );
}
if(rotation != 0) {
Point2D p1 = at.transform(new Point(r.x,r.y), null);
Point2D p2 = at.transform(new Point(r.x+r.width,r.y+r.width), null);
r.x = (int) Math.min(p1.getX(), p2.getX());
r.width = (int) Math.max(p1.getX(), p2.getX()) - r.x;
r.y = (int) Math.min(p1.getY(), p2.getY());
r.height = (int) Math.max(p1.getY(), p2.getY()) - r.y;
}
if(mapBorder != null) {
Insets ins = mapBorder.getBorderInsets(this);
r.width -= ins.left + ins.right;
r.height -= ins.top + ins.bottom;
}
Rectangle2D.Double r2d = new Rectangle2D.Double(
r.getX()/zoom, r.getY()/zoom,
r.getWidth()/zoom, r.getHeight()/zoom);
return r2d;
}
示例6: initPositions
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
* 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;
}
}
}
示例7: transformImage
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
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);
}
示例8: buildLinearGradientShading
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
private PDShading buildLinearGradientShading(Paint paint, AffineTransform tf) throws IOException {
/*
* Batik has a copy of RadialGradientPaint, but it has the same structure as the
* AWT RadialGradientPaint. So we use Reflection to access the fields of both
* these classes.
*/
Color[] colors = getPropertyValue(paint, "getColors");
Color firstColor = colors[0];
PDColor firstColorMapped = colorMapper.mapColor(contentStream, firstColor);
applyAsStrokingColor(firstColor);
PDShadingType3 shading = new PDShadingType3(new COSDictionary());
shading.setShadingType(PDShading.SHADING_TYPE2);
shading.setColorSpace(firstColorMapped.getColorSpace());
float[] fractions = getPropertyValue(paint, "getFractions");
Point2D startPoint = getPropertyValue(paint, "getStartPoint");
Point2D endPoint = getPropertyValue(paint, "getEndPoint");
AffineTransform gradientTransform = getPropertyValue(paint, "getTransform");
tf.concatenate(gradientTransform);
tf.transform(startPoint, startPoint);
tf.transform(endPoint, endPoint);
COSArray coords = new COSArray();
coords.add(new COSFloat((float) startPoint.getX()));
coords.add(new COSFloat((float) startPoint.getY()));
coords.add(new COSFloat((float) endPoint.getX()));
coords.add(new COSFloat((float) endPoint.getY()));
shading.setCoords(coords);
PDFunctionType3 type3 = buildType3Function(colors, fractions);
COSArray extend = new COSArray();
extend.add(COSBoolean.TRUE);
extend.add(COSBoolean.TRUE);
shading.setFunction(type3);
shading.setExtend(extend);
return shading;
}
示例9: buildGradientShading
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
private PDShading buildGradientShading(AffineTransform tf, GradientPaint gradientPaint) throws IOException {
Color[] colors = new Color[] { gradientPaint.getColor1(), gradientPaint.getColor2() };
Color firstColor = colors[0];
PDColor firstColorMapped = colorMapper.mapColor(contentStream, firstColor);
applyAsStrokingColor(firstColor);
PDShadingType3 shading = new PDShadingType3(new COSDictionary());
shading.setShadingType(PDShading.SHADING_TYPE2);
shading.setColorSpace(firstColorMapped.getColorSpace());
float[] fractions = new float[] { 0, 1 };
Point2D startPoint = gradientPaint.getPoint1();
Point2D endPoint = gradientPaint.getPoint2();
tf.transform(startPoint, startPoint);
tf.transform(endPoint, endPoint);
COSArray coords = new COSArray();
coords.add(new COSFloat((float) startPoint.getX()));
coords.add(new COSFloat((float) startPoint.getY()));
coords.add(new COSFloat((float) endPoint.getX()));
coords.add(new COSFloat((float) endPoint.getY()));
shading.setCoords(coords);
PDFunctionType3 type3 = buildType3Function(colors, fractions);
COSArray extend = new COSArray();
extend.add(COSBoolean.TRUE);
extend.add(COSBoolean.TRUE);
shading.setFunction(type3);
shading.setExtend(extend);
return shading;
}
示例10: transformShape
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
protected static Shape transformShape(AffineTransform tx, Shape clip) {
if (clip == null) {
return null;
}
if (clip instanceof Rectangle2D &&
(tx.getType() & NON_RECTILINEAR_TRANSFORM_MASK) == 0)
{
Rectangle2D rect = (Rectangle2D) clip;
double matrix[] = new double[4];
matrix[0] = rect.getX();
matrix[1] = rect.getY();
matrix[2] = matrix[0] + rect.getWidth();
matrix[3] = matrix[1] + rect.getHeight();
tx.transform(matrix, 0, matrix, 0, 2);
fixRectangleOrientation(matrix, rect);
return new Rectangle2D.Double(matrix[0], matrix[1],
matrix[2] - matrix[0],
matrix[3] - matrix[1]);
}
if (tx.isIdentity()) {
return cloneShape(clip);
}
return tx.createTransformedShape(clip);
}
示例11: deviceFillRect
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
@Override
protected void deviceFillRect(int x, int y, int width, int height,
Color color) {
/*
* Transform to device coordinates
*/
AffineTransform deviceTransform = getTransform();
/* check if rotated or sheared */
int transformType = deviceTransform.getType();
boolean usePath = ((transformType &
(AffineTransform.TYPE_GENERAL_ROTATION |
AffineTransform.TYPE_GENERAL_TRANSFORM)) != 0);
if (usePath) {
fill(new Rectangle2D.Float(x, y, width, height));
return;
}
Point2D.Float tlc_pos = new Point2D.Float(x, y);
deviceTransform.transform(tlc_pos, tlc_pos);
Point2D.Float brc_pos = new Point2D.Float(x+width, y+height);
deviceTransform.transform(brc_pos, brc_pos);
float deviceWidth = (float) (brc_pos.getX() - tlc_pos.getX());
float deviceHeight = (float)(brc_pos.getY() - tlc_pos.getY());
WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob();
wPrinterJob.fillRect((float)tlc_pos.getX(), (float)tlc_pos.getY(),
deviceWidth, deviceHeight, color);
}
示例12: findTranslation
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
private AffineTransform findTranslation(AffineTransform at, BufferedImage bi, int angle) {//45
Point2D p2din, p2dout;
double ytrans = 0.0, xtrans = 0.0;
if (angle <= 90) {
p2din = new Point2D.Double(0.0, 0.0);
p2dout = at.transform(p2din, null);
ytrans = p2dout.getY();
p2din = new Point2D.Double(0, bi.getHeight());
p2dout = at.transform(p2din, null);
xtrans = p2dout.getX();
}
/*else if(angle<=135){
p2din = new Point2D.Double(0.0, bi.getHeight());
p2dout = at.transform(p2din, null);
ytrans = p2dout.getY();
p2din = new Point2D.Double(bi.getWidth(),bi.getHeight());
p2dout = at.transform(p2din, null);
xtrans = p2dout.getX();
}*/
else if (angle <= 180) {
p2din = new Point2D.Double(0.0, bi.getHeight());
p2dout = at.transform(p2din, null);
ytrans = p2dout.getY();
p2din = new Point2D.Double(bi.getWidth(), bi.getHeight());
p2dout = at.transform(p2din, null);
xtrans = p2dout.getX();
}
/*else if(angle<=225){
p2din = new Point2D.Double(bi.getWidth(), bi.getHeight());
p2dout = at.transform(p2din, null);
ytrans = p2dout.getY();
p2din = new Point2D.Double(bi.getWidth(),0.0);
p2dout = at.transform(p2din, null);
xtrans = p2dout.getX();
}*/
else if (angle <= 270) {
p2din = new Point2D.Double(bi.getWidth(), bi.getHeight());
p2dout = at.transform(p2din, null);
ytrans = p2dout.getY();
p2din = new Point2D.Double(bi.getWidth(), 0.0);
p2dout = at.transform(p2din, null);
xtrans = p2dout.getX();
} else {
p2din = new Point2D.Double(bi.getWidth(), 0.0);
p2dout = at.transform(p2din, null);
ytrans = p2dout.getY();
p2din = new Point2D.Double(0.0, 0.0);
p2dout = at.transform(p2din, null);
xtrans = p2dout.getX();
}
AffineTransform tat = new AffineTransform();
tat.translate(-xtrans, -ytrans);
return tat;
}
示例13: buildRadialGradientShading
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
private PDShading buildRadialGradientShading(Paint paint, AffineTransform tf) throws IOException {
/*
* Batik has a copy of RadialGradientPaint, but it has the same structure as the
* AWT RadialGradientPaint. So we use Reflection to access the fields of both
* these classes.
*/
Color[] colors = getPropertyValue(paint, "getColors");
Color firstColor = colors[0];
PDColor firstColorMapped = colorMapper.mapColor(contentStream, firstColor);
applyAsStrokingColor(firstColor);
PDShadingType3 shading = new PDShadingType3(new COSDictionary());
shading.setShadingType(PDShading.SHADING_TYPE3);
shading.setColorSpace(firstColorMapped.getColorSpace());
float[] fractions = getPropertyValue(paint, "getFractions");
Point2D centerPoint = getPropertyValue(paint, "getCenterPoint");
Point2D focusPoint = getPropertyValue(paint, "getFocusPoint");
AffineTransform gradientTransform = getPropertyValue(paint, "getTransform");
tf.concatenate(gradientTransform);
tf.transform(centerPoint, centerPoint);
tf.transform(focusPoint, focusPoint);
@SuppressWarnings("ConstantConditions")
float radius = getPropertyValue(paint, "getRadius");
radius = (float) Math.abs(radius * tf.getScaleX());
COSArray coords = new COSArray();
coords.add(new COSFloat((float) centerPoint.getX()));
coords.add(new COSFloat((float) centerPoint.getY()));
coords.add(new COSFloat(0));
coords.add(new COSFloat((float) focusPoint.getX()));
coords.add(new COSFloat((float) focusPoint.getY()));
coords.add(new COSFloat(radius));
shading.setCoords(coords);
PDFunctionType3 type3 = buildType3Function(colors, fractions);
COSArray extend = new COSArray();
extend.add(COSBoolean.TRUE);
extend.add(COSBoolean.TRUE);
shading.setFunction(type3);
shading.setExtend(extend);
return shading;
}
示例14: drawText
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
private void drawText( Graphics g, int w, int h ) {
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.white);
g2.fillRect(0, 0, w, h);
g2.setColor(Color.black);
/// sets font, RenderingHints.
setParams( g2 );
/// If flag is set, recalculate fontMetrics and reset the scrollbar
if ( updateFontMetrics || isPrinting ) {
/// NOTE: re-calculates in case G2 transform
/// is something other than NONE
calcFontMetrics( g2, w, h );
updateFontMetrics = false;
}
/// Calculate the amount of text that can be drawn...
calcTextRange();
/// Draw according to the set "Text to Use" mode
if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) {
int charToDraw = drawStart;
if ( showGrid )
drawGrid( g2 );
for ( int i = 0; i < numCharDown && charToDraw <= drawEnd; i++ ) {
for ( int j = 0; j < numCharAcross && charToDraw <= drawEnd; j++, charToDraw++ ) {
int gridLocX = j * gridWidth + canvasInset_X;
int gridLocY = i * gridHeight + canvasInset_Y;
modeSpecificDrawChar( g2, charToDraw,
gridLocX + gridWidth / 2,
gridLocY + maxAscent );
}
}
}
else if ( textToUse == USER_TEXT ) {
g2.drawRect( 0, 0, w - 1, h - 1 );
for ( int i = drawStart; i <= drawEnd; i++ ) {
int lineStartX = canvasInset_Y;
int lineStartY = ( i - drawStart ) * gridHeight + maxAscent;
modeSpecificDrawLine( g2, userText[i], lineStartX, lineStartY );
}
}
else {
float xPos, yPos = (float) canvasInset_Y;
g2.drawRect( 0, 0, w - 1, h - 1 );
for ( int i = drawStart; i <= drawEnd; i++ ) {
TextLayout oneLine = (TextLayout) lineBreakTLs.elementAt( i );
xPos =
oneLine.isLeftToRight() ?
canvasInset_X : ( (float) w - oneLine.getAdvance() - canvasInset_X );
float fmData[] = {0, oneLine.getAscent(), 0, oneLine.getDescent(), 0, oneLine.getLeading()};
if (g2Transform != NONE) {
AffineTransform at = getAffineTransform(g2Transform);
at.transform( fmData, 0, fmData, 0, 3);
}
//yPos += oneLine.getAscent();
yPos += fmData[1]; // ascent
//oneLine.draw( g2, xPos, yPos );
tlDrawLine( g2, oneLine, xPos, yPos );
//yPos += oneLine.getDescent() + oneLine.getLeading();
yPos += fmData[3] + fmData[5]; // descent + leading
}
}
g2.dispose();
}
示例15: setupGlyphImages
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
* The strike cache works like this.
*
* -Each glyph is thought of as having a transform, usually identity.
* -Each request for a strike is based on a device transform, either the
* one in the frc or the rendering transform.
* -For general info, strikes are held with soft references.
* -When rendering, strikes must be held with hard references for the
* duration of the rendering call. GlyphList will have to hold this
* info along with the image and position info, but toss the strike info
* when done.
* -Build the strike cache as needed. If the dev transform we want to use
* has changed from the last time it is built, the cache is flushed by
* the caller before these methods are called.
*
* Use a tx that doesn't include translation components of dst tx.
*/
Object setupGlyphImages(long[] images, float[] positions, AffineTransform tx) {
int len = sgv.glyphs.length;
GlyphStrike[] sl = getAllStrikes();
for (int i = 0; i < len; ++i) {
GlyphStrike gs = sl[indices[i]];
int glyphID = sgv.glyphs[i];
images[i] = gs.strike.getGlyphImagePtr(glyphID);
gs.getGlyphPosition(glyphID, i*2, sgv.positions, positions);
}
tx.transform(positions, 0, positions, 0, len);
return sl;
}