Return-Path: X-Original-To: apmail-poi-commits-archive@minotaur.apache.org Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 35A2E18688 for ; Mon, 19 Oct 2015 05:59:54 +0000 (UTC) Received: (qmail 95181 invoked by uid 500); 19 Oct 2015 05:59:54 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 95148 invoked by uid 500); 19 Oct 2015 05:59:54 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 95139 invoked by uid 99); 19 Oct 2015 05:59:54 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Oct 2015 05:59:53 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 6DA5F1A2C64 for ; Mon, 19 Oct 2015 05:59:53 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.791 X-Spam-Level: * X-Spam-Status: No, score=1.791 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id uel3YuYI7u7Y for ; Mon, 19 Oct 2015 05:59:41 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id C2AC02045A for ; Mon, 19 Oct 2015 05:59:40 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 34800E046C for ; Mon, 19 Oct 2015 05:59:40 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 9EC3A3A098C for ; Mon, 19 Oct 2015 05:59:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1709355 [2/4] - in /poi/trunk/src/ooxml: java/org/apache/poi/xdgf/exceptions/ java/org/apache/poi/xdgf/geom/ java/org/apache/poi/xdgf/usermodel/ java/org/apache/poi/xdgf/usermodel/section/ java/org/apache/poi/xdgf/usermodel/section/geometr... Date: Mon, 19 Oct 2015 05:59:38 -0000 To: commits@poi.apache.org From: virtuald@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20151019055939.9EC3A3A098C@svn01-us-west.apache.org> Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFShape.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFShape.java?rev=1709355&r1=1709354&r2=1709355&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFShape.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFShape.java Mon Oct 19 05:59:37 2015 @@ -41,903 +41,906 @@ import com.microsoft.schemas.office.visi import com.microsoft.schemas.office.visio.x2012.main.TextType; /** - * A shape is a collection of Geometry Visualization, Format, Text, Images, - * and Shape Data in a Drawing Page. + * A shape is a collection of Geometry Visualization, Format, Text, Images, and + * Shape Data in a Drawing Page. */ public class XDGFShape extends XDGFSheet { - XDGFBaseContents _parentPage; - XDGFShape _parent; // only non-null if a subshape - - XDGFMaster _master = null; - XDGFShape _masterShape = null; - - XDGFText _text = null; - - // subshapes if they exist - List _shapes = null; - - // properties specific to shapes - - // center of rotation relative to origin of parent - Double _pinX = null; - Double _pinY = null; - - Double _width = null; - Double _height = null; - - // center of rotation relative to self - Double _locPinX = null; - Double _locPinY = null; - - // start x coordinate, relative to parent - // -> one dimensional shapes only - Double _beginX = null; - Double _beginY = null; - - // end x coordinate, relative to parent - // -> one dimensional shapes only - Double _endX = null; - Double _endY = null; - - Double _angle = null; - Double _rotationXAngle = null; - Double _rotationYAngle = null; - Double _rotationZAngle = null; - - // end x coordinate, relative to parent - Boolean _flipX = null; - Boolean _flipY = null; - - // center of text relative to this shape - Double _txtPinX = null; - Double _txtPinY = null; - - // center of text relative to text block - Double _txtLocPinX = null; - Double _txtLocPinY = null; - - Double _txtAngle = null; - - Double _txtWidth = null; - Double _txtHeight = null; - - public XDGFShape(ShapeSheetType shapeSheet, XDGFBaseContents parentPage, XDGFDocument document) { - this(null, shapeSheet, parentPage, document); - } - - public XDGFShape(XDGFShape parent, ShapeSheetType shapeSheet, XDGFBaseContents parentPage, XDGFDocument document) { - - super(shapeSheet, document); - - _parent = parent; - _parentPage = parentPage; - - TextType text = shapeSheet.getText(); - if (text != null) - _text = new XDGFText(text, this); - - if (shapeSheet.isSetShapes()) { - _shapes = new ArrayList(); - for (ShapeSheetType shape: shapeSheet.getShapes().getShapeArray()) - _shapes.add(new XDGFShape(this, shape, parentPage, document)); - } - - readProperties(); - } - - @Override - public String toString() { - if (_parentPage instanceof XDGFMasterContents) - return _parentPage + ": "; - else - return ""; - } - - protected void readProperties() { - - _pinX = XDGFCell.maybeGetDouble(_cells, "PinX"); - _pinY = XDGFCell.maybeGetDouble(_cells, "PinY"); - _width = XDGFCell.maybeGetDouble(_cells, "Width"); - _height = XDGFCell.maybeGetDouble(_cells, "Height"); - _locPinX = XDGFCell.maybeGetDouble(_cells, "LocPinX"); - _locPinY = XDGFCell.maybeGetDouble(_cells, "LocPinY"); - _beginX = XDGFCell.maybeGetDouble(_cells, "BeginX"); - _beginY = XDGFCell.maybeGetDouble(_cells, "BeginY"); - _endX = XDGFCell.maybeGetDouble(_cells, "EndX"); - _endY = XDGFCell.maybeGetDouble(_cells, "EndY"); - - _angle = XDGFCell.maybeGetDouble(_cells, "Angle"); - _rotationXAngle = XDGFCell.maybeGetDouble(_cells, "RotationXAngle"); - _rotationYAngle = XDGFCell.maybeGetDouble(_cells, "RotationYAngle"); - _rotationZAngle = XDGFCell.maybeGetDouble(_cells, "RotationZAngle"); - - _flipX = XDGFCell.maybeGetBoolean(_cells, "FlipX"); - _flipY = XDGFCell.maybeGetBoolean(_cells, "FlipY"); - - _txtPinX = XDGFCell.maybeGetDouble(_cells, "TxtPinX"); - _txtPinY = XDGFCell.maybeGetDouble(_cells, "TxtPinY"); - _txtLocPinX = XDGFCell.maybeGetDouble(_cells, "TxtLocPinX"); - _txtLocPinY = XDGFCell.maybeGetDouble(_cells, "TxtLocPinY"); - _txtWidth = XDGFCell.maybeGetDouble(_cells, "TxtWidth"); - _txtHeight = XDGFCell.maybeGetDouble(_cells, "TxtHeight"); - - _txtAngle = XDGFCell.maybeGetDouble(_cells, "TxtAngle"); - } - - /** - * Setup top level shapes - * - * Shapes that have a 'Master' attribute refer to a specific master in - * the page, whereas shapes with a 'MasterShape' attribute refer to a - * subshape of a Master. - * - * - */ - protected void setupMaster(XDGFPageContents pageContents, XDGFMasterContents master) { - - ShapeSheetType obj = getXmlObject(); - - if (obj.isSetMaster()) { - _master = pageContents.getMasterById(obj.getMaster()); - if (_master == null) - throw XDGFException.error("refers to non-existant master " + obj.getMaster(), - this); - - /* - * If a master has one top-level shape, a shape that inherits from - * that master inherits the descendant elements of that master - * shape. If a master has more than one master shape, a shape that - * inherits from that master inherits those master shapes as - * subshapes. - */ - - Collection masterShapes = _master.getContent().getTopLevelShapes(); - - switch (masterShapes.size()) { - case 0: - throw XDGFException.error("Could not retrieve master shape from " + _master, this); - case 1: - _masterShape = masterShapes.iterator().next(); - break; - default: - break; - } - - } else if (obj.isSetMasterShape()) { - _masterShape = master.getShapeById(obj.getMasterShape()); - if (_masterShape == null) - throw XDGFException.error("refers to non-existant master shape " + obj.getMasterShape(), - this); - - } - - setupSectionMasters(); - - if (_shapes != null) { - for (XDGFShape shape: _shapes) { - shape.setupMaster(pageContents, - _master == null ? master : _master.getContent()); - } - } - } - - protected void setupSectionMasters() { - - if (_masterShape == null) - return; - - try { - for (Entry section: _sections.entrySet()) { - XDGFSection master = _masterShape.getSection(section.getKey()); - if (master != null) - section.getValue().setupMaster(master); - } - - for (Entry section: _geometry.entrySet()) { - GeometrySection master = _masterShape.getGeometryByIdx(section.getKey()); - if (master != null) - section.getValue().setupMaster(master); - } - } catch (POIXMLException e) { - throw XDGFException.wrap(this.toString(), e); - } - } - - @Internal - public ShapeSheetType getXmlObject() { - return (ShapeSheetType)_sheet; - } - - public long getID() { - return getXmlObject().getID(); - } - - public String getType() { - return getXmlObject().getType(); - } - - public String getTextAsString() { - XDGFText text = getText(); - if (text == null) - return ""; - - return text.getTextContent(); - } - - public boolean hasText() { - return _text != null || (_masterShape != null && _masterShape._text != null); - } - - @Override - public XDGFCell getCell(String cellName) { - XDGFCell _cell = super.getCell(cellName); - - // if not found, ask the master - if (_cell == null && _masterShape != null) { - _cell = _masterShape.getCell(cellName); - } - - return _cell; - } - - public GeometrySection getGeometryByIdx(long idx) { - return _geometry.get(idx); - } - - // only available if this is a shape group - // -> May be null - public List getShapes() { - return _shapes; - } - - // unique to this shape on the page? - public String getName() { - String name = getXmlObject().getName(); - if (name == null) - return ""; - return name; - } - - // unique to this shape on the page? - public String getShapeType() { - String type = getXmlObject().getType(); - if (type == null) - return ""; - return type; - } - - // name of the symbol that this was derived from - public String getSymbolName() { - - if (_master == null) - return ""; - - String name = _master.getName(); - if (name == null) - return ""; - - return name; - } - - public XDGFShape getMasterShape() { - return _masterShape; - } - - // returns the parent shape of this shape, if its in a subshape - public XDGFShape getParentShape() { - return _parent; - } - - public XDGFShape getTopmostParentShape() { - XDGFShape top = null; - if (_parent != null) { - top = _parent.getTopmostParentShape(); - if (top == null) - top = _parent; - } - - return top; - } - - public boolean hasMaster() { - return _master != null; - } - - public boolean hasMasterShape() { - return _masterShape != null; - } - - public boolean hasParent() { - return _parent != null; - } - - public boolean hasShapes() { - return _shapes != null; - } - - public boolean isTopmost() { - return _parent == null; - } - - public boolean isShape1D() { - return getBeginX() != null; - } - - public boolean isDeleted() { - return getXmlObject().isSetDel() ? getXmlObject().getDel() : false; - } - - public XDGFText getText() { - if (_text == null && _masterShape != null) - return _masterShape.getText(); - - return _text; - } - - public Double getPinX() { - if (_pinX == null && _masterShape != null) - return _masterShape.getPinX(); - - if (_pinX == null) - throw XDGFException.error("PinX not set!", this); - - return _pinX; - } - - public Double getPinY() { - if (_pinY == null && _masterShape != null) - return _masterShape.getPinY(); - - if (_pinY == null) - throw XDGFException.error("PinY not specified!", this); - - return _pinY; - } - - public Double getWidth() { - if (_width == null && _masterShape != null) - return _masterShape.getWidth(); - - if (_width == null) - throw XDGFException.error("Width not specified!", this); - - return _width; - } - - public Double getHeight() { - if (_height == null && _masterShape != null) - return _masterShape.getHeight(); - - if (_height == null) - throw XDGFException.error("Height not specified!", this); - - return _height; - } - - public Double getLocPinX() { - if (_locPinX == null && _masterShape != null) - return _masterShape.getLocPinX(); - - if (_locPinX == null) - throw XDGFException.error("LocPinX not specified!", this); - - return _locPinX; - } - - public Double getLocPinY() { - if (_locPinY == null && _masterShape != null) - return _masterShape.getLocPinY(); - - if (_locPinY == null) - throw XDGFException.error("LocPinY not specified!", this); - - return _locPinY; - } - - public Double getBeginX() { - if (_beginX == null && _masterShape != null) - return _masterShape.getBeginX(); - - return _beginX; - } - - public Double getBeginY() { - if (_beginY == null && _masterShape != null) - return _masterShape.getBeginY(); - - return _beginY; - } - - public Double getEndX() { - if (_endX == null && _masterShape != null) - return _masterShape.getEndX(); - - return _endX; - } - - public Double getEndY() { - if (_endY == null && _masterShape != null) - return _masterShape.getEndY(); - - return _endY; - } - - public Double getAngle() { - if (_angle == null && _masterShape != null) - return _masterShape.getAngle(); - - return _angle; - } - - public Boolean getFlipX() { - if (_flipX == null && _masterShape != null) - return _masterShape.getFlipX(); - - return _flipX; - } - - public Boolean getFlipY() { - if (_flipY == null && _masterShape != null) - return _masterShape.getFlipY(); - - return _flipY; - } - + XDGFBaseContents _parentPage; + XDGFShape _parent; // only non-null if a subshape + + XDGFMaster _master = null; + XDGFShape _masterShape = null; + + XDGFText _text = null; + + // subshapes if they exist + List _shapes = null; + + // properties specific to shapes + + // center of rotation relative to origin of parent + Double _pinX = null; + Double _pinY = null; + + Double _width = null; + Double _height = null; + + // center of rotation relative to self + Double _locPinX = null; + Double _locPinY = null; + + // start x coordinate, relative to parent + // -> one dimensional shapes only + Double _beginX = null; + Double _beginY = null; + + // end x coordinate, relative to parent + // -> one dimensional shapes only + Double _endX = null; + Double _endY = null; + + Double _angle = null; + Double _rotationXAngle = null; + Double _rotationYAngle = null; + Double _rotationZAngle = null; + + // end x coordinate, relative to parent + Boolean _flipX = null; + Boolean _flipY = null; + + // center of text relative to this shape + Double _txtPinX = null; + Double _txtPinY = null; + + // center of text relative to text block + Double _txtLocPinX = null; + Double _txtLocPinY = null; + + Double _txtAngle = null; + + Double _txtWidth = null; + Double _txtHeight = null; + + public XDGFShape(ShapeSheetType shapeSheet, XDGFBaseContents parentPage, + XDGFDocument document) { + this(null, shapeSheet, parentPage, document); + } + + public XDGFShape(XDGFShape parent, ShapeSheetType shapeSheet, + XDGFBaseContents parentPage, XDGFDocument document) { + + super(shapeSheet, document); + + _parent = parent; + _parentPage = parentPage; + + TextType text = shapeSheet.getText(); + if (text != null) + _text = new XDGFText(text, this); + + if (shapeSheet.isSetShapes()) { + _shapes = new ArrayList(); + for (ShapeSheetType shape : shapeSheet.getShapes().getShapeArray()) + _shapes.add(new XDGFShape(this, shape, parentPage, document)); + } + + readProperties(); + } + + @Override + public String toString() { + if (_parentPage instanceof XDGFMasterContents) + return _parentPage + ": "; + else + return ""; + } + + protected void readProperties() { + + _pinX = XDGFCell.maybeGetDouble(_cells, "PinX"); + _pinY = XDGFCell.maybeGetDouble(_cells, "PinY"); + _width = XDGFCell.maybeGetDouble(_cells, "Width"); + _height = XDGFCell.maybeGetDouble(_cells, "Height"); + _locPinX = XDGFCell.maybeGetDouble(_cells, "LocPinX"); + _locPinY = XDGFCell.maybeGetDouble(_cells, "LocPinY"); + _beginX = XDGFCell.maybeGetDouble(_cells, "BeginX"); + _beginY = XDGFCell.maybeGetDouble(_cells, "BeginY"); + _endX = XDGFCell.maybeGetDouble(_cells, "EndX"); + _endY = XDGFCell.maybeGetDouble(_cells, "EndY"); + + _angle = XDGFCell.maybeGetDouble(_cells, "Angle"); + _rotationXAngle = XDGFCell.maybeGetDouble(_cells, "RotationXAngle"); + _rotationYAngle = XDGFCell.maybeGetDouble(_cells, "RotationYAngle"); + _rotationZAngle = XDGFCell.maybeGetDouble(_cells, "RotationZAngle"); + + _flipX = XDGFCell.maybeGetBoolean(_cells, "FlipX"); + _flipY = XDGFCell.maybeGetBoolean(_cells, "FlipY"); + + _txtPinX = XDGFCell.maybeGetDouble(_cells, "TxtPinX"); + _txtPinY = XDGFCell.maybeGetDouble(_cells, "TxtPinY"); + _txtLocPinX = XDGFCell.maybeGetDouble(_cells, "TxtLocPinX"); + _txtLocPinY = XDGFCell.maybeGetDouble(_cells, "TxtLocPinY"); + _txtWidth = XDGFCell.maybeGetDouble(_cells, "TxtWidth"); + _txtHeight = XDGFCell.maybeGetDouble(_cells, "TxtHeight"); + + _txtAngle = XDGFCell.maybeGetDouble(_cells, "TxtAngle"); + } + + /** + * Setup top level shapes + * + * Shapes that have a 'Master' attribute refer to a specific master in the + * page, whereas shapes with a 'MasterShape' attribute refer to a subshape + * of a Master. + * + * + */ + protected void setupMaster(XDGFPageContents pageContents, + XDGFMasterContents master) { + + ShapeSheetType obj = getXmlObject(); + + if (obj.isSetMaster()) { + _master = pageContents.getMasterById(obj.getMaster()); + if (_master == null) + throw XDGFException.error("refers to non-existant master " + + obj.getMaster(), this); + + /* + * If a master has one top-level shape, a shape that inherits from + * that master inherits the descendant elements of that master + * shape. If a master has more than one master shape, a shape that + * inherits from that master inherits those master shapes as + * subshapes. + */ + + Collection masterShapes = _master.getContent() + .getTopLevelShapes(); + + switch (masterShapes.size()) { + case 0: + throw XDGFException + .error("Could not retrieve master shape from " + + _master, this); + case 1: + _masterShape = masterShapes.iterator().next(); + break; + default: + break; + } + + } else if (obj.isSetMasterShape()) { + _masterShape = master.getShapeById(obj.getMasterShape()); + if (_masterShape == null) + throw XDGFException.error( + "refers to non-existant master shape " + + obj.getMasterShape(), this); + + } + + setupSectionMasters(); + + if (_shapes != null) { + for (XDGFShape shape : _shapes) { + shape.setupMaster(pageContents, _master == null ? master + : _master.getContent()); + } + } + } + + protected void setupSectionMasters() { + + if (_masterShape == null) + return; + + try { + for (Entry section : _sections.entrySet()) { + XDGFSection master = _masterShape.getSection(section.getKey()); + if (master != null) + section.getValue().setupMaster(master); + } + + for (Entry section : _geometry.entrySet()) { + GeometrySection master = _masterShape.getGeometryByIdx(section + .getKey()); + if (master != null) + section.getValue().setupMaster(master); + } + } catch (POIXMLException e) { + throw XDGFException.wrap(this.toString(), e); + } + } + + @Override + @Internal + public ShapeSheetType getXmlObject() { + return (ShapeSheetType) _sheet; + } + + public long getID() { + return getXmlObject().getID(); + } + + public String getType() { + return getXmlObject().getType(); + } + + public String getTextAsString() { + XDGFText text = getText(); + if (text == null) + return ""; + + return text.getTextContent(); + } + + public boolean hasText() { + return _text != null + || (_masterShape != null && _masterShape._text != null); + } + + @Override + public XDGFCell getCell(String cellName) { + XDGFCell _cell = super.getCell(cellName); + + // if not found, ask the master + if (_cell == null && _masterShape != null) { + _cell = _masterShape.getCell(cellName); + } + + return _cell; + } + + public GeometrySection getGeometryByIdx(long idx) { + return _geometry.get(idx); + } + + // only available if this is a shape group + // -> May be null + public List getShapes() { + return _shapes; + } + + // unique to this shape on the page? + public String getName() { + String name = getXmlObject().getName(); + if (name == null) + return ""; + return name; + } + + // unique to this shape on the page? + public String getShapeType() { + String type = getXmlObject().getType(); + if (type == null) + return ""; + return type; + } + + // name of the symbol that this was derived from + public String getSymbolName() { + + if (_master == null) + return ""; + + String name = _master.getName(); + if (name == null) + return ""; + + return name; + } + + public XDGFShape getMasterShape() { + return _masterShape; + } + + // returns the parent shape of this shape, if its in a subshape + public XDGFShape getParentShape() { + return _parent; + } + + public XDGFShape getTopmostParentShape() { + XDGFShape top = null; + if (_parent != null) { + top = _parent.getTopmostParentShape(); + if (top == null) + top = _parent; + } + + return top; + } + + public boolean hasMaster() { + return _master != null; + } + + public boolean hasMasterShape() { + return _masterShape != null; + } + + public boolean hasParent() { + return _parent != null; + } + + public boolean hasShapes() { + return _shapes != null; + } + + public boolean isTopmost() { + return _parent == null; + } + + public boolean isShape1D() { + return getBeginX() != null; + } + + public boolean isDeleted() { + return getXmlObject().isSetDel() ? getXmlObject().getDel() : false; + } + + public XDGFText getText() { + if (_text == null && _masterShape != null) + return _masterShape.getText(); + + return _text; + } + + public Double getPinX() { + if (_pinX == null && _masterShape != null) + return _masterShape.getPinX(); + + if (_pinX == null) + throw XDGFException.error("PinX not set!", this); + + return _pinX; + } + + public Double getPinY() { + if (_pinY == null && _masterShape != null) + return _masterShape.getPinY(); + + if (_pinY == null) + throw XDGFException.error("PinY not specified!", this); + + return _pinY; + } + + public Double getWidth() { + if (_width == null && _masterShape != null) + return _masterShape.getWidth(); + + if (_width == null) + throw XDGFException.error("Width not specified!", this); + + return _width; + } + + public Double getHeight() { + if (_height == null && _masterShape != null) + return _masterShape.getHeight(); + + if (_height == null) + throw XDGFException.error("Height not specified!", this); + + return _height; + } + + public Double getLocPinX() { + if (_locPinX == null && _masterShape != null) + return _masterShape.getLocPinX(); + + if (_locPinX == null) + throw XDGFException.error("LocPinX not specified!", this); + + return _locPinX; + } + + public Double getLocPinY() { + if (_locPinY == null && _masterShape != null) + return _masterShape.getLocPinY(); + + if (_locPinY == null) + throw XDGFException.error("LocPinY not specified!", this); + + return _locPinY; + } + + public Double getBeginX() { + if (_beginX == null && _masterShape != null) + return _masterShape.getBeginX(); + + return _beginX; + } + + public Double getBeginY() { + if (_beginY == null && _masterShape != null) + return _masterShape.getBeginY(); + + return _beginY; + } + + public Double getEndX() { + if (_endX == null && _masterShape != null) + return _masterShape.getEndX(); + + return _endX; + } + + public Double getEndY() { + if (_endY == null && _masterShape != null) + return _masterShape.getEndY(); + + return _endY; + } + + public Double getAngle() { + if (_angle == null && _masterShape != null) + return _masterShape.getAngle(); + + return _angle; + } + + public Boolean getFlipX() { + if (_flipX == null && _masterShape != null) + return _masterShape.getFlipX(); + + return _flipX; + } + + public Boolean getFlipY() { + if (_flipY == null && _masterShape != null) + return _masterShape.getFlipY(); + + return _flipY; + } + public Double getTxtPinX() { - if (_txtPinX == null && - _masterShape != null && _masterShape._txtPinX != null) + if (_txtPinX == null && _masterShape != null + && _masterShape._txtPinX != null) return _masterShape._txtPinX; - + if (_txtPinX == null) - return getWidth()*0.5; - + return getWidth() * 0.5; + return _txtPinX; } - public Double getTxtPinY() { - if (_txtLocPinY == null && - _masterShape != null && _masterShape._txtLocPinY != null) + if (_txtLocPinY == null && _masterShape != null + && _masterShape._txtLocPinY != null) return _masterShape._txtLocPinY; - + if (_txtPinY == null) - return getHeight()*0.5; - + return getHeight() * 0.5; + return _txtPinY; } - public Double getTxtLocPinX() { - if (_txtLocPinX == null && - _masterShape != null && _masterShape._txtLocPinX != null) + if (_txtLocPinX == null && _masterShape != null + && _masterShape._txtLocPinX != null) return _masterShape._txtLocPinX; - + if (_txtLocPinX == null) - return getTxtWidth()*0.5; - + return getTxtWidth() * 0.5; + return _txtLocPinX; } - public Double getTxtLocPinY() { - if (_txtLocPinY == null && - _masterShape != null && _masterShape._txtLocPinY != null) + if (_txtLocPinY == null && _masterShape != null + && _masterShape._txtLocPinY != null) return _masterShape._txtLocPinY; - + if (_txtLocPinY == null) - return getTxtHeight()*0.5; - + return getTxtHeight() * 0.5; + return _txtLocPinY; } - + public Double getTxtAngle() { - if (_txtAngle == null && _masterShape != null) - return _masterShape.getTxtAngle(); - - return _txtAngle; - } - + if (_txtAngle == null && _masterShape != null) + return _masterShape.getTxtAngle(); + + return _txtAngle; + } + public Double getTxtWidth() { - if (_txtWidth == null && - _masterShape != null && _masterShape._txtWidth != null) + if (_txtWidth == null && _masterShape != null + && _masterShape._txtWidth != null) return _masterShape._txtWidth; - + if (_txtWidth == null) return getWidth(); - + return _txtWidth; } - public Double getTxtHeight() { - if (_txtHeight == null && - _masterShape != null && _masterShape._txtHeight != null) + if (_txtHeight == null && _masterShape != null + && _masterShape._txtHeight != null) return _masterShape._txtHeight; - + if (_txtHeight == null) return getHeight(); - + return _txtHeight; } - + + @Override + public Integer getLineCap() { + + Integer lineCap = super.getLineCap(); + if (lineCap != null) + return lineCap; + + // get from master + if (_masterShape != null) { + return _masterShape.getLineCap(); + } + + // get default + XDGFStyleSheet style = _document.getDefaultLineStyle(); + if (style != null) + return style.getLineCap(); + + return null; + } + @Override - public Integer getLineCap() { - - Integer lineCap = super.getLineCap(); - if (lineCap != null) - return lineCap; - - // get from master - if (_masterShape != null) { - return _masterShape.getLineCap(); - } - - // get default - XDGFStyleSheet style = _document.getDefaultLineStyle(); - if (style != null) - return style.getLineCap(); - - return null; - } - + public Color getLineColor() { + + Color lineColor = super.getLineColor(); + if (lineColor != null) + return lineColor; + + // get from master + if (_masterShape != null) { + return _masterShape.getLineColor(); + } + + // get default + XDGFStyleSheet style = _document.getDefaultLineStyle(); + if (style != null) + return style.getLineColor(); + + return null; + } + @Override - public Color getLineColor() { - - Color lineColor = super.getLineColor(); - if (lineColor != null) - return lineColor; - - // get from master - if (_masterShape != null) { - return _masterShape.getLineColor(); - } - - // get default - XDGFStyleSheet style = _document.getDefaultLineStyle(); - if (style != null) - return style.getLineColor(); - - return null; - } - + public Integer getLinePattern() { + + Integer linePattern = super.getLinePattern(); + if (linePattern != null) + return linePattern; + + // get from master + if (_masterShape != null) { + return _masterShape.getLinePattern(); + } + + // get default + XDGFStyleSheet style = _document.getDefaultLineStyle(); + if (style != null) + return style.getLinePattern(); + + return null; + } + @Override - public Integer getLinePattern() { - - Integer linePattern = super.getLinePattern(); - if (linePattern != null) - return linePattern; - - // get from master - if (_masterShape != null) { - return _masterShape.getLinePattern(); - } - - // get default - XDGFStyleSheet style = _document.getDefaultLineStyle(); - if (style != null) - return style.getLinePattern(); - - return null; - } - + public Double getLineWeight() { + + Double lineWeight = super.getLineWeight(); + if (lineWeight != null) + return lineWeight; + + // get from master + if (_masterShape != null) { + return _masterShape.getLineWeight(); + } + + // get default + XDGFStyleSheet style = _document.getDefaultLineStyle(); + if (style != null) + return style.getLineWeight(); + + return null; + } + @Override - public Double getLineWeight() { - - Double lineWeight = super.getLineWeight(); - if (lineWeight != null) - return lineWeight; - - // get from master - if (_masterShape != null) { - return _masterShape.getLineWeight(); - } - - // get default - XDGFStyleSheet style = _document.getDefaultLineStyle(); - if (style != null) - return style.getLineWeight(); - - return null; - } - public Color getFontColor() { - - Color fontColor = super.getFontColor(); - if (fontColor != null) - return fontColor; - - // get from master - if (_masterShape != null) { - return _masterShape.getFontColor(); - } - - // get default - XDGFStyleSheet style = _document.getDefaultTextStyle(); - if (style != null) - return style.getFontColor(); - - return null; - } - - public Double getFontSize() { - - Double fontSize = super.getFontSize(); - if (fontSize != null) - return fontSize; - - // get from master - if (_masterShape != null) { - return _masterShape.getFontSize(); - } - - // get default - XDGFStyleSheet style = _document.getDefaultTextStyle(); - if (style != null) - return style.getFontSize(); - - return null; - } - - public Stroke getStroke() { - - float lineWeight = getLineWeight().floatValue(); - int cap; - int join = BasicStroke.JOIN_MITER; - float miterlimit = 10.0f; - - switch (getLineCap()) { - case 0: - cap = BasicStroke.CAP_ROUND; - break; - case 1: - cap = BasicStroke.CAP_SQUARE; - break; - case 2: - cap = BasicStroke.CAP_BUTT; // TODO: what does extended mean? - break; - default: - throw new POIXMLException("Invalid line cap specified"); - } - - float[] dash = null; - - // these line patterns are just approximations - switch (getLinePattern()) { - case 0: // transparent - break; - case 1: // solid - break; - case 2: - dash = new float[]{5,3}; - break; - case 3: - dash = new float[]{1,4}; - break; - case 4: - dash = new float[]{6,3,1,3}; - break; - case 5: - dash = new float[]{6,3,1,3,1,3}; - break; - case 6: - dash = new float[]{1,3,6,3,6,3}; - break; - case 7: - dash = new float[]{15,3,6,3}; - break; - case 8: - dash = new float[]{6,3,6,3}; - break; - case 9: - dash = new float[]{3,2}; - break; - case 10: - dash = new float[]{1,2}; - break; - case 11: - dash = new float[]{3,2,1,2}; - break; - case 12: - dash = new float[]{3,2,1,2,1}; - break; - case 13: - dash = new float[]{1,2,3,2,3,2}; - break; - case 14: - dash = new float[]{3,2,7,2}; - break; - case 15: - dash = new float[]{7,2,3,2,3,2}; - break; - case 16: - dash = new float[]{12,6}; - break; - case 17: - dash = new float[]{1,6}; - break; - case 18: - dash = new float[]{1,6,12,6}; - break; - case 19: - dash = new float[]{1,6,1,6,12,6}; - break; - case 20: - dash = new float[]{1,6,12,6,12,6}; - break; - case 21: - dash = new float[]{30,6,12,6}; - break; - case 22: - dash = new float[]{30,6,12,6,12,6}; - break; - case 23: - dash = new float[]{1}; - break; - case 254: - throw new POIXMLException("Unsupported line pattern value"); - default: - throw new POIXMLException("Invalid line pattern value"); - } - - // dashes are in units of line width - if (dash != null) { - for (int i = 0; i < dash.length; i++) { - dash[i] *= lineWeight; - } - } - - return new BasicStroke(lineWeight, cap, join, miterlimit, dash, 0); - } - - - // - // Geometry - // - - public Iterable getGeometrySections() { - return new CombinedIterable<>(_geometry, - _masterShape != null ? _masterShape._geometry : null); - } - - - // returns a rectangle in local coordinates - public Rectangle2D.Double getBounds() { - return new Rectangle2D.Double(0, 0, getWidth(), - getHeight()); - } - - // returns bounds as a path in local coordinates - // -> useful if you need to transform to global coordinates - // -> Don't use for 1d objects, fails for infinite line objects - public Path2D.Double getBoundsAsPath() { - - Double w = getWidth(); - Double h = getHeight(); - - Path2D.Double bounds = new Path2D.Double(); - bounds.moveTo(0, 0); - bounds.lineTo(w, 0); - bounds.lineTo(w, h); - bounds.lineTo(0, h); - bounds.lineTo(0, 0); - - return bounds; - } - - // returns the path in local coordinates - public Path2D.Double getPath() { - for (GeometrySection geoSection: getGeometrySections()) { - if (geoSection.getNoShow() == true) - continue; - - return geoSection.getPath(this); - } - - return null; - } - - /* - * Returns true if the shape has a drawable geometry associated with it - */ - public boolean hasGeometry() { - for (GeometrySection geoSection: getGeometrySections()) { - if (geoSection.getNoShow() == false) - return true; - } - return false; - } - - /** - * Returns a transform that can translate shape-local coordinates - * to the coordinates of its parent shape - */ - protected AffineTransform getParentTransform() { - // TODO: There's probably a better way to do this - AffineTransform tr = new AffineTransform(); - - Double locX = getLocPinX(); - Double locY = getLocPinY(); - Boolean flipX = getFlipX(); - Boolean flipY = getFlipY(); - Double angle = getAngle(); - - tr.translate(-locX, -locY); - - tr.translate(getPinX(), getPinY()); - - // rotate about the origin - if (angle != null && Math.abs(angle) > 0.001) { - tr.rotate(angle, locX, locY); - } - - // flip if necessary - - if (flipX != null && flipX) { - tr.scale(-1, 1); - tr.translate(-getWidth(), 0); - } - - if (flipY != null && flipY) { - tr.scale(1, -1); - tr.translate(0, -getHeight()); - } - - return tr; - } - + Color fontColor = super.getFontColor(); + if (fontColor != null) + return fontColor; + + // get from master + if (_masterShape != null) { + return _masterShape.getFontColor(); + } + + // get default + XDGFStyleSheet style = _document.getDefaultTextStyle(); + if (style != null) + return style.getFontColor(); + + return null; + } + + @Override + public Double getFontSize() { + + Double fontSize = super.getFontSize(); + if (fontSize != null) + return fontSize; + + // get from master + if (_masterShape != null) { + return _masterShape.getFontSize(); + } + + // get default + XDGFStyleSheet style = _document.getDefaultTextStyle(); + if (style != null) + return style.getFontSize(); + + return null; + } + + public Stroke getStroke() { + + float lineWeight = getLineWeight().floatValue(); + int cap; + int join = BasicStroke.JOIN_MITER; + float miterlimit = 10.0f; + + switch (getLineCap()) { + case 0: + cap = BasicStroke.CAP_ROUND; + break; + case 1: + cap = BasicStroke.CAP_SQUARE; + break; + case 2: + cap = BasicStroke.CAP_BUTT; // TODO: what does extended mean? + break; + default: + throw new POIXMLException("Invalid line cap specified"); + } + + float[] dash = null; + + // these line patterns are just approximations + switch (getLinePattern()) { + case 0: // transparent + break; + case 1: // solid + break; + case 2: + dash = new float[] { 5, 3 }; + break; + case 3: + dash = new float[] { 1, 4 }; + break; + case 4: + dash = new float[] { 6, 3, 1, 3 }; + break; + case 5: + dash = new float[] { 6, 3, 1, 3, 1, 3 }; + break; + case 6: + dash = new float[] { 1, 3, 6, 3, 6, 3 }; + break; + case 7: + dash = new float[] { 15, 3, 6, 3 }; + break; + case 8: + dash = new float[] { 6, 3, 6, 3 }; + break; + case 9: + dash = new float[] { 3, 2 }; + break; + case 10: + dash = new float[] { 1, 2 }; + break; + case 11: + dash = new float[] { 3, 2, 1, 2 }; + break; + case 12: + dash = new float[] { 3, 2, 1, 2, 1 }; + break; + case 13: + dash = new float[] { 1, 2, 3, 2, 3, 2 }; + break; + case 14: + dash = new float[] { 3, 2, 7, 2 }; + break; + case 15: + dash = new float[] { 7, 2, 3, 2, 3, 2 }; + break; + case 16: + dash = new float[] { 12, 6 }; + break; + case 17: + dash = new float[] { 1, 6 }; + break; + case 18: + dash = new float[] { 1, 6, 12, 6 }; + break; + case 19: + dash = new float[] { 1, 6, 1, 6, 12, 6 }; + break; + case 20: + dash = new float[] { 1, 6, 12, 6, 12, 6 }; + break; + case 21: + dash = new float[] { 30, 6, 12, 6 }; + break; + case 22: + dash = new float[] { 30, 6, 12, 6, 12, 6 }; + break; + case 23: + dash = new float[] { 1 }; + break; + case 254: + throw new POIXMLException("Unsupported line pattern value"); + default: + throw new POIXMLException("Invalid line pattern value"); + } + + // dashes are in units of line width + if (dash != null) { + for (int i = 0; i < dash.length; i++) { + dash[i] *= lineWeight; + } + } + + return new BasicStroke(lineWeight, cap, join, miterlimit, dash, 0); + } + + // + // Geometry + // + + public Iterable getGeometrySections() { + return new CombinedIterable(_geometry, + _masterShape != null ? _masterShape._geometry : null); + } + + // returns a rectangle in local coordinates + public Rectangle2D.Double getBounds() { + return new Rectangle2D.Double(0, 0, getWidth(), getHeight()); + } + + // returns bounds as a path in local coordinates + // -> useful if you need to transform to global coordinates + // -> Don't use for 1d objects, fails for infinite line objects + public Path2D.Double getBoundsAsPath() { + + Double w = getWidth(); + Double h = getHeight(); + + Path2D.Double bounds = new Path2D.Double(); + bounds.moveTo(0, 0); + bounds.lineTo(w, 0); + bounds.lineTo(w, h); + bounds.lineTo(0, h); + bounds.lineTo(0, 0); + + return bounds; + } + + // returns the path in local coordinates + public Path2D.Double getPath() { + for (GeometrySection geoSection : getGeometrySections()) { + if (geoSection.getNoShow() == true) + continue; + + return geoSection.getPath(this); + } + + return null; + } + + /* + * Returns true if the shape has a drawable geometry associated with it + */ + public boolean hasGeometry() { + for (GeometrySection geoSection : getGeometrySections()) { + if (geoSection.getNoShow() == false) + return true; + } + return false; + } + + /** + * Returns a transform that can translate shape-local coordinates to the + * coordinates of its parent shape + */ + protected AffineTransform getParentTransform() { + // TODO: There's probably a better way to do this + AffineTransform tr = new AffineTransform(); + + Double locX = getLocPinX(); + Double locY = getLocPinY(); + Boolean flipX = getFlipX(); + Boolean flipY = getFlipY(); + Double angle = getAngle(); + + tr.translate(-locX, -locY); + + tr.translate(getPinX(), getPinY()); + + // rotate about the origin + if (angle != null && Math.abs(angle) > 0.001) { + tr.rotate(angle, locX, locY); + } + + // flip if necessary + + if (flipX != null && flipX) { + tr.scale(-1, 1); + tr.translate(-getWidth(), 0); + } + + if (flipY != null && flipY) { + tr.scale(1, -1); + tr.translate(0, -getHeight()); + } + + return tr; + } /** * The visitor will first visit this shape, then it's children - * + * * This is useful because exceptions will be marked with the shapes as it * propagates up the shape hierarchy. */ - public void visitShapes(ShapeVisitor visitor, AffineTransform tr, int level) { - - tr = (AffineTransform)tr.clone(); - tr.concatenate(getParentTransform()); - - try { - if (visitor.accept(this)) - visitor.visit(this, tr, level); - - if (_shapes != null) { - for (XDGFShape shape: _shapes) { - shape.visitShapes(visitor, tr, level + 1); - } - } - } catch (StopVisitingThisBranch e) { - // intentionally empty - } catch (POIXMLException e) { - throw XDGFException.wrap(this.toString(), e); - } - } - - /** - * The visitor will first visit this shape, then it's children. No transform + public void visitShapes(ShapeVisitor visitor, AffineTransform tr, int level) { + + tr = (AffineTransform) tr.clone(); + tr.concatenate(getParentTransform()); + + try { + if (visitor.accept(this)) + visitor.visit(this, tr, level); + + if (_shapes != null) { + for (XDGFShape shape : _shapes) { + shape.visitShapes(visitor, tr, level + 1); + } + } + } catch (StopVisitingThisBranch e) { + // intentionally empty + } catch (POIXMLException e) { + throw XDGFException.wrap(this.toString(), e); + } + } + + /** + * The visitor will first visit this shape, then it's children. No transform * is calculated for this visit - * + * * This is useful because exceptions will be marked with the shapes as it * propagates up the shape hierarchy. */ - public void visitShapes(ShapeVisitor visitor, int level) { - - try { - if (visitor.accept(this)) - visitor.visit(this, null, level); - - if (_shapes != null) { - for (XDGFShape shape: _shapes) { - shape.visitShapes(visitor, level + 1); - } - } - } catch (StopVisitingThisBranch e) { - // intentionally empty - } catch (POIXMLException e) { - throw XDGFException.wrap(this.toString(), e); - } - } - + public void visitShapes(ShapeVisitor visitor, int level) { + + try { + if (visitor.accept(this)) + visitor.visit(this, null, level); + + if (_shapes != null) { + for (XDGFShape shape : _shapes) { + shape.visitShapes(visitor, level + 1); + } + } + } catch (StopVisitingThisBranch e) { + // intentionally empty + } catch (POIXMLException e) { + throw XDGFException.wrap(this.toString(), e); + } + } + } Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFSheet.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFSheet.java?rev=1709355&r1=1709354&r2=1709355&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFSheet.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFSheet.java Mon Oct 19 05:59:37 2015 @@ -39,166 +39,166 @@ import com.microsoft.schemas.office.visi */ public abstract class XDGFSheet { - protected XDGFDocument _document; - protected SheetType _sheet; + protected XDGFDocument _document; + protected SheetType _sheet; - // cells - protected Map _cells = new HashMap<>(); - - // sections - protected Map _sections = new HashMap<>(); - - // special: geometry sections (key: index, value: section) - protected SortedMap _geometry = new TreeMap<>(); - - // special: character section - protected CharacterSection _character = null; - - public XDGFSheet(SheetType sheet, XDGFDocument document) { - try { - _sheet = sheet; - _document = document; - - for (CellType cell: sheet.getCellArray()) { - if (_cells.containsKey(cell.getN())) - throw new POIXMLException("Unexpected duplicate cell " + cell.getN()); // this shouldn't happen - - _cells.put(cell.getN(), new XDGFCell(cell)); - } - - // only geometry sections can have duplicate names - // sections can be found in the master too, if there are no attributes here! - - // no idea if I have a master in this space. go figure. - - for (SectionType section: sheet.getSectionArray()) { - String name = section.getN(); - if (name.equals("Geometry")) { - _geometry.put(section.getIX(), new GeometrySection(section, this)); - } else if (name.equals("Character")) { - _character = new CharacterSection(section, this); - } else { - _sections.put(name, XDGFSection.load(section, this)); - } - } - } catch (POIXMLException e) { - throw XDGFException.wrap(this.toString(), e); - } - } - - abstract SheetType getXmlObject(); - - public XDGFDocument getDocument() { - return _document; - } - - // A cell is really just a setting - public XDGFCell getCell(String cellName) { - return _cells.get(cellName); - } - - public XDGFSection getSection(String sectionName) { - return _sections.get(sectionName); - } - - public XDGFStyleSheet getLineStyle() { - if (!_sheet.isSetLineStyle()) - return null; - - return _document.getStyleById(_sheet.getLineStyle()); - } - - public XDGFStyleSheet getFillStyle() { - if (!_sheet.isSetFillStyle()) - return null; - - return _document.getStyleById(_sheet.getFillStyle()); - } - - public XDGFStyleSheet getTextStyle() { - if (!_sheet.isSetTextStyle()) - return null; - - return _document.getStyleById(_sheet.getTextStyle()); - } - - public Color getFontColor() { - Color fontColor = null; - - if (_character != null) { - fontColor = _character.getFontColor(); - if (fontColor != null) - return fontColor; - } - - XDGFStyleSheet style = getTextStyle(); - if (style != null) - return style.getFontColor(); - - return null; - } - - public Double getFontSize() { - Double fontSize = null; - - if (_character != null) { - fontSize = _character.getFontSize(); - if (fontSize != null) - return fontSize; - } - - XDGFStyleSheet style = getTextStyle(); - if (style != null) - return style.getFontSize(); - - return null; - } - - public Integer getLineCap() { - Integer lineCap = XDGFCell.maybeGetInteger(_cells, "LineCap"); - if (lineCap != null) - return lineCap; - - XDGFStyleSheet style = getLineStyle(); - if (style != null) - return style.getLineCap(); - - return null; - } - - public Color getLineColor() { - String lineColor = XDGFCell.maybeGetString(_cells, "LineColor"); - if (lineColor != null) - return Color.decode(lineColor); - - XDGFStyleSheet style = getLineStyle(); - if (style != null) - return style.getLineColor(); - - return null; - } - - public Integer getLinePattern() { - Integer linePattern = XDGFCell.maybeGetInteger(_cells, "LinePattern"); - if (linePattern != null) - return linePattern; - - XDGFStyleSheet style = getLineStyle(); - if (style != null) - return style.getLinePattern(); - - return null; - } - - public Double getLineWeight() { - Double lineWeight = XDGFCell.maybeGetDouble(_cells, "LineWeight"); - if (lineWeight != null) - return lineWeight; - - XDGFStyleSheet style = getLineStyle(); - if (style != null) - return style.getLineWeight(); - - return null; - } + // cells + protected Map _cells = new HashMap(); + + // sections + protected Map _sections = new HashMap(); + + // special: geometry sections (key: index, value: section) + protected SortedMap _geometry = new TreeMap(); + + // special: character section + protected CharacterSection _character = null; + + public XDGFSheet(SheetType sheet, XDGFDocument document) { + try { + _sheet = sheet; + _document = document; + + for (CellType cell: sheet.getCellArray()) { + if (_cells.containsKey(cell.getN())) + throw new POIXMLException("Unexpected duplicate cell " + cell.getN()); // this shouldn't happen + + _cells.put(cell.getN(), new XDGFCell(cell)); + } + + // only geometry sections can have duplicate names + // sections can be found in the master too, if there are no attributes here! + + // no idea if I have a master in this space. go figure. + + for (SectionType section: sheet.getSectionArray()) { + String name = section.getN(); + if (name.equals("Geometry")) { + _geometry.put(section.getIX(), new GeometrySection(section, this)); + } else if (name.equals("Character")) { + _character = new CharacterSection(section, this); + } else { + _sections.put(name, XDGFSection.load(section, this)); + } + } + } catch (POIXMLException e) { + throw XDGFException.wrap(this.toString(), e); + } + } + + abstract SheetType getXmlObject(); + + public XDGFDocument getDocument() { + return _document; + } + + // A cell is really just a setting + public XDGFCell getCell(String cellName) { + return _cells.get(cellName); + } + + public XDGFSection getSection(String sectionName) { + return _sections.get(sectionName); + } + + public XDGFStyleSheet getLineStyle() { + if (!_sheet.isSetLineStyle()) + return null; + + return _document.getStyleById(_sheet.getLineStyle()); + } + + public XDGFStyleSheet getFillStyle() { + if (!_sheet.isSetFillStyle()) + return null; + + return _document.getStyleById(_sheet.getFillStyle()); + } + + public XDGFStyleSheet getTextStyle() { + if (!_sheet.isSetTextStyle()) + return null; + + return _document.getStyleById(_sheet.getTextStyle()); + } + + public Color getFontColor() { + Color fontColor = null; + + if (_character != null) { + fontColor = _character.getFontColor(); + if (fontColor != null) + return fontColor; + } + + XDGFStyleSheet style = getTextStyle(); + if (style != null) + return style.getFontColor(); + + return null; + } + + public Double getFontSize() { + Double fontSize = null; + + if (_character != null) { + fontSize = _character.getFontSize(); + if (fontSize != null) + return fontSize; + } + + XDGFStyleSheet style = getTextStyle(); + if (style != null) + return style.getFontSize(); + + return null; + } + + public Integer getLineCap() { + Integer lineCap = XDGFCell.maybeGetInteger(_cells, "LineCap"); + if (lineCap != null) + return lineCap; + + XDGFStyleSheet style = getLineStyle(); + if (style != null) + return style.getLineCap(); + + return null; + } + + public Color getLineColor() { + String lineColor = XDGFCell.maybeGetString(_cells, "LineColor"); + if (lineColor != null) + return Color.decode(lineColor); + + XDGFStyleSheet style = getLineStyle(); + if (style != null) + return style.getLineColor(); + + return null; + } + + public Integer getLinePattern() { + Integer linePattern = XDGFCell.maybeGetInteger(_cells, "LinePattern"); + if (linePattern != null) + return linePattern; + + XDGFStyleSheet style = getLineStyle(); + if (style != null) + return style.getLinePattern(); + + return null; + } + + public Double getLineWeight() { + Double lineWeight = XDGFCell.maybeGetDouble(_cells, "LineWeight"); + if (lineWeight != null) + return lineWeight; + + XDGFStyleSheet style = getLineStyle(); + if (style != null) + return style.getLineWeight(); + + return null; + } } Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFStyleSheet.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFStyleSheet.java?rev=1709355&r1=1709354&r2=1709355&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFStyleSheet.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFStyleSheet.java Mon Oct 19 05:59:37 2015 @@ -22,15 +22,15 @@ import org.apache.poi.util.Internal; import com.microsoft.schemas.office.visio.x2012.main.StyleSheetType; public class XDGFStyleSheet extends XDGFSheet { - - public XDGFStyleSheet(StyleSheetType styleSheet, XDGFDocument document) { - super(styleSheet, document); - } - - @Internal - public StyleSheetType getXmlObject() { - return (StyleSheetType)_sheet; - } - - + + public XDGFStyleSheet(StyleSheetType styleSheet, XDGFDocument document) { + super(styleSheet, document); + } + + @Override + @Internal + public StyleSheetType getXmlObject() { + return (StyleSheetType) _sheet; + } + } Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFText.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFText.java?rev=1709355&r1=1709354&r2=1709355&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFText.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFText.java Mon Oct 19 05:59:37 2015 @@ -33,118 +33,125 @@ import com.microsoft.schemas.office.visi public class XDGFText { - TextType _text; - XDGFShape _parent; - - public XDGFText(TextType text, XDGFShape parent) { - _text = text; - _parent = parent; - } - - @Internal - TextType getXmlObject() { - return _text; - } - - public String getTextContent() { - // casting here is wrong, but there's no other way of getting the value, - // as it doesn't seem to be exposed by complex types (even though this - // is a mixed type) - return ((TextTypeImpl)_text).getStringValue(); - } - - // these are in the shape coordinate system - // -> See https://msdn.microsoft.com/en-us/library/hh644132(v=office.12).aspx - public Rectangle2D.Double getTextBounds() { - - double txtPinX = _parent.getTxtPinX(); - double txtPinY = _parent.getTxtPinY(); - - double txtLocPinX = _parent.getTxtLocPinX(); - double txtLocPinY = _parent.getTxtLocPinY(); - - double txtWidth = _parent.getTxtWidth(); - double txtHeight = _parent.getTxtHeight(); - - double x = txtPinX - txtLocPinX; - double y = txtPinY - txtLocPinY; - - return new Rectangle2D.Double(x, y, txtWidth, txtHeight); - } - - // returns bounds as a path in local coordinates - // -> useful if you need to transform to global coordinates - public Path2D.Double getBoundsAsPath() { - - Rectangle2D.Double rect = getTextBounds(); - Double w = rect.getWidth(); - Double h = rect.getHeight(); - - Path2D.Double bounds = new Path2D.Double(); - bounds.moveTo(0, 0); - bounds.lineTo(w, 0); - bounds.lineTo(w, h); - bounds.lineTo(0, h); - bounds.lineTo(0, 0); - - return bounds; - } - - // center of text in local coordinates - public Point2D.Double getTextCenter() { - return new Point2D.Double(_parent.getTxtLocPinX(), _parent.getTxtLocPinY()); - } - - // assumes graphics is set properly to draw in the right style - public void draw(Graphics2D graphics) { - - String textContent = getTextContent(); - if (textContent.length() == 0) - return; - - Rectangle2D.Double bounds = getTextBounds(); - - String[] lines = textContent.trim().split("\n"); - FontRenderContext frc = graphics.getFontRenderContext(); - Font font = graphics.getFont(); - - AffineTransform oldTr = graphics.getTransform(); - - // visio is in flipped coordinates, so translate the text to be in the right place - Boolean flipX = _parent.getFlipX(); - Boolean flipY = _parent.getFlipY(); - - if (flipY == null || !_parent.getFlipY()) { - graphics.translate(bounds.x, bounds.y); - graphics.scale(1, -1); - graphics.translate(0, -bounds.height + graphics.getFontMetrics().getMaxCharBounds(graphics).getHeight()); - } - - if (flipX != null && _parent.getFlipX()) { - graphics.scale(-1, 1); - graphics.translate(-bounds.width, 0); - } - - Double txtAngle = _parent.getTxtAngle(); - if (txtAngle != null && Math.abs(txtAngle) > 0.01) - graphics.rotate(txtAngle); - - float nextY = 0; - for (String line: lines) { - - if (line.length() == 0) - continue; - - TextLayout layout = new TextLayout(line, font, frc); - - if (layout.isLeftToRight()) - layout.draw(graphics, 0, nextY); - else - layout.draw(graphics, (float)(bounds.width - layout.getAdvance()), nextY); - - nextY += layout.getAscent() + layout.getDescent() + layout.getLeading(); - } - - graphics.setTransform(oldTr); - } + TextType _text; + XDGFShape _parent; + + public XDGFText(TextType text, XDGFShape parent) { + _text = text; + _parent = parent; + } + + @Internal + TextType getXmlObject() { + return _text; + } + + public String getTextContent() { + // casting here is wrong, but there's no other way of getting the value, + // as it doesn't seem to be exposed by complex types (even though this + // is a mixed type) + return ((TextTypeImpl) _text).getStringValue(); + } + + // these are in the shape coordinate system + // -> See + // https://msdn.microsoft.com/en-us/library/hh644132(v=office.12).aspx + public Rectangle2D.Double getTextBounds() { + + double txtPinX = _parent.getTxtPinX(); + double txtPinY = _parent.getTxtPinY(); + + double txtLocPinX = _parent.getTxtLocPinX(); + double txtLocPinY = _parent.getTxtLocPinY(); + + double txtWidth = _parent.getTxtWidth(); + double txtHeight = _parent.getTxtHeight(); + + double x = txtPinX - txtLocPinX; + double y = txtPinY - txtLocPinY; + + return new Rectangle2D.Double(x, y, txtWidth, txtHeight); + } + + // returns bounds as a path in local coordinates + // -> useful if you need to transform to global coordinates + public Path2D.Double getBoundsAsPath() { + + Rectangle2D.Double rect = getTextBounds(); + Double w = rect.getWidth(); + Double h = rect.getHeight(); + + Path2D.Double bounds = new Path2D.Double(); + bounds.moveTo(0, 0); + bounds.lineTo(w, 0); + bounds.lineTo(w, h); + bounds.lineTo(0, h); + bounds.lineTo(0, 0); + + return bounds; + } + + // center of text in local coordinates + public Point2D.Double getTextCenter() { + return new Point2D.Double(_parent.getTxtLocPinX(), + _parent.getTxtLocPinY()); + } + + // assumes graphics is set properly to draw in the right style + public void draw(Graphics2D graphics) { + + String textContent = getTextContent(); + if (textContent.length() == 0) + return; + + Rectangle2D.Double bounds = getTextBounds(); + + String[] lines = textContent.trim().split("\n"); + FontRenderContext frc = graphics.getFontRenderContext(); + Font font = graphics.getFont(); + + AffineTransform oldTr = graphics.getTransform(); + + // visio is in flipped coordinates, so translate the text to be in the + // right place + Boolean flipX = _parent.getFlipX(); + Boolean flipY = _parent.getFlipY(); + + if (flipY == null || !_parent.getFlipY()) { + graphics.translate(bounds.x, bounds.y); + graphics.scale(1, -1); + graphics.translate(0, -bounds.height + + graphics.getFontMetrics().getMaxCharBounds(graphics) + .getHeight()); + } + + if (flipX != null && _parent.getFlipX()) { + graphics.scale(-1, 1); + graphics.translate(-bounds.width, 0); + } + + Double txtAngle = _parent.getTxtAngle(); + if (txtAngle != null && Math.abs(txtAngle) > 0.01) + graphics.rotate(txtAngle); + + float nextY = 0; + for (String line : lines) { + + if (line.length() == 0) + continue; + + TextLayout layout = new TextLayout(line, font, frc); + + if (layout.isLeftToRight()) + layout.draw(graphics, 0, nextY); + else + layout.draw(graphics, + (float) (bounds.width - layout.getAdvance()), nextY); + + nextY += layout.getAscent() + layout.getDescent() + + layout.getLeading(); + } + + graphics.setTransform(oldTr); + } } Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XmlVisioDocument.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XmlVisioDocument.java?rev=1709355&r1=1709354&r2=1709355&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XmlVisioDocument.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/XmlVisioDocument.java Mon Oct 19 05:59:37 2015 @@ -36,78 +36,75 @@ import com.microsoft.schemas.office.visi public class XmlVisioDocument extends POIXMLDocument { - public static String CORE_DOCUMENT = "http://schemas.microsoft.com/visio/2010/relationships/document"; - - XDGFPages _pages; - XDGFMasters _masters; - XDGFDocument _document; - - - public XmlVisioDocument(OPCPackage pkg) throws IOException { - super(pkg, CORE_DOCUMENT); - - VisioDocumentType document; - - try { - document = VisioDocumentDocument1.Factory.parse(getPackagePart().getInputStream()).getVisioDocument(); - } catch (XmlException | IOException e) { - throw new POIXMLException(e); - } - - _document = new XDGFDocument(document); - - //build a tree of POIXMLDocumentParts, this document being the root + public static String CORE_DOCUMENT = "http://schemas.microsoft.com/visio/2010/relationships/document"; + + XDGFPages _pages; + XDGFMasters _masters; + XDGFDocument _document; + + public XmlVisioDocument(OPCPackage pkg) throws IOException { + super(pkg, CORE_DOCUMENT); + + VisioDocumentType document; + + try { + document = VisioDocumentDocument1.Factory.parse(getPackagePart().getInputStream()).getVisioDocument(); + } catch (XmlException e) { + throw new POIXMLException(e); + } catch (IOException e) { + throw new POIXMLException(e); + } + + _document = new XDGFDocument(document); + + //build a tree of POIXMLDocumentParts, this document being the root load(new XDGFFactory(_document)); - } - - public XmlVisioDocument(InputStream is) throws IOException { - this(PackageHelper.open(is)); - } - - - @Override + } + + public XmlVisioDocument(InputStream is) throws IOException { + this(PackageHelper.open(is)); + } + + @Override protected void onDocumentRead() throws IOException { - - // by the time this gets called, all other document parts should - // have been loaded, so it's safe to build the document structure - - // note that in other onDocumentRead(), relations/etc may not have - // loaded yet, so it's not quite safe - - for (POIXMLDocumentPart part: getRelations()) { - - // organize the document pieces - if (part instanceof XDGFPages) - _pages = (XDGFPages)part; - - else if (part instanceof XDGFMasters) - _masters = (XDGFMasters)part; - } - - if (_masters != null) - _masters.onDocumentRead(); - - _pages.onDocumentRead(); - } - - - - @Override - public List getAllEmbedds() throws OpenXML4JException { - throw new UnsupportedOperationException("Not implemented"); - } - - // - // Useful public API goes here - // - - public Collection getPages() { - return _pages.getPageList(); - } - - - public XDGFStyleSheet getStyleById(long id) { - return _document.getStyleById(id); - } - + + // by the time this gets called, all other document parts should + // have been loaded, so it's safe to build the document structure + + // note that in other onDocumentRead(), relations/etc may not have + // loaded yet, so it's not quite safe + + for (POIXMLDocumentPart part : getRelations()) { + + // organize the document pieces + if (part instanceof XDGFPages) + _pages = (XDGFPages) part; + + else if (part instanceof XDGFMasters) + _masters = (XDGFMasters) part; + } + + if (_masters != null) + _masters.onDocumentRead(); + + _pages.onDocumentRead(); + } + + @Override + public List getAllEmbedds() throws OpenXML4JException { + throw new UnsupportedOperationException("Not implemented"); + } + + // + // Useful public API goes here + // + + public Collection getPages() { + return _pages.getPageList(); + } + + public XDGFStyleSheet getStyleById(long id) { + return _document.getStyleById(id); + } + } Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/CharacterSection.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/CharacterSection.java?rev=1709355&r1=1709354&r2=1709355&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/CharacterSection.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/CharacterSection.java Mon Oct 19 05:59:37 2015 @@ -29,43 +29,43 @@ import com.microsoft.schemas.office.visi import com.microsoft.schemas.office.visio.x2012.main.SectionType; public class CharacterSection extends XDGFSection { - - Double _fontSize = null; - Color _fontColor = null; - - Map _characterCells = new HashMap<>(); - - public CharacterSection(SectionType section, XDGFSheet containingSheet) { - super(section, containingSheet); - - // there aren't cells for this, just a single row - RowType row = section.getRowArray(0); - - for (CellType cell: row.getCellArray()) { - _characterCells.put(cell.getN(), new XDGFCell(cell)); - } - - if (row != null) { - _fontSize = XDGFCell.maybeGetDouble(_characterCells, "Size"); - - String tmpColor = XDGFCell.maybeGetString(_characterCells, "Color"); - if (tmpColor != null) - _fontColor = Color.decode(tmpColor); - } - } - - public Double getFontSize() { - return _fontSize; - } - - public Color getFontColor() { - return _fontColor; - } - - @Override - public void setupMaster(XDGFSection section) { - - } - + + Double _fontSize = null; + Color _fontColor = null; + + Map _characterCells = new HashMap(); + + public CharacterSection(SectionType section, XDGFSheet containingSheet) { + super(section, containingSheet); + + // there aren't cells for this, just a single row + RowType row = section.getRowArray(0); + + for (CellType cell: row.getCellArray()) { + _characterCells.put(cell.getN(), new XDGFCell(cell)); + } + + if (row != null) { + _fontSize = XDGFCell.maybeGetDouble(_characterCells, "Size"); + + String tmpColor = XDGFCell.maybeGetString(_characterCells, "Color"); + if (tmpColor != null) + _fontColor = Color.decode(tmpColor); + } + } + + public Double getFontSize() { + return _fontSize; + } + + public Color getFontColor() { + return _fontColor; + } + + @Override + public void setupMaster(XDGFSection section) { + + } + } Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/CombinedIterable.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/CombinedIterable.java?rev=1709355&r1=1709354&r2=1709355&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/CombinedIterable.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/CombinedIterable.java Mon Oct 19 05:59:37 2015 @@ -19,118 +19,119 @@ package org.apache.poi.xdgf.usermodel.se import java.util.Collections; import java.util.Iterator; +import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.SortedMap; -import java.util.Map.Entry; // iterates over the base and master public class CombinedIterable implements Iterable { - final SortedMap _baseItems; - final SortedMap _masterItems; - - public CombinedIterable(SortedMap baseItems, - SortedMap masterItems) { - _baseItems = baseItems; - _masterItems = masterItems; - } - - @Override - public Iterator iterator() { - - final Iterator> vmasterI; - - if (_masterItems != null) - vmasterI = _masterItems.entrySet().iterator(); - else - vmasterI = Collections.emptyIterator(); - - return new Iterator() { - - Long lastI = Long.MIN_VALUE; - - Entry currentBase = null; - Entry currentMaster = null; - - // grab the iterator for both - Iterator> baseI = _baseItems.entrySet().iterator(); - Iterator> masterI = vmasterI; - - @Override - public boolean hasNext() { - return currentBase != null || currentMaster != null || baseI.hasNext() || masterI.hasNext(); - } - - @Override - public T next() { - - // TODO: This seems far more complex than it needs to be - - long baseIdx = Long.MAX_VALUE; - long masterIdx = Long.MAX_VALUE; - - if (currentBase == null) { - while (baseI.hasNext()) { - currentBase = baseI.next(); - if (currentBase.getKey() > lastI) { - baseIdx = currentBase.getKey(); - break; - } - } - } else { - baseIdx = currentBase.getKey(); - } - - if (currentMaster == null) { - while (masterI.hasNext()) { - currentMaster = masterI.next(); - if (currentMaster.getKey() > lastI) { - masterIdx = currentMaster.getKey(); - break; - } - } - } else { - masterIdx = currentMaster.getKey(); - } - - T val; - - if (currentBase != null) { - - if (baseIdx <= masterIdx) { - lastI = baseIdx; - val = currentBase.getValue(); - - // discard master if same as base - if (masterIdx == baseIdx) { - currentMaster = null; - } - - currentBase = null; - - } else { - lastI = masterIdx; - val = currentMaster.getValue(); - currentMaster = null; - } - - } else if (currentMaster != null) { - lastI = currentMaster.getKey(); - val = currentMaster.getValue(); - - currentMaster = null; - } else { - throw new NoSuchElementException(); - } - - return val; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; - } + final SortedMap _baseItems; + final SortedMap _masterItems; + + public CombinedIterable(SortedMap baseItems, + SortedMap masterItems) { + _baseItems = baseItems; + _masterItems = masterItems; + } + + @Override + public Iterator iterator() { + + final Iterator> vmasterI; + + if (_masterItems != null) + vmasterI = _masterItems.entrySet().iterator(); + else + vmasterI = Collections.emptyIterator(); + + return new Iterator() { + + Long lastI = Long.MIN_VALUE; + + Entry currentBase = null; + Entry currentMaster = null; + + // grab the iterator for both + Iterator> baseI = _baseItems.entrySet().iterator(); + Iterator> masterI = vmasterI; + + @Override + public boolean hasNext() { + return currentBase != null || currentMaster != null + || baseI.hasNext() || masterI.hasNext(); + } + + @Override + public T next() { + + // TODO: This seems far more complex than it needs to be + + long baseIdx = Long.MAX_VALUE; + long masterIdx = Long.MAX_VALUE; + + if (currentBase == null) { + while (baseI.hasNext()) { + currentBase = baseI.next(); + if (currentBase.getKey() > lastI) { + baseIdx = currentBase.getKey(); + break; + } + } + } else { + baseIdx = currentBase.getKey(); + } + + if (currentMaster == null) { + while (masterI.hasNext()) { + currentMaster = masterI.next(); + if (currentMaster.getKey() > lastI) { + masterIdx = currentMaster.getKey(); + break; + } + } + } else { + masterIdx = currentMaster.getKey(); + } + + T val; + + if (currentBase != null) { + + if (baseIdx <= masterIdx) { + lastI = baseIdx; + val = currentBase.getValue(); + + // discard master if same as base + if (masterIdx == baseIdx) { + currentMaster = null; + } + + currentBase = null; + + } else { + lastI = masterIdx; + val = currentMaster.getValue(); + currentMaster = null; + } + + } else if (currentMaster != null) { + lastI = currentMaster.getKey(); + val = currentMaster.getValue(); + + currentMaster = null; + } else { + throw new NoSuchElementException(); + } + + return val; + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } } Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/GenericSection.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/GenericSection.java?rev=1709355&r1=1709354&r2=1709355&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/GenericSection.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/GenericSection.java Mon Oct 19 05:59:37 2015 @@ -23,11 +23,11 @@ import com.microsoft.schemas.office.visi public class GenericSection extends XDGFSection { - public GenericSection(SectionType section, XDGFSheet containingSheet) { - super(section, containingSheet); - } + public GenericSection(SectionType section, XDGFSheet containingSheet) { + super(section, containingSheet); + } - @Override - public void setupMaster(XDGFSection section) { - } + @Override + public void setupMaster(XDGFSection section) { + } } Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/GeometrySection.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/GeometrySection.java?rev=1709355&r1=1709354&r2=1709355&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/GeometrySection.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/GeometrySection.java Mon Oct 19 05:59:37 2015 @@ -29,9 +29,9 @@ import org.apache.poi.xdgf.usermodel.XDG import org.apache.poi.xdgf.usermodel.XDGFShape; import org.apache.poi.xdgf.usermodel.XDGFSheet; import org.apache.poi.xdgf.usermodel.section.geometry.Ellipse; +import org.apache.poi.xdgf.usermodel.section.geometry.GeometryRow; import org.apache.poi.xdgf.usermodel.section.geometry.GeometryRowFactory; import org.apache.poi.xdgf.usermodel.section.geometry.InfiniteLine; -import org.apache.poi.xdgf.usermodel.section.geometry.GeometryRow; import org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot; import org.apache.poi.xdgf.usermodel.section.geometry.SplineStart; @@ -40,116 +40,116 @@ import com.microsoft.schemas.office.visi public class GeometrySection extends XDGFSection { - GeometrySection _master = null; - - // rows - SortedMap _rows = new TreeMap<>(); - - public GeometrySection(SectionType section, XDGFSheet containingSheet) { - super(section, containingSheet); - - for (RowType row: section.getRowArray()) { - if (_rows.containsKey(row.getIX())) - throw new POIXMLException("Index element '" + row.getIX() + "' already exists"); - - _rows.put(row.getIX(), GeometryRowFactory.load(row)); - } - } - - @Override - public void setupMaster(XDGFSection master) { - - _master = (GeometrySection)master; - - for (Entry entry : _rows.entrySet()) { - GeometryRow masterRow = _master._rows.get(entry.getKey()); - if (masterRow != null) { - try { - entry.getValue().setupMaster(masterRow); - } catch (ClassCastException e) { - // this can happen when a dynamic connector overrides its master's geometry - // .. probably can happen elsewhere too, I imagine. - //throw XDGFException.error("Mismatched geometry section '" + entry.getKey() + "' in master", this, e); - } - } - } - } - - // returns True if this row shouldn't be displayed - public Boolean getNoShow() { - Boolean noShow = XDGFCell.maybeGetBoolean(_cells, "NoShow"); - if (noShow == null) { - if (_master != null) - return _master.getNoShow(); - - return false; - } - - return noShow; - } - - public Iterable getCombinedRows() { - return new CombinedIterable<>(_rows, - _master == null ? null : _master._rows); - } - - public Path2D.Double getPath(XDGFShape parent) { - - Iterator rows = getCombinedRows().iterator(); - - // special cases - GeometryRow first = rows.next(); - - if (first instanceof Ellipse) { - return ((Ellipse)first).getPath(); - } else if (first instanceof InfiniteLine) { - return ((InfiniteLine)first).getPath(); - } else if (first instanceof SplineStart) { - throw new POIXMLException("SplineStart must be preceded by another type"); - } else { - - // everything else is a path - Path2D.Double path = new Path2D.Double(); - - // dealing with splines makes this more complex - SplineCollector renderer = null; - GeometryRow row; - - while (true) { - - if (first != null) { - row = first; - first = null; - } else { - if (!rows.hasNext()) - break; - row = rows.next(); - } - - if (row instanceof SplineStart) { - if (renderer != null) - throw new POIXMLException("SplineStart found multiple times!"); - renderer = new SplineCollector((SplineStart) row); - } else if (row instanceof SplineKnot) { - if (renderer == null) - throw new POIXMLException("SplineKnot found without SplineStart!"); - renderer.addKnot((SplineKnot) row); - } else { - if (renderer != null) { - renderer.addToPath(path, parent); - renderer = null; - } - - row.addToPath(path, parent); - } - } - - // just in case we end iteration - if (renderer != null) - renderer.addToPath(path, parent); - - return path; - } - } - + GeometrySection _master = null; + + // rows + SortedMap _rows = new TreeMap(); + + public GeometrySection(SectionType section, XDGFSheet containingSheet) { + super(section, containingSheet); + + for (RowType row: section.getRowArray()) { + if (_rows.containsKey(row.getIX())) + throw new POIXMLException("Index element '" + row.getIX() + "' already exists"); + + _rows.put(row.getIX(), GeometryRowFactory.load(row)); + } + } + + @Override + public void setupMaster(XDGFSection master) { + + _master = (GeometrySection)master; + + for (Entry entry : _rows.entrySet()) { + GeometryRow masterRow = _master._rows.get(entry.getKey()); + if (masterRow != null) { + try { + entry.getValue().setupMaster(masterRow); + } catch (ClassCastException e) { + // this can happen when a dynamic connector overrides its master's geometry + // .. probably can happen elsewhere too, I imagine. + //throw XDGFException.error("Mismatched geometry section '" + entry.getKey() + "' in master", this, e); + } + } + } + } + + // returns True if this row shouldn't be displayed + public Boolean getNoShow() { + Boolean noShow = XDGFCell.maybeGetBoolean(_cells, "NoShow"); + if (noShow == null) { + if (_master != null) + return _master.getNoShow(); + + return false; + } + + return noShow; + } + + public Iterable getCombinedRows() { + return new CombinedIterable(_rows, + _master == null ? null : _master._rows); + } + + public Path2D.Double getPath(XDGFShape parent) { + + Iterator rows = getCombinedRows().iterator(); + + // special cases + GeometryRow first = rows.next(); + + if (first instanceof Ellipse) { + return ((Ellipse)first).getPath(); + } else if (first instanceof InfiniteLine) { + return ((InfiniteLine)first).getPath(); + } else if (first instanceof SplineStart) { + throw new POIXMLException("SplineStart must be preceded by another type"); + } else { + + // everything else is a path + Path2D.Double path = new Path2D.Double(); + + // dealing with splines makes this more complex + SplineCollector renderer = null; + GeometryRow row; + + while (true) { + + if (first != null) { + row = first; + first = null; + } else { + if (!rows.hasNext()) + break; + row = rows.next(); + } + + if (row instanceof SplineStart) { + if (renderer != null) + throw new POIXMLException("SplineStart found multiple times!"); + renderer = new SplineCollector((SplineStart) row); + } else if (row instanceof SplineKnot) { + if (renderer == null) + throw new POIXMLException("SplineKnot found without SplineStart!"); + renderer.addKnot((SplineKnot) row); + } else { + if (renderer != null) { + renderer.addToPath(path, parent); + renderer = null; + } + + row.addToPath(path, parent); + } + } + + // just in case we end iteration + if (renderer != null) + renderer.addToPath(path, parent); + + return path; + } + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org