Class: Postsvg::Svg::Elements::Text

Inherits:
Postsvg::Svg::Element show all
Defined in:
lib/postsvg/svg/elements/text.rb

Constant Summary collapse

ELEMENT_NAME =
"text"

Constants inherited from Postsvg::Svg::Element

Postsvg::Svg::Element::REGISTRY

Instance Attribute Summary collapse

Attributes inherited from Postsvg::Svg::Element

#attributes, #children, #clip_path_id, #transform

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Postsvg::Svg::Element

#default_fill, #element_name, register, registry

Constructor Details

#initialize(x:, y:, content:, font_family:, font_size:, fill:, stroke_paint:, stroke:, **rest) ⇒ Text

Returns a new instance of Text.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/postsvg/svg/elements/text.rb', line 13

def initialize(x:, y:, content:, font_family:, font_size:,
               fill:, stroke_paint:, stroke:, **rest)
  super(**rest)
  @x = x
  @y = y
  @content = content
  @font_family = font_family
  @font_size = font_size
  @fill = fill
  @stroke_paint = stroke_paint
  @stroke = stroke
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



10
11
12
# File 'lib/postsvg/svg/elements/text.rb', line 10

def content
  @content
end

#fillObject (readonly)

Returns the value of attribute fill.



10
11
12
# File 'lib/postsvg/svg/elements/text.rb', line 10

def fill
  @fill
end

#font_familyObject (readonly)

Returns the value of attribute font_family.



10
11
12
# File 'lib/postsvg/svg/elements/text.rb', line 10

def font_family
  @font_family
end

#font_sizeObject (readonly)

Returns the value of attribute font_size.



10
11
12
# File 'lib/postsvg/svg/elements/text.rb', line 10

def font_size
  @font_size
end

#strokeObject (readonly)

Returns the value of attribute stroke.



10
11
12
# File 'lib/postsvg/svg/elements/text.rb', line 10

def stroke
  @stroke
end

#stroke_paintObject (readonly)

Returns the value of attribute stroke_paint.



10
11
12
# File 'lib/postsvg/svg/elements/text.rb', line 10

def stroke_paint
  @stroke_paint
end

#xObject (readonly)

Returns the value of attribute x.



10
11
12
# File 'lib/postsvg/svg/elements/text.rb', line 10

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



10
11
12
# File 'lib/postsvg/svg/elements/text.rb', line 10

def y
  @y
end

Class Method Details

.from_node(node) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/postsvg/svg/elements/text.rb', line 26

def self.from_node(node)
  new(x: AttributeParser.number(node["x"], default: 0),
      y: AttributeParser.number(node["y"], default: 0),
      content: node.text,
      font_family: node["font-family"] || "Helvetica",
      font_size: AttributeParser.number(node["font-size"], default: 12),
      fill: Paint.parse(node["fill"]),
      stroke_paint: Paint.parse(node["stroke"]),
      stroke: Stroke.parse(node),
      transform: TransformList.parse(node["transform"]),
      clip_path_id: Elements.parse_clip_path_id(node["clip-path"]),
      attributes: Elements.node_attributes(node))
end