xmlDecodeDrawing.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
  2. // this source code is governed by a BSD-style license that can be found in
  3. // the LICENSE file.
  4. //
  5. // Package excelize providing a set of functions that allow you to write to
  6. // and read from XLSX / XLSM / XLTM files. Supports reading and writing
  7. // spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
  8. // complex components by high compatibility, and provided streaming API for
  9. // generating or reading data from a worksheet with huge amounts of data. This
  10. // library needs Go version 1.15 or later.
  11. package excelize
  12. import "encoding/xml"
  13. // decodeCellAnchor directly maps the oneCellAnchor (One Cell Anchor Shape
  14. // Size) and twoCellAnchor (Two Cell Anchor Shape Size). This element
  15. // specifies a two cell anchor placeholder for a group, a shape, or a drawing
  16. // element. It moves with cells and its extents are in EMU units.
  17. type decodeCellAnchor struct {
  18. EditAs string `xml:"editAs,attr,omitempty"`
  19. From *decodeFrom `xml:"from"`
  20. To *decodeTo `xml:"to"`
  21. Sp *decodeSp `xml:"sp"`
  22. ClientData *decodeClientData `xml:"clientData"`
  23. Content string `xml:",innerxml"`
  24. }
  25. // xdrSp (Shape) directly maps the sp element. This element specifies the
  26. // existence of a single shape. A shape can either be a preset or a custom
  27. // geometry, defined using the SpreadsheetDrawingML framework. In addition to
  28. // a geometry each shape can have both visual and non-visual properties
  29. // attached. Text and corresponding styling information can also be attached
  30. // to a shape. This shape is specified along with all other shapes within
  31. // either the shape tree or group shape elements.
  32. type decodeSp struct {
  33. NvSpPr *decodeNvSpPr `xml:"nvSpPr"`
  34. SpPr *decodeSpPr `xml:"spPr"`
  35. }
  36. // decodeSp (Non-Visual Properties for a Shape) directly maps the nvSpPr
  37. // element. This element specifies all non-visual properties for a shape. This
  38. // element is a container for the non-visual identification properties, shape
  39. // properties and application properties that are to be associated with a
  40. // shape. This allows for additional information that does not affect the
  41. // appearance of the shape to be stored.
  42. type decodeNvSpPr struct {
  43. CNvPr *decodeCNvPr `xml:"cNvPr"`
  44. ExtLst *decodeExt `xml:"extLst"`
  45. CNvSpPr *decodeCNvSpPr `xml:"cNvSpPr"`
  46. }
  47. // decodeCNvSpPr (Connection Non-Visual Shape Properties) directly maps the
  48. // cNvSpPr element. This element specifies the set of non-visual properties
  49. // for a connection shape. These properties specify all data about the
  50. // connection shape which do not affect its display within a spreadsheet.
  51. type decodeCNvSpPr struct {
  52. TxBox bool `xml:"txBox,attr"`
  53. }
  54. // decodeWsDr directly maps the root element for a part of this content type
  55. // shall wsDr. In order to solve the problem that the label structure is
  56. // changed after serialization and deserialization, two different structures
  57. // are defined. decodeWsDr just for deserialization.
  58. type decodeWsDr struct {
  59. A string `xml:"xmlns a,attr"`
  60. Xdr string `xml:"xmlns xdr,attr"`
  61. R string `xml:"xmlns r,attr"`
  62. OneCellAnchor []*decodeCellAnchor `xml:"oneCellAnchor,omitempty"`
  63. TwoCellAnchor []*decodeCellAnchor `xml:"twoCellAnchor,omitempty"`
  64. XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing wsDr,omitempty"`
  65. }
  66. // decodeTwoCellAnchor directly maps the oneCellAnchor (One Cell Anchor Shape
  67. // Size) and twoCellAnchor (Two Cell Anchor Shape Size). This element
  68. // specifies a two cell anchor placeholder for a group, a shape, or a drawing
  69. // element. It moves with cells and its extents are in EMU units.
  70. type decodeTwoCellAnchor struct {
  71. From *decodeFrom `xml:"from"`
  72. To *decodeTo `xml:"to"`
  73. Pic *decodePic `xml:"pic,omitempty"`
  74. ClientData *decodeClientData `xml:"clientData"`
  75. }
  76. // decodeCNvPr directly maps the cNvPr (Non-Visual Drawing Properties). This
  77. // element specifies non-visual canvas properties. This allows for additional
  78. // information that does not affect the appearance of the picture to be
  79. // stored.
  80. type decodeCNvPr struct {
  81. ID int `xml:"id,attr"`
  82. Name string `xml:"name,attr"`
  83. Descr string `xml:"descr,attr"`
  84. Title string `xml:"title,attr,omitempty"`
  85. }
  86. // decodePicLocks directly maps the picLocks (Picture Locks). This element
  87. // specifies all locking properties for a graphic frame. These properties
  88. // inform the generating application about specific properties that have been
  89. // previously locked and thus should not be changed.
  90. type decodePicLocks struct {
  91. NoAdjustHandles bool `xml:"noAdjustHandles,attr,omitempty"`
  92. NoChangeArrowheads bool `xml:"noChangeArrowheads,attr,omitempty"`
  93. NoChangeAspect bool `xml:"noChangeAspect,attr"`
  94. NoChangeShapeType bool `xml:"noChangeShapeType,attr,omitempty"`
  95. NoCrop bool `xml:"noCrop,attr,omitempty"`
  96. NoEditPoints bool `xml:"noEditPoints,attr,omitempty"`
  97. NoGrp bool `xml:"noGrp,attr,omitempty"`
  98. NoMove bool `xml:"noMove,attr,omitempty"`
  99. NoResize bool `xml:"noResize,attr,omitempty"`
  100. NoRot bool `xml:"noRot,attr,omitempty"`
  101. NoSelect bool `xml:"noSelect,attr,omitempty"`
  102. }
  103. // decodeBlip directly maps the blip element in the namespace
  104. // http://purl.oclc.org/ooxml/officeDoc ument/relationships - This element
  105. // specifies the existence of an image (binary large image or picture) and
  106. // contains a reference to the image data.
  107. type decodeBlip struct {
  108. Embed string `xml:"embed,attr"`
  109. Cstate string `xml:"cstate,attr,omitempty"`
  110. R string `xml:"r,attr"`
  111. }
  112. // decodeStretch directly maps the stretch element. This element specifies
  113. // that a BLIP should be stretched to fill the target rectangle. The other
  114. // option is a tile where a BLIP is tiled to fill the available area.
  115. type decodeStretch struct {
  116. FillRect string `xml:"fillRect"`
  117. }
  118. // decodeOff directly maps the colOff and rowOff element. This element is used
  119. // to specify the column offset within a cell.
  120. type decodeOff struct {
  121. X int `xml:"x,attr"`
  122. Y int `xml:"y,attr"`
  123. }
  124. // decodeExt directly maps the ext element.
  125. type decodeExt struct {
  126. Cx int `xml:"cx,attr"`
  127. Cy int `xml:"cy,attr"`
  128. }
  129. // decodePrstGeom directly maps the prstGeom (Preset geometry). This element
  130. // specifies when a preset geometric shape should be used instead of a custom
  131. // geometric shape. The generating application should be able to render all
  132. // preset geometries enumerated in the ST_ShapeType list.
  133. type decodePrstGeom struct {
  134. Prst string `xml:"prst,attr"`
  135. }
  136. // decodeXfrm directly maps the xfrm (2D Transform for Graphic Frame). This
  137. // element specifies the transform to be applied to the corresponding graphic
  138. // frame. This transformation is applied to the graphic frame just as it would
  139. // be for a shape or group shape.
  140. type decodeXfrm struct {
  141. Off decodeOff `xml:"off"`
  142. Ext decodeExt `xml:"ext"`
  143. }
  144. // decodeCNvPicPr directly maps the cNvPicPr (Non-Visual Picture Drawing
  145. // Properties). This element specifies the non-visual properties for the picture
  146. // canvas. These properties are to be used by the generating application to
  147. // determine how certain properties are to be changed for the picture object in
  148. // question.
  149. type decodeCNvPicPr struct {
  150. PicLocks decodePicLocks `xml:"picLocks"`
  151. }
  152. // directly maps the nvPicPr (Non-Visual Properties for a Picture). This
  153. // element specifies all non-visual properties for a picture. This element is
  154. // a container for the non-visual identification properties, shape properties
  155. // and application properties that are to be associated with a picture. This
  156. // allows for additional information that does not affect the appearance of
  157. // the picture to be stored.
  158. type decodeNvPicPr struct {
  159. CNvPr decodeCNvPr `xml:"cNvPr"`
  160. CNvPicPr decodeCNvPicPr `xml:"cNvPicPr"`
  161. }
  162. // decodeBlipFill directly maps the blipFill (Picture Fill). This element
  163. // specifies the kind of picture fill that the picture object has. Because a
  164. // picture has a picture fill already by default, it is possible to have two
  165. // fills specified for a picture object.
  166. type decodeBlipFill struct {
  167. Blip decodeBlip `xml:"blip"`
  168. Stretch decodeStretch `xml:"stretch"`
  169. }
  170. // decodeSpPr directly maps the spPr (Shape Properties). This element
  171. // specifies the visual shape properties that can be applied to a picture.
  172. // These are the same properties that are allowed to describe the visual
  173. // properties of a shape but are used here to describe the visual appearance
  174. // of a picture within a document.
  175. type decodeSpPr struct {
  176. Xfrm decodeXfrm `xml:"xfrm"`
  177. PrstGeom decodePrstGeom `xml:"prstGeom"`
  178. }
  179. // decodePic elements encompass the definition of pictures within the
  180. // DrawingML framework. While pictures are in many ways very similar to shapes
  181. // they have specific properties that are unique in order to optimize for
  182. // picture- specific scenarios.
  183. type decodePic struct {
  184. NvPicPr decodeNvPicPr `xml:"nvPicPr"`
  185. BlipFill decodeBlipFill `xml:"blipFill"`
  186. SpPr decodeSpPr `xml:"spPr"`
  187. }
  188. // decodeFrom specifies the starting anchor.
  189. type decodeFrom struct {
  190. Col int `xml:"col"`
  191. ColOff int `xml:"colOff"`
  192. Row int `xml:"row"`
  193. RowOff int `xml:"rowOff"`
  194. }
  195. // decodeTo directly specifies the ending anchor.
  196. type decodeTo struct {
  197. Col int `xml:"col"`
  198. ColOff int `xml:"colOff"`
  199. Row int `xml:"row"`
  200. RowOff int `xml:"rowOff"`
  201. }
  202. // decodeClientData directly maps the clientData element. An empty element
  203. // which specifies (via attributes) certain properties related to printing and
  204. // selection of the drawing object. The fLocksWithSheet attribute (either true
  205. // or false) determines whether to disable selection when the sheet is
  206. // protected, and fPrintsWithSheet attribute (either true or false) determines
  207. // whether the object is printed when the sheet is printed.
  208. type decodeClientData struct {
  209. FLocksWithSheet bool `xml:"fLocksWithSheet,attr"`
  210. FPrintsWithSheet bool `xml:"fPrintsWithSheet,attr"`
  211. }