xmlDecodeDrawing.go 9.8 KB

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