xmlDrawing.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. package excelize
  2. // Source relationship and namespace.
  3. const (
  4. SourceRelationship = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
  5. SourceRelationshipChart = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"
  6. SourceRelationshipImage = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
  7. SourceRelationshipTable = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table"
  8. SourceRelationshipDrawingML = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
  9. SourceRelationshipHyperLink = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
  10. SourceRelationshipWorkSheet = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"
  11. SourceRelationshipChart201506 = "http://schemas.microsoft.com/office/drawing/2015/06/chart"
  12. SourceRelationshipChart20070802 = "http://schemas.microsoft.com/office/drawing/2007/8/2/chart"
  13. SourceRelationshipChart2014 = "http://schemas.microsoft.com/office/drawing/2014/chart"
  14. SourceRelationshipCompatibility = "http://schemas.openxmlformats.org/markup-compatibility/2006"
  15. NameSpaceDrawingML = "http://schemas.openxmlformats.org/drawingml/2006/main"
  16. NameSpaceDrawingMLChart = "http://schemas.openxmlformats.org/drawingml/2006/chart"
  17. NameSpaceDrawingMLSpreadSheet = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
  18. NameSpaceSpreadSheet = "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
  19. NameSpaceXML = "http://www.w3.org/XML/1998/namespace"
  20. )
  21. var supportImageTypes = map[string]string{".gif": ".gif", ".jpg": ".jpeg", ".jpeg": ".jpeg", ".png": ".png"}
  22. // xlsxCNvPr directly maps the cNvPr (Non-Visual Drawing Properties). This
  23. // element specifies non-visual canvas properties. This allows for additional
  24. // information that does not affect the appearance of the picture to be stored.
  25. type xlsxCNvPr struct {
  26. ID int `xml:"id,attr"`
  27. Name string `xml:"name,attr"`
  28. Descr string `xml:"descr,attr"`
  29. Title string `xml:"title,attr,omitempty"`
  30. }
  31. // xlsxPicLocks directly maps the picLocks (Picture Locks). This element
  32. // specifies all locking properties for a graphic frame. These properties inform
  33. // the generating application about specific properties that have been
  34. // previously locked and thus should not be changed.
  35. type xlsxPicLocks struct {
  36. NoAdjustHandles bool `xml:"noAdjustHandles,attr,omitempty"`
  37. NoChangeArrowheads bool `xml:"noChangeArrowheads,attr,omitempty"`
  38. NoChangeAspect bool `xml:"noChangeAspect,attr"`
  39. NoChangeShapeType bool `xml:"noChangeShapeType,attr,omitempty"`
  40. NoCrop bool `xml:"noCrop,attr,omitempty"`
  41. NoEditPoints bool `xml:"noEditPoints,attr,omitempty"`
  42. NoGrp bool `xml:"noGrp,attr,omitempty"`
  43. NoMove bool `xml:"noMove,attr,omitempty"`
  44. NoResize bool `xml:"noResize,attr,omitempty"`
  45. NoRot bool `xml:"noRot,attr,omitempty"`
  46. NoSelect bool `xml:"noSelect,attr,omitempty"`
  47. }
  48. // xlsxBlip directly maps the blip element in the namespace
  49. // http://purl.oclc.org/ooxml/officeDoc ument/relationships - This element
  50. // specifies the existence of an image (binary large image or picture) and
  51. // contains a reference to the image data.
  52. type xlsxBlip struct {
  53. Embed string `xml:"r:embed,attr"`
  54. Cstate string `xml:"cstate,attr,omitempty"`
  55. R string `xml:"xmlns:r,attr"`
  56. }
  57. // xlsxStretch directly maps the stretch element. This element specifies that a
  58. // BLIP should be stretched to fill the target rectangle. The other option is a
  59. // tile where a BLIP is tiled to fill the available area.
  60. type xlsxStretch struct {
  61. FillRect string `xml:"a:fillRect"`
  62. }
  63. // xlsxOff directly maps the colOff and rowOff element. This element is used to
  64. // specify the column offset within a cell.
  65. type xlsxOff struct {
  66. X int `xml:"x,attr"`
  67. Y int `xml:"y,attr"`
  68. }
  69. // xlsxExt directly maps the ext element.
  70. type xlsxExt struct {
  71. Cx int `xml:"cx,attr"`
  72. Cy int `xml:"cy,attr"`
  73. }
  74. // xlsxPrstGeom directly maps the prstGeom (Preset geometry). This element
  75. // specifies when a preset geometric shape should be used instead of a custom
  76. // geometric shape. The generating application should be able to render all
  77. // preset geometries enumerated in the ST_ShapeType list.
  78. type xlsxPrstGeom struct {
  79. Prst string `xml:"prst,attr"`
  80. }
  81. // xlsxXfrm directly maps the xfrm (2D Transform for Graphic Frame). This
  82. // element specifies the transform to be applied to the corresponding graphic
  83. // frame. This transformation is applied to the graphic frame just as it would
  84. // be for a shape or group shape.
  85. type xlsxXfrm struct {
  86. Off xlsxOff `xml:"a:off"`
  87. Ext xlsxExt `xml:"a:ext"`
  88. }
  89. // xlsxCNvPicPr directly maps the cNvPicPr (Non-Visual Picture Drawing
  90. // Properties). This element specifies the non-visual properties for the picture
  91. // canvas. These properties are to be used by the generating application to
  92. // determine how certain properties are to be changed for the picture object in
  93. // question.
  94. type xlsxCNvPicPr struct {
  95. PicLocks xlsxPicLocks `xml:"a:picLocks"`
  96. }
  97. // directly maps the nvPicPr (Non-Visual Properties for a Picture). This element
  98. // specifies all non-visual properties for a picture. This element is a
  99. // container for the non-visual identification properties, shape properties and
  100. // application properties that are to be associated with a picture. This allows
  101. // for additional information that does not affect the appearance of the picture
  102. // to be stored.
  103. type xlsxNvPicPr struct {
  104. CNvPr xlsxCNvPr `xml:"xdr:cNvPr"`
  105. CNvPicPr xlsxCNvPicPr `xml:"xdr:cNvPicPr"`
  106. }
  107. // xlsxBlipFill directly maps the blipFill (Picture Fill). This element
  108. // specifies the kind of picture fill that the picture object has. Because a
  109. // picture has a picture fill already by default, it is possible to have two
  110. // fills specified for a picture object.
  111. type xlsxBlipFill struct {
  112. Blip xlsxBlip `xml:"a:blip"`
  113. Stretch xlsxStretch `xml:"a:stretch"`
  114. }
  115. // xlsxSpPr directly maps the spPr (Shape Properties). This element specifies
  116. // the visual shape properties that can be applied to a picture. These are the
  117. // same properties that are allowed to describe the visual properties of a shape
  118. // but are used here to describe the visual appearance of a picture within a
  119. // document.
  120. type xlsxSpPr struct {
  121. Xfrm xlsxXfrm `xml:"a:xfrm"`
  122. PrstGeom xlsxPrstGeom `xml:"a:prstGeom"`
  123. }
  124. // xlsxPic elements encompass the definition of pictures within the DrawingML
  125. // framework. While pictures are in many ways very similar to shapes they have
  126. // specific properties that are unique in order to optimize for picture-
  127. // specific scenarios.
  128. type xlsxPic struct {
  129. NvPicPr xlsxNvPicPr `xml:"xdr:nvPicPr"`
  130. BlipFill xlsxBlipFill `xml:"xdr:blipFill"`
  131. SpPr xlsxSpPr `xml:"xdr:spPr"`
  132. }
  133. // xlsxFrom specifies the starting anchor.
  134. type xlsxFrom struct {
  135. Col int `xml:"xdr:col"`
  136. ColOff int `xml:"xdr:colOff"`
  137. Row int `xml:"xdr:row"`
  138. RowOff int `xml:"xdr:rowOff"`
  139. }
  140. // xlsxTo directly specifies the ending anchor.
  141. type xlsxTo struct {
  142. Col int `xml:"xdr:col"`
  143. ColOff int `xml:"xdr:colOff"`
  144. Row int `xml:"xdr:row"`
  145. RowOff int `xml:"xdr:rowOff"`
  146. }
  147. // xlsxClientData directly maps the clientData element. An empty element which
  148. // specifies (via attributes) certain properties related to printing and
  149. // selection of the drawing object. The fLocksWithSheet attribute (either true
  150. // or false) determines whether to disable selection when the sheet is
  151. // protected, and fPrintsWithSheet attribute (either true or false) determines
  152. // whether the object is printed when the sheet is printed.
  153. type xlsxClientData struct {
  154. FLocksWithSheet bool `xml:"fLocksWithSheet,attr"`
  155. FPrintsWithSheet bool `xml:"fPrintsWithSheet,attr"`
  156. }
  157. // xlsxCellAnchor directly maps the oneCellAnchor (One Cell Anchor Shape Size)
  158. // and twoCellAnchor (Two Cell Anchor Shape Size). This element specifies a two
  159. // cell anchor placeholder for a group, a shape, or a drawing element. It moves
  160. // with cells and its extents are in EMU units.
  161. type xlsxCellAnchor struct {
  162. EditAs string `xml:"editAs,attr,omitempty"`
  163. From *xlsxFrom `xml:"xdr:from"`
  164. To *xlsxTo `xml:"xdr:to"`
  165. Pic *xlsxPic `xml:"xdr:pic,omitempty"`
  166. GraphicFrame string `xml:",innerxml"`
  167. ClientData *xlsxClientData `xml:"xdr:clientData"`
  168. }
  169. // xlsxWsDr directly maps the root element for a part of this content type shall
  170. // wsDr.
  171. type xlsxWsDr struct {
  172. OneCellAnchor []*xlsxCellAnchor `xml:"xdr:oneCellAnchor"`
  173. TwoCellAnchor []*xlsxCellAnchor `xml:"xdr:twoCellAnchor"`
  174. Xdr string `xml:"xmlns:xdr,attr"`
  175. A string `xml:"xmlns:a,attr"`
  176. }
  177. // graphicFrame (Graphic Frame) directly maps the graphicFrame element.
  178. type graphicFrame struct {
  179. GraphicFrame *xlsxGraphicFrame `xml:"xdr:graphicFrame"`
  180. }
  181. // xlsxGraphicFrame (Graphic Frame) directly maps the xdr:graphicFrame element.
  182. // This element specifies the existence of a graphics frame. This frame contains
  183. // a graphic that was generated by an external source and needs a container in
  184. // which to be displayed on the slide surface.
  185. type xlsxGraphicFrame struct {
  186. Macro string `xml:"macro,attr"`
  187. NvGraphicFramePr xlsxNvGraphicFramePr `xml:"xdr:nvGraphicFramePr"`
  188. Xfrm xlsxXfrm `xml:"xdr:xfrm"`
  189. Graphic *xlsxGraphic `xml:"a:graphic"`
  190. }
  191. // xlsxNvGraphicFramePr (Non-Visual Properties for a Graphic Frame) directly
  192. // maps the xdr:nvGraphicFramePr element. This element specifies all non-visual
  193. // properties for a graphic frame. This element is a container for the non-
  194. // visual identification properties, shape properties and application properties
  195. // that are to be associated with a graphic frame. This allows for additional
  196. // information that does not affect the appearance of the graphic frame to be
  197. // stored.
  198. type xlsxNvGraphicFramePr struct {
  199. CNvPr *xlsxCNvPr `xml:"xdr:cNvPr"`
  200. ChicNvGraphicFramePr string `xml:"xdr:cNvGraphicFramePr"`
  201. }
  202. // xlsxGraphic (Graphic Object) directly maps the a:graphic element. This
  203. // element specifies the existence of a single graphic object. Document authors
  204. // should refer to this element when they wish to persist a graphical object of
  205. // some kind. The specification for this graphical object is provided entirely
  206. // by the document author and referenced within the graphicData child element.
  207. type xlsxGraphic struct {
  208. GraphicData *xlsxGraphicData `xml:"a:graphicData"`
  209. }
  210. // xlsxGraphicData (Graphic Object Data) directly maps the a:graphicData
  211. // element. This element specifies the reference to a graphic object within the
  212. // document. This graphic object is provided entirely by the document authors
  213. // who choose to persist this data within the document.
  214. type xlsxGraphicData struct {
  215. URI string `xml:"uri,attr"`
  216. Chart *xlsxChart `xml:"c:chart,omitempty"`
  217. }
  218. // xlsxChart (Chart) directly maps the c:chart element.
  219. type xlsxChart struct {
  220. C string `xml:"xmlns:c,attr"`
  221. RID string `xml:"r:id,attr"`
  222. R string `xml:"xmlns:r,attr"`
  223. }
  224. // encodeWsDr directly maps the element xdr:wsDr.
  225. type encodeWsDr struct {
  226. WsDr xlsxWsDr `xml:"xdr:wsDr"`
  227. }
  228. // formatPicture directly maps the format settings of the picture.
  229. type formatPicture struct {
  230. FPrintsWithSheet bool `json:"print_obj"`
  231. FLocksWithSheet bool `json:"locked"`
  232. NoChangeAspect bool `json:"lock_aspect_ratio"`
  233. OffsetX int `json:"x_offset"`
  234. OffsetY int `json:"y_offset"`
  235. XScale float64 `json:"x_scale"`
  236. YScale float64 `json:"y_scale"`
  237. }