Class: RQRCode::Renderer::SvgBody

Inherits:
Body
  • Object
show all
Defined in:
lib/rqrcode/renderer.rb

Overview

ImageMagick doesn’t generate well-formed SVG, and it uses circles (wtf), so we special-case it

Constant Summary collapse

COLORS =
{true => "black", false => "white"}.freeze

Instance Attribute Summary

Attributes inherited from Body

#modules, #options, #type

Instance Method Summary collapse

Methods inherited from Body

#height, #initialize, new, #scale, #width

Constructor Details

This class inherits a constructor from RQRCode::Renderer::Body

Instance Method Details

#each {|%{<?xml version="1.0" standalone="yes"?>}| ... } ⇒ Object

Yields:

  • (%{<?xml version="1.0" standalone="yes"?>})


99
100
101
102
103
104
105
106
107
108
# File 'lib/rqrcode/renderer.rb', line 99

def each
  yield %{<?xml version="1.0" standalone="yes"?>}
  yield %{<svg xmlns="http://www.w3.org/2000/svg" width="#{width * scale}" height="#{height * scale}">}
  modules.each.with_index do |row, y|
    row.each.with_index do |dark, x|
      yield %{<rect width="#{scale}" height="#{scale}" x="#{x * scale}" y="#{y * scale}" style="fill:#{COLORS[dark]}"/>}
    end
  end
  yield %{</svg>}
end