vectory 0.4.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +7 -1
- data/lib/vectory/capture.rb +115 -0
- data/lib/vectory/datauri.rb +1 -1
- data/lib/vectory/emf.rb +15 -0
- data/lib/vectory/eps.rb +9 -0
- data/lib/vectory/ps.rb +9 -0
- data/lib/vectory/svg.rb +11 -0
- data/lib/vectory/svg_mapping.rb +14 -7
- data/lib/vectory/system_call.rb +4 -3
- data/lib/vectory/utils.rb +80 -98
- data/lib/vectory/vector.rb +4 -0
- data/lib/vectory/version.rb +1 -1
- data/vectory.gemspec +5 -1
- metadata +17 -54
- data/bin/vectory +0 -9
- data/spec/examples/emf2eps/img.emf +0 -0
- data/spec/examples/emf2eps/img.emf.datauri +0 -1
- data/spec/examples/emf2eps/ref.eps +0 -88
- data/spec/examples/emf2ps/img.emf +0 -0
- data/spec/examples/emf2ps/ref.ps +0 -125
- data/spec/examples/emf2svg/img.emf +0 -0
- data/spec/examples/emf2svg/ref.svg +0 -9
- data/spec/examples/eps2emf/img.eps +0 -199
- data/spec/examples/eps2emf/img.eps.datauri +0 -1
- data/spec/examples/eps2emf/ref.emf +0 -0
- data/spec/examples/eps2ps/img.eps +0 -199
- data/spec/examples/eps2ps/ref.ps +0 -549
- data/spec/examples/eps2svg/img.eps +0 -199
- data/spec/examples/eps2svg/ref.svg +0 -173
- data/spec/examples/eps_but_svg_extension.svg +0 -199
- data/spec/examples/img.jpg +0 -0
- data/spec/examples/ps2emf/img.ps +0 -549
- data/spec/examples/ps2emf/img.ps.datauri +0 -1
- data/spec/examples/ps2emf/ref.emf +0 -0
- data/spec/examples/ps2eps/img.ps +0 -549
- data/spec/examples/ps2eps/ref.eps +0 -844
- data/spec/examples/ps2svg/img.ps +0 -549
- data/spec/examples/ps2svg/ref.svg +0 -476
- data/spec/examples/svg/action_schemaexpg1.svg +0 -124
- data/spec/examples/svg/action_schemaexpg2.svg +0 -124
- data/spec/examples/svg/doc-ref.xml +0 -109
- data/spec/examples/svg/doc.xml +0 -51
- data/spec/examples/svg/doc2-ref.xml +0 -59
- data/spec/examples/svg/doc2.xml +0 -28
- data/spec/examples/svg2emf/img.svg +0 -1
- data/spec/examples/svg2emf/img.svg.datauri +0 -1
- data/spec/examples/svg2emf/ref.emf +0 -0
- data/spec/examples/svg2eps/img.svg +0 -1
- data/spec/examples/svg2eps/ref.eps +0 -88
- data/spec/examples/svg2ps/img.svg +0 -1
- data/spec/examples/svg2ps/ref.ps +0 -125
- data/spec/spec_helper.rb +0 -22
- data/spec/support/matchers.rb +0 -51
- data/spec/support/text_matcher.rb +0 -63
- data/spec/support/vectory_helper.rb +0 -30
- data/spec/vectory/cli_spec.rb +0 -215
- data/spec/vectory/datauri_spec.rb +0 -181
- data/spec/vectory/emf_spec.rb +0 -62
- data/spec/vectory/eps_spec.rb +0 -67
- data/spec/vectory/file_magic_spec.rb +0 -24
- data/spec/vectory/inkscape_converter_spec.rb +0 -43
- data/spec/vectory/ps_spec.rb +0 -58
- data/spec/vectory/svg_mapping_spec.rb +0 -42
- data/spec/vectory/svg_spec.rb +0 -73
- data/spec/vectory/vector_spec.rb +0 -97
- data/spec/vectory_spec.rb +0 -7
@@ -1,24 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
require_relative "../../lib/vectory/file_magic"
|
4
|
-
|
5
|
-
RSpec.describe Vectory::FileMagic do
|
6
|
-
describe "#detect" do
|
7
|
-
references = {
|
8
|
-
"spec/examples/eps2svg/img.eps" => :eps,
|
9
|
-
"spec/examples/eps2emf/img.eps" => :eps,
|
10
|
-
"spec/examples/eps2svg/ref.svg" => :svg,
|
11
|
-
"spec/examples/svg2emf/img.svg" => :svg,
|
12
|
-
"spec/examples/eps2emf/ref.emf" => :emf,
|
13
|
-
"spec/examples/svg2emf/ref.emf" => :emf,
|
14
|
-
}
|
15
|
-
|
16
|
-
references.each do |file, format|
|
17
|
-
context file do
|
18
|
-
it "returns #{format} format" do
|
19
|
-
expect(described_class.detect(file)).to eq format
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe Vectory::InkscapeConverter do
|
4
|
-
describe "#convert " do
|
5
|
-
context "file has inproper format: svg extension, but eps content" do
|
6
|
-
let(:input) { "spec/examples/eps_but_svg_extension.svg" }
|
7
|
-
|
8
|
-
it "raises error" do
|
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
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "inkscape is not installed" do
|
24
|
-
let(:input) { "spec/examples/eps2svg/img.eps" }
|
25
|
-
|
26
|
-
it "raises error" do
|
27
|
-
with_tmp_dir do |dir|
|
28
|
-
tmp_input_path = File.join(dir, "image.eps")
|
29
|
-
FileUtils.cp(input, tmp_input_path)
|
30
|
-
|
31
|
-
expect(Vectory::InkscapeConverter.instance)
|
32
|
-
.to receive(:inkscape_path).and_return(nil)
|
33
|
-
|
34
|
-
expect do
|
35
|
-
Vectory::InkscapeConverter.convert(tmp_input_path,
|
36
|
-
"svg",
|
37
|
-
"--export-type=svg")
|
38
|
-
end.to raise_error(Vectory::InkscapeNotFoundError)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
data/spec/vectory/ps_spec.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe Vectory::Ps do
|
4
|
-
describe "#to_eps" do
|
5
|
-
let(:input) { "spec/examples/ps2eps/img.ps" }
|
6
|
-
let(:reference) { "spec/examples/ps2eps/ref.eps" }
|
7
|
-
|
8
|
-
it "returns eps content" do
|
9
|
-
expect(Vectory::Ps.from_path(input).to_eps.content)
|
10
|
-
.to be_equivalent_eps_to File.read(reference)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#to_emf" do
|
15
|
-
let(:input) { "spec/examples/ps2emf/img.ps" }
|
16
|
-
let(:reference) { "spec/examples/ps2emf/ref.emf" }
|
17
|
-
|
18
|
-
it "returns emf content" do
|
19
|
-
expect(Vectory::Ps.from_path(input).to_emf.content)
|
20
|
-
.to be_equivalent_to File.read(reference)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#to_svg" do
|
25
|
-
let(:input) { "spec/examples/ps2svg/img.ps" }
|
26
|
-
let(:reference) { "spec/examples/ps2svg/ref.svg" }
|
27
|
-
|
28
|
-
it "returns svg content" do
|
29
|
-
expect(Vectory::Ps.from_path(input).to_svg.content)
|
30
|
-
.to be_equivalent_svg_to File.read(reference)
|
31
|
-
end
|
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
|
58
|
-
end
|
@@ -1,42 +0,0 @@
|
|
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
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe Vectory::Svg do
|
4
|
-
describe "#to_emf" do
|
5
|
-
let(:input) { "spec/examples/svg2emf/img.svg" }
|
6
|
-
let(:reference) { "spec/examples/svg2emf/ref.emf" }
|
7
|
-
|
8
|
-
it "returns emf content" do
|
9
|
-
expect(Vectory::Svg.from_path(input).to_emf.content)
|
10
|
-
.to be_equivalent_to File.read(reference)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#to_eps" do
|
15
|
-
let(:input) { "spec/examples/svg2eps/img.svg" }
|
16
|
-
let(:reference) { "spec/examples/svg2eps/ref.eps" }
|
17
|
-
|
18
|
-
it "returns eps content" do
|
19
|
-
expect(Vectory::Svg.from_path(input).to_eps.content)
|
20
|
-
.to be_equivalent_eps_to File.read(reference)
|
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
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#to_ps" do
|
33
|
-
let(:input) { "spec/examples/svg2ps/img.svg" }
|
34
|
-
let(:reference) { "spec/examples/svg2ps/ref.ps" }
|
35
|
-
|
36
|
-
it "returns ps content" do
|
37
|
-
expect(Vectory::Svg.from_path(input).to_ps.content)
|
38
|
-
.to be_equivalent_eps_to File.read(reference)
|
39
|
-
end
|
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
|
73
|
-
end
|
data/spec/vectory/vector_spec.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe Vectory::Vector do
|
4
|
-
describe "#to_uri" do
|
5
|
-
let(:input) { "spec/examples/eps2emf/img.eps" }
|
6
|
-
let(:vector) { Vectory::Eps.from_path(input) }
|
7
|
-
|
8
|
-
it "returns Datauri object" do
|
9
|
-
expect(vector.to_uri).to be_kind_of(Vectory::Datauri)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#write" do
|
14
|
-
let(:image) { Vectory::Emf.from_path("spec/examples/emf2svg/img.emf") }
|
15
|
-
|
16
|
-
context "no arg" do
|
17
|
-
it "saves to a temporary directory" do
|
18
|
-
expect(image.write.path).to include(Dir.tmpdir)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "path provided" do
|
23
|
-
it "saves to the provided path" do
|
24
|
-
Dir.mktmpdir do |tmp_dir|
|
25
|
-
provided_path = File.join(tmp_dir, "image.emf")
|
26
|
-
expect(image.write(provided_path).path).to eq provided_path
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "created from path and no arg provided" do
|
32
|
-
it "saves to a temporary directory" do
|
33
|
-
expect(image.write.path).to include(Dir.tmpdir)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "written two times without arg" do
|
38
|
-
it "writes to the same path" do
|
39
|
-
initial_path = image.write.path
|
40
|
-
expect(image.write.path).to eq initial_path
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "after conversion and no arg" do
|
45
|
-
it "saves to a temporary directory" do
|
46
|
-
expect(image.to_svg.write.path).to include(Dir.tmpdir)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "#path" do
|
52
|
-
let(:image) { Vectory::Emf.from_path("spec/examples/emf2svg/img.emf") }
|
53
|
-
|
54
|
-
context "created from path" do
|
55
|
-
it "raises error that it is not written to disk" do
|
56
|
-
expect { image.path }.to raise_error(Vectory::NotWrittenToDiskError)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "written to disk" do
|
61
|
-
before { image.write }
|
62
|
-
|
63
|
-
it "returns path on a disk" do
|
64
|
-
expect(image.path).to include(Dir.tmpdir)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "#size" do
|
70
|
-
let(:image) { Vectory::Emf.from_path("spec/examples/emf2svg/img.emf") }
|
71
|
-
|
72
|
-
it "returns content size" do
|
73
|
-
expect(image.size).to eq 1060
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "#file_size" do
|
78
|
-
let(:image) { Vectory::Eps.from_path("spec/examples/eps2emf/img.eps") }
|
79
|
-
|
80
|
-
context "not written to disk" do
|
81
|
-
it "raises not-written error" do
|
82
|
-
expect { image.file_size }
|
83
|
-
.to raise_error(Vectory::NotWrittenToDiskError)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "written to disk" do
|
88
|
-
before { image.write }
|
89
|
-
|
90
|
-
it "returns file size" do
|
91
|
-
expect(image.file_size).to satisfy("be either 2926 or 3125") do |v|
|
92
|
-
[2926, 3125].include?(v) # depends on file system
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|