prawn 2.1.0 → 2.4.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 +9 -41
- data/lib/prawn.rb +37 -49
- data/lib/prawn/document.rb +193 -141
- data/lib/prawn/document/bounding_box.rb +50 -30
- data/lib/prawn/document/column_box.rb +7 -7
- data/lib/prawn/document/internals.rb +8 -6
- data/lib/prawn/document/span.rb +22 -16
- data/lib/prawn/encoding.rb +69 -68
- data/lib/prawn/errors.rb +12 -7
- data/lib/prawn/font.rb +104 -69
- data/lib/prawn/font_metric_cache.rb +20 -13
- data/lib/prawn/{font → fonts}/afm.rb +108 -72
- 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 +126 -81
- 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 +43 -39
- data/lib/prawn/graphics/dash.rb +23 -11
- data/lib/prawn/graphics/join_style.rb +9 -3
- data/lib/prawn/graphics/patterns.rb +204 -102
- data/lib/prawn/graphics/transformation.rb +15 -9
- data/lib/prawn/graphics/transparency.rb +17 -13
- data/lib/prawn/grid.rb +84 -48
- data/lib/prawn/image_handler.rb +5 -5
- data/lib/prawn/images.rb +60 -49
- data/lib/prawn/images/image.rb +2 -1
- data/lib/prawn/images/jpg.rb +31 -22
- data/lib/prawn/images/png.rb +67 -63
- data/lib/prawn/measurement_extensions.rb +10 -9
- data/lib/prawn/measurements.rb +19 -15
- data/lib/prawn/outline.rb +98 -77
- data/lib/prawn/repeater.rb +15 -11
- data/lib/prawn/security.rb +93 -70
- 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 +76 -60
- data/lib/prawn/text/box.rb +18 -14
- data/lib/prawn/text/formatted.rb +5 -5
- data/lib/prawn/text/formatted/arranger.rb +80 -40
- data/lib/prawn/text/formatted/box.rb +140 -101
- data/lib/prawn/text/formatted/fragment.rb +11 -14
- data/lib/prawn/text/formatted/line_wrap.rb +128 -67
- data/lib/prawn/text/formatted/parser.rb +147 -123
- data/lib/prawn/text/formatted/wrap.rb +48 -32
- 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 +7 -8
- 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 +7 -8
- data/manual/bounding_box/creation.rb +6 -7
- data/manual/bounding_box/indentation.rb +14 -15
- data/manual/bounding_box/nesting.rb +25 -18
- 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 +15 -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 +18 -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 +5 -6
- data/manual/graphics/fill_rules.rb +10 -10
- data/manual/graphics/gradients.rb +27 -21
- data/manual/graphics/graphics.rb +48 -40
- data/manual/graphics/helper.rb +19 -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 +15 -16
- data/manual/graphics/stroke_join.rb +5 -6
- data/manual/graphics/translate.rb +10 -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 +10 -11
- 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 +16 -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 +21 -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 +10 -8
- data/manual/text/formatted_callbacks.rb +33 -24
- data/manual/text/formatted_text.rb +36 -25
- data/manual/text/free_flowing_text.rb +22 -23
- 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 +12 -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 +33 -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 +20 -19
- data/manual/text/utf8.rb +11 -12
- data/manual/text/win_ansi_charset.rb +27 -25
- data/prawn.gemspec +41 -34
- data/spec/extensions/encoding_helpers.rb +3 -3
- data/spec/prawn/document/bounding_box_spec.rb +550 -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 +44 -0
- data/spec/prawn/document_spec.rb +805 -0
- data/spec/prawn/font_metric_cache_spec.rb +54 -0
- data/spec/prawn/font_spec.rb +544 -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 +872 -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 +229 -0
- data/spec/prawn/measurements_extensions_spec.rb +24 -0
- data/spec/prawn/outline_spec.rb +512 -0
- data/spec/prawn/repeater_spec.rb +166 -0
- data/spec/prawn/soft_mask_spec.rb +74 -0
- data/spec/prawn/stamp_spec.rb +173 -0
- data/spec/prawn/text/box_spec.rb +1110 -0
- data/spec/prawn/text/formatted/arranger_spec.rb +466 -0
- data/spec/prawn/text/formatted/box_spec.rb +849 -0
- data/spec/prawn/text/formatted/fragment_spec.rb +343 -0
- data/spec/prawn/text/formatted/line_wrap_spec.rb +495 -0
- data/spec/prawn/text/formatted/parser_spec.rb +697 -0
- data/spec/prawn/text_draw_text_spec.rb +150 -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 +102 -222
- metadata.gz.sig +0 -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,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Implementation of the "ARCFOUR" algorithm ("alleged RC4 (tm)"). Implemented
|
4
4
|
# as described at:
|
@@ -39,7 +39,7 @@ class Arcfour
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def encrypt(string)
|
42
|
-
string.unpack('c*').map{ |byte| byte ^ key_byte }.pack('c*')
|
42
|
+
string.unpack('c*').map { |byte| byte ^ key_byte }.pack('c*')
|
43
43
|
end
|
44
44
|
|
45
45
|
private
|
data/lib/prawn/soft_mask.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
3
|
# soft_mask.rb : Implements soft-masking
|
4
4
|
#
|
5
5
|
# Copyright September 2012, Alexander Mankuta. All Rights Reserved.
|
@@ -31,51 +31,51 @@ module Prawn
|
|
31
31
|
renderer.min_version(1.4)
|
32
32
|
|
33
33
|
group_attrs = ref!(
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
34
|
+
Type: :Group,
|
35
|
+
S: :Transparency,
|
36
|
+
CS: :DeviceRGB,
|
37
|
+
I: false,
|
38
|
+
K: false
|
39
39
|
)
|
40
40
|
|
41
41
|
group = ref!(
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
42
|
+
Type: :XObject,
|
43
|
+
Subtype: :Form,
|
44
|
+
BBox: state.page.dimensions,
|
45
|
+
Group: group_attrs
|
46
46
|
)
|
47
47
|
|
48
48
|
state.page.stamp_stream(group, &block)
|
49
49
|
|
50
50
|
mask = ref!(
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
51
|
+
Type: :Mask,
|
52
|
+
S: :Luminosity,
|
53
|
+
G: group
|
54
54
|
)
|
55
55
|
|
56
56
|
g_state = ref!(
|
57
|
-
:
|
58
|
-
:
|
57
|
+
Type: :ExtGState,
|
58
|
+
SMask: mask,
|
59
59
|
|
60
|
-
:
|
61
|
-
:
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
65
|
-
:
|
60
|
+
AIS: false,
|
61
|
+
BM: :Normal,
|
62
|
+
OP: false,
|
63
|
+
op: false,
|
64
|
+
OPM: 1,
|
65
|
+
SA: true
|
66
66
|
)
|
67
67
|
|
68
68
|
registry_key = {
|
69
|
-
:
|
70
|
-
:
|
71
|
-
:
|
69
|
+
bbox: state.page.dimensions,
|
70
|
+
mask: [group.stream.filters.normalized, group.stream.filtered_stream],
|
71
|
+
page: state.page_count
|
72
72
|
}.hash
|
73
73
|
|
74
74
|
if soft_mask_registry[registry_key]
|
75
75
|
renderer.add_content "/#{soft_mask_registry[registry_key]} gs"
|
76
76
|
else
|
77
77
|
masks = page.resources[:ExtGState] ||= {}
|
78
|
-
id = masks.empty? ? 'GS1' : masks.keys.
|
78
|
+
id = masks.empty? ? 'GS1' : masks.keys.max.succ
|
79
79
|
masks[id] = g_state
|
80
80
|
|
81
81
|
soft_mask_registry[registry_key] = id
|
data/lib/prawn/stamp.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
3
|
# stamp.rb : Implements a repeatable stamp
|
4
4
|
#
|
5
5
|
# Copyright October 2009, Daniel Nelson. All Rights Reserved.
|
@@ -92,9 +92,9 @@ module Prawn
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def stamp_dictionary(name)
|
95
|
-
|
95
|
+
raise Prawn::Errors::InvalidName if name.empty?
|
96
96
|
if stamp_dictionary_registry[name].nil?
|
97
|
-
|
97
|
+
raise Prawn::Errors::UndefinedObjectName
|
98
98
|
end
|
99
99
|
|
100
100
|
dict = stamp_dictionary_registry[name]
|
@@ -105,20 +105,27 @@ module Prawn
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def create_stamp_dictionary(name)
|
108
|
-
|
109
|
-
|
108
|
+
raise Prawn::Errors::InvalidName if name.empty?
|
109
|
+
raise Prawn::Errors::NameTaken unless stamp_dictionary_registry[name].nil?
|
110
|
+
|
110
111
|
# BBox origin is the lower left margin of the page, so we need
|
111
112
|
# it to be the full dimension of the page, or else things that
|
112
113
|
# should appear near the top or right margin are invisible
|
113
|
-
dictionary = ref!(
|
114
|
-
|
115
|
-
|
116
|
-
|
114
|
+
dictionary = ref!(
|
115
|
+
Type: :XObject,
|
116
|
+
Subtype: :Form,
|
117
|
+
BBox: [
|
118
|
+
0, 0,
|
119
|
+
state.page.dimensions[2], state.page.dimensions[3]
|
120
|
+
]
|
121
|
+
)
|
117
122
|
|
118
123
|
dictionary_name = "Stamp#{next_stamp_dictionary_id}"
|
119
124
|
|
120
|
-
stamp_dictionary_registry[name] = {
|
121
|
-
|
125
|
+
stamp_dictionary_registry[name] = {
|
126
|
+
stamp_dictionary_name: dictionary_name,
|
127
|
+
stamp_dictionary: dictionary
|
128
|
+
}
|
122
129
|
dictionary
|
123
130
|
end
|
124
131
|
|
@@ -127,7 +134,7 @@ module Prawn
|
|
127
134
|
# to the /Annot dictionary of the object that contains the
|
128
135
|
# call to the stamp object.
|
129
136
|
def update_annotation_references(annots)
|
130
|
-
if annots
|
137
|
+
if annots&.any?
|
131
138
|
state.page.dictionary.data[:Annots] ||= []
|
132
139
|
state.page.dictionary.data[:Annots] |= annots
|
133
140
|
end
|
data/lib/prawn/text.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# text.rb : Implements PDF text primitives
|
4
4
|
#
|
@@ -6,12 +6,10 @@
|
|
6
6
|
#
|
7
7
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
8
|
|
9
|
-
require
|
9
|
+
require 'zlib'
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
require_relative "text/formatted"
|
14
|
-
require_relative "text/box"
|
11
|
+
require_relative 'text/formatted'
|
12
|
+
require_relative 'text/box'
|
15
13
|
|
16
14
|
module Prawn
|
17
15
|
module Text
|
@@ -19,11 +17,11 @@ module Prawn
|
|
19
17
|
include Prawn::Text::Formatted
|
20
18
|
|
21
19
|
# No-Break Space
|
22
|
-
|
20
|
+
NBSP = "\u00A0"
|
23
21
|
# Zero Width Space (indicate word boundaries without a space)
|
24
|
-
|
22
|
+
ZWSP = "\u200B"
|
25
23
|
# Soft Hyphen (invisible, except when causing a line break)
|
26
|
-
|
24
|
+
SHY = "\u00AD"
|
27
25
|
|
28
26
|
# @group Stable API
|
29
27
|
|
@@ -139,9 +137,9 @@ module Prawn
|
|
139
137
|
# each line is included below the last line;
|
140
138
|
# otherwise, document.y is placed just below the
|
141
139
|
# descender of the last line printed [true]
|
142
|
-
# <tt>:mode</tt>:: The text rendering mode to use. Use this to specify if
|
143
|
-
# text should render with the fill color, stroke color
|
144
|
-
# both. See the comments to text_rendering_mode() to see
|
140
|
+
# <tt>:mode</tt>:: The text rendering mode to use. Use this to specify if
|
141
|
+
# the text should render with the fill color, stroke color
|
142
|
+
# or both. See the comments to text_rendering_mode() to see
|
145
143
|
# a list of valid options. [0]
|
146
144
|
#
|
147
145
|
# == Exceptions
|
@@ -153,15 +151,17 @@ module Prawn
|
|
153
151
|
#
|
154
152
|
def text(string, options = {})
|
155
153
|
return false if string.nil?
|
154
|
+
|
156
155
|
# we modify the options. don't change the user's hash
|
157
156
|
options = options.dup
|
158
157
|
|
159
|
-
|
158
|
+
p = options[:inline_format]
|
159
|
+
if p
|
160
160
|
p = [] unless p.is_a?(Array)
|
161
161
|
options.delete(:inline_format)
|
162
|
-
array =
|
162
|
+
array = text_formatter.format(string, *p)
|
163
163
|
else
|
164
|
-
array = [{ :
|
164
|
+
array = [{ text: string }]
|
165
165
|
end
|
166
166
|
|
167
167
|
formatted_text(array, options)
|
@@ -190,26 +190,27 @@ module Prawn
|
|
190
190
|
def formatted_text(array, options = {})
|
191
191
|
options = inspect_options_for_text(options.dup)
|
192
192
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
193
|
+
color = options.delete(:color)
|
194
|
+
if color
|
195
|
+
array =
|
196
|
+
array.map do |fragment|
|
197
|
+
fragment[:color] ? fragment : fragment.merge(color: color)
|
198
|
+
end
|
197
199
|
end
|
198
200
|
|
199
201
|
if @indent_paragraphs
|
200
|
-
|
202
|
+
text_formatter.array_paragraphs(array).each do |paragraph|
|
201
203
|
remaining_text = draw_indented_formatted_line(paragraph, options)
|
202
204
|
|
203
|
-
if @no_text_printed
|
204
|
-
|
205
|
-
|
206
|
-
@bounding_box.move_past_bottom
|
207
|
-
remaining_text = draw_indented_formatted_line(paragraph, options)
|
208
|
-
end
|
205
|
+
if @no_text_printed && !@all_text_printed
|
206
|
+
@bounding_box.move_past_bottom
|
207
|
+
remaining_text = draw_indented_formatted_line(paragraph, options)
|
209
208
|
end
|
210
209
|
|
211
|
-
|
212
|
-
|
210
|
+
unless @all_text_printed
|
211
|
+
remaining_text = fill_formatted_text_box(remaining_text, options)
|
212
|
+
draw_remaining_formatted_text_on_new_pages(remaining_text, options)
|
213
|
+
end
|
213
214
|
end
|
214
215
|
else
|
215
216
|
remaining_text = fill_formatted_text_box(array, options)
|
@@ -236,7 +237,8 @@ module Prawn
|
|
236
237
|
# == Rotation
|
237
238
|
#
|
238
239
|
# Text can be rotated before it is placed on the canvas by specifying the
|
239
|
-
# <tt>:rotate</tt> option with a given angle. Rotation occurs
|
240
|
+
# <tt>:rotate</tt> option with a given angle. Rotation occurs
|
241
|
+
# counter-clockwise.
|
240
242
|
#
|
241
243
|
# == Encoding
|
242
244
|
#
|
@@ -253,7 +255,8 @@ module Prawn
|
|
253
255
|
#
|
254
256
|
# == Options (default values marked in [])
|
255
257
|
#
|
256
|
-
# <tt>:at</tt>:: <tt>[x, y]</tt>(required). The position at which to start
|
258
|
+
# <tt>:at</tt>:: <tt>[x, y]</tt>(required). The position at which to start
|
259
|
+
# the text
|
257
260
|
# <tt>:kerning</tt>:: <tt>boolean</tt>. Whether or not to use kerning (if it
|
258
261
|
# is available with the current font)
|
259
262
|
# [value of default_kerning?]
|
@@ -277,7 +280,7 @@ module Prawn
|
|
277
280
|
text = text.to_s.dup
|
278
281
|
save_font do
|
279
282
|
process_text_options(options)
|
280
|
-
font.normalize_encoding
|
283
|
+
text = font.normalize_encoding(text)
|
281
284
|
font_size(options[:size]) { draw_text!(text, options) }
|
282
285
|
end
|
283
286
|
end
|
@@ -289,9 +292,9 @@ module Prawn
|
|
289
292
|
unless font.unicode? || font.class.hide_m17n_warning || text.ascii_only?
|
290
293
|
warn "PDF's built-in fonts have very limited support for " \
|
291
294
|
"internationalized text.\nIf you need full UTF-8 support, " \
|
292
|
-
"consider using
|
295
|
+
"consider using an external font instead.\n\nTo disable this " \
|
293
296
|
"warning, add the following line to your code:\n" \
|
294
|
-
"Prawn::
|
297
|
+
"Prawn::Fonts::AFM.hide_m17n_warning = true\n"
|
295
298
|
|
296
299
|
font.class.hide_m17n_warning = true
|
297
300
|
end
|
@@ -317,7 +320,7 @@ module Prawn
|
|
317
320
|
# any text
|
318
321
|
#
|
319
322
|
def height_of(string, options = {})
|
320
|
-
height_of_formatted([{ :
|
323
|
+
height_of_formatted([{ text: string }], options)
|
321
324
|
end
|
322
325
|
|
323
326
|
# Gets height of formatted text in PDF points.
|
@@ -332,15 +335,15 @@ module Prawn
|
|
332
335
|
#
|
333
336
|
def height_of_formatted(array, options = {})
|
334
337
|
if options[:indent_paragraphs]
|
335
|
-
|
336
|
-
|
338
|
+
raise NotImplementedError,
|
339
|
+
':indent_paragraphs option not available with height_of'
|
337
340
|
end
|
338
341
|
process_final_gap_option(options)
|
339
342
|
box = Text::Formatted::Box.new(
|
340
343
|
array,
|
341
|
-
options.merge(:
|
344
|
+
options.merge(height: 100_000_000, document: self)
|
342
345
|
)
|
343
|
-
box.render(:
|
346
|
+
box.render(dry_run: true)
|
344
347
|
|
345
348
|
height = box.height
|
346
349
|
height += box.line_gap + box.leading if @final_gap
|
@@ -350,7 +353,7 @@ module Prawn
|
|
350
353
|
private
|
351
354
|
|
352
355
|
def draw_remaining_formatted_text_on_new_pages(remaining_text, options)
|
353
|
-
|
356
|
+
until remaining_text.empty?
|
354
357
|
@bounding_box.move_past_bottom
|
355
358
|
previous_remaining_text = remaining_text
|
356
359
|
remaining_text = fill_formatted_text_box(remaining_text, options)
|
@@ -359,14 +362,15 @@ module Prawn
|
|
359
362
|
end
|
360
363
|
|
361
364
|
def draw_indented_formatted_line(string, options)
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
365
|
+
gap =
|
366
|
+
if options.fetch(:direction, text_direction) == :ltr
|
367
|
+
[@indent_paragraphs, 0]
|
368
|
+
else
|
369
|
+
[0, @indent_paragraphs]
|
370
|
+
end
|
367
371
|
|
368
372
|
indent(*gap) do
|
369
|
-
fill_formatted_text_box(string, options.dup.merge(:
|
373
|
+
fill_formatted_text_box(string, options.dup.merge(single_line: true))
|
370
374
|
end
|
371
375
|
end
|
372
376
|
|
@@ -384,33 +388,41 @@ module Prawn
|
|
384
388
|
end
|
385
389
|
|
386
390
|
def merge_text_box_positioning_options(options)
|
387
|
-
bottom =
|
388
|
-
|
391
|
+
bottom =
|
392
|
+
if @bounding_box.stretchy?
|
393
|
+
@margin_box.absolute_bottom
|
394
|
+
else
|
395
|
+
@bounding_box.absolute_bottom
|
396
|
+
end
|
389
397
|
|
390
398
|
options[:height] = y - bottom
|
391
399
|
options[:width] = bounds.width
|
392
|
-
options[:at] = [
|
393
|
-
|
400
|
+
options[:at] = [
|
401
|
+
@bounding_box.left_side - @bounding_box.absolute_left,
|
402
|
+
y - @bounding_box.absolute_bottom
|
403
|
+
]
|
394
404
|
end
|
395
405
|
|
396
406
|
def inspect_options_for_draw_text(options)
|
397
407
|
if options[:at].nil?
|
398
|
-
|
408
|
+
raise ArgumentError, 'The :at option is required for draw_text'
|
399
409
|
elsif options[:align]
|
400
|
-
|
410
|
+
raise ArgumentError, 'The :align option does not work with draw_text'
|
401
411
|
end
|
402
|
-
|
412
|
+
|
413
|
+
if options[:kerning].nil?
|
403
414
|
options[:kerning] = default_kerning?
|
404
415
|
end
|
405
|
-
valid_options = PDF::Core::Text::VALID_OPTIONS + [
|
416
|
+
valid_options = PDF::Core::Text::VALID_OPTIONS + %i[at rotate]
|
406
417
|
Prawn.verify_options(valid_options, options)
|
407
418
|
options
|
408
419
|
end
|
409
420
|
|
410
421
|
def inspect_options_for_text(options)
|
411
422
|
if options[:at]
|
412
|
-
|
413
|
-
|
423
|
+
raise ArgumentError,
|
424
|
+
':at is no longer a valid option with text.' \
|
425
|
+
'use draw_text or text_box instead'
|
414
426
|
end
|
415
427
|
process_final_gap_option(options)
|
416
428
|
process_indent_paragraphs_option(options)
|
@@ -428,13 +440,17 @@ module Prawn
|
|
428
440
|
options.delete(:indent_paragraphs)
|
429
441
|
end
|
430
442
|
|
431
|
-
def move_text_position(
|
432
|
-
bottom =
|
433
|
-
|
443
|
+
def move_text_position(amount)
|
444
|
+
bottom =
|
445
|
+
if @bounding_box.stretchy?
|
446
|
+
@margin_box.absolute_bottom
|
447
|
+
else
|
448
|
+
@bounding_box.absolute_bottom
|
449
|
+
end
|
434
450
|
|
435
|
-
@bounding_box.move_past_bottom if (y -
|
451
|
+
@bounding_box.move_past_bottom if (y - amount) < bottom
|
436
452
|
|
437
|
-
self.y -=
|
453
|
+
self.y -= amount
|
438
454
|
end
|
439
455
|
end
|
440
456
|
end
|
data/lib/prawn/text/box.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# text/rectangle.rb : Implements text boxes
|
4
4
|
#
|
@@ -7,7 +7,7 @@
|
|
7
7
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
8
|
#
|
9
9
|
|
10
|
-
require_relative
|
10
|
+
require_relative 'formatted/box'
|
11
11
|
|
12
12
|
module Prawn
|
13
13
|
module Text
|
@@ -52,7 +52,8 @@ module Prawn
|
|
52
52
|
# <tt>[x, y]</tt>. The upper left corner of the box
|
53
53
|
# [@document.bounds.left, @document.bounds.top]
|
54
54
|
# <tt>:width</tt>::
|
55
|
-
# <tt>number</tt>. The width of the box
|
55
|
+
# <tt>number</tt>. The width of the box
|
56
|
+
# [@document.bounds.right - @at[0]]
|
56
57
|
# <tt>:height</tt>::
|
57
58
|
# <tt>number</tt>. The height of the box [default_height()]
|
58
59
|
# <tt>:direction</tt>::
|
@@ -60,7 +61,7 @@ module Prawn
|
|
60
61
|
# or right-to-left) [value of document.text_direction]
|
61
62
|
# <tt>:fallback_fonts</tt>::
|
62
63
|
# An array of font names. Each name must be the name of an AFM font or
|
63
|
-
# the name that was used to register a family of
|
64
|
+
# the name that was used to register a family of external fonts (see
|
64
65
|
# Prawn::Document#font_families). If present, then each glyph will be
|
65
66
|
# rendered using the first font that includes the glyph, starting with
|
66
67
|
# the current font and then moving through :fallback_fonts from
|
@@ -82,7 +83,8 @@ module Prawn
|
|
82
83
|
# <tt>number</tt>. Additional space between lines [value of
|
83
84
|
# document.default_leading]
|
84
85
|
# <tt>:single_line</tt>::
|
85
|
-
# <tt>boolean</tt>. If true, then only the first line will be drawn
|
86
|
+
# <tt>boolean</tt>. If true, then only the first line will be drawn
|
87
|
+
# [false]
|
86
88
|
# <tt>:overflow</tt>::
|
87
89
|
# <tt>:truncate</tt>, <tt>:shrink_to_fit</tt>, or <tt>:expand</tt>
|
88
90
|
# This controls the behavior when the amount of text
|
@@ -105,13 +107,15 @@ module Prawn
|
|
105
107
|
options = options.dup
|
106
108
|
options[:document] = self
|
107
109
|
|
108
|
-
box =
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
110
|
+
box =
|
111
|
+
if options[:inline_format]
|
112
|
+
p = options.delete(:inline_format)
|
113
|
+
p = [] unless p.is_a?(Array)
|
114
|
+
array = text_formatter.format(string, *p)
|
115
|
+
Text::Formatted::Box.new(array, options)
|
116
|
+
else
|
117
|
+
Text::Box.new(string, options)
|
118
|
+
end
|
115
119
|
|
116
120
|
box.render
|
117
121
|
end
|
@@ -126,12 +130,12 @@ module Prawn
|
|
126
130
|
#
|
127
131
|
class Box < Prawn::Text::Formatted::Box
|
128
132
|
def initialize(string, options = {})
|
129
|
-
super([{ :
|
133
|
+
super([{ text: string }], options)
|
130
134
|
end
|
131
135
|
|
132
136
|
def render(flags = {})
|
133
137
|
leftover = super(flags)
|
134
|
-
leftover.
|
138
|
+
leftover.map { |hash| hash[:text] }.join
|
135
139
|
end
|
136
140
|
end
|
137
141
|
end
|