prawn 2.0.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/GPLv2 +20 -21
- data/Gemfile +3 -9
- data/Rakefile +20 -23
- data/lib/prawn.rb +37 -49
- data/lib/prawn/document.rb +181 -133
- data/lib/prawn/document/bounding_box.rb +41 -29
- data/lib/prawn/document/column_box.rb +7 -7
- data/lib/prawn/document/internals.rb +18 -8
- data/lib/prawn/document/span.rb +21 -16
- data/lib/prawn/encoding.rb +69 -68
- data/lib/prawn/errors.rb +12 -7
- data/lib/prawn/font.rb +115 -69
- data/lib/prawn/font_metric_cache.rb +14 -8
- data/lib/prawn/{font → fonts}/afm.rb +102 -68
- data/lib/prawn/{font → fonts}/dfont.rb +5 -11
- data/lib/prawn/fonts/otf.rb +11 -0
- data/lib/prawn/fonts/ttc.rb +36 -0
- data/lib/prawn/{font → fonts}/ttf.rb +87 -68
- data/lib/prawn/graphics.rb +120 -80
- data/lib/prawn/graphics/blend_mode.rb +65 -0
- data/lib/prawn/graphics/cap_style.rb +3 -3
- data/lib/prawn/graphics/color.rb +27 -25
- data/lib/prawn/graphics/dash.rb +23 -11
- data/lib/prawn/graphics/join_style.rb +9 -3
- data/lib/prawn/graphics/patterns.rb +197 -67
- data/lib/prawn/graphics/transformation.rb +17 -8
- data/lib/prawn/graphics/transparency.rb +17 -13
- data/lib/prawn/grid.rb +48 -47
- data/lib/prawn/image_handler.rb +5 -5
- data/lib/prawn/images.rb +39 -30
- data/lib/prawn/images/image.rb +2 -1
- data/lib/prawn/images/jpg.rb +28 -22
- data/lib/prawn/images/png.rb +107 -66
- data/lib/prawn/measurement_extensions.rb +10 -9
- data/lib/prawn/measurements.rb +19 -15
- data/lib/prawn/outline.rb +97 -77
- data/lib/prawn/repeater.rb +14 -10
- data/lib/prawn/security.rb +81 -61
- data/lib/prawn/security/arcfour.rb +2 -2
- data/lib/prawn/soft_mask.rb +26 -26
- data/lib/prawn/stamp.rb +20 -13
- data/lib/prawn/text.rb +68 -52
- data/lib/prawn/text/box.rb +11 -8
- data/lib/prawn/text/formatted.rb +5 -5
- data/lib/prawn/text/formatted/arranger.rb +78 -49
- data/lib/prawn/text/formatted/box.rb +134 -100
- data/lib/prawn/text/formatted/fragment.rb +11 -14
- data/lib/prawn/text/formatted/line_wrap.rb +121 -63
- data/lib/prawn/text/formatted/parser.rb +139 -117
- data/lib/prawn/text/formatted/wrap.rb +43 -31
- data/lib/prawn/transformation_stack.rb +44 -0
- data/lib/prawn/utilities.rb +7 -22
- data/lib/prawn/version.rb +2 -2
- data/lib/prawn/view.rb +17 -7
- data/manual/basic_concepts/adding_pages.rb +6 -7
- data/manual/basic_concepts/basic_concepts.rb +31 -22
- data/manual/basic_concepts/creation.rb +10 -11
- data/manual/basic_concepts/cursor.rb +4 -5
- data/manual/basic_concepts/measurement.rb +6 -7
- data/manual/basic_concepts/origin.rb +5 -6
- data/manual/basic_concepts/other_cursor_helpers.rb +11 -12
- data/manual/basic_concepts/view.rb +22 -16
- data/manual/bounding_box/bounding_box.rb +29 -24
- data/manual/bounding_box/bounds.rb +11 -12
- data/manual/bounding_box/canvas.rb +4 -5
- data/manual/bounding_box/creation.rb +6 -7
- data/manual/bounding_box/indentation.rb +14 -15
- data/manual/bounding_box/nesting.rb +24 -17
- data/manual/bounding_box/russian_boxes.rb +14 -13
- data/manual/bounding_box/stretchy.rb +12 -13
- data/manual/contents.rb +28 -22
- data/manual/cover.rb +33 -28
- data/manual/document_and_page_options/background.rb +11 -13
- data/manual/document_and_page_options/document_and_page_options.rb +25 -20
- data/manual/document_and_page_options/metadata.rb +18 -16
- data/manual/document_and_page_options/page_margins.rb +18 -20
- data/manual/document_and_page_options/page_size.rb +13 -12
- data/manual/document_and_page_options/print_scaling.rb +17 -15
- data/manual/example_helper.rb +5 -4
- data/manual/graphics/blend_mode.rb +52 -0
- data/manual/graphics/circle_and_ellipse.rb +4 -5
- data/manual/graphics/color.rb +7 -9
- data/manual/graphics/common_lines.rb +7 -8
- data/manual/graphics/fill_and_stroke.rb +4 -5
- data/manual/graphics/fill_rules.rb +9 -10
- data/manual/graphics/gradients.rb +27 -21
- data/manual/graphics/graphics.rb +48 -39
- data/manual/graphics/helper.rb +12 -9
- data/manual/graphics/line_width.rb +8 -7
- data/manual/graphics/lines_and_curves.rb +7 -8
- data/manual/graphics/polygon.rb +6 -8
- data/manual/graphics/rectangle.rb +4 -5
- data/manual/graphics/rotate.rb +6 -7
- data/manual/graphics/scale.rb +14 -15
- data/manual/graphics/soft_masks.rb +4 -5
- data/manual/graphics/stroke_cap.rb +6 -7
- data/manual/graphics/stroke_dash.rb +11 -12
- data/manual/graphics/stroke_join.rb +5 -6
- data/manual/graphics/translate.rb +9 -10
- data/manual/graphics/transparency.rb +7 -8
- data/manual/how_to_read_this_manual.rb +6 -6
- data/manual/images/absolute_position.rb +6 -7
- data/manual/images/fit.rb +7 -8
- data/manual/images/horizontal.rb +9 -10
- data/manual/images/images.rb +28 -24
- data/manual/images/plain_image.rb +5 -6
- data/manual/images/scale.rb +9 -10
- data/manual/images/vertical.rb +13 -14
- data/manual/images/width_and_height.rb +10 -11
- data/manual/layout/boxes.rb +5 -6
- data/manual/layout/content.rb +7 -8
- data/manual/layout/layout.rb +18 -16
- data/manual/layout/simple_grid.rb +6 -7
- data/manual/outline/add_subsection_to.rb +20 -21
- data/manual/outline/insert_section_after.rb +15 -16
- data/manual/outline/outline.rb +21 -17
- data/manual/outline/sections_and_pages.rb +17 -18
- data/manual/repeatable_content/alternate_page_numbering.rb +21 -17
- data/manual/repeatable_content/page_numbering.rb +17 -16
- data/manual/repeatable_content/repeatable_content.rb +25 -19
- data/manual/repeatable_content/repeater.rb +14 -15
- data/manual/repeatable_content/stamp.rb +14 -15
- data/manual/security/encryption.rb +9 -10
- data/manual/security/permissions.rb +19 -14
- data/manual/security/security.rb +19 -16
- data/manual/table.rb +3 -3
- data/manual/text/alignment.rb +16 -17
- data/manual/text/color.rb +12 -11
- data/manual/text/column_box.rb +9 -10
- data/manual/text/fallback_fonts.rb +25 -21
- data/manual/text/font.rb +11 -12
- data/manual/text/font_size.rb +13 -14
- data/manual/text/font_style.rb +7 -8
- data/manual/text/formatted_callbacks.rb +25 -21
- data/manual/text/formatted_text.rb +33 -25
- data/manual/text/free_flowing_text.rb +20 -21
- data/manual/text/inline.rb +18 -19
- data/manual/text/kerning_and_character_spacing.rb +14 -15
- data/manual/text/leading.rb +7 -8
- data/manual/text/line_wrapping.rb +37 -18
- data/manual/text/paragraph_indentation.rb +13 -14
- data/manual/text/positioned_text.rb +15 -16
- data/manual/text/registering_families.rb +20 -21
- data/manual/text/rendering_and_color.rb +9 -10
- data/manual/text/right_to_left_text.rb +26 -19
- data/manual/text/rotation.rb +28 -23
- data/manual/text/single_usage.rb +8 -9
- data/manual/text/text.rb +57 -52
- data/manual/text/text_box_excess.rb +20 -17
- data/manual/text/text_box_extensions.rb +18 -15
- data/manual/text/text_box_overflow.rb +18 -19
- data/manual/text/utf8.rb +11 -12
- data/manual/text/win_ansi_charset.rb +21 -19
- data/prawn.gemspec +45 -33
- data/spec/extensions/encoding_helpers.rb +3 -3
- data/spec/prawn/document/bounding_box_spec.rb +546 -0
- data/spec/prawn/document/column_box_spec.rb +75 -0
- data/spec/prawn/document/security_spec.rb +176 -0
- data/spec/prawn/document_annotations_spec.rb +76 -0
- data/spec/prawn/document_destinations_spec.rb +15 -0
- data/spec/prawn/document_grid_spec.rb +99 -0
- data/spec/prawn/document_reference_spec.rb +27 -0
- data/spec/prawn/document_span_spec.rb +36 -0
- data/spec/prawn/document_spec.rb +802 -0
- data/spec/prawn/font_metric_cache_spec.rb +54 -0
- data/spec/prawn/font_spec.rb +542 -0
- data/spec/prawn/graphics/blend_mode_spec.rb +63 -0
- data/spec/prawn/graphics/transparency_spec.rb +81 -0
- data/spec/prawn/graphics_spec.rb +837 -0
- data/spec/prawn/graphics_stroke_styles_spec.rb +229 -0
- data/spec/prawn/image_handler_spec.rb +53 -0
- data/spec/prawn/images/jpg_spec.rb +20 -0
- data/spec/prawn/images/png_spec.rb +283 -0
- data/spec/prawn/images_spec.rb +224 -0
- data/spec/prawn/measurements_extensions_spec.rb +24 -0
- data/spec/prawn/outline_spec.rb +412 -0
- data/spec/prawn/repeater_spec.rb +165 -0
- data/spec/prawn/soft_mask_spec.rb +74 -0
- data/spec/prawn/stamp_spec.rb +172 -0
- data/spec/prawn/text/box_spec.rb +1112 -0
- data/spec/prawn/text/formatted/arranger_spec.rb +466 -0
- data/spec/prawn/text/formatted/box_spec.rb +846 -0
- data/spec/prawn/text/formatted/fragment_spec.rb +343 -0
- data/spec/prawn/text/formatted/line_wrap_spec.rb +494 -0
- data/spec/prawn/text/formatted/parser_spec.rb +697 -0
- data/spec/prawn/text_draw_text_spec.rb +149 -0
- data/spec/prawn/text_rendering_mode_spec.rb +48 -0
- data/spec/prawn/text_spacing_spec.rb +95 -0
- data/spec/prawn/text_spec.rb +603 -0
- data/spec/prawn/text_with_inline_formatting_spec.rb +35 -0
- data/spec/prawn/transformation_stack_spec.rb +66 -0
- data/spec/prawn/view_spec.rb +63 -0
- data/spec/prawn_manual_spec.rb +35 -0
- data/spec/spec_helper.rb +19 -23
- metadata +145 -185
- metadata.gz.sig +4 -0
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/16bit.png +0 -0
- data/data/images/arrow.png +0 -0
- data/data/images/arrow2.png +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/dice.png +0 -0
- data/data/images/dice_interlaced.png +0 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/data/images/license.md +0 -8
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/data/images/page_white_text.png +0 -0
- data/data/images/pal_bk.png +0 -0
- data/data/images/pigs.jpg +0 -0
- data/data/images/prawn.png +0 -0
- data/data/images/ruport.png +0 -0
- data/data/images/ruport_data.dat +0 -0
- data/data/images/ruport_transparent.png +0 -0
- data/data/images/ruport_type0.png +0 -0
- data/data/images/stef.jpg +0 -0
- data/data/images/tru256.bmp +0 -0
- data/data/images/web-links.dat +0 -1
- data/data/images/web-links.png +0 -0
- data/data/pdfs/complex_template.pdf +0 -0
- data/data/pdfs/contains_ttf_font.pdf +0 -0
- data/data/pdfs/encrypted.pdf +0 -0
- data/data/pdfs/form.pdf +1 -819
- data/data/pdfs/hexagon.pdf +0 -61
- data/data/pdfs/indirect_reference.pdf +0 -86
- data/data/pdfs/multipage_template.pdf +0 -127
- data/data/pdfs/nested_pages.pdf +0 -118
- data/data/pdfs/page_without_mediabox.pdf +0 -193
- data/data/pdfs/resources_as_indirect_object.pdf +0 -83
- data/data/pdfs/two_hexagons.pdf +0 -90
- data/data/pdfs/version_1_6.pdf +0 -61
- data/data/shift_jis_text.txt +0 -1
- data/spec/acceptance/png.rb +0 -24
- data/spec/annotations_spec.rb +0 -67
- data/spec/bounding_box_spec.rb +0 -501
- data/spec/column_box_spec.rb +0 -59
- data/spec/destinations_spec.rb +0 -13
- data/spec/document_spec.rb +0 -742
- data/spec/extensions/mocha.rb +0 -45
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/font_spec.rb +0 -475
- data/spec/formatted_text_arranger_spec.rb +0 -423
- data/spec/formatted_text_box_spec.rb +0 -716
- data/spec/formatted_text_fragment_spec.rb +0 -299
- data/spec/graphics_spec.rb +0 -666
- data/spec/grid_spec.rb +0 -95
- data/spec/image_handler_spec.rb +0 -53
- data/spec/images_spec.rb +0 -167
- data/spec/inline_formatted_text_parser_spec.rb +0 -568
- data/spec/jpg_spec.rb +0 -23
- data/spec/line_wrap_spec.rb +0 -366
- data/spec/measurement_units_spec.rb +0 -22
- data/spec/outline_spec.rb +0 -409
- data/spec/png_spec.rb +0 -235
- data/spec/reference_spec.rb +0 -25
- data/spec/repeater_spec.rb +0 -154
- data/spec/security_spec.rb +0 -151
- data/spec/soft_mask_spec.rb +0 -78
- data/spec/span_spec.rb +0 -43
- data/spec/stamp_spec.rb +0 -179
- data/spec/stroke_styles_spec.rb +0 -208
- data/spec/text_at_spec.rb +0 -142
- data/spec/text_box_spec.rb +0 -1038
- data/spec/text_rendering_mode_spec.rb +0 -45
- data/spec/text_spacing_spec.rb +0 -93
- data/spec/text_spec.rb +0 -549
- data/spec/text_with_inline_formatting_spec.rb +0 -35
- data/spec/transparency_spec.rb +0 -91
- data/spec/view_spec.rb +0 -42
@@ -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,14 +190,15 @@ module Prawn
|
|
190
190
|
def formatted_text(array, options = {})
|
191
191
|
options = inspect_options_for_text(options.dup)
|
192
192
|
|
193
|
-
|
193
|
+
color = options.delete(:color)
|
194
|
+
if color
|
194
195
|
array = array.map do |fragment|
|
195
|
-
fragment[:color] ? fragment : fragment.merge(:
|
196
|
+
fragment[:color] ? fragment : fragment.merge(color: color)
|
196
197
|
end
|
197
198
|
end
|
198
199
|
|
199
200
|
if @indent_paragraphs
|
200
|
-
|
201
|
+
text_formatter.array_paragraphs(array).each do |paragraph|
|
201
202
|
remaining_text = draw_indented_formatted_line(paragraph, options)
|
202
203
|
|
203
204
|
if @no_text_printed
|
@@ -208,8 +209,10 @@ module Prawn
|
|
208
209
|
end
|
209
210
|
end
|
210
211
|
|
211
|
-
|
212
|
-
|
212
|
+
unless @all_text_printed
|
213
|
+
remaining_text = fill_formatted_text_box(remaining_text, options)
|
214
|
+
draw_remaining_formatted_text_on_new_pages(remaining_text, options)
|
215
|
+
end
|
213
216
|
end
|
214
217
|
else
|
215
218
|
remaining_text = fill_formatted_text_box(array, options)
|
@@ -236,7 +239,8 @@ module Prawn
|
|
236
239
|
# == Rotation
|
237
240
|
#
|
238
241
|
# 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
|
242
|
+
# <tt>:rotate</tt> option with a given angle. Rotation occurs
|
243
|
+
# counter-clockwise.
|
240
244
|
#
|
241
245
|
# == Encoding
|
242
246
|
#
|
@@ -253,7 +257,8 @@ module Prawn
|
|
253
257
|
#
|
254
258
|
# == Options (default values marked in [])
|
255
259
|
#
|
256
|
-
# <tt>:at</tt>:: <tt>[x, y]</tt>(required). The position at which to start
|
260
|
+
# <tt>:at</tt>:: <tt>[x, y]</tt>(required). The position at which to start
|
261
|
+
# the text
|
257
262
|
# <tt>:kerning</tt>:: <tt>boolean</tt>. Whether or not to use kerning (if it
|
258
263
|
# is available with the current font)
|
259
264
|
# [value of default_kerning?]
|
@@ -277,7 +282,7 @@ module Prawn
|
|
277
282
|
text = text.to_s.dup
|
278
283
|
save_font do
|
279
284
|
process_text_options(options)
|
280
|
-
font.normalize_encoding
|
285
|
+
text = font.normalize_encoding(text)
|
281
286
|
font_size(options[:size]) { draw_text!(text, options) }
|
282
287
|
end
|
283
288
|
end
|
@@ -289,9 +294,9 @@ module Prawn
|
|
289
294
|
unless font.unicode? || font.class.hide_m17n_warning || text.ascii_only?
|
290
295
|
warn "PDF's built-in fonts have very limited support for " \
|
291
296
|
"internationalized text.\nIf you need full UTF-8 support, " \
|
292
|
-
"consider using
|
297
|
+
"consider using an external font instead.\n\nTo disable this " \
|
293
298
|
"warning, add the following line to your code:\n" \
|
294
|
-
"Prawn::
|
299
|
+
"Prawn::Fonts::AFM.hide_m17n_warning = true\n"
|
295
300
|
|
296
301
|
font.class.hide_m17n_warning = true
|
297
302
|
end
|
@@ -317,7 +322,7 @@ module Prawn
|
|
317
322
|
# any text
|
318
323
|
#
|
319
324
|
def height_of(string, options = {})
|
320
|
-
height_of_formatted([{ :
|
325
|
+
height_of_formatted([{ text: string }], options)
|
321
326
|
end
|
322
327
|
|
323
328
|
# Gets height of formatted text in PDF points.
|
@@ -332,15 +337,15 @@ module Prawn
|
|
332
337
|
#
|
333
338
|
def height_of_formatted(array, options = {})
|
334
339
|
if options[:indent_paragraphs]
|
335
|
-
|
336
|
-
|
340
|
+
raise NotImplementedError, ':indent_paragraphs option not available' \
|
341
|
+
'with height_of'
|
337
342
|
end
|
338
343
|
process_final_gap_option(options)
|
339
344
|
box = Text::Formatted::Box.new(
|
340
345
|
array,
|
341
|
-
options.merge(:
|
346
|
+
options.merge(height: 100_000_000, document: self)
|
342
347
|
)
|
343
|
-
box.render(:
|
348
|
+
box.render(dry_run: true)
|
344
349
|
|
345
350
|
height = box.height
|
346
351
|
height += box.line_gap + box.leading if @final_gap
|
@@ -350,7 +355,7 @@ module Prawn
|
|
350
355
|
private
|
351
356
|
|
352
357
|
def draw_remaining_formatted_text_on_new_pages(remaining_text, options)
|
353
|
-
|
358
|
+
until remaining_text.empty?
|
354
359
|
@bounding_box.move_past_bottom
|
355
360
|
previous_remaining_text = remaining_text
|
356
361
|
remaining_text = fill_formatted_text_box(remaining_text, options)
|
@@ -359,14 +364,14 @@ module Prawn
|
|
359
364
|
end
|
360
365
|
|
361
366
|
def draw_indented_formatted_line(string, options)
|
362
|
-
if options.fetch(:direction, text_direction) == :ltr
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
+
gap = if options.fetch(:direction, text_direction) == :ltr
|
368
|
+
[@indent_paragraphs, 0]
|
369
|
+
else
|
370
|
+
[0, @indent_paragraphs]
|
371
|
+
end
|
367
372
|
|
368
373
|
indent(*gap) do
|
369
|
-
fill_formatted_text_box(string, options.dup.merge(:
|
374
|
+
fill_formatted_text_box(string, options.dup.merge(single_line: true))
|
370
375
|
end
|
371
376
|
end
|
372
377
|
|
@@ -384,33 +389,40 @@ module Prawn
|
|
384
389
|
end
|
385
390
|
|
386
391
|
def merge_text_box_positioning_options(options)
|
387
|
-
bottom =
|
388
|
-
|
392
|
+
bottom =
|
393
|
+
if @bounding_box.stretchy?
|
394
|
+
@margin_box.absolute_bottom
|
395
|
+
else
|
396
|
+
@bounding_box.absolute_bottom
|
397
|
+
end
|
389
398
|
|
390
399
|
options[:height] = y - bottom
|
391
400
|
options[:width] = bounds.width
|
392
|
-
options[:at] = [
|
393
|
-
|
401
|
+
options[:at] = [
|
402
|
+
@bounding_box.left_side - @bounding_box.absolute_left,
|
403
|
+
y - @bounding_box.absolute_bottom
|
404
|
+
]
|
394
405
|
end
|
395
406
|
|
396
407
|
def inspect_options_for_draw_text(options)
|
397
408
|
if options[:at].nil?
|
398
|
-
|
409
|
+
raise ArgumentError, 'The :at option is required for draw_text'
|
399
410
|
elsif options[:align]
|
400
|
-
|
411
|
+
raise ArgumentError, 'The :align option does not work with draw_text'
|
401
412
|
end
|
402
|
-
|
413
|
+
|
414
|
+
if options[:kerning].nil?
|
403
415
|
options[:kerning] = default_kerning?
|
404
416
|
end
|
405
|
-
valid_options = PDF::Core::Text::VALID_OPTIONS + [
|
417
|
+
valid_options = PDF::Core::Text::VALID_OPTIONS + %i[at rotate]
|
406
418
|
Prawn.verify_options(valid_options, options)
|
407
419
|
options
|
408
420
|
end
|
409
421
|
|
410
422
|
def inspect_options_for_text(options)
|
411
423
|
if options[:at]
|
412
|
-
|
413
|
-
|
424
|
+
raise ArgumentError, ':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,9 +107,10 @@ module Prawn
|
|
105
107
|
options = options.dup
|
106
108
|
options[:document] = self
|
107
109
|
|
108
|
-
box = if
|
110
|
+
box = if options[:inline_format]
|
111
|
+
p = options.delete(:inline_format)
|
109
112
|
p = [] unless p.is_a?(Array)
|
110
|
-
array =
|
113
|
+
array = text_formatter.format(string, *p)
|
111
114
|
Text::Formatted::Box.new(array, options)
|
112
115
|
else
|
113
116
|
Text::Box.new(string, options)
|
@@ -126,7 +129,7 @@ module Prawn
|
|
126
129
|
#
|
127
130
|
class Box < Prawn::Text::Formatted::Box
|
128
131
|
def initialize(string, options = {})
|
129
|
-
super([{ :
|
132
|
+
super([{ text: string }], options)
|
130
133
|
end
|
131
134
|
|
132
135
|
def render(flags = {})
|