lib/write_xlsx/drawing.rb in write_xlsx-0.62.0 vs lib/write_xlsx/drawing.rb in write_xlsx-0.64.0

- old
+ new

@@ -87,11 +87,11 @@ # Add attribute for images. attributes << :editAs << 'oneCell' if type == 2 # Add attribute for shapes. - attributes << :editAs << shape[:edit_as] if shape && !shape[:edit_as].nil? + attributes << :editAs << shape.edit_as if shape && !shape.edit_as.nil? @writer.tag_elements('xdr:twoCellAnchor', attributes) do # Write the xdr:from element. write_from(col_from, row_from, col_from_offset, row_from_offset) # Write the xdr:from element. @@ -398,11 +398,11 @@ # # Write the <xdr:sp> element. # def write_sp(index, col_absolute, row_absolute, width, height, shape) - if shape[:connect] != 0 + if shape.connect != 0 attributes = [:macro, ''] @writer.tag_elements('xdr:cxnSp', attributes) do # Write the xdr:nvCxnSpPr element. write_nv_cxn_sp_pr(index, shape) @@ -420,11 +420,11 @@ # Write the xdr:spPr element. write_xdr_sp_pr(index, col_absolute, row_absolute, width, height, shape) # Write the xdr:txBody element. - if shape[:text] != 0 + if shape.text != 0 write_txBody(col_absolute, row_absolute, width, height, shape) end end end end @@ -433,25 +433,25 @@ # Write the <xdr:nvCxnSpPr> element. # def write_nv_cxn_sp_pr(index, shape) @writer.tag_elements('xdr:nvCxnSpPr') do - shape[:name] = [shape[:type], index].join(' ') unless shape[:name] - write_c_nv_pr(shape[:id], shape[:name]) + shape.name = [shape.type, index].join(' ') unless shape.name + write_c_nv_pr(shape.id, shape.name) @writer.tag_elements('xdr:cNvCxnSpPr') do attributes = [:noChangeShapeType, '1'] @writer.empty_tag('a:cxnSpLocks', attributes) - if shape[:start] - attributes = ['id', shape[:start], 'idx', shape[:start_index]] + if shape.start + attributes = ['id', shape.start, 'idx', shape.start_index] @writer.empty_tag('a:stCxn', attributes) end - if shape[:end] - attributes = ['id', shape[:end], 'idx', shape[:end_index]] + if shape.end + attributes = ['id', shape.end, 'idx', shape.end_index] @writer.empty_tag('a:endCxn', attributes) end end end end @@ -459,18 +459,17 @@ # # Write the <xdr:NvSpPr> element. # def write_nv_sp_pr(index, shape) attributes = [] + attributes << 'txBox' << 1 if shape.tx_box @writer.tag_elements('xdr:nvSpPr') do - shape_name = "#{shape[:type]} #{index}" - write_c_nv_pr(shape[:id], shape_name) - attributes = ['txBox', 1] if shape[:tx_box] != 0 + write_c_nv_pr(shape.id, "#{shape.type} #{index}") + @writer.tag_elements('xdr:cNvSpPr', attributes) do - attributes = [:noChangeArrowheads, '1'] - @writer.empty_tag('a:spLocks', attributes) + @writer.empty_tag('a:spLocks', [:noChangeArrowheads, '1']) end end end # @@ -483,11 +482,11 @@ # Write the xdr:blipFill element. write_blip_fill(index) # Pictures are rectangle shapes by default. shape = Shape.new - shape[:type] = 'rect' + shape.type = 'rect' # Write the xdr:spPr element. write_sp_pr(col_absolute, row_absolute, width, height, shape) end end @@ -594,13 +593,13 @@ write_a_xfrm(col_absolute, row_absolute, width, height, shape) # Write the a:prstGeom element. write_a_prst_geom(shape) - if shape[:fill].to_s.bytesize > 1 + if shape.fill.to_s.bytesize > 1 # Write the a:solidFill element. - write_a_solid_fill(shape[:fill]) + write_a_solid_fill(shape.fill) else @writer.empty_tag('a:noFill') end # Write the a:ln element. @@ -609,19 +608,19 @@ end # # Write the <a:xfrm> element. # - def write_a_xfrm(col_absolute, row_absolute, width, height, shape = {}) + def write_a_xfrm(col_absolute, row_absolute, width, height, shape = nil) attributes = [] - rotation = shape[:rotation] || 0 + rotation = shape ? shape.rotation : 0 rotation *= 60000 attributes << 'rot' << rotation if rotation != 0 - attributes << 'flipH' << 1 if ptrue?(shape[:flip_h]) - attributes << 'flipV' << 1 if ptrue?(shape[:flip_v]) + attributes << 'flipH' << 1 if shape && ptrue?(shape.flip_h) + attributes << 'flipV' << 1 if shape && ptrue?(shape.flip_v) @writer.tag_elements('a:xfrm', attributes) do # Write the a:off element. write_a_off( col_absolute, row_absolute ) # Write the a:ext element. @@ -657,11 +656,11 @@ # # Write the <a:prstGeom> element. # def write_a_prst_geom(shape = {}) attributes = [] - attributes << 'prst' << shape[:type] if shape[:type] + attributes << 'prst' << shape.type if shape.type @writer.tag_elements('a:prstGeom', attributes) do # Write the a:avLst element. write_a_av_lst(shape) end @@ -669,25 +668,25 @@ # # Write the <a:avLst> element. # def write_a_av_lst(shape = {}) - if shape[:adjustments].respond_to?(:empty?) - adjustments = shape[:adjustments] - elsif shape[:adjustments].respond_to?(:coerce) - adjustments = [shape[:adjustments]] - elsif !shape[:adjustments] + if shape.adjustments.respond_to?(:empty?) + adjustments = shape.adjustments + elsif shape.adjustments.respond_to?(:coerce) + adjustments = [shape.adjustments] + elsif !shape.adjustments adjustments = [] end if adjustments.respond_to?(:empty?) && !adjustments.empty? @writer.tag_elements('a:avLst') do i = 0 adjustments.each do |adj| i += 1 # Only connectors have multiple adjustments. - suffix = shape[:connect] != 0 ? i : '' + suffix = shape.connect != 0 ? i : '' # Scale Adjustments: 100,000 = 100%. adj_int = (adj * 1000).to_i attributes = [:name, "adj#{suffix}", :fmla, "val #{adj_int}"] @@ -712,27 +711,27 @@ # # Write the <a:ln> elements. # def write_a_ln(shape = {}) - weight = shape[:line_weight] || 0 + weight = shape.line_weight || 0 attributes = ['w', weight * 9525] @writer.tag_elements('a:ln', attributes) do - line = shape[:line] || 0 + line = shape.line || 0 if line.to_s.bytesize > 1 # Write the a:solidFill element. write_a_solid_fill(line) else @writer.empty_tag('a:noFill') end - if shape[:line_type] != '' - attributes = ['val', shape[:line_type]] + if shape.line_type != '' + attributes = ['val', shape.line_type] @writer.empty_tag('a:prstDash', attributes) end - if shape[:connect] != 0 + if shape.connect != 0 @writer.empty_tag('a:round') else attributes = ['lim', 800000] @writer.empty_tag('a:miter', attributes) end @@ -751,35 +750,35 @@ :wrap, "square", :lIns, "27432", :tIns, "22860", :rIns, "27432", :bIns, "22860", - :anchor, shape[:valign], + :anchor, shape.valign, :upright, "1" ] @writer.tag_elements('xdr:txBody') do @writer.empty_tag('a:bodyPr', attributes) @writer.empty_tag('a:lstStyle') @writer.tag_elements('a:p') do - rotation = shape[:format][:rotation] || 0 + rotation = shape.format[:rotation] || 0 rotation *= 60000 - attributes = [:algn, shape[:align], :rtl, rotation] + attributes = [:algn, shape.align, :rtl, rotation] @writer.tag_elements('a:pPr', attributes) do attributes = [:sz, "1000"] @writer.empty_tag('a:defRPr', attributes) end @writer.tag_elements('a:r') do - size = shape[:format][:size] || 8 + size = shape.format[:size] || 8 size *= 100 - bold = shape[:format][:bold] || 0 - italic = shape[:format][:italic] || 0 - underline = ptrue?(shape[:format][:underline]) ? 'sng' : 'none' - strike = ptrue?(shape[:format][:font_strikeout]) ? 'Strike' : 'noStrike' + bold = shape.format[:bold] || 0 + italic = shape.format[:italic] || 0 + underline = ptrue?(shape.format[:underline]) ? 'sng' : 'none' + strike = ptrue?(shape.format[:font_strikeout]) ? 'Strike' : 'noStrike' attributes = [ :lang, "en-US", :sz, size, :b, bold, @@ -787,26 +786,26 @@ :u, underline, :strike, strike, :baseline, 0 ] @writer.tag_elements('a:rPr', attributes) do - color = shape[:format][:color] + color = shape.format[:color] if color color = shape.get_palette_color(color) color = color.sub(/^FF/, '') # Remove leading FF from rgb for shape color. else color = '000000' end write_a_solid_fill(color) - font = shape[:format][:font] || 'Calibri' + font = shape.format[:font] || 'Calibri' attributes = [:typeface, font] @writer.empty_tag('a:latin', attributes) @writer.empty_tag('a:cs', attributes) end @writer.tag_elements('a:t') do - @writer.characters(shape[:text]) + @writer.characters(shape.text) end end end end end