xmlDrawing.go 11 KB

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