prawn 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/prawn/document/bounding_box.rb +213 -141
- data/lib/prawn/document/column_box.rb +61 -26
- data/lib/prawn/document/internals.rb +25 -16
- data/lib/prawn/document/span.rb +20 -18
- data/lib/prawn/document.rb +257 -171
- data/lib/prawn/encoding.rb +2 -5
- data/lib/prawn/errors.rb +23 -34
- data/lib/prawn/font.rb +248 -135
- data/lib/prawn/font_metric_cache.rb +11 -10
- data/lib/prawn/fonts/afm.rb +85 -45
- data/lib/prawn/fonts/dfont.rb +7 -1
- data/lib/prawn/fonts/otf.rb +4 -1
- data/lib/prawn/fonts/to_unicode_cmap.rb +151 -0
- data/lib/prawn/fonts/ttc.rb +7 -2
- data/lib/prawn/fonts/ttf.rb +305 -93
- data/lib/prawn/fonts.rb +14 -0
- data/lib/prawn/graphics/blend_mode.rb +25 -28
- data/lib/prawn/graphics/cap_style.rb +9 -12
- data/lib/prawn/graphics/color.rb +57 -34
- data/lib/prawn/graphics/dash.rb +45 -42
- data/lib/prawn/graphics/join_style.rb +17 -11
- data/lib/prawn/graphics/patterns.rb +190 -69
- data/lib/prawn/graphics/transformation.rb +48 -41
- data/lib/prawn/graphics/transparency.rb +16 -40
- data/lib/prawn/graphics.rb +363 -253
- data/lib/prawn/grid.rb +184 -57
- data/lib/prawn/image_handler.rb +27 -10
- data/lib/prawn/images/image.rb +8 -10
- data/lib/prawn/images/jpg.rb +42 -19
- data/lib/prawn/images/png.rb +92 -41
- data/lib/prawn/images.rb +44 -57
- data/lib/prawn/measurement_extensions.rb +39 -8
- data/lib/prawn/measurements.rb +60 -5
- data/lib/prawn/outline.rb +114 -108
- data/lib/prawn/repeater.rb +51 -35
- data/lib/prawn/security/arcfour.rb +4 -4
- data/lib/prawn/security.rb +75 -70
- data/lib/prawn/soft_mask.rb +42 -30
- data/lib/prawn/stamp.rb +38 -42
- data/lib/prawn/text/box.rb +146 -96
- data/lib/prawn/text/formatted/arranger.rb +87 -26
- data/lib/prawn/text/formatted/box.rb +221 -150
- data/lib/prawn/text/formatted/fragment.rb +130 -14
- data/lib/prawn/text/formatted/line_wrap.rb +33 -24
- data/lib/prawn/text/formatted/parser.rb +112 -72
- data/lib/prawn/text/formatted/wrap.rb +12 -17
- data/lib/prawn/text/formatted.rb +75 -0
- data/lib/prawn/text.rb +441 -196
- data/lib/prawn/transformation_stack.rb +29 -10
- data/lib/prawn/utilities.rb +13 -13
- data/lib/prawn/version.rb +2 -1
- data/lib/prawn/view.rb +68 -53
- data/lib/prawn.rb +23 -18
- data.tar.gz.sig +0 -0
- metadata +54 -177
- metadata.gz.sig +0 -0
- data/.yardopts +0 -10
- data/Gemfile +0 -5
- data/Rakefile +0 -25
- data/manual/absolute_position.pdf +0 -0
- data/manual/basic_concepts/adding_pages.rb +0 -26
- data/manual/basic_concepts/basic_concepts.rb +0 -43
- data/manual/basic_concepts/creation.rb +0 -38
- data/manual/basic_concepts/cursor.rb +0 -32
- data/manual/basic_concepts/measurement.rb +0 -24
- data/manual/basic_concepts/origin.rb +0 -37
- data/manual/basic_concepts/other_cursor_helpers.rb +0 -39
- data/manual/basic_concepts/view.rb +0 -48
- data/manual/bounding_box/bounding_box.rb +0 -41
- data/manual/bounding_box/bounds.rb +0 -48
- data/manual/bounding_box/canvas.rb +0 -23
- data/manual/bounding_box/creation.rb +0 -22
- data/manual/bounding_box/indentation.rb +0 -45
- data/manual/bounding_box/nesting.rb +0 -52
- data/manual/bounding_box/russian_boxes.rb +0 -40
- data/manual/bounding_box/stretchy.rb +0 -29
- data/manual/contents.rb +0 -35
- data/manual/cover.rb +0 -43
- data/manual/document_and_page_options/background.rb +0 -29
- data/manual/document_and_page_options/document_and_page_options.rb +0 -34
- data/manual/document_and_page_options/metadata.rb +0 -25
- data/manual/document_and_page_options/page_margins.rb +0 -36
- data/manual/document_and_page_options/page_size.rb +0 -34
- data/manual/document_and_page_options/print_scaling.rb +0 -23
- data/manual/example_helper.rb +0 -8
- data/manual/graphics/blend_mode.rb +0 -52
- data/manual/graphics/circle_and_ellipse.rb +0 -21
- data/manual/graphics/color.rb +0 -22
- data/manual/graphics/common_lines.rb +0 -29
- data/manual/graphics/fill_and_stroke.rb +0 -41
- data/manual/graphics/fill_rules.rb +0 -38
- data/manual/graphics/gradients.rb +0 -43
- data/manual/graphics/graphics.rb +0 -64
- data/manual/graphics/helper.rb +0 -34
- data/manual/graphics/line_width.rb +0 -36
- data/manual/graphics/lines_and_curves.rb +0 -40
- data/manual/graphics/polygon.rb +0 -27
- data/manual/graphics/rectangle.rb +0 -20
- data/manual/graphics/rotate.rb +0 -25
- data/manual/graphics/scale.rb +0 -42
- data/manual/graphics/soft_masks.rb +0 -44
- data/manual/graphics/stroke_cap.rb +0 -30
- data/manual/graphics/stroke_dash.rb +0 -47
- data/manual/graphics/stroke_join.rb +0 -29
- data/manual/graphics/translate.rb +0 -29
- data/manual/graphics/transparency.rb +0 -33
- data/manual/how_to_read_this_manual.rb +0 -39
- data/manual/images/absolute_position.rb +0 -22
- data/manual/images/fit.rb +0 -20
- data/manual/images/horizontal.rb +0 -24
- data/manual/images/images.rb +0 -41
- data/manual/images/plain_image.rb +0 -17
- data/manual/images/scale.rb +0 -21
- data/manual/images/vertical.rb +0 -30
- data/manual/images/width_and_height.rb +0 -24
- data/manual/layout/boxes.rb +0 -26
- data/manual/layout/content.rb +0 -24
- data/manual/layout/layout.rb +0 -27
- data/manual/layout/simple_grid.rb +0 -22
- data/manual/outline/add_subsection_to.rb +0 -60
- data/manual/outline/insert_section_after.rb +0 -46
- data/manual/outline/outline.rb +0 -33
- data/manual/outline/sections_and_pages.rb +0 -66
- data/manual/repeatable_content/alternate_page_numbering.rb +0 -36
- data/manual/repeatable_content/page_numbering.rb +0 -55
- data/manual/repeatable_content/repeatable_content.rb +0 -35
- data/manual/repeatable_content/repeater.rb +0 -54
- data/manual/repeatable_content/stamp.rb +0 -40
- data/manual/security/encryption.rb +0 -28
- data/manual/security/permissions.rb +0 -43
- data/manual/security/security.rb +0 -28
- data/manual/table.rb +0 -16
- data/manual/text/alignment.rb +0 -43
- data/manual/text/color.rb +0 -24
- data/manual/text/column_box.rb +0 -30
- data/manual/text/fallback_fonts.rb +0 -41
- data/manual/text/font.rb +0 -40
- data/manual/text/font_size.rb +0 -44
- data/manual/text/font_style.rb +0 -25
- data/manual/text/formatted_callbacks.rb +0 -70
- data/manual/text/formatted_text.rb +0 -61
- data/manual/text/free_flowing_text.rb +0 -50
- data/manual/text/inline.rb +0 -40
- data/manual/text/kerning_and_character_spacing.rb +0 -38
- data/manual/text/leading.rb +0 -24
- data/manual/text/line_wrapping.rb +0 -60
- data/manual/text/paragraph_indentation.rb +0 -31
- data/manual/text/positioned_text.rb +0 -37
- data/manual/text/registering_families.rb +0 -51
- data/manual/text/rendering_and_color.rb +0 -36
- data/manual/text/right_to_left_text.rb +0 -54
- data/manual/text/rotation.rb +0 -52
- data/manual/text/single_usage.rb +0 -36
- data/manual/text/text.rb +0 -75
- data/manual/text/text_box_excess.rb +0 -35
- data/manual/text/text_box_extensions.rb +0 -48
- data/manual/text/text_box_overflow.rb +0 -51
- data/manual/text/utf8.rb +0 -27
- data/manual/text/win_ansi_charset.rb +0 -62
- data/prawn.gemspec +0 -51
- data/spec/data/curves.pdf +0 -66
- data/spec/extensions/encoding_helpers.rb +0 -11
- data/spec/prawn/document/bounding_box_spec.rb +0 -550
- data/spec/prawn/document/column_box_spec.rb +0 -75
- data/spec/prawn/document/security_spec.rb +0 -176
- data/spec/prawn/document_annotations_spec.rb +0 -76
- data/spec/prawn/document_destinations_spec.rb +0 -15
- data/spec/prawn/document_grid_spec.rb +0 -99
- data/spec/prawn/document_reference_spec.rb +0 -27
- data/spec/prawn/document_span_spec.rb +0 -44
- data/spec/prawn/document_spec.rb +0 -805
- data/spec/prawn/font_metric_cache_spec.rb +0 -54
- data/spec/prawn/font_spec.rb +0 -544
- data/spec/prawn/graphics/blend_mode_spec.rb +0 -63
- data/spec/prawn/graphics/transparency_spec.rb +0 -81
- data/spec/prawn/graphics_spec.rb +0 -872
- data/spec/prawn/graphics_stroke_styles_spec.rb +0 -229
- data/spec/prawn/image_handler_spec.rb +0 -53
- data/spec/prawn/images/jpg_spec.rb +0 -20
- data/spec/prawn/images/png_spec.rb +0 -283
- data/spec/prawn/images_spec.rb +0 -229
- data/spec/prawn/measurements_extensions_spec.rb +0 -24
- data/spec/prawn/outline_spec.rb +0 -512
- data/spec/prawn/repeater_spec.rb +0 -166
- data/spec/prawn/soft_mask_spec.rb +0 -74
- data/spec/prawn/stamp_spec.rb +0 -173
- data/spec/prawn/text/box_spec.rb +0 -1110
- data/spec/prawn/text/formatted/arranger_spec.rb +0 -466
- data/spec/prawn/text/formatted/box_spec.rb +0 -849
- data/spec/prawn/text/formatted/fragment_spec.rb +0 -343
- data/spec/prawn/text/formatted/line_wrap_spec.rb +0 -495
- data/spec/prawn/text/formatted/parser_spec.rb +0 -697
- data/spec/prawn/text_draw_text_spec.rb +0 -150
- data/spec/prawn/text_rendering_mode_spec.rb +0 -48
- data/spec/prawn/text_spacing_spec.rb +0 -95
- data/spec/prawn/text_spec.rb +0 -603
- data/spec/prawn/text_with_inline_formatting_spec.rb +0 -35
- data/spec/prawn/transformation_stack_spec.rb +0 -66
- data/spec/prawn/view_spec.rb +0 -63
- data/spec/prawn_manual_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -48
data/lib/prawn/outline.rb
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Prawn
|
4
|
-
class Document
|
4
|
+
class Document # rubocop: disable Style/Documentation
|
5
5
|
# @group Stable API
|
6
6
|
|
7
7
|
# Lazily instantiates a Prawn::Outline object for document. This is used as
|
8
8
|
# point of entry to methods to build the outline tree for a document's table
|
9
9
|
# of contents.
|
10
|
+
#
|
11
|
+
# @return [Prawn::Outline]
|
10
12
|
def outline
|
11
13
|
@outline ||= Outline.new(self)
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
|
-
# The Outline class organizes the outline tree items for the document.
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# best way to understand how this works is to follow the method calls through
|
21
|
-
# a real example.
|
22
|
-
#
|
23
|
-
# Some ideas for the organization of this class were gleaned from name_tree.
|
24
|
-
# In particular the way in which the OutlineItems are finally rendered into
|
25
|
-
# document objects in PdfObject through a hash.
|
17
|
+
# The Outline class organizes the outline tree items for the document. Note
|
18
|
+
# that the {prev} and {parent} are adjusted while navigating through the
|
19
|
+
# nested blocks. These attributes along with the presence or absence of blocks
|
20
|
+
# are the primary means by which the relations for the various
|
21
|
+
# `PDF::Core::OutlineItem`s and the `PDF::Core::OutlineRoot` are set.
|
26
22
|
#
|
23
|
+
# Some ideas for the organization of this class were gleaned from `name_tree`.
|
24
|
+
# In particular the way in which the `PDF::Core::OutlineItem`s are finally
|
25
|
+
# rendered into document objects through a hash.
|
27
26
|
class Outline
|
28
27
|
# @private
|
29
28
|
attr_accessor :parent, :prev, :document, :items
|
30
29
|
|
30
|
+
# @param document [Prawn::Document]
|
31
31
|
def initialize(document)
|
32
32
|
@document = document
|
33
33
|
@parent = root
|
@@ -37,74 +37,81 @@ module Prawn
|
|
37
37
|
|
38
38
|
# @group Stable API
|
39
39
|
|
40
|
-
# Returns the current page number of the document
|
40
|
+
# Returns the current page number of the document.
|
41
|
+
#
|
42
|
+
# @return [Integer]
|
41
43
|
def page_number
|
42
44
|
@document.page_number
|
43
45
|
end
|
44
46
|
|
45
47
|
# Defines/Updates an outline for the document.
|
48
|
+
#
|
46
49
|
# The outline is an optional nested index that appears on the side of a PDF
|
47
50
|
# document usually with direct links to pages. The outline DSL is defined by
|
48
|
-
# nested blocks involving two methods: section and page
|
49
|
-
#
|
50
|
-
#
|
51
|
-
# outline tree using the same syntax and scope.
|
51
|
+
# nested blocks involving two methods: {section} and {page}. Note that one
|
52
|
+
# can also use {update} to add more sections to the end of the outline tree
|
53
|
+
# using the same syntax and scope.
|
52
54
|
#
|
53
55
|
# The syntax is best illustrated with an example:
|
54
56
|
#
|
55
|
-
#
|
57
|
+
# ```ruby
|
58
|
+
# Prawn::Document.generate('outlined_document.pdf') do
|
56
59
|
# text "Page 1. This is the first Chapter. "
|
57
60
|
# start_new_page
|
58
61
|
# text "Page 2. More in the first Chapter. "
|
59
62
|
# start_new_page
|
60
63
|
# outline.define do
|
61
|
-
# section 'Chapter 1', :
|
62
|
-
# page :
|
63
|
-
# page :
|
64
|
+
# section 'Chapter 1', destination: 1, closed: true do
|
65
|
+
# page destination: 1, title: 'Page 1'
|
66
|
+
# page destination: 2, title: 'Page 2'
|
64
67
|
# end
|
65
68
|
# end
|
66
69
|
# start_new_page do
|
67
70
|
# outline.update do
|
68
|
-
# section 'Chapter 2', :
|
69
|
-
# page :
|
71
|
+
# section 'Chapter 2', destination: 2, do
|
72
|
+
# page destination: 3, title: 'Page 3'
|
70
73
|
# end
|
71
74
|
# end
|
72
75
|
# end
|
76
|
+
# ```
|
73
77
|
#
|
78
|
+
# @yield
|
79
|
+
# @return [void]
|
74
80
|
def define(&block)
|
75
81
|
instance_eval(&block) if block
|
76
82
|
end
|
77
83
|
|
78
84
|
alias update define
|
79
85
|
|
80
|
-
# Inserts an outline section to the outline tree (see
|
81
|
-
# Although you will probably choose to exclusively use outline#define so
|
82
|
-
# that your outline tree is contained and easy to manage, this method gives
|
83
|
-
# you the option to insert sections to the outline tree at any point during
|
84
|
-
# document generation. This method allows you to add a child subsection to
|
85
|
-
# any other item at any level in the outline tree. Currently the only way
|
86
|
-
# to locate the place of entry is with the title for the item. If your title
|
87
|
-
# names are not unique consider using define_outline.
|
88
|
-
# The method takes the following arguments:
|
89
|
-
# title: a string that must match an outline title to add
|
90
|
-
# the subsection to
|
91
|
-
# position: either :first or :last (the default) where the subsection will
|
92
|
-
# be placed relative to other child elements. If you need to position
|
93
|
-
# your subsection in between other elements then consider using
|
94
|
-
# #insert_section_after
|
95
|
-
# block: uses the same DSL syntax as outline#define, for example:
|
86
|
+
# Inserts an outline section to the outline tree (see {define}).
|
96
87
|
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
88
|
+
# Although you will probably choose to exclusively use {define} so that your
|
89
|
+
# outline tree is contained and easy to manage, this method gives you the
|
90
|
+
# option to insert sections to the outline tree at any point during document
|
91
|
+
# generation. This method allows you to add a child subsection to any other
|
92
|
+
# item at any level in the outline tree. Currently the only way to locate
|
93
|
+
# the place of entry is with the title for the item. If your title names are
|
94
|
+
# not unique consider using {define}.
|
100
95
|
#
|
101
|
-
#
|
102
|
-
#
|
103
|
-
# text "Inserted Page"
|
104
|
-
# outline.add_subsection_to :title => 'Page 2', :first do
|
105
|
-
# outline.page :destination => page_number, :title => "Inserted Page"
|
106
|
-
# end
|
96
|
+
# Consider using this method instead of {update} if you want to have the
|
97
|
+
# outline object to be scoped as self (see {insert_section_after} example).
|
107
98
|
#
|
99
|
+
# ```ruby
|
100
|
+
# go_to_page 2
|
101
|
+
# start_new_page
|
102
|
+
# text "Inserted Page"
|
103
|
+
# outline.add_subsection_to title: 'Page 2', :first do
|
104
|
+
# outline.page destination: page_number, title: "Inserted Page"
|
105
|
+
# end
|
106
|
+
# ```
|
107
|
+
#
|
108
|
+
# @param title [String] An outline title to add the subsection to.
|
109
|
+
# @param position [:first, :last] (:last)
|
110
|
+
# Where the subsection will be placed relative to other child elements. If
|
111
|
+
# you need to position your subsection in between other elements then
|
112
|
+
# consider using {insert_section_after}.
|
113
|
+
# @yield Uses the same DSL syntax as {define}
|
114
|
+
# @return [void]
|
108
115
|
def add_subsection_to(title, position = :last, &block)
|
109
116
|
@parent = items[title]
|
110
117
|
unless @parent
|
@@ -116,19 +123,18 @@ module Prawn
|
|
116
123
|
insert_section(nxt, &block)
|
117
124
|
end
|
118
125
|
|
119
|
-
# Inserts an outline section to the outline tree (see
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
126
|
+
# Inserts an outline section to the outline tree (see {define}).
|
127
|
+
#
|
128
|
+
# Although you will probably choose to exclusively use {define} so that your
|
129
|
+
# outline tree is contained and easy to manage, this method gives you the
|
130
|
+
# option to insert sections to the outline tree at any point during document
|
131
|
+
# generation. Unlike {add_subsection_to}, this method allows you to enter
|
132
|
+
# a section after any other item at any level in the outline tree.
|
125
133
|
# Currently the only way to locate the place of entry is with the title for
|
126
134
|
# the item. If your title names are not unique consider using
|
127
|
-
#
|
128
|
-
# The method takes the following arguments:
|
129
|
-
# title: the title of other section or page to insert new section after
|
130
|
-
# block: uses the same DSL syntax as outline#define, for example:
|
135
|
+
# {define}.
|
131
136
|
#
|
137
|
+
# @example
|
132
138
|
# go_to_page 2
|
133
139
|
# start_new_page
|
134
140
|
# text "Inserted Page"
|
@@ -138,6 +144,10 @@ module Prawn
|
|
138
144
|
# end
|
139
145
|
# end
|
140
146
|
#
|
147
|
+
# @param title [String]
|
148
|
+
# The title of other section or page to insert new section after.
|
149
|
+
# @yield Uses the same DSL syntax as {define}.
|
150
|
+
# @return [void]
|
141
151
|
def insert_section_after(title, &block)
|
142
152
|
@prev = items[title]
|
143
153
|
unless @prev
|
@@ -149,67 +159,63 @@ module Prawn
|
|
149
159
|
insert_section(nxt, &block)
|
150
160
|
end
|
151
161
|
|
152
|
-
#
|
153
|
-
# context
|
154
|
-
#
|
155
|
-
# Adds an outine section to the outline tree.
|
156
|
-
# Although you will probably choose to exclusively use outline#define so
|
157
|
-
# that your outline tree is contained and easy to manage, this method gives
|
158
|
-
# you the option to add sections to the outline tree at any point during
|
159
|
-
# document generation. When not being called from within another #section
|
160
|
-
# block the section will be added at the top level after the other root
|
161
|
-
# elements of the outline. For more flexible placement try using
|
162
|
-
# outline#insert_section_after and/or outline#add_subsection_to
|
162
|
+
# Adds an outline section to the outline tree.
|
163
163
|
#
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
# closed - whether the section should show its nested outline
|
172
|
-
# elements.
|
173
|
-
# - defaults to false.
|
174
|
-
# block: more nested subsections and/or page blocks
|
164
|
+
# Although you will probably choose to exclusively use {define} so that your
|
165
|
+
# outline tree is contained and easy to manage, this method gives you the
|
166
|
+
# option to add sections to the outline tree at any point during document
|
167
|
+
# generation. When not being called from within another {section} block the
|
168
|
+
# section will be added at the top level after the other root elements of
|
169
|
+
# the outline. For more flexible placement try using {insert_section_after}
|
170
|
+
# and/or {add_subsection_to}.
|
175
171
|
#
|
176
|
-
# example
|
177
|
-
#
|
178
|
-
#
|
179
|
-
# outline.page :destionation => 3, :title => 'Page 3'
|
172
|
+
# @example
|
173
|
+
# outline.section 'Added Section', destination: 3 do
|
174
|
+
# outline.page destionation: 3, title: 'Page 3'
|
180
175
|
# end
|
176
|
+
#
|
177
|
+
# @param title [String] The outline text that appears for the section.
|
178
|
+
# @param options [Hash{Symbol => any}]
|
179
|
+
# @option options :destination [Integer, Array]
|
180
|
+
# - Optional page number for a destination link to the top of the page
|
181
|
+
# (using a `:FIT` destination).
|
182
|
+
# - An array with a custom destination (see the `#dest_*` methods of the
|
183
|
+
# `PDF::Core::Destination` module).
|
184
|
+
# @option options :closed [Boolean] (false)
|
185
|
+
# Whether the section should show its nested outline elements.
|
186
|
+
# @yield More nested subsections and/or page blocks.
|
187
|
+
# @return [void]
|
181
188
|
def section(title, options = {}, &block)
|
182
189
|
add_outline_item(title, options, &block)
|
183
190
|
end
|
184
191
|
|
185
|
-
# See Outline#define above for more documentation on how it is used in that
|
186
|
-
# context
|
187
|
-
#
|
188
192
|
# Adds a page to the outline.
|
189
|
-
# Although you will probably choose to exclusively use outline#define so
|
190
|
-
# that your outline tree is contained and easy to manage, this method also
|
191
|
-
# gives you the option to add pages to the root of outline tree at any point
|
192
|
-
# during document generation. Note that the page will be added at the top
|
193
|
-
# level after the other root outline elements. For more flexible placement
|
194
|
-
# try using outline#insert_section_after and/or outline#add_subsection_to.
|
195
193
|
#
|
196
|
-
#
|
197
|
-
#
|
198
|
-
#
|
199
|
-
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
203
|
-
#
|
204
|
-
#
|
205
|
-
#
|
206
|
-
# example usage:
|
194
|
+
# Although you will probably choose to exclusively use {define} so that your
|
195
|
+
# outline tree is contained and easy to manage, this method also gives you
|
196
|
+
# the option to add pages to the root of outline tree at any point during
|
197
|
+
# document generation. Note that the page will be added at the top level
|
198
|
+
# after the other root outline elements. For more flexible placement try
|
199
|
+
# using {insert_section_after} and/or {add_subsection_to}.
|
200
|
+
#
|
201
|
+
# @note This method is almost identical to {section} except that it does not
|
202
|
+
# accept a block thereby defining the outline item as a leaf on the
|
203
|
+
# outline tree structure.
|
207
204
|
#
|
208
|
-
#
|
205
|
+
# @example
|
206
|
+
# outline.page title: "Very Last Page"
|
209
207
|
#
|
210
|
-
#
|
211
|
-
#
|
212
|
-
#
|
208
|
+
# @param options [Hash{Symbol => any}]
|
209
|
+
# @option options :title [String] REQUIRED.
|
210
|
+
# The outline text that appears for the page.
|
211
|
+
# @option options :destination [Integer, Array]
|
212
|
+
# - The page number for a destination link to the top of the page (using
|
213
|
+
# a `:FIT` destination).
|
214
|
+
# - An array with a custom destination (see the `#dest_*` methods of the
|
215
|
+
# `PDF::Core::Destination` module).
|
216
|
+
# @option options :closed [Boolean] (false)
|
217
|
+
# Whether the section should show its nested outline elements.
|
218
|
+
# @return [void]
|
213
219
|
def page(options = {})
|
214
220
|
if options[:title]
|
215
221
|
title = options[:title]
|
data/lib/prawn/repeater.rb
CHANGED
@@ -1,19 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# repeater.rb : Implements repeated page elements.
|
4
|
-
# Heavy inspired by repeating_element() in PDF::Wrapper
|
5
|
-
# http://pdf-wrapper.rubyforge.org/
|
6
|
-
#
|
7
|
-
# Copyright November 2009, Gregory Brown. All Rights Reserved.
|
8
|
-
#
|
9
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
10
|
-
|
11
3
|
module Prawn
|
12
|
-
class Document
|
4
|
+
class Document # rubocop: disable Style/Documentation
|
13
5
|
# A list of all repeaters in the document.
|
14
|
-
# See
|
6
|
+
# See {repeat} for details.
|
15
7
|
#
|
16
8
|
# @private
|
9
|
+
# @return [Array]
|
17
10
|
def repeaters
|
18
11
|
@repeaters ||= []
|
19
12
|
end
|
@@ -21,60 +14,66 @@ module Prawn
|
|
21
14
|
# @group Experimental API
|
22
15
|
|
23
16
|
# Provides a way to execute a block of code repeatedly based on
|
24
|
-
# a page_filter
|
17
|
+
# a `page_filter`. Since Stamp is used under the hood, this method is very
|
25
18
|
# space efficient.
|
26
19
|
#
|
27
|
-
# Available page filters are:
|
28
|
-
# :all -- repeats on every page
|
29
|
-
# :odd -- repeats on odd pages
|
30
|
-
# :even -- repeats on even pages
|
31
|
-
# some_array -- repeats on every page listed in the array
|
32
|
-
# some_range -- repeats on every page included in the range
|
33
|
-
# some_lambda -- yields page number and repeats for true return values
|
34
|
-
#
|
35
20
|
# Also accepts an optional second argument for dynamic content which
|
36
21
|
# executes the code in the context of the filtered pages without using
|
37
22
|
# a Stamp.
|
38
23
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
# Prawn::Document.generate("repeat.pdf", :skip_page_creation => true) do
|
42
|
-
#
|
24
|
+
# @example
|
25
|
+
# Prawn::Document.generate("repeat.pdf", skip_page_creation: true) do
|
43
26
|
# repeat :all do
|
44
|
-
# draw_text "ALLLLLL", :
|
27
|
+
# draw_text "ALLLLLL", at: bounds.top_left
|
45
28
|
# end
|
46
29
|
#
|
47
30
|
# repeat :odd do
|
48
|
-
# draw_text "ODD", :
|
31
|
+
# draw_text "ODD", at: [0, 0]
|
49
32
|
# end
|
50
33
|
#
|
51
34
|
# repeat :even do
|
52
|
-
# draw_text "EVEN", :
|
35
|
+
# draw_text "EVEN", at: [0, 0]
|
53
36
|
# end
|
54
37
|
#
|
55
|
-
# repeat [1,2] do
|
56
|
-
# draw_text "[1,2]", :
|
38
|
+
# repeat [1, 2] do
|
39
|
+
# draw_text "[1, 2]", at: [100, 0]
|
57
40
|
# end
|
58
41
|
#
|
59
42
|
# repeat 2..4 do
|
60
|
-
# draw_text "2..4", :
|
43
|
+
# draw_text "2..4", at: [200, 0]
|
61
44
|
# end
|
62
45
|
#
|
63
46
|
# repeat(lambda { |pg| pg % 3 == 0 }) do
|
64
|
-
# draw_text "Every third", :
|
47
|
+
# draw_text "Every third", at: [250, 20]
|
65
48
|
# end
|
66
49
|
#
|
67
50
|
# 10.times do
|
68
51
|
# start_new_page
|
69
|
-
# draw_text "A wonderful page", :
|
52
|
+
# draw_text "A wonderful page", at: [400, 400]
|
70
53
|
# end
|
71
54
|
#
|
72
|
-
# repeat(:all, :
|
73
|
-
# text page_number, :
|
55
|
+
# repeat(:all, dynamic: true) do
|
56
|
+
# text page_number, at: [500, 0]
|
74
57
|
# end
|
75
|
-
#
|
76
58
|
# end
|
77
59
|
#
|
60
|
+
# @param page_filter [:all, :odd, :even, Array<Integer>, Range, Proc]
|
61
|
+
# Pages to draw the repeater content on.
|
62
|
+
#
|
63
|
+
# Available page filters are:
|
64
|
+
#
|
65
|
+
# - `:all` -- repeats on every page.
|
66
|
+
# - `:odd` -- repeats on odd pages.
|
67
|
+
# - `:even` -- repeats on even pages.
|
68
|
+
# - Array of Integers -- repeats on every page listed in the array.
|
69
|
+
# - Range -- repeats on every page included in the range.
|
70
|
+
# - Proc -- yields page number and repeats for true return values.
|
71
|
+
# @param options [Hash]
|
72
|
+
# @option options :dynamic [Boolean] (false)
|
73
|
+
# A dynamic repeater executes block on every matched page. A static
|
74
|
+
# repeater uses {stamp} to prepare the content (runs the block once) and
|
75
|
+
# puts it on every matched page.
|
76
|
+
# @return [void]
|
78
77
|
def repeat(page_filter, options = {}, &block)
|
79
78
|
dynamic = options.fetch(:dynamic, false)
|
80
79
|
repeaters << Prawn::Repeater.new(
|
@@ -83,10 +82,19 @@ module Prawn
|
|
83
82
|
end
|
84
83
|
end
|
85
84
|
|
86
|
-
|
85
|
+
# Repeater object.
|
86
|
+
#
|
87
|
+
# @private
|
88
|
+
class Repeater
|
87
89
|
class << self
|
88
90
|
attr_writer :count
|
89
91
|
|
92
|
+
# Repeater counter.
|
93
|
+
#
|
94
|
+
# It's not an exact number of repeaters but a counter used to generate
|
95
|
+
# unique repeater stamp names.
|
96
|
+
#
|
97
|
+
# @return [Integer]
|
90
98
|
def count
|
91
99
|
@count ||= 0
|
92
100
|
end
|
@@ -106,10 +114,18 @@ module Prawn
|
|
106
114
|
Repeater.count += 1
|
107
115
|
end
|
108
116
|
|
117
|
+
# Should this repeater run on this page?
|
118
|
+
#
|
119
|
+
# @param page_number [Integer]
|
120
|
+
# @return [Boolean]
|
109
121
|
def match?(page_number)
|
110
122
|
@document.page_match?(@page_filter, page_number)
|
111
123
|
end
|
112
124
|
|
125
|
+
# Run repeater.
|
126
|
+
#
|
127
|
+
# @param page_number [Integer]
|
128
|
+
# @return [void]
|
113
129
|
def run(page_number)
|
114
130
|
if !@dynamic
|
115
131
|
@document.stamp(@stamp_name) if match?(page_number)
|
@@ -6,10 +6,6 @@
|
|
6
6
|
#
|
7
7
|
# "RC4" is a trademark of RSA Data Security, Inc.
|
8
8
|
#
|
9
|
-
# Copyright August 2009, Brad Ediger. All Rights Reserved.
|
10
|
-
#
|
11
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
12
|
-
|
13
9
|
# @private
|
14
10
|
class Arcfour
|
15
11
|
def initialize(key)
|
@@ -38,6 +34,10 @@ class Arcfour
|
|
38
34
|
@i = @j = 0
|
39
35
|
end
|
40
36
|
|
37
|
+
# Encrypt string.
|
38
|
+
#
|
39
|
+
# @param string [String]
|
40
|
+
# @return [String]
|
41
41
|
def encrypt(string)
|
42
42
|
string.unpack('c*').map { |byte| byte ^ key_byte }.pack('c*')
|
43
43
|
end
|