pdf-core 0.2.4 → 0.2.5
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/COPYING +2 -0
- data/GPLv2 +340 -0
- data/GPLv3 +674 -0
- data/Gemfile +3 -0
- data/LICENSE +56 -0
- data/Rakefile +11 -0
- data/pdf-core.gemspec +3 -1
- data/spec/filters_spec.rb +34 -0
- data/spec/name_tree_spec.rb +122 -0
- data/spec/object_store_spec.rb +49 -0
- data/spec/pdf_object_spec.rb +172 -0
- data/spec/reference_spec.rb +62 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/stream_spec.rb +59 -0
- metadata +15 -2
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative "spec_helper"
|
4
|
+
|
5
|
+
describe "A Reference object" do
|
6
|
+
it "should produce a PDF reference on #to_s call" do
|
7
|
+
ref = PDF::Core::Reference(1,true)
|
8
|
+
ref.to_s.should == "1 0 R"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should allow changing generation number" do
|
12
|
+
ref = PDF::Core::Reference(1,true)
|
13
|
+
ref.gen = 1
|
14
|
+
ref.to_s.should == "1 1 R"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should generate a valid PDF object for the referenced data" do
|
18
|
+
ref = PDF::Core::Reference(2,[1,"foo"])
|
19
|
+
ref.object.should == "2 0 obj\n#{PDF::Core::PdfObject([1,"foo"])}\nendobj\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should include stream fileds in dictionary when serializing" do
|
23
|
+
ref = PDF::Core::Reference(1, {})
|
24
|
+
ref.stream << 'Hello'
|
25
|
+
ref.object.should == "1 0 obj\n<< /Length 5\n>>\nstream\nHello\nendstream\nendobj\n"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should append data to stream when #<< is used" do
|
29
|
+
ref = PDF::Core::Reference(1, {})
|
30
|
+
ref << "BT\n/F1 12 Tf\n72 712 Td\n( A stream ) Tj\nET"
|
31
|
+
ref.object.should == "1 0 obj\n<< /Length 41\n>>\nstream"+
|
32
|
+
"\nBT\n/F1 12 Tf\n72 712 Td\n( A stream ) Tj\nET" +
|
33
|
+
"\nendstream\nendobj\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should copy the data and stream from another ref on #replace" do
|
37
|
+
from = PDF::Core::Reference(3, {:foo => 'bar'})
|
38
|
+
from << "has a stream too"
|
39
|
+
|
40
|
+
to = PDF::Core::Reference(4, {:foo => 'baz'})
|
41
|
+
to.replace from
|
42
|
+
|
43
|
+
# should preserve identifier but copy data and stream
|
44
|
+
to.identifier.should == 4
|
45
|
+
to.data.should == from.data
|
46
|
+
to.stream.should == from.stream
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should copy a compressed stream from a compressed ref on #replace" do
|
50
|
+
from = PDF::Core::Reference(5, {:foo => 'bar'})
|
51
|
+
from << "has a stream too " * 20
|
52
|
+
from.stream.compress!
|
53
|
+
|
54
|
+
to = PDF::Core::Reference(6, {:foo => 'baz'})
|
55
|
+
to.replace from
|
56
|
+
|
57
|
+
to.identifier.should == 6
|
58
|
+
to.data.should == from.data
|
59
|
+
to.stream.should == from.stream
|
60
|
+
to.stream.compressed?.should == true
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
puts "PDF::Core specs: Running on Ruby Version: #{RUBY_VERSION}"
|
4
|
+
|
5
|
+
require "bundler"
|
6
|
+
Bundler.setup
|
7
|
+
|
8
|
+
if ENV["COVERAGE"]
|
9
|
+
require "simplecov"
|
10
|
+
SimpleCov.start
|
11
|
+
end
|
12
|
+
|
13
|
+
require_relative "../lib/pdf/core"
|
14
|
+
|
15
|
+
|
16
|
+
require "rspec"
|
17
|
+
require "pdf/reader"
|
18
|
+
require "pdf/inspector"
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
22
|
+
end
|
23
|
+
|
24
|
+
RSpec::Matchers.define :have_parseable_xobjects do
|
25
|
+
match do |actual|
|
26
|
+
expect { PDF::Inspector::XObject.analyze(actual.render) }.not_to raise_error
|
27
|
+
true
|
28
|
+
end
|
29
|
+
failure_message_for_should do |actual|
|
30
|
+
"expected that #{actual}'s XObjects could be successfully parsed"
|
31
|
+
end
|
32
|
+
end
|
data/spec/stream_spec.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative "spec_helper"
|
4
|
+
|
5
|
+
describe "Stream object" do
|
6
|
+
it "should compress a stream upon request" do
|
7
|
+
stream = PDF::Core::Stream.new
|
8
|
+
stream << "Hi There " * 20
|
9
|
+
|
10
|
+
cstream = PDF::Core::Stream.new
|
11
|
+
cstream << "Hi There " * 20
|
12
|
+
cstream.compress!
|
13
|
+
|
14
|
+
cstream.filtered_stream.length.should be < stream.length,
|
15
|
+
"compressed stream expected to be smaller than source but wasn't"
|
16
|
+
cstream.data[:Filter].should == [:FlateDecode]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should expose sompression state" do
|
20
|
+
stream = PDF::Core::Stream.new
|
21
|
+
stream << "Hello"
|
22
|
+
stream.compress!
|
23
|
+
|
24
|
+
stream.should be_compressed
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should detect from filters if stream is compressed" do
|
28
|
+
stream = PDF::Core::Stream.new
|
29
|
+
stream << "Hello"
|
30
|
+
stream.filters << :FlateDecode
|
31
|
+
|
32
|
+
stream.should be_compressed
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have Length if in data" do
|
36
|
+
stream = PDF::Core::Stream.new
|
37
|
+
stream << "hello"
|
38
|
+
|
39
|
+
stream.data[:Length].should == 5
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should update Length when updated" do
|
43
|
+
stream = PDF::Core::Stream.new
|
44
|
+
stream << "hello"
|
45
|
+
stream.data[:Length].should == 5
|
46
|
+
|
47
|
+
stream << " world"
|
48
|
+
stream.data[:Length].should == 11
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should corecly handle decode params" do
|
52
|
+
stream = PDF::Core::Stream.new
|
53
|
+
stream << "Hello"
|
54
|
+
stream.filters << { :FlateDecode => { :Predictor => 15 } }
|
55
|
+
|
56
|
+
stream.data[:DecodeParms].should == [{ :Predictor => 15 }]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdf-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory Brown
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-03-
|
15
|
+
date: 2014-03-19 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: pdf-reader
|
@@ -95,6 +95,12 @@ executables: []
|
|
95
95
|
extensions: []
|
96
96
|
extra_rdoc_files: []
|
97
97
|
files:
|
98
|
+
- COPYING
|
99
|
+
- GPLv2
|
100
|
+
- GPLv3
|
101
|
+
- Gemfile
|
102
|
+
- LICENSE
|
103
|
+
- Rakefile
|
98
104
|
- lib/pdf/core.rb
|
99
105
|
- lib/pdf/core/annotations.rb
|
100
106
|
- lib/pdf/core/byte_string.rb
|
@@ -115,6 +121,13 @@ files:
|
|
115
121
|
- lib/pdf/core/stream.rb
|
116
122
|
- lib/pdf/core/text.rb
|
117
123
|
- pdf-core.gemspec
|
124
|
+
- spec/filters_spec.rb
|
125
|
+
- spec/name_tree_spec.rb
|
126
|
+
- spec/object_store_spec.rb
|
127
|
+
- spec/pdf_object_spec.rb
|
128
|
+
- spec/reference_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
- spec/stream_spec.rb
|
118
131
|
homepage: http://prawn.majesticseacreature.com
|
119
132
|
licenses: []
|
120
133
|
metadata: {}
|