prawn 2.1.0 → 2.3.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 +3 -9
- data/Rakefile +20 -23
- data/lib/prawn.rb +36 -49
- data/lib/prawn/document.rb +180 -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 +8 -6
- 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 +102 -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 +119 -81
- data/lib/prawn/graphics/blend_mode.rb +9 -8
- 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 +190 -96
- data/lib/prawn/graphics/transformation.rb +15 -9
- 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 +65 -62
- 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 +53 -32
- 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 +122 -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 +7 -5
- 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 +12 -9
- 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 -40
- 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 +3 -4
- 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 +44 -31
- 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/{image_handler_spec.rb → prawn/image_handler_spec.rb} +14 -14
- 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/{transformation_stack_spec.rb → prawn/transformation_stack_spec.rb} +22 -19
- data/spec/prawn/view_spec.rb +63 -0
- data/spec/prawn_manual_spec.rb +35 -0
- data/spec/spec_helper.rb +18 -19
- metadata +144 -180
- 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/blend_modes_bottom_layer.jpg +0 -0
- data/data/images/blend_modes_top_layer.jpg +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/indexed_transparency.png +0 -0
- data/data/images/indexed_transparency_alpha.dat +0 -0
- data/data/images/indexed_transparency_color.dat +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/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_spec.rb +0 -35
- data/spec/annotations_spec.rb +0 -67
- data/spec/blend_mode_spec.rb +0 -71
- 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 -738
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/font_spec.rb +0 -475
- data/spec/formatted_text_arranger_spec.rb +0 -452
- data/spec/formatted_text_box_spec.rb +0 -716
- data/spec/formatted_text_fragment_spec.rb +0 -299
- data/spec/graphics_spec.rb +0 -705
- data/spec/grid_spec.rb +0 -95
- 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 -257
- 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 -1042
- data/spec/text_rendering_mode_spec.rb +0 -45
- data/spec/text_spacing_spec.rb +0 -93
- data/spec/text_spec.rb +0 -543
- 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
|
#
|
@@ -32,59 +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
|
87
|
-
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'
|
88
75
|
|
89
76
|
Prawn.image_handler.register(Prawn::Images::PNG)
|
90
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
|
#
|
@@ -64,10 +64,12 @@ module Prawn
|
|
64
64
|
# NOTE: We probably need to rethink the options validation system, but this
|
65
65
|
# constant temporarily allows for extensions to modify the list.
|
66
66
|
|
67
|
-
VALID_OPTIONS = [
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
71
73
|
|
72
74
|
# Any module added to this array will be included into instances of
|
73
75
|
# Prawn::Document at the per-object level. These will also be inherited by
|
@@ -153,15 +155,22 @@ module Prawn
|
|
153
155
|
# <tt>:right_margin</tt>:: Sets the right margin in points [0.5 inch]
|
154
156
|
# <tt>:top_margin</tt>:: Sets the top margin in points [0.5 inch]
|
155
157
|
# <tt>:bottom_margin</tt>:: Sets the bottom margin in points [0.5 inch]
|
156
|
-
# <tt>:skip_page_creation</tt>:: Creates a document without starting the
|
157
|
-
#
|
158
|
-
# <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]
|
159
164
|
# <tt>:background_scale</tt>:: Backgound image scale [1] [nil]
|
160
|
-
# <tt>:info</tt>:: Generic hash allowing for custom metadata properties
|
161
|
-
#
|
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]
|
162
170
|
#
|
163
|
-
# Setting e.g. the :margin to 100 points and the :left_margin to 50 will
|
164
|
-
# 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.
|
165
174
|
#
|
166
175
|
# The :margin can also be an array much like CSS shorthand:
|
167
176
|
#
|
@@ -172,8 +181,8 @@ module Prawn
|
|
172
181
|
# # Top is 10, right is 20, bottom is 30, left is 40.
|
173
182
|
# :margin => [10, 20, 30, 40]
|
174
183
|
#
|
175
|
-
# Additionally, :page_size can be specified as a simple two value array
|
176
|
-
# 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.
|
177
186
|
#
|
178
187
|
# Usage:
|
179
188
|
#
|
@@ -181,13 +190,15 @@ module Prawn
|
|
181
190
|
# pdf = Prawn::Document.new
|
182
191
|
#
|
183
192
|
# # New document, A4 paper, landscaped
|
184
|
-
# pdf = Prawn::Document.new(:
|
193
|
+
# pdf = Prawn::Document.new(page_size: "A4", page_layout: :landscape)
|
185
194
|
#
|
186
195
|
# # New document, Custom size
|
187
|
-
# pdf = Prawn::Document.new(:
|
196
|
+
# pdf = Prawn::Document.new(page_size: [200, 300])
|
188
197
|
#
|
189
198
|
# # New document, with background
|
190
|
-
# pdf = Prawn::Document.new(
|
199
|
+
# pdf = Prawn::Document.new(
|
200
|
+
# background: "#{Prawn::DATADIR}/images/pigs.jpg"
|
201
|
+
# )
|
191
202
|
#
|
192
203
|
def initialize(options = {}, &block)
|
193
204
|
options = options.dup
|
@@ -199,21 +210,22 @@ module Prawn
|
|
199
210
|
|
200
211
|
self.class.extensions.reverse_each { |e| extend e }
|
201
212
|
self.state = PDF::Core::DocumentState.new(options)
|
202
|
-
|
213
|
+
state.populate_pages_from_store(self)
|
203
214
|
renderer.min_version(state.store.min_version) if state.store.min_version
|
204
215
|
|
205
216
|
renderer.min_version(1.6) if options[:print_scaling] == :none
|
206
217
|
|
207
218
|
@background = options[:background]
|
208
219
|
@background_scale = options[:background_scale] || 1
|
209
|
-
@font_size
|
220
|
+
@font_size = 12
|
210
221
|
|
211
|
-
@bounding_box
|
212
|
-
@margin_box
|
222
|
+
@bounding_box = nil
|
223
|
+
@margin_box = nil
|
213
224
|
|
214
225
|
@page_number = 0
|
215
226
|
|
216
|
-
@text_formatter = options.delete(:text_formatter) ||
|
227
|
+
@text_formatter = options.delete(:text_formatter) ||
|
228
|
+
Text::Formatted::Parser
|
217
229
|
|
218
230
|
options[:size] = options.delete(:page_size)
|
219
231
|
options[:layout] = options.delete(:page_layout)
|
@@ -240,24 +252,28 @@ module Prawn
|
|
240
252
|
# pdf.start_new_page(:margin => 100)
|
241
253
|
#
|
242
254
|
def start_new_page(options = {})
|
243
|
-
|
244
|
-
|
245
|
-
|
255
|
+
last_page = state.page
|
256
|
+
if last_page
|
257
|
+
last_page_size = last_page.size
|
258
|
+
last_page_layout = last_page.layout
|
246
259
|
last_page_margins = last_page.margins.dup
|
247
260
|
end
|
248
261
|
|
249
262
|
page_options = {
|
250
|
-
:
|
251
|
-
:
|
252
|
-
:
|
263
|
+
size: options[:size] || last_page_size,
|
264
|
+
layout: options[:layout] || last_page_layout,
|
265
|
+
margins: last_page_margins
|
253
266
|
}
|
254
267
|
if last_page
|
255
|
-
|
268
|
+
if last_page.graphic_state
|
269
|
+
new_graphic_state = last_page.graphic_state.dup
|
270
|
+
end
|
256
271
|
|
257
|
-
# erase the color space so that it gets reset on new page for fussy
|
258
|
-
|
272
|
+
# erase the color space so that it gets reset on new page for fussy
|
273
|
+
# pdf-readers
|
274
|
+
new_graphic_state&.color_space = {}
|
259
275
|
|
260
|
-
page_options
|
276
|
+
page_options[:graphic_state] = new_graphic_state
|
261
277
|
end
|
262
278
|
|
263
279
|
state.page = PDF::Core::Page.new(self, page_options)
|
@@ -277,7 +293,11 @@ module Prawn
|
|
277
293
|
state.insert_page(state.page, @page_number)
|
278
294
|
@page_number += 1
|
279
295
|
|
280
|
-
|
296
|
+
if @background
|
297
|
+
canvas do
|
298
|
+
image(@background, scale: @background_scale, at: bounds.top_left)
|
299
|
+
end
|
300
|
+
end
|
281
301
|
@y = @bounding_box.absolute_top
|
282
302
|
|
283
303
|
float do
|
@@ -286,6 +306,26 @@ module Prawn
|
|
286
306
|
end
|
287
307
|
end
|
288
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
|
+
|
289
329
|
# Returns the number of pages in the document
|
290
330
|
#
|
291
331
|
# pdf = Prawn::Document.new
|
@@ -302,9 +342,9 @@ module Prawn
|
|
302
342
|
#
|
303
343
|
# See Prawn::Document#number_pages for a sample usage of this capability.
|
304
344
|
#
|
305
|
-
def go_to_page(
|
306
|
-
@page_number =
|
307
|
-
state.page = state.pages[
|
345
|
+
def go_to_page(page_number)
|
346
|
+
@page_number = page_number
|
347
|
+
state.page = state.pages[page_number - 1]
|
308
348
|
generate_margin_box
|
309
349
|
@y = @bounding_box.absolute_top
|
310
350
|
end
|
@@ -351,13 +391,13 @@ module Prawn
|
|
351
391
|
# Renders the PDF document to string.
|
352
392
|
# Pass an open file descriptor to render to file.
|
353
393
|
#
|
354
|
-
def render(*
|
394
|
+
def render(*arguments, &block)
|
355
395
|
(1..page_count).each do |i|
|
356
396
|
go_to_page i
|
357
397
|
repeaters.each { |r| r.run(i) }
|
358
398
|
end
|
359
399
|
|
360
|
-
renderer.render(*
|
400
|
+
renderer.render(*arguments, &block)
|
361
401
|
end
|
362
402
|
|
363
403
|
# Renders the PDF document to file.
|
@@ -365,7 +405,7 @@ module Prawn
|
|
365
405
|
# pdf.render_file "foo.pdf"
|
366
406
|
#
|
367
407
|
def render_file(filename)
|
368
|
-
File.open(filename,
|
408
|
+
File.open(filename, 'wb') { |f| render(f) }
|
369
409
|
end
|
370
410
|
|
371
411
|
# The bounds method returns the current bounding box you are currently in,
|
@@ -374,14 +414,15 @@ module Prawn
|
|
374
414
|
# block, the box defined by that call will be returned instead of the
|
375
415
|
# document margin box.
|
376
416
|
#
|
377
|
-
# Another important point about bounding boxes is that all x and
|
378
|
-
# within a bounding box code block are relative to the bottom
|
379
|
-
# 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.
|
380
420
|
#
|
381
421
|
# For example:
|
382
422
|
#
|
383
423
|
# Prawn::Document.new do
|
384
|
-
# # 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
|
385
426
|
#
|
386
427
|
# # Draw a border around the page (the manual way)
|
387
428
|
# stroke do
|
@@ -408,8 +449,8 @@ module Prawn
|
|
408
449
|
|
409
450
|
# Sets Document#bounds to the BoundingBox provided. See above for a brief
|
410
451
|
# description of what a bounding box is. This function is useful if you
|
411
|
-
# really need to change the bounding box manually, but usually, just
|
412
|
-
# 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.
|
413
454
|
#
|
414
455
|
def bounds=(bounding_box)
|
415
456
|
@bounding_box = bounding_box
|
@@ -418,15 +459,15 @@ module Prawn
|
|
418
459
|
# Moves up the document by n points relative to the current position inside
|
419
460
|
# the current bounding box.
|
420
461
|
#
|
421
|
-
def move_up(
|
422
|
-
self.y +=
|
462
|
+
def move_up(amount)
|
463
|
+
self.y += amount
|
423
464
|
end
|
424
465
|
|
425
|
-
# Moves down the document by n points relative to the current position
|
426
|
-
# the current bounding box.
|
466
|
+
# Moves down the document by n points relative to the current position
|
467
|
+
# inside the current bounding box.
|
427
468
|
#
|
428
|
-
def move_down(
|
429
|
-
self.y -=
|
469
|
+
def move_down(amount)
|
470
|
+
self.y -= amount
|
430
471
|
end
|
431
472
|
|
432
473
|
# Moves down the document and then executes a block.
|
@@ -486,50 +527,54 @@ module Prawn
|
|
486
527
|
bounds.indent(left, right, &block)
|
487
528
|
end
|
488
529
|
|
489
|
-
# Places a text box on specified pages for page numbering. This should be
|
490
|
-
# towards the end of document creation, after all your content is
|
491
|
-
# place. In your template string, <page> refers to the current
|
492
|
-
# <total> refers to the total amount of pages in the document.
|
493
|
-
# occur at the end of your Prawn::Document.generate
|
494
|
-
# 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.
|
495
537
|
#
|
496
538
|
# Parameters are:
|
497
539
|
#
|
498
540
|
# <tt>string</tt>:: Template string for page number wording.
|
499
541
|
# Should include '<page>' and, optionally, '<total>'.
|
500
542
|
# <tt>options</tt>:: A hash for page numbering and text box options.
|
501
|
-
# <tt>:page_filter</tt>:: A filter to specify which pages to place page
|
502
|
-
# 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?'
|
503
545
|
# <tt>:start_count_at</tt>:: The starting count to increment pages from.
|
504
|
-
# <tt>:total_pages</tt>:: If provided, will replace <total> with the
|
505
|
-
# Useful to override the total
|
506
|
-
# 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.
|
507
550
|
# <tt>:color</tt>:: Text fill color.
|
508
551
|
#
|
509
|
-
# Please refer to Prawn::Text::text_box for additional options
|
510
|
-
# formatting and placement.
|
511
|
-
#
|
512
|
-
# Example: Print page numbers on every page except for the first. Start counting from
|
513
|
-
# five.
|
552
|
+
# Please refer to Prawn::Text::text_box for additional options
|
553
|
+
# concerning text formatting and placement.
|
514
554
|
#
|
515
|
-
#
|
516
|
-
#
|
517
|
-
#
|
518
|
-
#
|
519
|
-
#
|
520
|
-
#
|
521
|
-
#
|
522
|
-
#
|
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
|
523
568
|
#
|
524
569
|
def number_pages(string, options = {})
|
525
570
|
opts = options.dup
|
526
571
|
start_count_at = opts.delete(:start_count_at).to_i
|
527
572
|
|
528
|
-
if opts.key?(:page_filter)
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
573
|
+
page_filter = if opts.key?(:page_filter)
|
574
|
+
opts.delete(:page_filter)
|
575
|
+
else
|
576
|
+
:all
|
577
|
+
end
|
533
578
|
|
534
579
|
total_pages = opts.delete(:total_pages)
|
535
580
|
txtcolor = opts.delete(:color)
|
@@ -549,12 +594,14 @@ module Prawn
|
|
549
594
|
end
|
550
595
|
if page_match?(page_filter, p)
|
551
596
|
go_to_page(p)
|
552
|
-
# 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
|
553
599
|
fill_color txtcolor unless txtcolor.nil?
|
554
600
|
total_pages = total_pages.nil? ? page_count : total_pages
|
555
|
-
str = string.gsub(
|
601
|
+
str = string.gsub('<page>', pseudopage.to_s)
|
602
|
+
.gsub('<total>', total_pages.to_s)
|
556
603
|
text_box str, opts
|
557
|
-
start_count = true
|
604
|
+
start_count = true # increment page count as soon as first match found
|
558
605
|
end
|
559
606
|
pseudopage += 1 if start_count
|
560
607
|
end
|
@@ -572,21 +619,21 @@ module Prawn
|
|
572
619
|
# the current page or column.
|
573
620
|
#
|
574
621
|
# @private
|
575
|
-
def group(*
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
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'
|
581
628
|
end
|
582
629
|
|
583
630
|
# @private
|
584
631
|
def transaction
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
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'
|
590
637
|
end
|
591
638
|
|
592
639
|
# Provides a way to execute a block of code repeatedly based on a
|
@@ -617,8 +664,8 @@ module Prawn
|
|
617
664
|
# @private
|
618
665
|
|
619
666
|
def mask(*fields)
|
620
|
-
# Stores the current state of the named attributes, executes the block,
|
621
|
-
# 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.
|
622
669
|
# -- I will remove the nodoc if/when this feature is a little less hacky
|
623
670
|
stored = {}
|
624
671
|
fields.each { |f| stored[f] = send(f) }
|
@@ -630,7 +677,7 @@ module Prawn
|
|
630
677
|
|
631
678
|
def initialize_first_page(options)
|
632
679
|
if options[:skip_page_creation]
|
633
|
-
start_new_page(options.merge(:
|
680
|
+
start_new_page(options.merge(orphan: true))
|
634
681
|
else
|
635
682
|
start_new_page(options)
|
636
683
|
end
|
@@ -648,11 +695,11 @@ module Prawn
|
|
648
695
|
|
649
696
|
private
|
650
697
|
|
651
|
-
# setting override_settings to true ensures that a new graphic state does
|
652
|
-
# previous settings.
|
698
|
+
# setting override_settings to true ensures that a new graphic state does
|
699
|
+
# not end up using previous settings.
|
653
700
|
def use_graphic_settings(override_settings = false)
|
654
|
-
set_fill_color if current_fill_color !=
|
655
|
-
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
|
656
703
|
write_line_width if line_width != 1 || override_settings
|
657
704
|
write_stroke_cap_style if cap_style != :butt || override_settings
|
658
705
|
write_stroke_join_style if join_style != :miter || override_settings
|
@@ -661,14 +708,16 @@ module Prawn
|
|
661
708
|
|
662
709
|
def generate_margin_box
|
663
710
|
old_margin_box = @margin_box
|
664
|
-
page
|
711
|
+
page = state.page
|
665
712
|
|
666
713
|
@margin_box = BoundingBox.new(
|
667
714
|
self,
|
668
|
-
nil,
|
669
|
-
[
|
670
|
-
:
|
671
|
-
|
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])
|
672
721
|
)
|
673
722
|
|
674
723
|
# This check maintains indentation settings across page breaks
|
@@ -679,25 +728,23 @@ module Prawn
|
|
679
728
|
|
680
729
|
# we must update bounding box if not flowing from the previous page
|
681
730
|
#
|
682
|
-
@bounding_box = @margin_box unless @bounding_box
|
731
|
+
@bounding_box = @margin_box unless @bounding_box&.parent
|
683
732
|
end
|
684
733
|
|
685
734
|
def apply_margin_options(options)
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
[
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
state.page.margins[side] = margin
|
700
|
-
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
|
701
748
|
end
|
702
749
|
end
|
703
750
|
|