prawn 2.1.0 → 2.2.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 +4 -4
- checksums.yaml.gz.sig +2 -0
- data.tar.gz.sig +0 -0
- data/Gemfile +1 -9
- data/Rakefile +12 -22
- data/lib/prawn.rb +29 -48
- data/lib/prawn/document.rb +148 -123
- data/lib/prawn/document/bounding_box.rb +33 -26
- data/lib/prawn/document/column_box.rb +5 -7
- data/lib/prawn/document/internals.rb +6 -6
- data/lib/prawn/document/span.rb +20 -17
- data/lib/prawn/encoding.rb +65 -67
- data/lib/prawn/errors.rb +10 -7
- data/lib/prawn/font.rb +78 -62
- data/lib/prawn/font/afm.rb +93 -66
- data/lib/prawn/font/dfont.rb +2 -10
- data/lib/prawn/font/ttc.rb +34 -0
- data/lib/prawn/font/ttf.rb +73 -65
- data/lib/prawn/font_metric_cache.rb +9 -8
- data/lib/prawn/graphics.rb +110 -70
- data/lib/prawn/graphics/blend_mode.rb +7 -8
- data/lib/prawn/graphics/cap_style.rb +2 -4
- data/lib/prawn/graphics/color.rb +23 -26
- data/lib/prawn/graphics/dash.rb +22 -12
- data/lib/prawn/graphics/join_style.rb +8 -4
- data/lib/prawn/graphics/patterns.rb +185 -96
- data/lib/prawn/graphics/transformation.rb +11 -9
- data/lib/prawn/graphics/transparency.rb +15 -13
- data/lib/prawn/grid.rb +20 -20
- data/lib/prawn/image_handler.rb +4 -6
- data/lib/prawn/images.rb +22 -15
- data/lib/prawn/images/image.rb +0 -1
- data/lib/prawn/images/jpg.rb +26 -22
- data/lib/prawn/images/png.rb +60 -57
- data/lib/prawn/measurement_extensions.rb +8 -9
- data/lib/prawn/measurements.rb +14 -15
- data/lib/prawn/outline.rb +96 -78
- data/lib/prawn/repeater.rb +12 -10
- data/lib/prawn/security.rb +66 -48
- data/lib/prawn/security/arcfour.rb +1 -3
- data/lib/prawn/soft_mask.rb +23 -25
- data/lib/prawn/stamp.rb +16 -12
- data/lib/prawn/text.rb +59 -45
- data/lib/prawn/text/box.rb +9 -8
- data/lib/prawn/text/formatted.rb +4 -6
- data/lib/prawn/text/formatted/arranger.rb +51 -30
- data/lib/prawn/text/formatted/box.rb +112 -88
- data/lib/prawn/text/formatted/fragment.rb +10 -15
- data/lib/prawn/text/formatted/line_wrap.rb +118 -61
- data/lib/prawn/text/formatted/parser.rb +134 -110
- data/lib/prawn/text/formatted/wrap.rb +42 -32
- data/lib/prawn/transformation_stack.rb +3 -4
- data/lib/prawn/utilities.rb +6 -21
- data/lib/prawn/version.rb +1 -3
- data/lib/prawn/view.rb +4 -2
- data/manual/basic_concepts/adding_pages.rb +4 -7
- data/manual/basic_concepts/basic_concepts.rb +29 -22
- data/manual/basic_concepts/creation.rb +8 -11
- data/manual/basic_concepts/cursor.rb +2 -5
- data/manual/basic_concepts/measurement.rb +3 -6
- data/manual/basic_concepts/origin.rb +3 -6
- data/manual/basic_concepts/other_cursor_helpers.rb +9 -12
- data/manual/basic_concepts/view.rb +20 -16
- data/manual/bounding_box/bounding_box.rb +27 -24
- data/manual/bounding_box/bounds.rb +9 -12
- data/manual/bounding_box/canvas.rb +2 -5
- data/manual/bounding_box/creation.rb +4 -7
- data/manual/bounding_box/indentation.rb +12 -15
- data/manual/bounding_box/nesting.rb +22 -17
- data/manual/bounding_box/russian_boxes.rb +8 -9
- data/manual/bounding_box/stretchy.rb +10 -13
- data/manual/contents.rb +26 -22
- data/manual/cover.rb +22 -20
- data/manual/document_and_page_options/background.rb +9 -13
- data/manual/document_and_page_options/document_and_page_options.rb +23 -20
- data/manual/document_and_page_options/metadata.rb +16 -16
- data/manual/document_and_page_options/page_margins.rb +16 -20
- data/manual/document_and_page_options/page_size.rb +11 -12
- data/manual/document_and_page_options/print_scaling.rb +15 -15
- data/manual/example_helper.rb +2 -4
- data/manual/graphics/blend_mode.rb +10 -9
- data/manual/graphics/circle_and_ellipse.rb +2 -5
- data/manual/graphics/color.rb +5 -9
- data/manual/graphics/common_lines.rb +5 -8
- data/manual/graphics/fill_and_stroke.rb +2 -5
- data/manual/graphics/fill_rules.rb +7 -10
- data/manual/graphics/gradients.rb +25 -21
- data/manual/graphics/graphics.rb +49 -43
- data/manual/graphics/helper.rb +10 -9
- data/manual/graphics/line_width.rb +5 -7
- data/manual/graphics/lines_and_curves.rb +5 -8
- data/manual/graphics/polygon.rb +4 -8
- data/manual/graphics/rectangle.rb +2 -5
- data/manual/graphics/rotate.rb +4 -7
- data/manual/graphics/scale.rb +12 -15
- data/manual/graphics/soft_masks.rb +1 -4
- data/manual/graphics/stroke_cap.rb +3 -6
- data/manual/graphics/stroke_dash.rb +9 -12
- data/manual/graphics/stroke_join.rb +2 -5
- data/manual/graphics/translate.rb +7 -10
- data/manual/graphics/transparency.rb +5 -8
- data/manual/how_to_read_this_manual.rb +4 -6
- data/manual/images/absolute_position.rb +4 -7
- data/manual/images/fit.rb +5 -8
- data/manual/images/horizontal.rb +6 -9
- data/manual/images/images.rb +25 -23
- data/manual/images/plain_image.rb +3 -6
- data/manual/images/scale.rb +7 -10
- data/manual/images/vertical.rb +10 -13
- data/manual/images/width_and_height.rb +8 -11
- data/manual/layout/boxes.rb +3 -6
- data/manual/layout/content.rb +5 -8
- data/manual/layout/layout.rb +16 -16
- data/manual/layout/simple_grid.rb +4 -7
- data/manual/outline/add_subsection_to.rb +18 -21
- data/manual/outline/insert_section_after.rb +13 -16
- data/manual/outline/outline.rb +19 -17
- data/manual/outline/sections_and_pages.rb +15 -18
- data/manual/repeatable_content/alternate_page_numbering.rb +19 -17
- data/manual/repeatable_content/page_numbering.rb +15 -16
- data/manual/repeatable_content/repeatable_content.rb +23 -19
- data/manual/repeatable_content/repeater.rb +12 -15
- data/manual/repeatable_content/stamp.rb +12 -15
- data/manual/security/encryption.rb +7 -10
- data/manual/security/permissions.rb +17 -14
- data/manual/security/security.rb +17 -16
- data/manual/table.rb +2 -4
- data/manual/text/alignment.rb +14 -17
- data/manual/text/color.rb +10 -11
- data/manual/text/column_box.rb +5 -8
- data/manual/text/fallback_fonts.rb +23 -21
- data/manual/text/font.rb +9 -12
- data/manual/text/font_size.rb +11 -14
- data/manual/text/font_style.rb +4 -7
- data/manual/text/formatted_callbacks.rb +23 -21
- data/manual/text/formatted_text.rb +31 -25
- data/manual/text/free_flowing_text.rb +18 -21
- data/manual/text/inline.rb +16 -19
- data/manual/text/kerning_and_character_spacing.rb +12 -15
- data/manual/text/leading.rb +5 -8
- data/manual/text/line_wrapping.rb +33 -17
- data/manual/text/paragraph_indentation.rb +11 -14
- data/manual/text/positioned_text.rb +13 -16
- data/manual/text/registering_families.rb +16 -19
- data/manual/text/rendering_and_color.rb +7 -10
- data/manual/text/right_to_left_text.rb +24 -19
- data/manual/text/rotation.rb +26 -23
- data/manual/text/single_usage.rb +6 -9
- data/manual/text/text.rb +56 -52
- data/manual/text/text_box_excess.rb +18 -17
- data/manual/text/text_box_extensions.rb +16 -15
- data/manual/text/text_box_overflow.rb +15 -18
- data/manual/text/utf8.rb +9 -12
- data/manual/text/win_ansi_charset.rb +18 -19
- data/prawn.gemspec +37 -27
- data/spec/extensions/encoding_helpers.rb +0 -2
- data/spec/manual_spec.rb +33 -0
- data/spec/prawn/document/bounding_box_spec.rb +546 -0
- data/spec/prawn/document/column_box_spec.rb +73 -0
- data/spec/prawn/document/security_spec.rb +173 -0
- data/spec/prawn/document_annotations_spec.rb +74 -0
- data/spec/prawn/document_destinations_spec.rb +13 -0
- data/spec/prawn/document_grid_spec.rb +96 -0
- data/spec/prawn/document_reference_spec.rb +25 -0
- data/spec/prawn/document_span_spec.rb +34 -0
- data/spec/prawn/document_spec.rb +751 -0
- data/spec/prawn/font_metric_cache_spec.rb +52 -0
- data/spec/prawn/font_spec.rb +513 -0
- data/spec/prawn/graphics/blend_mode_spec.rb +61 -0
- data/spec/prawn/graphics/transparency_spec.rb +79 -0
- data/spec/prawn/graphics_spec.rb +817 -0
- data/spec/prawn/graphics_stroke_styles_spec.rb +227 -0
- data/spec/{image_handler_spec.rb → prawn/image_handler_spec.rb} +13 -15
- data/spec/prawn/images/jpg_spec.rb +18 -0
- data/spec/prawn/images/png_spec.rb +281 -0
- data/spec/prawn/images_spec.rb +170 -0
- data/spec/prawn/measurements_extensions_spec.rb +22 -0
- data/spec/prawn/outline_spec.rb +408 -0
- data/spec/prawn/repeater_spec.rb +163 -0
- data/spec/prawn/soft_mask_spec.rb +72 -0
- data/spec/prawn/stamp_spec.rb +168 -0
- data/spec/prawn/text/box_spec.rb +1113 -0
- data/spec/prawn/text/formatted/arranger_spec.rb +464 -0
- data/spec/prawn/text/formatted/box_spec.rb +825 -0
- data/spec/prawn/text/formatted/fragment_spec.rb +341 -0
- data/spec/prawn/text/formatted/line_wrap_spec.rb +491 -0
- data/spec/prawn/text/formatted/parser_spec.rb +667 -0
- data/spec/prawn/text_draw_text_spec.rb +147 -0
- data/spec/prawn/text_rendering_mode_spec.rb +42 -0
- data/spec/prawn/text_spacing_spec.rb +93 -0
- data/spec/prawn/text_spec.rb +601 -0
- data/spec/prawn/text_with_inline_formatting_spec.rb +33 -0
- data/spec/{transformation_stack_spec.rb → prawn/transformation_stack_spec.rb} +21 -20
- data/spec/prawn/view_spec.rb +45 -0
- data/spec/spec_helper.rb +16 -16
- metadata +96 -151
- metadata.gz.sig +1 -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
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# measurement_extensions.rb: Core extensions for Prawn::Measurements
|
3
2
|
#
|
4
3
|
# Copyright December 2008, Florian Witteler. All Rights Reserved.
|
@@ -17,34 +16,34 @@ class Numeric
|
|
17
16
|
# @group Experimental API
|
18
17
|
|
19
18
|
def mm
|
20
|
-
|
19
|
+
mm2pt(self)
|
21
20
|
end
|
22
21
|
|
23
22
|
def cm
|
24
|
-
|
23
|
+
cm2pt(self)
|
25
24
|
end
|
26
25
|
|
27
26
|
def dm
|
28
|
-
|
27
|
+
dm2pt(self)
|
29
28
|
end
|
30
29
|
|
31
30
|
def m
|
32
|
-
|
31
|
+
m2pt(self)
|
33
32
|
end
|
34
33
|
|
35
34
|
def in
|
36
|
-
|
35
|
+
in2pt(self)
|
37
36
|
end
|
38
37
|
|
39
38
|
def yd
|
40
|
-
|
39
|
+
yd2pt(self)
|
41
40
|
end
|
42
41
|
|
43
42
|
def ft
|
44
|
-
|
43
|
+
ft2pt(self)
|
45
44
|
end
|
46
45
|
|
47
46
|
def pt
|
48
|
-
|
47
|
+
pt2pt(self)
|
49
48
|
end
|
50
49
|
end
|
data/lib/prawn/measurements.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# measurements.rb: Conversions from other measurements to PDF points
|
3
2
|
#
|
4
3
|
# Copyright December 2008, Florian Witteler. All Rights Reserved.
|
@@ -9,62 +8,62 @@ module Prawn
|
|
9
8
|
module Measurements
|
10
9
|
# metric conversions
|
11
10
|
def cm2mm(cm)
|
12
|
-
|
11
|
+
cm * 10
|
13
12
|
end
|
14
13
|
|
15
14
|
def dm2mm(dm)
|
16
|
-
|
15
|
+
dm * 100
|
17
16
|
end
|
18
17
|
|
19
18
|
def m2mm(m)
|
20
|
-
|
19
|
+
m * 1000
|
21
20
|
end
|
22
21
|
|
23
22
|
# imperial conversions
|
24
23
|
# from http://en.wikipedia.org/wiki/Imperial_units
|
25
24
|
def ft2in(ft)
|
26
|
-
|
25
|
+
ft * 12
|
27
26
|
end
|
28
27
|
|
29
28
|
def yd2in(yd)
|
30
|
-
|
29
|
+
yd * 36
|
31
30
|
end
|
32
31
|
|
33
32
|
# PostscriptPoint-converisons
|
34
33
|
def pt2pt(pt)
|
35
|
-
|
34
|
+
pt
|
36
35
|
end
|
37
36
|
|
38
37
|
def in2pt(inch)
|
39
|
-
|
38
|
+
inch * 72
|
40
39
|
end
|
41
40
|
|
42
41
|
def ft2pt(ft)
|
43
|
-
|
42
|
+
in2pt(ft2in(ft))
|
44
43
|
end
|
45
44
|
|
46
45
|
def yd2pt(yd)
|
47
|
-
|
46
|
+
in2pt(yd2in(yd))
|
48
47
|
end
|
49
48
|
|
50
49
|
def mm2pt(mm)
|
51
|
-
|
50
|
+
mm * (72 / 25.4)
|
52
51
|
end
|
53
52
|
|
54
53
|
def cm2pt(cm)
|
55
|
-
|
54
|
+
mm2pt(cm2mm(cm))
|
56
55
|
end
|
57
56
|
|
58
57
|
def dm2pt(dm)
|
59
|
-
|
58
|
+
mm2pt(dm2mm(dm))
|
60
59
|
end
|
61
60
|
|
62
61
|
def m2pt(m)
|
63
|
-
|
62
|
+
mm2pt(m2mm(m))
|
64
63
|
end
|
65
64
|
|
66
65
|
def pt2mm(pt)
|
67
|
-
|
66
|
+
pt * 1 / mm2pt(1) # (25.4 / 72)
|
68
67
|
end
|
69
68
|
end
|
70
69
|
end
|
data/lib/prawn/outline.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
module Prawn
|
4
2
|
class Document
|
5
3
|
# @group Stable API
|
6
4
|
|
7
|
-
# Lazily instantiates a Prawn::Outline object for document. This is used as
|
8
|
-
# to methods to build the outline tree for a document's table
|
5
|
+
# Lazily instantiates a Prawn::Outline object for document. This is used as
|
6
|
+
# point of entry to methods to build the outline tree for a document's table
|
7
|
+
# of contents.
|
9
8
|
def outline
|
10
9
|
@outline ||= Outline.new(self)
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
14
13
|
# The Outline class organizes the outline tree items for the document.
|
15
|
-
# Note that the prev and parent instance variables are adjusted while
|
16
|
-
# through the nested blocks. These variables along with the
|
17
|
-
# of blocks are the primary means by which the relations
|
18
|
-
# OutlineItems and the OutlineRoot are set. Unfortunately, the
|
19
|
-
# understand how this works is to follow the method calls through
|
14
|
+
# Note that the prev and parent instance variables are adjusted while
|
15
|
+
# navigating through the nested blocks. These variables along with the
|
16
|
+
# presence or absense of blocks are the primary means by which the relations
|
17
|
+
# for the various OutlineItems and the OutlineRoot are set. Unfortunately, the
|
18
|
+
# best way to understand how this works is to follow the method calls through
|
19
|
+
# a real example.
|
20
20
|
#
|
21
|
-
# Some ideas for the organization of this class were gleaned from name_tree.
|
22
|
-
# particular the way in which the OutlineItems are finally rendered into
|
23
|
-
# objects in PdfObject through a hash.
|
21
|
+
# Some ideas for the organization of this class were gleaned from name_tree.
|
22
|
+
# In particular the way in which the OutlineItems are finally rendered into
|
23
|
+
# document objects in PdfObject through a hash.
|
24
24
|
#
|
25
25
|
class Outline
|
26
26
|
# @private
|
@@ -42,10 +42,11 @@ module Prawn
|
|
42
42
|
|
43
43
|
# Defines/Updates an outline for the document.
|
44
44
|
# The outline is an optional nested index that appears on the side of a PDF
|
45
|
-
# document usually with direct links to pages. The outline DSL is defined by
|
46
|
-
# blocks involving two methods: section and page; see the
|
47
|
-
# for their arguments and options. Note that
|
48
|
-
# to add more sections to the end of the
|
45
|
+
# document usually with direct links to pages. The outline DSL is defined by
|
46
|
+
# nested blocks involving two methods: section and page; see the
|
47
|
+
# documentation on those methods for their arguments and options. Note that
|
48
|
+
# one can also use outline#update to add more sections to the end of the
|
49
|
+
# outline tree using the same syntax and scope.
|
49
50
|
#
|
50
51
|
# The syntax is best illustrated with an example:
|
51
52
|
#
|
@@ -69,28 +70,31 @@ module Prawn
|
|
69
70
|
# end
|
70
71
|
#
|
71
72
|
def define(&block)
|
72
|
-
instance_eval(&block)
|
73
|
+
instance_eval(&block) if block
|
73
74
|
end
|
74
75
|
|
75
|
-
alias
|
76
|
+
alias update define
|
76
77
|
|
77
78
|
# Inserts an outline section to the outline tree (see outline#define).
|
78
79
|
# Although you will probably choose to exclusively use outline#define so
|
79
|
-
# that your outline tree is contained and easy to manage, this method
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
80
|
+
# that your outline tree is contained and easy to manage, this method gives
|
81
|
+
# you the option to insert sections to the outline tree at any point during
|
82
|
+
# document generation. This method allows you to add a child subsection to
|
83
|
+
# any other item at any level in the outline tree. Currently the only way
|
84
|
+
# to locate the place of entry is with the title for the item. If your title
|
85
|
+
# names are not unique consider using define_outline.
|
85
86
|
# The method takes the following arguments:
|
86
|
-
# title: a string that must match an outline title to add
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
87
|
+
# title: a string that must match an outline title to add
|
88
|
+
# the subsection to
|
89
|
+
# position: either :first or :last (the default) where the subsection will
|
90
|
+
# be placed relative to other child elements. If you need to position
|
91
|
+
# your subsection in between other elements then consider using
|
92
|
+
# #insert_section_after
|
90
93
|
# block: uses the same DSL syntax as outline#define, for example:
|
91
94
|
#
|
92
|
-
# Consider using this method inside of outline.update if you want to have
|
93
|
-
# to be scoped as self (see #insert_section_after
|
95
|
+
# Consider using this method inside of outline.update if you want to have
|
96
|
+
# the outline object to be scoped as self (see #insert_section_after
|
97
|
+
# example).
|
94
98
|
#
|
95
99
|
# go_to_page 2
|
96
100
|
# start_new_page
|
@@ -101,8 +105,10 @@ module Prawn
|
|
101
105
|
#
|
102
106
|
def add_subsection_to(title, position = :last, &block)
|
103
107
|
@parent = items[title]
|
104
|
-
|
105
|
-
|
108
|
+
unless @parent
|
109
|
+
raise Prawn::Errors::UnknownOutlineTitle,
|
110
|
+
"\n No outline item with title: '#{title}' exists in the outline tree"
|
111
|
+
end
|
106
112
|
@prev = position == :first ? nil : @parent.data.last
|
107
113
|
nxt = position == :first ? @parent.data.first : nil
|
108
114
|
insert_section(nxt, &block)
|
@@ -110,12 +116,13 @@ module Prawn
|
|
110
116
|
|
111
117
|
# Inserts an outline section to the outline tree (see outline#define).
|
112
118
|
# Although you will probably choose to exclusively use outline#define so
|
113
|
-
# that your outline tree is contained and easy to manage, this method
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
# Currently the only way to locate the place of entry is with the title for
|
118
|
-
# item. If your title names are not unique consider using
|
119
|
+
# that your outline tree is contained and easy to manage, this method gives
|
120
|
+
# you the option to insert sections to the outline tree at any point during
|
121
|
+
# document generation. Unlike outline.add_section, this method allows you to
|
122
|
+
# enter a section after any other item at any level in the outline tree.
|
123
|
+
# Currently the only way to locate the place of entry is with the title for
|
124
|
+
# the item. If your title names are not unique consider using
|
125
|
+
# define_outline.
|
119
126
|
# The method takes the following arguments:
|
120
127
|
# title: the title of other section or page to insert new section after
|
121
128
|
# block: uses the same DSL syntax as outline#define, for example:
|
@@ -131,30 +138,36 @@ module Prawn
|
|
131
138
|
#
|
132
139
|
def insert_section_after(title, &block)
|
133
140
|
@prev = items[title]
|
134
|
-
|
135
|
-
|
141
|
+
unless @prev
|
142
|
+
raise Prawn::Errors::UnknownOutlineTitle,
|
143
|
+
"\n No outline item with title: '#{title}' exists in the outline tree"
|
144
|
+
end
|
136
145
|
@parent = @prev.data.parent
|
137
146
|
nxt = @prev.data.next
|
138
147
|
insert_section(nxt, &block)
|
139
148
|
end
|
140
149
|
|
141
|
-
# See outline#define above for documentation on how this is used in that
|
150
|
+
# See outline#define above for documentation on how this is used in that
|
151
|
+
# context
|
142
152
|
#
|
143
153
|
# Adds an outine section to the outline tree.
|
144
154
|
# Although you will probably choose to exclusively use outline#define so
|
145
|
-
# that your outline tree is contained and easy to manage, this method
|
146
|
-
#
|
147
|
-
#
|
148
|
-
# the section will be added at the top level after the other root
|
149
|
-
# For more flexible placement try using
|
150
|
-
# outline#add_subsection_to
|
155
|
+
# that your outline tree is contained and easy to manage, this method gives
|
156
|
+
# you the option to add sections to the outline tree at any point during
|
157
|
+
# document generation. When not being called from within another #section
|
158
|
+
# block the section will be added at the top level after the other root
|
159
|
+
# elements of the outline. For more flexible placement try using
|
160
|
+
# outline#insert_section_after and/or outline#add_subsection_to
|
161
|
+
#
|
151
162
|
# Takes the following arguments:
|
152
163
|
# title: the outline text that appears for the section.
|
153
|
-
# options: destination - optional integer defining the page number for
|
154
|
-
#
|
155
|
-
#
|
156
|
-
#
|
157
|
-
#
|
164
|
+
# options: destination - optional integer defining the page number for
|
165
|
+
# a destination link to the top of the page (using a :FIT
|
166
|
+
# destination).
|
167
|
+
# - or an array with a custom destination (see the #dest_*
|
168
|
+
# methods of the PDF::Destination module)
|
169
|
+
# closed - whether the section should show its nested outline
|
170
|
+
# elements.
|
158
171
|
# - defaults to false.
|
159
172
|
# block: more nested subsections and/or page blocks
|
160
173
|
#
|
@@ -167,36 +180,40 @@ module Prawn
|
|
167
180
|
add_outline_item(title, options, &block)
|
168
181
|
end
|
169
182
|
|
170
|
-
# See Outline#define above for more documentation on how it is used in that
|
183
|
+
# See Outline#define above for more documentation on how it is used in that
|
184
|
+
# context
|
171
185
|
#
|
172
186
|
# Adds a page to the outline.
|
173
187
|
# Although you will probably choose to exclusively use outline#define so
|
174
188
|
# that your outline tree is contained and easy to manage, this method also
|
175
189
|
# gives you the option to add pages to the root of outline tree at any point
|
176
|
-
# during document generation. Note that the page will be added at the
|
177
|
-
#
|
178
|
-
# using outline#insert_section_after and/or outline#add_subsection_to.
|
190
|
+
# during document generation. Note that the page will be added at the top
|
191
|
+
# level after the other root outline elements. For more flexible placement
|
192
|
+
# try using outline#insert_section_after and/or outline#add_subsection_to.
|
179
193
|
#
|
180
194
|
# Takes the following arguments:
|
181
|
-
#
|
182
|
-
#
|
183
|
-
#
|
184
|
-
#
|
185
|
-
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
195
|
+
# options:
|
196
|
+
# title - REQUIRED. The outline text that appears for the page.
|
197
|
+
# destination - optional integer defining the page number for
|
198
|
+
# a destination link to the top of the page (using a :FIT
|
199
|
+
# destination).
|
200
|
+
# or an array with a custom destination (see the dest_* methods
|
201
|
+
# of the PDF::Destination module)
|
202
|
+
# closed - whether the section should show its nested outline elements.
|
203
|
+
# - defaults to false.
|
189
204
|
# example usage:
|
190
205
|
#
|
191
206
|
# outline.page :title => "Very Last Page"
|
192
|
-
#
|
193
|
-
#
|
207
|
+
#
|
208
|
+
# Note: this method is almost identical to section except that it does not
|
209
|
+
# accept a block thereby defining the outline item as a leaf on the outline
|
210
|
+
# tree structure.
|
194
211
|
def page(options = {})
|
195
212
|
if options[:title]
|
196
213
|
title = options[:title]
|
197
214
|
else
|
198
|
-
|
199
|
-
|
215
|
+
raise Prawn::Errors::RequiredOption,
|
216
|
+
"\nTitle is a required option for page"
|
200
217
|
end
|
201
218
|
add_outline_item(title, options)
|
202
219
|
end
|
@@ -207,15 +224,16 @@ module Prawn
|
|
207
224
|
# lazily initialized, so that documents that do not have an outline
|
208
225
|
# do not incur the additional overhead.
|
209
226
|
def root
|
210
|
-
document.state.store.root.data[:Outlines] ||=
|
227
|
+
document.state.store.root.data[:Outlines] ||=
|
228
|
+
document.ref!(PDF::Core::OutlineRoot.new)
|
211
229
|
end
|
212
230
|
|
213
231
|
def add_outline_item(title, options, &block)
|
214
232
|
outline_item = create_outline_item(title, options)
|
215
|
-
|
233
|
+
establish_relations(outline_item)
|
216
234
|
increase_count
|
217
235
|
set_variables_for_block(outline_item, block)
|
218
|
-
|
236
|
+
yield if block
|
219
237
|
reset_parent(outline_item)
|
220
238
|
end
|
221
239
|
|
@@ -234,7 +252,7 @@ module Prawn
|
|
234
252
|
items[title] = document.ref!(outline_item)
|
235
253
|
end
|
236
254
|
|
237
|
-
def
|
255
|
+
def establish_relations(outline_item)
|
238
256
|
prev.data.next = outline_item if prev
|
239
257
|
parent.data.first = outline_item unless prev
|
240
258
|
parent.data.last = outline_item
|
@@ -244,11 +262,11 @@ module Prawn
|
|
244
262
|
counting_parent = parent
|
245
263
|
while counting_parent
|
246
264
|
counting_parent.data.count += 1
|
247
|
-
if counting_parent == root
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
265
|
+
counting_parent = if counting_parent == root
|
266
|
+
nil
|
267
|
+
else
|
268
|
+
counting_parent.data.parent
|
269
|
+
end
|
252
270
|
end
|
253
271
|
end
|
254
272
|
|
@@ -267,7 +285,7 @@ module Prawn
|
|
267
285
|
def insert_section(nxt, &block)
|
268
286
|
last = @parent.data.last
|
269
287
|
if block
|
270
|
-
|
288
|
+
yield
|
271
289
|
end
|
272
290
|
adjust_relations(nxt, last)
|
273
291
|
reset_root_positioning
|
data/lib/prawn/repeater.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
1
|
# repeater.rb : Implements repeated page elements.
|
4
2
|
# Heavy inspired by repeating_element() in PDF::Wrapper
|
5
3
|
# http://pdf-wrapper.rubyforge.org/
|
@@ -20,9 +18,9 @@ module Prawn
|
|
20
18
|
|
21
19
|
# @group Experimental API
|
22
20
|
|
23
|
-
# Provides a way to execute a block of code repeatedly based on
|
24
|
-
# page_filter. Since Stamp is used under the hood, this method is very
|
25
|
-
# efficient.
|
21
|
+
# Provides a way to execute a block of code repeatedly based on
|
22
|
+
# a page_filter. Since Stamp is used under the hood, this method is very
|
23
|
+
# space efficient.
|
26
24
|
#
|
27
25
|
# Available page filters are:
|
28
26
|
# :all -- repeats on every page
|
@@ -32,8 +30,9 @@ module Prawn
|
|
32
30
|
# some_range -- repeats on every page included in the range
|
33
31
|
# some_lambda -- yields page number and repeats for true return values
|
34
32
|
#
|
35
|
-
# Also accepts an optional second argument for dynamic content which
|
36
|
-
# in the context of the filtered pages without using
|
33
|
+
# Also accepts an optional second argument for dynamic content which
|
34
|
+
# executes the code in the context of the filtered pages without using
|
35
|
+
# a Stamp.
|
37
36
|
#
|
38
37
|
# Example:
|
39
38
|
#
|
@@ -75,7 +74,10 @@ module Prawn
|
|
75
74
|
# end
|
76
75
|
#
|
77
76
|
def repeat(page_filter, options = {}, &block)
|
78
|
-
|
77
|
+
dynamic = options.fetch(:dynamic, false)
|
78
|
+
repeaters << Prawn::Repeater.new(
|
79
|
+
self, page_filter, dynamic, &block
|
80
|
+
)
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
@@ -91,10 +93,10 @@ module Prawn
|
|
91
93
|
attr_reader :name
|
92
94
|
|
93
95
|
def initialize(document, page_filter, dynamic = false, &block)
|
94
|
-
@document
|
96
|
+
@document = document
|
95
97
|
@page_filter = page_filter
|
96
98
|
@dynamic = dynamic
|
97
|
-
@stamp_name
|
99
|
+
@stamp_name = "prawn_repeater(#{Repeater.count})"
|
98
100
|
@document.create_stamp(@stamp_name, &block) unless dynamic
|
99
101
|
@block = block if dynamic
|
100
102
|
@graphic_state = document.state.page.graphic_state.dup
|