prawn 2.2.2 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/GPLv2 +20 -21
- data/Gemfile +2 -0
- data/Rakefile +4 -26
- data/lib/prawn.rb +10 -3
- data/lib/prawn/document.rb +60 -33
- data/lib/prawn/document/bounding_box.rb +19 -6
- data/lib/prawn/document/column_box.rb +2 -0
- data/lib/prawn/document/internals.rb +6 -4
- data/lib/prawn/document/span.rb +4 -1
- data/lib/prawn/encoding.rb +4 -1
- data/lib/prawn/errors.rb +2 -0
- data/lib/prawn/font.rb +37 -18
- data/lib/prawn/font_metric_cache.rb +15 -9
- data/lib/prawn/{font → fonts}/afm.rb +32 -23
- data/lib/prawn/{font → fonts}/dfont.rb +3 -1
- data/lib/prawn/fonts/otf.rb +11 -0
- data/lib/prawn/{font → fonts}/ttc.rb +3 -1
- data/lib/prawn/{font → fonts}/ttf.rb +73 -36
- data/lib/prawn/graphics.rb +31 -33
- data/lib/prawn/graphics/blend_mode.rb +2 -0
- data/lib/prawn/graphics/cap_style.rb +2 -0
- data/lib/prawn/graphics/color.rb +26 -19
- data/lib/prawn/graphics/dash.rb +3 -1
- data/lib/prawn/graphics/join_style.rb +3 -1
- data/lib/prawn/graphics/patterns.rb +63 -50
- data/lib/prawn/graphics/transformation.rb +7 -3
- data/lib/prawn/graphics/transparency.rb +2 -0
- data/lib/prawn/grid.rb +75 -39
- data/lib/prawn/image_handler.rb +2 -0
- data/lib/prawn/images.rb +42 -38
- data/lib/prawn/images/image.rb +2 -0
- data/lib/prawn/images/jpg.rb +6 -1
- data/lib/prawn/images/png.rb +11 -10
- data/lib/prawn/measurement_extensions.rb +2 -0
- data/lib/prawn/measurements.rb +5 -0
- data/lib/prawn/outline.rb +8 -5
- data/lib/prawn/repeater.rb +3 -1
- data/lib/prawn/security.rb +49 -44
- data/lib/prawn/security/arcfour.rb +2 -0
- data/lib/prawn/soft_mask.rb +3 -1
- data/lib/prawn/stamp.rb +4 -1
- data/lib/prawn/text.rb +32 -30
- data/lib/prawn/text/box.rb +13 -10
- data/lib/prawn/text/formatted.rb +2 -0
- data/lib/prawn/text/formatted/arranger.rb +50 -31
- data/lib/prawn/text/formatted/box.rb +43 -28
- data/lib/prawn/text/formatted/fragment.rb +2 -0
- data/lib/prawn/text/formatted/line_wrap.rb +23 -19
- data/lib/prawn/text/formatted/parser.rb +36 -36
- data/lib/prawn/text/formatted/wrap.rb +19 -13
- data/lib/prawn/transformation_stack.rb +5 -2
- data/lib/prawn/utilities.rb +2 -2
- data/lib/prawn/version.rb +3 -1
- data/lib/prawn/view.rb +15 -7
- data/manual/basic_concepts/adding_pages.rb +2 -0
- data/manual/basic_concepts/basic_concepts.rb +4 -2
- data/manual/basic_concepts/creation.rb +2 -0
- data/manual/basic_concepts/cursor.rb +2 -0
- data/manual/basic_concepts/measurement.rb +4 -2
- data/manual/basic_concepts/origin.rb +2 -0
- data/manual/basic_concepts/other_cursor_helpers.rb +2 -0
- data/manual/basic_concepts/view.rb +2 -0
- data/manual/bounding_box/bounding_box.rb +4 -2
- data/manual/bounding_box/bounds.rb +6 -4
- data/manual/bounding_box/canvas.rb +5 -3
- data/manual/bounding_box/creation.rb +2 -0
- data/manual/bounding_box/indentation.rb +2 -0
- data/manual/bounding_box/nesting.rb +3 -1
- data/manual/bounding_box/russian_boxes.rb +6 -4
- data/manual/bounding_box/stretchy.rb +2 -0
- data/manual/contents.rb +2 -0
- data/manual/cover.rb +10 -7
- data/manual/document_and_page_options/background.rb +8 -2
- data/manual/document_and_page_options/document_and_page_options.rb +7 -5
- data/manual/document_and_page_options/metadata.rb +2 -0
- data/manual/document_and_page_options/page_margins.rb +2 -0
- data/manual/document_and_page_options/page_size.rb +2 -0
- data/manual/document_and_page_options/print_scaling.rb +4 -1
- data/manual/example_helper.rb +5 -2
- data/manual/graphics/blend_mode.rb +6 -4
- data/manual/graphics/circle_and_ellipse.rb +2 -0
- data/manual/graphics/color.rb +2 -0
- data/manual/graphics/common_lines.rb +3 -1
- data/manual/graphics/fill_and_stroke.rb +3 -1
- data/manual/graphics/fill_rules.rb +6 -3
- data/manual/graphics/gradients.rb +2 -0
- data/manual/graphics/graphics.rb +4 -2
- data/manual/graphics/helper.rb +13 -4
- data/manual/graphics/line_width.rb +3 -0
- data/manual/graphics/lines_and_curves.rb +3 -1
- data/manual/graphics/polygon.rb +2 -0
- data/manual/graphics/rectangle.rb +2 -0
- data/manual/graphics/rotate.rb +2 -0
- data/manual/graphics/scale.rb +2 -0
- data/manual/graphics/soft_masks.rb +2 -0
- data/manual/graphics/stroke_cap.rb +3 -1
- data/manual/graphics/stroke_dash.rb +7 -5
- data/manual/graphics/stroke_join.rb +3 -1
- data/manual/graphics/translate.rb +4 -1
- data/manual/graphics/transparency.rb +2 -0
- data/manual/how_to_read_this_manual.rb +2 -0
- data/manual/images/absolute_position.rb +2 -0
- data/manual/images/fit.rb +2 -0
- data/manual/images/horizontal.rb +5 -3
- data/manual/images/images.rb +4 -2
- data/manual/images/plain_image.rb +2 -0
- data/manual/images/scale.rb +5 -3
- data/manual/images/vertical.rb +9 -4
- data/manual/images/width_and_height.rb +5 -3
- data/manual/layout/boxes.rb +2 -0
- data/manual/layout/content.rb +4 -2
- data/manual/layout/layout.rb +4 -2
- data/manual/layout/simple_grid.rb +2 -0
- data/manual/outline/add_subsection_to.rb +2 -0
- data/manual/outline/insert_section_after.rb +2 -0
- data/manual/outline/outline.rb +5 -3
- data/manual/outline/sections_and_pages.rb +2 -0
- data/manual/repeatable_content/alternate_page_numbering.rb +2 -0
- data/manual/repeatable_content/page_numbering.rb +2 -0
- data/manual/repeatable_content/repeatable_content.rb +4 -2
- data/manual/repeatable_content/repeater.rb +2 -0
- data/manual/repeatable_content/stamp.rb +2 -0
- data/manual/security/encryption.rb +2 -0
- data/manual/security/permissions.rb +6 -2
- data/manual/security/security.rb +5 -3
- data/manual/table.rb +2 -0
- data/manual/text/alignment.rb +4 -2
- data/manual/text/color.rb +2 -0
- data/manual/text/column_box.rb +5 -3
- data/manual/text/fallback_fonts.rb +4 -2
- data/manual/text/font.rb +2 -0
- data/manual/text/font_size.rb +2 -0
- data/manual/text/font_style.rb +7 -2
- data/manual/text/formatted_callbacks.rb +19 -12
- data/manual/text/formatted_text.rb +10 -5
- data/manual/text/free_flowing_text.rb +5 -3
- data/manual/text/inline.rb +2 -0
- data/manual/text/kerning_and_character_spacing.rb +6 -4
- data/manual/text/leading.rb +2 -0
- data/manual/text/line_wrapping.rb +4 -1
- data/manual/text/paragraph_indentation.rb +6 -5
- data/manual/text/positioned_text.rb +2 -0
- data/manual/text/registering_families.rb +4 -2
- data/manual/text/rendering_and_color.rb +3 -1
- data/manual/text/right_to_left_text.rb +8 -6
- data/manual/text/rotation.rb +11 -4
- data/manual/text/single_usage.rb +2 -0
- data/manual/text/text.rb +4 -3
- data/manual/text/text_box_excess.rb +2 -0
- data/manual/text/text_box_extensions.rb +3 -1
- data/manual/text/text_box_overflow.rb +14 -10
- data/manual/text/utf8.rb +3 -1
- data/manual/text/win_ansi_charset.rb +15 -12
- data/prawn.gemspec +9 -12
- data/spec/extensions/encoding_helpers.rb +4 -2
- data/spec/prawn/document/bounding_box_spec.rb +90 -86
- data/spec/prawn/document/column_box_spec.rb +2 -0
- data/spec/prawn/document/security_spec.rb +12 -9
- data/spec/prawn/document_annotations_spec.rb +2 -0
- data/spec/prawn/document_destinations_spec.rb +2 -0
- data/spec/prawn/document_grid_spec.rb +3 -0
- data/spec/prawn/document_reference_spec.rb +2 -0
- data/spec/prawn/document_span_spec.rb +16 -6
- data/spec/prawn/document_spec.rb +87 -39
- data/spec/prawn/font_metric_cache_spec.rb +2 -0
- data/spec/prawn/font_spec.rb +60 -29
- data/spec/prawn/graphics/blend_mode_spec.rb +4 -2
- data/spec/prawn/graphics/transparency_spec.rb +2 -0
- data/spec/prawn/graphics_spec.rb +117 -62
- data/spec/prawn/graphics_stroke_styles_spec.rb +2 -0
- data/spec/prawn/image_handler_spec.rb +2 -0
- data/spec/prawn/images/jpg_spec.rb +2 -0
- data/spec/prawn/images/png_spec.rb +2 -0
- data/spec/prawn/images_spec.rb +66 -7
- data/spec/prawn/measurements_extensions_spec.rb +2 -0
- data/spec/prawn/outline_spec.rb +133 -29
- data/spec/prawn/repeater_spec.rb +15 -12
- data/spec/prawn/soft_mask_spec.rb +3 -1
- data/spec/prawn/stamp_spec.rb +12 -7
- data/spec/prawn/text/box_spec.rb +82 -85
- data/spec/prawn/text/formatted/arranger_spec.rb +40 -38
- data/spec/prawn/text/formatted/box_spec.rb +86 -62
- data/spec/prawn/text/formatted/fragment_spec.rb +10 -8
- data/spec/prawn/text/formatted/line_wrap_spec.rb +10 -6
- data/spec/prawn/text/formatted/parser_spec.rb +32 -2
- data/spec/prawn/text_draw_text_spec.rb +13 -10
- data/spec/prawn/text_rendering_mode_spec.rb +7 -1
- data/spec/prawn/text_spacing_spec.rb +8 -6
- data/spec/prawn/text_spec.rb +18 -16
- data/spec/prawn/text_with_inline_formatting_spec.rb +4 -2
- data/spec/prawn/transformation_stack_spec.rb +2 -0
- data/spec/prawn/view_spec.rb +18 -0
- data/spec/{manual_spec.rb → prawn_manual_spec.rb} +6 -4
- data/spec/spec_helper.rb +9 -10
- metadata +46 -117
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d64c2da1e4be48e40f4fa6fa4de35e04c75debf0119e8c59b3fba9d944c112db
|
4
|
+
data.tar.gz: 393bbdd1a5df657d5c6190d4bd10ecd7353522e714b2f60c8d9c5f70e5bc1ce9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4980639ca24796d577be790ed0f6fa85c985f1a6eb147e4c5db1df261c5d50afe8a466f06b65588b71a897e22e8d2b7b01daceed1714f6164124057154d2d28
|
7
|
+
data.tar.gz: e0fd560d4a80f2827736d599266bcb2e2fe19abedcde639520fba8bd19a2f12fe2cf0e8a60a91b87dbac4336d25c680f94b2341e5f9ce3d6d24f2e65f24e24a3
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/GPLv2
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
GNU GENERAL PUBLIC LICENSE
|
2
|
+
Version 2, June 1991
|
3
3
|
|
4
|
-
Copyright (C) 1989, 1991 Free Software Foundation, Inc
|
5
|
-
|
4
|
+
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
5
|
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
6
6
|
Everyone is permitted to copy and distribute verbatim copies
|
7
7
|
of this license document, but changing it is not allowed.
|
8
8
|
|
9
|
-
|
9
|
+
Preamble
|
10
10
|
|
11
11
|
The licenses for most software are designed to take away your
|
12
12
|
freedom to share and change it. By contrast, the GNU General Public
|
@@ -15,7 +15,7 @@ software--to make sure the software is free for all its users. This
|
|
15
15
|
General Public License applies to most of the Free Software
|
16
16
|
Foundation's software and to any other program whose authors commit to
|
17
17
|
using it. (Some other Free Software Foundation software is covered by
|
18
|
-
the GNU
|
18
|
+
the GNU Lesser General Public License instead.) You can apply it to
|
19
19
|
your programs, too.
|
20
20
|
|
21
21
|
When we speak of free software, we are referring to freedom, not
|
@@ -55,8 +55,8 @@ patent must be licensed for everyone's free use or not licensed at all.
|
|
55
55
|
|
56
56
|
The precise terms and conditions for copying, distribution and
|
57
57
|
modification follow.
|
58
|
-
|
59
|
-
|
58
|
+
|
59
|
+
GNU GENERAL PUBLIC LICENSE
|
60
60
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
61
61
|
|
62
62
|
0. This License applies to any program or other work which contains
|
@@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions:
|
|
110
110
|
License. (Exception: if the Program itself is interactive but
|
111
111
|
does not normally print such an announcement, your work based on
|
112
112
|
the Program is not required to print an announcement.)
|
113
|
-
|
113
|
+
|
114
114
|
These requirements apply to the modified work as a whole. If
|
115
115
|
identifiable sections of that work are not derived from the Program,
|
116
116
|
and can be reasonably considered independent and separate works in
|
@@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent
|
|
168
168
|
access to copy the source code from the same place counts as
|
169
169
|
distribution of the source code, even though third parties are not
|
170
170
|
compelled to copy the source along with the object code.
|
171
|
-
|
171
|
+
|
172
172
|
4. You may not copy, modify, sublicense, or distribute the Program
|
173
173
|
except as expressly provided under this License. Any attempt
|
174
174
|
otherwise to copy, modify, sublicense or distribute the Program is
|
@@ -225,7 +225,7 @@ impose that choice.
|
|
225
225
|
|
226
226
|
This section is intended to make thoroughly clear what is believed to
|
227
227
|
be a consequence of the rest of this License.
|
228
|
-
|
228
|
+
|
229
229
|
8. If the distribution and/or use of the Program is restricted in
|
230
230
|
certain countries either by patents or by copyrighted interfaces, the
|
231
231
|
original copyright holder who places the Program under this License
|
@@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals
|
|
255
255
|
of preserving the free status of all derivatives of our free software and
|
256
256
|
of promoting the sharing and reuse of software generally.
|
257
257
|
|
258
|
-
|
258
|
+
NO WARRANTY
|
259
259
|
|
260
260
|
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
261
261
|
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
@@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
|
277
277
|
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
278
278
|
POSSIBILITY OF SUCH DAMAGES.
|
279
279
|
|
280
|
-
|
281
|
-
|
282
|
-
|
280
|
+
END OF TERMS AND CONDITIONS
|
281
|
+
|
282
|
+
How to Apply These Terms to Your New Programs
|
283
283
|
|
284
284
|
If you develop a new program, and you want it to be of the greatest
|
285
285
|
possible use to the public, the best way to achieve this is to make it
|
@@ -303,17 +303,16 @@ the "copyright" line and a pointer to where the full notice is found.
|
|
303
303
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
304
304
|
GNU General Public License for more details.
|
305
305
|
|
306
|
-
You should have received a copy of the GNU General Public License
|
307
|
-
|
308
|
-
|
309
|
-
|
306
|
+
You should have received a copy of the GNU General Public License along
|
307
|
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
308
|
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
310
309
|
|
311
310
|
Also add information on how to contact you by electronic and paper mail.
|
312
311
|
|
313
312
|
If the program is interactive, make it output a short notice like this
|
314
313
|
when it starts in an interactive mode:
|
315
314
|
|
316
|
-
Gnomovision version 69, Copyright (C) year
|
315
|
+
Gnomovision version 69, Copyright (C) year name of author
|
317
316
|
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
318
317
|
This is free software, and you are welcome to redistribute it
|
319
318
|
under certain conditions; type `show c' for details.
|
@@ -336,5 +335,5 @@ necessary. Here is a sample; alter the names:
|
|
336
335
|
This General Public License does not permit incorporating your program into
|
337
336
|
proprietary programs. If your program is a subroutine library, you may
|
338
337
|
consider it more useful to permit linking proprietary applications with the
|
339
|
-
library. If this is what you want to do, use the GNU
|
338
|
+
library. If this is what you want to do, use the GNU Lesser General
|
340
339
|
Public License instead of this License.
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,23 +1,9 @@
|
|
1
|
-
|
2
|
-
Bundler.setup
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
require '
|
6
|
-
require 'yard'
|
7
|
-
require 'rubygems/package_task'
|
8
|
-
require 'rubocop/rake_task'
|
3
|
+
GEMSPEC = File.expand_path('prawn.gemspec', __dir__)
|
4
|
+
require 'prawn/dev/tasks'
|
9
5
|
|
10
|
-
task default: [
|
11
|
-
|
12
|
-
desc 'Run all rspec files'
|
13
|
-
RSpec::Core::RakeTask.new('spec') do |c|
|
14
|
-
c.rspec_opts = '-t ~unresolved'
|
15
|
-
end
|
16
|
-
|
17
|
-
YARD::Rake::YardocTask.new do |t|
|
18
|
-
t.options = ['--output-dir', 'doc/html']
|
19
|
-
end
|
20
|
-
task docs: :yard
|
6
|
+
task default: %i[spec rubocop]
|
21
7
|
|
22
8
|
desc "Generate the 'Prawn by Example' manual"
|
23
9
|
task :manual do
|
@@ -27,12 +13,6 @@ task :manual do
|
|
27
13
|
puts 'The Prawn manual is available at manual.pdf. Happy Prawning!'
|
28
14
|
end
|
29
15
|
|
30
|
-
spec = Gem::Specification.load 'prawn.gemspec'
|
31
|
-
Gem::PackageTask.new(spec) do |pkg|
|
32
|
-
pkg.need_zip = true
|
33
|
-
pkg.need_tar = true
|
34
|
-
end
|
35
|
-
|
36
16
|
desc 'Run a console with Prawn loaded'
|
37
17
|
task :console do
|
38
18
|
require 'irb'
|
@@ -43,5 +23,3 @@ task :console do
|
|
43
23
|
ARGV.clear
|
44
24
|
IRB.start
|
45
25
|
end
|
46
|
-
|
47
|
-
RuboCop::RakeTask.new
|
data/lib/prawn.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Welcome to Prawn, the best PDF Generation library ever.
|
2
4
|
# This documentation covers user level functionality.
|
3
5
|
#
|
@@ -28,11 +30,17 @@ module Prawn
|
|
28
30
|
# Detected unknown option(s): [:tomato]
|
29
31
|
# Accepted options are: [:page_size, :page_layout, :left_margin, ...]
|
30
32
|
#
|
31
|
-
|
33
|
+
# @private
|
34
|
+
attr_accessor :debug
|
35
|
+
|
32
36
|
module_function :debug, :debug=
|
33
37
|
|
34
|
-
|
38
|
+
module_function
|
39
|
+
|
40
|
+
# @private
|
41
|
+
def verify_options(accepted, actual)
|
35
42
|
return unless debug || $DEBUG
|
43
|
+
|
36
44
|
unless (act = Set[*actual.keys]).subset?(acc = Set[*accepted])
|
37
45
|
raise Prawn::Errors::UnknownOption,
|
38
46
|
"\nDetected unknown option(s): #{(act - acc).to_a.inspect}\n" \
|
@@ -40,7 +48,6 @@ module Prawn
|
|
40
48
|
end
|
41
49
|
yield if block_given?
|
42
50
|
end
|
43
|
-
module_function :verify_options
|
44
51
|
end
|
45
52
|
|
46
53
|
require_relative 'prawn/version'
|
data/lib/prawn/document.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# document.rb : Implements PDF document generation for Prawn
|
2
4
|
#
|
3
5
|
# Copyright April 2008, Gregory Brown. All Rights Reserved.
|
@@ -62,11 +64,11 @@ module Prawn
|
|
62
64
|
# NOTE: We probably need to rethink the options validation system, but this
|
63
65
|
# constant temporarily allows for extensions to modify the list.
|
64
66
|
|
65
|
-
VALID_OPTIONS = [
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
VALID_OPTIONS = %i[
|
68
|
+
page_size page_layout margin left_margin
|
69
|
+
right_margin top_margin bottom_margin skip_page_creation
|
70
|
+
compress background info
|
71
|
+
text_formatter print_scaling
|
70
72
|
].freeze
|
71
73
|
|
72
74
|
# Any module added to this array will be included into instances of
|
@@ -96,6 +98,7 @@ module Prawn
|
|
96
98
|
|
97
99
|
# @private
|
98
100
|
def self.inherited(base)
|
101
|
+
super
|
99
102
|
extensions.each { |e| base.extensions << e }
|
100
103
|
end
|
101
104
|
|
@@ -269,7 +272,7 @@ module Prawn
|
|
269
272
|
|
270
273
|
# erase the color space so that it gets reset on new page for fussy
|
271
274
|
# pdf-readers
|
272
|
-
new_graphic_state
|
275
|
+
new_graphic_state&.color_space = {}
|
273
276
|
|
274
277
|
page_options[:graphic_state] = new_graphic_state
|
275
278
|
end
|
@@ -304,6 +307,26 @@ module Prawn
|
|
304
307
|
end
|
305
308
|
end
|
306
309
|
|
310
|
+
# Remove page of the document by index
|
311
|
+
#
|
312
|
+
# pdf = Prawn::Document.new
|
313
|
+
# pdf.page_count #=> 1
|
314
|
+
# 3.times { pdf.start_new_page }
|
315
|
+
# pdf.page_count #=> 4
|
316
|
+
# pdf.delete_page(-1)
|
317
|
+
# pdf.page_count #=> 3
|
318
|
+
#
|
319
|
+
def delete_page(index)
|
320
|
+
return false if index.abs > (state.pages.count - 1)
|
321
|
+
|
322
|
+
state.pages.delete_at(index)
|
323
|
+
|
324
|
+
state.store.pages.data[:Kids].delete_at(index)
|
325
|
+
state.store.pages.data[:Count] -= 1
|
326
|
+
@page_number -= 1
|
327
|
+
true
|
328
|
+
end
|
329
|
+
|
307
330
|
# Returns the number of pages in the document
|
308
331
|
#
|
309
332
|
# pdf = Prawn::Document.new
|
@@ -320,9 +343,9 @@ module Prawn
|
|
320
343
|
#
|
321
344
|
# See Prawn::Document#number_pages for a sample usage of this capability.
|
322
345
|
#
|
323
|
-
def go_to_page(
|
324
|
-
@page_number =
|
325
|
-
state.page = state.pages[
|
346
|
+
def go_to_page(page_number)
|
347
|
+
@page_number = page_number
|
348
|
+
state.page = state.pages[page_number - 1]
|
326
349
|
generate_margin_box
|
327
350
|
@y = @bounding_box.absolute_top
|
328
351
|
end
|
@@ -369,13 +392,13 @@ module Prawn
|
|
369
392
|
# Renders the PDF document to string.
|
370
393
|
# Pass an open file descriptor to render to file.
|
371
394
|
#
|
372
|
-
def render(*
|
395
|
+
def render(*arguments, &block)
|
373
396
|
(1..page_count).each do |i|
|
374
397
|
go_to_page i
|
375
398
|
repeaters.each { |r| r.run(i) }
|
376
399
|
end
|
377
400
|
|
378
|
-
renderer.render(*
|
401
|
+
renderer.render(*arguments, &block)
|
379
402
|
end
|
380
403
|
|
381
404
|
# Renders the PDF document to file.
|
@@ -437,15 +460,15 @@ module Prawn
|
|
437
460
|
# Moves up the document by n points relative to the current position inside
|
438
461
|
# the current bounding box.
|
439
462
|
#
|
440
|
-
def move_up(
|
441
|
-
self.y +=
|
463
|
+
def move_up(amount)
|
464
|
+
self.y += amount
|
442
465
|
end
|
443
466
|
|
444
467
|
# Moves down the document by n points relative to the current position
|
445
468
|
# inside the current bounding box.
|
446
469
|
#
|
447
|
-
def move_down(
|
448
|
-
self.y -=
|
470
|
+
def move_down(amount)
|
471
|
+
self.y -= amount
|
449
472
|
end
|
450
473
|
|
451
474
|
# Moves down the document and then executes a block.
|
@@ -548,11 +571,12 @@ module Prawn
|
|
548
571
|
opts = options.dup
|
549
572
|
start_count_at = opts.delete(:start_count_at).to_i
|
550
573
|
|
551
|
-
page_filter =
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
574
|
+
page_filter =
|
575
|
+
if opts.key?(:page_filter)
|
576
|
+
opts.delete(:page_filter)
|
577
|
+
else
|
578
|
+
:all
|
579
|
+
end
|
556
580
|
|
557
581
|
total_pages = opts.delete(:total_pages)
|
558
582
|
txtcolor = opts.delete(:color)
|
@@ -563,12 +587,13 @@ module Prawn
|
|
563
587
|
pseudopage = 0
|
564
588
|
(1..page_count).each do |p|
|
565
589
|
unless start_count
|
566
|
-
pseudopage =
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
590
|
+
pseudopage =
|
591
|
+
case start_count_at
|
592
|
+
when 0
|
593
|
+
1
|
594
|
+
else
|
595
|
+
start_count_at.to_i
|
596
|
+
end
|
572
597
|
end
|
573
598
|
if page_match?(page_filter, p)
|
574
599
|
go_to_page(p)
|
@@ -597,7 +622,7 @@ module Prawn
|
|
597
622
|
# the current page or column.
|
598
623
|
#
|
599
624
|
# @private
|
600
|
-
def group(*
|
625
|
+
def group(*_arguments)
|
601
626
|
raise NotImplementedError,
|
602
627
|
'Document#group has been disabled because its implementation ' \
|
603
628
|
'lead to corrupted documents whenever a page boundary was ' \
|
@@ -646,9 +671,9 @@ module Prawn
|
|
646
671
|
# and then restores the original values after the block has executed.
|
647
672
|
# -- I will remove the nodoc if/when this feature is a little less hacky
|
648
673
|
stored = {}
|
649
|
-
fields.each { |f| stored[f] =
|
674
|
+
fields.each { |f| stored[f] = public_send(f) }
|
650
675
|
yield
|
651
|
-
fields.each { |f|
|
676
|
+
fields.each { |f| public_send("#{f}=", stored[f]) }
|
652
677
|
end
|
653
678
|
|
654
679
|
# @group Extension API
|
@@ -706,17 +731,19 @@ module Prawn
|
|
706
731
|
|
707
732
|
# we must update bounding box if not flowing from the previous page
|
708
733
|
#
|
709
|
-
@bounding_box = @margin_box unless @bounding_box
|
734
|
+
@bounding_box = @margin_box unless @bounding_box&.parent
|
710
735
|
end
|
711
736
|
|
712
737
|
def apply_margin_options(options)
|
713
|
-
sides = [
|
738
|
+
sides = %i[top right bottom left]
|
714
739
|
margin = Array(options[:margin])
|
715
740
|
|
716
741
|
# Treat :margin as CSS shorthand with 1-4 values.
|
717
742
|
positions = {
|
718
|
-
4 => [0, 1, 2, 3],
|
719
|
-
|
743
|
+
4 => [0, 1, 2, 3],
|
744
|
+
3 => [0, 1, 2, 1],
|
745
|
+
2 => [0, 1, 0, 1],
|
746
|
+
1 => [0, 0, 0, 0],
|
720
747
|
0 => []
|
721
748
|
}[margin.length]
|
722
749
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# bounding_box.rb : Implements a mechanism for shifting the coordinate space
|
2
4
|
#
|
3
5
|
# Copyright May 2008, Gregory Brown. All Rights Reserved.
|
@@ -153,10 +155,10 @@ module Prawn
|
|
153
155
|
# Of course, if you use canvas, you will be responsible for ensuring that
|
154
156
|
# you remain within the printable area of your document.
|
155
157
|
#
|
156
|
-
def bounding_box(
|
158
|
+
def bounding_box(point, *args, &block)
|
157
159
|
init_bounding_box(block) do |parent_box|
|
158
|
-
|
159
|
-
@bounding_box = BoundingBox.new(self, parent_box,
|
160
|
+
point = map_to_absolute(point)
|
161
|
+
@bounding_box = BoundingBox.new(self, parent_box, point, *args)
|
160
162
|
end
|
161
163
|
end
|
162
164
|
|
@@ -171,7 +173,9 @@ module Prawn
|
|
171
173
|
init_bounding_box(block, hold_position: true) do |_|
|
172
174
|
# Canvas bbox acts like margin_box in that its parent bounds are unset.
|
173
175
|
@bounding_box = BoundingBox.new(
|
174
|
-
self,
|
176
|
+
self,
|
177
|
+
nil,
|
178
|
+
[0, page.dimensions[3]],
|
175
179
|
width: page.dimensions[2],
|
176
180
|
height: page.dimensions[3]
|
177
181
|
)
|
@@ -219,7 +223,14 @@ module Prawn
|
|
219
223
|
# is used for.
|
220
224
|
#
|
221
225
|
class BoundingBox
|
222
|
-
|
226
|
+
class NoReferenceBounds < StandardError
|
227
|
+
def initialize(message = "Can't find reference bounds: my parent is unset")
|
228
|
+
super
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
# @private
|
233
|
+
def initialize(document, parent, point, options = {})
|
223
234
|
unless options[:width]
|
224
235
|
raise ArgumentError, 'BoundingBox needs the :width option to be set'
|
225
236
|
end
|
@@ -457,6 +468,7 @@ module Prawn
|
|
457
468
|
#
|
458
469
|
def height
|
459
470
|
return @height if @height
|
471
|
+
|
460
472
|
@stretched_height = [
|
461
473
|
(absolute_top - @document.y),
|
462
474
|
@stretched_height.to_f
|
@@ -500,7 +512,8 @@ module Prawn
|
|
500
512
|
#
|
501
513
|
def reference_bounds
|
502
514
|
if stretchy?
|
503
|
-
raise
|
515
|
+
raise NoReferenceBounds unless @parent
|
516
|
+
|
504
517
|
@parent.reference_bounds
|
505
518
|
else
|
506
519
|
self
|