Class: Emfsvg::Svg::Elements::Text
- Inherits:
-
Emfsvg::Svg::Element
- Object
- Emfsvg::Svg::Element
- Emfsvg::Svg::Elements::Text
- Defined in:
- lib/emfsvg/svg/elements/text.rb
Overview
Constant Summary collapse
- ELEMENT_NAME =
"text"
Instance Attribute Summary collapse
-
#clip_path ⇒ Object
readonly
Returns the value of attribute clip_path.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#fill ⇒ Object
readonly
Returns the value of attribute fill.
-
#font_family ⇒ Object
readonly
Returns the value of attribute font_family.
-
#font_size ⇒ Object
readonly
Returns the value of attribute font_size.
-
#font_style ⇒ Object
readonly
Returns the value of attribute font_style.
-
#font_weight ⇒ Object
readonly
Returns the value of attribute font_weight.
-
#stroke ⇒ Object
readonly
Returns the value of attribute stroke.
-
#text_anchor ⇒ Object
readonly
Returns the value of attribute text_anchor.
-
#transform_matrix ⇒ Object
readonly
Returns the value of attribute transform_matrix.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
-
#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
constructor
A new instance of Text.
- #italic? ⇒ Boolean
- #transformed? ⇒ Boolean
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_path ⇒ Object (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 |
#content ⇒ Object (readonly)
Returns the value of attribute content.
15 16 17 |
# File 'lib/emfsvg/svg/elements/text.rb', line 15 def content @content end |
#fill ⇒ Object (readonly)
Returns the value of attribute fill.
15 16 17 |
# File 'lib/emfsvg/svg/elements/text.rb', line 15 def fill @fill end |
#font_family ⇒ Object (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_size ⇒ Object (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_style ⇒ Object (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_weight ⇒ Object (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 |
#stroke ⇒ Object (readonly)
Returns the value of attribute stroke.
15 16 17 |
# File 'lib/emfsvg/svg/elements/text.rb', line 15 def stroke @stroke end |
#text_anchor ⇒ Object (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_matrix ⇒ Object (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 |
#x ⇒ Object (readonly)
Returns the value of attribute x.
15 16 17 |
# File 'lib/emfsvg/svg/elements/text.rb', line 15 def x @x end |
#y ⇒ Object (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
61 62 63 |
# File 'lib/emfsvg/svg/elements/text.rb', line 61 def italic? font_style == "italic" end |
#transformed? ⇒ Boolean
36 37 38 |
# File 'lib/emfsvg/svg/elements/text.rb', line 36 def transformed? !transform_matrix.identity? end |