prawn-svg 0.9.1.1 → 0.9.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/prawn/svg/svg.rb +12 -5
  2. metadata +2 -2
data/lib/prawn/svg/svg.rb CHANGED
@@ -135,11 +135,14 @@ class Prawn::Svg
135
135
  calls << ['text_box', [element.text, opts], []]
136
136
 
137
137
  when 'line'
138
+ return unless attrs['x1'] && attrs['y1'] && attrs['x2'] && attrs['y2']
138
139
  calls << ['line', [x(attrs['x1']), y(attrs['y1']), x(attrs['x2']), y(attrs['y2'])], []]
139
140
 
140
141
  when 'polyline'
142
+ return unless attrs['points']
141
143
  points = attrs['points'].split(/\s+/)
142
- x, y = points.shift.split(",")
144
+ return unless base_point = points.shift
145
+ x, y = base_point.split(",")
143
146
  calls << ['move_to', [x(x), y(y)], []]
144
147
  calls << ['stroke', [], []]
145
148
  calls = calls.last.last
@@ -149,6 +152,7 @@ class Prawn::Svg
149
152
  end
150
153
 
151
154
  when 'polygon'
155
+ return unless attrs['points']
152
156
  points = attrs['points'].split(/\s+/).collect do |point|
153
157
  x, y = point.split(",")
154
158
  [x(x), y(y)]
@@ -156,16 +160,19 @@ class Prawn::Svg
156
160
  calls << ["polygon", points, []]
157
161
 
158
162
  when 'circle'
163
+ return unless attrs['r']
159
164
  calls << ["circle_at",
160
165
  [[x(attrs['cx'] || "0"), y(attrs['cy'] || "0")], {:radius => distance(attrs['r'])}],
161
166
  []]
162
167
 
163
168
  when 'ellipse'
169
+ return unless attrs['rx'] && attrs['ry']
164
170
  calls << ["ellipse_at",
165
171
  [[x(attrs['cx'] || "0"), y(attrs['cy'] || "0")], distance(attrs['rx']), distance(attrs['ry'])],
166
172
  []]
167
173
 
168
174
  when 'rect'
175
+ return unless attrs['x'] && attrs['y'] && attrs['width'] && attrs['height']
169
176
  radius = distance(attrs['rx'] || attrs['ry'])
170
177
  args = [[x(attrs['x']), y(attrs['y'])], distance(attrs['width']), distance(attrs['height'])]
171
178
  if radius
@@ -280,18 +287,18 @@ class Prawn::Svg
280
287
  end
281
288
 
282
289
  def x(value)
283
- (pixels(value) - @x_offset) * scale
290
+ (points(value) - @x_offset) * scale
284
291
  end
285
292
 
286
293
  def y(value)
287
- (@actual_height - (pixels(value) - @y_offset)) * scale
294
+ (@actual_height - (points(value) - @y_offset)) * scale
288
295
  end
289
296
 
290
297
  def distance(value)
291
- value && (pixels(value) * scale)
298
+ value && (points(value) * scale)
292
299
  end
293
300
 
294
- def pixels(value)
301
+ def points(value)
295
302
  if value.is_a?(String) && match = value.match(/\d(cm|dm|ft|in|m|mm|yd)$/)
296
303
  send("#{match[1]}2pt", value.to_f)
297
304
  else
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 9
8
8
  - 1
9
- - 1
10
- version: 0.9.1.1
9
+ - 2
10
+ version: 0.9.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roger Nesbitt