Class: Sevgi::Graphics::Canvas

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sevgi/graphics/auxilary/canvas.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width:, height:, unit: "mm", margins: []) ⇒ Canvas

Returns a new instance of Canvas.



14
15
16
17
18
19
20
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 14

def initialize(width:, height:, unit: "mm", margins: [])
  @dim    = Dim[width, height, unit]
  @margin = Margin[*margins]

  compute
  freeze
end

Instance Attribute Details

#dimObject (readonly)

Returns the value of attribute dim.



12
13
14
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 12

def dim
  @dim
end

#innerObject (readonly)

Returns the value of attribute inner.



12
13
14
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 12

def inner
  @inner
end

#marginObject (readonly)

Returns the value of attribute margin.



12
13
14
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 12

def margin
  @margin
end

Class Method Details

.call(arg = Paper.default) ⇒ Object



39
40
41
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 39

def call(arg = Paper.default, *)
  canvas(arg).with(*)
end

Instance Method Details

#attributesObject



22
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 22

def attributes      = { **viewport, viewBox: viewbox }

#conformingObject



24
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 24

def conforming(...) = self.class.conforming(self, ...)

#viewboxObject



28
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 28

def viewbox         = F.prettify(-margin.left, -margin.top, width, height).join(" ")

#viewportObject



26
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 26

def viewport        = { width: "#{width}#{unit}", height: "#{height}#{unit}" }

#with(*margins) ⇒ Object



30
# File 'lib/sevgi/graphics/auxilary/canvas.rb', line 30

def with(*margins)  = margins.empty? ? self : self.class.new(**dim.to_h, margins:)