Module: Writexlsx::Utility::Drawing

Included in:
Package::Button, Package::Comment, Package::Vml
Defined in:
lib/write_xlsx/utility/drawing.rb

Instance Method Summary collapse

Instance Method Details

#pixels_to_points(vertices) ⇒ Object

Convert vertices from pixels to points.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/write_xlsx/utility/drawing.rb', line 10

def pixels_to_points(vertices)
  _col_start, _row_start, _x1,    _y1,
  _col_end,   _row_end,   _x2,    _y2,
  left,      top,       width, height  = vertices.flatten

  left   *= 0.75
  top    *= 0.75
  width  *= 0.75
  height *= 0.75

  [left, top, width, height]
end

#shape_style_base(left_str, top_str, width_str, height_str, z_index_str) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/write_xlsx/utility/drawing.rb', line 42

def shape_style_base(left_str, top_str, width_str, height_str, z_index_str)
  [
    'position:absolute;',
    'margin-left:',
    left_str, 'pt;',
    'margin-top:',
    top_str, 'pt;',
    'width:',
    width_str, 'pt;',
    'height:',
    height_str, 'pt;',
    'z-index:',
    z_index_str, ';'
  ]
end

#v_shape_attributes_base(id) ⇒ Object



23
24
25
26
27
28
# File 'lib/write_xlsx/utility/drawing.rb', line 23

def v_shape_attributes_base(id)
  [
    ['id',    "_x0000_s#{id}"],
    ['type',  type]
  ]
end

#v_shape_style_base(z_index, vertices) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/write_xlsx/utility/drawing.rb', line 30

def v_shape_style_base(z_index, vertices)
  left, top, width, height = pixels_to_points(vertices)

  left_str    = float_to_str(left)
  top_str     = float_to_str(top)
  width_str   = float_to_str(width)
  height_str  = float_to_str(height)
  z_index_str = float_to_str(z_index)

  shape_style_base(left_str, top_str, width_str, height_str, z_index_str)
end

#write_anchorObject

Write the <x:Anchor> element.



80
81
82
83
84
85
# File 'lib/write_xlsx/utility/drawing.rb', line 80

def write_anchor
  col_start, row_start, x1, y1, col_end, row_end, x2, y2 = @vertices
  data = [col_start, x1, row_start, y1, col_end, x2, row_end, y2].join(', ')

  @writer.data_element('x:Anchor', data)
end

#write_auto_fillObject

Write the <x:AutoFill> element.



90
91
92
# File 'lib/write_xlsx/utility/drawing.rb', line 90

def write_auto_fill
  @writer.data_element('x:AutoFill', 'False')
end

#write_comment_path(gradientshapeok, connecttype) ⇒ Object

Write the <v:path> element.



68
69
70
71
72
73
74
75
# File 'lib/write_xlsx/utility/drawing.rb', line 68

def write_comment_path(gradientshapeok, connecttype)
  attributes = []

  attributes << %w[gradientshapeok t] if gradientshapeok
  attributes << ['o:connecttype', connecttype]

  @writer.empty_tag('v:path', attributes)
end

#write_div(align, font = nil) ⇒ Object

Write the <div> element.



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/write_xlsx/utility/drawing.rb', line 97

def write_div(align, font = nil)
  style = "text-align:#{align}"
  attributes = [['style', style]]

  @writer.tag_elements('div', attributes) do
    if font
      # Write the font element.
      write_font(font)
    end
  end
end

#write_fillObject

Write the <v:fill> element.



61
62
63
# File 'lib/write_xlsx/utility/drawing.rb', line 61

def write_fill
  @writer.empty_tag('v:fill', fill_attributes)
end

#write_font(font) ⇒ Object

Write the <font> element.



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/write_xlsx/utility/drawing.rb', line 112

def write_font(font)
  caption = font[:_caption]
  face    = 'Calibri'
  size    = 220
  color   = '#000000'

  attributes = [
    ['face',  face],
    ['size',  size],
    ['color', color]
  ]
  @writer.data_element('font', caption, attributes)
end

#write_strokeObject

Write the <v:stroke> element.



129
130
131
132
133
# File 'lib/write_xlsx/utility/drawing.rb', line 129

def write_stroke
  attributes = [%w[joinstyle miter]]

  @writer.empty_tag('v:stroke', attributes)
end