use of java.awt.geom.NoninvertibleTransformException in project jdk8u_jdk by JetBrains.
the class WPathGraphics method draw.
/**
* Strokes the outline of a Shape using the settings of the current
* graphics state. The rendering attributes applied include the
* clip, transform, paint or color, composite and stroke attributes.
* @param s The shape to be drawn.
* @see #setStroke
* @see #setPaint
* @see java.awt.Graphics#setColor
* @see #transform
* @see #setTransform
* @see #clip
* @see #setClip
* @see #setComposite
*/
@Override
public void draw(Shape s) {
Stroke stroke = getStroke();
/* If the line being drawn is thinner than can be
* rendered, then change the line width, stroke
* the shape, and then set the line width back.
* We can only do this for BasicStroke's.
*/
if (stroke instanceof BasicStroke) {
BasicStroke lineStroke;
BasicStroke minLineStroke = null;
float deviceLineWidth;
float lineWidth;
AffineTransform deviceTransform;
Point2D.Float penSize;
/* Get the requested line width in user space.
*/
lineStroke = (BasicStroke) stroke;
lineWidth = lineStroke.getLineWidth();
penSize = new Point2D.Float(lineWidth, lineWidth);
/* Compute the line width in device coordinates.
* Work on a point in case there is asymetric scaling
* between user and device space.
* Take the absolute value in case there is negative
* scaling in effect.
*/
deviceTransform = getTransform();
deviceTransform.deltaTransform(penSize, penSize);
deviceLineWidth = Math.min(Math.abs(penSize.x), Math.abs(penSize.y));
/* If the requested line is too thin then map our
* minimum line width back to user space and set
* a new BasicStroke.
*/
if (deviceLineWidth < MIN_DEVICE_LINEWIDTH) {
Point2D.Float minPenSize = new Point2D.Float(MIN_DEVICE_LINEWIDTH, MIN_DEVICE_LINEWIDTH);
try {
AffineTransform inverse;
float minLineWidth;
/* Convert the minimum line width from device
* space to user space.
*/
inverse = deviceTransform.createInverse();
inverse.deltaTransform(minPenSize, minPenSize);
minLineWidth = Math.max(Math.abs(minPenSize.x), Math.abs(minPenSize.y));
/* Use all of the parameters from the current
* stroke but change the line width to our
* calculated minimum.
*/
minLineStroke = new BasicStroke(minLineWidth, lineStroke.getEndCap(), lineStroke.getLineJoin(), lineStroke.getMiterLimit(), lineStroke.getDashArray(), lineStroke.getDashPhase());
setStroke(minLineStroke);
} catch (NoninvertibleTransformException e) {
/* If we can't invert the matrix there is something
* very wrong so don't worry about the minor matter
* of a minimum line width.
*/
}
}
super.draw(s);
/* If we changed the stroke, put back the old
* stroke in order to maintain a minimum line
* width.
*/
if (minLineStroke != null) {
setStroke(lineStroke);
}
/* The stroke in effect was not a BasicStroke so we
* will not try to enforce a minimum line width.
*/
} else {
super.draw(s);
}
}
use of java.awt.geom.NoninvertibleTransformException in project jdk8u_jdk by JetBrains.
the class NativeStrike method getNativePointSize.
/* The following method prepares data used in obtaining FontMetrics.
* This is the one case in which we allow anything other than a
* simple scale to be used with a native font. We do this because in
* order to ensure that clients get the overall metrics they expect
* for a font whatever coordinate system (combination of font and
* device transform) they use.
* X11 fonts can only have a scale applied (remind : non-uniform?)
* We strip out everything else and if necessary obtain an inverse
* tx which we use to return metrics for the font in the transformed
* coordinate system of the font. ie we pass X11 a simple scale, and
* then apply the non-scale part of the font TX to that result.
*/
private int getNativePointSize() {
/* Make a copy of the glyphTX in which we will store the
* font transform, inverting the devTx if necessary
*/
double[] mat = new double[4];
desc.glyphTx.getMatrix(mat);
fontTx = new AffineTransform(mat);
/* Now work backwards to get the font transform */
if (!desc.devTx.isIdentity() && desc.devTx.getType() != AffineTransform.TYPE_TRANSLATION) {
try {
invertDevTx = desc.devTx.createInverse();
fontTx.concatenate(invertDevTx);
} catch (NoninvertibleTransformException e) {
e.printStackTrace();
}
}
/* At this point the fontTx may be a simple +ve scale, or it
* may be something more complex.
*/
Point2D.Float pt = new Point2D.Float(1f, 1f);
fontTx.deltaTransform(pt, pt);
double ptSize = Math.abs(pt.y);
int ttype = fontTx.getType();
if ((ttype & ~AffineTransform.TYPE_UNIFORM_SCALE) != 0 || fontTx.getScaleY() <= 0) {
/* We need to create an inverse transform that doesn't
* include the point size (strictly the uniform scale)
*/
fontTx.scale(1 / ptSize, 1 / ptSize);
} else {
// no need
fontTx = null;
}
return (int) ptSize;
}
use of java.awt.geom.NoninvertibleTransformException in project jdk8u_jdk by JetBrains.
the class AttributeValues method extractRotation.
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;
}
use of java.awt.geom.NoninvertibleTransformException in project android_frameworks_base by crdroidandroid.
the class Matrix_Delegate method native_invert.
@LayoutlibDelegate
static /*package*/
boolean native_invert(long native_object, long inverse) {
Matrix_Delegate d = sManager.getDelegate(native_object);
if (d == null) {
return false;
}
Matrix_Delegate inv_mtx = sManager.getDelegate(inverse);
if (inv_mtx == null) {
return false;
}
try {
AffineTransform affineTransform = d.getAffineTransform();
AffineTransform inverseTransform = affineTransform.createInverse();
inv_mtx.mValues[0] = (float) inverseTransform.getScaleX();
inv_mtx.mValues[1] = (float) inverseTransform.getShearX();
inv_mtx.mValues[2] = (float) inverseTransform.getTranslateX();
inv_mtx.mValues[3] = (float) inverseTransform.getScaleX();
inv_mtx.mValues[4] = (float) inverseTransform.getShearY();
inv_mtx.mValues[5] = (float) inverseTransform.getTranslateY();
return true;
} catch (NoninvertibleTransformException e) {
return false;
}
}
Aggregations