lib/prawn/svg/svg.rb in prawn-svg-0.9.1.1 vs lib/prawn/svg/svg.rb in prawn-svg-0.9.1.2

- old
+ new

@@ -133,41 +133,48 @@ end calls << ['text_box', [element.text, opts], []] when 'line' + return unless attrs['x1'] && attrs['y1'] && attrs['x2'] && attrs['y2'] calls << ['line', [x(attrs['x1']), y(attrs['y1']), x(attrs['x2']), y(attrs['y2'])], []] when 'polyline' + return unless attrs['points'] points = attrs['points'].split(/\s+/) - x, y = points.shift.split(",") + return unless base_point = points.shift + x, y = base_point.split(",") calls << ['move_to', [x(x), y(y)], []] calls << ['stroke', [], []] calls = calls.last.last points.each do |point| x, y = point.split(",") calls << ["line_to", [x(x), y(y)], []] end when 'polygon' + return unless attrs['points'] points = attrs['points'].split(/\s+/).collect do |point| x, y = point.split(",") [x(x), y(y)] end calls << ["polygon", points, []] when 'circle' + return unless attrs['r'] calls << ["circle_at", [[x(attrs['cx'] || "0"), y(attrs['cy'] || "0")], {:radius => distance(attrs['r'])}], []] when 'ellipse' + return unless attrs['rx'] && attrs['ry'] calls << ["ellipse_at", [[x(attrs['cx'] || "0"), y(attrs['cy'] || "0")], distance(attrs['rx']), distance(attrs['ry'])], []] when 'rect' + return unless attrs['x'] && attrs['y'] && attrs['width'] && attrs['height'] radius = distance(attrs['rx'] || attrs['ry']) args = [[x(attrs['x']), y(attrs['y'])], distance(attrs['width']), distance(attrs['height'])] if radius # n.b. does not support both rx and ry being specified with different values calls << ["rounded_rectangle", args + [radius], []] @@ -278,21 +285,21 @@ end end end def x(value) - (pixels(value) - @x_offset) * scale + (points(value) - @x_offset) * scale end def y(value) - (@actual_height - (pixels(value) - @y_offset)) * scale + (@actual_height - (points(value) - @y_offset)) * scale end def distance(value) - value && (pixels(value) * scale) + value && (points(value) * scale) end - def pixels(value) + def points(value) if value.is_a?(String) && match = value.match(/\d(cm|dm|ft|in|m|mm|yd)$/) send("#{match[1]}2pt", value.to_f) else value.to_f end