Class: Emfsvg::Svg::Elements::Text

Inherits:
Emfsvg::Svg::Element show all
Defined in:
lib/emfsvg/svg/elements/text.rb

Overview

content v1: single run, no , no textPath. Content is read from the element's text node.

Constant Summary collapse

ELEMENT_NAME =
"text"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Emfsvg::Svg::Element

#children, #element_name, register

Constructor Details

#initialize(x:, y:, content:, font_family:, font_size:, font_weight:, font_style:, text_anchor:, fill:, stroke:, clip_path: nil, transform_matrix: Emf::Model::Geometry::Matrix.identity) ⇒ Text

Returns a new instance of Text.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/emfsvg/svg/elements/text.rb', line 19

def initialize(x:, y:, content:, font_family:, font_size:, font_weight:,
               font_style:, text_anchor:, fill:, stroke:, clip_path: nil,
               transform_matrix: Emf::Model::Geometry::Matrix.identity)
  @x = x
  @y = y
  @content = content
  @font_family = font_family
  @font_size = font_size
  @font_weight = font_weight
  @font_style = font_style
  @text_anchor = text_anchor
  @fill = fill
  @stroke = stroke
  @clip_path = clip_path
  @transform_matrix = transform_matrix
end

Instance Attribute Details

#clip_pathObject (readonly)

Returns the value of attribute clip_path.



15
16
17
# File 'lib/emfsvg/svg/elements/text.rb', line 15

def clip_path
  @clip_path
end

#contentObject (readonly)

Returns the value of attribute content.



15
16
17
# File 'lib/emfsvg/svg/elements/text.rb', line 15

def content
  @content
end

#fillObject (readonly)

Returns the value of attribute fill.



15
16
17
# File 'lib/emfsvg/svg/elements/text.rb', line 15

def fill
  @fill
end

#font_familyObject (readonly)

Returns the value of attribute font_family.



15
16
17
# File 'lib/emfsvg/svg/elements/text.rb', line 15

def font_family
  @font_family
end

#font_sizeObject (readonly)

Returns the value of attribute font_size.



15
16
17
# File 'lib/emfsvg/svg/elements/text.rb', line 15

def font_size
  @font_size
end

#font_styleObject (readonly)

Returns the value of attribute font_style.



15
16
17
# File 'lib/emfsvg/svg/elements/text.rb', line 15

def font_style
  @font_style
end

#font_weightObject (readonly)

Returns the value of attribute font_weight.



15
16
17
# File 'lib/emfsvg/svg/elements/text.rb', line 15

def font_weight
  @font_weight
end

#strokeObject (readonly)

Returns the value of attribute stroke.



15
16
17
# File 'lib/emfsvg/svg/elements/text.rb', line 15

def stroke
  @stroke
end

#text_anchorObject (readonly)

Returns the value of attribute text_anchor.



15
16
17
# File 'lib/emfsvg/svg/elements/text.rb', line 15

def text_anchor
  @text_anchor
end

#transform_matrixObject (readonly)

Returns the value of attribute transform_matrix.



15
16
17
# File 'lib/emfsvg/svg/elements/text.rb', line 15

def transform_matrix
  @transform_matrix
end

#xObject (readonly)

Returns the value of attribute x.



15
16
17
# File 'lib/emfsvg/svg/elements/text.rb', line 15

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



15
16
17
# File 'lib/emfsvg/svg/elements/text.rb', line 15

def y
  @y
end

Class Method Details

.from_node(node) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/emfsvg/svg/elements/text.rb', line 40

def self.from_node(node)
  new(
    x: AttributeParser.float(node["x"]),
    y: AttributeParser.float(node["y"]),
    content: node.text,
    font_family: node["font-family"],
    font_size: AttributeParser.float(node["font-size"], default: 12.0),
    font_weight: parse_weight(node["font-weight"]),
    font_style: node["font-style"],
    text_anchor: node["text-anchor"] || "start",
    transform_matrix: Svg::TransformParser.parse(node["transform"]),
    **Stylable.parse_style(node)
  )
end

.parse_weight(value) ⇒ Object



55
56
57
58
59
# File 'lib/emfsvg/svg/elements/text.rb', line 55

def self.parse_weight(value)
  return 400 if value.nil? || value == "normal"

  value == "bold" ? 700 : value.to_i
end

Instance Method Details

#italic?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/emfsvg/svg/elements/text.rb', line 61

def italic?
  font_style == "italic"
end

#transformed?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/emfsvg/svg/elements/text.rb', line 36

def transformed?
  !transform_matrix.identity?
end