Java Code Examples for java.awt.geom.AffineTransform#deltaTransform()
The following examples show how to use
java.awt.geom.AffineTransform#deltaTransform() .
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: StrikeMetrics.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
void convertToUserSpace(AffineTransform invTx) { Point2D.Float pt2D = new Point2D.Float(); pt2D.x = ascentX; pt2D.y = ascentY; invTx.deltaTransform(pt2D, pt2D); ascentX = pt2D.x; ascentY = pt2D.y; pt2D.x = descentX; pt2D.y = descentY; invTx.deltaTransform(pt2D, pt2D); descentX = pt2D.x; descentY = pt2D.y; pt2D.x = baselineX; pt2D.y = baselineY; invTx.deltaTransform(pt2D, pt2D); baselineX = pt2D.x; baselineY = pt2D.y; pt2D.x = leadingX; pt2D.y = leadingY; invTx.deltaTransform(pt2D, pt2D); leadingX = pt2D.x; leadingY = pt2D.y; pt2D.x = maxAdvanceX; pt2D.y = maxAdvanceY; invTx.deltaTransform(pt2D, pt2D); maxAdvanceX = pt2D.x; maxAdvanceY = pt2D.y; }
Example 2
Source File: AttributeValues.java From dragonwell8_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 3
Source File: StrikeMetrics.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
void convertToUserSpace(AffineTransform invTx) { Point2D.Float pt2D = new Point2D.Float(); pt2D.x = ascentX; pt2D.y = ascentY; invTx.deltaTransform(pt2D, pt2D); ascentX = pt2D.x; ascentY = pt2D.y; pt2D.x = descentX; pt2D.y = descentY; invTx.deltaTransform(pt2D, pt2D); descentX = pt2D.x; descentY = pt2D.y; pt2D.x = baselineX; pt2D.y = baselineY; invTx.deltaTransform(pt2D, pt2D); baselineX = pt2D.x; baselineY = pt2D.y; pt2D.x = leadingX; pt2D.y = leadingY; invTx.deltaTransform(pt2D, pt2D); leadingX = pt2D.x; leadingY = pt2D.y; pt2D.x = maxAdvanceX; pt2D.y = maxAdvanceY; invTx.deltaTransform(pt2D, pt2D); maxAdvanceX = pt2D.x; maxAdvanceY = pt2D.y; }
Example 4
Source File: StrikeMetrics.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
void convertToUserSpace(AffineTransform invTx) { Point2D.Float pt2D = new Point2D.Float(); pt2D.x = ascentX; pt2D.y = ascentY; invTx.deltaTransform(pt2D, pt2D); ascentX = pt2D.x; ascentY = pt2D.y; pt2D.x = descentX; pt2D.y = descentY; invTx.deltaTransform(pt2D, pt2D); descentX = pt2D.x; descentY = pt2D.y; pt2D.x = baselineX; pt2D.y = baselineY; invTx.deltaTransform(pt2D, pt2D); baselineX = pt2D.x; baselineY = pt2D.y; pt2D.x = leadingX; pt2D.y = leadingY; invTx.deltaTransform(pt2D, pt2D); leadingX = pt2D.x; leadingY = pt2D.y; pt2D.x = maxAdvanceX; pt2D.y = maxAdvanceY; invTx.deltaTransform(pt2D, pt2D); maxAdvanceX = pt2D.x; maxAdvanceY = pt2D.y; }
Example 5
Source File: StrikeMetrics.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
void convertToUserSpace(AffineTransform invTx) { Point2D.Float pt2D = new Point2D.Float(); pt2D.x = ascentX; pt2D.y = ascentY; invTx.deltaTransform(pt2D, pt2D); ascentX = pt2D.x; ascentY = pt2D.y; pt2D.x = descentX; pt2D.y = descentY; invTx.deltaTransform(pt2D, pt2D); descentX = pt2D.x; descentY = pt2D.y; pt2D.x = baselineX; pt2D.y = baselineY; invTx.deltaTransform(pt2D, pt2D); baselineX = pt2D.x; baselineY = pt2D.y; pt2D.x = leadingX; pt2D.y = leadingY; invTx.deltaTransform(pt2D, pt2D); leadingX = pt2D.x; leadingY = pt2D.y; pt2D.x = maxAdvanceX; pt2D.y = maxAdvanceY; invTx.deltaTransform(pt2D, pt2D); maxAdvanceX = pt2D.x; maxAdvanceY = pt2D.y; }
Example 6
Source File: AttributeValues.java From TencentKona-8 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 7
Source File: StrikeMetrics.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
void convertToUserSpace(AffineTransform invTx) { Point2D.Float pt2D = new Point2D.Float(); pt2D.x = ascentX; pt2D.y = ascentY; invTx.deltaTransform(pt2D, pt2D); ascentX = pt2D.x; ascentY = pt2D.y; pt2D.x = descentX; pt2D.y = descentY; invTx.deltaTransform(pt2D, pt2D); descentX = pt2D.x; descentY = pt2D.y; pt2D.x = baselineX; pt2D.y = baselineY; invTx.deltaTransform(pt2D, pt2D); baselineX = pt2D.x; baselineY = pt2D.y; pt2D.x = leadingX; pt2D.y = leadingY; invTx.deltaTransform(pt2D, pt2D); leadingX = pt2D.x; leadingY = pt2D.y; pt2D.x = maxAdvanceX; pt2D.y = maxAdvanceY; invTx.deltaTransform(pt2D, pt2D); maxAdvanceX = pt2D.x; maxAdvanceY = pt2D.y; }
Example 8
Source File: NativeStrike.java From hottub with GNU General Public License v2.0 | 5 votes |
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 { fontTx = null; // no need } return (int)ptSize; }
Example 9
Source File: StandardGlyphVector.java From Bytecoder with Apache License 2.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 10
Source File: StandardGlyphVector.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public StandardGlyphVector(Font font, FontRenderContext frc, int[] glyphs, float[] positions, int[] indices, int flags) { initGlyphVector(font, frc, glyphs, positions, indices, flags); // this code should go into layout float track = getTracking(font); if (track != 0) { track *= font.getSize2D(); Point2D.Float trackPt = new Point2D.Float(track, 0); // advance delta if (font.isTransformed()) { AffineTransform at = font.getTransform(); at.deltaTransform(trackPt, trackPt); } // how do we know its a base glyph // for now, it is if the natural advance of the glyph is non-zero Font2D f2d = FontUtilities.getFont2D(font); FontStrike strike = f2d.getStrike(font, frc); float[] deltas = { trackPt.x, trackPt.y }; for (int j = 0; j < deltas.length; ++j) { float inc = deltas[j]; if (inc != 0) { float delta = 0; for (int i = j, n = 0; n < glyphs.length; i += 2) { if (strike.getGlyphAdvance(glyphs[n++]) != 0) { // might be an inadequate test positions[i] += delta; delta += inc; } } positions[positions.length-2+j] += delta; } } } }
Example 11
Source File: StandardGlyphVector.java From openjdk-jdk8u 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 12
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 13
Source File: NativeStrike.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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 { fontTx = null; // no need } return (int)ptSize; }
Example 14
Source File: StandardGlyphVector.java From openjdk-8 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 15
Source File: WPathGraphics.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Draw a line using a pen created using the specified color * and current stroke properties. */ @Override protected void deviceDrawLine(int xBegin, int yBegin, int xEnd, int yEnd, Color color) { Stroke stroke = getStroke(); if (stroke instanceof BasicStroke) { BasicStroke lineStroke = (BasicStroke) stroke; if (lineStroke.getDashArray() != null) { draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd)); return; } float lineWidth = lineStroke.getLineWidth(); Point2D.Float penSize = new Point2D.Float(lineWidth, lineWidth); AffineTransform deviceTransform = getTransform(); deviceTransform.deltaTransform(penSize, penSize); float deviceLineWidth = Math.min(Math.abs(penSize.x), Math.abs(penSize.y)); Point2D.Float begin_pos = new Point2D.Float(xBegin, yBegin); deviceTransform.transform(begin_pos, begin_pos); Point2D.Float end_pos = new Point2D.Float(xEnd, yEnd); deviceTransform.transform(end_pos, end_pos); int endCap = lineStroke.getEndCap(); int lineJoin = lineStroke.getLineJoin(); /* check if it's a one-pixel line */ if ((end_pos.getX() == begin_pos.getX()) && (end_pos.getY() == begin_pos.getY())) { /* endCap other than Round will not print! * due to Windows GDI limitation, force it to CAP_ROUND */ endCap = BasicStroke.CAP_ROUND; } WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob(); /* call native function that creates pen with style */ if (wPrinterJob.selectStylePen(endCap, lineJoin, deviceLineWidth, color)) { wPrinterJob.moveTo((float)begin_pos.getX(), (float)begin_pos.getY()); wPrinterJob.lineTo((float)end_pos.getX(), (float)end_pos.getY()); } /* selectStylePen is not supported, must be Win 9X */ else { /* let's see if we can use a a default pen * if it's round end (Windows' default style) * or it's vertical/horizontal * or stroke is too thin. */ double lowerRes = Math.min(wPrinterJob.getXRes(), wPrinterJob.getYRes()); if ((endCap == BasicStroke.CAP_ROUND) || (((xBegin == xEnd) || (yBegin == yEnd)) && (deviceLineWidth/lowerRes < MAX_THINLINE_INCHES))) { wPrinterJob.selectPen(deviceLineWidth, color); wPrinterJob.moveTo((float)begin_pos.getX(), (float)begin_pos.getY()); wPrinterJob.lineTo((float)end_pos.getX(), (float)end_pos.getY()); } else { draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd)); } } } }
Example 16
Source File: WPathGraphics.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Draw a line using a pen created using the specified color * and current stroke properties. */ @Override protected void deviceDrawLine(int xBegin, int yBegin, int xEnd, int yEnd, Color color) { Stroke stroke = getStroke(); if (stroke instanceof BasicStroke) { BasicStroke lineStroke = (BasicStroke) stroke; if (lineStroke.getDashArray() != null) { draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd)); return; } float lineWidth = lineStroke.getLineWidth(); Point2D.Float penSize = new Point2D.Float(lineWidth, lineWidth); AffineTransform deviceTransform = getTransform(); deviceTransform.deltaTransform(penSize, penSize); float deviceLineWidth = Math.min(Math.abs(penSize.x), Math.abs(penSize.y)); Point2D.Float begin_pos = new Point2D.Float(xBegin, yBegin); deviceTransform.transform(begin_pos, begin_pos); Point2D.Float end_pos = new Point2D.Float(xEnd, yEnd); deviceTransform.transform(end_pos, end_pos); int endCap = lineStroke.getEndCap(); int lineJoin = lineStroke.getLineJoin(); /* check if it's a one-pixel line */ if ((end_pos.getX() == begin_pos.getX()) && (end_pos.getY() == begin_pos.getY())) { /* endCap other than Round will not print! * due to Windows GDI limitation, force it to CAP_ROUND */ endCap = BasicStroke.CAP_ROUND; } WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob(); /* call native function that creates pen with style */ if (wPrinterJob.selectStylePen(endCap, lineJoin, deviceLineWidth, color)) { wPrinterJob.moveTo((float)begin_pos.getX(), (float)begin_pos.getY()); wPrinterJob.lineTo((float)end_pos.getX(), (float)end_pos.getY()); } /* selectStylePen is not supported, must be Win 9X */ else { /* let's see if we can use a a default pen * if it's round end (Windows' default style) * or it's vertical/horizontal * or stroke is too thin. */ double lowerRes = Math.min(wPrinterJob.getXRes(), wPrinterJob.getYRes()); if ((endCap == BasicStroke.CAP_ROUND) || (((xBegin == xEnd) || (yBegin == yEnd)) && (deviceLineWidth/lowerRes < MAX_THINLINE_INCHES))) { wPrinterJob.selectPen(deviceLineWidth, color); wPrinterJob.moveTo((float)begin_pos.getX(), (float)begin_pos.getY()); wPrinterJob.lineTo((float)end_pos.getX(), (float)end_pos.getY()); } else { draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd)); } } } }
Example 17
Source File: WPathGraphics.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Draw the bounding rectangle using transformed coordinates. */ @Override protected void deviceFrameRect(int x, int y, int width, int height, Color color) { 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) { draw(new Rectangle2D.Float(x, y, width, height)); return; } Stroke stroke = getStroke(); if (stroke instanceof BasicStroke) { BasicStroke lineStroke = (BasicStroke) stroke; int endCap = lineStroke.getEndCap(); int lineJoin = lineStroke.getLineJoin(); /* check for default style and try to optimize it by * calling the frameRect native function instead of using paths. */ if ((endCap == BasicStroke.CAP_SQUARE) && (lineJoin == BasicStroke.JOIN_MITER) && (lineStroke.getMiterLimit() ==10.0f)) { float lineWidth = lineStroke.getLineWidth(); Point2D.Float penSize = new Point2D.Float(lineWidth, lineWidth); deviceTransform.deltaTransform(penSize, penSize); float deviceLineWidth = Math.min(Math.abs(penSize.x), Math.abs(penSize.y)); /* transform upper left coordinate */ Point2D.Float ul_pos = new Point2D.Float(x, y); deviceTransform.transform(ul_pos, ul_pos); /* transform lower right coordinate */ Point2D.Float lr_pos = new Point2D.Float(x + width, y + height); deviceTransform.transform(lr_pos, lr_pos); float w = (float) (lr_pos.getX() - ul_pos.getX()); float h = (float)(lr_pos.getY() - ul_pos.getY()); WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob(); /* use selectStylePen, if supported */ if (wPrinterJob.selectStylePen(endCap, lineJoin, deviceLineWidth, color) == true) { wPrinterJob.frameRect((float)ul_pos.getX(), (float)ul_pos.getY(), w, h); } /* not supported, must be a Win 9x */ else { double lowerRes = Math.min(wPrinterJob.getXRes(), wPrinterJob.getYRes()); if ((deviceLineWidth/lowerRes) < MAX_THINLINE_INCHES) { /* use the default pen styles for thin pens. */ wPrinterJob.selectPen(deviceLineWidth, color); wPrinterJob.frameRect((float)ul_pos.getX(), (float)ul_pos.getY(), w, h); } else { draw(new Rectangle2D.Float(x, y, width, height)); } } } else { draw(new Rectangle2D.Float(x, y, width, height)); } } }
Example 18
Source File: WPathGraphics.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * Draw a line using a pen created using the specified color * and current stroke properties. */ @Override protected void deviceDrawLine(int xBegin, int yBegin, int xEnd, int yEnd, Color color) { Stroke stroke = getStroke(); if (stroke instanceof BasicStroke) { BasicStroke lineStroke = (BasicStroke) stroke; if (lineStroke.getDashArray() != null) { draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd)); return; } float lineWidth = lineStroke.getLineWidth(); Point2D.Float penSize = new Point2D.Float(lineWidth, lineWidth); AffineTransform deviceTransform = getTransform(); deviceTransform.deltaTransform(penSize, penSize); float deviceLineWidth = Math.min(Math.abs(penSize.x), Math.abs(penSize.y)); Point2D.Float begin_pos = new Point2D.Float(xBegin, yBegin); deviceTransform.transform(begin_pos, begin_pos); Point2D.Float end_pos = new Point2D.Float(xEnd, yEnd); deviceTransform.transform(end_pos, end_pos); int endCap = lineStroke.getEndCap(); int lineJoin = lineStroke.getLineJoin(); /* check if it's a one-pixel line */ if ((end_pos.getX() == begin_pos.getX()) && (end_pos.getY() == begin_pos.getY())) { /* endCap other than Round will not print! * due to Windows GDI limitation, force it to CAP_ROUND */ endCap = BasicStroke.CAP_ROUND; } WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob(); /* call native function that creates pen with style */ if (wPrinterJob.selectStylePen(endCap, lineJoin, deviceLineWidth, color)) { wPrinterJob.moveTo((float)begin_pos.getX(), (float)begin_pos.getY()); wPrinterJob.lineTo((float)end_pos.getX(), (float)end_pos.getY()); } /* selectStylePen is not supported, must be Win 9X */ else { /* let's see if we can use a a default pen * if it's round end (Windows' default style) * or it's vertical/horizontal * or stroke is too thin. */ double lowerRes = Math.min(wPrinterJob.getXRes(), wPrinterJob.getYRes()); if ((endCap == BasicStroke.CAP_ROUND) || (((xBegin == xEnd) || (yBegin == yEnd)) && (deviceLineWidth/lowerRes < MAX_THINLINE_INCHES))) { wPrinterJob.selectPen(deviceLineWidth, color); wPrinterJob.moveTo((float)begin_pos.getX(), (float)begin_pos.getY()); wPrinterJob.lineTo((float)end_pos.getX(), (float)end_pos.getY()); } else { draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd)); } } } }
Example 19
Source File: WPathGraphics.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * Draw a line using a pen created using the specified color * and current stroke properties. */ @Override protected void deviceDrawLine(int xBegin, int yBegin, int xEnd, int yEnd, Color color) { Stroke stroke = getStroke(); if (stroke instanceof BasicStroke) { BasicStroke lineStroke = (BasicStroke) stroke; if (lineStroke.getDashArray() != null) { draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd)); return; } float lineWidth = lineStroke.getLineWidth(); Point2D.Float penSize = new Point2D.Float(lineWidth, lineWidth); AffineTransform deviceTransform = getTransform(); deviceTransform.deltaTransform(penSize, penSize); float deviceLineWidth = Math.min(Math.abs(penSize.x), Math.abs(penSize.y)); Point2D.Float begin_pos = new Point2D.Float(xBegin, yBegin); deviceTransform.transform(begin_pos, begin_pos); Point2D.Float end_pos = new Point2D.Float(xEnd, yEnd); deviceTransform.transform(end_pos, end_pos); int endCap = lineStroke.getEndCap(); int lineJoin = lineStroke.getLineJoin(); /* check if it's a one-pixel line */ if ((end_pos.getX() == begin_pos.getX()) && (end_pos.getY() == begin_pos.getY())) { /* endCap other than Round will not print! * due to Windows GDI limitation, force it to CAP_ROUND */ endCap = BasicStroke.CAP_ROUND; } WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob(); /* call native function that creates pen with style */ if (wPrinterJob.selectStylePen(endCap, lineJoin, deviceLineWidth, color)) { wPrinterJob.moveTo((float)begin_pos.getX(), (float)begin_pos.getY()); wPrinterJob.lineTo((float)end_pos.getX(), (float)end_pos.getY()); } /* selectStylePen is not supported, must be Win 9X */ else { /* let's see if we can use a a default pen * if it's round end (Windows' default style) * or it's vertical/horizontal * or stroke is too thin. */ double lowerRes = Math.min(wPrinterJob.getXRes(), wPrinterJob.getYRes()); if ((endCap == BasicStroke.CAP_ROUND) || (((xBegin == xEnd) || (yBegin == yEnd)) && (deviceLineWidth/lowerRes < MAX_THINLINE_INCHES))) { wPrinterJob.selectPen(deviceLineWidth, color); wPrinterJob.moveTo((float)begin_pos.getX(), (float)begin_pos.getY()); wPrinterJob.lineTo((float)end_pos.getX(), (float)end_pos.getY()); } else { draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd)); } } } }
Example 20
Source File: WPathGraphics.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Draw a line using a pen created using the specified color * and current stroke properties. */ protected void deviceDrawLine(int xBegin, int yBegin, int xEnd, int yEnd, Color color) { Stroke stroke = getStroke(); if (stroke instanceof BasicStroke) { BasicStroke lineStroke = (BasicStroke) stroke; if (lineStroke.getDashArray() != null) { draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd)); return; } float lineWidth = lineStroke.getLineWidth(); Point2D.Float penSize = new Point2D.Float(lineWidth, lineWidth); AffineTransform deviceTransform = getTransform(); deviceTransform.deltaTransform(penSize, penSize); float deviceLineWidth = Math.min(Math.abs(penSize.x), Math.abs(penSize.y)); Point2D.Float begin_pos = new Point2D.Float(xBegin, yBegin); deviceTransform.transform(begin_pos, begin_pos); Point2D.Float end_pos = new Point2D.Float(xEnd, yEnd); deviceTransform.transform(end_pos, end_pos); int endCap = lineStroke.getEndCap(); int lineJoin = lineStroke.getLineJoin(); /* check if it's a one-pixel line */ if ((end_pos.getX() == begin_pos.getX()) && (end_pos.getY() == begin_pos.getY())) { /* endCap other than Round will not print! * due to Windows GDI limitation, force it to CAP_ROUND */ endCap = BasicStroke.CAP_ROUND; } WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob(); /* call native function that creates pen with style */ if (wPrinterJob.selectStylePen(endCap, lineJoin, deviceLineWidth, color)) { wPrinterJob.moveTo((float)begin_pos.getX(), (float)begin_pos.getY()); wPrinterJob.lineTo((float)end_pos.getX(), (float)end_pos.getY()); } /* selectStylePen is not supported, must be Win 9X */ else { /* let's see if we can use a a default pen * if it's round end (Windows' default style) * or it's vertical/horizontal * or stroke is too thin. */ double lowerRes = Math.min(wPrinterJob.getXRes(), wPrinterJob.getYRes()); if ((endCap == BasicStroke.CAP_ROUND) || (((xBegin == xEnd) || (yBegin == yEnd)) && (deviceLineWidth/lowerRes < MAX_THINLINE_INCHES))) { wPrinterJob.selectPen(deviceLineWidth, color); wPrinterJob.moveTo((float)begin_pos.getX(), (float)begin_pos.getY()); wPrinterJob.lineTo((float)end_pos.getX(), (float)end_pos.getY()); } else { draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd)); } } } }