Class: Writexlsx::Drawing

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/write_xlsx/drawing.rb

Constant Summary

Constants included from Utility

Utility::CHAR_WIDTHS, Utility::COL_MAX, Utility::DEFAULT_COL_PIXELS, Utility::MAX_DIGIT_WIDTH, Utility::PADDING, Utility::PERL_TRUE_VALUES, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utility

#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #color, #convert_date_time, #convert_font_args, #dash_types, delete_files, #escape_url, #fill_properties, #float_to_str, #get_font_latin_attributes, #get_font_style_attributes, #layout_properties, #legend_properties, #line_fill_properties, #line_properties, #palette_color_from_index, #params_to_font, #pattern_properties, #pixels_to_points, #ptrue?, #put_deprecate_message, #quote_sheetname, #r_id_attributes, #row_col_notation, #shape_style_base, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #v_shape_attributes_base, #v_shape_style_base, #value_or_raise, #write_a_body_pr, #write_a_def_rpr, #write_a_end_para_rpr, #write_a_lst_style, #write_a_p_formula, #write_a_p_pr_formula, #write_a_srgb_clr, #write_anchor, #write_auto_fill, #write_color, #write_comment_path, #write_def_rpr_r_pr_common, #write_div, #write_fill, #write_font, #write_stroke, #write_tx_pr, #write_xml_declaration, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xl_string_pixel_width, #xml_str

Constructor Details

#initialize(type, dimensions, width, height, shape, anchor, rel_index = nil, url_rel_index = nil, tip = nil, name = nil, description = nil, decorative = nil) ⇒ Drawing

Returns a new instance of Drawing.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/write_xlsx/drawing.rb', line 15

def initialize(type, dimensions, width, height, shape, anchor, rel_index = nil, url_rel_index = nil, tip = nil, name = nil, description = nil, decorative = nil)
  @type = type
  @dimensions = dimensions
  @width = width
  @height = height
  @shape = shape
  @anchor = anchor
  @rel_index = rel_index
  @url_rel_index = url_rel_index
  @tip = tip
  @name = name
  @description = description
  @decorative = decorative
end

Instance Attribute Details

#anchorObject

Returns the value of attribute anchor.



11
12
13
# File 'lib/write_xlsx/drawing.rb', line 11

def anchor
  @anchor
end

#decorativeObject (readonly)

Returns the value of attribute decorative.



12
13
14
# File 'lib/write_xlsx/drawing.rb', line 12

def decorative
  @decorative
end

#descriptionObject

Returns the value of attribute description.



11
12
13
# File 'lib/write_xlsx/drawing.rb', line 11

def description
  @description
end

#dimensionsObject

Returns the value of attribute dimensions.



11
12
13
# File 'lib/write_xlsx/drawing.rb', line 11

def dimensions
  @dimensions
end

#embedded=(value) ⇒ Object (writeonly)

Sets the attribute embedded

Parameters:

  • value

    the value to set the attribute embedded to.



13
14
15
# File 'lib/write_xlsx/drawing.rb', line 13

def embedded=(value)
  @embedded = value
end

#heightObject

Returns the value of attribute height.



11
12
13
# File 'lib/write_xlsx/drawing.rb', line 11

def height
  @height
end

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/write_xlsx/drawing.rb', line 11

def name
  @name
end

#orientation=(value) ⇒ Object (writeonly)

Sets the attribute orientation

Parameters:

  • value

    the value to set the attribute orientation to.



13
14
15
# File 'lib/write_xlsx/drawing.rb', line 13

def orientation=(value)
  @orientation = value
end

#rel_indexObject

Returns the value of attribute rel_index.



11
12
13
# File 'lib/write_xlsx/drawing.rb', line 11

def rel_index
  @rel_index
end

#shapeObject

Returns the value of attribute shape.



11
12
13
# File 'lib/write_xlsx/drawing.rb', line 11

def shape
  @shape
end

#tipObject (readonly)

Returns the value of attribute tip.



12
13
14
# File 'lib/write_xlsx/drawing.rb', line 12

def tip
  @tip
end

#typeObject

Returns the value of attribute type.



11
12
13
# File 'lib/write_xlsx/drawing.rb', line 11

def type
  @type
end

#url_rel_indexObject

Returns the value of attribute url_rel_index.



11
12
13
# File 'lib/write_xlsx/drawing.rb', line 11

def url_rel_index
  @url_rel_index
end

#widthObject

Returns the value of attribute width.



11
12
13
# File 'lib/write_xlsx/drawing.rb', line 11

def width
  @width
end

#writer=(value) ⇒ Object (writeonly)

Sets the attribute writer

Parameters:

  • value

    the value to set the attribute writer to.



13
14
15
# File 'lib/write_xlsx/drawing.rb', line 13

def writer=(value)
  @writer = value
end

Instance Method Details

#write_a16_creation_idObject

Write the <a16:creationId> element.



315
316
317
318
319
320
321
322
323
324
325
# File 'lib/write_xlsx/drawing.rb', line 315

def write_a16_creation_id
  xmlns_a_16 = 'http://schemas.microsoft.com/office/drawing/2014/main'
  id         = '{00000000-0008-0000-0000-000002000000}'

  attributes = [
    ['xmlns:a16', xmlns_a_16],
    ['id',        id]
  ]

  @writer.empty_tag('a16:creationId', attributes)
end

#write_a_av_lst(shape = {}) ⇒ Object

Write the <a:avLst> element.



724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
# File 'lib/write_xlsx/drawing.rb', line 724

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
    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

        # Scale Adjustments: 100,000 = 100%.
        adj_int = (adj * 1000).to_i

        attributes = [
          [:name, "adj#{suffix}"],
          [:fmla, "val #{adj_int}"]
        ]
        @writer.empty_tag('a:gd', attributes)
      end
    end
  else
    @writer.empty_tag('a:avLst')
  end
end

#write_a_blip(index) ⇒ Object

Write the <a:blip> element.



594
595
596
597
598
599
600
601
602
603
604
605
# File 'lib/write_xlsx/drawing.rb', line 594

def write_a_blip(index)
  schema  = 'http://schemas.openxmlformats.org/officeDocument/'
  xmlns_r = "#{schema}2006/relationships"
  r_embed = "rId#{index}"

  attributes = [
    ['xmlns:r', xmlns_r],
    ['r:embed', r_embed]
  ]

  @writer.empty_tag('a:blip', attributes)
end

#write_a_ext(cx, cy) ⇒ Object

Write the <a:ext> element.



699
700
701
702
703
704
705
706
# File 'lib/write_xlsx/drawing.rb', line 699

def write_a_ext(cx, cy)
  attributes = [
    ['cx', cx],
    ['cy', cy]
  ]

  @writer.empty_tag('a:ext', attributes)
end

#write_a_fill_rectObject

Write the <a:fillRect> element.



620
621
622
# File 'lib/write_xlsx/drawing.rb', line 620

def write_a_fill_rect
  @writer.empty_tag('a:fillRect')
end

#write_a_graphic_frame_locksObject

Write the <a:graphicFrameLocks> element.



344
345
346
347
348
349
350
# File 'lib/write_xlsx/drawing.rb', line 344

def write_a_graphic_frame_locks
  no_grp = 1

  attributes = [['noGrp', no_grp]]

  @writer.empty_tag('a:graphicFrameLocks', attributes)
end

Write the <a:hlinkClick> element.



256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/write_xlsx/drawing.rb', line 256

def write_a_hlink_click(index, tip)
  schema  = 'http://schemas.openxmlformats.org/officeDocument/'
  xmlns_r = "#{schema}2006/relationships"
  r_id    = "rId#{index}"

  attributes = [
    ['xmlns:r', xmlns_r],
    ['r:id', r_id]
  ]

  attributes << ['tooltip', tip] if tip

  @writer.empty_tag('a:hlinkClick', attributes)
end

#write_a_ln(shape = {}) ⇒ Object

Write the <a:ln> elements.



770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
# File 'lib/write_xlsx/drawing.rb', line 770

def write_a_ln(shape = {})
  weight = shape.line_weight || 0
  attributes = [['w', weight * 9525]]
  @writer.tag_elements('a:ln', attributes) do
    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]]
      @writer.empty_tag('a:prstDash', attributes)
    end

    if shape.connect == 0
      attributes = [['lim', 800000]]
      @writer.empty_tag('a:miter', attributes)
    else
      @writer.empty_tag('a:round')
    end

    @writer.empty_tag('a:headEnd')
    @writer.empty_tag('a:tailEnd')
  end
end

#write_a_offObject

Write the <a:off> element.



685
686
687
688
689
690
691
692
693
694
# File 'lib/write_xlsx/drawing.rb', line 685

def write_a_off
  x, y = dimensions[8, 2]

  attributes = [
    ['x', x],
    ['y', y]
  ]

  @writer.empty_tag('a:off', attributes)
end

#write_a_pic_locksObject

Write the <a:picLocks> element.



571
572
573
574
575
576
577
# File 'lib/write_xlsx/drawing.rb', line 571

def write_a_pic_locks
  no_change_aspect = 1

  attributes = [['noChangeAspect', no_change_aspect]]

  @writer.empty_tag('a:picLocks', attributes)
end

#write_a_prst_geom(shape = {}) ⇒ Object

Write the <a:prstGeom> element.



711
712
713
714
715
716
717
718
719
# File 'lib/write_xlsx/drawing.rb', line 711

def write_a_prst_geom(shape = {})
  attributes = []
  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
end

#write_a_solid_fill(rgb = '000000') ⇒ Object

Write the <a:solidFill> element.



759
760
761
762
763
764
765
# File 'lib/write_xlsx/drawing.rb', line 759

def write_a_solid_fill(rgb = '000000')
  attributes = [['val', rgb]]

  @writer.tag_elements('a:solidFill') do
    @writer.empty_tag('a:srgbClr', attributes)
  end
end

#write_a_stretchObject

Write the <a:stretch> element.



610
611
612
613
614
615
# File 'lib/write_xlsx/drawing.rb', line 610

def write_a_stretch
  @writer.tag_elements('a:stretch') do
    # Write the a:fillRect element.
    write_a_fill_rect
  end
end

#write_a_uri_ext(uri) ⇒ Object

Write the <a:ext> element.



289
290
291
292
293
294
295
# File 'lib/write_xlsx/drawing.rb', line 289

def write_a_uri_ext(uri)
  attributes = [
    ['uri', uri]
  ]

  @writer.start_tag('a:ext', attributes)
end

#write_a_xfrm(shape = nil) ⇒ Object

Write the <a:xfrm> element.



664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
# File 'lib/write_xlsx/drawing.rb', line 664

def write_a_xfrm(shape = nil)
  attributes = []

  rotation = shape ? shape.rotation : 0
  rotation *= 60000

  attributes << ['rot', rotation] if rotation != 0
  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
    # Write the a:ext element.
    write_a_ext(width, height)
  end
end

#write_absolute_anchor(index) ⇒ Object

Write the <xdr:absoluteAnchor> element.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/write_xlsx/drawing.rb', line 73

def write_absolute_anchor(index)
  @writer.tag_elements('xdr:absoluteAnchor') do
    # Different co-ordinates for horizonatal (= 0) and vertical (= 1).
    if ptrue?(@orientation)
      # Write the xdr:pos element.
      write_pos(0, -47625)

      # Write the xdr:ext element.
      write_xdr_ext(6162675, 6124575)
    else

      # Write the xdr:pos element.
      write_pos(0, 0)

      # Write the xdr:ext element.
      write_xdr_ext(9308969, 6078325)
    end

    # Write the xdr:graphicFrame element.
    write_graphic_frame(index, index)

    # Write the xdr:clientData element.
    write_client_data
  end
end

#write_adec_decorativeObject

Write the <adec:decorative> element.



300
301
302
303
304
305
306
307
308
309
310
# File 'lib/write_xlsx/drawing.rb', line 300

def write_adec_decorative
  xmlns_adec = 'http://schemas.microsoft.com/office/drawing/2017/decorative'
  val        = 1

  attributes = [
    ['xmlns:adec', xmlns_adec],
    ['val',        val]
  ]

  @writer.empty_tag('adec:decorative', attributes)
end

#write_atag_graphic(index) ⇒ Object

Write the <a:graphic> element.



397
398
399
400
401
402
# File 'lib/write_xlsx/drawing.rb', line 397

def write_atag_graphic(index)
  @writer.tag_elements('a:graphic') do
    # Write the a:graphicData element.
    write_atag_graphic_data(index)
  end
end

#write_atag_graphic_data(index) ⇒ Object

Write the <a:graphicData> element.



407
408
409
410
411
412
413
414
415
416
# File 'lib/write_xlsx/drawing.rb', line 407

def write_atag_graphic_data(index)
  uri = 'http://schemas.openxmlformats.org/drawingml/2006/chart'

  attributes = [['uri', uri]]

  @writer.tag_elements('a:graphicData', attributes) do
    # Write the c:chart element.
    write_c_chart(index)
  end
end

#write_blip_fillObject

Write the <xdr:blipFill> element.



582
583
584
585
586
587
588
589
# File 'lib/write_xlsx/drawing.rb', line 582

def write_blip_fill
  @writer.tag_elements('xdr:blipFill') do
    # Write the a:blip element.
    write_a_blip(rel_index)
    # Write the a:stretch element.
    write_a_stretch
  end
end

#write_c_chart(id) ⇒ Object

Write the <c:chart> element.



421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/write_xlsx/drawing.rb', line 421

def write_c_chart(id)
  schema  = 'http://schemas.openxmlformats.org/'
  xmlns_c = "#{schema}drawingml/2006/chart"
  xmlns_r = "#{schema}officeDocument/2006/relationships"

  attributes = [
    ['xmlns:c', xmlns_c],
    ['xmlns:r', xmlns_r]
  ]
  attributes << r_id_attributes(id)

  @writer.empty_tag('c:chart', attributes)
end

#write_c_nv_graphic_frame_prObject

Write the <xdr:cNvGraphicFramePr> element.



330
331
332
333
334
335
336
337
338
339
# File 'lib/write_xlsx/drawing.rb', line 330

def write_c_nv_graphic_frame_pr
  if @embedded
    @writer.empty_tag('xdr:cNvGraphicFramePr')
  else
    @writer.tag_elements('xdr:cNvGraphicFramePr') do
      # Write the a:graphicFrameLocks element.
      write_a_graphic_frame_locks
    end
  end
end

#write_c_nv_pic_prObject

Write the <xdr:cNvPicPr> element.



561
562
563
564
565
566
# File 'lib/write_xlsx/drawing.rb', line 561

def write_c_nv_pic_pr
  @writer.tag_elements('xdr:cNvPicPr') do
    # Write the a:picLocks element.
    write_a_pic_locks
  end
end

#write_c_nv_pr(index, name, description = nil, url_rel_index = nil, tip = nil, decorative = nil) ⇒ Object

Write the <xdr:cNvPr> element.



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/write_xlsx/drawing.rb', line 228

def write_c_nv_pr(index, name, description = nil, url_rel_index = nil, tip = nil, decorative = nil)
  attributes = [
    ['id',   index],
    ['name', name]
  ]

  # Add description attribute for images.
  attributes << ['descr', description] if ptrue?(description) && !ptrue?(decorative)

  if ptrue?(url_rel_index) || ptrue?(decorative)
    @writer.tag_elements('xdr:cNvPr', attributes) do
      if ptrue?(url_rel_index)
        # Write the a:hlinkClick element.
        write_a_hlink_click(url_rel_index, tip)
      end
      if ptrue?(decorative)
        # Write the adec:decorative element.
        write_decorative
      end
    end
  else
    @writer.empty_tag('xdr:cNvPr', attributes)
  end
end

#write_client_dataObject

Write the <xdr:clientData> element.



438
439
440
# File 'lib/write_xlsx/drawing.rb', line 438

def write_client_data
  @writer.empty_tag('xdr:clientData')
end

#write_col(data) ⇒ Object

Write the <xdr:col> element.



138
139
140
# File 'lib/write_xlsx/drawing.rb', line 138

def write_col(data)
  @writer.data_element('xdr:col', data)
end

#write_col_off(data) ⇒ Object

Write the <xdr:colOff> element.



145
146
147
# File 'lib/write_xlsx/drawing.rb', line 145

def write_col_off(data)
  @writer.data_element('xdr:colOff', data)
end

#write_decorativeObject

Write the <adec:decorative> element.



274
275
276
277
278
279
280
281
282
283
284
# File 'lib/write_xlsx/drawing.rb', line 274

def write_decorative
  @writer.tag_elements('a:extLst') do
    write_a_uri_ext('{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}')
    write_a16_creation_id
    @writer.end_tag('a:ext')

    write_a_uri_ext('{C183D7F6-B498-43B3-948B-1728B52AA6E4}')
    write_adec_decorative
    @writer.end_tag('a:ext')
  end
end

#write_fromObject

Write the <xdr:from> element.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/write_xlsx/drawing.rb', line 102

def write_from
  col, row, col_offset, row_offset = dimensions

  @writer.tag_elements('xdr:from') do
    # Write the xdr:col element.
    write_col(col)
    # Write the xdr:colOff element.
    write_col_off(col_offset)
    # Write the xdr:row element.
    write_row(row)
    # Write the xdr:rowOff element.
    write_row_off(row_offset)
  end
end

#write_graphic_frame(index, rel_index, name = nil, description = nil, decorative = nil, macro = nil) ⇒ Object

Write the <xdr:graphicFrame> element.



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/write_xlsx/drawing.rb', line 190

def write_graphic_frame(
      index, rel_index, name = nil,
      description = nil, decorative = nil, macro = nil
    )
  macro  ||= ''

  attributes = [['macro', macro]]

  @writer.tag_elements('xdr:graphicFrame', attributes) do
    # Write the xdr:nvGraphicFramePr element.
    write_nv_graphic_frame_pr(index, name, description, decorative)
    # Write the xdr:xfrm element.
    write_xfrm
    # Write the a:graphic element.
    write_atag_graphic(rel_index)
  end
end

#write_nv_cxn_sp_pr(index, shape) ⇒ Object

Write the <xdr:nvCxnSpPr> element.



477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/write_xlsx/drawing.rb', line 477

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)

    @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]
        ]
        @writer.empty_tag('a:stCxn', attributes)
      end

      if shape.end
        attributes = [
          ['id', shape.end],
          ['idx', shape.end_index]
        ]
        @writer.empty_tag('a:endCxn', attributes)
      end
    end
  end
end

#write_nv_graphic_frame_pr(index, name = nil, description = nil, decorative = nil) ⇒ Object

Write the <xdr:nvGraphicFramePr> element.



211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/write_xlsx/drawing.rb', line 211

def write_nv_graphic_frame_pr(
      index, name = nil, description = nil, decorative = nil
    )
  name = "Chart #{index}" unless ptrue?(name)

  @writer.tag_elements('xdr:nvGraphicFramePr') do
    # Write the xdr:cNvPr element.
    write_c_nv_pr(index + 1, name, description,
                  nil, nil, decorative)
    # Write the xdr:cNvGraphicFramePr element.
    write_c_nv_graphic_frame_pr
  end
end

#write_nv_pic_pr(index) ⇒ Object

Write the <xdr:nvPicPr> element.

def write_nv_pic_pr(index, _rel_index, description, url_rel_index, tip, decorative)



546
547
548
549
550
551
552
553
554
555
556
# File 'lib/write_xlsx/drawing.rb', line 546

def write_nv_pic_pr(index)
  @writer.tag_elements('xdr:nvPicPr') do
    # Write the xdr:cNvPr element.
    write_c_nv_pr(
      index + 1, "Picture #{index}", description,
      url_rel_index, tip, decorative
    )
    # Write the xdr:cNvPicPr element.
    write_c_nv_pic_pr
  end
end

#write_nv_sp_pr(index, shape) ⇒ Object

Write the <xdr:NvSpPr> element.



508
509
510
511
512
513
514
515
516
517
518
519
# File 'lib/write_xlsx/drawing.rb', line 508

def write_nv_sp_pr(index, shape)
  attributes = []
  attributes << ['txBox', 1] if shape.tx_box

  @writer.tag_elements('xdr:nvSpPr') do
    write_c_nv_pr(shape.id, "#{shape.type} #{index}")

    @writer.tag_elements('xdr:cNvSpPr', attributes) do
      @writer.empty_tag('a:spLocks', [[:noChangeArrowheads, '1']])
    end
  end
end

#write_pic(index) ⇒ Object

Write the <xdr:pic> element.



524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
# File 'lib/write_xlsx/drawing.rb', line 524

def write_pic(index)
  col_absolute, row_absolute = dimensions[8, 2]

  @writer.tag_elements('xdr:pic') do
    # Write the xdr:nvPicPr element.
    write_nv_pic_pr(index)
    # Write the xdr:blipFill element.
    write_blip_fill

    # Pictures are rectangle shapes by default.
    pic_shape = Shape.new
    pic_shape.type = 'rect'

    # Write the xdr:spPr element.
    write_sp_pr(pic_shape)
  end
end

#write_pos(x, y) ⇒ Object

Write the <xdr:pos> element.



166
167
168
169
170
171
172
173
# File 'lib/write_xlsx/drawing.rb', line 166

def write_pos(x, y)
  attributes = [
    ['x', x],
    ['y', y]
  ]

  @writer.empty_tag('xdr:pos', attributes)
end

#write_row(data) ⇒ Object

Write the <xdr:row> element.



152
153
154
# File 'lib/write_xlsx/drawing.rb', line 152

def write_row(data)
  @writer.data_element('xdr:row', data)
end

#write_row_off(data) ⇒ Object

Write the <xdr:rowOff> element.



159
160
161
# File 'lib/write_xlsx/drawing.rb', line 159

def write_row_off(data)
  @writer.data_element('xdr:rowOff', data)
end

#write_sp(index, shape) ⇒ Object

Write the <xdr:sp> element.



445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/write_xlsx/drawing.rb', line 445

def write_sp(index, shape)
  if shape.connect == 0
    # Add attribute for shapes.
    attributes = [
      [:macro, ''],
      [:textlink, '']
    ]
    @writer.tag_elements('xdr:sp', attributes) do
      # Write the xdr:nvSpPr element.
      write_nv_sp_pr(index, shape)

      # Write the xdr:spPr element.
      write_xdr_sp_pr(shape)

      # Write the xdr:txBody element.
      write_tx_body(shape) if shape.text != 0
    end
  else
    attributes = [[:macro,  '']]
    @writer.tag_elements('xdr:cxnSp', attributes) do
      # Write the xdr:nvCxnSpPr element.
      write_nv_cxn_sp_pr(index, shape)

      # Write the xdr:spPr element.
      write_xdr_sp_pr(shape)
    end
  end
end

#write_sp_pr(shape) ⇒ Object

Write the <xdr:spPr> element, for charts.



627
628
629
630
631
632
633
634
# File 'lib/write_xlsx/drawing.rb', line 627

def write_sp_pr(shape)
  @writer.tag_elements('xdr:spPr') do
    # Write the a:xfrm element.
    write_a_xfrm
    # Write the a:prstGeom element.
    write_a_prst_geom(shape)
  end
end

#write_toObject

Write the <xdr:to> element.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/write_xlsx/drawing.rb', line 120

def write_to
  col, row, col_offset, row_offset = dimensions[4, 4]

  @writer.tag_elements('xdr:to') do
    # Write the xdr:col element.
    write_col(col)
    # Write the xdr:colOff element.
    write_col_off(col_offset)
    # Write the xdr:row element.
    write_row(row)
    # Write the xdr:rowOff element.
    write_row_off(row_offset)
  end
end

#write_two_cell_anchor(index) ⇒ Object

Write the <xdr:twoCellAnchor> element.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/write_xlsx/drawing.rb', line 33

def write_two_cell_anchor(index)
  attributes      = []

  # Add attribute for images.
  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
    # Write the xdr:from element.
    write_from
    # Write the xdr:to element.
    write_to

    if type == 1
      # Graphic frame.

      # Write the xdr:graphicFrame element for charts.
      write_graphic_frame(index, rel_index, name, description, decorative)
    elsif type == 2
      # Write the xdr:pic element.
      write_pic(index)
    else
      # Write the xdr:sp element for shapes.
      write_sp(index, shape)
    end

    # Write the xdr:clientData element.
    write_client_data
  end
end

#write_tx_body(shape) ⇒ Object

Write the <xdr:txBody> element.



802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
# File 'lib/write_xlsx/drawing.rb', line 802

def write_tx_body(shape)
  attributes = [
    [:vertOverflow, "clip"],
    [:wrap,         "square"],
    [:lIns,         "27432"],
    [:tIns,         "22860"],
    [:rIns,         "27432"],
    [:bIns,         "22860"],
    [: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 *= 60000

      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 *= 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'

        attributes = [
          [:lang,     "en-US"],
          [:sz,       size],
          [:b,        bold],
          [:i,        italic],
          [:u,        underline],
          [:strike,   strike],
          [:baseline, 0]
        ]
        @writer.tag_elements('a:rPr', attributes) do
          color = shape.format[:color]
          if color
            color = shape.palette_color_from_index(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'
          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)
        end
      end
    end
  end
end

#write_xdr_ext(cx, cy) ⇒ Object

Write the <xdr:ext> element.



178
179
180
181
182
183
184
185
# File 'lib/write_xlsx/drawing.rb', line 178

def write_xdr_ext(cx, cy)
  attributes = [
    ['cx', cx],
    ['cy', cy]
  ]

  @writer.empty_tag('xdr:ext', attributes)
end

#write_xdr_sp_pr(shape) ⇒ Object

Write the <xdr:spPr> element for shapes.



639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
# File 'lib/write_xlsx/drawing.rb', line 639

def write_xdr_sp_pr(shape)
  attributes = [%w[bwMode auto]]

  @writer.tag_elements('xdr:spPr', attributes) do
    # Write the a:xfrm element.
    write_a_xfrm(shape)

    # Write the a:prstGeom element.
    write_a_prst_geom(shape)

    if shape.fill.to_s.bytesize > 1
      # Write the a:solidFill element.
      write_a_solid_fill(shape.fill)
    else
      @writer.empty_tag('a:noFill')
    end

    # Write the a:ln element.
    write_a_ln(shape)
  end
end

#write_xfrmObject

Write the <xdr:xfrm> element.



355
356
357
358
359
360
361
362
# File 'lib/write_xlsx/drawing.rb', line 355

def write_xfrm
  @writer.tag_elements('xdr:xfrm') do
    # Write the xfrmOffset element.
    write_xfrm_offset
    # Write the xfrmOffset element.
    write_xfrm_extension
  end
end

#write_xfrm_extensionObject

Write the <a:ext> xfrm sub-element.



382
383
384
385
386
387
388
389
390
391
392
# File 'lib/write_xlsx/drawing.rb', line 382

def write_xfrm_extension
  x    = 0
  y    = 0

  attributes = [
    ['cx', x],
    ['cy', y]
  ]

  @writer.empty_tag('a:ext', attributes)
end

#write_xfrm_offsetObject

Write the <a:off> xfrm sub-element.



367
368
369
370
371
372
373
374
375
376
377
# File 'lib/write_xlsx/drawing.rb', line 367

def write_xfrm_offset
  x    = 0
  y    = 0

  attributes = [
    ['x', x],
    ['y', y]
  ]

  @writer.empty_tag('a:off', attributes)
end