Class: Emfsvg::Svg::Elements::Image
- Inherits:
-
Emfsvg::Svg::Element
- Object
- Emfsvg::Svg::Element
- Emfsvg::Svg::Elements::Image
- Defined in:
- lib/emfsvg/svg/elements/image.rb
Overview
Constant Summary collapse
- ELEMENT_NAME =
"image"
Instance Attribute Summary collapse
-
#clip_path ⇒ Object
readonly
Returns the value of attribute clip_path.
-
#fill ⇒ Object
readonly
Returns the value of attribute fill.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#stroke ⇒ Object
readonly
Returns the value of attribute stroke.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#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
- #base64? ⇒ Boolean
- #data_uri? ⇒ Boolean
- #decoded_bytes ⇒ Object
-
#initialize(x:, y:, width:, height:, href:, fill: nil, stroke: nil, clip_path: nil) ⇒ Image
constructor
A new instance of Image.
- #mime_type ⇒ Object
Methods inherited from Emfsvg::Svg::Element
#children, #element_name, register
Constructor Details
#initialize(x:, y:, width:, height:, href:, fill: nil, stroke: nil, clip_path: nil) ⇒ Image
Returns a new instance of Image.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/emfsvg/svg/elements/image.rb', line 15 def initialize(x:, y:, width:, height:, href:, fill: nil, stroke: nil, clip_path: nil) @x = x @y = y @width = width @height = height @href = href @fill = fill @stroke = stroke @clip_path = clip_path end |
Instance Attribute Details
#clip_path ⇒ Object (readonly)
Returns the value of attribute clip_path.
13 14 15 |
# File 'lib/emfsvg/svg/elements/image.rb', line 13 def clip_path @clip_path end |
#fill ⇒ Object (readonly)
Returns the value of attribute fill.
13 14 15 |
# File 'lib/emfsvg/svg/elements/image.rb', line 13 def fill @fill end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
13 14 15 |
# File 'lib/emfsvg/svg/elements/image.rb', line 13 def height @height end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
13 14 15 |
# File 'lib/emfsvg/svg/elements/image.rb', line 13 def href @href end |
#stroke ⇒ Object (readonly)
Returns the value of attribute stroke.
13 14 15 |
# File 'lib/emfsvg/svg/elements/image.rb', line 13 def stroke @stroke end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
13 14 15 |
# File 'lib/emfsvg/svg/elements/image.rb', line 13 def width @width end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
13 14 15 |
# File 'lib/emfsvg/svg/elements/image.rb', line 13 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
13 14 15 |
# File 'lib/emfsvg/svg/elements/image.rb', line 13 def y @y end |
Class Method Details
.from_node(node) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/emfsvg/svg/elements/image.rb', line 26 def self.from_node(node) href = node["xlink:href"] || node["href"] new( x: AttributeParser.float(node["x"]), y: AttributeParser.float(node["y"]), width: AttributeParser.float(node["width"]), height: AttributeParser.float(node["height"]), href: href, **Stylable.parse_style(node) ) end |
Instance Method Details
#base64? ⇒ Boolean
59 60 61 |
# File 'lib/emfsvg/svg/elements/image.rb', line 59 def base64? href.include?(";base64,") end |
#data_uri? ⇒ Boolean
38 39 40 |
# File 'lib/emfsvg/svg/elements/image.rb', line 38 def data_uri? href&.start_with?("data:") end |
#decoded_bytes ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/emfsvg/svg/elements/image.rb', line 49 def decoded_bytes return nil unless data_uri? match = href.match(/\Adata:[^;,]+(?:;[^,]*)*,(.*)\z/m) return nil unless match payload = match[1] base64? ? Base64.decode64(payload) : payload end |
#mime_type ⇒ Object
42 43 44 45 46 47 |
# File 'lib/emfsvg/svg/elements/image.rb', line 42 def mime_type return nil unless data_uri? match = href.match(/\Adata:([^;,]+)/) match ? match[1] : nil end |