Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Renderer errors with --enable-frozen-string-literal #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/combine_pdf/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ def format_hash_to_pdf(object)
end
object[:indirect_reference_id] ||= 0
object[:indirect_generation_number] ||= 0
return "#{object[:indirect_reference_id]} #{object[:indirect_generation_number]} R".force_encoding(Encoding::ASCII_8BIT)
return "#{object[:indirect_reference_id]} #{object[:indirect_generation_number]} R".b.force_encoding(Encoding::ASCII_8BIT)
end

# if the object is indirect...
out = []
if object[:indirect_reference_id]
object[:indirect_reference_id] ||= 0
object[:indirect_generation_number] ||= 0
out << "#{object[:indirect_reference_id]} #{object[:indirect_generation_number]} obj\n".force_encoding(Encoding::ASCII_8BIT)
out << "#{object[:indirect_reference_id]} #{object[:indirect_generation_number]} obj\n".b.force_encoding(Encoding::ASCII_8BIT)
if object[:indirect_without_dictionary]
out << object_to_pdf(object[:indirect_without_dictionary])
out << "\nendobj\n"
Expand All @@ -126,11 +126,11 @@ def format_hash_to_pdf(object)
# (using LESS-THAN SIGNs (3Ch) and GREATER-THAN SIGNs (3Eh)).
out << "<<\n".b
object.each do |key, value|
out << "#{object_to_pdf key} #{object_to_pdf value}\n".force_encoding(Encoding::ASCII_8BIT) unless PDF::PRIVATE_HASH_KEYS.include? key
out << "#{object_to_pdf key} #{object_to_pdf value}\n".b.force_encoding(Encoding::ASCII_8BIT) unless PDF::PRIVATE_HASH_KEYS.include? key
end
object.delete :Length
out << '>>'.b
out << "\nstream\n#{object[:raw_stream_content]}\nendstream".force_encoding(Encoding::ASCII_8BIT) if object[:raw_stream_content]
out << "\nstream\n#{object[:raw_stream_content]}\nendstream".b.force_encoding(Encoding::ASCII_8BIT) if object[:raw_stream_content]
out << "\nendobj\n" if object[:indirect_reference_id]
out.join.force_encoding(Encoding::ASCII_8BIT)
end
Expand Down
26 changes: 26 additions & 0 deletions test/combine_pdf/renderer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,30 @@ def test_numeric_array_to_pdf

assert_equal(expected, actual)
end

def test_object_to_pdf_indirect_reference_id
actual = TestRenderer.new.test_object(
:indirect_reference_id => 1,
:indirect_generation_number => 2
)
assert_match /^1 2 obj/, actual
assert_match /endobj$/, actual
end

def test_object_to_pdf_is_reference_only
actual = TestRenderer.new.test_object(
:Pages => {
:referenced_object => { :Type => :Pages, :Count => 0, :indirect_reference_id => 3 },
:is_reference_only => true
}
)
assert_match /Pages 3 0 R/, actual
end

def test_object_to_pdf_raw_stream_content
actual = TestRenderer.new.test_object(
:raw_stream_content => 'Testing'
)
assert_match /stream\nTesting\nendstream/, actual
end
end