def to_svg(opts={})
with_options opts do
case opts[:use]
when 'rects' then bars = bars_to_rects
when 'path' then bars = bars_to_path
else
xdim_odd = (xdim % 2 == 1)
bars = xdim_odd ? bars_to_rects : bars_to_path
end
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<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\">\n<title>\#{escape title}</title>\n<g id=\"canvas\" \#{transform(opts)}>\n<rect x=\"0\" y=\"0\" width=\"\#{full_width}px\" height=\"\#{full_height}px\" fill=\"white\" />\n<g id=\"barcode\" fill=\"black\">\n\#{bars}\n</g></g>\n</svg>\n"
end
end