module RQRCode module Renderers class SVG class << self # Render the SVG from the qrcode string provided from the RQRCode gem # Options: # offset - Padding around the QR Code (e.g. 10) # unit - How many pixels per module (Default: 11) # fill - Background color (e.g "ffffff" or :white) # color - Foreground color for the code (e.g. "000000" or :black) def render(qrcode, options={}) offset = options[:offset].to_i || 0 color = options[:color] || "000" unit = options[:unit] || 11 # height and width dependent on offset and QR complexity dimension = (qrcode.modules.count*unit) + (2*offset) xml_tag = %{} open_tag = %{} close_tag = "" result = [] for c in 0...qrcode.modules.count tmp = [] for r in 0...qrcode.modules.count y = c*unit + offset x = r*unit + offset next unless qrcode.qrcode.checked?(c, r) tmp << %{} end result << tmp.join("\n") end if options[:fill] result.unshift %{} end return [xml_tag, open_tag, result, close_tag].flatten.join("\n") unless options[:qcontainer] svg = File.read(File.expand_path('../../qr_container.svg', __FILE__)) svg.gsub!(/#table_number/, options[:table_number].to_s) svg.gsub!(/#qrcode/, result.join("\n")) svg end end end end end