prawn-svg 0.15.0.0 → 0.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/README.md +51 -20
- data/lib/prawn/svg/attributes/clip_path.rb +17 -0
- data/lib/prawn/svg/attributes/color.rb +5 -0
- data/lib/prawn/svg/attributes/display.rb +5 -0
- data/lib/prawn/svg/attributes/font.rb +38 -0
- data/lib/prawn/svg/attributes/opacity.rb +15 -0
- data/lib/prawn/svg/attributes/stroke.rb +35 -0
- data/lib/prawn/svg/attributes/transform.rb +50 -0
- data/lib/prawn/svg/attributes.rb +6 -0
- data/lib/prawn/svg/calculators/aspect_ratio.rb +58 -0
- data/lib/prawn/svg/calculators/document_sizing.rb +99 -0
- data/lib/prawn/svg/calculators/pixels.rb +21 -0
- data/lib/prawn/svg/color.rb +197 -12
- data/lib/prawn/svg/css.rb +40 -0
- data/lib/prawn/svg/document.rb +37 -48
- data/lib/prawn/svg/elements/base.rb +238 -0
- data/lib/prawn/svg/elements/circle.rb +25 -0
- data/lib/prawn/svg/elements/container.rb +15 -0
- data/lib/prawn/svg/elements/ellipse.rb +23 -0
- data/lib/prawn/svg/elements/gradient.rb +120 -0
- data/lib/prawn/svg/elements/ignored.rb +5 -0
- data/lib/prawn/svg/elements/image.rb +81 -0
- data/lib/prawn/svg/elements/line.rb +16 -0
- data/lib/prawn/svg/elements/path.rb +405 -0
- data/lib/prawn/svg/elements/polygon.rb +17 -0
- data/lib/prawn/svg/elements/polyline.rb +22 -0
- data/lib/prawn/svg/elements/rect.rb +33 -0
- data/lib/prawn/svg/elements/root.rb +13 -0
- data/lib/prawn/svg/elements/style.rb +10 -0
- data/lib/prawn/svg/elements/text.rb +87 -0
- data/lib/prawn/svg/elements/use.rb +29 -0
- data/lib/prawn/svg/elements.rb +33 -0
- data/lib/prawn/svg/extension.rb +4 -4
- data/lib/prawn/svg/font.rb +10 -92
- data/lib/prawn/svg/font_registry.rb +73 -0
- data/lib/prawn/svg/interface.rb +91 -31
- data/lib/prawn/svg/loaders/data.rb +18 -0
- data/lib/prawn/svg/loaders/file.rb +66 -0
- data/lib/prawn/svg/loaders/web.rb +28 -0
- data/lib/prawn/svg/state.rb +39 -0
- data/lib/prawn/svg/ttf.rb +61 -0
- data/lib/prawn/svg/url_loader.rb +46 -0
- data/lib/prawn/svg/version.rb +2 -2
- data/lib/prawn-svg.rb +20 -6
- data/prawn-svg.gemspec +8 -5
- data/spec/integration_spec.rb +141 -0
- data/spec/prawn/svg/attributes/font_spec.rb +52 -0
- data/spec/prawn/svg/attributes/transform_spec.rb +56 -0
- data/spec/prawn/svg/calculators/aspect_ratio_spec.rb +95 -0
- data/spec/prawn/svg/calculators/document_sizing_spec.rb +128 -0
- data/spec/prawn/svg/color_spec.rb +43 -8
- data/spec/prawn/svg/css_spec.rb +24 -0
- data/spec/prawn/svg/document_spec.rb +48 -19
- data/spec/prawn/svg/elements/base_spec.rb +147 -0
- data/spec/prawn/svg/elements/gradient_spec.rb +61 -0
- data/spec/prawn/svg/elements/path_spec.rb +123 -0
- data/spec/prawn/svg/elements/style_spec.rb +23 -0
- data/spec/prawn/svg/elements/text_spec.rb +61 -0
- data/spec/prawn/svg/font_registry_spec.rb +54 -0
- data/spec/prawn/svg/font_spec.rb +1 -28
- data/spec/prawn/svg/interface_spec.rb +94 -0
- data/spec/prawn/svg/loaders/data_spec.rb +55 -0
- data/spec/prawn/svg/loaders/file_spec.rb +84 -0
- data/spec/prawn/svg/loaders/web_spec.rb +37 -0
- data/spec/prawn/svg/ttf_spec.rb +32 -0
- data/spec/prawn/svg/url_loader_spec.rb +112 -0
- data/spec/sample_images/mushroom-long.jpg +0 -0
- data/spec/sample_images/mushroom-wide.jpg +0 -0
- data/spec/sample_svg/cap_styles.svg +13 -0
- data/spec/sample_svg/display_none.svg +13 -0
- data/spec/sample_svg/gistfile1.svg +36 -0
- data/spec/sample_svg/gradients.svg +40 -0
- data/spec/sample_svg/hidden_paths.svg +6 -0
- data/spec/sample_svg/image01.svg +31 -31
- data/spec/sample_svg/image03.svg +30 -0
- data/spec/sample_svg/negminy.svg +25 -0
- data/spec/sample_svg/no_width_or_height.svg +4 -0
- data/spec/sample_svg/path.svg +5 -0
- data/spec/sample_svg/pie_piece.svg +7 -0
- data/spec/sample_svg/preserve-space.svg +19 -0
- data/spec/sample_svg/rect02.svg +8 -11
- data/spec/sample_svg/tspan03-cc.svg +21 -0
- data/spec/sample_svg/viewbox.svg +4 -0
- data/spec/sample_svg/viewport.svg +23 -0
- data/spec/sample_ttf/OpenSans-SemiboldItalic.ttf +0 -0
- data/spec/spec_helper.rb +24 -2
- metadata +150 -36
- data/lib/prawn/svg/element.rb +0 -237
- data/lib/prawn/svg/parser/image.rb +0 -134
- data/lib/prawn/svg/parser/path.rb +0 -374
- data/lib/prawn/svg/parser/text.rb +0 -66
- data/lib/prawn/svg/parser.rb +0 -233
- data/spec/lib/parser_spec.rb +0 -55
- data/spec/lib/path_spec.rb +0 -54
- data/spec/lib/svg_spec.rb +0 -47
- data/spec/prawn/svg/element_spec.rb +0 -36
- data/spec/prawn/svg/parser/text_spec.rb +0 -4
data/spec/lib/parser_spec.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Prawn::Svg::Parser do
|
4
|
-
describe "document width and height" do
|
5
|
-
it "handles the width and height being set as a %" do
|
6
|
-
svg = <<-SVG
|
7
|
-
<svg width="50%" height="50%" version="1.1">
|
8
|
-
<line x1="10%" y1="10%" x2="90%" y2="90%" />
|
9
|
-
</svg>
|
10
|
-
SVG
|
11
|
-
|
12
|
-
document = Prawn::Svg::Document.new(svg, [2000, 2000], {})
|
13
|
-
Prawn::Svg::Parser.new(document).parse[-2][-1].should == [["line", [100.0, 900.0, 900.0, 100.0], []]]
|
14
|
-
end
|
15
|
-
|
16
|
-
it "handles the width and height being set in inches" do
|
17
|
-
svg = <<-SVG
|
18
|
-
<svg width="10in" height="10in" version="1.1">
|
19
|
-
<line x1="1in" y1="1in" x2="9in" y2="9in" />
|
20
|
-
</svg>
|
21
|
-
SVG
|
22
|
-
|
23
|
-
document = Prawn::Svg::Document.new(svg, [2000, 2000], {})
|
24
|
-
Prawn::Svg::Parser.new(document).parse[-2][-1].should == [["line", [72.0, 720.0 - 72.0, 720.0 - 72.0, 72.0], []]]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe :parse_element do
|
29
|
-
before(:each) do
|
30
|
-
@document = Prawn::Svg::Document.new("<svg></svg>", [100, 100], {})
|
31
|
-
@parser = Prawn::Svg::Parser.new(@document)
|
32
|
-
end
|
33
|
-
|
34
|
-
def mock_element(name, attributes = {})
|
35
|
-
e = double(:name => name, :attributes => attributes)
|
36
|
-
Prawn::Svg::Element.new(@document, e, [], {})
|
37
|
-
end
|
38
|
-
|
39
|
-
it "ignores tags it doesn't know about" do
|
40
|
-
calls = []
|
41
|
-
@parser.send :parse_element, mock_element("unknown")
|
42
|
-
calls.should == []
|
43
|
-
@document.warnings.length.should == 1
|
44
|
-
@document.warnings.first.should include("Unknown tag")
|
45
|
-
end
|
46
|
-
|
47
|
-
it "ignores tags that don't have all required attributes set" do
|
48
|
-
calls = []
|
49
|
-
@parser.send :parse_element, mock_element("ellipse", "rx" => "1")
|
50
|
-
calls.should == []
|
51
|
-
@document.warnings.length.should == 1
|
52
|
-
@document.warnings.first.should include("Must have attributes ry on tag ellipse")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
data/spec/lib/path_spec.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Prawn::Svg::Parser::Path do
|
4
|
-
before :each do
|
5
|
-
@path = Prawn::Svg::Parser::Path.new
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "command parsing" do
|
9
|
-
it "correctly parses a valid path" do
|
10
|
-
calls = []
|
11
|
-
@path.stub(:run_path_command) {|*args| calls << args}
|
12
|
-
@path.parse("A12.34 -56.78 89B4 5 12-34 -.5.7+3 2.3e3 4e4 4e+4 c31,-2e-5C 6,7 T QX 0 Z")
|
13
|
-
|
14
|
-
calls.should == [
|
15
|
-
["A", [12.34, -56.78, 89]],
|
16
|
-
["B", [4, 5, 12, -34, -0.5, 0.7, 3, 2.3e3, 4e4, 4e4]],
|
17
|
-
["c", [31, -2e-5]],
|
18
|
-
["C", [6, 7]],
|
19
|
-
["T", []],
|
20
|
-
["Q", []],
|
21
|
-
["X", [0]],
|
22
|
-
["Z", []]
|
23
|
-
]
|
24
|
-
end
|
25
|
-
|
26
|
-
it "treats subsequent points to m/M command as relative/absolute depending on command" do
|
27
|
-
|
28
|
-
[
|
29
|
-
["M", [1,2,3,4]],
|
30
|
-
["L", [3,4]],
|
31
|
-
["m", [5,6,7,8]],
|
32
|
-
["l", [7,8]]
|
33
|
-
].each do |args|
|
34
|
-
@path.should_receive(:run_path_command).with(*args).and_call_original
|
35
|
-
end
|
36
|
-
|
37
|
-
@path.parse("M 1,2 3,4 m 5,6 7,8")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "correctly parses an empty path" do
|
41
|
-
@path.should_not_receive(:run_path_command)
|
42
|
-
@path.parse("").should == []
|
43
|
-
@path.parse(" ").should == []
|
44
|
-
end
|
45
|
-
|
46
|
-
it "raises on invalid characters in the path" do
|
47
|
-
lambda {@path.parse("M 10 % 20")}.should raise_error(Prawn::Svg::Parser::Path::InvalidError)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "raises on numerical data before a command letter" do
|
51
|
-
lambda {@path.parse("10 P")}.should raise_error(Prawn::Svg::Parser::Path::InvalidError)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/spec/lib/svg_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Prawn::Svg::Interface do
|
4
|
-
root = "#{File.dirname(__FILE__)}/../.."
|
5
|
-
|
6
|
-
describe "sample file rendering" do
|
7
|
-
files = Dir["#{root}/spec/sample_svg/*.svg"]
|
8
|
-
|
9
|
-
it "has at least 10 SVG sample files to test" do
|
10
|
-
files.length.should >= 10
|
11
|
-
end
|
12
|
-
|
13
|
-
files.each do |file|
|
14
|
-
it "renders the #{File.basename file} sample file without warnings or crashing" do
|
15
|
-
warnings = nil
|
16
|
-
Prawn::Document.generate("#{root}/spec/sample_output/#{File.basename file}.pdf") do |prawn|
|
17
|
-
r = prawn.svg IO.read(file), :at => [0, prawn.bounds.top], :width => prawn.bounds.width, :cache_images => true
|
18
|
-
warnings = r[:warnings].reject {|w| w =~ /Verdana/ && w =~ /is not a known font/ }
|
19
|
-
end
|
20
|
-
warnings.should == []
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "multiple file rendering" do
|
26
|
-
it "renders multiple files on to the same PDF" do
|
27
|
-
Prawn::Document.generate("#{root}/spec/sample_output/multiple.pdf") do |prawn|
|
28
|
-
width = prawn.bounds.width
|
29
|
-
|
30
|
-
y = prawn.bounds.top - 12
|
31
|
-
prawn.draw_text "This is multiple SVGs being output to the same PDF", :at => [0, y]
|
32
|
-
|
33
|
-
y -= 12
|
34
|
-
prawn.svg IO.read("#{root}/spec/sample_svg/arcs01.svg"), :at => [0, y], :width => width / 2
|
35
|
-
prawn.svg IO.read("#{root}/spec/sample_svg/circle01.svg"), :at => [width / 2, y], :width => width / 2
|
36
|
-
|
37
|
-
y -= 120
|
38
|
-
prawn.draw_text "Here are some more PDFs below", :at => [0, y]
|
39
|
-
|
40
|
-
y -= 12
|
41
|
-
prawn.svg IO.read("#{root}/spec/sample_svg/quad01.svg"), :at => [0, y], :width => width / 3
|
42
|
-
prawn.svg IO.read("#{root}/spec/sample_svg/rect01.svg"), :at => [width / 3, y], :width => width / 3
|
43
|
-
prawn.svg IO.read("#{root}/spec/sample_svg/rect02.svg"), :at => [width / 3 * 2, y], :width => width / 3
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
-
|
3
|
-
describe Prawn::Svg::Element do
|
4
|
-
before :each do
|
5
|
-
e = double(:attributes => {})
|
6
|
-
|
7
|
-
@document = Struct.new(:fallback_font_name, :css_parser, :warnings).new("Courier", nil, [])
|
8
|
-
@element = Prawn::Svg::Element.new(@document, e, [], {})
|
9
|
-
end
|
10
|
-
|
11
|
-
describe :parse_font_attributes_and_call do
|
12
|
-
it "uses a font if it can find it" do
|
13
|
-
@element.should_receive(:add_call_and_enter).with('font', 'Helvetica', :style => :normal)
|
14
|
-
|
15
|
-
@element.attributes["font-family"] = "Helvetica"
|
16
|
-
@element.send :parse_font_attributes_and_call
|
17
|
-
end
|
18
|
-
|
19
|
-
it "uses the fallback font if the requested font is not defined" do
|
20
|
-
@element.should_receive(:add_call_and_enter).with('font', 'Courier', :style => :normal)
|
21
|
-
|
22
|
-
@element.attributes["font-family"] = "Font That Doesn't Exist"
|
23
|
-
@element.send :parse_font_attributes_and_call
|
24
|
-
end
|
25
|
-
|
26
|
-
it "doesn't call the font method if there's no fallback font" do
|
27
|
-
@document.fallback_font_name = nil
|
28
|
-
|
29
|
-
@element.should_not_receive(:add_call_and_enter)
|
30
|
-
|
31
|
-
@element.attributes["font-family"] = "Font That Doesn't Exist"
|
32
|
-
@element.send :parse_font_attributes_and_call
|
33
|
-
@document.warnings.length.should == 1
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|