prawn-svg 0.9.1.4 → 0.9.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/prawn/svg/parser.rb +23 -11
- data/lib/prawn/svg/svg.rb +1 -1
- metadata +3 -3
data/lib/prawn/svg/parser.rb
CHANGED
@@ -32,11 +32,16 @@ class Prawn::Svg::Parser
|
|
32
32
|
#
|
33
33
|
# Construct a Parser object.
|
34
34
|
#
|
35
|
-
# The +data+ argument is SVG data.
|
35
|
+
# The +data+ argument is SVG data.
|
36
|
+
#
|
37
|
+
# +bounds+ is a tuple [width, height] that specifies the bounds of the drawing space in points.
|
38
|
+
#
|
39
|
+
# +options+ can optionally contain
|
36
40
|
# the key :width or :height. If both are specified, only :width will be used.
|
37
41
|
#
|
38
|
-
def initialize(data, options)
|
42
|
+
def initialize(data, bounds, options)
|
39
43
|
@data = data
|
44
|
+
@bounds = bounds
|
40
45
|
@options = options
|
41
46
|
@warnings = []
|
42
47
|
@css_parser = CssParser::Parser.new if CSS_PARSER_LOADED
|
@@ -66,6 +71,7 @@ class Prawn::Svg::Parser
|
|
66
71
|
private
|
67
72
|
def parse_document
|
68
73
|
@root = REXML::Document.new(@data).root
|
74
|
+
@actual_width, @actual_height = @bounds # set this first so % width/heights can be used
|
69
75
|
|
70
76
|
if vb = @root.attributes['viewBox']
|
71
77
|
x1, y1, x2, y2 = vb.strip.split(/\s+/)
|
@@ -73,8 +79,8 @@ class Prawn::Svg::Parser
|
|
73
79
|
@actual_width, @actual_height = [x2.to_f - x1.to_f, y2.to_f - y1.to_f]
|
74
80
|
else
|
75
81
|
@x_offset, @y_offset = [0, 0]
|
76
|
-
@actual_width = @root.attributes['width']
|
77
|
-
@actual_height = @root.attributes['height']
|
82
|
+
@actual_width = points(@root.attributes['width'], :x)
|
83
|
+
@actual_height = points(@root.attributes['height'], :y)
|
78
84
|
end
|
79
85
|
end
|
80
86
|
|
@@ -361,20 +367,26 @@ class Prawn::Svg::Parser
|
|
361
367
|
end
|
362
368
|
|
363
369
|
def x(value)
|
364
|
-
(points(value) - @x_offset) * scale
|
370
|
+
(points(value, :x) - @x_offset) * scale
|
365
371
|
end
|
366
372
|
|
367
373
|
def y(value)
|
368
|
-
(@actual_height - (points(value) - @y_offset)) * scale
|
374
|
+
(@actual_height - (points(value, :y) - @y_offset)) * scale
|
369
375
|
end
|
370
376
|
|
371
|
-
def distance(value)
|
372
|
-
value && (points(value) * scale)
|
377
|
+
def distance(value, axis = nil)
|
378
|
+
value && (points(value, axis) * scale)
|
373
379
|
end
|
374
380
|
|
375
|
-
def points(value)
|
376
|
-
if value.is_a?(String)
|
377
|
-
|
381
|
+
def points(value, axis = nil)
|
382
|
+
if value.is_a?(String)
|
383
|
+
if match = value.match(/\d(cm|dm|ft|in|m|mm|yd)$/)
|
384
|
+
send("#{match[1]}2pt", value.to_f)
|
385
|
+
elsif value[-1..-1] == "%"
|
386
|
+
value.to_f * (axis == :y ? @actual_height : @actual_width) / 100.0
|
387
|
+
else
|
388
|
+
value.to_f
|
389
|
+
end
|
378
390
|
else
|
379
391
|
value.to_f
|
380
392
|
end
|
data/lib/prawn/svg/svg.rb
CHANGED
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 0
|
7
7
|
- 9
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.9.1.
|
9
|
+
- 5
|
10
|
+
version: 0.9.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Roger Nesbitt
|
@@ -63,7 +63,7 @@ files:
|
|
63
63
|
- lib/prawn/svg_document.rb
|
64
64
|
- lib/prawn-svg.rb
|
65
65
|
has_rdoc: true
|
66
|
-
homepage:
|
66
|
+
homepage: http://github.com/mogest/prawn-svg
|
67
67
|
licenses: []
|
68
68
|
|
69
69
|
post_install_message:
|