spec/document_spec.rb in podoff-1.1.0 vs spec/document_spec.rb in podoff-1.1.1
- old
+ new
@@ -95,10 +95,19 @@
expect(d.objs.values.first.document).to equal(d)
expect(@d.objs.values.first.document).to equal(@d)
expect(d.root).to eq('65 0')
end
+
+ it 'sports objs with properly recomputed attributes' do
+
+ pa = @d.page(1)
+
+ d = @d.dup
+
+ expect(d.objs[pa.ref].attributes).to eq(pa.attributes)
+ end
end
context 'additions' do
before :each do
@@ -118,17 +127,16 @@
expect(fo.document).to eq(@d)
expect(fo.ref).to eq('7 0')
expect(fo.source).to eq(
- '7 0 obj ' +
- '<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> endobj')
+ '7 0 obj <</Type /Font /Subtype /Type1 /BaseFont /Helvetica>> endobj')
s = @d.write(:string)
d = Podoff.parse(s)
- expect(d.xref).to eq(682)
+ expect(d.xref).to eq(680)
end
it 'doesn\'t mind a slash in front of the font name' do
fo = @d.add_base_font('/Helvetica')
@@ -139,12 +147,11 @@
expect(fo.document).to eq(@d)
expect(fo.ref).to eq('7 0')
expect(fo.source).to eq(
- '7 0 obj ' +
- '<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> endobj')
+ '7 0 obj <</Type /Font /Subtype /Type1 /BaseFont /Helvetica>> endobj')
end
end
describe '#add_stream' do
@@ -183,19 +190,24 @@
}
expect(st.obj.document).to eq(@d)
expect(st.obj.ref).to eq('7 0')
- expect(st.obj.source.to_s).to eq(%{
+ expect(st.to_s).to eq(%{
+7 0 obj
+<</Length 97>>
+stream
BT /Helvetica 35 Tf 10 20 Td (thirty here) Tj ET
BT /Helvetica 35 Tf 40 50 Td (sixty there) Tj ET
+endstream
+endobj
}.strip)
d = Podoff.parse(@d.write(:string))
- expect(d.source.index('<< /Length 97 >>')).to eq(618)
- expect(d.xref).to eq(759)
+ expect(d.source.index('<</Length 97>>')).to eq(618)
+ expect(d.xref).to eq(757)
end
it 'returns the open stream when no arg given' do
st = @d.add_stream
@@ -271,18 +283,48 @@
pa.insert_contents(st)
s = d.write(:string)
expect(
- d.write(:string).index(%{
+ s.index(%{
7 0 obj
-<< /Length 37 >>
+<</Length 37>>
stream
BT 10 20 Td (hello open stream) Tj ET
endstream
endobj
}.strip)
).to eq(722)
+ end
+
+ it 'writes a proper xref table' do
+
+ d = Podoff.load('pdfs/t0.pdf')
+
+ pa = d.re_add(d.page(1))
+ st = d.add_stream
+ st.bt(10, 20, 'hello open stream')
+ pa.insert_contents(st)
+
+ s = d.write(:string)
+
+ expect(s[808..-1].strip).to eq(%{
+xref
+0 1
+0000000000 65535 f
+3 1
+0000000611 00000 n
+7 1
+0000000723 00000 n
+trailer
+<<
+/Prev 414
+/Size 7
+/Root 1 0 R
+>>
+startxref 809
+%%EOF
+ }.strip)
end
end
describe '#rewrite' do