prawn 2.2.2 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/GPLv2 +20 -21
- data/Gemfile +2 -0
- data/Rakefile +10 -3
- data/lib/prawn.rb +9 -3
- data/lib/prawn/document.rb +40 -18
- data/lib/prawn/document/bounding_box.rb +9 -4
- data/lib/prawn/document/column_box.rb +2 -0
- data/lib/prawn/document/internals.rb +6 -4
- data/lib/prawn/document/span.rb +2 -0
- data/lib/prawn/encoding.rb +4 -1
- data/lib/prawn/errors.rb +2 -0
- data/lib/prawn/font.rb +34 -17
- data/lib/prawn/font_metric_cache.rb +8 -3
- data/lib/prawn/{font → fonts}/afm.rb +14 -7
- data/lib/prawn/{font → fonts}/dfont.rb +3 -1
- data/lib/prawn/fonts/otf.rb +11 -0
- data/lib/prawn/{font → fonts}/ttc.rb +3 -1
- data/lib/prawn/{font → fonts}/ttf.rb +23 -12
- data/lib/prawn/graphics.rb +24 -26
- data/lib/prawn/graphics/blend_mode.rb +2 -0
- data/lib/prawn/graphics/cap_style.rb +2 -0
- data/lib/prawn/graphics/color.rb +8 -3
- data/lib/prawn/graphics/dash.rb +3 -1
- data/lib/prawn/graphics/join_style.rb +2 -0
- data/lib/prawn/graphics/patterns.rb +7 -2
- data/lib/prawn/graphics/transformation.rb +5 -1
- data/lib/prawn/graphics/transparency.rb +2 -0
- data/lib/prawn/grid.rb +39 -38
- data/lib/prawn/image_handler.rb +2 -0
- data/lib/prawn/images.rb +21 -19
- data/lib/prawn/images/image.rb +2 -0
- data/lib/prawn/images/jpg.rb +2 -0
- data/lib/prawn/images/png.rb +9 -9
- data/lib/prawn/measurement_extensions.rb +2 -0
- data/lib/prawn/measurements.rb +5 -0
- data/lib/prawn/outline.rb +2 -0
- data/lib/prawn/repeater.rb +2 -0
- data/lib/prawn/security.rb +26 -24
- data/lib/prawn/security/arcfour.rb +2 -0
- data/lib/prawn/soft_mask.rb +3 -1
- data/lib/prawn/stamp.rb +4 -1
- data/lib/prawn/text.rb +14 -12
- data/lib/prawn/text/box.rb +3 -1
- data/lib/prawn/text/formatted.rb +2 -0
- data/lib/prawn/text/formatted/arranger.rb +12 -12
- data/lib/prawn/text/formatted/box.rb +23 -13
- data/lib/prawn/text/formatted/fragment.rb +2 -0
- data/lib/prawn/text/formatted/line_wrap.rb +10 -8
- data/lib/prawn/text/formatted/parser.rb +8 -10
- data/lib/prawn/text/formatted/wrap.rb +4 -2
- data/lib/prawn/transformation_stack.rb +5 -2
- data/lib/prawn/utilities.rb +2 -2
- data/lib/prawn/version.rb +3 -1
- data/lib/prawn/view.rb +15 -7
- data/manual/basic_concepts/adding_pages.rb +2 -0
- data/manual/basic_concepts/basic_concepts.rb +4 -2
- data/manual/basic_concepts/creation.rb +2 -0
- data/manual/basic_concepts/cursor.rb +2 -0
- data/manual/basic_concepts/measurement.rb +3 -1
- data/manual/basic_concepts/origin.rb +2 -0
- data/manual/basic_concepts/other_cursor_helpers.rb +2 -0
- data/manual/basic_concepts/view.rb +2 -0
- data/manual/bounding_box/bounding_box.rb +4 -2
- data/manual/bounding_box/bounds.rb +6 -4
- data/manual/bounding_box/canvas.rb +2 -0
- data/manual/bounding_box/creation.rb +2 -0
- data/manual/bounding_box/indentation.rb +2 -0
- data/manual/bounding_box/nesting.rb +2 -0
- data/manual/bounding_box/russian_boxes.rb +6 -4
- data/manual/bounding_box/stretchy.rb +2 -0
- data/manual/contents.rb +2 -0
- data/manual/cover.rb +10 -7
- data/manual/document_and_page_options/background.rb +2 -0
- data/manual/document_and_page_options/document_and_page_options.rb +4 -2
- data/manual/document_and_page_options/metadata.rb +2 -0
- data/manual/document_and_page_options/page_margins.rb +2 -0
- data/manual/document_and_page_options/page_size.rb +2 -0
- data/manual/document_and_page_options/print_scaling.rb +2 -0
- data/manual/example_helper.rb +5 -2
- data/manual/graphics/blend_mode.rb +6 -4
- data/manual/graphics/circle_and_ellipse.rb +2 -0
- data/manual/graphics/color.rb +2 -0
- data/manual/graphics/common_lines.rb +2 -0
- data/manual/graphics/fill_and_stroke.rb +2 -0
- data/manual/graphics/fill_rules.rb +2 -0
- data/manual/graphics/gradients.rb +2 -0
- data/manual/graphics/graphics.rb +4 -2
- data/manual/graphics/helper.rb +2 -0
- data/manual/graphics/line_width.rb +3 -0
- data/manual/graphics/lines_and_curves.rb +2 -0
- data/manual/graphics/polygon.rb +2 -0
- data/manual/graphics/rectangle.rb +2 -0
- data/manual/graphics/rotate.rb +2 -0
- data/manual/graphics/scale.rb +2 -0
- data/manual/graphics/soft_masks.rb +2 -0
- data/manual/graphics/stroke_cap.rb +3 -1
- data/manual/graphics/stroke_dash.rb +2 -0
- data/manual/graphics/stroke_join.rb +3 -1
- data/manual/graphics/translate.rb +2 -0
- data/manual/graphics/transparency.rb +2 -0
- data/manual/how_to_read_this_manual.rb +2 -0
- data/manual/images/absolute_position.rb +2 -0
- data/manual/images/fit.rb +2 -0
- data/manual/images/horizontal.rb +3 -1
- data/manual/images/images.rb +4 -2
- data/manual/images/plain_image.rb +2 -0
- data/manual/images/scale.rb +2 -0
- data/manual/images/vertical.rb +3 -1
- data/manual/images/width_and_height.rb +2 -0
- data/manual/layout/boxes.rb +2 -0
- data/manual/layout/content.rb +2 -0
- data/manual/layout/layout.rb +4 -2
- data/manual/layout/simple_grid.rb +2 -0
- data/manual/outline/add_subsection_to.rb +2 -0
- data/manual/outline/insert_section_after.rb +2 -0
- data/manual/outline/outline.rb +4 -2
- data/manual/outline/sections_and_pages.rb +2 -0
- data/manual/repeatable_content/alternate_page_numbering.rb +2 -0
- data/manual/repeatable_content/page_numbering.rb +2 -0
- data/manual/repeatable_content/repeatable_content.rb +4 -2
- data/manual/repeatable_content/repeater.rb +2 -0
- data/manual/repeatable_content/stamp.rb +2 -0
- data/manual/security/encryption.rb +2 -0
- data/manual/security/permissions.rb +2 -0
- data/manual/security/security.rb +4 -2
- data/manual/table.rb +2 -0
- data/manual/text/alignment.rb +2 -0
- data/manual/text/color.rb +2 -0
- data/manual/text/column_box.rb +4 -2
- data/manual/text/fallback_fonts.rb +4 -2
- data/manual/text/font.rb +2 -0
- data/manual/text/font_size.rb +2 -0
- data/manual/text/font_style.rb +4 -2
- data/manual/text/formatted_callbacks.rb +2 -0
- data/manual/text/formatted_text.rb +3 -1
- data/manual/text/free_flowing_text.rb +2 -0
- data/manual/text/inline.rb +2 -0
- data/manual/text/kerning_and_character_spacing.rb +2 -0
- data/manual/text/leading.rb +2 -0
- data/manual/text/line_wrapping.rb +4 -1
- data/manual/text/paragraph_indentation.rb +2 -0
- data/manual/text/positioned_text.rb +2 -0
- data/manual/text/registering_families.rb +4 -2
- data/manual/text/rendering_and_color.rb +2 -0
- data/manual/text/right_to_left_text.rb +2 -0
- data/manual/text/rotation.rb +3 -1
- data/manual/text/single_usage.rb +2 -0
- data/manual/text/text.rb +4 -3
- data/manual/text/text_box_excess.rb +2 -0
- data/manual/text/text_box_extensions.rb +2 -0
- data/manual/text/text_box_overflow.rb +3 -1
- data/manual/text/utf8.rb +3 -1
- data/manual/text/win_ansi_charset.rb +6 -3
- data/prawn.gemspec +14 -11
- data/spec/extensions/encoding_helpers.rb +4 -2
- data/spec/prawn/document/bounding_box_spec.rb +8 -8
- data/spec/prawn/document/column_box_spec.rb +2 -0
- data/spec/prawn/document/security_spec.rb +12 -9
- data/spec/prawn/document_annotations_spec.rb +2 -0
- data/spec/prawn/document_destinations_spec.rb +2 -0
- data/spec/prawn/document_grid_spec.rb +3 -0
- data/spec/prawn/document_reference_spec.rb +2 -0
- data/spec/prawn/document_span_spec.rb +2 -0
- data/spec/prawn/document_spec.rb +59 -14
- data/spec/prawn/font_metric_cache_spec.rb +2 -0
- data/spec/prawn/font_spec.rb +45 -16
- data/spec/prawn/graphics/blend_mode_spec.rb +4 -2
- data/spec/prawn/graphics/transparency_spec.rb +2 -0
- data/spec/prawn/graphics_spec.rb +40 -20
- data/spec/prawn/graphics_stroke_styles_spec.rb +2 -0
- data/spec/prawn/image_handler_spec.rb +2 -0
- data/spec/prawn/images/jpg_spec.rb +2 -0
- data/spec/prawn/images/png_spec.rb +2 -0
- data/spec/prawn/images_spec.rb +56 -2
- data/spec/prawn/measurements_extensions_spec.rb +2 -0
- data/spec/prawn/outline_spec.rb +6 -2
- data/spec/prawn/repeater_spec.rb +6 -4
- data/spec/prawn/soft_mask_spec.rb +2 -0
- data/spec/prawn/stamp_spec.rb +11 -7
- data/spec/prawn/text/box_spec.rb +26 -27
- data/spec/prawn/text/formatted/arranger_spec.rb +30 -28
- data/spec/prawn/text/formatted/box_spec.rb +78 -57
- data/spec/prawn/text/formatted/fragment_spec.rb +10 -8
- data/spec/prawn/text/formatted/line_wrap_spec.rb +8 -5
- data/spec/prawn/text/formatted/parser_spec.rb +32 -2
- data/spec/prawn/text_draw_text_spec.rb +5 -3
- data/spec/prawn/text_rendering_mode_spec.rb +7 -1
- data/spec/prawn/text_spacing_spec.rb +6 -4
- data/spec/prawn/text_spec.rb +9 -7
- data/spec/prawn/text_with_inline_formatting_spec.rb +3 -1
- data/spec/prawn/transformation_stack_spec.rb +2 -0
- data/spec/prawn/view_spec.rb +18 -0
- data/spec/{manual_spec.rb → prawn_manual_spec.rb} +6 -4
- data/spec/spec_helper.rb +9 -10
- metadata +86 -73
- metadata.gz.sig +4 -2
data/lib/prawn/soft_mask.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# soft_mask.rb : Implements soft-masking
|
2
4
|
#
|
3
5
|
# Copyright September 2012, Alexander Mankuta. All Rights Reserved.
|
@@ -73,7 +75,7 @@ module Prawn
|
|
73
75
|
renderer.add_content "/#{soft_mask_registry[registry_key]} gs"
|
74
76
|
else
|
75
77
|
masks = page.resources[:ExtGState] ||= {}
|
76
|
-
id = masks.empty? ? 'GS1' : masks.keys.
|
78
|
+
id = masks.empty? ? 'GS1' : masks.keys.max.succ
|
77
79
|
masks[id] = g_state
|
78
80
|
|
79
81
|
soft_mask_registry[registry_key] = id
|
data/lib/prawn/stamp.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# stamp.rb : Implements a repeatable stamp
|
2
4
|
#
|
3
5
|
# Copyright October 2009, Daniel Nelson. All Rights Reserved.
|
@@ -105,6 +107,7 @@ module Prawn
|
|
105
107
|
def create_stamp_dictionary(name)
|
106
108
|
raise Prawn::Errors::InvalidName if name.empty?
|
107
109
|
raise Prawn::Errors::NameTaken unless stamp_dictionary_registry[name].nil?
|
110
|
+
|
108
111
|
# BBox origin is the lower left margin of the page, so we need
|
109
112
|
# it to be the full dimension of the page, or else things that
|
110
113
|
# should appear near the top or right margin are invisible
|
@@ -131,7 +134,7 @@ module Prawn
|
|
131
134
|
# to the /Annot dictionary of the object that contains the
|
132
135
|
# call to the stamp object.
|
133
136
|
def update_annotation_references(annots)
|
134
|
-
if annots
|
137
|
+
if annots&.any?
|
135
138
|
state.page.dictionary.data[:Annots] ||= []
|
136
139
|
state.page.dictionary.data[:Annots] |= annots
|
137
140
|
end
|
data/lib/prawn/text.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# text.rb : Implements PDF text primitives
|
2
4
|
#
|
3
5
|
# Copyright May 2008, Gregory Brown. All Rights Reserved.
|
@@ -6,8 +8,6 @@
|
|
6
8
|
|
7
9
|
require 'zlib'
|
8
10
|
|
9
|
-
require 'pdf/core/text'
|
10
|
-
|
11
11
|
require_relative 'text/formatted'
|
12
12
|
require_relative 'text/box'
|
13
13
|
|
@@ -17,11 +17,11 @@ module Prawn
|
|
17
17
|
include Prawn::Text::Formatted
|
18
18
|
|
19
19
|
# No-Break Space
|
20
|
-
NBSP = "\u00A0"
|
20
|
+
NBSP = "\u00A0"
|
21
21
|
# Zero Width Space (indicate word boundaries without a space)
|
22
|
-
ZWSP = "\u200B"
|
22
|
+
ZWSP = "\u200B"
|
23
23
|
# Soft Hyphen (invisible, except when causing a line break)
|
24
|
-
SHY = "\u00AD"
|
24
|
+
SHY = "\u00AD"
|
25
25
|
|
26
26
|
# @group Stable API
|
27
27
|
|
@@ -151,6 +151,7 @@ module Prawn
|
|
151
151
|
#
|
152
152
|
def text(string, options = {})
|
153
153
|
return false if string.nil?
|
154
|
+
|
154
155
|
# we modify the options. don't change the user's hash
|
155
156
|
options = options.dup
|
156
157
|
|
@@ -281,7 +282,7 @@ module Prawn
|
|
281
282
|
text = text.to_s.dup
|
282
283
|
save_font do
|
283
284
|
process_text_options(options)
|
284
|
-
font.normalize_encoding
|
285
|
+
text = font.normalize_encoding(text)
|
285
286
|
font_size(options[:size]) { draw_text!(text, options) }
|
286
287
|
end
|
287
288
|
end
|
@@ -293,9 +294,9 @@ module Prawn
|
|
293
294
|
unless font.unicode? || font.class.hide_m17n_warning || text.ascii_only?
|
294
295
|
warn "PDF's built-in fonts have very limited support for " \
|
295
296
|
"internationalized text.\nIf you need full UTF-8 support, " \
|
296
|
-
"consider using
|
297
|
+
"consider using an external font instead.\n\nTo disable this " \
|
297
298
|
"warning, add the following line to your code:\n" \
|
298
|
-
"Prawn::
|
299
|
+
"Prawn::Fonts::AFM.hide_m17n_warning = true\n"
|
299
300
|
|
300
301
|
font.class.hide_m17n_warning = true
|
301
302
|
end
|
@@ -409,10 +410,11 @@ module Prawn
|
|
409
410
|
elsif options[:align]
|
410
411
|
raise ArgumentError, 'The :align option does not work with draw_text'
|
411
412
|
end
|
413
|
+
|
412
414
|
if options[:kerning].nil?
|
413
415
|
options[:kerning] = default_kerning?
|
414
416
|
end
|
415
|
-
valid_options = PDF::Core::Text::VALID_OPTIONS + [
|
417
|
+
valid_options = PDF::Core::Text::VALID_OPTIONS + %i[at rotate]
|
416
418
|
Prawn.verify_options(valid_options, options)
|
417
419
|
options
|
418
420
|
end
|
@@ -438,7 +440,7 @@ module Prawn
|
|
438
440
|
options.delete(:indent_paragraphs)
|
439
441
|
end
|
440
442
|
|
441
|
-
def move_text_position(
|
443
|
+
def move_text_position(amount)
|
442
444
|
bottom =
|
443
445
|
if @bounding_box.stretchy?
|
444
446
|
@margin_box.absolute_bottom
|
@@ -446,9 +448,9 @@ module Prawn
|
|
446
448
|
@bounding_box.absolute_bottom
|
447
449
|
end
|
448
450
|
|
449
|
-
@bounding_box.move_past_bottom if (y -
|
451
|
+
@bounding_box.move_past_bottom if (y - amount) < bottom
|
450
452
|
|
451
|
-
self.y -=
|
453
|
+
self.y -= amount
|
452
454
|
end
|
453
455
|
end
|
454
456
|
end
|
data/lib/prawn/text/box.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# text/rectangle.rb : Implements text boxes
|
2
4
|
#
|
3
5
|
# Copyright November 2009, Daniel Nelson. All Rights Reserved.
|
@@ -59,7 +61,7 @@ module Prawn
|
|
59
61
|
# or right-to-left) [value of document.text_direction]
|
60
62
|
# <tt>:fallback_fonts</tt>::
|
61
63
|
# An array of font names. Each name must be the name of an AFM font or
|
62
|
-
# the name that was used to register a family of
|
64
|
+
# the name that was used to register a family of external fonts (see
|
63
65
|
# Prawn::Document#font_families). If present, then each glyph will be
|
64
66
|
# rendered using the first font that includes the glyph, starting with
|
65
67
|
# the current font and then moving through :fallback_fonts from
|
data/lib/prawn/text/formatted.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# core/text/formatted/arranger.rb : Implements a data structure for 2-stage
|
2
4
|
# processing of lines of formatted text
|
3
5
|
#
|
@@ -5,8 +7,6 @@
|
|
5
7
|
#
|
6
8
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
7
9
|
|
8
|
-
# rubocop: disable Style/AccessorMethodName
|
9
|
-
|
10
10
|
module Prawn
|
11
11
|
module Text
|
12
12
|
module Formatted #:nodoc:
|
@@ -57,12 +57,10 @@ module Prawn
|
|
57
57
|
end
|
58
58
|
|
59
59
|
@fragments.collect do |fragment|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
fragment.text.dup.force_encoding(::Encoding::UTF_8)
|
65
|
-
end
|
60
|
+
fragment.text.dup.encode(::Encoding::UTF_8)
|
61
|
+
rescue ::Encoding::InvalidByteSequenceError,
|
62
|
+
::Encoding::UndefinedConversionError
|
63
|
+
fragment.text.dup.force_encoding(::Encoding::UTF_8)
|
66
64
|
end.join
|
67
65
|
end
|
68
66
|
|
@@ -81,8 +79,8 @@ module Prawn
|
|
81
79
|
@document
|
82
80
|
)
|
83
81
|
@fragments << fragment
|
84
|
-
|
85
|
-
|
82
|
+
self.fragment_measurements = fragment
|
83
|
+
self.line_measurement_maximums = fragment
|
86
84
|
end
|
87
85
|
end
|
88
86
|
|
@@ -166,6 +164,7 @@ module Prawn
|
|
166
164
|
@document.character_spacing(character_spacing) do
|
167
165
|
if font || font_style != :normal
|
168
166
|
raise 'Bad font family' unless @document.font.family
|
167
|
+
|
169
168
|
@document.font(
|
170
169
|
font || @document.font.family, style: font_style
|
171
170
|
) do
|
@@ -179,6 +178,7 @@ module Prawn
|
|
179
178
|
|
180
179
|
def update_last_string(printed, unprinted, normalized_soft_hyphen = nil)
|
181
180
|
return if printed.nil?
|
181
|
+
|
182
182
|
if printed.empty?
|
183
183
|
@consumed.pop
|
184
184
|
else
|
@@ -284,7 +284,7 @@ module Prawn
|
|
284
284
|
end
|
285
285
|
end
|
286
286
|
|
287
|
-
def
|
287
|
+
def fragment_measurements=(fragment)
|
288
288
|
apply_font_settings(fragment) do
|
289
289
|
fragment.width = @document.width_of(
|
290
290
|
fragment.text,
|
@@ -296,7 +296,7 @@ module Prawn
|
|
296
296
|
end
|
297
297
|
end
|
298
298
|
|
299
|
-
def
|
299
|
+
def line_measurement_maximums=(fragment)
|
300
300
|
@max_line_height = [
|
301
301
|
defined?(@max_line_height) && @max_line_height,
|
302
302
|
fragment.line_height
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# text/formatted/rectangle.rb : Implements text boxes with formatted text
|
2
4
|
#
|
3
5
|
# Copyright February 2010, Daniel Nelson. All Rights Reserved.
|
@@ -246,6 +248,7 @@ module Prawn
|
|
246
248
|
#
|
247
249
|
def height
|
248
250
|
return 0 if @baseline_y.nil? || @descender.nil?
|
251
|
+
|
249
252
|
(@baseline_y - @descender).abs
|
250
253
|
end
|
251
254
|
|
@@ -267,6 +270,9 @@ module Prawn
|
|
267
270
|
else
|
268
271
|
@at[0] + @width - line_width
|
269
272
|
end
|
273
|
+
else
|
274
|
+
raise ArgumentError,
|
275
|
+
'align must be one of :left, :right, :center or :justify symbols'
|
270
276
|
end
|
271
277
|
|
272
278
|
x += accumulated_width
|
@@ -338,19 +344,19 @@ module Prawn
|
|
338
344
|
end
|
339
345
|
|
340
346
|
def valid_options
|
341
|
-
PDF::Core::Text::VALID_OPTIONS + [
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
347
|
+
PDF::Core::Text::VALID_OPTIONS + %i[
|
348
|
+
at
|
349
|
+
height width
|
350
|
+
align valign
|
351
|
+
rotate rotate_around
|
352
|
+
overflow min_font_size
|
353
|
+
disable_wrap_by_char
|
354
|
+
leading character_spacing
|
355
|
+
mode single_line
|
356
|
+
document
|
357
|
+
direction
|
358
|
+
fallback_fonts
|
359
|
+
draw_text_callback
|
354
360
|
]
|
355
361
|
end
|
356
362
|
|
@@ -496,6 +502,7 @@ module Prawn
|
|
496
502
|
@vertical_alignment_processed
|
497
503
|
return
|
498
504
|
end
|
505
|
+
|
499
506
|
@vertical_alignment_processed = true
|
500
507
|
|
501
508
|
return if @vertical_align == :top
|
@@ -587,6 +594,7 @@ module Prawn
|
|
587
594
|
|
588
595
|
def draw_fragment_overlay_link(fragment)
|
589
596
|
return unless fragment.link
|
597
|
+
|
590
598
|
box = fragment.absolute_bounding_box
|
591
599
|
@document.link_annotation(
|
592
600
|
box,
|
@@ -601,6 +609,7 @@ module Prawn
|
|
601
609
|
|
602
610
|
def draw_fragment_overlay_anchor(fragment)
|
603
611
|
return unless fragment.anchor
|
612
|
+
|
604
613
|
box = fragment.absolute_bounding_box
|
605
614
|
@document.link_annotation(
|
606
615
|
box,
|
@@ -611,6 +620,7 @@ module Prawn
|
|
611
620
|
|
612
621
|
def draw_fragment_overlay_local(fragment)
|
613
622
|
return unless fragment.local
|
623
|
+
|
614
624
|
box = fragment.absolute_bounding_box
|
615
625
|
@document.link_annotation(
|
616
626
|
box,
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# core/text/formatted/line_wrap.rb : Implements individual line wrapping of
|
2
4
|
# formatted text
|
3
5
|
#
|
@@ -39,7 +41,7 @@ module Prawn
|
|
39
41
|
# rubocop: disable Lint/AssignmentInCondition
|
40
42
|
while fragment = @arranger.next_string
|
41
43
|
# rubocop: enable Lint/AssignmentInCondition
|
42
|
-
@fragment_output = ''
|
44
|
+
@fragment_output = +''
|
43
45
|
|
44
46
|
fragment.lstrip! if first_fragment_on_this_line?(fragment)
|
45
47
|
next if empty_line?(fragment)
|
@@ -91,11 +93,11 @@ module Prawn
|
|
91
93
|
false
|
92
94
|
else
|
93
95
|
tokenize(fragment).each do |segment|
|
94
|
-
if segment == zero_width_space(segment.encoding)
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
segment_width = if segment == zero_width_space(segment.encoding)
|
97
|
+
0
|
98
|
+
else
|
99
|
+
@document.width_of(segment, kerning: @kerning)
|
100
|
+
end
|
99
101
|
|
100
102
|
if @accumulated_width + segment_width <= @width
|
101
103
|
@accumulated_width += segment_width
|
@@ -242,6 +244,7 @@ module Prawn
|
|
242
244
|
!fragment.strip.empty?
|
243
245
|
raise Prawn::Errors::CannotFit
|
244
246
|
end
|
247
|
+
|
245
248
|
@arranger.update_last_string(
|
246
249
|
@fragment_output,
|
247
250
|
remaining_text,
|
@@ -284,8 +287,7 @@ module Prawn
|
|
284
287
|
end
|
285
288
|
|
286
289
|
def update_line_status_based_on_last_output
|
287
|
-
if @fragment_output
|
288
|
-
word_division_scan_pattern(@fragment_output.encoding)
|
290
|
+
if @fragment_output&.match?(word_division_scan_pattern(@fragment_output.encoding))
|
289
291
|
@line_contains_more_than_one_word = true
|
290
292
|
end
|
291
293
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# text/formatted/parser.rb : Implements a bi-directional parser between a subset
|
2
4
|
# of html and formatted text arrays
|
3
5
|
#
|
@@ -55,21 +57,17 @@ module Prawn
|
|
55
57
|
array.collect do |hash|
|
56
58
|
prefix = ''
|
57
59
|
suffix = ''
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
suffix = suffixes[style] + suffix
|
62
|
-
end
|
60
|
+
hash[:styles]&.each do |style|
|
61
|
+
prefix += prefixes[style]
|
62
|
+
suffix = suffixes[style] + suffix
|
63
63
|
end
|
64
64
|
|
65
65
|
font = hash[:font] ? " name='#{hash[:font]}'" : nil
|
66
66
|
size = hash[:size] ? " size='#{hash[:size]}'" : nil
|
67
|
-
|
68
|
-
character_spacing
|
67
|
+
character_spacing =
|
68
|
+
if hash[:character_spacing]
|
69
69
|
" character_spacing='#{hash[:character_spacing]}'"
|
70
|
-
|
71
|
-
character_spacing = nil
|
72
|
-
end
|
70
|
+
end
|
73
71
|
if font || size || character_spacing
|
74
72
|
prefix += "<font#{font}#{size}#{character_spacing}>"
|
75
73
|
suffix = '</font>'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# wrap.rb: Handles text wrapping for for formatted text
|
2
4
|
#
|
3
5
|
# Contributed by Daniel Nelson
|
@@ -103,12 +105,12 @@ module Prawn
|
|
103
105
|
end
|
104
106
|
|
105
107
|
@printed_lines << printed_fragments.map do |s|
|
106
|
-
s.force_encoding(::Encoding::UTF_8)
|
108
|
+
s.dup.force_encoding(::Encoding::UTF_8)
|
107
109
|
end.join
|
108
110
|
end
|
109
111
|
|
110
112
|
def word_spacing_for_this_line
|
111
|
-
if @align == :justify && @line_wrap.space_count
|
113
|
+
if @align == :justify && @line_wrap.space_count.positive? &&
|
112
114
|
!@line_wrap.paragraph_finished?
|
113
115
|
(available_width - @line_wrap.width) / @line_wrap.space_count
|
114
116
|
else
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# transformation_stack.rb : Stores the transformations that have been applied to
|
2
4
|
# the document
|
3
5
|
#
|
@@ -7,7 +9,7 @@
|
|
7
9
|
|
8
10
|
require 'matrix'
|
9
11
|
|
10
|
-
# rubocop: disable Metrics/ParameterLists
|
12
|
+
# rubocop: disable Metrics/ParameterLists, Naming/MethodParameterName
|
11
13
|
module Prawn
|
12
14
|
module TransformationStack
|
13
15
|
def add_to_transformation_stack(a, b, c, d, e, f)
|
@@ -21,7 +23,7 @@ module Prawn
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def restore_transformation_stack
|
24
|
-
@transformation_stack
|
26
|
+
@transformation_stack&.pop
|
25
27
|
end
|
26
28
|
|
27
29
|
def current_transformation_matrix_with_translation(x = 0, y = 0)
|
@@ -39,3 +41,4 @@ module Prawn
|
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
44
|
+
# rubocop: enable Metrics/ParameterLists, Naming/MethodParameterName
|