本文整理汇总了Java中java.awt.geom.AffineTransform.TYPE_GENERAL_TRANSFORM属性的典型用法代码示例。如果您正苦于以下问题:Java AffineTransform.TYPE_GENERAL_TRANSFORM属性的具体用法?Java AffineTransform.TYPE_GENERAL_TRANSFORM怎么用?Java AffineTransform.TYPE_GENERAL_TRANSFORM使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.awt.geom.AffineTransform
的用法示例。
在下文中一共展示了AffineTransform.TYPE_GENERAL_TRANSFORM属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: needToCopyBgColorImage
/**
* Return true if drawing <code>img</code> will
* invoke a Java2D bug (#4258675). The bug in question
* occurs when a draw image call with a background color
* parameter tries to render a sheared
* or rotated image. The portions of the bounding
* rectangle not covered by the sheared image
* are incorrectly drawn with the background color.
*/
private boolean needToCopyBgColorImage(Image img) {
boolean needToCopy;
AffineTransform transform = getTransform();
return (transform.getType()
& (AffineTransform.TYPE_GENERAL_ROTATION
| AffineTransform.TYPE_GENERAL_TRANSFORM)) != 0;
}
示例2: platformFontCount
@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;
}
}
示例3: deviceFillRect
@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);
}
示例4: needToCopyBgColorImage
/**
* Return true if drawing {@code img} will
* invoke a Java2D bug (#4258675). The bug in question
* occurs when a draw image call with a background color
* parameter tries to render a sheared
* or rotated image. The portions of the bounding
* rectangle not covered by the sheared image
* are incorrectly drawn with the background color.
*/
private boolean needToCopyBgColorImage(Image img) {
boolean needToCopy;
AffineTransform transform = getTransform();
return (transform.getType()
& (AffineTransform.TYPE_GENERAL_ROTATION
| AffineTransform.TYPE_GENERAL_TRANSFORM)) != 0;
}
示例5: userSpaceLineWidth
private float userSpaceLineWidth(AffineTransform at, float lw) {
double widthScale;
if ((at.getType() & (AffineTransform.TYPE_GENERAL_TRANSFORM |
AffineTransform.TYPE_GENERAL_SCALE)) != 0) {
widthScale = Math.sqrt(at.getDeterminant());
} else {
/* First calculate the "maximum scale" of this transform. */
double A = at.getScaleX(); // m00
double C = at.getShearX(); // m01
double B = at.getShearY(); // m10
double D = at.getScaleY(); // m11
/*
* Given a 2 x 2 affine matrix [ A B ] such that
* [ C D ]
* v' = [x' y'] = [Ax + Cy, Bx + Dy], we want to
* find the maximum magnitude (norm) of the vector v'
* with the constraint (x^2 + y^2 = 1).
* The equation to maximize is
* |v'| = sqrt((Ax+Cy)^2+(Bx+Dy)^2)
* or |v'| = sqrt((AA+BB)x^2 + 2(AC+BD)xy + (CC+DD)y^2).
* Since sqrt is monotonic we can maximize |v'|^2
* instead and plug in the substitution y = sqrt(1 - x^2).
* Trigonometric equalities can then be used to get
* rid of most of the sqrt terms.
*/
double EA = A*A + B*B; // x^2 coefficient
double EB = 2*(A*C + B*D); // xy coefficient
double EC = C*C + D*D; // y^2 coefficient
/*
* There is a lot of calculus omitted here.
*
* Conceptually, in the interests of understanding the
* terms that the calculus produced we can consider
* that EA and EC end up providing the lengths along
* the major axes and the hypot term ends up being an
* adjustment for the additional length along the off-axis
* angle of rotated or sheared ellipses as well as an
* adjustment for the fact that the equation below
* averages the two major axis lengths. (Notice that
* the hypot term contains a part which resolves to the
* difference of these two axis lengths in the absence
* of rotation.)
*
* In the calculus, the ratio of the EB and (EA-EC) terms
* ends up being the tangent of 2*theta where theta is
* the angle that the long axis of the ellipse makes
* with the horizontal axis. Thus, this equation is
* calculating the length of the hypotenuse of a triangle
* along that axis.
*/
double hypot = Math.sqrt(EB*EB + (EA-EC)*(EA-EC));
/* sqrt omitted, compare to squared limits below. */
double widthsquared = ((EA + EC + hypot)/2.0);
widthScale = Math.sqrt(widthsquared);
}
return (float) (lw / widthScale);
}
示例6: invalidateTransform
protected void invalidateTransform() {
int type = transform.getType();
int origTransformState = transformState;
if (type == AffineTransform.TYPE_IDENTITY) {
transformState = TRANSFORM_ISIDENT;
transX = transY = 0;
} else if (type == AffineTransform.TYPE_TRANSLATION) {
double dtx = transform.getTranslateX();
double dty = transform.getTranslateY();
transX = (int) Math.floor(dtx + 0.5);
transY = (int) Math.floor(dty + 0.5);
if (dtx == transX && dty == transY) {
transformState = TRANSFORM_INT_TRANSLATE;
} else {
transformState = TRANSFORM_ANY_TRANSLATE;
}
} else if ((type & (AffineTransform.TYPE_FLIP |
AffineTransform.TYPE_MASK_ROTATION |
AffineTransform.TYPE_GENERAL_TRANSFORM)) == 0)
{
transformState = TRANSFORM_TRANSLATESCALE;
transX = transY = 0;
} else {
transformState = TRANSFORM_GENERIC;
transX = transY = 0;
}
if (transformState >= TRANSFORM_TRANSLATESCALE ||
origTransformState >= TRANSFORM_TRANSLATESCALE)
{
/* Its only in this case that the previous or current transform
* was more than a translate that font info is invalidated
*/
cachedFRC = null;
this.validFontInfo = false;
this.fontMetrics = null;
this.glyphVectorFontInfo = null;
if (transformState != origTransformState) {
invalidatePipe();
}
}
if (strokeState != STROKE_CUSTOM) {
validateBasicStroke((BasicStroke) stroke);
}
}
示例7: isTransformQuadrantRotated
public static boolean isTransformQuadrantRotated(AffineTransform tr) {
return ((tr.getType() & (AffineTransform.TYPE_GENERAL_ROTATION |
AffineTransform.TYPE_GENERAL_TRANSFORM)) == 0);
}
示例8: userSpaceLineWidth
private final double userSpaceLineWidth(AffineTransform at, double lw) {
double widthScale;
if (at == null) {
widthScale = 1.0d;
} else if ((at.getType() & (AffineTransform.TYPE_GENERAL_TRANSFORM |
AffineTransform.TYPE_GENERAL_SCALE)) != 0) {
widthScale = Math.sqrt(at.getDeterminant());
} else {
// First calculate the "maximum scale" of this transform.
double A = at.getScaleX(); // m00
double C = at.getShearX(); // m01
double B = at.getShearY(); // m10
double D = at.getScaleY(); // m11
/*
* Given a 2 x 2 affine matrix [ A B ] such that
* [ C D ]
* v' = [x' y'] = [Ax + Cy, Bx + Dy], we want to
* find the maximum magnitude (norm) of the vector v'
* with the constraint (x^2 + y^2 = 1).
* The equation to maximize is
* |v'| = sqrt((Ax+Cy)^2+(Bx+Dy)^2)
* or |v'| = sqrt((AA+BB)x^2 + 2(AC+BD)xy + (CC+DD)y^2).
* Since sqrt is monotonic we can maximize |v'|^2
* instead and plug in the substitution y = sqrt(1 - x^2).
* Trigonometric equalities can then be used to get
* rid of most of the sqrt terms.
*/
double EA = A*A + B*B; // x^2 coefficient
double EB = 2.0d * (A*C + B*D); // xy coefficient
double EC = C*C + D*D; // y^2 coefficient
/*
* There is a lot of calculus omitted here.
*
* Conceptually, in the interests of understanding the
* terms that the calculus produced we can consider
* that EA and EC end up providing the lengths along
* the major axes and the hypot term ends up being an
* adjustment for the additional length along the off-axis
* angle of rotated or sheared ellipses as well as an
* adjustment for the fact that the equation below
* averages the two major axis lengths. (Notice that
* the hypot term contains a part which resolves to the
* difference of these two axis lengths in the absence
* of rotation.)
*
* In the calculus, the ratio of the EB and (EA-EC) terms
* ends up being the tangent of 2*theta where theta is
* the angle that the long axis of the ellipse makes
* with the horizontal axis. Thus, this equation is
* calculating the length of the hypotenuse of a triangle
* along that axis.
*/
double hypot = Math.sqrt(EB*EB + (EA-EC)*(EA-EC));
// sqrt omitted, compare to squared limits below.
double widthsquared = ((EA + EC + hypot) / 2.0d);
widthScale = Math.sqrt(widthsquared);
}
return (lw / widthScale);
}
示例9: userSpaceLineWidth
private final float userSpaceLineWidth(AffineTransform at, float lw) {
float widthScale;
if (at == null) {
widthScale = 1.0f;
} else if ((at.getType() & (AffineTransform.TYPE_GENERAL_TRANSFORM |
AffineTransform.TYPE_GENERAL_SCALE)) != 0) {
widthScale = (float)Math.sqrt(at.getDeterminant());
} else {
// First calculate the "maximum scale" of this transform.
double A = at.getScaleX(); // m00
double C = at.getShearX(); // m01
double B = at.getShearY(); // m10
double D = at.getScaleY(); // m11
/*
* Given a 2 x 2 affine matrix [ A B ] such that
* [ C D ]
* v' = [x' y'] = [Ax + Cy, Bx + Dy], we want to
* find the maximum magnitude (norm) of the vector v'
* with the constraint (x^2 + y^2 = 1).
* The equation to maximize is
* |v'| = sqrt((Ax+Cy)^2+(Bx+Dy)^2)
* or |v'| = sqrt((AA+BB)x^2 + 2(AC+BD)xy + (CC+DD)y^2).
* Since sqrt is monotonic we can maximize |v'|^2
* instead and plug in the substitution y = sqrt(1 - x^2).
* Trigonometric equalities can then be used to get
* rid of most of the sqrt terms.
*/
double EA = A*A + B*B; // x^2 coefficient
double EB = 2.0d * (A*C + B*D); // xy coefficient
double EC = C*C + D*D; // y^2 coefficient
/*
* There is a lot of calculus omitted here.
*
* Conceptually, in the interests of understanding the
* terms that the calculus produced we can consider
* that EA and EC end up providing the lengths along
* the major axes and the hypot term ends up being an
* adjustment for the additional length along the off-axis
* angle of rotated or sheared ellipses as well as an
* adjustment for the fact that the equation below
* averages the two major axis lengths. (Notice that
* the hypot term contains a part which resolves to the
* difference of these two axis lengths in the absence
* of rotation.)
*
* In the calculus, the ratio of the EB and (EA-EC) terms
* ends up being the tangent of 2*theta where theta is
* the angle that the long axis of the ellipse makes
* with the horizontal axis. Thus, this equation is
* calculating the length of the hypotenuse of a triangle
* along that axis.
*/
double hypot = Math.sqrt(EB*EB + (EA-EC)*(EA-EC));
// sqrt omitted, compare to squared limits below.
double widthsquared = ((EA + EC + hypot) / 2.0d);
widthScale = (float)Math.sqrt(widthsquared);
}
return (lw / widthScale);
}
示例10: getStrike
private FontStrike getStrike(FontStrikeDesc desc, boolean copy) {
/* Before looking in the map, see if the descriptor matches the
* last strike returned from this Font2D. This should often be a win
* since its common for the same font, in the same size to be
* used frequently, for example in many parts of a UI.
*
* If its not the same then we use the descriptor to locate a
* Reference to the strike. If it exists and points to a strike,
* then we update the last strike to refer to that and return it.
*
* If the key isn't in the map, or its reference object has been
* collected, then we create a new strike, put it in the map and
* set it to be the last strike.
*/
FontStrike strike = lastFontStrike.get();
if (strike != null && desc.equals(strike.desc)) {
//strike.lastlookupTime = System.currentTimeMillis();
return strike;
} else {
Reference<FontStrike> strikeRef = strikeCache.get(desc);
if (strikeRef != null) {
strike = strikeRef.get();
if (strike != null) {
//strike.lastlookupTime = System.currentTimeMillis();
lastFontStrike = new SoftReference<>(strike);
StrikeCache.refStrike(strike);
return strike;
}
}
/* When we create a new FontStrike instance, we *must*
* ask the StrikeCache for a reference. We must then ensure
* this reference remains reachable, by storing it in the
* Font2D's strikeCache map.
* So long as the Reference is there (reachable) then if the
* reference is cleared, it will be enqueued for disposal.
* If for some reason we explicitly remove this reference, it
* must only be done when holding a strong reference to the
* referent (the FontStrike), or if the reference is cleared,
* then we must explicitly "dispose" of the native resources.
* The only place this currently happens is in this same method,
* where we find a cleared reference and need to overwrite it
* here with a new reference.
* Clearing the whilst holding a strong reference, should only
* be done if the
*/
if (copy) {
desc = new FontStrikeDesc(desc);
}
strike = createStrike(desc);
//StrikeCache.addStrike();
/* If we are creating many strikes on this font which
* involve non-quadrant rotations, or more general
* transforms which include shears, then force the use
* of weak references rather than soft references.
* This means that it won't live much beyond the next GC,
* which is what we want for what is likely a transient strike.
*/
int txType = desc.glyphTx.getType();
if (txType == AffineTransform.TYPE_GENERAL_TRANSFORM ||
(txType & AffineTransform.TYPE_GENERAL_ROTATION) != 0 &&
strikeCache.size() > 10) {
strikeRef = StrikeCache.getStrikeRef(strike, true);
} else {
strikeRef = StrikeCache.getStrikeRef(strike);
}
strikeCache.put(desc, strikeRef);
//strike.lastlookupTime = System.currentTimeMillis();
lastFontStrike = new SoftReference<>(strike);
StrikeCache.refStrike(strike);
return strike;
}
}