lib/write_xlsx/drawing.rb in write_xlsx-1.00.0 vs lib/write_xlsx/drawing.rb in write_xlsx-1.01.0

- old
+ new

@@ -2,10 +2,19 @@ require 'write_xlsx/package/xml_writer_simple' require 'write_xlsx/utility' module Writexlsx class Drawing + attr_accessor :type, :dimensions, :width, :height, :name, :shape, :anchor + + def initialize(type, dimensions, width, height, name, shape, anchor) + @type, @dimensions, @width, @height, @name, @shape, @anchor = + type, dimensions, width, height, name, shape, anchor + end + end + + class Drawings include Writexlsx::Utility attr_writer :embedded, :orientation def initialize @@ -30,14 +39,14 @@ write_xml_declaration do # Write the xdr:wsDr element. write_drawing_workspace do if @embedded index = 0 - @drawings.each do |dimensions| + @drawings.each do |drawing| # Write the xdr:twoCellAnchor element. index += 1 - write_two_cell_anchor(index, *(dimensions.flatten)) + write_two_cell_anchor(index, drawing) end else # Write the xdr:absoluteAnchor element. write_absolute_anchor(1) end @@ -46,12 +55,12 @@ end # # Add a chart, image or shape sub object to the drawing. # - def add_drawing_object(*args) - @drawings << args.flatten + def add_drawing_object(drawing) + @drawings << drawing end private # @@ -69,17 +78,28 @@ # # Write the <xdr:twoCellAnchor> element. # def write_two_cell_anchor(*args) - index, type, col_from, row_from, col_from_offset, row_from_offset, - col_to, row_to, col_to_offset, row_to_offset, col_absolute, row_absolute, - width, height, description, shape = args + index, drawing = args + type = drawing.type + width = drawing.width + height = drawing.height + description = drawing.name + shape = drawing.shape + anchor = drawing.anchor + col_from, row_from, col_from_offset, row_from_offset, + col_to, row_to, col_to_offset, row_to_offset, col_absolute, row_absolute = drawing.dimensions + attributes = [] # Add attribute for images. - attributes << [:editAs, 'oneCell'] if type == 2 + if anchor == 2 + attributes << [:editAs, 'oneCell'] + elsif anchor == 3 + attributes << [:editAs, 'absolute'] + end # Add attribute for shapes. attributes << [:editAs, shape.edit_as] if shape && shape.edit_as @writer.tag_elements('xdr:twoCellAnchor', attributes) do