prawn 2.0.2 → 2.3.0
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.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/GPLv2 +20 -21
- data/Gemfile +3 -9
- data/Rakefile +20 -23
- data/lib/prawn.rb +37 -49
- data/lib/prawn/document.rb +181 -133
- data/lib/prawn/document/bounding_box.rb +41 -29
- data/lib/prawn/document/column_box.rb +7 -7
- data/lib/prawn/document/internals.rb +18 -8
- data/lib/prawn/document/span.rb +21 -16
- data/lib/prawn/encoding.rb +69 -68
- data/lib/prawn/errors.rb +12 -7
- data/lib/prawn/font.rb +115 -69
- data/lib/prawn/font_metric_cache.rb +14 -8
- data/lib/prawn/{font → fonts}/afm.rb +102 -68
- data/lib/prawn/{font → fonts}/dfont.rb +5 -11
- data/lib/prawn/fonts/otf.rb +11 -0
- data/lib/prawn/fonts/ttc.rb +36 -0
- data/lib/prawn/{font → fonts}/ttf.rb +87 -68
- data/lib/prawn/graphics.rb +120 -80
- data/lib/prawn/graphics/blend_mode.rb +65 -0
- data/lib/prawn/graphics/cap_style.rb +3 -3
- data/lib/prawn/graphics/color.rb +27 -25
- data/lib/prawn/graphics/dash.rb +23 -11
- data/lib/prawn/graphics/join_style.rb +9 -3
- data/lib/prawn/graphics/patterns.rb +197 -67
- data/lib/prawn/graphics/transformation.rb +17 -8
- data/lib/prawn/graphics/transparency.rb +17 -13
- data/lib/prawn/grid.rb +48 -47
- data/lib/prawn/image_handler.rb +5 -5
- data/lib/prawn/images.rb +39 -30
- data/lib/prawn/images/image.rb +2 -1
- data/lib/prawn/images/jpg.rb +28 -22
- data/lib/prawn/images/png.rb +107 -66
- data/lib/prawn/measurement_extensions.rb +10 -9
- data/lib/prawn/measurements.rb +19 -15
- data/lib/prawn/outline.rb +97 -77
- data/lib/prawn/repeater.rb +14 -10
- data/lib/prawn/security.rb +81 -61
- data/lib/prawn/security/arcfour.rb +2 -2
- data/lib/prawn/soft_mask.rb +26 -26
- data/lib/prawn/stamp.rb +20 -13
- data/lib/prawn/text.rb +68 -52
- data/lib/prawn/text/box.rb +11 -8
- data/lib/prawn/text/formatted.rb +5 -5
- data/lib/prawn/text/formatted/arranger.rb +78 -49
- data/lib/prawn/text/formatted/box.rb +134 -100
- data/lib/prawn/text/formatted/fragment.rb +11 -14
- data/lib/prawn/text/formatted/line_wrap.rb +121 -63
- data/lib/prawn/text/formatted/parser.rb +139 -117
- data/lib/prawn/text/formatted/wrap.rb +43 -31
- data/lib/prawn/transformation_stack.rb +44 -0
- data/lib/prawn/utilities.rb +7 -22
- data/lib/prawn/version.rb +2 -2
- data/lib/prawn/view.rb +17 -7
- data/manual/basic_concepts/adding_pages.rb +6 -7
- data/manual/basic_concepts/basic_concepts.rb +31 -22
- data/manual/basic_concepts/creation.rb +10 -11
- data/manual/basic_concepts/cursor.rb +4 -5
- data/manual/basic_concepts/measurement.rb +6 -7
- data/manual/basic_concepts/origin.rb +5 -6
- data/manual/basic_concepts/other_cursor_helpers.rb +11 -12
- data/manual/basic_concepts/view.rb +22 -16
- data/manual/bounding_box/bounding_box.rb +29 -24
- data/manual/bounding_box/bounds.rb +11 -12
- data/manual/bounding_box/canvas.rb +4 -5
- data/manual/bounding_box/creation.rb +6 -7
- data/manual/bounding_box/indentation.rb +14 -15
- data/manual/bounding_box/nesting.rb +24 -17
- data/manual/bounding_box/russian_boxes.rb +14 -13
- data/manual/bounding_box/stretchy.rb +12 -13
- data/manual/contents.rb +28 -22
- data/manual/cover.rb +33 -28
- data/manual/document_and_page_options/background.rb +11 -13
- data/manual/document_and_page_options/document_and_page_options.rb +25 -20
- data/manual/document_and_page_options/metadata.rb +18 -16
- data/manual/document_and_page_options/page_margins.rb +18 -20
- data/manual/document_and_page_options/page_size.rb +13 -12
- data/manual/document_and_page_options/print_scaling.rb +17 -15
- data/manual/example_helper.rb +5 -4
- data/manual/graphics/blend_mode.rb +52 -0
- data/manual/graphics/circle_and_ellipse.rb +4 -5
- data/manual/graphics/color.rb +7 -9
- data/manual/graphics/common_lines.rb +7 -8
- data/manual/graphics/fill_and_stroke.rb +4 -5
- data/manual/graphics/fill_rules.rb +9 -10
- data/manual/graphics/gradients.rb +27 -21
- data/manual/graphics/graphics.rb +48 -39
- data/manual/graphics/helper.rb +12 -9
- data/manual/graphics/line_width.rb +8 -7
- data/manual/graphics/lines_and_curves.rb +7 -8
- data/manual/graphics/polygon.rb +6 -8
- data/manual/graphics/rectangle.rb +4 -5
- data/manual/graphics/rotate.rb +6 -7
- data/manual/graphics/scale.rb +14 -15
- data/manual/graphics/soft_masks.rb +4 -5
- data/manual/graphics/stroke_cap.rb +6 -7
- data/manual/graphics/stroke_dash.rb +11 -12
- data/manual/graphics/stroke_join.rb +5 -6
- data/manual/graphics/translate.rb +9 -10
- data/manual/graphics/transparency.rb +7 -8
- data/manual/how_to_read_this_manual.rb +6 -6
- data/manual/images/absolute_position.rb +6 -7
- data/manual/images/fit.rb +7 -8
- data/manual/images/horizontal.rb +9 -10
- data/manual/images/images.rb +28 -24
- data/manual/images/plain_image.rb +5 -6
- data/manual/images/scale.rb +9 -10
- data/manual/images/vertical.rb +13 -14
- data/manual/images/width_and_height.rb +10 -11
- data/manual/layout/boxes.rb +5 -6
- data/manual/layout/content.rb +7 -8
- data/manual/layout/layout.rb +18 -16
- data/manual/layout/simple_grid.rb +6 -7
- data/manual/outline/add_subsection_to.rb +20 -21
- data/manual/outline/insert_section_after.rb +15 -16
- data/manual/outline/outline.rb +21 -17
- data/manual/outline/sections_and_pages.rb +17 -18
- data/manual/repeatable_content/alternate_page_numbering.rb +21 -17
- data/manual/repeatable_content/page_numbering.rb +17 -16
- data/manual/repeatable_content/repeatable_content.rb +25 -19
- data/manual/repeatable_content/repeater.rb +14 -15
- data/manual/repeatable_content/stamp.rb +14 -15
- data/manual/security/encryption.rb +9 -10
- data/manual/security/permissions.rb +19 -14
- data/manual/security/security.rb +19 -16
- data/manual/table.rb +3 -3
- data/manual/text/alignment.rb +16 -17
- data/manual/text/color.rb +12 -11
- data/manual/text/column_box.rb +9 -10
- data/manual/text/fallback_fonts.rb +25 -21
- data/manual/text/font.rb +11 -12
- data/manual/text/font_size.rb +13 -14
- data/manual/text/font_style.rb +7 -8
- data/manual/text/formatted_callbacks.rb +25 -21
- data/manual/text/formatted_text.rb +33 -25
- data/manual/text/free_flowing_text.rb +20 -21
- data/manual/text/inline.rb +18 -19
- data/manual/text/kerning_and_character_spacing.rb +14 -15
- data/manual/text/leading.rb +7 -8
- data/manual/text/line_wrapping.rb +37 -18
- data/manual/text/paragraph_indentation.rb +13 -14
- data/manual/text/positioned_text.rb +15 -16
- data/manual/text/registering_families.rb +20 -21
- data/manual/text/rendering_and_color.rb +9 -10
- data/manual/text/right_to_left_text.rb +26 -19
- data/manual/text/rotation.rb +28 -23
- data/manual/text/single_usage.rb +8 -9
- data/manual/text/text.rb +57 -52
- data/manual/text/text_box_excess.rb +20 -17
- data/manual/text/text_box_extensions.rb +18 -15
- data/manual/text/text_box_overflow.rb +18 -19
- data/manual/text/utf8.rb +11 -12
- data/manual/text/win_ansi_charset.rb +21 -19
- data/prawn.gemspec +45 -33
- data/spec/extensions/encoding_helpers.rb +3 -3
- data/spec/prawn/document/bounding_box_spec.rb +546 -0
- data/spec/prawn/document/column_box_spec.rb +75 -0
- data/spec/prawn/document/security_spec.rb +176 -0
- data/spec/prawn/document_annotations_spec.rb +76 -0
- data/spec/prawn/document_destinations_spec.rb +15 -0
- data/spec/prawn/document_grid_spec.rb +99 -0
- data/spec/prawn/document_reference_spec.rb +27 -0
- data/spec/prawn/document_span_spec.rb +36 -0
- data/spec/prawn/document_spec.rb +802 -0
- data/spec/prawn/font_metric_cache_spec.rb +54 -0
- data/spec/prawn/font_spec.rb +542 -0
- data/spec/prawn/graphics/blend_mode_spec.rb +63 -0
- data/spec/prawn/graphics/transparency_spec.rb +81 -0
- data/spec/prawn/graphics_spec.rb +837 -0
- data/spec/prawn/graphics_stroke_styles_spec.rb +229 -0
- data/spec/prawn/image_handler_spec.rb +53 -0
- data/spec/prawn/images/jpg_spec.rb +20 -0
- data/spec/prawn/images/png_spec.rb +283 -0
- data/spec/prawn/images_spec.rb +224 -0
- data/spec/prawn/measurements_extensions_spec.rb +24 -0
- data/spec/prawn/outline_spec.rb +412 -0
- data/spec/prawn/repeater_spec.rb +165 -0
- data/spec/prawn/soft_mask_spec.rb +74 -0
- data/spec/prawn/stamp_spec.rb +172 -0
- data/spec/prawn/text/box_spec.rb +1112 -0
- data/spec/prawn/text/formatted/arranger_spec.rb +466 -0
- data/spec/prawn/text/formatted/box_spec.rb +846 -0
- data/spec/prawn/text/formatted/fragment_spec.rb +343 -0
- data/spec/prawn/text/formatted/line_wrap_spec.rb +494 -0
- data/spec/prawn/text/formatted/parser_spec.rb +697 -0
- data/spec/prawn/text_draw_text_spec.rb +149 -0
- data/spec/prawn/text_rendering_mode_spec.rb +48 -0
- data/spec/prawn/text_spacing_spec.rb +95 -0
- data/spec/prawn/text_spec.rb +603 -0
- data/spec/prawn/text_with_inline_formatting_spec.rb +35 -0
- data/spec/prawn/transformation_stack_spec.rb +66 -0
- data/spec/prawn/view_spec.rb +63 -0
- data/spec/prawn_manual_spec.rb +35 -0
- data/spec/spec_helper.rb +19 -23
- metadata +145 -185
- metadata.gz.sig +4 -0
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/16bit.png +0 -0
- data/data/images/arrow.png +0 -0
- data/data/images/arrow2.png +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/dice.png +0 -0
- data/data/images/dice_interlaced.png +0 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/data/images/license.md +0 -8
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/data/images/page_white_text.png +0 -0
- data/data/images/pal_bk.png +0 -0
- data/data/images/pigs.jpg +0 -0
- data/data/images/prawn.png +0 -0
- data/data/images/ruport.png +0 -0
- data/data/images/ruport_data.dat +0 -0
- data/data/images/ruport_transparent.png +0 -0
- data/data/images/ruport_type0.png +0 -0
- data/data/images/stef.jpg +0 -0
- data/data/images/tru256.bmp +0 -0
- data/data/images/web-links.dat +0 -1
- data/data/images/web-links.png +0 -0
- data/data/pdfs/complex_template.pdf +0 -0
- data/data/pdfs/contains_ttf_font.pdf +0 -0
- data/data/pdfs/encrypted.pdf +0 -0
- data/data/pdfs/form.pdf +1 -819
- data/data/pdfs/hexagon.pdf +0 -61
- data/data/pdfs/indirect_reference.pdf +0 -86
- data/data/pdfs/multipage_template.pdf +0 -127
- data/data/pdfs/nested_pages.pdf +0 -118
- data/data/pdfs/page_without_mediabox.pdf +0 -193
- data/data/pdfs/resources_as_indirect_object.pdf +0 -83
- data/data/pdfs/two_hexagons.pdf +0 -90
- data/data/pdfs/version_1_6.pdf +0 -61
- data/data/shift_jis_text.txt +0 -1
- data/spec/acceptance/png.rb +0 -24
- data/spec/annotations_spec.rb +0 -67
- data/spec/bounding_box_spec.rb +0 -501
- data/spec/column_box_spec.rb +0 -59
- data/spec/destinations_spec.rb +0 -13
- data/spec/document_spec.rb +0 -742
- data/spec/extensions/mocha.rb +0 -45
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/font_spec.rb +0 -475
- data/spec/formatted_text_arranger_spec.rb +0 -423
- data/spec/formatted_text_box_spec.rb +0 -716
- data/spec/formatted_text_fragment_spec.rb +0 -299
- data/spec/graphics_spec.rb +0 -666
- data/spec/grid_spec.rb +0 -95
- data/spec/image_handler_spec.rb +0 -53
- data/spec/images_spec.rb +0 -167
- data/spec/inline_formatted_text_parser_spec.rb +0 -568
- data/spec/jpg_spec.rb +0 -23
- data/spec/line_wrap_spec.rb +0 -366
- data/spec/measurement_units_spec.rb +0 -22
- data/spec/outline_spec.rb +0 -409
- data/spec/png_spec.rb +0 -235
- data/spec/reference_spec.rb +0 -25
- data/spec/repeater_spec.rb +0 -154
- data/spec/security_spec.rb +0 -151
- data/spec/soft_mask_spec.rb +0 -78
- data/spec/span_spec.rb +0 -43
- data/spec/stamp_spec.rb +0 -179
- data/spec/stroke_styles_spec.rb +0 -208
- data/spec/text_at_spec.rb +0 -142
- data/spec/text_box_spec.rb +0 -1038
- data/spec/text_rendering_mode_spec.rb +0 -45
- data/spec/text_spacing_spec.rb +0 -93
- data/spec/text_spec.rb +0 -549
- data/spec/text_with_inline_formatting_spec.rb +0 -35
- data/spec/transparency_spec.rb +0 -91
- data/spec/view_spec.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1dd091ffaaed7c69fe8a0353317736d1f145e91f3f133a6d04ed0cffd7b5eb37
|
4
|
+
data.tar.gz: 98d1b0c973c9bf1947681ea971240fe9c351a9bcc1a74c91e7f8f677510eb11c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b75677d2586bf8a812549075cc9532bc02f78dc18b0e0db99711ad1087586f4fef6ae2f244e96a73366172410357d19e9371ac7b7eacf4a3bcbf85292ffb028
|
7
|
+
data.tar.gz: 138ac861e5016c49836a882c8beda2d2ed250e63959307ffe720624d322fd92b21ca71945e9cf58d0439851f8ebec515d13fb5f1d1660a3c9f4c996c5d04e701
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
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
@@ -1,11 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
4
|
|
5
|
-
|
6
|
-
platforms :rbx do
|
7
|
-
gem "rubysl-singleton", "~> 2.0"
|
8
|
-
gem "rubysl-digest", "~> 2.0"
|
9
|
-
gem "rubysl-enumerator", "~> 2.0"
|
10
|
-
end
|
11
|
-
end
|
5
|
+
gemspec
|
data/Rakefile
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
Bundler.setup
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
require 'rake'
|
5
4
|
require 'rspec/core/rake_task'
|
@@ -7,43 +6,33 @@ require 'yard'
|
|
7
6
|
require 'rubygems/package_task'
|
8
7
|
require 'rubocop/rake_task'
|
9
8
|
|
10
|
-
task :
|
9
|
+
task default: %i[spec rubocop]
|
11
10
|
|
12
|
-
desc
|
13
|
-
RSpec::Core::RakeTask.new(
|
14
|
-
c.rspec_opts =
|
15
|
-
end
|
16
|
-
|
17
|
-
desc "Show library's code statistics"
|
18
|
-
task :stats do
|
19
|
-
require 'code_statistics/code_statistics'
|
20
|
-
puts CodeStatistics::CodeStatistics.new(
|
21
|
-
[
|
22
|
-
["Prawn", "lib"],
|
23
|
-
["Specs", "spec"]
|
24
|
-
]
|
25
|
-
).to_s
|
11
|
+
desc 'Run all rspec files'
|
12
|
+
RSpec::Core::RakeTask.new('spec') do |c|
|
13
|
+
c.rspec_opts = '-t ~unresolved'
|
26
14
|
end
|
27
15
|
|
28
16
|
YARD::Rake::YardocTask.new do |t|
|
29
17
|
t.options = ['--output-dir', 'doc/html']
|
30
18
|
end
|
31
|
-
task :
|
19
|
+
task docs: :yard
|
32
20
|
|
33
21
|
desc "Generate the 'Prawn by Example' manual"
|
34
22
|
task :manual do
|
35
|
-
puts
|
36
|
-
require File.expand_path(File.join(
|
37
|
-
|
23
|
+
puts 'Building manual...'
|
24
|
+
require File.expand_path(File.join(__dir__, %w[manual contents]))
|
25
|
+
prawn_manual_document.render_file('manual.pdf')
|
26
|
+
puts 'The Prawn manual is available at manual.pdf. Happy Prawning!'
|
38
27
|
end
|
39
28
|
|
40
|
-
spec = Gem::Specification.load
|
29
|
+
spec = Gem::Specification.load 'prawn.gemspec'
|
41
30
|
Gem::PackageTask.new(spec) do |pkg|
|
42
31
|
pkg.need_zip = true
|
43
32
|
pkg.need_tar = true
|
44
33
|
end
|
45
34
|
|
46
|
-
desc
|
35
|
+
desc 'Run a console with Prawn loaded'
|
47
36
|
task :console do
|
48
37
|
require 'irb'
|
49
38
|
require 'irb/completion'
|
@@ -55,3 +44,11 @@ task :console do
|
|
55
44
|
end
|
56
45
|
|
57
46
|
RuboCop::RakeTask.new
|
47
|
+
|
48
|
+
task :checksum do
|
49
|
+
require 'digest/sha2'
|
50
|
+
built_gem_path = "prawn-#{Prawn::VERSION}.gem"
|
51
|
+
checksum = Digest::SHA512.new.hexdigest(File.read(built_gem_path))
|
52
|
+
checksum_path = "checksums/#{built_gem_path}.sha512"
|
53
|
+
File.write(checksum_path, checksum)
|
54
|
+
end
|
data/lib/prawn.rb
CHANGED
@@ -1,19 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Welcome to Prawn, the best PDF Generation library ever.
|
4
4
|
# This documentation covers user level functionality.
|
5
5
|
#
|
6
|
-
require
|
6
|
+
require 'set'
|
7
7
|
|
8
8
|
require 'ttfunk'
|
9
|
-
require
|
9
|
+
require 'pdf/core'
|
10
10
|
|
11
11
|
module Prawn
|
12
|
-
extend self
|
13
|
-
|
14
12
|
file = __FILE__
|
15
13
|
file = File.readlink(file) if File.symlink?(file)
|
16
|
-
dir
|
14
|
+
dir = File.dirname(file)
|
17
15
|
|
18
16
|
# The base source directory for Prawn as installed on the system
|
19
17
|
#
|
@@ -23,7 +21,7 @@ module Prawn
|
|
23
21
|
|
24
22
|
FLOAT_PRECISION = 1.0e-9
|
25
23
|
|
26
|
-
#
|
24
|
+
# When set to true, Prawn will verify hash options to ensure only valid keys
|
27
25
|
# are used. Off by default.
|
28
26
|
#
|
29
27
|
# Example:
|
@@ -32,58 +30,48 @@ module Prawn
|
|
32
30
|
# Detected unknown option(s): [:tomato]
|
33
31
|
# Accepted options are: [:page_size, :page_layout, :left_margin, ...]
|
34
32
|
#
|
35
|
-
|
33
|
+
# @private
|
34
|
+
attr_accessor :debug
|
35
|
+
module_function :debug, :debug=
|
36
|
+
|
37
|
+
module_function
|
36
38
|
|
37
|
-
|
39
|
+
# @private
|
40
|
+
def verify_options(accepted, actual)
|
38
41
|
return unless debug || $DEBUG
|
42
|
+
|
39
43
|
unless (act = Set[*actual.keys]).subset?(acc = Set[*accepted])
|
40
|
-
|
41
|
-
|
42
|
-
|
44
|
+
raise Prawn::Errors::UnknownOption,
|
45
|
+
"\nDetected unknown option(s): #{(act - acc).to_a.inspect}\n" \
|
46
|
+
"Accepted options are: #{accepted.inspect}"
|
43
47
|
end
|
44
48
|
yield if block_given?
|
45
49
|
end
|
46
|
-
|
47
|
-
module Configurable # @private
|
48
|
-
def configuration(*args)
|
49
|
-
@config ||= Marshal.load(Marshal.dump(default_configuration))
|
50
|
-
if Hash === args[0]
|
51
|
-
@config.update(args[0])
|
52
|
-
elsif args.length > 1
|
53
|
-
@config.values_at(*args)
|
54
|
-
elsif args.length == 1
|
55
|
-
@config[args[0]]
|
56
|
-
else
|
57
|
-
@config
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
alias_method :C, :configuration
|
62
|
-
end
|
63
50
|
end
|
64
51
|
|
65
|
-
require_relative
|
52
|
+
require_relative 'prawn/version'
|
66
53
|
|
67
|
-
require_relative
|
54
|
+
require_relative 'prawn/errors'
|
68
55
|
|
69
|
-
require_relative
|
70
|
-
require_relative
|
71
|
-
require_relative
|
72
|
-
require_relative
|
73
|
-
require_relative
|
74
|
-
require_relative
|
75
|
-
require_relative
|
76
|
-
require_relative
|
77
|
-
require_relative
|
78
|
-
require_relative
|
79
|
-
require_relative
|
80
|
-
require_relative
|
81
|
-
require_relative
|
82
|
-
require_relative
|
83
|
-
require_relative
|
84
|
-
require_relative
|
85
|
-
require_relative
|
86
|
-
require_relative
|
56
|
+
require_relative 'prawn/utilities'
|
57
|
+
require_relative 'prawn/text'
|
58
|
+
require_relative 'prawn/graphics'
|
59
|
+
require_relative 'prawn/images'
|
60
|
+
require_relative 'prawn/images/image'
|
61
|
+
require_relative 'prawn/images/jpg'
|
62
|
+
require_relative 'prawn/images/png'
|
63
|
+
require_relative 'prawn/stamp'
|
64
|
+
require_relative 'prawn/soft_mask'
|
65
|
+
require_relative 'prawn/security'
|
66
|
+
require_relative 'prawn/transformation_stack'
|
67
|
+
require_relative 'prawn/document'
|
68
|
+
require_relative 'prawn/font'
|
69
|
+
require_relative 'prawn/measurements'
|
70
|
+
require_relative 'prawn/repeater'
|
71
|
+
require_relative 'prawn/outline'
|
72
|
+
require_relative 'prawn/grid'
|
73
|
+
require_relative 'prawn/view'
|
74
|
+
require_relative 'prawn/image_handler'
|
87
75
|
|
88
76
|
Prawn.image_handler.register(Prawn::Images::PNG)
|
89
77
|
Prawn.image_handler.register(Prawn::Images::JPG)
|
data/lib/prawn/document.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# document.rb : Implements PDF document generation for Prawn
|
4
4
|
#
|
@@ -6,21 +6,21 @@
|
|
6
6
|
#
|
7
7
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
8
|
|
9
|
-
require
|
9
|
+
require 'stringio'
|
10
10
|
|
11
|
-
require_relative
|
12
|
-
require_relative
|
13
|
-
require_relative
|
14
|
-
require_relative
|
11
|
+
require_relative 'document/bounding_box'
|
12
|
+
require_relative 'document/column_box'
|
13
|
+
require_relative 'document/internals'
|
14
|
+
require_relative 'document/span'
|
15
15
|
|
16
16
|
module Prawn
|
17
17
|
# The Prawn::Document class is how you start creating a PDF document.
|
18
18
|
#
|
19
19
|
# There are three basic ways you can instantiate PDF Documents in Prawn, they
|
20
|
-
# are through assignment, implicit block or explicit block. Below is an
|
21
|
-
# of each type, each example does exactly the same thing, makes a PDF
|
22
|
-
# with all the defaults and puts in the default font "Hello There"
|
23
|
-
# saves it to the current directory as "example.pdf"
|
20
|
+
# are through assignment, implicit block or explicit block. Below is an
|
21
|
+
# example of each type, each example does exactly the same thing, makes a PDF
|
22
|
+
# document with all the defaults and puts in the default font "Hello There"
|
23
|
+
# and then saves it to the current directory as "example.pdf"
|
24
24
|
#
|
25
25
|
# For example, assignment can be like this:
|
26
26
|
#
|
@@ -42,8 +42,8 @@ module Prawn
|
|
42
42
|
# pdf.text words
|
43
43
|
# end
|
44
44
|
#
|
45
|
-
# Usually, the block forms are used when you are simply creating a PDF
|
46
|
-
# that you want to immediately save or render out.
|
45
|
+
# Usually, the block forms are used when you are simply creating a PDF
|
46
|
+
# document that you want to immediately save or render out.
|
47
47
|
#
|
48
48
|
# See the new and generate methods for further details on the above.
|
49
49
|
#
|
@@ -57,16 +57,19 @@ module Prawn
|
|
57
57
|
include Prawn::Images
|
58
58
|
include Prawn::Stamp
|
59
59
|
include Prawn::SoftMask
|
60
|
+
include Prawn::TransformationStack
|
60
61
|
|
61
62
|
# @group Extension API
|
62
63
|
|
63
64
|
# NOTE: We probably need to rethink the options validation system, but this
|
64
65
|
# constant temporarily allows for extensions to modify the list.
|
65
66
|
|
66
|
-
VALID_OPTIONS = [
|
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
|
72
|
+
].freeze
|
70
73
|
|
71
74
|
# Any module added to this array will be included into instances of
|
72
75
|
# Prawn::Document at the per-object level. These will also be inherited by
|
@@ -152,15 +155,22 @@ module Prawn
|
|
152
155
|
# <tt>:right_margin</tt>:: Sets the right margin in points [0.5 inch]
|
153
156
|
# <tt>:top_margin</tt>:: Sets the top margin in points [0.5 inch]
|
154
157
|
# <tt>:bottom_margin</tt>:: Sets the bottom margin in points [0.5 inch]
|
155
|
-
# <tt>:skip_page_creation</tt>:: Creates a document without starting the
|
156
|
-
#
|
157
|
-
# <tt>:
|
158
|
+
# <tt>:skip_page_creation</tt>:: Creates a document without starting the
|
159
|
+
# first page [false]
|
160
|
+
# <tt>:compress</tt>:: Compresses content streams before rendering them
|
161
|
+
# [false]
|
162
|
+
# <tt>:background</tt>:: An image path to be used as background on all pages
|
163
|
+
# [nil]
|
158
164
|
# <tt>:background_scale</tt>:: Backgound image scale [1] [nil]
|
159
|
-
# <tt>:info</tt>:: Generic hash allowing for custom metadata properties
|
160
|
-
#
|
165
|
+
# <tt>:info</tt>:: Generic hash allowing for custom metadata properties
|
166
|
+
# [nil]
|
167
|
+
# <tt>:text_formatter</tt>: The text formatter to use for
|
168
|
+
# <tt>:inline_format</tt>ted text
|
169
|
+
# [Prawn::Text::Formatted::Parser]
|
161
170
|
#
|
162
|
-
# Setting e.g. the :margin to 100 points and the :left_margin to 50 will
|
163
|
-
# of 100 points on every side except for the left, where
|
171
|
+
# Setting e.g. the :margin to 100 points and the :left_margin to 50 will
|
172
|
+
# result in margins of 100 points on every side except for the left, where
|
173
|
+
# it will be 50.
|
164
174
|
#
|
165
175
|
# The :margin can also be an array much like CSS shorthand:
|
166
176
|
#
|
@@ -171,8 +181,8 @@ module Prawn
|
|
171
181
|
# # Top is 10, right is 20, bottom is 30, left is 40.
|
172
182
|
# :margin => [10, 20, 30, 40]
|
173
183
|
#
|
174
|
-
# Additionally, :page_size can be specified as a simple two value array
|
175
|
-
# the width and height of the document you need in PDF Points.
|
184
|
+
# Additionally, :page_size can be specified as a simple two value array
|
185
|
+
# giving the width and height of the document you need in PDF Points.
|
176
186
|
#
|
177
187
|
# Usage:
|
178
188
|
#
|
@@ -180,13 +190,15 @@ module Prawn
|
|
180
190
|
# pdf = Prawn::Document.new
|
181
191
|
#
|
182
192
|
# # New document, A4 paper, landscaped
|
183
|
-
# pdf = Prawn::Document.new(:
|
193
|
+
# pdf = Prawn::Document.new(page_size: "A4", page_layout: :landscape)
|
184
194
|
#
|
185
195
|
# # New document, Custom size
|
186
|
-
# pdf = Prawn::Document.new(:
|
196
|
+
# pdf = Prawn::Document.new(page_size: [200, 300])
|
187
197
|
#
|
188
198
|
# # New document, with background
|
189
|
-
# pdf = Prawn::Document.new(
|
199
|
+
# pdf = Prawn::Document.new(
|
200
|
+
# background: "#{Prawn::DATADIR}/images/pigs.jpg"
|
201
|
+
# )
|
190
202
|
#
|
191
203
|
def initialize(options = {}, &block)
|
192
204
|
options = options.dup
|
@@ -198,21 +210,22 @@ module Prawn
|
|
198
210
|
|
199
211
|
self.class.extensions.reverse_each { |e| extend e }
|
200
212
|
self.state = PDF::Core::DocumentState.new(options)
|
201
|
-
|
213
|
+
state.populate_pages_from_store(self)
|
202
214
|
renderer.min_version(state.store.min_version) if state.store.min_version
|
203
215
|
|
204
216
|
renderer.min_version(1.6) if options[:print_scaling] == :none
|
205
217
|
|
206
218
|
@background = options[:background]
|
207
219
|
@background_scale = options[:background_scale] || 1
|
208
|
-
@font_size
|
220
|
+
@font_size = 12
|
209
221
|
|
210
|
-
@bounding_box
|
211
|
-
@margin_box
|
222
|
+
@bounding_box = nil
|
223
|
+
@margin_box = nil
|
212
224
|
|
213
225
|
@page_number = 0
|
214
226
|
|
215
|
-
@text_formatter = options.delete(:text_formatter) ||
|
227
|
+
@text_formatter = options.delete(:text_formatter) ||
|
228
|
+
Text::Formatted::Parser
|
216
229
|
|
217
230
|
options[:size] = options.delete(:page_size)
|
218
231
|
options[:layout] = options.delete(:page_layout)
|
@@ -239,24 +252,28 @@ module Prawn
|
|
239
252
|
# pdf.start_new_page(:margin => 100)
|
240
253
|
#
|
241
254
|
def start_new_page(options = {})
|
242
|
-
|
243
|
-
|
244
|
-
|
255
|
+
last_page = state.page
|
256
|
+
if last_page
|
257
|
+
last_page_size = last_page.size
|
258
|
+
last_page_layout = last_page.layout
|
245
259
|
last_page_margins = last_page.margins.dup
|
246
260
|
end
|
247
261
|
|
248
262
|
page_options = {
|
249
|
-
:
|
250
|
-
:
|
251
|
-
:
|
263
|
+
size: options[:size] || last_page_size,
|
264
|
+
layout: options[:layout] || last_page_layout,
|
265
|
+
margins: last_page_margins
|
252
266
|
}
|
253
267
|
if last_page
|
254
|
-
|
268
|
+
if last_page.graphic_state
|
269
|
+
new_graphic_state = last_page.graphic_state.dup
|
270
|
+
end
|
255
271
|
|
256
|
-
# erase the color space so that it gets reset on new page for fussy
|
257
|
-
|
272
|
+
# erase the color space so that it gets reset on new page for fussy
|
273
|
+
# pdf-readers
|
274
|
+
new_graphic_state&.color_space = {}
|
258
275
|
|
259
|
-
page_options
|
276
|
+
page_options[:graphic_state] = new_graphic_state
|
260
277
|
end
|
261
278
|
|
262
279
|
state.page = PDF::Core::Page.new(self, page_options)
|
@@ -276,7 +293,11 @@ module Prawn
|
|
276
293
|
state.insert_page(state.page, @page_number)
|
277
294
|
@page_number += 1
|
278
295
|
|
279
|
-
|
296
|
+
if @background
|
297
|
+
canvas do
|
298
|
+
image(@background, scale: @background_scale, at: bounds.top_left)
|
299
|
+
end
|
300
|
+
end
|
280
301
|
@y = @bounding_box.absolute_top
|
281
302
|
|
282
303
|
float do
|
@@ -285,6 +306,26 @@ module Prawn
|
|
285
306
|
end
|
286
307
|
end
|
287
308
|
|
309
|
+
# Remove page of the document by index
|
310
|
+
#
|
311
|
+
# pdf = Prawn::Document.new
|
312
|
+
# pdf.page_count #=> 1
|
313
|
+
# 3.times { pdf.start_new_page }
|
314
|
+
# pdf.page_count #=> 4
|
315
|
+
# pdf.delete_page(-1)
|
316
|
+
# pdf.page_count #=> 3
|
317
|
+
#
|
318
|
+
def delete_page(index)
|
319
|
+
return false if index.abs > (state.pages.count - 1)
|
320
|
+
|
321
|
+
state.pages.delete_at(index)
|
322
|
+
|
323
|
+
state.store.pages.data[:Kids].delete_at(index)
|
324
|
+
state.store.pages.data[:Count] -= 1
|
325
|
+
@page_number -= 1
|
326
|
+
true
|
327
|
+
end
|
328
|
+
|
288
329
|
# Returns the number of pages in the document
|
289
330
|
#
|
290
331
|
# pdf = Prawn::Document.new
|
@@ -301,9 +342,9 @@ module Prawn
|
|
301
342
|
#
|
302
343
|
# See Prawn::Document#number_pages for a sample usage of this capability.
|
303
344
|
#
|
304
|
-
def go_to_page(
|
305
|
-
@page_number =
|
306
|
-
state.page = state.pages[
|
345
|
+
def go_to_page(page_number)
|
346
|
+
@page_number = page_number
|
347
|
+
state.page = state.pages[page_number - 1]
|
307
348
|
generate_margin_box
|
308
349
|
@y = @bounding_box.absolute_top
|
309
350
|
end
|
@@ -350,13 +391,13 @@ module Prawn
|
|
350
391
|
# Renders the PDF document to string.
|
351
392
|
# Pass an open file descriptor to render to file.
|
352
393
|
#
|
353
|
-
def render(*
|
394
|
+
def render(*arguments, &block)
|
354
395
|
(1..page_count).each do |i|
|
355
396
|
go_to_page i
|
356
397
|
repeaters.each { |r| r.run(i) }
|
357
398
|
end
|
358
399
|
|
359
|
-
renderer.render(*
|
400
|
+
renderer.render(*arguments, &block)
|
360
401
|
end
|
361
402
|
|
362
403
|
# Renders the PDF document to file.
|
@@ -364,7 +405,7 @@ module Prawn
|
|
364
405
|
# pdf.render_file "foo.pdf"
|
365
406
|
#
|
366
407
|
def render_file(filename)
|
367
|
-
File.open(filename,
|
408
|
+
File.open(filename, 'wb') { |f| render(f) }
|
368
409
|
end
|
369
410
|
|
370
411
|
# The bounds method returns the current bounding box you are currently in,
|
@@ -373,14 +414,15 @@ module Prawn
|
|
373
414
|
# block, the box defined by that call will be returned instead of the
|
374
415
|
# document margin box.
|
375
416
|
#
|
376
|
-
# Another important point about bounding boxes is that all x and
|
377
|
-
# within a bounding box code block are relative to the bottom
|
378
|
-
# bounding box.
|
417
|
+
# Another important point about bounding boxes is that all x and
|
418
|
+
# y measurements within a bounding box code block are relative to the bottom
|
419
|
+
# left corner of the bounding box.
|
379
420
|
#
|
380
421
|
# For example:
|
381
422
|
#
|
382
423
|
# Prawn::Document.new do
|
383
|
-
# # In the default "margin box" of a Prawn document of 0.5in along each
|
424
|
+
# # In the default "margin box" of a Prawn document of 0.5in along each
|
425
|
+
# # edge
|
384
426
|
#
|
385
427
|
# # Draw a border around the page (the manual way)
|
386
428
|
# stroke do
|
@@ -407,8 +449,8 @@ module Prawn
|
|
407
449
|
|
408
450
|
# Sets Document#bounds to the BoundingBox provided. See above for a brief
|
409
451
|
# description of what a bounding box is. This function is useful if you
|
410
|
-
# really need to change the bounding box manually, but usually, just
|
411
|
-
# and exiting bounding box code blocks is good enough.
|
452
|
+
# really need to change the bounding box manually, but usually, just
|
453
|
+
# entering and exiting bounding box code blocks is good enough.
|
412
454
|
#
|
413
455
|
def bounds=(bounding_box)
|
414
456
|
@bounding_box = bounding_box
|
@@ -417,15 +459,15 @@ module Prawn
|
|
417
459
|
# Moves up the document by n points relative to the current position inside
|
418
460
|
# the current bounding box.
|
419
461
|
#
|
420
|
-
def move_up(
|
421
|
-
self.y +=
|
462
|
+
def move_up(amount)
|
463
|
+
self.y += amount
|
422
464
|
end
|
423
465
|
|
424
|
-
# Moves down the document by n points relative to the current position
|
425
|
-
# the current bounding box.
|
466
|
+
# Moves down the document by n points relative to the current position
|
467
|
+
# inside the current bounding box.
|
426
468
|
#
|
427
|
-
def move_down(
|
428
|
-
self.y -=
|
469
|
+
def move_down(amount)
|
470
|
+
self.y -= amount
|
429
471
|
end
|
430
472
|
|
431
473
|
# Moves down the document and then executes a block.
|
@@ -485,50 +527,54 @@ module Prawn
|
|
485
527
|
bounds.indent(left, right, &block)
|
486
528
|
end
|
487
529
|
|
488
|
-
# Places a text box on specified pages for page numbering. This should be
|
489
|
-
# towards the end of document creation, after all your content is
|
490
|
-
# place. In your template string, <page> refers to the current
|
491
|
-
# <total> refers to the total amount of pages in the document.
|
492
|
-
# occur at the end of your Prawn::Document.generate
|
493
|
-
# through existing pages after they are
|
530
|
+
# Places a text box on specified pages for page numbering. This should be
|
531
|
+
# called towards the end of document creation, after all your content is
|
532
|
+
# already in place. In your template string, <page> refers to the current
|
533
|
+
# page, and <total> refers to the total amount of pages in the document.
|
534
|
+
# Page numbering should occur at the end of your Prawn::Document.generate
|
535
|
+
# block because the method iterates through existing pages after they are
|
536
|
+
# created.
|
494
537
|
#
|
495
538
|
# Parameters are:
|
496
539
|
#
|
497
540
|
# <tt>string</tt>:: Template string for page number wording.
|
498
541
|
# Should include '<page>' and, optionally, '<total>'.
|
499
542
|
# <tt>options</tt>:: A hash for page numbering and text box options.
|
500
|
-
# <tt>:page_filter</tt>:: A filter to specify which pages to place page
|
501
|
-
# Refer to the method 'page_match?'
|
543
|
+
# <tt>:page_filter</tt>:: A filter to specify which pages to place page
|
544
|
+
# numbers on. Refer to the method 'page_match?'
|
502
545
|
# <tt>:start_count_at</tt>:: The starting count to increment pages from.
|
503
|
-
# <tt>:total_pages</tt>:: If provided, will replace <total> with the
|
504
|
-
# Useful to override the total
|
505
|
-
# the start_count_at
|
546
|
+
# <tt>:total_pages</tt>:: If provided, will replace <total> with the
|
547
|
+
# value given. Useful to override the total
|
548
|
+
# number of pages when using the start_count_at
|
549
|
+
# option.
|
506
550
|
# <tt>:color</tt>:: Text fill color.
|
507
551
|
#
|
508
|
-
# Please refer to Prawn::Text::text_box for additional options
|
509
|
-
# formatting and placement.
|
510
|
-
#
|
511
|
-
# Example: Print page numbers on every page except for the first. Start counting from
|
512
|
-
# five.
|
552
|
+
# Please refer to Prawn::Text::text_box for additional options
|
553
|
+
# concerning text formatting and placement.
|
513
554
|
#
|
514
|
-
#
|
515
|
-
#
|
516
|
-
#
|
517
|
-
#
|
518
|
-
#
|
519
|
-
#
|
520
|
-
#
|
521
|
-
#
|
555
|
+
# Example:
|
556
|
+
# Print page numbers on every page except for the first. Start counting
|
557
|
+
# from five.
|
558
|
+
#
|
559
|
+
# Prawn::Document.generate("page_with_numbering.pdf") do
|
560
|
+
# number_pages "<page> in a total of <total>", {
|
561
|
+
# start_count_at: 5,
|
562
|
+
# page_filter: lambda { |pg| pg != 1 },
|
563
|
+
# at: [bounds.right - 50, 0],
|
564
|
+
# align: :right,
|
565
|
+
# size: 14
|
566
|
+
# }
|
567
|
+
# end
|
522
568
|
#
|
523
569
|
def number_pages(string, options = {})
|
524
570
|
opts = options.dup
|
525
571
|
start_count_at = opts.delete(:start_count_at).to_i
|
526
572
|
|
527
|
-
if opts.key?(:page_filter)
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
573
|
+
page_filter = if opts.key?(:page_filter)
|
574
|
+
opts.delete(:page_filter)
|
575
|
+
else
|
576
|
+
:all
|
577
|
+
end
|
532
578
|
|
533
579
|
total_pages = opts.delete(:total_pages)
|
534
580
|
txtcolor = opts.delete(:color)
|
@@ -548,12 +594,14 @@ module Prawn
|
|
548
594
|
end
|
549
595
|
if page_match?(page_filter, p)
|
550
596
|
go_to_page(p)
|
551
|
-
# have to use fill_color here otherwise text reverts back to default
|
597
|
+
# have to use fill_color here otherwise text reverts back to default
|
598
|
+
# fill color
|
552
599
|
fill_color txtcolor unless txtcolor.nil?
|
553
600
|
total_pages = total_pages.nil? ? page_count : total_pages
|
554
|
-
str = string.gsub(
|
601
|
+
str = string.gsub('<page>', pseudopage.to_s)
|
602
|
+
.gsub('<total>', total_pages.to_s)
|
555
603
|
text_box str, opts
|
556
|
-
start_count = true
|
604
|
+
start_count = true # increment page count as soon as first match found
|
557
605
|
end
|
558
606
|
pseudopage += 1 if start_count
|
559
607
|
end
|
@@ -571,21 +619,21 @@ module Prawn
|
|
571
619
|
# the current page or column.
|
572
620
|
#
|
573
621
|
# @private
|
574
|
-
def group(*
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
622
|
+
def group(*_arguments)
|
623
|
+
raise NotImplementedError,
|
624
|
+
'Document#group has been disabled because its implementation ' \
|
625
|
+
'lead to corrupted documents whenever a page boundary was ' \
|
626
|
+
'crossed. We will try to work on reimplementing it in a ' \
|
627
|
+
'future release'
|
580
628
|
end
|
581
629
|
|
582
630
|
# @private
|
583
631
|
def transaction
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
632
|
+
raise NotImplementedError,
|
633
|
+
'Document#transaction has been disabled because its implementation ' \
|
634
|
+
'lead to corrupted documents whenever a page boundary was ' \
|
635
|
+
'crossed. We will try to work on reimplementing it in a ' \
|
636
|
+
'future release'
|
589
637
|
end
|
590
638
|
|
591
639
|
# Provides a way to execute a block of code repeatedly based on a
|
@@ -616,8 +664,8 @@ module Prawn
|
|
616
664
|
# @private
|
617
665
|
|
618
666
|
def mask(*fields)
|
619
|
-
# Stores the current state of the named attributes, executes the block,
|
620
|
-
# then restores the original values after the block has executed.
|
667
|
+
# Stores the current state of the named attributes, executes the block,
|
668
|
+
# and then restores the original values after the block has executed.
|
621
669
|
# -- I will remove the nodoc if/when this feature is a little less hacky
|
622
670
|
stored = {}
|
623
671
|
fields.each { |f| stored[f] = send(f) }
|
@@ -629,7 +677,7 @@ module Prawn
|
|
629
677
|
|
630
678
|
def initialize_first_page(options)
|
631
679
|
if options[:skip_page_creation]
|
632
|
-
start_new_page(options.merge(:
|
680
|
+
start_new_page(options.merge(orphan: true))
|
633
681
|
else
|
634
682
|
start_new_page(options)
|
635
683
|
end
|
@@ -647,11 +695,11 @@ module Prawn
|
|
647
695
|
|
648
696
|
private
|
649
697
|
|
650
|
-
# setting override_settings to true ensures that a new graphic state does
|
651
|
-
# previous settings.
|
698
|
+
# setting override_settings to true ensures that a new graphic state does
|
699
|
+
# not end up using previous settings.
|
652
700
|
def use_graphic_settings(override_settings = false)
|
653
|
-
set_fill_color if current_fill_color !=
|
654
|
-
set_stroke_color if current_stroke_color !=
|
701
|
+
set_fill_color if current_fill_color != '000000' || override_settings
|
702
|
+
set_stroke_color if current_stroke_color != '000000' || override_settings
|
655
703
|
write_line_width if line_width != 1 || override_settings
|
656
704
|
write_stroke_cap_style if cap_style != :butt || override_settings
|
657
705
|
write_stroke_join_style if join_style != :miter || override_settings
|
@@ -660,14 +708,16 @@ module Prawn
|
|
660
708
|
|
661
709
|
def generate_margin_box
|
662
710
|
old_margin_box = @margin_box
|
663
|
-
page
|
711
|
+
page = state.page
|
664
712
|
|
665
713
|
@margin_box = BoundingBox.new(
|
666
714
|
self,
|
667
|
-
nil,
|
668
|
-
[
|
669
|
-
:
|
670
|
-
|
715
|
+
nil, # margin box has no parent
|
716
|
+
[page.margins[:left], page.dimensions[-1] - page.margins[:top]],
|
717
|
+
width: page.dimensions[-2] -
|
718
|
+
(page.margins[:left] + page.margins[:right]),
|
719
|
+
height: page.dimensions[-1] -
|
720
|
+
(page.margins[:top] + page.margins[:bottom])
|
671
721
|
)
|
672
722
|
|
673
723
|
# This check maintains indentation settings across page breaks
|
@@ -678,25 +728,23 @@ module Prawn
|
|
678
728
|
|
679
729
|
# we must update bounding box if not flowing from the previous page
|
680
730
|
#
|
681
|
-
@bounding_box = @margin_box unless @bounding_box
|
731
|
+
@bounding_box = @margin_box unless @bounding_box&.parent
|
682
732
|
end
|
683
733
|
|
684
734
|
def apply_margin_options(options)
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
[
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
state.page.margins[side] = margin
|
699
|
-
end
|
735
|
+
sides = %i[top right bottom left]
|
736
|
+
margin = Array(options[:margin])
|
737
|
+
|
738
|
+
# Treat :margin as CSS shorthand with 1-4 values.
|
739
|
+
positions = {
|
740
|
+
4 => [0, 1, 2, 3], 3 => [0, 1, 2, 1],
|
741
|
+
2 => [0, 1, 0, 1], 1 => [0, 0, 0, 0],
|
742
|
+
0 => []
|
743
|
+
}[margin.length]
|
744
|
+
|
745
|
+
sides.zip(positions).each do |side, pos|
|
746
|
+
new_margin = options[:"#{side}_margin"] || (margin[pos] if pos)
|
747
|
+
state.page.margins[side] = new_margin if new_margin
|
700
748
|
end
|
701
749
|
end
|
702
750
|
|