lib/barby/outputter/svg_outputter.rb in barby-0.6.6 vs lib/barby/outputter/svg_outputter.rb in barby-0.6.7

- old
+ new

@@ -19,11 +19,10 @@ register :to_svg, :bars_to_rects, :bars_to_path attr_writer :title, :xdim, :ydim, :height, :rmargin, :lmargin, :tmargin, :bmargin, :xmargin, :ymargin, :margin - def initialize(*) super @title, @xdim, @ydim, @height, @rmargin, @lmargin, @tmargin, @bmargin, @xmargin, @ymargin, @margin = nil end @@ -37,11 +36,11 @@ bars = xdim_odd ? bars_to_rects : bars_to_path end <<-"EOT" <?xml version="1.0" encoding="UTF-8"?> -<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="#{svg_width(opts)}px" height="#{svg_height(opts)}px" viewBox="0 0 #{svg_width(opts)} #{svg_height(opts)}" version="1.1"> +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="#{svg_width(opts)}px" height="#{svg_height(opts)}px" viewBox="0 0 #{svg_width(opts)} #{svg_height(opts)}" version="1.1" preserveAspectRatio="none" > <title>#{escape title}</title> <g id="canvas" #{transform(opts)}> <rect x="0" y="0" width="#{full_width}px" height="#{full_height}px" fill="white" /> <g id="barcode" fill="black"> #{bars} @@ -49,11 +48,10 @@ </svg> EOT end end - def bars_to_rects(opts={}) rects = '' with_options opts do x, y = lmargin, tmargin @@ -83,18 +81,16 @@ end # with_options rects end - def bars_to_path(opts={}) with_options opts do %Q|<path stroke="black" stroke-width="#{xdim}" d="#{bars_to_path_data(opts)}" />| end end - def bars_to_path_data(opts={}) path_data = '' with_options opts do x, y = lmargin+(xdim/2), tmargin @@ -122,16 +118,14 @@ end # with_options path_data end - def title @title || barcode.to_s end - def width length * xdim end def height @@ -187,25 +181,22 @@ def length barcode.two_dimensional? ? encoding.first.length : encoding.length end - def svg_width(opts={}) opts[:rot] ? full_height : full_width end def svg_height(opts={}) opts[:rot] ? full_width : full_height end - def transform(opts={}) opts[:rot] ? %Q|transform="rotate(-90) translate(-#{full_width}, 0)"| : nil end - private def _xmargin @xmargin || _margin end @@ -221,10 +212,8 @@ #Escape XML special characters <, & and > def escape(str) str.gsub('&', '&amp;').gsub('<', '&lt;').gsub('>', '&gt;') end - end - end