vectory 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/README.adoc +167 -0
- data/lib/vectory/datauri.rb +13 -0
- data/lib/vectory/image.rb +4 -0
- data/lib/vectory/inkscape_converter.rb +82 -11
- data/lib/vectory/svg.rb +84 -1
- data/lib/vectory/svg_mapping.rb +118 -0
- data/lib/vectory/system_call.rb +10 -2
- data/lib/vectory/utils.rb +111 -0
- data/lib/vectory/vector.rb +25 -2
- data/lib/vectory/version.rb +1 -1
- data/lib/vectory.rb +3 -0
- data/spec/examples/svg/action_schemaexpg1.svg +124 -0
- data/spec/examples/svg/action_schemaexpg2.svg +124 -0
- data/spec/examples/svg/doc-ref.xml +109 -0
- data/spec/examples/svg/doc.xml +51 -0
- data/spec/examples/svg/doc2-ref.xml +59 -0
- data/spec/examples/svg/doc2.xml +28 -0
- data/spec/support/matchers.rb +12 -0
- data/spec/support/vectory_helper.rb +14 -0
- data/spec/vectory/cli_spec.rb +15 -14
- data/spec/vectory/datauri_spec.rb +80 -0
- data/spec/vectory/emf_spec.rb +27 -3
- data/spec/vectory/eps_spec.rb +36 -9
- data/spec/vectory/file_magic_spec.rb +3 -3
- data/spec/vectory/inkscape_converter_spec.rb +11 -6
- data/spec/vectory/ps_spec.rb +28 -3
- data/spec/vectory/svg_mapping_spec.rb +42 -0
- data/spec/vectory/svg_spec.rb +43 -3
- data/spec/vectory/vector_spec.rb +37 -0
- data/vectory.gemspec +0 -4
- metadata +22 -70
- /data/spec/examples/emf2eps/{img.eps → ref.eps} +0 -0
- /data/spec/examples/emf2ps/{img.ps → ref.ps} +0 -0
- /data/spec/examples/emf2svg/{img.svg → ref.svg} +0 -0
- /data/spec/examples/eps2emf/{img.emf → ref.emf} +0 -0
- /data/spec/examples/eps2ps/{img.ps → ref.ps} +0 -0
- /data/spec/examples/eps2svg/{img.svg → ref.svg} +0 -0
- /data/spec/examples/ps2emf/{img.emf → ref.emf} +0 -0
- /data/spec/examples/ps2eps/{img.eps → ref.eps} +0 -0
- /data/spec/examples/ps2svg/{img.svg → ref.svg} +0 -0
- /data/spec/examples/svg2emf/{img.emf → ref.emf} +0 -0
- /data/spec/examples/svg2eps/{img.eps → ref.eps} +0 -0
- /data/spec/examples/svg2ps/{img.ps → ref.ps} +0 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
<?xml version='1.0'?>
|
2
|
+
<standard-document type="semantic" version="1.8.2" xmlns="http://www.example.com">
|
3
|
+
<bibdata type="standard">
|
4
|
+
<title language="en" format="text/plain">Document title</title>
|
5
|
+
<docidentifier/>
|
6
|
+
<docnumber/>
|
7
|
+
<version/>
|
8
|
+
<language>en</language>
|
9
|
+
<script>Latn</script>
|
10
|
+
<status>
|
11
|
+
<stage>published</stage>
|
12
|
+
</status>
|
13
|
+
<copyright>
|
14
|
+
<from>2021</from>
|
15
|
+
</copyright>
|
16
|
+
<ext>
|
17
|
+
<doctype>article</doctype>
|
18
|
+
</ext>
|
19
|
+
</bibdata>
|
20
|
+
<sections><svgmap id="_d5b5049a-dd53-4ea0-bc6f-e8773bd59052"><target href="mn://action_schema"><xref target="ref1">Computer</xref></target></svgmap>
|
21
|
+
<figure>
|
22
|
+
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' id='Layer_1_000000001' x='0px' y='0px' viewBox='0 0 595.28 841.89' style='enable-background:new 0 0 595.28 841.89;' xml:space='preserve'>
|
23
|
+
<style type='text/css'>
|
24
|
+
#Layer_1_000000001 { fill:none } svg[id='Layer_1_000000001'] {
|
25
|
+
fill:none } .st0{fill:none;stroke:#000000;stroke-miterlimit:10;}
|
26
|
+
</style>
|
27
|
+
<image/>
|
28
|
+
<a xlink:href='#ref1' xlink:dummy='Layer_1_000000001'>
|
29
|
+
<rect x='123.28' y='273.93' class='st0' width='88.05' height='41.84'/>
|
30
|
+
</a>
|
31
|
+
<a xlink:href='mn://basic_attribute_schema'>
|
32
|
+
<rect x='324.69' y='450.52' class='st0' width='132.62' height='40.75'/>
|
33
|
+
</a>
|
34
|
+
<a xlink:href='mn://support_resource_schema'>
|
35
|
+
<rect x='324.69' y='528.36' class='st0' width='148.16' height='40.75'/>
|
36
|
+
</a>
|
37
|
+
</svg>
|
38
|
+
</figure>
|
39
|
+
<svgmap id='_60dadf08-48d4-4164-845c-b4e293e00abd'>
|
40
|
+
<figure>
|
41
|
+
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' id='Layer_1_000000002' x='0px' y='0px' viewBox='0 0 595.28 841.89' style='enable-background:new 0 0 595.28 841.89;' xml:space='preserve'>
|
42
|
+
<style type='text/css'>
|
43
|
+
#Layer_1_000000002 { fill:none } svg[id='Layer_1_000000002'] {
|
44
|
+
fill:none } .st0{fill:none;stroke:#000000;stroke-miterlimit:10;}
|
45
|
+
</style>
|
46
|
+
<image/>
|
47
|
+
<a xlink:href='mn://action_schema' xlink:dummy='Layer_1_000000002'>
|
48
|
+
<rect x='123.28' y='273.93' class='st0' width='88.05' height='41.84'/>
|
49
|
+
</a>
|
50
|
+
<a xlink:href='http://www.example.com'>
|
51
|
+
<rect x='324.69' y='450.52' class='st0' width='132.62' height='40.75'/>
|
52
|
+
</a>
|
53
|
+
<a xlink:href='mn://support_resource_schema'>
|
54
|
+
<rect x='324.69' y='528.36' class='st0' width='148.16' height='40.75'/>
|
55
|
+
</a>
|
56
|
+
</svg>
|
57
|
+
</figure>
|
58
|
+
<target href="mn://support_resource_schema"><eref type="express" bibitemid="express_action_schema" citeas=""><localityStack><locality type="anchor"><referenceFrom>action_schema.basic</referenceFrom></locality></localityStack>Coffee</eref></target></svgmap></sections>
|
59
|
+
</standard-document>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<standard-document type="semantic" version="1.8.2" xmlns="http://www.example.com">
|
2
|
+
<bibdata type="standard">
|
3
|
+
<title language="en" format="text/plain">Document title</title>
|
4
|
+
<docidentifier/>
|
5
|
+
<docnumber/>
|
6
|
+
<version/>
|
7
|
+
<language>en</language>
|
8
|
+
<script>Latn</script>
|
9
|
+
<status>
|
10
|
+
<stage>published</stage>
|
11
|
+
</status>
|
12
|
+
<copyright>
|
13
|
+
<from>2021</from>
|
14
|
+
</copyright>
|
15
|
+
<ext>
|
16
|
+
<doctype>article</doctype>
|
17
|
+
</ext>
|
18
|
+
</bibdata>
|
19
|
+
<sections>
|
20
|
+
<svgmap id="_d5b5049a-dd53-4ea0-bc6f-e8773bd59052"><target href="mn://action_schema"><xref target="ref1">Computer</xref></target></svgmap>
|
21
|
+
<svgmap id="_4072bdcb-5895-4821-b636-5795b96787cb">
|
22
|
+
<figure><image src="action_schemaexpg1.svg"/></figure>
|
23
|
+
<target href="mn://action_schema"><xref target="ref1">Computer</xref></target><target href="http://www.example.com"><link target="http://www.example.com">Phone</link></target>
|
24
|
+
</svgmap>
|
25
|
+
<svgmap id="_60dadf08-48d4-4164-845c-b4e293e00abd">
|
26
|
+
<figure><image src="action_schemaexpg2.svg" alt="Workmap"/></figure>
|
27
|
+
<target href="href1.htm"><xref target="ref1">Computer</xref></target><target href="mn://basic_attribute_schema"><link target="http://www.example.com">Phone</link></target><target href="mn://support_resource_schema"><eref type="express" bibitemid="express_action_schema" citeas=""><localityStack><locality type="anchor"><referenceFrom>action_schema.basic</referenceFrom></locality></localityStack>Coffee</eref></target></svgmap></sections>
|
28
|
+
</standard-document>
|
data/spec/support/matchers.rb
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
RSpec::Matchers.define :be_eps do
|
2
|
+
match do |actual|
|
3
|
+
actual.start_with?("%!PS-Adobe-3.0")
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
RSpec::Matchers.define :be_svg do
|
8
|
+
match do |actual|
|
9
|
+
actual.include?("<svg")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
1
13
|
RSpec::Matchers.define :be_equivalent_eps_to do |expected|
|
2
14
|
match do |actual|
|
3
15
|
e = sub_time_and_version(expected)
|
@@ -13,5 +13,19 @@ module Vectory
|
|
13
13
|
Dir.chdir(dir, &block)
|
14
14
|
end
|
15
15
|
end
|
16
|
+
|
17
|
+
def xmlpp(xml)
|
18
|
+
xsl = <<~XSL
|
19
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
20
|
+
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
|
21
|
+
<xsl:strip-space elements="*"/>
|
22
|
+
<xsl:template match="/">
|
23
|
+
<xsl:copy-of select="."/>
|
24
|
+
</xsl:template>
|
25
|
+
</xsl:stylesheet>
|
26
|
+
XSL
|
27
|
+
Nokogiri::XSLT(xsl).transform(Nokogiri::XML(xml, &:noblanks))
|
28
|
+
.to_xml(indent: 2, encoding: "UTF-8")
|
29
|
+
end
|
16
30
|
end
|
17
31
|
end
|
data/spec/vectory/cli_spec.rb
CHANGED
@@ -11,10 +11,11 @@ RSpec.describe Vectory::CLI do
|
|
11
11
|
shared_examples "converter" do |format|
|
12
12
|
it "creates file of a chosen format" do
|
13
13
|
matcher = case format
|
14
|
-
when "eps", "ps" then "
|
15
|
-
when "svg" then "
|
14
|
+
when "eps", "ps" then "be_eps"
|
15
|
+
when "svg" then "be_svg"
|
16
16
|
else "be_equivalent_to"
|
17
17
|
end
|
18
|
+
|
18
19
|
with_tmp_dir do |dir|
|
19
20
|
output = File.join(dir, "output.#{format}")
|
20
21
|
status = described_class.start(["-f", format, "-o", output, input])
|
@@ -27,84 +28,84 @@ RSpec.describe Vectory::CLI do
|
|
27
28
|
|
28
29
|
context "eps to ps" do
|
29
30
|
let(:input) { "spec/examples/eps2ps/img.eps" }
|
30
|
-
let(:reference) { "spec/examples/eps2ps/
|
31
|
+
let(:reference) { "spec/examples/eps2ps/ref.ps" }
|
31
32
|
|
32
33
|
it_behaves_like "converter", "ps"
|
33
34
|
end
|
34
35
|
|
35
36
|
context "eps to svg" do
|
36
37
|
let(:input) { "spec/examples/eps2svg/img.eps" }
|
37
|
-
let(:reference) { "spec/examples/eps2svg/
|
38
|
+
let(:reference) { "spec/examples/eps2svg/ref.svg" }
|
38
39
|
|
39
40
|
it_behaves_like "converter", "svg"
|
40
41
|
end
|
41
42
|
|
42
43
|
context "eps to emf" do
|
43
44
|
let(:input) { "spec/examples/eps2emf/img.eps" }
|
44
|
-
let(:reference) { "spec/examples/eps2emf/
|
45
|
+
let(:reference) { "spec/examples/eps2emf/ref.emf" }
|
45
46
|
|
46
47
|
it_behaves_like "converter", "emf"
|
47
48
|
end
|
48
49
|
|
49
50
|
context "ps to eps" do
|
50
51
|
let(:input) { "spec/examples/ps2eps/img.ps" }
|
51
|
-
let(:reference) { "spec/examples/ps2eps/
|
52
|
+
let(:reference) { "spec/examples/ps2eps/ref.eps" }
|
52
53
|
|
53
54
|
it_behaves_like "converter", "eps"
|
54
55
|
end
|
55
56
|
|
56
57
|
context "ps to emf" do
|
57
58
|
let(:input) { "spec/examples/ps2emf/img.ps" }
|
58
|
-
let(:reference) { "spec/examples/ps2emf/
|
59
|
+
let(:reference) { "spec/examples/ps2emf/ref.emf" }
|
59
60
|
|
60
61
|
it_behaves_like "converter", "emf"
|
61
62
|
end
|
62
63
|
|
63
64
|
context "ps to svg" do
|
64
65
|
let(:input) { "spec/examples/ps2svg/img.ps" }
|
65
|
-
let(:reference) { "spec/examples/ps2svg/
|
66
|
+
let(:reference) { "spec/examples/ps2svg/ref.svg" }
|
66
67
|
|
67
68
|
it_behaves_like "converter", "svg"
|
68
69
|
end
|
69
70
|
|
70
71
|
context "svg to emf" do
|
71
72
|
let(:input) { "spec/examples/svg2emf/img.svg" }
|
72
|
-
let(:reference) { "spec/examples/svg2emf/
|
73
|
+
let(:reference) { "spec/examples/svg2emf/ref.emf" }
|
73
74
|
|
74
75
|
it_behaves_like "converter", "emf"
|
75
76
|
end
|
76
77
|
|
77
78
|
context "svg to eps" do
|
78
79
|
let(:input) { "spec/examples/svg2eps/img.svg" }
|
79
|
-
let(:reference) { "spec/examples/svg2eps/
|
80
|
+
let(:reference) { "spec/examples/svg2eps/ref.eps" }
|
80
81
|
|
81
82
|
it_behaves_like "converter", "eps"
|
82
83
|
end
|
83
84
|
|
84
85
|
context "svg to ps" do
|
85
86
|
let(:input) { "spec/examples/svg2ps/img.svg" }
|
86
|
-
let(:reference) { "spec/examples/svg2ps/
|
87
|
+
let(:reference) { "spec/examples/svg2ps/ref.ps" }
|
87
88
|
|
88
89
|
it_behaves_like "converter", "ps"
|
89
90
|
end
|
90
91
|
|
91
92
|
context "emf to svg" do
|
92
93
|
let(:input) { "spec/examples/emf2svg/img.emf" }
|
93
|
-
let(:reference) { "spec/examples/emf2svg/
|
94
|
+
let(:reference) { "spec/examples/emf2svg/ref.svg" }
|
94
95
|
|
95
96
|
it_behaves_like "converter", "svg"
|
96
97
|
end
|
97
98
|
|
98
99
|
context "emf to eps" do
|
99
100
|
let(:input) { "spec/examples/emf2eps/img.emf" }
|
100
|
-
let(:reference) { "spec/examples/emf2eps/
|
101
|
+
let(:reference) { "spec/examples/emf2eps/ref.eps" }
|
101
102
|
|
102
103
|
it_behaves_like "converter", "eps"
|
103
104
|
end
|
104
105
|
|
105
106
|
context "emf to ps" do
|
106
107
|
let(:input) { "spec/examples/emf2ps/img.emf" }
|
107
|
-
let(:reference) { "spec/examples/emf2ps/
|
108
|
+
let(:reference) { "spec/examples/emf2ps/ref.ps" }
|
108
109
|
|
109
110
|
it_behaves_like "converter", "ps"
|
110
111
|
end
|
@@ -98,4 +98,84 @@ RSpec.describe Vectory::Datauri do
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
end
|
101
|
+
|
102
|
+
describe "#mime" do
|
103
|
+
context "incorrect data" do
|
104
|
+
let(:not_a_datauri) { "123abc" }
|
105
|
+
|
106
|
+
it "raises conversion error" do
|
107
|
+
expect { described_class.new(not_a_datauri).mime }
|
108
|
+
.to raise_error(Vectory::ConversionError)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "eps" do
|
113
|
+
let(:input) { "spec/examples/eps2emf/img.eps.datauri" }
|
114
|
+
|
115
|
+
it "returns eps" do
|
116
|
+
expect(described_class.from_path(input).mime)
|
117
|
+
.to eq "application/postscript"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "emf" do
|
122
|
+
let(:input) { "spec/examples/emf2eps/img.emf.datauri" }
|
123
|
+
|
124
|
+
it "returns emf" do
|
125
|
+
expect(described_class.from_path(input).mime).to eq "image/emf"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "svg" do
|
130
|
+
let(:input) { "spec/examples/svg2emf/img.svg.datauri" }
|
131
|
+
|
132
|
+
it "returns svg" do
|
133
|
+
expect(described_class.from_path(input).mime).to eq "image/svg+xml"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "dimensions (#height / #width)" do
|
139
|
+
context "incorrect data" do
|
140
|
+
let(:not_a_datauri) { "123abc" }
|
141
|
+
|
142
|
+
it "raises conversion error" do
|
143
|
+
expect { described_class.new(not_a_datauri).height }
|
144
|
+
.to raise_error(Vectory::ConversionError)
|
145
|
+
|
146
|
+
expect { described_class.new(not_a_datauri).width }
|
147
|
+
.to raise_error(Vectory::ConversionError)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context "eps" do
|
152
|
+
let(:input) { "spec/examples/eps2emf/img.eps.datauri" }
|
153
|
+
|
154
|
+
it "returns height and width" do
|
155
|
+
expect(described_class.from_path(input).height)
|
156
|
+
.to eq 707
|
157
|
+
|
158
|
+
expect(described_class.from_path(input).width)
|
159
|
+
.to eq 649
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context "emf" do
|
164
|
+
let(:input) { "spec/examples/emf2eps/img.emf.datauri" }
|
165
|
+
|
166
|
+
it "returns height and width" do
|
167
|
+
expect(described_class.from_path(input).height).to eq 90
|
168
|
+
expect(described_class.from_path(input).width).to eq 90
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context "svg" do
|
173
|
+
let(:input) { "spec/examples/svg2emf/img.svg.datauri" }
|
174
|
+
|
175
|
+
it "returns height and width" do
|
176
|
+
expect(described_class.from_path(input).height).to eq 90
|
177
|
+
expect(described_class.from_path(input).width).to eq 90
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
101
181
|
end
|
data/spec/vectory/emf_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
RSpec.describe Vectory::Emf do
|
4
4
|
describe "#to_svg" do
|
5
5
|
let(:input) { "spec/examples/emf2svg/img.emf" }
|
6
|
-
let(:reference) { "spec/examples/emf2svg/
|
6
|
+
let(:reference) { "spec/examples/emf2svg/ref.svg" }
|
7
7
|
|
8
8
|
it "returns svg content" do
|
9
9
|
expect(Vectory::Emf.from_path(input).to_svg.content)
|
@@ -18,7 +18,7 @@ RSpec.describe Vectory::Emf do
|
|
18
18
|
|
19
19
|
describe "#to_eps" do
|
20
20
|
let(:input) { "spec/examples/emf2eps/img.emf" }
|
21
|
-
let(:reference) { "spec/examples/emf2eps/
|
21
|
+
let(:reference) { "spec/examples/emf2eps/ref.eps" }
|
22
22
|
|
23
23
|
it "returns eps content" do
|
24
24
|
expect(Vectory::Emf.from_path(input).to_eps.content)
|
@@ -28,11 +28,35 @@ RSpec.describe Vectory::Emf do
|
|
28
28
|
|
29
29
|
describe "#to_ps" do
|
30
30
|
let(:input) { "spec/examples/emf2ps/img.emf" }
|
31
|
-
let(:reference) { "spec/examples/emf2ps/
|
31
|
+
let(:reference) { "spec/examples/emf2ps/ref.ps" }
|
32
32
|
|
33
33
|
it "returns ps content" do
|
34
34
|
expect(Vectory::Emf.from_path(input).to_ps.content)
|
35
35
|
.to be_equivalent_eps_to File.read(reference)
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
39
|
+
describe "#mime" do
|
40
|
+
let(:input) { "spec/examples/emf2eps/img.emf" }
|
41
|
+
|
42
|
+
it "returns emf" do
|
43
|
+
expect(described_class.from_path(input).mime).to eq "image/emf"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#height" do
|
48
|
+
let(:input) { "spec/examples/emf2eps/img.emf" }
|
49
|
+
|
50
|
+
it "returns height" do
|
51
|
+
expect(described_class.from_path(input).height).to eq 90
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#width" do
|
56
|
+
let(:input) { "spec/examples/emf2eps/img.emf" }
|
57
|
+
|
58
|
+
it "returns width" do
|
59
|
+
expect(described_class.from_path(input).width).to eq 90
|
60
|
+
end
|
61
|
+
end
|
38
62
|
end
|
data/spec/vectory/eps_spec.rb
CHANGED
@@ -3,38 +3,65 @@ require "spec_helper"
|
|
3
3
|
RSpec.describe Vectory::Eps do
|
4
4
|
shared_examples "converter" do |format|
|
5
5
|
it "returns content of a chosen format" do
|
6
|
+
to_format_method = "to_#{format}"
|
7
|
+
content = described_class.from_path(input)
|
8
|
+
.public_send(to_format_method)
|
9
|
+
.content
|
10
|
+
|
6
11
|
matcher = case format
|
7
|
-
when "eps", "ps" then "
|
8
|
-
when "svg" then "
|
12
|
+
when "eps", "ps" then "be_eps"
|
13
|
+
when "svg" then "be_svg"
|
9
14
|
else "be_equivalent_to"
|
10
15
|
end
|
11
16
|
|
12
|
-
|
13
|
-
expect(described_class.from_path(input)
|
14
|
-
.public_send(to_format_method)
|
15
|
-
.content)
|
17
|
+
expect(content)
|
16
18
|
.to public_send(matcher, File.read(reference))
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
22
|
describe "#to_ps" do
|
21
23
|
let(:input) { "spec/examples/eps2ps/img.eps" }
|
22
|
-
let(:reference) { "spec/examples/eps2ps/
|
24
|
+
let(:reference) { "spec/examples/eps2ps/ref.ps" }
|
23
25
|
|
24
26
|
it_behaves_like "converter", "ps"
|
25
27
|
end
|
26
28
|
|
27
29
|
describe "#to_svg" do
|
28
30
|
let(:input) { "spec/examples/eps2svg/img.eps" }
|
29
|
-
let(:reference) { "spec/examples/eps2svg/
|
31
|
+
let(:reference) { "spec/examples/eps2svg/ref.svg" }
|
30
32
|
|
31
33
|
it_behaves_like "converter", "svg"
|
32
34
|
end
|
33
35
|
|
34
36
|
describe "#to_emf" do
|
35
37
|
let(:input) { "spec/examples/eps2emf/img.eps" }
|
36
|
-
let(:reference) { "spec/examples/eps2emf/
|
38
|
+
let(:reference) { "spec/examples/eps2emf/ref.emf" }
|
37
39
|
|
38
40
|
it_behaves_like "converter", "emf"
|
39
41
|
end
|
42
|
+
|
43
|
+
describe "#mime" do
|
44
|
+
let(:input) { "spec/examples/eps2emf/img.eps" }
|
45
|
+
|
46
|
+
it "returns postscript" do
|
47
|
+
expect(described_class.from_path(input).mime)
|
48
|
+
.to eq "application/postscript"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#height" do
|
53
|
+
let(:input) { "spec/examples/eps2emf/img.eps" }
|
54
|
+
|
55
|
+
it "returns height" do
|
56
|
+
expect(described_class.from_path(input).height).to eq 707
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#width" do
|
61
|
+
let(:input) { "spec/examples/eps2emf/img.eps" }
|
62
|
+
|
63
|
+
it "returns width" do
|
64
|
+
expect(described_class.from_path(input).width).to eq 649
|
65
|
+
end
|
66
|
+
end
|
40
67
|
end
|
@@ -7,10 +7,10 @@ RSpec.describe Vectory::FileMagic do
|
|
7
7
|
references = {
|
8
8
|
"spec/examples/eps2svg/img.eps" => :eps,
|
9
9
|
"spec/examples/eps2emf/img.eps" => :eps,
|
10
|
-
"spec/examples/eps2svg/
|
10
|
+
"spec/examples/eps2svg/ref.svg" => :svg,
|
11
11
|
"spec/examples/svg2emf/img.svg" => :svg,
|
12
|
-
"spec/examples/eps2emf/
|
13
|
-
"spec/examples/svg2emf/
|
12
|
+
"spec/examples/eps2emf/ref.emf" => :emf,
|
13
|
+
"spec/examples/svg2emf/ref.emf" => :emf,
|
14
14
|
}
|
15
15
|
|
16
16
|
references.each do |file, format|
|
@@ -5,13 +5,18 @@ RSpec.describe Vectory::InkscapeConverter do
|
|
5
5
|
context "file has inproper format: svg extension, but eps content" do
|
6
6
|
let(:input) { "spec/examples/eps_but_svg_extension.svg" }
|
7
7
|
|
8
|
-
let(:command) do
|
9
|
-
Vectory::InkscapeConverter.convert(input, "svg", "--export-type=eps")
|
10
|
-
end
|
11
|
-
|
12
8
|
it "raises error" do
|
13
|
-
|
14
|
-
|
9
|
+
with_tmp_dir do |dir|
|
10
|
+
tmp_input_path = File.join(dir, File.basename(input))
|
11
|
+
FileUtils.cp(input, tmp_input_path)
|
12
|
+
|
13
|
+
expect do
|
14
|
+
Vectory::InkscapeConverter.convert(tmp_input_path,
|
15
|
+
"emf",
|
16
|
+
"--export-type=emf")
|
17
|
+
end.to raise_error(Vectory::ConversionError,
|
18
|
+
/parser error : Start tag expected/)
|
19
|
+
end
|
15
20
|
end
|
16
21
|
end
|
17
22
|
|
data/spec/vectory/ps_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
RSpec.describe Vectory::Ps do
|
4
4
|
describe "#to_eps" do
|
5
5
|
let(:input) { "spec/examples/ps2eps/img.ps" }
|
6
|
-
let(:reference) { "spec/examples/ps2eps/
|
6
|
+
let(:reference) { "spec/examples/ps2eps/ref.eps" }
|
7
7
|
|
8
8
|
it "returns eps content" do
|
9
9
|
expect(Vectory::Ps.from_path(input).to_eps.content)
|
@@ -13,7 +13,7 @@ RSpec.describe Vectory::Ps do
|
|
13
13
|
|
14
14
|
describe "#to_emf" do
|
15
15
|
let(:input) { "spec/examples/ps2emf/img.ps" }
|
16
|
-
let(:reference) { "spec/examples/ps2emf/
|
16
|
+
let(:reference) { "spec/examples/ps2emf/ref.emf" }
|
17
17
|
|
18
18
|
it "returns emf content" do
|
19
19
|
expect(Vectory::Ps.from_path(input).to_emf.content)
|
@@ -23,11 +23,36 @@ RSpec.describe Vectory::Ps do
|
|
23
23
|
|
24
24
|
describe "#to_svg" do
|
25
25
|
let(:input) { "spec/examples/ps2svg/img.ps" }
|
26
|
-
let(:reference) { "spec/examples/ps2svg/
|
26
|
+
let(:reference) { "spec/examples/ps2svg/ref.svg" }
|
27
27
|
|
28
28
|
it "returns svg content" do
|
29
29
|
expect(Vectory::Ps.from_path(input).to_svg.content)
|
30
30
|
.to be_equivalent_svg_to File.read(reference)
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
describe "#mime" do
|
35
|
+
let(:input) { "spec/examples/ps2emf/img.ps" }
|
36
|
+
|
37
|
+
it "returns postscript" do
|
38
|
+
expect(described_class.from_path(input).mime)
|
39
|
+
.to eq "application/postscript"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#height" do
|
44
|
+
let(:input) { "spec/examples/ps2emf/img.ps" }
|
45
|
+
|
46
|
+
it "returns height" do
|
47
|
+
expect(described_class.from_path(input).height).to eq 707
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#width" do
|
52
|
+
let(:input) { "spec/examples/ps2emf/img.ps" }
|
53
|
+
|
54
|
+
it "returns width" do
|
55
|
+
expect(described_class.from_path(input).width).to eq 649
|
56
|
+
end
|
57
|
+
end
|
33
58
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Vectory::SvgMapping do
|
4
|
+
context "no namespace" do
|
5
|
+
let(:source) { Vectory::SvgMapping.from_path("doc.xml") }
|
6
|
+
let(:reference) { File.read("doc-ref.xml") }
|
7
|
+
let(:work_dir) { "spec/examples/svg" }
|
8
|
+
|
9
|
+
it "rewrites ids" do
|
10
|
+
Dir.chdir(work_dir) do
|
11
|
+
content = source.call
|
12
|
+
|
13
|
+
expect(xmlpp(strip_image_and_style(content)))
|
14
|
+
.to be_equivalent_to xmlpp(reference)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with namespaces" do
|
20
|
+
let(:source) { Vectory::SvgMapping.from_path("doc2.xml") }
|
21
|
+
let(:reference) { File.read("doc2-ref.xml") }
|
22
|
+
let(:work_dir) { "spec/examples/svg" }
|
23
|
+
|
24
|
+
it "rewrites ids" do
|
25
|
+
Dir.chdir(work_dir) do
|
26
|
+
content = source.call
|
27
|
+
|
28
|
+
expect(xmlpp(strip_image(content)))
|
29
|
+
.to be_equivalent_to xmlpp(reference)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def strip_image(xml)
|
35
|
+
xml.gsub(%r{<image.*?</image>}m, "<image/>")
|
36
|
+
end
|
37
|
+
|
38
|
+
def strip_image_and_style(xml)
|
39
|
+
xml.gsub(%r{<image.*?</image>}m, "<image/>")
|
40
|
+
.gsub(%r{<style.*?</style>}m, "<style/>") # rubocop:disable Layout/MultilineMethodCallIndentation
|
41
|
+
end
|
42
|
+
end
|
data/spec/vectory/svg_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
RSpec.describe Vectory::Svg do
|
4
4
|
describe "#to_emf" do
|
5
5
|
let(:input) { "spec/examples/svg2emf/img.svg" }
|
6
|
-
let(:reference) { "spec/examples/svg2emf/
|
6
|
+
let(:reference) { "spec/examples/svg2emf/ref.emf" }
|
7
7
|
|
8
8
|
it "returns emf content" do
|
9
9
|
expect(Vectory::Svg.from_path(input).to_emf.content)
|
@@ -13,21 +13,61 @@ RSpec.describe Vectory::Svg do
|
|
13
13
|
|
14
14
|
describe "#to_eps" do
|
15
15
|
let(:input) { "spec/examples/svg2eps/img.svg" }
|
16
|
-
let(:reference) { "spec/examples/svg2eps/
|
16
|
+
let(:reference) { "spec/examples/svg2eps/ref.eps" }
|
17
17
|
|
18
18
|
it "returns eps content" do
|
19
19
|
expect(Vectory::Svg.from_path(input).to_eps.content)
|
20
20
|
.to be_equivalent_eps_to File.read(reference)
|
21
21
|
end
|
22
|
+
|
23
|
+
context "remapped links beforehand" do
|
24
|
+
it "converts successfully" do
|
25
|
+
vector = Vectory::Svg.from_path(input)
|
26
|
+
vector.remap_links({})
|
27
|
+
expect { vector.to_eps }.not_to raise_error
|
28
|
+
end
|
29
|
+
end
|
22
30
|
end
|
23
31
|
|
24
32
|
describe "#to_ps" do
|
25
33
|
let(:input) { "spec/examples/svg2ps/img.svg" }
|
26
|
-
let(:reference) { "spec/examples/svg2ps/
|
34
|
+
let(:reference) { "spec/examples/svg2ps/ref.ps" }
|
27
35
|
|
28
36
|
it "returns ps content" do
|
29
37
|
expect(Vectory::Svg.from_path(input).to_ps.content)
|
30
38
|
.to be_equivalent_eps_to File.read(reference)
|
31
39
|
end
|
32
40
|
end
|
41
|
+
|
42
|
+
describe "#mime" do
|
43
|
+
let(:input) { "spec/examples/svg2emf/img.svg" }
|
44
|
+
|
45
|
+
it "returns svg" do
|
46
|
+
expect(described_class.from_path(input).mime).to eq "image/svg+xml"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#height" do
|
51
|
+
let(:input) { "spec/examples/svg2emf/img.svg" }
|
52
|
+
|
53
|
+
it "returns height" do
|
54
|
+
expect(described_class.from_path(input).height).to eq 90
|
55
|
+
end
|
56
|
+
|
57
|
+
context "incorrect data" do
|
58
|
+
let(:command) { described_class.from_content("incorrect123svg") }
|
59
|
+
|
60
|
+
it "raises query error" do
|
61
|
+
expect { command.height }.to raise_error(Vectory::InkscapeQueryError)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#width" do
|
67
|
+
let(:input) { "spec/examples/svg2emf/img.svg" }
|
68
|
+
|
69
|
+
it "returns width" do
|
70
|
+
expect(described_class.from_path(input).width).to eq 90
|
71
|
+
end
|
72
|
+
end
|
33
73
|
end
|