Skip to content

Commit

Permalink
More template-related cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
practicingruby committed Sep 11, 2014
1 parent e80af11 commit bd88d48
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 46 deletions.
14 changes: 0 additions & 14 deletions lib/prawn/document/internals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,6 @@ def on_page_create(&block)

private

# adds a new, empty content stream to each page. Used in templating so
# that imported content streams can be left pristine
#
def fresh_content_streams(options={})
(1..page_count).each do |i|
go_to_page i
state.page.new_content_stream
apply_margin_options(options)
generate_margin_box
use_graphic_settings(options[:template])
forget_text_rendering_mode!
end
end

def finalize_all_page_contents
(1..page_count).each do |i|
go_to_page i
Expand Down
25 changes: 2 additions & 23 deletions lib/prawn/font.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,31 +398,10 @@ def eql?( other ) #:nodoc:

private

# generate a font identifier that hasn't been used on the curretn page yet
# generate a font identifier that hasn't been used on the current page yet
#
def generate_unique_id
offset, id = 0, nil

while id.nil? || page_contains_font_id?(id)
offset += 1
id = :"F#{@document.font_registry.size + offset}"
end

id
end

# Returns true if the provided font identifier already exists in the document.
# This is used when adding new fonts to a document to ensure we don't step
# on fonts imported from a template.
#
# page_contains_font_id?("F1")
# => true
#
def page_contains_font_id?(id)
id = id.to_s
@document.state.page.fonts.keys.any? { |exist_id|
exist_id.to_s[0,id.size] == id
}
:"F#{@document.font_registry.size + 1}"
end

def size
Expand Down
2 changes: 1 addition & 1 deletion prawn.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
spec.licenses = ['RUBY', 'GPL-2', 'GPL-3']

spec.add_dependency('ttfunk', '~> 1.3.0')
spec.add_dependency('pdf-core', "~> 0.3.0")
spec.add_dependency('pdf-core', "~> 0.3.1")

spec.add_development_dependency('pdf-inspector', '~> 1.1.0')
spec.add_development_dependency('yard')
Expand Down
11 changes: 3 additions & 8 deletions spec/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ def self.format(string)
end

describe "When beginning each new page" do

describe "Background template feature" do
describe "Background image feature" do
before(:each) do
@filename = "#{Prawn::DATADIR}/images/pigs.jpg"
@pdf = Prawn::Document.new(:background => @filename)
Expand All @@ -128,11 +127,7 @@ def self.format(string)
@pdf.instance_variable_defined?(:@background).should == true
@pdf.instance_variable_get(:@background).should == @filename
end


end


end

describe "Prawn::Document#float" do
Expand Down Expand Up @@ -530,7 +525,7 @@ def self.format(string)
end

describe "content stream characteristics" do
it "should have 1 single content stream for a single page PDF with no templates" do
it "should have 1 single content stream for a single page PDF" do
@pdf = Prawn::Document.new
@pdf.text "James"
output = StringIO.new(@pdf.render)
Expand All @@ -541,7 +536,7 @@ def self.format(string)
streams.size.should == 1
end

it "should have 1 single content stream for a single page PDF with no templates, even if go_to_page is used" do
it "should have 1 single content stream for a single page PDF, even if go_to_page is used" do
@pdf = Prawn::Document.new
@pdf.text "James"
@pdf.go_to_page(1)
Expand Down

0 comments on commit bd88d48

Please sign in to comment.