Class: Sevgi::Graphics::Canvas
- Inherits:
-
Object
- Object
- Sevgi::Graphics::Canvas
- Extended by:
- Forwardable
- Defined in:
- lib/sevgi/graphics/auxiliary/canvas.rb
Overview
SVG canvas size, margins, viewport, and viewBox.
Instance Attribute Summary collapse
-
#inner ⇒ Object
readonly
Returns the value of attribute inner.
-
#margin ⇒ Sevgi::Graphics::Margin
readonly
Canvas margins.
-
#size ⇒ Sevgi::Graphics::Paper
readonly
Paper size object.
Class Method Summary collapse
-
.call(arg = Undefined, **kwargs) ⇒ Sevgi::Graphics::Canvas
Builds a canvas from a paper profile or explicit size.
-
.from_paper(arg = Undefined, **kwargs) ⇒ Sevgi::Graphics::Canvas
Builds a canvas from a paper profile or explicit size.
Instance Method Summary collapse
-
#attributes(origin = Undefined) ⇒ Hash
Returns SVG root viewport attributes.
-
#initialize(width:, height:, unit: "mm", name: :custom, margins: []) ⇒ void
constructor
Creates a canvas.
-
#viewbox(origin = Undefined) ⇒ String
Returns the SVG viewBox string.
-
#viewport ⇒ Hash
Returns SVG width and height attributes.
-
#with(**kwargs) ⇒ Sevgi::Graphics::Canvas
Returns a canvas with selected fields replaced.
Constructor Details
#initialize(width:, height:, unit: "mm", name: :custom, margins: []) ⇒ void
Creates a canvas.
67 68 69 70 71 72 73 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 67 def initialize(width:, height:, unit: "mm", name: :custom, margins: []) @size = Paper[width, height, unit, name] @margin = Margin[*margins] compute freeze end |
Instance Attribute Details
#inner ⇒ Object (readonly)
Returns the value of attribute inner.
57 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 57 attr_reader :size, :margin, :inner |
#margin ⇒ Sevgi::Graphics::Margin (readonly)
Returns canvas margins.
57 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 57 attr_reader :size, :margin, :inner |
#size ⇒ Sevgi::Graphics::Paper (readonly)
Returns paper size object.
57 58 59 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 57 def size @size end |
Class Method Details
.call(arg = Undefined, **kwargs) ⇒ Sevgi::Graphics::Canvas
15 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 15 def self.call(...) = from_paper(...) |
.from_paper(arg = Undefined, **kwargs) ⇒ Sevgi::Graphics::Canvas
Builds a canvas from a paper profile or explicit size.
22 23 24 25 26 27 28 29 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 22 def self.from_paper(arg = Undefined, **kwargs) case arg when Undefined new(**kwargs) else new(**paper(arg).to_h, **kwargs) end end |
Instance Method Details
#attributes(origin = Undefined) ⇒ Hash
80 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 80 def attributes(...) = {**, viewBox: viewbox(...)} |
#viewbox(origin = Undefined) ⇒ String
Returns the SVG viewBox string.
90 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 90 def viewbox(origin = Undefined) = prettify(*originate(origin), width, height).join(" ") |
#viewport ⇒ Hash
Returns SVG width and height attributes.
84 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 84 def = {width: "#{width}#{unit}", height: "#{height}#{unit}"} |
#with(**kwargs) ⇒ Sevgi::Graphics::Canvas
Returns a canvas with selected fields replaced.
95 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 95 def with(**kwargs) = self.class.new(**size.to_h, margins: kwargs.fetch(:margins, margin.to_a)) |