import java.util.ArrayList;
import java.util.List;
import java.awt.geom.Rectangle2D;
+import java.awt.geom.AffineTransform;
import java.awt.*;
/**
spgr.setRectY2((anchor.y + anchor.height)*MASTER_DPI/POINT_DPI);
}
+ /**
+ * Sets the coordinate space of this group. All children are constrained
+ * to these coordinates.
+ *
+ * @param anchor the coordinate space of this group
+ */
+ public void setCoordinates(Rectangle2D anchor){
+ EscherContainerRecord spContainer = (EscherContainerRecord)_escherContainer.getChildRecords().get(0);
+ EscherSpgrRecord spgr = (EscherSpgrRecord)getEscherChild(spContainer, EscherSpgrRecord.RECORD_ID);
+
+ int x1 = (int)Math.round(anchor.getX()*MASTER_DPI/POINT_DPI);
+ int y1 = (int)Math.round(anchor.getY()*MASTER_DPI/POINT_DPI);
+ int x2 = (int)Math.round((anchor.getX() + anchor.getWidth())*MASTER_DPI/POINT_DPI);
+ int y2 = (int)Math.round((anchor.getY() + anchor.getHeight())*MASTER_DPI/POINT_DPI);
+
+ spgr.setRectX1(x1);
+ spgr.setRectY1(y1);
+ spgr.setRectX2(x2);
+ spgr.setRectY2(y2);
+
+ }
+
+ /**
+ * Gets the coordinate space of this group. All children are constrained
+ * to these coordinates.
+ *
+ * @return the coordinate space of this group
+ */
+ public Rectangle2D getCoordinates(){
+ EscherContainerRecord spContainer = (EscherContainerRecord)_escherContainer.getChildRecords().get(0);
+ EscherSpgrRecord spgr = (EscherSpgrRecord)getEscherChild(spContainer, EscherSpgrRecord.RECORD_ID);
+
+ Rectangle2D.Float anchor = new Rectangle2D.Float();
+ anchor.x = (float)spgr.getRectX1()*POINT_DPI/MASTER_DPI;
+ anchor.y = (float)spgr.getRectY1()*POINT_DPI/MASTER_DPI;
+ anchor.width = (float)(spgr.getRectX2() - spgr.getRectX1())*POINT_DPI/MASTER_DPI;
+ anchor.height = (float)(spgr.getRectY2() - spgr.getRectY1())*POINT_DPI/MASTER_DPI;
+
+ return anchor;
+ }
+
/**
* Create a new ShapeGroup and create an instance of <code>EscherSpgrContainer</code> which represents a group of shapes
*/
* @return the anchor of this shape group
*/
public Rectangle2D getAnchor2D(){
- EscherContainerRecord groupInfoContainer = (EscherContainerRecord)_escherContainer.getChild(0);
- EscherSpgrRecord spgr = (EscherSpgrRecord)getEscherChild(groupInfoContainer, EscherSpgrRecord.RECORD_ID);
- Rectangle2D anchor = new Rectangle2D.Float(
- (float)spgr.getRectX1()*POINT_DPI/MASTER_DPI,
- (float)spgr.getRectY1()*POINT_DPI/MASTER_DPI,
- (float)(spgr.getRectX2() - spgr.getRectX1())*POINT_DPI/MASTER_DPI,
- (float)(spgr.getRectY2() - spgr.getRectY1())*POINT_DPI/MASTER_DPI
- );
+ EscherContainerRecord spContainer = (EscherContainerRecord)_escherContainer.getChildRecords().get(0);
+ EscherClientAnchorRecord clientAnchor = (EscherClientAnchorRecord)getEscherChild(spContainer, EscherClientAnchorRecord.RECORD_ID);
+ Rectangle2D.Float anchor = new Rectangle2D.Float();
+ anchor.x = (float)clientAnchor.getCol1()*POINT_DPI/MASTER_DPI;
+ anchor.y = (float)clientAnchor.getFlag()*POINT_DPI/MASTER_DPI;
+ anchor.width = (float)(clientAnchor.getDx1() - clientAnchor.getCol1())*POINT_DPI/MASTER_DPI ;
+ anchor.height = (float)(clientAnchor.getRow1() - clientAnchor.getFlag())*POINT_DPI/MASTER_DPI;
return anchor;
}
}
public void draw(Graphics2D graphics){
+ Rectangle2D anchor = getAnchor2D();
+ Rectangle2D coords = getCoordinates();
+
+ //transform coordinates
+ AffineTransform at = graphics.getTransform();
+
+ if(!anchor.equals(coords)){
+ graphics.scale(coords.getWidth()/anchor.getWidth(), coords.getHeight()/anchor.getHeight());
+
+ graphics.translate(
+ 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);
}
+
+ graphics.setTransform(at);
}
}
while (measurer.getPosition() < paragraphEnd) {\r
int startIndex = measurer.getPosition();\r
int nextBreak = text.indexOf('\n', measurer.getPosition() + 1);\r
- RichTextRun rt = getRichTextRunAt(startIndex + 1);\r
+\r
+ int rtIdx = startIndex == 0 ? 0 : startIndex + 1;\r
+ if(startIndex == 0 || startIndex == text.length() - 1) rtIdx = startIndex;\r
+ else rtIdx = startIndex + 1;\r
+\r
+ RichTextRun rt = getRichTextRunAt(rtIdx);\r
if(rt == null) {\r
logger.log(POILogger.WARN, "RichTextRun not found at pos" + (startIndex + 1) + "; text.length: " + text.length());\r
break;\r
}\r
}\r
\r
- textHeight += textLayout.getAscent() + textLayout.getLeading();\r
+ textHeight += textLayout.getAscent() + textLayout.getDescent();\r
\r
int lineSpacing = rt.getLineSpacing();\r
- if(lineSpacing != 0) el._spacing = textLayout.getDescent()*lineSpacing/100;\r
- else el._spacing = textLayout.getDescent();\r
+ if(lineSpacing != 0) el._spacing = textLayout.getLeading()*lineSpacing/100;\r
+ else el._spacing = textLayout.getLeading();\r
\r
textHeight += el._spacing;\r
\r