\r
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);\r
Graphics2D graphics = img.createGraphics();\r
+ graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);\r
+ graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);\r
+ graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);\r
+ graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);\r
+\r
graphics.setPaint(Color.white);\r
graphics.fill(new Rectangle2D.Float(0, 0, width, height));\r
\r
public java.awt.Shape getOutline(){
ShapeOutline outline = AutoShapes.getShapeOutline(getShapeType());
- Rectangle2D anchor = getAnchor2D();
+ Rectangle2D anchor = getLogicalAnchor2D();
if(outline == null){
- logger.log(POILogger.WARN, "getOutline() is not implemented for " + ShapeTypes.typeName(getShapeType()));
+ logger.log(POILogger.WARN, "Outline not found for " + ShapeTypes.typeName(getShapeType()));
return anchor;
} else {
java.awt.Shape shape = outline.getOutline(this);
return path;\r
}\r
};\r
- }\r
\r
+ shapes[ShapeTypes.Can] = new ShapeOutline(){\r
+ public java.awt.Shape getOutline(Shape shape){\r
+ //m10800,qx0@1l0@2qy10800,21600,21600@2l21600@1qy10800,xem0@1qy10800@0,21600@1nfe\r
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);\r
+\r
+ GeneralPath path = new GeneralPath();\r
+\r
+ path.append(new Arc2D.Float(0, 0, 21600, adjval, 0, 180, Arc2D.OPEN), false);\r
+ path.moveTo(0, adjval/2);\r
+\r
+ path.lineTo(0, 21600 - adjval/2);\r
+ path.closePath();\r
+\r
+ path.append(new Arc2D.Float(0, 21600 - adjval, 21600, adjval, 180, 180, Arc2D.OPEN), false);\r
+ path.moveTo(21600, 21600 - adjval/2);\r
+\r
+ path.lineTo(21600, adjval/2);\r
+ path.append(new Arc2D.Float(0, 0, 21600, adjval, 180, 180, Arc2D.OPEN), false);\r
+ path.moveTo(0, adjval/2);\r
+ path.closePath();\r
+ return path;\r
+ }\r
+ };\r
+\r
+ shapes[ShapeTypes.LeftBrace] = new ShapeOutline(){\r
+ public java.awt.Shape getOutline(Shape shape){\r
+ //m21600,qx10800@0l10800@2qy0@11,10800@3l10800@1qy21600,21600e\r
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 1800);\r
+ int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 10800);\r
+\r
+ GeneralPath path = new GeneralPath();\r
+ path.moveTo(21600, 0);\r
+\r
+ path.append(new Arc2D.Float(10800, 0, 21600, adjval*2, 90, 90, Arc2D.OPEN), false);\r
+ path.moveTo(10800, adjval);\r
+\r
+ path.lineTo(10800, adjval2 - adjval);\r
+\r
+ path.append(new Arc2D.Float(-10800, adjval2 - 2*adjval, 21600, adjval*2, 270, 90, Arc2D.OPEN), false);\r
+ path.moveTo(0, adjval2);\r
+\r
+ path.append(new Arc2D.Float(-10800, adjval2, 21600, adjval*2, 0, 90, Arc2D.OPEN), false);\r
+ path.moveTo(10800, adjval2 + adjval);\r
+\r
+ path.lineTo(10800, 21600 - adjval);\r
+\r
+ path.append(new Arc2D.Float(10800, 21600 - 2*adjval, 21600, adjval*2, 180, 90, Arc2D.OPEN), false);\r
+\r
+ return path;\r
+ }\r
+ };\r
+\r
+ shapes[ShapeTypes.RightBrace] = new ShapeOutline(){\r
+ public java.awt.Shape getOutline(Shape shape){\r
+ //m,qx10800@0 l10800@2qy21600@11,10800@3l10800@1qy,21600e\r
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 1800);\r
+ int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 10800);\r
+\r
+ GeneralPath path = new GeneralPath();\r
+ path.moveTo(0, 0);\r
+\r
+ path.append(new Arc2D.Float(-10800, 0, 21600, adjval*2, 0, 90, Arc2D.OPEN), false);\r
+ path.moveTo(10800, adjval);\r
+\r
+ path.lineTo(10800, adjval2 - adjval);\r
+\r
+ path.append(new Arc2D.Float(10800, adjval2 - 2*adjval, 21600, adjval*2, 180, 90, Arc2D.OPEN), false);\r
+ path.moveTo(21600, adjval2);\r
+\r
+ path.append(new Arc2D.Float(10800, adjval2, 21600, adjval*2, 90, 90, Arc2D.OPEN), false);\r
+ path.moveTo(10800, adjval2 + adjval);\r
+\r
+ path.lineTo(10800, 21600 - adjval);\r
+\r
+ path.append(new Arc2D.Float(-10800, 21600 - 2*adjval, 21600, adjval*2, 270, 90, Arc2D.OPEN), false);\r
+\r
+ return path;\r
+ }\r
+ };\r
+\r
+ }\r
}\r
}
public java.awt.Shape getOutline(){
- Rectangle2D anchor = getAnchor2D();
+ Rectangle2D anchor = getLogicalAnchor2D();
return new Line2D.Double(anchor.getX(), anchor.getY(), anchor.getX() + anchor.getWidth(), anchor.getY() + anchor.getHeight());
}
}
return anchor;
}
+ public Rectangle2D getLogicalAnchor2D(){
+ return getAnchor2D();
+ }
+
/**
* Sets the anchor (the bounding box rectangle) of this shape.
* All coordinates should be expressed in points (72 dpi).
* @return the shape outline
*/
public java.awt.Shape getOutline(){
- return getAnchor2D();
+ return getLogicalAnchor2D();
}
}
EscherClientAnchorRecord clientAnchor = (EscherClientAnchorRecord)getEscherChild(spContainer, EscherClientAnchorRecord.RECORD_ID);
Rectangle2D.Float anchor = new Rectangle2D.Float();
if(clientAnchor == null){
- logger.log(POILogger.WARN, "EscherClientAnchorRecord was not found for the shape group");
+ logger.log(POILogger.INFO, "EscherClientAnchorRecord was not found for shape group. Searching for EscherChildAnchorRecord.");
EscherChildAnchorRecord rec = (EscherChildAnchorRecord)getEscherChild(spContainer, EscherChildAnchorRecord.RECORD_ID);
anchor = new Rectangle2D.Float(
(float)rec.getDx1()*POINT_DPI/MASTER_DPI,
//transform coordinates
AffineTransform at = graphics.getTransform();
-
+ /*
if(!anchor.equals(coords)){
graphics.scale(anchor.getWidth()/coords.getWidth(), anchor.getHeight()/coords.getHeight());
anchor.getX()*coords.getWidth()/anchor.getWidth() - coords.getX(),
anchor.getY()*coords.getHeight()/anchor.getHeight() - coords.getY());
}
-
+ */
Shape[] sh = getShapes();
for (int i = 0; i < sh.length; i++) {
sh[i].draw(graphics);
protected static POILogger logger = POILogFactory.getLogger(ShapePainter.class);\r
\r
public static void paint(SimpleShape shape, Graphics2D graphics){\r
- Rectangle2D anchor = shape.getAnchor2D();\r
+ Rectangle2D anchor = shape.getLogicalAnchor2D();\r
java.awt.Shape outline = shape.getOutline();\r
\r
//flip vertical\r
import java.awt.*;
import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
/**
* An abstract simple (non-group) shape.
return angle;
}
+ public Rectangle2D getLogicalAnchor2D(){
+ Rectangle2D anchor = getAnchor2D();
+
+ //if it is a groupped shape see if we need to transform the coordinates
+ if (_parent != null){
+ Shape top = _parent;
+ while(top.getParent() != null) top = top.getParent();
+
+ Rectangle2D clientAnchor = top.getAnchor2D();
+ Rectangle2D spgrAnchor = ((ShapeGroup)top).getCoordinates();
+
+ double scalex = (double)spgrAnchor.getWidth()/clientAnchor.getWidth();
+ double scaley = (double)spgrAnchor.getHeight()/clientAnchor.getHeight();
+
+ double x = clientAnchor.getX() + (anchor.getX() - spgrAnchor.getX())/scalex;
+ double y = clientAnchor.getY() + (anchor.getY() - spgrAnchor.getY())/scaley;
+ double width = anchor.getWidth()/scalex;
+ double height = anchor.getHeight()/scaley;
+
+ anchor = new Rectangle2D.Double(x, y, width, height);
+
+ }
+
+ int angle = getRotation();
+ if(angle != 0){
+ double centerX = anchor.getX() + anchor.getWidth()/2;
+ double centerY = anchor.getY() + anchor.getHeight()/2;
+
+ AffineTransform trans = new AffineTransform();
+ trans.translate(centerX, centerY);
+ trans.rotate(Math.toRadians(angle));
+ trans.translate(-centerX, -centerY);
+
+ Rectangle2D rect = trans.createTransformedShape(anchor).getBounds2D();
+ if((anchor.getWidth() < anchor.getHeight() && rect.getWidth() > rect.getHeight()) ||
+ (anchor.getWidth() > anchor.getHeight() && rect.getWidth() < rect.getHeight()) ){
+ trans = new AffineTransform();
+ trans.translate(centerX, centerY);
+ trans.rotate(Math.PI/2);
+ trans.translate(-centerX, -centerY);
+ anchor = trans.createTransformedShape(anchor).getBounds2D();
+ }
+ }
+ return anchor;
+ }
+
public void draw(Graphics2D graphics){
AffineTransform at = graphics.getTransform();
ShapePainter.paint(this, graphics);
for (int i = 0; i < rt.length; i++) {\r
int start = rt[i].getStartIndex();\r
int end = rt[i].getEndIndex();\r
- if(start == end) continue;\r
+ if(start == end) {\r
+ logger.log(POILogger.INFO, "Skipping RichTextRun with zero length");\r
+ continue;\r
+ }\r
\r
at.addAttribute(TextAttribute.FAMILY, rt[i].getFontName(), start, end);\r
at.addAttribute(TextAttribute.SIZE, new Float(rt[i].getFontSize()), start, end);\r
int paragraphStart = it.getBeginIndex();\r
int paragraphEnd = it.getEndIndex();\r
\r
- Rectangle2D anchor = _shape.getAnchor2D();\r
+ Rectangle2D anchor = _shape.getLogicalAnchor2D();\r
\r
float textHeight = 0;\r
ArrayList lines = new ArrayList();\r
TextLayout textLayout = measurer.nextLayout(wrappingWidth + 1,\r
nextBreak == -1 ? paragraphEnd : nextBreak, true);\r
if (textLayout == null) {\r
- textLayout = measurer.nextLayout(wrappingWidth,\r
+ textLayout = measurer.nextLayout((float)anchor.getWidth(),\r
nextBreak == -1 ? paragraphEnd : nextBreak, false);\r
}\r
if(textLayout == null){\r
if(rt.isBullet() && (prStart || startIndex == 0)){\r
it.setIndex(startIndex);\r
\r
- AttributedString bat = new AttributedString(Character.toString(rt.getBulletChar()), it.getAttributes());\r
+ AttributedString bat = new AttributedString(Character.toString(rt.getBulletChar()));\r
Color clr = rt.getBulletColor();\r
if (clr != null) bat.addAttribute(TextAttribute.FOREGROUND, clr);\r
+ else bat.addAttribute(TextAttribute.FOREGROUND, it.getAttribute(TextAttribute.FOREGROUND));\r
+ bat.addAttribute(TextAttribute.FAMILY, it.getAttribute(TextAttribute.FAMILY));\r
+ bat.addAttribute(TextAttribute.SIZE, it.getAttribute(TextAttribute.SIZE));\r
\r
TextLayout bulletLayout = new TextLayout(bat.getIterator(), graphics.getFontRenderContext());\r
if(text.substring(startIndex, endIndex).length() > 1){\r