Module: Asciidoctor::Diagram::SVG

Defined in:
lib/asciidoctor-diagram/util/svg.rb

Class Method Summary collapse

Class Method Details

.get_image_size(data) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/asciidoctor-diagram/util/svg.rb', line 7

def self.get_image_size(data)
  if m = START_TAG_REGEX.match(data)
    start_tag = m[0]
    if (w = WIDTH_REGEX.match(start_tag)) && (h = HEIGHT_REGEX.match(start_tag))
      width = w[:value].to_i * to_px_factor(w[:unit])
      height = h[:value].to_i * to_px_factor(h[:unit])
      return [width.to_i, height.to_i]
    end

    if v = VIEWBOX_REGEX.match(start_tag)
      width = v[:width]
      height = v[:height]
      return [width.to_i, height.to_i]
    end
  end

  nil
end