prawn-core 0.7.2 → 0.8.4
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.
- data/Rakefile +1 -1
- data/examples/general/background.rb +1 -1
- data/examples/general/measurement_units.rb +2 -2
- data/examples/general/outlines.rb +50 -0
- data/examples/general/repeaters.rb +11 -7
- data/examples/general/stamp.rb +6 -6
- data/examples/graphics/basic_images.rb +1 -1
- data/examples/graphics/curves.rb +1 -1
- data/examples/graphics/rounded_polygons.rb +19 -0
- data/examples/graphics/rounded_rectangle.rb +20 -0
- data/examples/graphics/transformations.rb +52 -0
- data/examples/m17n/win_ansi_charset.rb +1 -1
- data/examples/text/font_calculations.rb +3 -3
- data/examples/text/indent_paragraphs.rb +18 -0
- data/examples/text/kerning.rb +4 -4
- data/examples/text/rotated.rb +98 -0
- data/examples/text/simple_text.rb +3 -3
- data/examples/text/simple_text_ttf.rb +1 -1
- data/lib/prawn/byte_string.rb +1 -0
- data/lib/prawn/core.rb +12 -5
- data/lib/prawn/core/object_store.rb +99 -0
- data/lib/prawn/core/page.rb +96 -0
- data/lib/prawn/core/text.rb +75 -0
- data/lib/prawn/document.rb +71 -78
- data/lib/prawn/document/annotations.rb +2 -2
- data/lib/prawn/document/bounding_box.rb +19 -9
- data/lib/prawn/document/column_box.rb +13 -12
- data/lib/prawn/document/graphics_state.rb +49 -0
- data/lib/prawn/document/internals.rb +5 -40
- data/lib/prawn/document/page_geometry.rb +1 -18
- data/lib/prawn/document/snapshot.rb +12 -7
- data/lib/prawn/errors.rb +18 -0
- data/lib/prawn/font.rb +4 -2
- data/lib/prawn/font/afm.rb +8 -0
- data/lib/prawn/font/dfont.rb +12 -4
- data/lib/prawn/font/ttf.rb +9 -0
- data/lib/prawn/graphics.rb +66 -9
- data/lib/prawn/graphics/color.rb +1 -1
- data/lib/prawn/graphics/transformation.rb +156 -0
- data/lib/prawn/graphics/transparency.rb +3 -7
- data/lib/prawn/images.rb +4 -3
- data/lib/prawn/images/png.rb +2 -2
- data/lib/prawn/outline.rb +278 -0
- data/lib/prawn/pdf_object.rb +5 -3
- data/lib/prawn/repeater.rb +25 -13
- data/lib/prawn/stamp.rb +6 -29
- data/lib/prawn/text.rb +139 -121
- data/lib/prawn/text/box.rb +168 -102
- data/spec/bounding_box_spec.rb +7 -2
- data/spec/document_spec.rb +7 -5
- data/spec/font_spec.rb +9 -1
- data/spec/graphics_spec.rb +229 -0
- data/spec/object_store_spec.rb +5 -5
- data/spec/outline_spec.rb +229 -0
- data/spec/repeater_spec.rb +18 -1
- data/spec/snapshot_spec.rb +7 -7
- data/spec/span_spec.rb +6 -2
- data/spec/spec_helper.rb +7 -3
- data/spec/stamp_spec.rb +13 -0
- data/spec/text_at_spec.rb +119 -0
- data/spec/text_box_spec.rb +257 -4
- data/spec/text_spec.rb +278 -180
- data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +12 -0
- metadata +16 -3
- data/lib/prawn/object_store.rb +0 -92
@@ -7,7 +7,7 @@ require "#{File.dirname(__FILE__)}/../example_helper.rb"
|
|
7
7
|
Prawn::Document.generate "simple_text_ttf.pdf" do
|
8
8
|
fill_color "0000ff"
|
9
9
|
font "#{Prawn::BASEDIR}/data/fonts/comicsans.ttf"
|
10
|
-
|
10
|
+
draw_text "Hello World", :at => [200,720], :size => 32
|
11
11
|
|
12
12
|
font "#{Prawn::BASEDIR}/data/fonts/Chalkboard.ttf"
|
13
13
|
|
data/lib/prawn/byte_string.rb
CHANGED
data/lib/prawn/core.rb
CHANGED
@@ -4,6 +4,9 @@
|
|
4
4
|
# Copyright April 2008, Gregory Brown. All Rights Reserved.
|
5
5
|
#
|
6
6
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
7
|
+
|
8
|
+
require "set"
|
9
|
+
|
7
10
|
%w[ttfunk/lib].each do |dep|
|
8
11
|
$LOAD_PATH.unshift(File.dirname(__FILE__) + "/../../vendor/#{dep}")
|
9
12
|
end
|
@@ -18,14 +21,17 @@ rescue LoadError
|
|
18
21
|
end
|
19
22
|
|
20
23
|
module Prawn
|
24
|
+
extend self
|
25
|
+
|
21
26
|
file = __FILE__
|
22
27
|
file = File.readlink(file) if File.symlink?(file)
|
23
|
-
dir
|
28
|
+
dir = File.dirname(file)
|
24
29
|
|
25
30
|
# The base source directory for Prawn as installed on the system
|
31
|
+
#
|
26
32
|
BASEDIR = File.expand_path(File.join(dir, '..', '..'))
|
27
33
|
|
28
|
-
VERSION = "0.
|
34
|
+
VERSION = "0.8.4"
|
29
35
|
|
30
36
|
extend self
|
31
37
|
|
@@ -40,9 +46,8 @@ module Prawn
|
|
40
46
|
#
|
41
47
|
attr_accessor :debug
|
42
48
|
|
43
|
-
def verify_options(accepted,actual) #:nodoc:
|
49
|
+
def verify_options(accepted, actual) #:nodoc:
|
44
50
|
return unless debug || $DEBUG
|
45
|
-
require "set"
|
46
51
|
unless (act=Set[*actual.keys]).subset?(acc=Set[*accepted])
|
47
52
|
raise Prawn::Errors::UnknownOption,
|
48
53
|
"\nDetected unknown option(s): #{(act - acc).to_a.inspect}\n" <<
|
@@ -71,8 +76,9 @@ end
|
|
71
76
|
|
72
77
|
require "prawn/compatibility"
|
73
78
|
require "prawn/errors"
|
79
|
+
require "prawn/core/page"
|
80
|
+
require "prawn/core/object_store"
|
74
81
|
require "prawn/pdf_object"
|
75
|
-
require "prawn/object_store"
|
76
82
|
require "prawn/text"
|
77
83
|
require "prawn/graphics"
|
78
84
|
require "prawn/images"
|
@@ -85,3 +91,4 @@ require "prawn/font"
|
|
85
91
|
require "prawn/encoding"
|
86
92
|
require "prawn/measurements"
|
87
93
|
require "prawn/repeater"
|
94
|
+
require "prawn/outline"
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# prawn/core/object_store.rb : Implements PDF object repository for Prawn
|
4
|
+
#
|
5
|
+
# Copyright August 2009, Brad Ediger. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
+
|
9
|
+
module Prawn
|
10
|
+
module Core
|
11
|
+
class ObjectStore #:nodoc:
|
12
|
+
|
13
|
+
include Enumerable
|
14
|
+
|
15
|
+
BASE_OBJECTS = %w[info pages root]
|
16
|
+
|
17
|
+
def initialize(info={})
|
18
|
+
@objects = {}
|
19
|
+
@identifiers = []
|
20
|
+
|
21
|
+
# Create required PDF roots
|
22
|
+
@info = ref(info).identifier
|
23
|
+
@pages = ref(:Type => :Pages, :Count => 0, :Kids => []).identifier
|
24
|
+
@root = ref(:Type => :Catalog, :Pages => pages).identifier
|
25
|
+
end
|
26
|
+
|
27
|
+
def ref(data, &block)
|
28
|
+
push(size + 1, data, &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
%w[info pages root].each do |name|
|
32
|
+
define_method(name) do
|
33
|
+
@objects[instance_variable_get("@#{name}")]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Adds the given reference to the store and returns the reference object.
|
38
|
+
# If the object provided is not a Prawn::Reference, one is created from the
|
39
|
+
# arguments provided.
|
40
|
+
#
|
41
|
+
def push(*args, &block)
|
42
|
+
reference = if args.first.is_a?(Prawn::Reference)
|
43
|
+
args.first
|
44
|
+
else
|
45
|
+
Prawn::Reference.new(*args, &block)
|
46
|
+
end
|
47
|
+
@objects[reference.identifier] = reference
|
48
|
+
@identifiers << reference.identifier
|
49
|
+
reference
|
50
|
+
end
|
51
|
+
|
52
|
+
alias_method :<<, :push
|
53
|
+
|
54
|
+
def each
|
55
|
+
@identifiers.each do |id|
|
56
|
+
yield @objects[id]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def [](id)
|
61
|
+
@objects[id]
|
62
|
+
end
|
63
|
+
|
64
|
+
def size
|
65
|
+
@identifiers.size
|
66
|
+
end
|
67
|
+
alias_method :length, :size
|
68
|
+
|
69
|
+
def compact
|
70
|
+
# Clear live markers
|
71
|
+
each { |o| o.live = false }
|
72
|
+
|
73
|
+
# Recursively mark reachable objects live, starting from the roots
|
74
|
+
# (the only objects referenced in the trailer)
|
75
|
+
root.mark_live
|
76
|
+
info.mark_live
|
77
|
+
|
78
|
+
# Renumber live objects to eliminate gaps (shrink the xref table)
|
79
|
+
if @objects.any?{ |_, o| !o.live }
|
80
|
+
new_id = 1
|
81
|
+
new_objects = {}
|
82
|
+
new_identifiers = []
|
83
|
+
|
84
|
+
each do |obj|
|
85
|
+
if obj.live
|
86
|
+
obj.identifier = new_id
|
87
|
+
new_objects[new_id] = obj
|
88
|
+
new_identifiers << new_id
|
89
|
+
new_id += 1
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
@objects = new_objects
|
94
|
+
@identifiers = new_identifiers
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# prawn/core/page.rb : Implements low-level representation of a PDF page
|
4
|
+
#
|
5
|
+
# Copyright February 2010, Gregory Brown. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
+
#
|
9
|
+
module Prawn
|
10
|
+
module Core
|
11
|
+
class Page #:nodoc:
|
12
|
+
def initialize(document, options={})
|
13
|
+
@document = document
|
14
|
+
@size = options[:size] || "LETTER"
|
15
|
+
|
16
|
+
@layout = options[:layout] || :portrait
|
17
|
+
|
18
|
+
@margins = options[:margins] || { :left => 36,
|
19
|
+
:right => 36,
|
20
|
+
:top => 36,
|
21
|
+
:bottom => 36 }
|
22
|
+
|
23
|
+
@content = document.ref(:Length => 0)
|
24
|
+
@dictionary = document.ref(:Type => :Page,
|
25
|
+
:Parent => document.store.pages,
|
26
|
+
:MediaBox => dimensions,
|
27
|
+
:Contents => content)
|
28
|
+
|
29
|
+
resources[:ProcSet] = [:PDF, :Text, :ImageB, :ImageC, :ImageI]
|
30
|
+
|
31
|
+
@stamp_stream = nil
|
32
|
+
@stamp_dictionary = nil
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_accessor :size, :layout, :margins, :document, :content, :dictionary
|
36
|
+
|
37
|
+
def in_stamp_stream?
|
38
|
+
!!@stamp_stream
|
39
|
+
end
|
40
|
+
|
41
|
+
def stamp_stream(dictionary)
|
42
|
+
@stamp_stream = ""
|
43
|
+
@stamp_dictionary = dictionary
|
44
|
+
|
45
|
+
document.send(:update_colors)
|
46
|
+
yield if block_given?
|
47
|
+
document.send(:update_colors)
|
48
|
+
|
49
|
+
@stamp_dictionary.data[:Length] = @stamp_stream.length + 1
|
50
|
+
@stamp_dictionary << @stamp_stream
|
51
|
+
|
52
|
+
@stamp_stream = nil
|
53
|
+
@stamp_dictionary = nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def dimensions
|
57
|
+
coords = Prawn::Document::PageGeometry::SIZES[size] || size
|
58
|
+
[0,0] + case(layout)
|
59
|
+
when :portrait
|
60
|
+
coords
|
61
|
+
when :landscape
|
62
|
+
coords.reverse
|
63
|
+
else
|
64
|
+
raise Prawn::Errors::InvalidPageLayout,
|
65
|
+
"Layout must be either :portrait or :landscape"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def content
|
70
|
+
@stamp_stream || document.store[@content]
|
71
|
+
end
|
72
|
+
|
73
|
+
def dictionary
|
74
|
+
@stamp_dictionary || document.store[@dictionary]
|
75
|
+
end
|
76
|
+
|
77
|
+
def resources
|
78
|
+
dictionary.data[:Resources] ||= {}
|
79
|
+
end
|
80
|
+
|
81
|
+
def fonts
|
82
|
+
resources[:Font] ||= {}
|
83
|
+
end
|
84
|
+
|
85
|
+
def xobjects
|
86
|
+
resources[:XObject] ||= {}
|
87
|
+
end
|
88
|
+
|
89
|
+
def ext_gstates
|
90
|
+
resources[:ExtGState] ||= {}
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# prawn/core/text.rb : Implements low level text helpers for Prawn
|
4
|
+
#
|
5
|
+
# Copyright January 2010, Daniel Nelson. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
+
|
9
|
+
ruby_18 { $KCODE="U" }
|
10
|
+
|
11
|
+
module Prawn
|
12
|
+
module Core
|
13
|
+
module Text #:nodoc:
|
14
|
+
|
15
|
+
# These should be used as a base. Extensions may build on this list
|
16
|
+
#
|
17
|
+
VALID_OPTIONS = [:kerning, :size, :style]
|
18
|
+
|
19
|
+
attr_reader :text_options
|
20
|
+
attr_reader :skip_encoding
|
21
|
+
|
22
|
+
# Low level text placement method. All font and size alterations
|
23
|
+
# should already be set
|
24
|
+
#
|
25
|
+
def draw_text!(text, options)
|
26
|
+
x,y = map_to_absolute(options[:at])
|
27
|
+
add_text_content(text,x,y,options)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Low level call to set the current font style and extract text options from
|
31
|
+
# an options hash. Should be called from within a save_font block
|
32
|
+
#
|
33
|
+
def process_text_options(options)
|
34
|
+
if options[:style]
|
35
|
+
raise "Bad font family" unless font.family
|
36
|
+
font(font.family, :style => options[:style])
|
37
|
+
end
|
38
|
+
|
39
|
+
# must compare against false to keep kerning on as default
|
40
|
+
unless options[:kerning] == false
|
41
|
+
options[:kerning] = font.has_kerning_data?
|
42
|
+
end
|
43
|
+
|
44
|
+
options[:size] ||= font_size
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def add_text_content(text, x, y, options)
|
50
|
+
chunks = font.encode_text(text,options)
|
51
|
+
|
52
|
+
add_content "\nBT"
|
53
|
+
|
54
|
+
if options[:rotate]
|
55
|
+
rad = options[:rotate].to_i * Math::PI / 180
|
56
|
+
arr = [ Math.cos(rad), Math.sin(rad), -Math.sin(rad), Math.cos(rad), x, y ]
|
57
|
+
add_content "%.3f %.3f %.3f %.3f %.3f %.3f Tm" % arr
|
58
|
+
else
|
59
|
+
add_content "#{x} #{y} Td"
|
60
|
+
end
|
61
|
+
|
62
|
+
chunks.each do |(subset, string)|
|
63
|
+
font.add_to_current_page(subset)
|
64
|
+
add_content "/#{font.identifier_for(subset)} #{font_size} Tf"
|
65
|
+
|
66
|
+
operation = options[:kerning] && string.is_a?(Array) ? "TJ" : "Tj"
|
67
|
+
add_content Prawn::PdfObject(string, true) << " " << operation
|
68
|
+
end
|
69
|
+
|
70
|
+
add_content "ET\n"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
data/lib/prawn/document.rb
CHANGED
@@ -15,6 +15,7 @@ require "prawn/document/span"
|
|
15
15
|
require "prawn/document/annotations"
|
16
16
|
require "prawn/document/destinations"
|
17
17
|
require "prawn/document/snapshot"
|
18
|
+
require "prawn/document/graphics_state"
|
18
19
|
|
19
20
|
module Prawn
|
20
21
|
|
@@ -53,20 +54,21 @@ module Prawn
|
|
53
54
|
#
|
54
55
|
class Document
|
55
56
|
|
56
|
-
include Text
|
57
|
-
include PageGeometry
|
58
57
|
include Internals
|
59
58
|
include Annotations
|
60
59
|
include Destinations
|
61
60
|
include Snapshot
|
61
|
+
include GraphicsState
|
62
62
|
include Prawn::Text
|
63
63
|
include Prawn::Graphics
|
64
64
|
include Prawn::Images
|
65
65
|
include Prawn::Stamp
|
66
|
+
|
66
67
|
|
67
|
-
attr_accessor :margin_box
|
68
|
-
attr_reader :margins, :
|
68
|
+
attr_accessor :margin_box, :page
|
69
|
+
attr_reader :margins, :y, :store, :pages
|
69
70
|
attr_writer :font_size
|
71
|
+
attr_accessor :default_line_wrap
|
70
72
|
|
71
73
|
|
72
74
|
# Any module added to this array will be included into instances of
|
@@ -109,7 +111,7 @@ module Prawn
|
|
109
111
|
# # self here is set to the newly instantiated Prawn::Document
|
110
112
|
# # and so any variables in the outside scope are unavailable
|
111
113
|
# font "Times-Roman"
|
112
|
-
#
|
114
|
+
# draw_text "Hello World", :at => [200,720], :size => 32
|
113
115
|
# end
|
114
116
|
#
|
115
117
|
# If you need to access your local and instance variables, use the explicit
|
@@ -121,7 +123,7 @@ module Prawn
|
|
121
123
|
# Prawn::Document.generate "example.pdf" do |pdf|
|
122
124
|
# # self here is left alone
|
123
125
|
# pdf.font "Times-Roman"
|
124
|
-
# pdf.
|
126
|
+
# pdf.draw_text content, :at => [200,720], :size => 32
|
125
127
|
# end
|
126
128
|
#
|
127
129
|
def self.generate(filename,options={},&block)
|
@@ -181,6 +183,10 @@ module Prawn
|
|
181
183
|
:compress, :skip_encoding, :text_options, :background, :info,
|
182
184
|
:optimize_objects], options
|
183
185
|
|
186
|
+
|
187
|
+
# need to fix, as the refactoring breaks this
|
188
|
+
# raise NotImplementedError if options[:skip_page_creation]
|
189
|
+
|
184
190
|
self.class.extensions.reverse_each { |e| extend e }
|
185
191
|
|
186
192
|
options[:info] ||= {}
|
@@ -194,39 +200,40 @@ module Prawn
|
|
194
200
|
end
|
195
201
|
|
196
202
|
@version = 1.3
|
197
|
-
@store = ObjectStore.new(options[:info])
|
203
|
+
@store = Prawn::Core::ObjectStore.new(options[:info])
|
198
204
|
@trailer = {}
|
205
|
+
|
199
206
|
@before_render_callbacks = []
|
200
207
|
@on_page_create_callback = nil
|
201
208
|
|
202
|
-
@
|
203
|
-
@page_layout = options[:page_layout] || :portrait
|
204
|
-
@compress = options[:compress] || false
|
209
|
+
@compress = options[:compress] || false
|
205
210
|
@optimize_objects = options.fetch(:optimize_objects, false)
|
206
|
-
@skip_encoding
|
207
|
-
@background
|
208
|
-
@font_size
|
209
|
-
|
211
|
+
@skip_encoding = options[:skip_encoding]
|
212
|
+
@background = options[:background]
|
213
|
+
@font_size = 12
|
214
|
+
|
215
|
+
@pages = []
|
216
|
+
@page = nil
|
217
|
+
|
210
218
|
@bounding_box = nil
|
211
219
|
@margin_box = nil
|
212
220
|
|
213
221
|
@text_options = options[:text_options] || {}
|
214
|
-
|
215
|
-
apply_margin_option(options) if options[:margin]
|
216
|
-
|
217
|
-
default_margin = 36 # 0.5 inch
|
218
|
-
@margins = { :left => options[:left_margin] || default_margin,
|
219
|
-
:right => options[:right_margin] || default_margin,
|
220
|
-
:top => options[:top_margin] || default_margin,
|
221
|
-
:bottom => options[:bottom_margin] || default_margin }
|
222
|
-
|
223
|
-
generate_margin_box
|
222
|
+
@default_line_wrap = Prawn::Text::LineWrap.new
|
224
223
|
|
225
|
-
@bounding_box = @margin_box
|
226
224
|
@page_number = 0
|
227
225
|
|
228
|
-
|
226
|
+
options[:size] = options.delete(:page_size)
|
227
|
+
options[:layout] = options.delete(:page_layout)
|
229
228
|
|
229
|
+
if options[:skip_page_creation]
|
230
|
+
start_new_page(options.merge(:orphan => true))
|
231
|
+
else
|
232
|
+
start_new_page(options)
|
233
|
+
end
|
234
|
+
|
235
|
+
@bounding_box = @margin_box
|
236
|
+
|
230
237
|
if block
|
231
238
|
block.arity < 1 ? instance_eval(&block) : block[self]
|
232
239
|
end
|
@@ -243,32 +250,45 @@ module Prawn
|
|
243
250
|
# pdf.start_new_page(:margin => 100)
|
244
251
|
#
|
245
252
|
def start_new_page(options = {})
|
246
|
-
|
247
|
-
|
248
|
-
|
253
|
+
if last_page = page
|
254
|
+
last_page_size = last_page.size
|
255
|
+
last_page_layout = last_page.layout
|
256
|
+
last_page_margins = last_page.margins
|
257
|
+
end
|
258
|
+
|
259
|
+
self.page = Prawn::Core::Page.new(self,
|
260
|
+
:size => options[:size] || last_page_size,
|
261
|
+
:layout => options[:layout] || last_page_layout,
|
262
|
+
:margins => last_page_margins )
|
263
|
+
|
249
264
|
|
250
265
|
apply_margin_option(options) if options[:margin]
|
251
266
|
|
252
267
|
[:left,:right,:top,:bottom].each do |side|
|
253
268
|
if margin = options[:"#{side}_margin"]
|
254
|
-
|
269
|
+
page.margins[side] = margin
|
255
270
|
end
|
256
271
|
end
|
257
272
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
273
|
+
generate_margin_box
|
274
|
+
|
275
|
+
update_colors
|
276
|
+
undash if dashed?
|
277
|
+
|
278
|
+
unless options[:orphan]
|
279
|
+
pages.insert(@page_number, page)
|
280
|
+
@store.pages.data[:Kids].insert(@page_number, page.dictionary)
|
281
|
+
@store.pages.data[:Count] += 1
|
282
|
+
@page_number += 1
|
283
|
+
|
284
|
+
save_graphics_state
|
263
285
|
|
264
|
-
|
265
|
-
|
266
|
-
@y = @bounding_box.absolute_top
|
286
|
+
canvas { image(@background, :at => bounds.top_left) } if @background
|
287
|
+
@y = @bounding_box.absolute_top
|
267
288
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
@on_page_create_callback.call(self) if @on_page_create_callback
|
289
|
+
float do
|
290
|
+
@on_page_create_callback.call(self) if @on_page_create_callback
|
291
|
+
end
|
272
292
|
end
|
273
293
|
end
|
274
294
|
|
@@ -280,7 +300,7 @@ module Prawn
|
|
280
300
|
# pdf.page_count #=> 4
|
281
301
|
#
|
282
302
|
def page_count
|
283
|
-
|
303
|
+
pages.length
|
284
304
|
end
|
285
305
|
|
286
306
|
# Returns the 1-based page number of the current page. Returns 0 if the
|
@@ -289,7 +309,7 @@ module Prawn
|
|
289
309
|
def page_number
|
290
310
|
@page_number
|
291
311
|
end
|
292
|
-
|
312
|
+
|
293
313
|
# Re-opens the page with the given (1-based) page number so that you can
|
294
314
|
# draw on it. Does not restore page state such as margins, page orientation,
|
295
315
|
# or paper size, so you'll have to handle that yourself.
|
@@ -298,9 +318,7 @@ module Prawn
|
|
298
318
|
#
|
299
319
|
def go_to_page(k)
|
300
320
|
@page_number = k
|
301
|
-
|
302
|
-
@current_page = jump_to.identifier
|
303
|
-
@page_content = jump_to.data[:Contents].identifier
|
321
|
+
self.page = pages[k-1]
|
304
322
|
end
|
305
323
|
|
306
324
|
def y=(new_y)
|
@@ -481,11 +499,6 @@ module Prawn
|
|
481
499
|
fields.each { |f| send("#{f}=", stored[f]) }
|
482
500
|
end
|
483
501
|
|
484
|
-
# Raised if group() is called with a block that is too big to be
|
485
|
-
# rendered in the current context.
|
486
|
-
#
|
487
|
-
CannotGroup = Class.new(StandardError) #FIXME: should be in prawn/errors.rb
|
488
|
-
|
489
502
|
# Attempts to group the given block vertically within the current context.
|
490
503
|
# First attempts to render it in the current position on the current page.
|
491
504
|
# If that attempt overflows, it is tried anew after starting a new context
|
@@ -505,7 +518,7 @@ module Prawn
|
|
505
518
|
success = transaction { yield }
|
506
519
|
|
507
520
|
unless success
|
508
|
-
raise CannotGroup if second_attempt
|
521
|
+
raise Prawn::Errors::CannotGroup if second_attempt
|
509
522
|
old_bounding_box.move_past_bottom
|
510
523
|
group(second_attempt=true) { yield }
|
511
524
|
end
|
@@ -533,7 +546,7 @@ module Prawn
|
|
533
546
|
page_count.times do |i|
|
534
547
|
go_to_page(i+1)
|
535
548
|
str = string.gsub("<page>","#{i+1}").gsub("<total>","#{page_count}")
|
536
|
-
|
549
|
+
draw_text str, :at => position
|
537
550
|
end
|
538
551
|
end
|
539
552
|
|
@@ -543,35 +556,16 @@ module Prawn
|
|
543
556
|
def compression_enabled?
|
544
557
|
!!@compress
|
545
558
|
end
|
546
|
-
|
559
|
+
|
547
560
|
private
|
548
561
|
|
549
|
-
# See Prawn::Document::Internals for low-level PDF functions
|
550
|
-
#
|
551
|
-
def build_new_page_content
|
552
|
-
generate_margin_box
|
553
|
-
@page_content = ref(:Length => 0)
|
554
|
-
|
555
|
-
@current_page = ref(:Type => :Page,
|
556
|
-
:Parent => @store.pages,
|
557
|
-
:MediaBox => page_dimensions,
|
558
|
-
:Contents => page_content)
|
559
|
-
|
560
|
-
# include all proc sets, all the time (recommended by PDF 1.4 Reference
|
561
|
-
# section 9.1)
|
562
|
-
page_resources[:ProcSet] = [:PDF, :Text, :ImageB, :ImageC, :ImageI]
|
563
|
-
|
564
|
-
update_colors
|
565
|
-
undash if dashed?
|
566
|
-
end
|
567
|
-
|
568
562
|
def generate_margin_box
|
569
563
|
old_margin_box = @margin_box
|
570
564
|
@margin_box = BoundingBox.new(
|
571
565
|
self,
|
572
|
-
[
|
573
|
-
:width =>
|
574
|
-
:height =>
|
566
|
+
[ page.margins[:left], page.dimensions[-1] - page.margins[:top] ] ,
|
567
|
+
:width => page.dimensions[-2] - (page.margins[:left] + page.margins[:right]),
|
568
|
+
:height => page.dimensions[-1] - (page.margins[:top] + page.margins[:bottom])
|
575
569
|
)
|
576
570
|
|
577
571
|
# we must update bounding box if not flowing from the previous page
|
@@ -591,6 +585,5 @@ module Prawn
|
|
591
585
|
options[:"#{p}_margin"] ||= margin[i]
|
592
586
|
end
|
593
587
|
end
|
594
|
-
|
595
588
|
end
|
596
589
|
end
|