From 7f30a6c9430476bcd5fc1662523ada0e95f60947 Mon Sep 17 00:00:00 2001 From: Ri Xu Date: Sun, 30 Apr 2017 20:03:43 +0800 Subject: - Initialize shape support: new function `AddShape()` added. Relate issue #38; - Drawing `nvPicPr` element ID property calculation changed; - go test updated --- xmlDrawing.go | 137 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 115 insertions(+), 22 deletions(-) (limited to 'xmlDrawing.go') diff --git a/xmlDrawing.go b/xmlDrawing.go index baab798..0ec2bc4 100644 --- a/xmlDrawing.go +++ b/xmlDrawing.go @@ -1,5 +1,7 @@ package excelize +import "encoding/xml" + // Source relationship and namespace. const ( SourceRelationship = "http://schemas.openxmlformats.org/officeDocument/2006/relationships" @@ -162,42 +164,40 @@ type xlsxTo struct { RowOff int `xml:"xdr:rowOff"` } -// xlsxClientData directly maps the clientData element. An empty element which +// xdrClientData directly maps the clientData element. An empty element which // specifies (via attributes) certain properties related to printing and // selection of the drawing object. The fLocksWithSheet attribute (either true // or false) determines whether to disable selection when the sheet is // protected, and fPrintsWithSheet attribute (either true or false) determines // whether the object is printed when the sheet is printed. -type xlsxClientData struct { +type xdrClientData struct { FLocksWithSheet bool `xml:"fLocksWithSheet,attr"` FPrintsWithSheet bool `xml:"fPrintsWithSheet,attr"` } -// xlsxCellAnchor directly maps the oneCellAnchor (One Cell Anchor Shape Size) +// xdrCellAnchor directly maps the oneCellAnchor (One Cell Anchor Shape Size) // and twoCellAnchor (Two Cell Anchor Shape Size). This element specifies a two // cell anchor placeholder for a group, a shape, or a drawing element. It moves // with cells and its extents are in EMU units. -type xlsxCellAnchor struct { - EditAs string `xml:"editAs,attr,omitempty"` - From *xlsxFrom `xml:"xdr:from"` - To *xlsxTo `xml:"xdr:to"` - Pic *xlsxPic `xml:"xdr:pic,omitempty"` - GraphicFrame string `xml:",innerxml"` - ClientData *xlsxClientData `xml:"xdr:clientData"` +type xdrCellAnchor struct { + EditAs string `xml:"editAs,attr,omitempty"` + From *xlsxFrom `xml:"xdr:from"` + To *xlsxTo `xml:"xdr:to"` + Ext *xlsxExt `xml:"xdr:ext"` + Sp *xdrSp `xml:"xdr:sp"` + Pic *xlsxPic `xml:"xdr:pic,omitempty"` + GraphicFrame string `xml:",innerxml"` + ClientData *xdrClientData `xml:"xdr:clientData"` } // xlsxWsDr directly maps the root element for a part of this content type shall // wsDr. type xlsxWsDr struct { - OneCellAnchor []*xlsxCellAnchor `xml:"xdr:oneCellAnchor"` - TwoCellAnchor []*xlsxCellAnchor `xml:"xdr:twoCellAnchor"` - Xdr string `xml:"xmlns:xdr,attr"` - A string `xml:"xmlns:a,attr"` -} - -// graphicFrame (Graphic Frame) directly maps the graphicFrame element. -type graphicFrame struct { - GraphicFrame *xlsxGraphicFrame `xml:"xdr:graphicFrame"` + XMLName xml.Name `xml:"xdr:wsDr"` + OneCellAnchor []*xdrCellAnchor `xml:"xdr:oneCellAnchor"` + TwoCellAnchor []*xdrCellAnchor `xml:"xdr:twoCellAnchor"` + Xdr string `xml:"xmlns:xdr,attr"` + A string `xml:"xmlns:a,attr"` } // xlsxGraphicFrame (Graphic Frame) directly maps the xdr:graphicFrame element. @@ -205,6 +205,7 @@ type graphicFrame struct { // a graphic that was generated by an external source and needs a container in // which to be displayed on the slide surface. type xlsxGraphicFrame struct { + XMLName xml.Name `xml:"xdr:graphicFrame"` Macro string `xml:"macro,attr"` NvGraphicFramePr xlsxNvGraphicFramePr `xml:"xdr:nvGraphicFramePr"` Xfrm xlsxXfrm `xml:"xdr:xfrm"` @@ -248,9 +249,85 @@ type xlsxChart struct { R string `xml:"xmlns:r,attr"` } -// encodeWsDr directly maps the element xdr:wsDr. -type encodeWsDr struct { - WsDr xlsxWsDr `xml:"xdr:wsDr"` +// xdrSp (Shape) directly maps the xdr:sp element. This element specifies the +// existence of a single shape. A shape can either be a preset or a custom +// geometry, defined using the SpreadsheetDrawingML framework. In addition to a +// geometry each shape can have both visual and non-visual properties attached. +// Text and corresponding styling information can also be attached to a shape. +// This shape is specified along with all other shapes within either the shape +// tree or group shape elements. +type xdrSp struct { + Macro string `xml:"macro,attr"` + Textlink string `xml:"textlink,attr"` + NvSpPr *xdrNvSpPr `xml:"xdr:nvSpPr"` + SpPr *xlsxSpPr `xml:"xdr:spPr"` + Style *xdrStyle `xml:"xdr:style"` + TxBody *xdrTxBody `xml:"xdr:txBody"` +} + +// xdrNvSpPr (Non-Visual Properties for a Shape) directly maps the xdr:nvSpPr +// element. This element specifies all non-visual properties for a shape. This +// element is a container for the non-visual identification properties, shape +// properties and application properties that are to be associated with a shape. +// This allows for additional information that does not affect the appearance of +// the shape to be stored. +type xdrNvSpPr struct { + CNvPr *xlsxCNvPr `xml:"xdr:cNvPr"` + CNvSpPr *xdrCNvSpPr `xml:"xdr:cNvSpPr"` +} + +// xdrCNvSpPr (Connection Non-Visual Shape Properties) directly maps the +// xdr:cNvSpPr element. This element specifies the set of non-visual properties +// for a connection shape. These properties specify all data about the +// connection shape which do not affect its display within a spreadsheet. +type xdrCNvSpPr struct { + TxBox bool `xml:"txBox,attr"` +} + +// xdrStyle (Shape Style) directly maps the xdr:style element. The element +// specifies the style that is applied to a shape and the corresponding +// references for each of the style components such as lines and fills. +type xdrStyle struct { + LnRef *aRef `xml:"a:lnRef"` + FillRef *aRef `xml:"a:fillRef"` + EffectRef *aRef `xml:"a:effectRef"` + FontRef *aFontRef `xml:"a:fontRef"` +} + +// aRef directly maps the a:lnRef, a:fillRef and a:effectRef element. +type aRef struct { + Idx int `xml:"idx,attr"` + ScrgbClr *aScrgbClr `xml:"a:scrgbClr"` + SchemeClr *attrValString `xml:"a:schemeClr"` + SrgbClr *attrValString `xml:"a:srgbClr"` +} + +// aScrgbClr (RGB Color Model - Percentage Variant) directly maps the a:scrgbClr +// element. This element specifies a color using the red, green, blue RGB color +// model. Each component, red, green, and blue is expressed as a percentage from +// 0% to 100%. A linear gamma of 1.0 is assumed. +type aScrgbClr struct { + R float64 `xml:"r,attr"` + G float64 `xml:"g,attr"` + B float64 `xml:"b,attr"` +} + +// aFontRef (Font Reference) directly maps the a:fontRef element. This element +// represents a reference to a themed font. When used it specifies which themed +// font to use along with a choice of color. +type aFontRef struct { + Idx string `xml:"idx,attr"` + SchemeClr *attrValString `xml:"a:schemeClr"` +} + +// xdrTxBody (Shape Text Body) directly maps the xdr:txBody element. This +// element specifies the existence of text to be contained within the +// corresponding shape. All visible text and visible text related properties are +// contained within this element. There can be multiple paragraphs and within +// paragraphs multiple runs of text. +type xdrTxBody struct { + BodyPr *aBodyPr `xml:"a:bodyPr"` + P *aP `xml:"a:p"` } // formatPicture directly maps the format settings of the picture. @@ -263,3 +340,19 @@ type formatPicture struct { XScale float64 `json:"x_scale"` YScale float64 `json:"y_scale"` } + +// formatShape directly maps the format settings of the shape. +type formatShape struct { + Type string `json:"type"` + Width int `json:"width"` + Height int `json:"height"` + Format formatPicture `json:"format"` + Text string `json:"text"` + Color formatShapeColor `json:"color"` +} + +type formatShapeColor struct { + Line string `json:"line"` + Fill string `json:"fill"` + Effect string `json:"effect"` +} -- cgit v1.2.1