prawn-svg 0.31.0 → 0.33.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +35 -0
- data/README.md +8 -6
- data/lib/prawn/svg/attributes/stroke.rb +5 -0
- data/lib/prawn/svg/color.rb +46 -22
- data/lib/prawn/svg/css/selector_parser.rb +11 -11
- data/lib/prawn/svg/css/stylesheets.rb +4 -4
- data/lib/prawn/svg/document.rb +15 -2
- data/lib/prawn/svg/elements/base.rb +15 -16
- data/lib/prawn/svg/elements/call_duplicator.rb +1 -1
- data/lib/prawn/svg/elements/gradient.rb +2 -2
- data/lib/prawn/svg/elements/image.rb +6 -7
- data/lib/prawn/svg/elements/path.rb +0 -2
- data/lib/prawn/svg/elements/root.rb +1 -1
- data/lib/prawn/svg/elements/text_component.rb +10 -5
- data/lib/prawn/svg/gradients.rb +48 -0
- data/lib/prawn/svg/interface.rb +23 -8
- data/lib/prawn/svg/properties.rb +2 -0
- data/lib/prawn/svg/version.rb +1 -1
- data/lib/prawn-svg.rb +1 -0
- data/prawn-svg.gemspec +17 -15
- data/spec/integration_spec.rb +24 -24
- data/spec/prawn/svg/color_spec.rb +29 -16
- data/spec/prawn/svg/css/stylesheets_spec.rb +1 -19
- data/spec/prawn/svg/document_spec.rb +17 -0
- data/spec/prawn/svg/elements/base_spec.rb +15 -15
- data/spec/prawn/svg/elements/line_spec.rb +12 -12
- data/spec/prawn/svg/elements/marker_spec.rb +27 -27
- data/spec/prawn/svg/elements/polygon_spec.rb +9 -9
- data/spec/prawn/svg/elements/polyline_spec.rb +7 -7
- data/spec/prawn/svg/elements/root_spec.rb +28 -0
- data/spec/prawn/svg/elements/text_spec.rb +80 -53
- data/spec/prawn/svg/interface_spec.rb +10 -2
- data/spec/prawn/svg/pathable_spec.rb +4 -4
- data/spec/sample_svg/cmyk.svg +5 -0
- data/spec/sample_svg/gradients-cmyk.svg +40 -0
- data/spec/sample_svg/ordering.svg +12 -0
- data/spec/spec_helper.rb +2 -2
- metadata +53 -16
- data/.travis.yml +0 -8
data/lib/prawn/svg/properties.rb
CHANGED
@@ -34,10 +34,12 @@ class Prawn::SVG::Properties
|
|
34
34
|
"stroke" => Config.new("none", true, %w(inherit none currentColor)),
|
35
35
|
"stroke-dasharray" => Config.new("none", true, %w(inherit none)),
|
36
36
|
"stroke-linecap" => Config.new("butt", true, %w(inherit butt round square), true),
|
37
|
+
"stroke-linejoin" => Config.new("miter", true, %w(inherit miter round bevel), true),
|
37
38
|
"stroke-opacity" => Config.new("1", true),
|
38
39
|
"stroke-width" => Config.new("1", true),
|
39
40
|
"text-anchor" => Config.new("start", true, %w(inherit start middle end), true),
|
40
41
|
'text-decoration' => Config.new('none', true, %w(inherit none underline), true),
|
42
|
+
"dominant-baseline" => Config.new("auto", true, %w(inherit auto middle), true),
|
41
43
|
}.freeze
|
42
44
|
|
43
45
|
PROPERTIES.each do |name, value|
|
data/lib/prawn/svg/version.rb
CHANGED
data/lib/prawn-svg.rb
CHANGED
data/prawn-svg.gemspec
CHANGED
@@ -1,26 +1,28 @@
|
|
1
|
-
|
2
|
-
require File.expand_path('../lib/prawn/svg/version', __FILE__)
|
1
|
+
require File.expand_path('lib/prawn/svg/version', __dir__)
|
3
2
|
|
4
3
|
Gem::Specification.new do |gem|
|
5
4
|
gem.name = 'prawn-svg'
|
6
5
|
gem.version = Prawn::SVG::VERSION
|
7
|
-
gem.summary =
|
8
|
-
gem.description =
|
9
|
-
|
10
|
-
|
11
|
-
gem.
|
6
|
+
gem.summary = 'SVG renderer for Prawn PDF library'
|
7
|
+
gem.description = <<-EOT.strip
|
8
|
+
This gem allows you to render SVG directly into a PDF using the 'prawn' gem. Since PDF is vector-based, you'll get nice scaled graphics if you use SVG instead of an image.
|
9
|
+
EOT
|
10
|
+
gem.author = 'Mog Nesbitt'
|
11
|
+
gem.email = 'mog@seriousorange.com'
|
12
|
+
gem.homepage = 'http://github.com/mogest/prawn-svg'
|
12
13
|
gem.license = 'MIT'
|
13
14
|
|
14
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
15
16
|
gem.files = `git ls-files`.split("\n")
|
16
17
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
-
gem.
|
18
|
-
gem.require_paths = ["lib"]
|
18
|
+
gem.require_paths = ['lib']
|
19
19
|
|
20
|
-
gem.required_ruby_version = '>= 2.
|
20
|
+
gem.required_ruby_version = '>= 2.5.0'
|
21
21
|
|
22
|
-
gem.add_runtime_dependency
|
23
|
-
gem.add_runtime_dependency
|
24
|
-
gem.
|
25
|
-
gem.
|
22
|
+
gem.add_runtime_dependency 'css_parser', '~> 1.6'
|
23
|
+
gem.add_runtime_dependency 'matrix', '~> 0.4.2'
|
24
|
+
gem.add_runtime_dependency 'prawn', '>= 0.11.1', '< 3'
|
25
|
+
gem.add_runtime_dependency 'rexml', '~> 3.2'
|
26
|
+
gem.add_development_dependency 'rake', '~> 13.0'
|
27
|
+
gem.add_development_dependency 'rspec', '~> 3.0'
|
26
28
|
end
|
data/spec/integration_spec.rb
CHANGED
@@ -28,34 +28,34 @@ describe "Integration test" do
|
|
28
28
|
element.process
|
29
29
|
|
30
30
|
expect(element.calls).to eq [
|
31
|
-
["fill_color", ["000000"], []],
|
32
|
-
["transformation_matrix", [1, 0, 0, 1, 0, 0], []],
|
33
|
-
["transformation_matrix", [1, 0, 0, 1, 0, 0], []],
|
34
|
-
["save", [], []], ["restore", [], []],
|
35
|
-
["save", [], []],
|
36
|
-
["fill_color", ["0000ff"], []],
|
37
|
-
["fill", [], [
|
38
|
-
["rectangle", [[0.0, 200.0], 10.0, 10.0], []]
|
31
|
+
["fill_color", ["000000"], {}, []],
|
32
|
+
["transformation_matrix", [1, 0, 0, 1, 0, 0], {}, []],
|
33
|
+
["transformation_matrix", [1, 0, 0, 1, 0, 0], {}, []],
|
34
|
+
["save", [], {}, []], ["restore", [], {}, []],
|
35
|
+
["save", [], {}, []],
|
36
|
+
["fill_color", ["0000ff"], {}, []],
|
37
|
+
["fill", [], {}, [
|
38
|
+
["rectangle", [[0.0, 200.0], 10.0, 10.0], {}, []]
|
39
39
|
]],
|
40
|
-
["restore", [], []],
|
41
|
-
["save", [], []],
|
42
|
-
["fill_color", ["008000"], []],
|
43
|
-
["fill", [], [
|
44
|
-
["rectangle", [[10.0, 200.0], 10.0, 10.0], []]
|
40
|
+
["restore", [], {}, []],
|
41
|
+
["save", [], {}, []],
|
42
|
+
["fill_color", ["008000"], {}, []],
|
43
|
+
["fill", [], {}, [
|
44
|
+
["rectangle", [[10.0, 200.0], 10.0, 10.0], {}, []]
|
45
45
|
]],
|
46
|
-
["restore", [], []],
|
47
|
-
["save", [], []],
|
48
|
-
["fill_color", ["ff0000"], []],
|
49
|
-
["fill", [], [
|
50
|
-
["rectangle", [[20.0, 200.0], 10.0, 10.0], []]
|
46
|
+
["restore", [], {}, []],
|
47
|
+
["save", [], {}, []],
|
48
|
+
["fill_color", ["ff0000"], {}, []],
|
49
|
+
["fill", [], {}, [
|
50
|
+
["rectangle", [[20.0, 200.0], 10.0, 10.0], {}, []]
|
51
51
|
]],
|
52
|
-
["restore", [], []],
|
53
|
-
["save", [], []],
|
54
|
-
["fill_color", ["ffff00"], []],
|
55
|
-
["fill", [], [
|
56
|
-
["rectangle", [[30.0, 200.0], 10.0, 10.0], []]
|
52
|
+
["restore", [], {}, []],
|
53
|
+
["save", [], {}, []],
|
54
|
+
["fill_color", ["ffff00"], {}, []],
|
55
|
+
["fill", [], {}, [
|
56
|
+
["rectangle", [[30.0, 200.0], 10.0, 10.0], {}, []]
|
57
57
|
]],
|
58
|
-
["restore", [], []]
|
58
|
+
["restore", [], {}, []]
|
59
59
|
]
|
60
60
|
end
|
61
61
|
end
|
@@ -1,38 +1,43 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
|
3
3
|
describe Prawn::SVG::Color do
|
4
|
-
describe "::
|
4
|
+
describe "::css_color_to_prawn_color" do
|
5
5
|
it "converts #xxx to a hex value" do
|
6
|
-
Prawn::SVG::Color.
|
6
|
+
Prawn::SVG::Color.css_color_to_prawn_color("#9ab").should == "99aabb"
|
7
7
|
end
|
8
8
|
|
9
9
|
it "converts #xxxxxx to a hex value" do
|
10
|
-
Prawn::SVG::Color.
|
10
|
+
Prawn::SVG::Color.css_color_to_prawn_color("#9ab123").should == "9ab123"
|
11
11
|
end
|
12
12
|
|
13
13
|
it "converts an html colour name to a hex value" do
|
14
|
-
Prawn::SVG::Color.
|
14
|
+
Prawn::SVG::Color.css_color_to_prawn_color("White").should == "ffffff"
|
15
15
|
end
|
16
16
|
|
17
17
|
it "converts an rgb string to a hex value" do
|
18
|
-
Prawn::SVG::Color.
|
19
|
-
Prawn::SVG::Color.
|
18
|
+
Prawn::SVG::Color.css_color_to_prawn_color("rgb(16, 32, 48)").should == "102030"
|
19
|
+
Prawn::SVG::Color.css_color_to_prawn_color("rgb(-5, 50%, 120%)").should == "007fff"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "converts a CMYK string to an array of numbers" do
|
23
|
+
expect(Prawn::SVG::Color.css_color_to_prawn_color("device-cmyk(0, 0.32, 0.48, 1)")).to eq [0, 32, 48, 100]
|
24
|
+
expect(Prawn::SVG::Color.css_color_to_prawn_color("device-cmyk(-5, 50%, 120%, -5%)")).to eq [0, 50, 100, 0]
|
20
25
|
end
|
21
26
|
|
22
27
|
it "scans the string and finds the first colour it can parse" do
|
23
|
-
Prawn::SVG::Color.
|
28
|
+
Prawn::SVG::Color.css_color_to_prawn_color("function(#someurl, 0) nonexistent rgb( 3 ,4,5 ) white").should == "030405"
|
24
29
|
end
|
25
30
|
|
26
31
|
it "ignores url()s" do
|
27
|
-
expect(Prawn::SVG::Color.
|
32
|
+
expect(Prawn::SVG::Color.css_color_to_prawn_color("url(#someplace) red")).to eq 'ff0000'
|
28
33
|
end
|
29
34
|
|
30
35
|
it "returns black if the color doesn't exist" do
|
31
|
-
expect(Prawn::SVG::Color.
|
36
|
+
expect(Prawn::SVG::Color.css_color_to_prawn_color("blurble")).to eq '000000'
|
32
37
|
end
|
33
38
|
|
34
39
|
it "returns nil if there's no fallback after a url()" do
|
35
|
-
expect(Prawn::SVG::Color.
|
40
|
+
expect(Prawn::SVG::Color.css_color_to_prawn_color("url(#someplace)")).to be nil
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
@@ -42,19 +47,27 @@ describe Prawn::SVG::Color do
|
|
42
47
|
let(:drob_gradient) { double }
|
43
48
|
|
44
49
|
it "returns a list of all colors parsed, ignoring impossible or non-existent colors" do
|
45
|
-
results = Prawn::SVG::Color.parse("url(#nope) url(#flan) blurble green #123", gradients)
|
50
|
+
results = Prawn::SVG::Color.parse("url(#nope) url(#flan) blurble green #123", gradients, :rgb)
|
46
51
|
expect(results).to eq [
|
47
52
|
flan_gradient,
|
48
|
-
Prawn::SVG::Color::
|
49
|
-
Prawn::SVG::Color::
|
53
|
+
Prawn::SVG::Color::RGB.new("008000"),
|
54
|
+
Prawn::SVG::Color::RGB.new("112233")
|
50
55
|
]
|
51
56
|
end
|
52
57
|
|
53
58
|
it "appends black to the list if there aren't any url() references" do
|
54
|
-
results = Prawn::SVG::Color.parse("blurble green", gradients)
|
59
|
+
results = Prawn::SVG::Color.parse("blurble green", gradients, :rgb)
|
60
|
+
expect(results).to eq [
|
61
|
+
Prawn::SVG::Color::RGB.new("008000"),
|
62
|
+
Prawn::SVG::Color::RGB.new("000000")
|
63
|
+
]
|
64
|
+
end
|
65
|
+
|
66
|
+
it "works in CMYK color mode" do
|
67
|
+
results = Prawn::SVG::Color.parse("blurble green", gradients, :cmyk)
|
55
68
|
expect(results).to eq [
|
56
|
-
Prawn::SVG::Color::
|
57
|
-
Prawn::SVG::Color::
|
69
|
+
Prawn::SVG::Color::CMYK.new([100, 0, 100, 50]),
|
70
|
+
Prawn::SVG::Color::CMYK.new([0, 0, 0, 100])
|
58
71
|
]
|
59
72
|
end
|
60
73
|
end
|
@@ -68,25 +68,7 @@ RSpec.describe Prawn::SVG::CSS::Stylesheets do
|
|
68
68
|
[4, [["fill", "#ff0000", false], ["fill", "#330000", false], ["fill", "#440000", false], ["fill", "#00ff00", false]]],
|
69
69
|
]
|
70
70
|
|
71
|
-
#
|
72
|
-
# Under ruby < 2.6, a bug in REXML causes the /following-sibling selector to
|
73
|
-
# only pick the first matching sibling. This means the + CSS combinator behaves
|
74
|
-
# incorrectly in the following example:
|
75
|
-
#
|
76
|
-
# <a>
|
77
|
-
# <b a="1" />
|
78
|
-
# <b a="2" />
|
79
|
-
# <b a="3" />
|
80
|
-
# </a>
|
81
|
-
#
|
82
|
-
# The css selector `a b + b` will only pick the second <b>, whereas it should
|
83
|
-
# pick both the second and third <b> elements.
|
84
|
-
#
|
85
|
-
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.6.0')
|
86
|
-
expected << [5, [["fill", "#ff0000", false], ["fill", "#330000", false], ["fill", "#330000", false], ["fill", "#00ff00", false]]]
|
87
|
-
else
|
88
|
-
expected << [5, [["fill", "#ff0000", false], ["fill", "#330000", false], ["fill", "#330000", false], ["fill", "#440000", false], ["fill", "#00ff00", false]]]
|
89
|
-
end
|
71
|
+
expected << [5, [["fill", "#ff0000", false], ["fill", "#330000", false], ["fill", "#330000", false], ["fill", "#440000", false], ["fill", "#00ff00", false]]]
|
90
72
|
|
91
73
|
expected.concat [
|
92
74
|
[6, [["fill", "#ff0000", false], ["fill", "#441234", false], ["fill", "#0000ff", false]]],
|
@@ -5,6 +5,23 @@ describe Prawn::SVG::Document do
|
|
5
5
|
let(:options) { {} }
|
6
6
|
|
7
7
|
describe "#initialize" do
|
8
|
+
context "with a well-formed document" do
|
9
|
+
let(:svg) { "<svg></svg>" }
|
10
|
+
let(:options) { {color_mode: :cmyk} }
|
11
|
+
|
12
|
+
it "parses the XML and yields itself to its block" do
|
13
|
+
yielded = nil
|
14
|
+
|
15
|
+
document = Prawn::SVG::Document.new(svg, bounds, options) do |doc|
|
16
|
+
yielded = doc
|
17
|
+
end
|
18
|
+
|
19
|
+
expect(yielded).to eq document
|
20
|
+
expect(document.color_mode).to eq :cmyk
|
21
|
+
expect(document.root.name).to eq 'svg'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
8
25
|
context "when unparsable XML is provided" do
|
9
26
|
let(:svg) { "this isn't SVG data" }
|
10
27
|
|
@@ -32,12 +32,12 @@ describe Prawn::SVG::Elements::Base do
|
|
32
32
|
it "appends the relevant calls" do
|
33
33
|
element.process
|
34
34
|
expect(element.base_calls).to eq [
|
35
|
-
["transformation_matrix", [2, 0, 0, 2, 0, 0], [
|
36
|
-
["transparent", [0.5, 1], [
|
37
|
-
["fill_color", ["ff0000"], []],
|
38
|
-
["stroke_color", ["0000ff"], []],
|
39
|
-
["line_width", [5.0], []],
|
40
|
-
["fill_and_stroke", [], []]
|
35
|
+
["transformation_matrix", [2, 0, 0, 2, 0, 0], {}, [
|
36
|
+
["transparent", [0.5, 1], {}, [
|
37
|
+
["fill_color", ["ff0000"], {}, []],
|
38
|
+
["stroke_color", ["0000ff"], {}, []],
|
39
|
+
["line_width", [5.0], {}, []],
|
40
|
+
["fill_and_stroke", [], {}, []]
|
41
41
|
]]
|
42
42
|
]]
|
43
43
|
]
|
@@ -50,37 +50,37 @@ describe Prawn::SVG::Elements::Base do
|
|
50
50
|
|
51
51
|
context "with neither fill nor stroke" do
|
52
52
|
let(:svg) { '<rect style="fill: none;"></rect>' }
|
53
|
-
it { is_expected.to eq ['end_path', [], []] }
|
53
|
+
it { is_expected.to eq ['end_path', [], {}, []] }
|
54
54
|
end
|
55
55
|
|
56
56
|
context "with a fill only" do
|
57
57
|
let(:svg) { '<rect style="fill: black;"></rect>' }
|
58
|
-
it { is_expected.to eq ['fill', [], []] }
|
58
|
+
it { is_expected.to eq ['fill', [], {}, []] }
|
59
59
|
end
|
60
60
|
|
61
61
|
context "with a stroke only" do
|
62
62
|
let(:svg) { '<rect style="fill: none; stroke: black;"></rect>' }
|
63
|
-
it { is_expected.to eq ['stroke', [], []] }
|
63
|
+
it { is_expected.to eq ['stroke', [], {}, []] }
|
64
64
|
end
|
65
65
|
|
66
66
|
context "with fill and stroke" do
|
67
67
|
let(:svg) { '<rect style="fill: black; stroke: black;"></rect>' }
|
68
|
-
it { is_expected.to eq ['fill_and_stroke', [], []] }
|
68
|
+
it { is_expected.to eq ['fill_and_stroke', [], {}, []] }
|
69
69
|
end
|
70
70
|
|
71
71
|
context "with fill with evenodd fill rule" do
|
72
72
|
let(:svg) { '<rect style="fill: black; fill-rule: evenodd;"></rect>' }
|
73
|
-
it { is_expected.to eq ['fill', [{fill_rule: :even_odd}
|
73
|
+
it { is_expected.to eq ['fill', [], {fill_rule: :even_odd}, []] }
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
it "appends calls to the parent element" do
|
78
78
|
expect(element).to receive(:apply) do
|
79
|
-
element.send :add_call, "test", "argument"
|
79
|
+
element.send :add_call, "test", "argument", kw: 'argument'
|
80
80
|
end
|
81
81
|
|
82
82
|
element.process
|
83
|
-
expect(element.parent_calls).to eq [["fill", [], [["test", ["argument"], []]]]]
|
83
|
+
expect(element.parent_calls).to eq [["fill", [], {}, [["test", ["argument"], {kw: 'argument'}, []]]]]
|
84
84
|
end
|
85
85
|
|
86
86
|
it "quietly absorbs a SkipElementQuietly exception" do
|
@@ -149,8 +149,8 @@ describe Prawn::SVG::Elements::Base do
|
|
149
149
|
it "uses the parent's color element if 'currentColor' fill attribute provided" do
|
150
150
|
element.process
|
151
151
|
|
152
|
-
expect(flattened_calls).to include ['fill_color', ['ff0000']]
|
153
|
-
expect(flattened_calls).not_to include ['fill_color', ['00ff00']]
|
152
|
+
expect(flattened_calls).to include ['fill_color', ['ff0000'], {}]
|
153
|
+
expect(flattened_calls).not_to include ['fill_color', ['00ff00'], {}]
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
@@ -13,10 +13,10 @@ RSpec.describe Prawn::SVG::Elements::Line do
|
|
13
13
|
it "renders the line" do
|
14
14
|
subject.process
|
15
15
|
expect(subject.base_calls).to eq [
|
16
|
-
["stroke_color", ["000000"], []],
|
17
|
-
["stroke", [], [
|
18
|
-
["move_to", [[5.0, 590.0]], []],
|
19
|
-
["line_to", [[15.0, 580.0]], []]]
|
16
|
+
["stroke_color", ["000000"], {}, []],
|
17
|
+
["stroke", [], {}, [
|
18
|
+
["move_to", [[5.0, 590.0]], {}, []],
|
19
|
+
["line_to", [[15.0, 580.0]], {}, []]]
|
20
20
|
]
|
21
21
|
]
|
22
22
|
end
|
@@ -28,9 +28,9 @@ RSpec.describe Prawn::SVG::Elements::Line do
|
|
28
28
|
it "outlines a path from 0,0 to 0,0" do
|
29
29
|
subject.process
|
30
30
|
expect(subject.base_calls).to eq [
|
31
|
-
["end_path", [], [
|
32
|
-
["move_to", [[0, 600]], []],
|
33
|
-
["line_to", [[0, 600]], []]]
|
31
|
+
["end_path", [], {}, [
|
32
|
+
["move_to", [[0, 600]], {}, []],
|
33
|
+
["line_to", [[0, 600]], {}, []]]
|
34
34
|
]
|
35
35
|
]
|
36
36
|
end
|
@@ -43,11 +43,11 @@ RSpec.describe Prawn::SVG::Elements::Line do
|
|
43
43
|
subject.process
|
44
44
|
|
45
45
|
expect(subject.base_calls).to eq [
|
46
|
-
["fill_color", ["0000ff"], []],
|
47
|
-
["stroke_color", ["ff0000"], []],
|
48
|
-
["stroke", [], [
|
49
|
-
["move_to", [[0, 600]], []],
|
50
|
-
["line_to", [[15.0, 580.0]], []]]
|
46
|
+
["fill_color", ["0000ff"], {}, []],
|
47
|
+
["stroke_color", ["ff0000"], {}, []],
|
48
|
+
["stroke", [], {}, [
|
49
|
+
["move_to", [[0, 600]], {}, []],
|
50
|
+
["line_to", [[15.0, 580.0]], {}, []]]
|
51
51
|
]
|
52
52
|
]
|
53
53
|
end
|
@@ -54,41 +54,41 @@ RSpec.describe Prawn::SVG::Elements::Marker do
|
|
54
54
|
# in section 11.6.3.
|
55
55
|
|
56
56
|
expect(line_element.base_calls).to eq [
|
57
|
-
["stroke_color", ["000000"], []],
|
58
|
-
["line_width", [100.0], []],
|
59
|
-
["stroke", [], [
|
60
|
-
["move_to", [[0.0, 600.0]], []],
|
61
|
-
["line_to", [[10.0, 590.0]], []]
|
57
|
+
["stroke_color", ["000000"], {}, []],
|
58
|
+
["line_width", [100.0], {}, []],
|
59
|
+
["stroke", [], {}, [
|
60
|
+
["move_to", [[0.0, 600.0]], {}, []],
|
61
|
+
["line_to", [[10.0, 590.0]], {}, []]
|
62
62
|
]
|
63
63
|
],
|
64
|
-
["save", [], []],
|
65
|
-
["transformation_matrix", [1, 0, 0, 1, 10, -10], []],
|
66
|
-
["rotate", [-45, {origin: [0, 600.0]}
|
67
|
-
["transformation_matrix", [100.0, 0, 0, 100.0, 0, 0], []],
|
68
|
-
["transformation_matrix", [1, 0, 0, 1, -0.0, 1.5], []],
|
69
|
-
["rectangle", [[-0.5, 600.0], 4.0, 3.0], []],
|
70
|
-
["clip", [], []],
|
71
|
-
["transformation_matrix", [0.3, 0, 0, 0.3, 0, 0], []],
|
72
|
-
["transparent", [1.0, 1.0], [
|
73
|
-
["stroke_color", ["000000"], []],
|
74
|
-
["line_width", [100.0], []],
|
75
|
-
["cap_style", [:butt], []],
|
76
|
-
["
|
77
|
-
["
|
78
|
-
["
|
79
|
-
|
80
|
-
["move_to", [[0.0, 600.0]], []],
|
81
|
-
["line_to", [[10.0, 595.0]], []],
|
82
|
-
["line_to", [[0.0, 590.0]], []],
|
83
|
-
["close_path", [], []]
|
64
|
+
["save", [], {}, []],
|
65
|
+
["transformation_matrix", [1, 0, 0, 1, 10, -10], {}, []],
|
66
|
+
["rotate", [-45], {origin: [0, 600.0]}, [
|
67
|
+
["transformation_matrix", [100.0, 0, 0, 100.0, 0, 0], {}, []],
|
68
|
+
["transformation_matrix", [1, 0, 0, 1, -0.0, 1.5], {}, []],
|
69
|
+
["rectangle", [[-0.5, 600.0], 4.0, 3.0], {}, []],
|
70
|
+
["clip", [], {}, []],
|
71
|
+
["transformation_matrix", [0.3, 0, 0, 0.3, 0, 0], {}, []],
|
72
|
+
["transparent", [1.0, 1.0], {}, [
|
73
|
+
["stroke_color", ["000000"], {}, []],
|
74
|
+
["line_width", [100.0], {}, []],
|
75
|
+
["cap_style", [:butt], {}, []],
|
76
|
+
["join_style", [:miter], {}, []],
|
77
|
+
["undash", [], {}, []],
|
78
|
+
["save", [], {}, []],
|
79
|
+
["fill", [], {}, [
|
80
|
+
["move_to", [[0.0, 600.0]], {}, []],
|
81
|
+
["line_to", [[10.0, 595.0]], {}, []],
|
82
|
+
["line_to", [[0.0, 590.0]], {}, []],
|
83
|
+
["close_path", [], {}, []]
|
84
84
|
]
|
85
85
|
],
|
86
|
-
["restore", [], []],
|
86
|
+
["restore", [], {}, []],
|
87
87
|
]
|
88
88
|
]
|
89
89
|
]
|
90
90
|
],
|
91
|
-
["restore", [], []]
|
91
|
+
["restore", [], {}, []]
|
92
92
|
]
|
93
93
|
end
|
94
94
|
end
|
@@ -13,11 +13,11 @@ RSpec.describe Prawn::SVG::Elements::Polygon do
|
|
13
13
|
it "renders the polygon" do
|
14
14
|
subject.process
|
15
15
|
expect(subject.base_calls).to eq [
|
16
|
-
["fill", [], [
|
17
|
-
["move_to", [[10.0, 590.0]], []],
|
18
|
-
["line_to", [[20.0, 580.0]], []],
|
19
|
-
["line_to", [[30.0, 570.0]], []],
|
20
|
-
["close_path", [], []]]
|
16
|
+
["fill", [], {}, [
|
17
|
+
["move_to", [[10.0, 590.0]], {}, []],
|
18
|
+
["line_to", [[20.0, 580.0]], {}, []],
|
19
|
+
["line_to", [[30.0, 570.0]], {}, []],
|
20
|
+
["close_path", [], {}, []]]
|
21
21
|
]
|
22
22
|
]
|
23
23
|
end
|
@@ -29,10 +29,10 @@ RSpec.describe Prawn::SVG::Elements::Polygon do
|
|
29
29
|
it "ignores the last one" do
|
30
30
|
subject.process
|
31
31
|
expect(subject.base_calls).to eq [
|
32
|
-
["fill", [], [
|
33
|
-
["move_to", [[10.0, 590.0]], []],
|
34
|
-
["line_to", [[20.0, 580.0]], []],
|
35
|
-
["close_path", [], []]]
|
32
|
+
["fill", [], {}, [
|
33
|
+
["move_to", [[10.0, 590.0]], {}, []],
|
34
|
+
["line_to", [[20.0, 580.0]], {}, []],
|
35
|
+
["close_path", [], {}, []]]
|
36
36
|
]
|
37
37
|
]
|
38
38
|
end
|
@@ -13,10 +13,10 @@ RSpec.describe Prawn::SVG::Elements::Polyline do
|
|
13
13
|
it "renders the polyline" do
|
14
14
|
subject.process
|
15
15
|
expect(subject.base_calls).to eq [
|
16
|
-
["fill", [], [
|
17
|
-
["move_to", [[10.0, 590.0]], []],
|
18
|
-
["line_to", [[20.0, 580.0]], []],
|
19
|
-
["line_to", [[30.0, 570.0]], []]]
|
16
|
+
["fill", [], {}, [
|
17
|
+
["move_to", [[10.0, 590.0]], {}, []],
|
18
|
+
["line_to", [[20.0, 580.0]], {}, []],
|
19
|
+
["line_to", [[30.0, 570.0]], {}, []]]
|
20
20
|
]
|
21
21
|
]
|
22
22
|
end
|
@@ -28,9 +28,9 @@ RSpec.describe Prawn::SVG::Elements::Polyline do
|
|
28
28
|
it "ignores the last one" do
|
29
29
|
subject.process
|
30
30
|
expect(subject.base_calls).to eq [
|
31
|
-
["fill", [], [
|
32
|
-
["move_to", [[10.0, 590.0]], []],
|
33
|
-
["line_to", [[20.0, 580.0]], []]]
|
31
|
+
["fill", [], {}, [
|
32
|
+
["move_to", [[10.0, 590.0]], {}, []],
|
33
|
+
["line_to", [[20.0, 580.0]], {}, []]]
|
34
34
|
]
|
35
35
|
]
|
36
36
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Prawn::SVG::Elements::Root do
|
4
|
+
let(:color_mode) { :rgb }
|
5
|
+
let(:sizing) do
|
6
|
+
instance_double(Prawn::SVG::Calculators::DocumentSizing, x_offset: 0, y_offset: 0, x_scale: 1, y_scale: 1)
|
7
|
+
end
|
8
|
+
let(:document) do
|
9
|
+
instance_double(Prawn::SVG::Document, color_mode: color_mode, sizing: sizing)
|
10
|
+
end
|
11
|
+
let(:source) { double(name: 'svg', attributes: {}) }
|
12
|
+
let(:state) { Prawn::SVG::State.new }
|
13
|
+
let(:element) { Prawn::SVG::Elements::Root.new(document, source, [], state) }
|
14
|
+
|
15
|
+
it 'uses RGB black as the default color' do
|
16
|
+
element.apply
|
17
|
+
expect(element.calls.first).to eq ['fill_color', ['000000'], {}, []]
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when in CMYK mode' do
|
21
|
+
let(:color_mode) { :cmyk }
|
22
|
+
|
23
|
+
it 'uses CMYK black as the default color' do
|
24
|
+
element.apply
|
25
|
+
expect(element.calls.first).to eq ['fill_color', [[0, 0, 0, 100]], {}, []]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|