Class: Postsvg::SvgGenerator
- Inherits:
-
Object
- Object
- Postsvg::SvgGenerator
- Defined in:
- lib/postsvg/svg_generator.rb
Overview
Generates SVG output from PostScript graphics operations
Instance Method Summary collapse
- #add_path(path, graphics_state, operation) ⇒ Object
- #generate(width:, height:, viewbox:) ⇒ Object
-
#initialize ⇒ SvgGenerator
constructor
A new instance of SvgGenerator.
Constructor Details
#initialize ⇒ SvgGenerator
6 7 8 |
# File 'lib/postsvg/svg_generator.rb', line 6 def initialize @paths = [] end |
Instance Method Details
#add_path(path, graphics_state, operation) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/postsvg/svg_generator.rb', line 10 def add_path(path, graphics_state, operation) return if path.empty? svg_path = { d: build_path_data(path), operation: operation, stroke: graphics_state.stroke_color_hex, fill: graphics_state.fill_color_hex, stroke_width: graphics_state.line_width, } @paths << svg_path end |
#generate(width:, height:, viewbox:) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/postsvg/svg_generator.rb', line 24 def generate(width:, height:, viewbox:) svg_parts = [] svg_parts << '<?xml version="1.0" encoding="UTF-8"?>' svg_parts << %(<svg xmlns="http://www.w3.org/2000/svg" ) svg_parts << %(width="#{width}" height="#{height}" ) svg_parts << %(viewBox="#{viewbox}">) @paths.each do |path| svg_parts << build_path_element(path) end svg_parts << "</svg>" svg_parts.join("\n") end |