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.
71 72 73 74 75 76 77 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 71 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.
61 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 61 attr_reader :size, :margin, :inner |
#margin ⇒ Sevgi::Graphics::Margin (readonly)
Returns canvas margins.
61 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 61 attr_reader :size, :margin, :inner |
#size ⇒ Sevgi::Graphics::Paper (readonly)
Returns paper size object.
61 62 63 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 61 def size @size end |
Class Method Details
.call(arg = Undefined, **kwargs) ⇒ Sevgi::Graphics::Canvas
19 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 19 def self.call(...) = from_paper(...) |
.from_paper(arg = Undefined, **kwargs) ⇒ Sevgi::Graphics::Canvas
Builds a canvas from a paper profile or explicit size.
26 27 28 29 30 31 32 33 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 26 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
84 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 84 def attributes(...) = {**, viewBox: viewbox(...)} |
#viewbox(origin = Undefined) ⇒ String
Returns the SVG viewBox string.
94 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 94 def viewbox(origin = Undefined) = prettify(*originate(origin), width, height).join(" ") |
#viewport ⇒ Hash
Returns SVG width and height attributes.
88 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 88 def = {width: "#{width}#{unit}", height: "#{height}#{unit}"} |
#with(**kwargs) ⇒ Sevgi::Graphics::Canvas
Returns a canvas with selected fields replaced.
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/sevgi/graphics/auxiliary/canvas.rb', line 106 def with(**kwargs) unknown = kwargs.keys - REPLACEMENTS ArgumentError.("Unknown canvas option: #{unknown.first}") unless unknown.empty? margins = kwargs.fetch(:margins, margin.to_a) replacements = kwargs.dup.tap { it.delete(:margins) } self.class.new(**size.to_h, **replacements, margins:) end |