prawn 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/prawn/document/bounding_box.rb +213 -141
- data/lib/prawn/document/column_box.rb +61 -26
- data/lib/prawn/document/internals.rb +25 -16
- data/lib/prawn/document/span.rb +20 -18
- data/lib/prawn/document.rb +257 -171
- data/lib/prawn/encoding.rb +2 -5
- data/lib/prawn/errors.rb +23 -34
- data/lib/prawn/font.rb +248 -135
- data/lib/prawn/font_metric_cache.rb +11 -10
- data/lib/prawn/fonts/afm.rb +85 -45
- data/lib/prawn/fonts/dfont.rb +7 -1
- data/lib/prawn/fonts/otf.rb +4 -1
- data/lib/prawn/fonts/to_unicode_cmap.rb +151 -0
- data/lib/prawn/fonts/ttc.rb +7 -2
- data/lib/prawn/fonts/ttf.rb +305 -93
- data/lib/prawn/fonts.rb +14 -0
- data/lib/prawn/graphics/blend_mode.rb +25 -28
- data/lib/prawn/graphics/cap_style.rb +9 -12
- data/lib/prawn/graphics/color.rb +57 -34
- data/lib/prawn/graphics/dash.rb +45 -42
- data/lib/prawn/graphics/join_style.rb +17 -11
- data/lib/prawn/graphics/patterns.rb +190 -69
- data/lib/prawn/graphics/transformation.rb +48 -41
- data/lib/prawn/graphics/transparency.rb +16 -40
- data/lib/prawn/graphics.rb +363 -253
- data/lib/prawn/grid.rb +184 -57
- data/lib/prawn/image_handler.rb +27 -10
- data/lib/prawn/images/image.rb +8 -10
- data/lib/prawn/images/jpg.rb +42 -19
- data/lib/prawn/images/png.rb +92 -41
- data/lib/prawn/images.rb +44 -57
- data/lib/prawn/measurement_extensions.rb +39 -8
- data/lib/prawn/measurements.rb +60 -5
- data/lib/prawn/outline.rb +114 -108
- data/lib/prawn/repeater.rb +51 -35
- data/lib/prawn/security/arcfour.rb +4 -4
- data/lib/prawn/security.rb +75 -70
- data/lib/prawn/soft_mask.rb +42 -30
- data/lib/prawn/stamp.rb +38 -42
- data/lib/prawn/text/box.rb +146 -96
- data/lib/prawn/text/formatted/arranger.rb +87 -26
- data/lib/prawn/text/formatted/box.rb +221 -150
- data/lib/prawn/text/formatted/fragment.rb +130 -14
- data/lib/prawn/text/formatted/line_wrap.rb +33 -24
- data/lib/prawn/text/formatted/parser.rb +112 -72
- data/lib/prawn/text/formatted/wrap.rb +12 -17
- data/lib/prawn/text/formatted.rb +75 -0
- data/lib/prawn/text.rb +441 -196
- data/lib/prawn/transformation_stack.rb +29 -10
- data/lib/prawn/utilities.rb +13 -13
- data/lib/prawn/version.rb +2 -1
- data/lib/prawn/view.rb +68 -53
- data/lib/prawn.rb +23 -18
- data.tar.gz.sig +0 -0
- metadata +54 -177
- metadata.gz.sig +0 -0
- data/.yardopts +0 -10
- data/Gemfile +0 -5
- data/Rakefile +0 -25
- data/manual/absolute_position.pdf +0 -0
- data/manual/basic_concepts/adding_pages.rb +0 -26
- data/manual/basic_concepts/basic_concepts.rb +0 -43
- data/manual/basic_concepts/creation.rb +0 -38
- data/manual/basic_concepts/cursor.rb +0 -32
- data/manual/basic_concepts/measurement.rb +0 -24
- data/manual/basic_concepts/origin.rb +0 -37
- data/manual/basic_concepts/other_cursor_helpers.rb +0 -39
- data/manual/basic_concepts/view.rb +0 -48
- data/manual/bounding_box/bounding_box.rb +0 -41
- data/manual/bounding_box/bounds.rb +0 -48
- data/manual/bounding_box/canvas.rb +0 -23
- data/manual/bounding_box/creation.rb +0 -22
- data/manual/bounding_box/indentation.rb +0 -45
- data/manual/bounding_box/nesting.rb +0 -52
- data/manual/bounding_box/russian_boxes.rb +0 -40
- data/manual/bounding_box/stretchy.rb +0 -29
- data/manual/contents.rb +0 -35
- data/manual/cover.rb +0 -43
- data/manual/document_and_page_options/background.rb +0 -29
- data/manual/document_and_page_options/document_and_page_options.rb +0 -34
- data/manual/document_and_page_options/metadata.rb +0 -25
- data/manual/document_and_page_options/page_margins.rb +0 -36
- data/manual/document_and_page_options/page_size.rb +0 -34
- data/manual/document_and_page_options/print_scaling.rb +0 -23
- data/manual/example_helper.rb +0 -8
- data/manual/graphics/blend_mode.rb +0 -52
- data/manual/graphics/circle_and_ellipse.rb +0 -21
- data/manual/graphics/color.rb +0 -22
- data/manual/graphics/common_lines.rb +0 -29
- data/manual/graphics/fill_and_stroke.rb +0 -41
- data/manual/graphics/fill_rules.rb +0 -38
- data/manual/graphics/gradients.rb +0 -43
- data/manual/graphics/graphics.rb +0 -64
- data/manual/graphics/helper.rb +0 -34
- data/manual/graphics/line_width.rb +0 -36
- data/manual/graphics/lines_and_curves.rb +0 -40
- data/manual/graphics/polygon.rb +0 -27
- data/manual/graphics/rectangle.rb +0 -20
- data/manual/graphics/rotate.rb +0 -25
- data/manual/graphics/scale.rb +0 -42
- data/manual/graphics/soft_masks.rb +0 -44
- data/manual/graphics/stroke_cap.rb +0 -30
- data/manual/graphics/stroke_dash.rb +0 -47
- data/manual/graphics/stroke_join.rb +0 -29
- data/manual/graphics/translate.rb +0 -29
- data/manual/graphics/transparency.rb +0 -33
- data/manual/how_to_read_this_manual.rb +0 -39
- data/manual/images/absolute_position.rb +0 -22
- data/manual/images/fit.rb +0 -20
- data/manual/images/horizontal.rb +0 -24
- data/manual/images/images.rb +0 -41
- data/manual/images/plain_image.rb +0 -17
- data/manual/images/scale.rb +0 -21
- data/manual/images/vertical.rb +0 -30
- data/manual/images/width_and_height.rb +0 -24
- data/manual/layout/boxes.rb +0 -26
- data/manual/layout/content.rb +0 -24
- data/manual/layout/layout.rb +0 -27
- data/manual/layout/simple_grid.rb +0 -22
- data/manual/outline/add_subsection_to.rb +0 -60
- data/manual/outline/insert_section_after.rb +0 -46
- data/manual/outline/outline.rb +0 -33
- data/manual/outline/sections_and_pages.rb +0 -66
- data/manual/repeatable_content/alternate_page_numbering.rb +0 -36
- data/manual/repeatable_content/page_numbering.rb +0 -55
- data/manual/repeatable_content/repeatable_content.rb +0 -35
- data/manual/repeatable_content/repeater.rb +0 -54
- data/manual/repeatable_content/stamp.rb +0 -40
- data/manual/security/encryption.rb +0 -28
- data/manual/security/permissions.rb +0 -43
- data/manual/security/security.rb +0 -28
- data/manual/table.rb +0 -16
- data/manual/text/alignment.rb +0 -43
- data/manual/text/color.rb +0 -24
- data/manual/text/column_box.rb +0 -30
- data/manual/text/fallback_fonts.rb +0 -41
- data/manual/text/font.rb +0 -40
- data/manual/text/font_size.rb +0 -44
- data/manual/text/font_style.rb +0 -25
- data/manual/text/formatted_callbacks.rb +0 -70
- data/manual/text/formatted_text.rb +0 -61
- data/manual/text/free_flowing_text.rb +0 -50
- data/manual/text/inline.rb +0 -40
- data/manual/text/kerning_and_character_spacing.rb +0 -38
- data/manual/text/leading.rb +0 -24
- data/manual/text/line_wrapping.rb +0 -60
- data/manual/text/paragraph_indentation.rb +0 -31
- data/manual/text/positioned_text.rb +0 -37
- data/manual/text/registering_families.rb +0 -51
- data/manual/text/rendering_and_color.rb +0 -36
- data/manual/text/right_to_left_text.rb +0 -54
- data/manual/text/rotation.rb +0 -52
- data/manual/text/single_usage.rb +0 -36
- data/manual/text/text.rb +0 -75
- data/manual/text/text_box_excess.rb +0 -35
- data/manual/text/text_box_extensions.rb +0 -48
- data/manual/text/text_box_overflow.rb +0 -51
- data/manual/text/utf8.rb +0 -27
- data/manual/text/win_ansi_charset.rb +0 -62
- data/prawn.gemspec +0 -51
- data/spec/data/curves.pdf +0 -66
- data/spec/extensions/encoding_helpers.rb +0 -11
- data/spec/prawn/document/bounding_box_spec.rb +0 -550
- data/spec/prawn/document/column_box_spec.rb +0 -75
- data/spec/prawn/document/security_spec.rb +0 -176
- data/spec/prawn/document_annotations_spec.rb +0 -76
- data/spec/prawn/document_destinations_spec.rb +0 -15
- data/spec/prawn/document_grid_spec.rb +0 -99
- data/spec/prawn/document_reference_spec.rb +0 -27
- data/spec/prawn/document_span_spec.rb +0 -44
- data/spec/prawn/document_spec.rb +0 -805
- data/spec/prawn/font_metric_cache_spec.rb +0 -54
- data/spec/prawn/font_spec.rb +0 -544
- data/spec/prawn/graphics/blend_mode_spec.rb +0 -63
- data/spec/prawn/graphics/transparency_spec.rb +0 -81
- data/spec/prawn/graphics_spec.rb +0 -872
- data/spec/prawn/graphics_stroke_styles_spec.rb +0 -229
- data/spec/prawn/image_handler_spec.rb +0 -53
- data/spec/prawn/images/jpg_spec.rb +0 -20
- data/spec/prawn/images/png_spec.rb +0 -283
- data/spec/prawn/images_spec.rb +0 -229
- data/spec/prawn/measurements_extensions_spec.rb +0 -24
- data/spec/prawn/outline_spec.rb +0 -512
- data/spec/prawn/repeater_spec.rb +0 -166
- data/spec/prawn/soft_mask_spec.rb +0 -74
- data/spec/prawn/stamp_spec.rb +0 -173
- data/spec/prawn/text/box_spec.rb +0 -1110
- data/spec/prawn/text/formatted/arranger_spec.rb +0 -466
- data/spec/prawn/text/formatted/box_spec.rb +0 -849
- data/spec/prawn/text/formatted/fragment_spec.rb +0 -343
- data/spec/prawn/text/formatted/line_wrap_spec.rb +0 -495
- data/spec/prawn/text/formatted/parser_spec.rb +0 -697
- data/spec/prawn/text_draw_text_spec.rb +0 -150
- data/spec/prawn/text_rendering_mode_spec.rb +0 -48
- data/spec/prawn/text_spacing_spec.rb +0 -95
- data/spec/prawn/text_spec.rb +0 -603
- data/spec/prawn/text_with_inline_formatting_spec.rb +0 -35
- data/spec/prawn/transformation_stack_spec.rb +0 -66
- data/spec/prawn/view_spec.rb +0 -63
- data/spec/prawn_manual_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -48
@@ -1,11 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# text/formatted/fragment.rb : Implements information about a formatted fragment
|
4
|
-
#
|
5
|
-
# Copyright March 2010, Daniel Nelson. All Rights Reserved.
|
6
|
-
#
|
7
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
-
|
9
3
|
module Prawn
|
10
4
|
module Text
|
11
5
|
module Formatted
|
@@ -14,11 +8,19 @@ module Prawn
|
|
14
8
|
#
|
15
9
|
# @private
|
16
10
|
class Fragment
|
17
|
-
attr_reader :format_state
|
11
|
+
attr_reader :format_state
|
12
|
+
attr_reader :text
|
18
13
|
attr_writer :width
|
19
|
-
attr_accessor :line_height
|
20
|
-
attr_accessor :
|
21
|
-
|
14
|
+
attr_accessor :line_height
|
15
|
+
attr_accessor :descender
|
16
|
+
attr_accessor :ascender
|
17
|
+
attr_accessor :word_spacing
|
18
|
+
attr_accessor :left
|
19
|
+
attr_accessor :baseline
|
20
|
+
|
21
|
+
# @param text [String]
|
22
|
+
# @param format_state [Hash{Symbol => any}]
|
23
|
+
# @param document [Prawn::Documnt]
|
22
24
|
def initialize(text, format_state, document)
|
23
25
|
@format_state = format_state
|
24
26
|
@document = document
|
@@ -30,35 +32,58 @@ module Prawn
|
|
30
32
|
@text = process_text(@original_text)
|
31
33
|
end
|
32
34
|
|
35
|
+
# Width of fragment.
|
36
|
+
#
|
37
|
+
# @return [Number]
|
33
38
|
def width
|
34
39
|
if @word_spacing.zero? then @width
|
35
|
-
else
|
40
|
+
else
|
41
|
+
@width + (@word_spacing * space_count)
|
36
42
|
end
|
37
43
|
end
|
38
44
|
|
45
|
+
# Height of fragment.
|
46
|
+
#
|
47
|
+
# @return [Number]
|
39
48
|
def height
|
40
49
|
top - bottom
|
41
50
|
end
|
42
51
|
|
52
|
+
# Is this a subscript fragment?
|
53
|
+
#
|
54
|
+
# @return [Boolean]
|
43
55
|
def subscript?
|
44
56
|
styles.include?(:subscript)
|
45
57
|
end
|
46
58
|
|
59
|
+
# Is this a superscript fragment?
|
60
|
+
#
|
61
|
+
# @return [Boolean]
|
47
62
|
def superscript?
|
48
63
|
styles.include?(:superscript)
|
49
64
|
end
|
50
65
|
|
66
|
+
# Vertical offset of the fragment.
|
67
|
+
#
|
68
|
+
# @return [Number]
|
51
69
|
def y_offset
|
52
70
|
if subscript? then -descender
|
53
71
|
elsif superscript? then 0.85 * ascender
|
54
|
-
else
|
72
|
+
else
|
73
|
+
0
|
55
74
|
end
|
56
75
|
end
|
57
76
|
|
77
|
+
# Fragment bounding box, relative to the containing bounding box.
|
78
|
+
#
|
79
|
+
# @return [Array(Number, Number, Number, Number)]
|
58
80
|
def bounding_box
|
59
81
|
[left, bottom, right, top]
|
60
82
|
end
|
61
83
|
|
84
|
+
# Fragment bounding box, relative to the containing page.
|
85
|
+
#
|
86
|
+
# @return [Array(Number, Number, Number, Number)]
|
62
87
|
def absolute_bounding_box
|
63
88
|
box = bounding_box
|
64
89
|
box[0] += @document.bounds.absolute_left
|
@@ -68,53 +93,90 @@ module Prawn
|
|
68
93
|
box
|
69
94
|
end
|
70
95
|
|
96
|
+
# Underline endpoints.
|
97
|
+
#
|
98
|
+
# @return [Array(Array(Number, Number), Array(Number, Number))]
|
71
99
|
def underline_points
|
72
100
|
y = baseline - 1.25
|
73
101
|
[[left, y], [right, y]]
|
74
102
|
end
|
75
103
|
|
104
|
+
# Strikethrough endpoints.
|
105
|
+
#
|
106
|
+
# @return [Array(Array(Number, Number), Array(Number, Number))]
|
76
107
|
def strikethrough_points
|
77
|
-
y = baseline + ascender * 0.3
|
108
|
+
y = baseline + (ascender * 0.3)
|
78
109
|
[[left, y], [right, y]]
|
79
110
|
end
|
80
111
|
|
112
|
+
# Fragment font styles.
|
113
|
+
#
|
114
|
+
# @return [Array<Symbol>]
|
81
115
|
def styles
|
82
116
|
@format_state[:styles] || []
|
83
117
|
end
|
84
118
|
|
119
|
+
# Fragment link.
|
120
|
+
#
|
121
|
+
# @return [String, nil]
|
85
122
|
def link
|
86
123
|
@format_state[:link]
|
87
124
|
end
|
88
125
|
|
126
|
+
# Anchor.
|
127
|
+
#
|
128
|
+
# @return [PDF::Core::Reference, Array, Hash]
|
89
129
|
def anchor
|
90
130
|
@format_state[:anchor]
|
91
131
|
end
|
92
132
|
|
133
|
+
# Local destination.
|
134
|
+
#
|
135
|
+
# @return [String]
|
93
136
|
def local
|
94
137
|
@format_state[:local]
|
95
138
|
end
|
96
139
|
|
140
|
+
# Fragment color.
|
141
|
+
#
|
142
|
+
# @return [Color]
|
97
143
|
def color
|
98
144
|
@format_state[:color]
|
99
145
|
end
|
100
146
|
|
147
|
+
# Fragment font name.
|
148
|
+
#
|
149
|
+
# @return [String]
|
101
150
|
def font
|
102
151
|
@format_state[:font]
|
103
152
|
end
|
104
153
|
|
154
|
+
# Font size.
|
155
|
+
#
|
156
|
+
# @return [Number]
|
105
157
|
def size
|
106
158
|
@format_state[:size]
|
107
159
|
end
|
108
160
|
|
161
|
+
# Character spacing.
|
162
|
+
#
|
163
|
+
# @return [Number]
|
109
164
|
def character_spacing
|
110
165
|
@format_state[:character_spacing] ||
|
111
166
|
@document.character_spacing
|
112
167
|
end
|
113
168
|
|
169
|
+
# Text direction.
|
170
|
+
#
|
171
|
+
# @return [:ltr, :rtl]
|
114
172
|
def direction
|
115
173
|
@format_state[:direction]
|
116
174
|
end
|
117
175
|
|
176
|
+
# Set default text direction.
|
177
|
+
#
|
178
|
+
# @param direction [:ltr, :rtl]
|
179
|
+
# @return [void]
|
118
180
|
def default_direction=(direction)
|
119
181
|
unless @format_state[:direction]
|
120
182
|
@format_state[:direction] = direction
|
@@ -122,15 +184,24 @@ module Prawn
|
|
122
184
|
end
|
123
185
|
end
|
124
186
|
|
187
|
+
# Keep trailing spaces.
|
188
|
+
#
|
189
|
+
# @return [void]
|
125
190
|
def include_trailing_white_space!
|
126
191
|
@format_state.delete(:exclude_trailing_white_space)
|
127
192
|
@text = process_text(@original_text)
|
128
193
|
end
|
129
194
|
|
195
|
+
# Number of spaces in the text.
|
196
|
+
#
|
197
|
+
# @return [Integer]
|
130
198
|
def space_count
|
131
199
|
@text.count(' ')
|
132
200
|
end
|
133
201
|
|
202
|
+
# Callbacks.
|
203
|
+
#
|
204
|
+
# @return [Array]
|
134
205
|
def callback_objects
|
135
206
|
callback = @format_state[:callback]
|
136
207
|
if callback.nil?
|
@@ -142,62 +213,107 @@ module Prawn
|
|
142
213
|
end
|
143
214
|
end
|
144
215
|
|
216
|
+
# Horizontal coordinate of the right side of the fragment.
|
217
|
+
#
|
218
|
+
# @return [Number]
|
145
219
|
def right
|
146
220
|
left + width
|
147
221
|
end
|
148
222
|
|
223
|
+
# Vertical coordinate of the top side of the fragment.
|
224
|
+
#
|
225
|
+
# @return [Number]
|
149
226
|
def top
|
150
227
|
baseline + ascender
|
151
228
|
end
|
152
229
|
|
230
|
+
# Vertical coordinate of the bottom side of the fragment.
|
231
|
+
#
|
232
|
+
# @return [Number]
|
153
233
|
def bottom
|
154
234
|
baseline - descender
|
155
235
|
end
|
156
236
|
|
237
|
+
# Coordinates of the top left corner of the fragment.
|
238
|
+
#
|
239
|
+
# @return [Array(Number, Number)]
|
157
240
|
def top_left
|
158
241
|
[left, top]
|
159
242
|
end
|
160
243
|
|
244
|
+
# Coordinates of the top right corner of the fragment.
|
245
|
+
#
|
246
|
+
# @return [Array(Number, Number)]
|
161
247
|
def top_right
|
162
248
|
[right, top]
|
163
249
|
end
|
164
250
|
|
251
|
+
# Coordinates of the bottom right corner of the fragment.
|
252
|
+
#
|
253
|
+
# @return [Array(Number, Number)]
|
165
254
|
def bottom_right
|
166
255
|
[right, bottom]
|
167
256
|
end
|
168
257
|
|
258
|
+
# Coordinates of the bottom left corner of the fragment.
|
259
|
+
#
|
260
|
+
# @return [Array(Number, Number)]
|
169
261
|
def bottom_left
|
170
262
|
[left, bottom]
|
171
263
|
end
|
172
264
|
|
265
|
+
# Absolute horizontal coordinate of the left side of the fragment.
|
266
|
+
#
|
267
|
+
# @return [Number]
|
173
268
|
def absolute_left
|
174
269
|
absolute_bounding_box[0]
|
175
270
|
end
|
176
271
|
|
272
|
+
# Absolute horizontal coordinate of the right side of the fragment.
|
273
|
+
#
|
274
|
+
# @return [Number]
|
177
275
|
def absolute_right
|
178
276
|
absolute_bounding_box[2]
|
179
277
|
end
|
180
278
|
|
279
|
+
# Absolute vertical coordinate of the top side of the fragment.
|
280
|
+
#
|
281
|
+
# @return [Number]
|
181
282
|
def absolute_top
|
182
283
|
absolute_bounding_box[3]
|
183
284
|
end
|
184
285
|
|
286
|
+
# Absolute vertical coordinate of the bottom side of the fragment.
|
287
|
+
#
|
288
|
+
# @return [Number]
|
185
289
|
def absolute_bottom
|
186
290
|
absolute_bounding_box[1]
|
187
291
|
end
|
188
292
|
|
293
|
+
# Absolute coordinates of the top left corner of the fragment.
|
294
|
+
#
|
295
|
+
# @return [Array(Number, Number)]
|
189
296
|
def absolute_top_left
|
190
297
|
[absolute_left, absolute_top]
|
191
298
|
end
|
192
299
|
|
300
|
+
# Absolute coordinates of the top right corner of the fragment.
|
301
|
+
#
|
302
|
+
# @return [Array(Number, Number)]
|
193
303
|
def absolute_top_right
|
194
304
|
[absolute_right, absolute_top]
|
195
305
|
end
|
196
306
|
|
307
|
+
# Absolute coordinates of the bottom left corner of the fragment.
|
308
|
+
#
|
309
|
+
# @return [Array(Number, Number)]
|
197
310
|
def absolute_bottom_left
|
198
311
|
[absolute_left, absolute_bottom]
|
199
312
|
end
|
200
313
|
|
314
|
+
# Absolute coordinates of the bottom right corner of the fragment.
|
315
|
+
#
|
316
|
+
# @return [Array(Number, Number)]
|
201
317
|
def absolute_bottom_right
|
202
318
|
[absolute_right, absolute_bottom]
|
203
319
|
end
|
@@ -211,7 +327,7 @@ module Prawn
|
|
211
327
|
string = string.rstrip
|
212
328
|
|
213
329
|
if soft_hyphens_need_processing?(string)
|
214
|
-
string = process_soft_hyphens(string[0..-2]) + string[-1
|
330
|
+
string = process_soft_hyphens(string[0..-2]) + string[-1..]
|
215
331
|
end
|
216
332
|
elsif soft_hyphens_need_processing?(string)
|
217
333
|
string = process_soft_hyphens(string)
|
@@ -1,40 +1,49 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# core/text/formatted/line_wrap.rb : Implements individual line wrapping of
|
4
|
-
# formatted text
|
5
|
-
#
|
6
|
-
# Copyright February 2010, Daniel Nelson. All Rights Reserved.
|
7
|
-
#
|
8
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
9
|
-
#
|
10
|
-
|
11
3
|
module Prawn
|
12
4
|
module Text
|
13
|
-
module Formatted
|
5
|
+
module Formatted
|
6
|
+
# Implements individual line wrapping of formatted text.
|
7
|
+
#
|
14
8
|
# @private
|
15
|
-
class LineWrap
|
16
|
-
# The width of the last wrapped line
|
9
|
+
class LineWrap
|
10
|
+
# The width of the last wrapped line.
|
17
11
|
#
|
12
|
+
# @return [Number]
|
18
13
|
def width
|
19
14
|
@accumulated_width || 0
|
20
15
|
end
|
21
16
|
|
22
|
-
# The number of spaces in the last wrapped line
|
17
|
+
# The number of spaces in the last wrapped line.
|
18
|
+
# @return [Integer]
|
23
19
|
attr_reader :space_count
|
24
20
|
|
25
|
-
# Whether this line is the last line in the paragraph
|
21
|
+
# Whether this line is the last line in the paragraph.
|
22
|
+
#
|
23
|
+
# @return [Boolean]
|
26
24
|
def paragraph_finished?
|
27
25
|
@newline_encountered || next_string_newline? || @arranger.finished?
|
28
26
|
end
|
29
27
|
|
28
|
+
# Break the fragment into tokens.
|
29
|
+
#
|
30
|
+
# @param fragment [String]
|
31
|
+
# @return [Array<String>]
|
30
32
|
def tokenize(fragment)
|
31
33
|
fragment.scan(scan_pattern(fragment.encoding))
|
32
34
|
end
|
33
35
|
|
34
|
-
# Work in conjunction with the
|
35
|
-
# defined in the
|
36
|
-
# will fit within the width defined by the
|
36
|
+
# Work in conjunction with the {Prawn::Text::Formatted::Arranger}
|
37
|
+
# defined in the `:arranger` option to determine what formatted text
|
38
|
+
# will fit within the width defined by the `:width` option.
|
37
39
|
#
|
40
|
+
# @param options [Hash{Symbol => any}]
|
41
|
+
# @option options :document [Prawn::Document]
|
42
|
+
# @option options :kerning [Boolean]
|
43
|
+
# @option options :width [Number]
|
44
|
+
# @option options :disable_wrap_by_char [Boolean]
|
45
|
+
# @option options :arranger [Prawn::Text::Formatted::Arranger]
|
46
|
+
# @return [String]
|
38
47
|
def wrap_line(options)
|
39
48
|
initialize_line(options)
|
40
49
|
|
@@ -138,7 +147,7 @@ module Prawn
|
|
138
147
|
"[^#{ebc}]+",
|
139
148
|
"[#{ews}]+",
|
140
149
|
"#{ehy}+[^#{ebc}]*",
|
141
|
-
eshy.to_s
|
150
|
+
eshy.to_s,
|
142
151
|
]
|
143
152
|
|
144
153
|
pattern = patterns
|
@@ -154,17 +163,17 @@ module Prawn
|
|
154
163
|
#
|
155
164
|
def word_division_scan_pattern(encoding = ::Encoding::UTF_8)
|
156
165
|
common_whitespaces =
|
157
|
-
["\t", "\n", "\v", "\r", ' '].map
|
166
|
+
["\t", "\n", "\v", "\r", ' '].map { |c|
|
158
167
|
c.encode(encoding)
|
159
|
-
|
168
|
+
}
|
160
169
|
|
161
170
|
Regexp.union(
|
162
171
|
common_whitespaces +
|
163
172
|
[
|
164
173
|
zero_width_space(encoding),
|
165
174
|
soft_hyphen(encoding),
|
166
|
-
hyphen(encoding)
|
167
|
-
].compact
|
175
|
+
hyphen(encoding),
|
176
|
+
].compact,
|
168
177
|
)
|
169
178
|
end
|
170
179
|
|
@@ -179,7 +188,7 @@ module Prawn
|
|
179
188
|
[
|
180
189
|
whitespace(encoding),
|
181
190
|
soft_hyphen(encoding),
|
182
|
-
hyphen(encoding)
|
191
|
+
hyphen(encoding),
|
183
192
|
].join('')
|
184
193
|
end
|
185
194
|
|
@@ -230,7 +239,7 @@ module Prawn
|
|
230
239
|
else
|
231
240
|
update_output_based_on_last_fragment(
|
232
241
|
fragment,
|
233
|
-
soft_hyphen(fragment.encoding)
|
242
|
+
soft_hyphen(fragment.encoding),
|
234
243
|
)
|
235
244
|
update_line_status_based_on_last_output
|
236
245
|
pull_preceding_fragment_to_join_this_one?(fragment)
|
@@ -251,7 +260,7 @@ module Prawn
|
|
251
260
|
@arranger.update_last_string(
|
252
261
|
@fragment_output,
|
253
262
|
remaining_text,
|
254
|
-
normalized_soft_hyphen
|
263
|
+
normalized_soft_hyphen,
|
255
264
|
)
|
256
265
|
end
|
257
266
|
|