Class: Writexlsx::Drawing

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

Constant Summary

Constants included from Utility::Common

Utility::Common::PERL_TRUE_VALUES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utility::XmlPrimitives

#r_id_attributes, #write_color, #write_xml_declaration, #xml_str

Methods included from Utility::Common

#absolute_char, #check_parameter, #float_to_str, #ptrue?, #put_deprecate_message

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.



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

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.



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

def anchor
  @anchor
end

#decorativeObject (readonly)

Returns the value of attribute decorative.



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

def decorative
  @decorative
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#dimensionsObject

Returns the value of attribute dimensions.



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

def dimensions
  @dimensions
end

#embedded=(value) ⇒ Object (writeonly)

Sets the attribute embedded

Parameters:

  • value

    the value to set the attribute embedded to.



15
16
17
# File 'lib/write_xlsx/drawing.rb', line 15

def embedded=(value)
  @embedded = value
end

#heightObject

Returns the value of attribute height.



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

def height
  @height
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#orientation=(value) ⇒ Object (writeonly)

Sets the attribute orientation

Parameters:

  • value

    the value to set the attribute orientation to.



15
16
17
# File 'lib/write_xlsx/drawing.rb', line 15

def orientation=(value)
  @orientation = value
end

#rel_indexObject

Returns the value of attribute rel_index.



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

def rel_index
  @rel_index
end

#shapeObject

Returns the value of attribute shape.



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

def shape
  @shape
end

#tipObject (readonly)

Returns the value of attribute tip.



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

def tip
  @tip
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#url_rel_indexObject

Returns the value of attribute url_rel_index.



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

def url_rel_index
  @url_rel_index
end

#widthObject

Returns the value of attribute width.



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

def width
  @width
end

#writer=(value) ⇒ Object (writeonly)

Sets the attribute writer

Parameters:

  • value

    the value to set the attribute writer to.



15
16
17
# File 'lib/write_xlsx/drawing.rb', line 15

def writer=(value)
  @writer = value
end

Instance Method Details

#write_a16_creation_idObject

Write the <a16:creationId> element.



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

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.



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
755
756
# File 'lib/write_xlsx/drawing.rb', line 726

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.



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

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.



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

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.



622
623
624
# File 'lib/write_xlsx/drawing.rb', line 622

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

#write_a_graphic_frame_locksObject

Write the <a:graphicFrameLocks> element.



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

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.



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

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.



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
798
799
# File 'lib/write_xlsx/drawing.rb', line 772

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.



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

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.



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

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.



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

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.



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

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.



612
613
614
615
616
617
# File 'lib/write_xlsx/drawing.rb', line 612

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.



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

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.



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

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.



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

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.



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

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.



399
400
401
402
403
404
# File 'lib/write_xlsx/drawing.rb', line 399

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.



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

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.



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

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.



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

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.



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

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.



563
564
565
566
567
568
# File 'lib/write_xlsx/drawing.rb', line 563

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.



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

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.



440
441
442
# File 'lib/write_xlsx/drawing.rb', line 440

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

#write_col(data) ⇒ Object

Write the <xdr:col> element.



140
141
142
# File 'lib/write_xlsx/drawing.rb', line 140

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

#write_col_off(data) ⇒ Object

Write the <xdr:colOff> element.



147
148
149
# File 'lib/write_xlsx/drawing.rb', line 147

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

#write_decorativeObject

Write the <adec:decorative> element.



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

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.



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

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.



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

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.



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
504
505
# File 'lib/write_xlsx/drawing.rb', line 479

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.



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

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)



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

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.



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

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.



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

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.



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

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.



154
155
156
# File 'lib/write_xlsx/drawing.rb', line 154

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

#write_row_off(data) ⇒ Object

Write the <xdr:rowOff> element.



161
162
163
# File 'lib/write_xlsx/drawing.rb', line 161

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

#write_sp(index, shape) ⇒ Object

Write the <xdr:sp> element.



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
473
474
# File 'lib/write_xlsx/drawing.rb', line 447

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.



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

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.



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

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.



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
69
70
# File 'lib/write_xlsx/drawing.rb', line 35

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.



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
871
872
# File 'lib/write_xlsx/drawing.rb', line 804

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.



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

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.



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

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.



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

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.



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

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.



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

def write_xfrm_offset
  x    = 0
  y    = 0

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

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