Class: Dieses::Application::Canvas
- Inherits:
-
Geometry::Rect
- Object
- Geometry::Element
- Geometry::Rect
- Dieses::Application::Canvas
- Defined in:
- lib/dieses/application/canvas.rb
Constant Summary collapse
- TEMPLATE =
<<~XML <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg xmlns="http://www.w3.org/2000/svg" width="%{width}mm" height="%{height}mm" viewBox="0 0 %{width} %{height}" shape-rendering="geometricPrecision" %{header}> <style> svg { stroke: %8{color}; } svg { stroke-width: %8{medium}; } .altcolor { stroke: %8{altcolor}; } .extrafine { stroke-width: %8{extrafine}; } .fine { stroke-width: %8{fine}; } .medium { stroke-width: %8{medium}; } .broad { stroke-width: %8{broad}; } .extrabroad { stroke-width: %8{extrabroad}; } .dashed { stroke-dasharray: %8{dashed}; } </style> <g id="sheet"> %{content} </g> </svg> XML
Constants inherited from Geometry::Rect
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#paper ⇒ Object
readonly
Returns the value of attribute paper.
Attributes inherited from Geometry::Rect
Attributes inherited from Geometry::Element
Instance Method Summary collapse
- #<<(items) ⇒ Object
-
#initialize(paper = Paper.a4) ⇒ Canvas
constructor
A new instance of Canvas.
- #render(header: EMPTY_STRING, variables: EMPTY_HASH) ⇒ Object
Methods inherited from Geometry::Rect
#align, #angle, #bbox, #intersect, #orient, #orientation, #shrink, #to_h, #to_s, #to_svgf, #translate
Methods included from Geometry::Rect::Predicate
#cover?, #inside?, #onto?, #outside?
Methods inherited from Geometry::Element
#attr, #classify, #eql?, #to_svg
Constructor Details
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
29 30 31 |
# File 'lib/dieses/application/canvas.rb', line 29 def elements @elements end |
#paper ⇒ Object (readonly)
Returns the value of attribute paper.
29 30 31 |
# File 'lib/dieses/application/canvas.rb', line 29 def paper @paper end |
Instance Method Details
#<<(items) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/dieses/application/canvas.rb', line 38 def <<(items) [*items].each do |item| case item when Array then item.each { |element| elements << element } when Geometry::Element then elements << item else raise Error, 'Item must be an Array or Element' end end end |
#render(header: EMPTY_STRING, variables: EMPTY_HASH) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/dieses/application/canvas.rb', line 48 def render(header: EMPTY_STRING, variables: EMPTY_HASH) # We avoid prettifying XML through REXML which is pretty slow, at the cost of a somewhat hacky code. format(TEMPLATE, **variables(**variables), content: Geometry.to_svg(elements, paper, prefix: ' ' * 4), header: header) end |