@@ -31,25 +31,19 @@ func parseShapeOptions(opts *Shape) (*Shape, error) {
3131 if opts .Height == 0 {
3232 opts .Height = defaultShapeSize
3333 }
34- if opts .Format .PrintObject == nil {
35- opts .Format .PrintObject = boolPtr (true )
36- }
37- if opts .Format .Locked == nil {
38- opts .Format .Locked = boolPtr (false )
39- }
40- if opts .Format .ScaleX == 0 {
41- opts .Format .ScaleX = defaultDrawingScale
42- }
43- if opts .Format .ScaleY == 0 {
44- opts .Format .ScaleY = defaultDrawingScale
45- }
4634 if opts .Line .Width == nil {
4735 opts .Line .Width = float64Ptr (defaultShapeLineWidth )
4836 }
4937 if opts .Fill .Transparency < 0 || 100 < opts .Fill .Transparency {
5038 return opts , ErrTransparency
5139 }
52- return opts , nil
40+ format := opts .Format
41+ graphicOptions , err := format .parseGraphicOptions (nil )
42+ if err != nil {
43+ return opts , err
44+ }
45+ opts .Format = * graphicOptions
46+ return opts , err
5347}
5448
5549// AddShape provides the method to add shape in a sheet by given worksheet
@@ -325,9 +319,9 @@ func (f *File) AddShape(sheet string, opts *Shape) error {
325319 return f .addContentTypePart (drawingID , "drawings" )
326320}
327321
328- // twoCellAnchorShape create a two cell anchor shape size placeholder for a
322+ // cellAnchorShape create a two cell anchor shape size placeholder for a
329323// group, a shape, or a drawing element.
330- func (f * File ) twoCellAnchorShape (sheet , drawingXML , cell string , width , height uint , format GraphicOptions ) (* xlsxWsDr , * xdrCellAnchor , int , error ) {
324+ func (f * File ) cellAnchorShape (sheet , drawingXML , cell string , width , height uint , format GraphicOptions ) (* xlsxWsDr , * xdrCellAnchor , int , error ) {
331325 fromCol , fromRow , err := CellNameToCoordinates (cell )
332326 if err != nil {
333327 return nil , nil , 0 , err
@@ -339,27 +333,36 @@ func (f *File) twoCellAnchorShape(sheet, drawingXML, cell string, width, height
339333 if err != nil {
340334 return content , nil , cNvPrID , err
341335 }
342- twoCellAnchor := xdrCellAnchor {}
343- twoCellAnchor .EditAs = format .Positioning
336+ cellAnchor := xdrCellAnchor {}
337+ cellAnchor .EditAs = format .Positioning
344338 from := xlsxFrom {}
345339 from .Col = colStart
346340 from .ColOff = x1 * EMU
347341 from .Row = rowStart
348342 from .RowOff = y1 * EMU
349- to := xlsxTo {}
350- to .Col = colEnd
351- to .ColOff = x2 * EMU
352- to .Row = rowEnd
353- to .RowOff = y2 * EMU
354- twoCellAnchor .From = & from
355- twoCellAnchor .To = & to
356- return content , & twoCellAnchor , cNvPrID , err
343+ cellAnchor .From = & from
344+ if format .Positioning != "oneCell" {
345+ to := xlsxTo {}
346+ to .Col = colEnd
347+ to .ColOff = x2 * EMU
348+ to .Row = rowEnd
349+ to .RowOff = y2 * EMU
350+ cellAnchor .To = & to
351+ cellAnchor .EditAs = format .Positioning
352+ }
353+ if format .Positioning == "oneCell" {
354+ cellAnchor .Ext = & xlsxPositiveSize2D {
355+ Cx : x2 * EMU ,
356+ Cy : y2 * EMU ,
357+ }
358+ }
359+ return content , & cellAnchor , cNvPrID , err
357360}
358361
359362// addDrawingShape provides a function to add preset geometry by given sheet,
360363// drawingXML and format sets.
361364func (f * File ) addDrawingShape (sheet , drawingXML , cell string , opts * Shape ) error {
362- content , twoCellAnchor , cNvPrID , err := f .twoCellAnchorShape (
365+ content , cellAnchor , cNvPrID , err := f .cellAnchorShape (
363366 sheet , drawingXML , cell , opts .Width , opts .Height , opts .Format )
364367 if err != nil {
365368 return err
@@ -380,6 +383,12 @@ func (f *File) addDrawingShape(sheet, drawingXML, cell string, opts *Shape) erro
380383 },
381384 },
382385 SpPr : & xlsxSpPr {
386+ Xfrm : xlsxXfrm {
387+ Ext : xlsxPositiveSize2D {
388+ Cx : int (opts .Width ) * EMU ,
389+ Cy : int (opts .Height ) * EMU ,
390+ },
391+ },
383392 PrstGeom : xlsxPrstGeom {
384393 Prst : opts .Type ,
385394 },
@@ -476,12 +485,16 @@ func (f *File) addDrawingShape(sheet, drawingXML, cell string, opts *Shape) erro
476485 }
477486 shape .TxBody .P = append (shape .TxBody .P , paragraph )
478487 }
479- twoCellAnchor .Sp = & shape
480- twoCellAnchor .ClientData = & xdrClientData {
488+ cellAnchor .Sp = & shape
489+ cellAnchor .ClientData = & xdrClientData {
481490 FLocksWithSheet : * opts .Format .Locked ,
482491 FPrintsWithSheet : * opts .Format .PrintObject ,
483492 }
484- content .TwoCellAnchor = append (content .TwoCellAnchor , twoCellAnchor )
493+ if opts .Format .Positioning == "oneCell" {
494+ content .OneCellAnchor = append (content .OneCellAnchor , cellAnchor )
495+ } else {
496+ content .TwoCellAnchor = append (content .TwoCellAnchor , cellAnchor )
497+ }
485498 f .Drawings .Store (drawingXML , content )
486499 return err
487500}
0 commit comments