use of java.awt.geom.AffineTransform in project poi by apache.
the class XSLFFreeformShape method setPath.
@Override
public int setPath(Path2D.Double path) {
CTPath2D ctPath = CTPath2D.Factory.newInstance();
Rectangle2D bounds = path.getBounds2D();
int x0 = Units.toEMU(bounds.getX());
int y0 = Units.toEMU(bounds.getY());
PathIterator it = path.getPathIterator(new AffineTransform());
int numPoints = 0;
ctPath.setH(Units.toEMU(bounds.getHeight()));
ctPath.setW(Units.toEMU(bounds.getWidth()));
while (!it.isDone()) {
double[] vals = new double[6];
int type = it.currentSegment(vals);
switch(type) {
case PathIterator.SEG_MOVETO:
CTAdjPoint2D mv = ctPath.addNewMoveTo().addNewPt();
mv.setX(Units.toEMU(vals[0]) - x0);
mv.setY(Units.toEMU(vals[1]) - y0);
numPoints++;
break;
case PathIterator.SEG_LINETO:
CTAdjPoint2D ln = ctPath.addNewLnTo().addNewPt();
ln.setX(Units.toEMU(vals[0]) - x0);
ln.setY(Units.toEMU(vals[1]) - y0);
numPoints++;
break;
case PathIterator.SEG_QUADTO:
CTPath2DQuadBezierTo qbez = ctPath.addNewQuadBezTo();
CTAdjPoint2D qp1 = qbez.addNewPt();
qp1.setX(Units.toEMU(vals[0]) - x0);
qp1.setY(Units.toEMU(vals[1]) - y0);
CTAdjPoint2D qp2 = qbez.addNewPt();
qp2.setX(Units.toEMU(vals[2]) - x0);
qp2.setY(Units.toEMU(vals[3]) - y0);
numPoints += 2;
break;
case PathIterator.SEG_CUBICTO:
CTPath2DCubicBezierTo bez = ctPath.addNewCubicBezTo();
CTAdjPoint2D p1 = bez.addNewPt();
p1.setX(Units.toEMU(vals[0]) - x0);
p1.setY(Units.toEMU(vals[1]) - y0);
CTAdjPoint2D p2 = bez.addNewPt();
p2.setX(Units.toEMU(vals[2]) - x0);
p2.setY(Units.toEMU(vals[3]) - y0);
CTAdjPoint2D p3 = bez.addNewPt();
p3.setX(Units.toEMU(vals[4]) - x0);
p3.setY(Units.toEMU(vals[5]) - y0);
numPoints += 3;
break;
case PathIterator.SEG_CLOSE:
numPoints++;
ctPath.addNewClose();
break;
default:
throw new IllegalStateException("Unrecognized path segment type: " + type);
}
it.next();
}
XmlObject xo = getShapeProperties();
if (!(xo instanceof CTShapeProperties)) {
return -1;
}
((CTShapeProperties) xo).getCustGeom().getPathLst().setPathArray(new CTPath2D[] { ctPath });
setAnchor(bounds);
return numPoints;
}
use of java.awt.geom.AffineTransform in project intellij-community by JetBrains.
the class DiffLineSeparatorRenderer method paintLine.
private static void paintLine(@NotNull Graphics g, @NotNull int[] xPoints, @NotNull int[] yPoints, int lineHeight, @Nullable EditorColorsScheme scheme) {
int height = getHeight(lineHeight);
if (scheme == null)
scheme = EditorColorsManager.getInstance().getGlobalScheme();
Graphics2D gg = ((Graphics2D) g);
AffineTransform oldTransform = gg.getTransform();
for (int i = 0; i < height; i++) {
Color color = getTopBorderColor(i, lineHeight, scheme);
if (color == null)
color = getBottomBorderColor(i, lineHeight, scheme);
if (color == null)
color = getBackgroundColor(scheme);
gg.setColor(color);
gg.drawPolyline(xPoints, yPoints, xPoints.length);
gg.translate(0, 1);
}
gg.setTransform(oldTransform);
}
use of java.awt.geom.AffineTransform in project poi by apache.
the class HwmfPicture method draw.
public void draw(Graphics2D ctx, Rectangle2D graphicsBounds) {
AffineTransform at = ctx.getTransform();
try {
Rectangle2D wmfBounds = getBounds();
// scale output bounds to image bounds
ctx.translate(graphicsBounds.getX(), graphicsBounds.getY());
ctx.scale(graphicsBounds.getWidth() / wmfBounds.getWidth(), graphicsBounds.getHeight() / wmfBounds.getHeight());
HwmfGraphics g = new HwmfGraphics(ctx, wmfBounds);
for (HwmfRecord r : records) {
r.draw(g);
}
} finally {
ctx.setTransform(at);
}
}
use of java.awt.geom.AffineTransform in project poi by apache.
the class HwmfGraphics method drawString.
public void drawString(byte[] text, Rectangle2D bounds, int[] dx) {
HwmfFont font = prop.getFont();
if (font == null || text == null || text.length == 0) {
return;
}
double fontH = getFontHeight(font);
// TODO: another approx. ...
double fontW = fontH / 1.8;
int len = text.length;
Charset charset = (font.getCharSet().getCharset() == null) ? DEFAULT_CHARSET : font.getCharSet().getCharset();
String textString = new String(text, charset);
AttributedString as = new AttributedString(textString);
if (dx == null || dx.length == 0) {
addAttributes(as, font);
} else {
int[] dxNormed = dx;
//dxNormed[1] = 14 textString.get(1) = U+30ED
if (textString.length() != text.length) {
int codePoints = textString.codePointCount(0, textString.length());
dxNormed = new int[codePoints];
int dxPosition = 0;
for (int offset = 0; offset < textString.length(); ) {
dxNormed[offset] = dx[dxPosition];
int[] chars = new int[1];
int cp = textString.codePointAt(offset);
chars[0] = cp;
//now figure out how many bytes it takes to encode that
//code point in the charset
int byteLength = new String(chars, 0, chars.length).getBytes(charset).length;
dxPosition += byteLength;
offset += Character.charCount(cp);
}
}
for (int i = 0; i < dxNormed.length; i++) {
addAttributes(as, font);
// therefore we need to add the additional/suffix width to the next char
if (i < dxNormed.length - 1) {
as.addAttribute(TextAttribute.TRACKING, (dxNormed[i] - fontW) / fontH, i + 1, i + 2);
}
}
}
double angle = Math.toRadians(-font.getEscapement() / 10.);
final AffineTransform at = graphicsCtx.getTransform();
try {
graphicsCtx.translate(bounds.getX(), bounds.getY() + fontH);
graphicsCtx.rotate(angle);
if (prop.getBkMode() == HwmfBkMode.OPAQUE) {
// TODO: validate bounds
graphicsCtx.setBackground(prop.getBackgroundColor().getColor());
graphicsCtx.fill(new Rectangle2D.Double(0, 0, bounds.getWidth(), bounds.getHeight()));
}
graphicsCtx.setColor(prop.getTextColor().getColor());
// (float)bounds.getX(), (float)bounds.getY());
graphicsCtx.drawString(as.getIterator(), 0, 0);
} finally {
graphicsCtx.setTransform(at);
}
}
use of java.awt.geom.AffineTransform in project limelight by slagyr.
the class ImagePanelLayoutTest method hasConstrainedProportionsWhenHeightIsNotAuto.
@Test
public void hasConstrainedProportionsWhenHeightIsNotAuto() throws Exception {
panel.setFilename(TestUtil.DATA_DIR + "/star.gif");
parent.style.setHeight("100");
parent.childConsumableBounds = new Box(0, 0, 200, 100);
Layouts.on(parent, parent.getDefaultLayout());
AffineTransform tranform = panel.getTransform();
assertEquals(0.5, tranform.getScaleX(), 0.001);
assertEquals(0.5, tranform.getScaleY(), 0.001);
}
Aggregations