podoff 1.2.2 → 1.2.3
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 +7 -0
- data/CHANGELOG.md +59 -0
- data/LICENSE.txt +4 -1
- data/Makefile +12 -0
- data/lib/podoff.rb +12 -26
- data/podoff.gemspec +7 -5
- metadata +16 -29
- data/CHANGELOG.txt +0 -53
- data/out.txt +0 -1
- data/spec/alpha_spec.rb +0 -40
- data/spec/core_spec.rb +0 -99
- data/spec/document_spec.rb +0 -415
- data/spec/obj_spec.rb +0 -253
- data/spec/spec_helper.rb +0 -78
- data/spec/stream_spec.rb +0 -103
- data/spec/update_spec.rb +0 -36
- data/todo.txt +0 -21
data/spec/spec_helper.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Specifying podoff
|
4
|
-
#
|
5
|
-
# Tue Oct 20 13:10:29 JST 2015
|
6
|
-
#
|
7
|
-
|
8
|
-
require 'pp'
|
9
|
-
require 'ostruct'
|
10
|
-
|
11
|
-
require 'podoff'
|
12
|
-
|
13
|
-
|
14
|
-
RSpec::Matchers.define :be_encoded_as do |encoding|
|
15
|
-
|
16
|
-
match do |path|
|
17
|
-
|
18
|
-
fail ArgumentError.new("expecting a path (String) not a #{path.class}") \
|
19
|
-
unless path.is_a?(String)
|
20
|
-
|
21
|
-
$vic_r =
|
22
|
-
`(vim -c 'execute \"silent !echo \" . &fileencoding . " > _enc.txt" | q' #{path} > /dev/null 2>&1); cat _enc.txt; rm _enc.txt`.strip.downcase
|
23
|
-
|
24
|
-
$vic_r == encoding.downcase
|
25
|
-
end
|
26
|
-
|
27
|
-
failure_message do |path|
|
28
|
-
|
29
|
-
"expected #{encoding.downcase.inspect}, got #{$vic_r.to_s.inspect}"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
RSpec::Matchers.define :be_a_valid_pdf do
|
35
|
-
|
36
|
-
match do |o|
|
37
|
-
|
38
|
-
path =
|
39
|
-
if /\A%PDF-\d/.match(o)
|
40
|
-
File.open('tmp/_under_check.pdf', 'wb') { |f| f.write(o) }
|
41
|
-
'tmp/_under_check.pdf'
|
42
|
-
else
|
43
|
-
o
|
44
|
-
end
|
45
|
-
|
46
|
-
file_cmd =
|
47
|
-
/darwin/.match(RUBY_PLATFORM) ? 'file -I' : 'file -i'
|
48
|
-
vim_cmd =
|
49
|
-
"vim -c 'execute \"silent !echo \" . &fileencoding | q'"
|
50
|
-
|
51
|
-
cmd = [
|
52
|
-
"echo '* vim :'",
|
53
|
-
"#{vim_cmd} #{path}",
|
54
|
-
"echo '* #{file_cmd} :'",
|
55
|
-
"#{file_cmd} #{path}",
|
56
|
-
"echo",
|
57
|
-
"qpdf --check #{path}"
|
58
|
-
]
|
59
|
-
$qpdf_r = `(#{cmd.join('; ')}) 2>&1`
|
60
|
-
`#{file_cmd} #{path}; echo; qpdf --check #{path} 2>&1`
|
61
|
-
|
62
|
-
$qpdf_r = "#{$qpdf_r}\nexit: #{$?.exitstatus}"
|
63
|
-
#puts "." * 80
|
64
|
-
#puts $qpdf_r
|
65
|
-
|
66
|
-
$qpdf_r.match(/exit: 0$/)
|
67
|
-
end
|
68
|
-
|
69
|
-
failure_message do |o|
|
70
|
-
|
71
|
-
%{
|
72
|
-
--- qpdf ---------------------------------------------------------------------->
|
73
|
-
#{$qpdf_r}
|
74
|
-
<-- qpdf -----------------------------------------------------------------------
|
75
|
-
}.strip
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
data/spec/stream_spec.rb
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# specifying podoff
|
4
|
-
#
|
5
|
-
# Fri Oct 23 08:36:38 JST 2015
|
6
|
-
#
|
7
|
-
|
8
|
-
require 'spec_helper'
|
9
|
-
|
10
|
-
|
11
|
-
describe Podoff::Stream do
|
12
|
-
|
13
|
-
describe '#tf' do
|
14
|
-
|
15
|
-
it 'sets the current font' do
|
16
|
-
|
17
|
-
st = Podoff::Stream.new(OpenStruct.new(ref: '1 0'))
|
18
|
-
|
19
|
-
st.tf('/Helvetica', 35)
|
20
|
-
st.bt(10, 20, 'helvetic')
|
21
|
-
st.tf('/ZapfDingbats', 21)
|
22
|
-
st.bt(10, 50, 'zapfesque')
|
23
|
-
|
24
|
-
expect(st.to_s).to eq(%{
|
25
|
-
1 0 obj
|
26
|
-
<</Length 95>>
|
27
|
-
stream
|
28
|
-
BT /Helvetica 35 Tf 10 20 Td (helvetic) Tj ET
|
29
|
-
BT /ZapfDingbats 21 Tf 10 50 Td (zapfesque) Tj ET
|
30
|
-
endstream
|
31
|
-
endobj
|
32
|
-
}.strip)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '#bt' do
|
37
|
-
|
38
|
-
it 'works' do
|
39
|
-
|
40
|
-
st = Podoff::Stream.new(OpenStruct.new(ref: '1 0'))
|
41
|
-
st.bt(10, 20, 'hello world')
|
42
|
-
|
43
|
-
expect(st.to_s).to eq(%{
|
44
|
-
1 0 obj
|
45
|
-
<</Length 31>>
|
46
|
-
stream
|
47
|
-
BT 10 20 Td (hello world) Tj ET
|
48
|
-
endstream
|
49
|
-
endobj
|
50
|
-
}.strip)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'escapes the text' do
|
54
|
-
|
55
|
-
st = Podoff::Stream.new(OpenStruct.new(ref: '1 0'))
|
56
|
-
st.bt(10, 20, 'hello()world')
|
57
|
-
|
58
|
-
expect(st.to_s).to eq(%{
|
59
|
-
1 0 obj
|
60
|
-
<</Length 34>>
|
61
|
-
stream
|
62
|
-
BT 10 20 Td (hello\\(\\)world) Tj ET
|
63
|
-
endstream
|
64
|
-
endobj
|
65
|
-
}.strip)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe '#write' do
|
70
|
-
|
71
|
-
it 'injects text into the stream' do
|
72
|
-
|
73
|
-
st = Podoff::Stream.new(OpenStruct.new(ref: '1 0'))
|
74
|
-
st.bt(10, 20, 'abc')
|
75
|
-
st.write("\nBT 25 35 Td (ABC) Tj ET")
|
76
|
-
st.bt(30, 40, 'def')
|
77
|
-
|
78
|
-
expect(st.to_s).to eq(%{
|
79
|
-
1 0 obj
|
80
|
-
<</Length 71>>
|
81
|
-
stream
|
82
|
-
BT 10 20 Td (abc) Tj ET
|
83
|
-
BT 25 35 Td (ABC) Tj ET
|
84
|
-
BT 30 40 Td (def) Tj ET
|
85
|
-
endstream
|
86
|
-
endobj
|
87
|
-
}.strip)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe '#to_s' do
|
92
|
-
|
93
|
-
it 'applies /Filter /FlateDecode if stream.size > 98' do
|
94
|
-
|
95
|
-
st = Podoff::Stream.new(OpenStruct.new(ref: '1 0'))
|
96
|
-
st.write("BT /Helvetica 35 Tf 123 456 Td (Hello Nada) Tj ET\n" * 4)
|
97
|
-
|
98
|
-
expect(st.to_s).to match(
|
99
|
-
/^1 0 obj\n<<\/Length 60 \/Filter \/FlateDecode>>/)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
data/spec/update_spec.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# specifying podoff
|
4
|
-
#
|
5
|
-
# Tue Oct 20 17:25:49 JST 2015
|
6
|
-
#
|
7
|
-
|
8
|
-
require 'spec_helper'
|
9
|
-
|
10
|
-
|
11
|
-
describe Podoff do
|
12
|
-
|
13
|
-
before :all do
|
14
|
-
|
15
|
-
#@d0 = Podoff.load('pdfs/udocument0.pdf')
|
16
|
-
#@t0 = Podoff.load('pdfs/t0.pdf')
|
17
|
-
end
|
18
|
-
|
19
|
-
# describe 'Obj#add_free_text' do
|
20
|
-
#
|
21
|
-
# it 'annotates an object with free text' do
|
22
|
-
#
|
23
|
-
# doc = @t0.dup
|
24
|
-
# page = doc.page(1)
|
25
|
-
#
|
26
|
-
# puts page.source
|
27
|
-
# page.add_free_text(100, 100, 'free text', :helvetica, 15)
|
28
|
-
#
|
29
|
-
# expect(doc.objs.size).to eq(7)
|
30
|
-
# expect(doc.additions.size).to eq(2)
|
31
|
-
#
|
32
|
-
# doc.write('tmp/out.pdf')
|
33
|
-
# end
|
34
|
-
# end
|
35
|
-
end
|
36
|
-
|
data/todo.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
|
2
|
-
[o] implement Document#rewrite
|
3
|
-
[o] doc.add_stream { |st| st.bt ... }
|
4
|
-
[o] st = d.addstream
|
5
|
-
st.tf '/helv', 12
|
6
|
-
st.bt 5, 6, "hello"
|
7
|
-
d.write('out.pdf') # closes the stream...
|
8
|
-
[ ] fail if insert_content or insert_font on an unclosed stream obj
|
9
|
-
|
10
|
-
[o] Document.write('-') (stdout inspiration)
|
11
|
-
|
12
|
-
|
13
|
-
[ ] stop using the st-mark thing
|
14
|
-
[o] recompress idea? uncompress with pdftk, recompress with podoff
|
15
|
-
smaller docs anyway... /Filter /FlatDecode
|
16
|
-
|
17
|
-
decompress:
|
18
|
-
qpdf --qdf --object-streams=disable in.pdf out.pdf
|
19
|
-
recompress:
|
20
|
-
qpdf in.pdf out.pdf
|
21
|
-
|