prawn 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +7 -5
- data/lib/prawn.rb +4 -4
- data/lib/prawn/document.rb +47 -46
- data/lib/prawn/document/bounding_box.rb +13 -19
- data/lib/prawn/document/column_box.rb +3 -5
- data/lib/prawn/document/internals.rb +0 -1
- data/lib/prawn/document/span.rb +12 -12
- data/lib/prawn/errors.rb +32 -33
- data/lib/prawn/font.rb +29 -36
- data/lib/prawn/font/afm.rb +20 -20
- data/lib/prawn/font/dfont.rb +0 -1
- data/lib/prawn/font/ttf.rb +30 -27
- data/lib/prawn/font_metric_cache.rb +4 -8
- data/lib/prawn/graphics.rb +37 -42
- data/lib/prawn/graphics/cap_style.rb +1 -1
- data/lib/prawn/graphics/color.rb +21 -23
- data/lib/prawn/graphics/dash.rb +5 -6
- data/lib/prawn/graphics/join_style.rb +1 -2
- data/lib/prawn/graphics/patterns.rb +25 -21
- data/lib/prawn/graphics/transformation.rb +4 -5
- data/lib/prawn/graphics/transparency.rb +6 -8
- data/lib/prawn/grid.rb +21 -14
- data/lib/prawn/image_handler.rb +2 -2
- data/lib/prawn/images.rb +29 -31
- data/lib/prawn/images/image.rb +1 -1
- data/lib/prawn/images/jpg.rb +10 -12
- data/lib/prawn/images/png.rb +13 -13
- data/lib/prawn/measurements.rb +7 -14
- data/lib/prawn/outline.rb +6 -6
- data/lib/prawn/repeater.rb +1 -5
- data/lib/prawn/security.rb +17 -25
- data/lib/prawn/security/arcfour.rb +1 -1
- data/lib/prawn/soft_mask.rb +11 -12
- data/lib/prawn/stamp.rb +16 -8
- data/lib/prawn/text.rb +23 -20
- data/lib/prawn/text/box.rb +3 -6
- data/lib/prawn/text/formatted/arranger.rb +9 -12
- data/lib/prawn/text/formatted/box.rb +23 -22
- data/lib/prawn/text/formatted/fragment.rb +0 -4
- data/lib/prawn/text/formatted/line_wrap.rb +13 -24
- data/lib/prawn/text/formatted/parser.rb +16 -20
- data/lib/prawn/text/formatted/wrap.rb +2 -7
- data/lib/prawn/utilities.rb +6 -3
- data/lib/prawn/version.rb +1 -1
- data/manual/basic_concepts/basic_concepts.rb +0 -2
- data/manual/basic_concepts/view.rb +1 -1
- data/manual/bounding_box/bounding_box.rb +0 -3
- data/manual/bounding_box/russian_boxes.rb +7 -8
- data/manual/bounding_box/stretchy.rb +0 -1
- data/manual/contents.rb +2 -2
- data/manual/cover.rb +11 -12
- data/manual/document_and_page_options/document_and_page_options.rb +2 -5
- data/manual/document_and_page_options/metadata.rb +10 -10
- data/manual/document_and_page_options/page_size.rb +0 -1
- data/manual/graphics/fill_rules.rb +5 -4
- data/manual/graphics/graphics.rb +0 -3
- data/manual/graphics/lines_and_curves.rb +1 -1
- data/manual/graphics/rotate.rb +0 -2
- data/manual/graphics/scale.rb +4 -2
- data/manual/graphics/soft_masks.rb +0 -1
- data/manual/graphics/stroke_cap.rb +1 -1
- data/manual/graphics/stroke_join.rb +1 -1
- data/manual/graphics/translate.rb +3 -3
- data/manual/graphics/transparency.rb +0 -1
- data/manual/how_to_read_this_manual.rb +0 -1
- data/manual/images/images.rb +0 -3
- data/manual/layout/boxes.rb +5 -5
- data/manual/layout/content.rb +2 -2
- data/manual/layout/layout.rb +0 -3
- data/manual/outline/outline.rb +0 -3
- data/manual/repeatable_content/page_numbering.rb +1 -1
- data/manual/repeatable_content/repeatable_content.rb +0 -3
- data/manual/repeatable_content/repeater.rb +6 -6
- data/manual/security/encryption.rb +0 -2
- data/manual/security/permissions.rb +0 -2
- data/manual/security/security.rb +0 -3
- data/manual/text/alignment.rb +3 -3
- data/manual/text/color.rb +0 -1
- data/manual/text/column_box.rb +0 -1
- data/manual/text/fallback_fonts.rb +2 -2
- data/manual/text/formatted_callbacks.rb +3 -2
- data/manual/text/paragraph_indentation.rb +2 -3
- data/manual/text/registering_families.rb +13 -9
- data/manual/text/rotation.rb +0 -1
- data/manual/text/text.rb +0 -3
- data/manual/text/text_box_overflow.rb +7 -5
- data/manual/text/utf8.rb +1 -1
- data/manual/text/win_ansi_charset.rb +2 -2
- data/prawn.gemspec +4 -4
- data/spec/acceptance/png.rb +6 -7
- data/spec/annotations_spec.rb +21 -28
- data/spec/bounding_box_spec.rb +100 -109
- data/spec/column_box_spec.rb +26 -32
- data/spec/destinations_spec.rb +2 -4
- data/spec/document_spec.rb +145 -151
- data/spec/extensions/mocha.rb +0 -1
- data/spec/font_metric_cache_spec.rb +7 -7
- data/spec/font_spec.rb +103 -102
- data/spec/formatted_text_arranger_spec.rb +76 -74
- data/spec/formatted_text_box_spec.rb +170 -159
- data/spec/formatted_text_fragment_spec.rb +57 -56
- data/spec/graphics_spec.rb +158 -175
- data/spec/grid_spec.rb +28 -29
- data/spec/image_handler_spec.rb +4 -5
- data/spec/images_spec.rb +50 -36
- data/spec/inline_formatted_text_parser_spec.rb +397 -393
- data/spec/jpg_spec.rb +4 -6
- data/spec/line_wrap_spec.rb +54 -55
- data/spec/measurement_units_spec.rb +12 -15
- data/spec/outline_spec.rb +77 -98
- data/spec/png_spec.rb +55 -65
- data/spec/reference_spec.rb +3 -3
- data/spec/repeater_spec.rb +20 -26
- data/spec/security_spec.rb +42 -49
- data/spec/soft_mask_spec.rb +4 -5
- data/spec/span_spec.rb +5 -6
- data/spec/spec_helper.rb +2 -4
- data/spec/stamp_spec.rb +41 -22
- data/spec/stroke_styles_spec.rb +36 -39
- data/spec/text_at_spec.rb +28 -29
- data/spec/text_box_spec.rb +160 -165
- data/spec/text_rendering_mode_spec.rb +9 -9
- data/spec/text_spacing_spec.rb +13 -13
- data/spec/text_spec.rb +116 -124
- data/spec/text_with_inline_formatting_spec.rb +5 -5
- data/spec/transparency_spec.rb +20 -20
- data/spec/view_spec.rb +0 -1
- metadata +7 -7
@@ -10,7 +10,6 @@
|
|
10
10
|
module Prawn
|
11
11
|
module Text
|
12
12
|
module Formatted #:nodoc:
|
13
|
-
|
14
13
|
# @private
|
15
14
|
|
16
15
|
class Arranger #:nodoc:
|
@@ -24,7 +23,7 @@ module Prawn
|
|
24
23
|
attr_reader :fragments
|
25
24
|
attr_reader :current_format_state
|
26
25
|
|
27
|
-
def initialize(document, options={})
|
26
|
+
def initialize(document, options = {})
|
28
27
|
@document = document
|
29
28
|
@fragments = []
|
30
29
|
@unconsumed = []
|
@@ -33,7 +32,7 @@ module Prawn
|
|
33
32
|
|
34
33
|
def space_count
|
35
34
|
if @unfinalized_line
|
36
|
-
|
35
|
+
fail "Lines must be finalized before calling #space_count"
|
37
36
|
end
|
38
37
|
@fragments.inject(0) do |sum, fragment|
|
39
38
|
sum + fragment.space_count
|
@@ -42,7 +41,7 @@ module Prawn
|
|
42
41
|
|
43
42
|
def line_width
|
44
43
|
if @unfinalized_line
|
45
|
-
|
44
|
+
fail "Lines must be finalized before calling #line_width"
|
46
45
|
end
|
47
46
|
@fragments.inject(0) do |sum, fragment|
|
48
47
|
sum + fragment.width
|
@@ -51,7 +50,7 @@ module Prawn
|
|
51
50
|
|
52
51
|
def line
|
53
52
|
if @unfinalized_line
|
54
|
-
|
53
|
+
fail "Lines must be finalized before calling #line"
|
55
54
|
end
|
56
55
|
@fragments.collect do |fragment|
|
57
56
|
fragment.text.dup.force_encoding(::Encoding::UTF_8)
|
@@ -101,7 +100,7 @@ module Prawn
|
|
101
100
|
|
102
101
|
def next_string
|
103
102
|
unless @unfinalized_line
|
104
|
-
|
103
|
+
fail "Lines must not be finalized when calling #next_string"
|
105
104
|
end
|
106
105
|
hash = @unconsumed.shift
|
107
106
|
if hash.nil?
|
@@ -135,7 +134,7 @@ module Prawn
|
|
135
134
|
end
|
136
135
|
end
|
137
136
|
|
138
|
-
def apply_font_settings(fragment=nil, &block)
|
137
|
+
def apply_font_settings(fragment = nil, &block)
|
139
138
|
if fragment.nil?
|
140
139
|
font = current_format_state[:font]
|
141
140
|
size = current_format_state[:size]
|
@@ -153,7 +152,7 @@ module Prawn
|
|
153
152
|
|
154
153
|
@document.character_spacing(character_spacing) do
|
155
154
|
if font || font_style != :normal
|
156
|
-
|
155
|
+
fail "Bad font family" unless @document.font.family
|
157
156
|
@document.font(font || @document.font.family, :style => font_style) do
|
158
157
|
apply_font_size(size, styles, &block)
|
159
158
|
end
|
@@ -163,7 +162,7 @@ module Prawn
|
|
163
162
|
end
|
164
163
|
end
|
165
164
|
|
166
|
-
def update_last_string(printed, unprinted, normalized_soft_hyphen=nil)
|
165
|
+
def update_last_string(printed, unprinted, normalized_soft_hyphen = nil)
|
167
166
|
return if printed.nil?
|
168
167
|
if printed.empty?
|
169
168
|
@consumed.pop
|
@@ -183,7 +182,7 @@ module Prawn
|
|
183
182
|
|
184
183
|
def retrieve_fragment
|
185
184
|
if @unfinalized_line
|
186
|
-
|
185
|
+
fail "Lines must be finalized before fragments can be retrieved"
|
187
186
|
end
|
188
187
|
@fragments.shift
|
189
188
|
end
|
@@ -282,9 +281,7 @@ module Prawn
|
|
282
281
|
@max_descender = [defined?(@max_descender) && @max_descender, fragment.descender].compact.max
|
283
282
|
@max_ascender = [defined?(@max_ascender) && @max_ascender, fragment.ascender].compact.max
|
284
283
|
end
|
285
|
-
|
286
284
|
end
|
287
|
-
|
288
285
|
end
|
289
286
|
end
|
290
287
|
end
|
@@ -88,7 +88,7 @@ module Prawn
|
|
88
88
|
# Raises <tt>Prawn::Errors::CannotFit</tt> if not wide enough to print
|
89
89
|
# any text
|
90
90
|
#
|
91
|
-
def formatted_text_box(array, options={})
|
91
|
+
def formatted_text_box(array, options = {})
|
92
92
|
Text::Formatted::Box.new(array, options.merge(:document => self)).render
|
93
93
|
end
|
94
94
|
|
@@ -136,7 +136,7 @@ module Prawn
|
|
136
136
|
|
137
137
|
# See Prawn::Text#text_box for valid options
|
138
138
|
#
|
139
|
-
def initialize(formatted_text, options={})
|
139
|
+
def initialize(formatted_text, options = {})
|
140
140
|
@inked = false
|
141
141
|
Prawn.verify_options(valid_options, options)
|
142
142
|
options = options.dup
|
@@ -187,8 +187,8 @@ module Prawn
|
|
187
187
|
options[:kerning] = @document.default_kerning?
|
188
188
|
end
|
189
189
|
@options = { :kerning => options[:kerning],
|
190
|
-
|
191
|
-
|
190
|
+
:size => options[:size],
|
191
|
+
:style => options[:style] }
|
192
192
|
|
193
193
|
super(formatted_text, options)
|
194
194
|
end
|
@@ -203,7 +203,7 @@ module Prawn
|
|
203
203
|
#
|
204
204
|
# Returns any text that did not print under the current settings
|
205
205
|
#
|
206
|
-
def render(flags={})
|
206
|
+
def render(flags = {})
|
207
207
|
unprinted_text = []
|
208
208
|
|
209
209
|
@document.save_font do
|
@@ -248,7 +248,7 @@ module Prawn
|
|
248
248
|
|
249
249
|
# <tt>fragment</tt> is a Prawn::Text::Formatted::Fragment object
|
250
250
|
#
|
251
|
-
def draw_fragment(fragment, accumulated_width=0, line_width=0, word_spacing=0) #:nodoc:
|
251
|
+
def draw_fragment(fragment, accumulated_width = 0, line_width = 0, word_spacing = 0) #:nodoc:
|
252
252
|
case(@align)
|
253
253
|
when :left
|
254
254
|
x = @at[0]
|
@@ -279,10 +279,10 @@ module Prawn
|
|
279
279
|
@document.word_spacing(word_spacing) {
|
280
280
|
if @draw_text_callback
|
281
281
|
@draw_text_callback.call(fragment.text, :at => [x, y],
|
282
|
-
|
282
|
+
:kerning => @kerning)
|
283
283
|
else
|
284
284
|
@document.draw_text!(fragment.text, :at => [x, y],
|
285
|
-
|
285
|
+
:kerning => @kerning)
|
286
286
|
end
|
287
287
|
}
|
288
288
|
|
@@ -329,17 +329,20 @@ module Prawn
|
|
329
329
|
end
|
330
330
|
|
331
331
|
def valid_options
|
332
|
-
PDF::Core::Text::VALID_OPTIONS + [
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
332
|
+
PDF::Core::Text::VALID_OPTIONS + [
|
333
|
+
:at,
|
334
|
+
:height, :width,
|
335
|
+
:align, :valign,
|
336
|
+
:rotate, :rotate_around,
|
337
|
+
:overflow, :min_font_size,
|
338
|
+
:disable_wrap_by_char,
|
339
|
+
:leading, :character_spacing,
|
340
|
+
:mode, :single_line,
|
341
|
+
:document,
|
342
|
+
:direction,
|
343
|
+
:fallback_fonts,
|
344
|
+
:draw_text_callback
|
345
|
+
]
|
343
346
|
end
|
344
347
|
|
345
348
|
private
|
@@ -353,7 +356,7 @@ module Prawn
|
|
353
356
|
end
|
354
357
|
|
355
358
|
def original_text
|
356
|
-
@original_array.collect
|
359
|
+
@original_array.collect(&:dup)
|
357
360
|
end
|
358
361
|
|
359
362
|
def original_text=(formatted_text)
|
@@ -606,9 +609,7 @@ module Prawn
|
|
606
609
|
@document.stroke_line(fragment.strikethrough_points)
|
607
610
|
end
|
608
611
|
end
|
609
|
-
|
610
612
|
end
|
611
|
-
|
612
613
|
end
|
613
614
|
end
|
614
615
|
end
|
@@ -9,14 +9,11 @@
|
|
9
9
|
module Prawn
|
10
10
|
module Text
|
11
11
|
module Formatted
|
12
|
-
|
13
|
-
|
14
12
|
# Prawn::Text::Formatted::Fragment is a state store for a formatted text
|
15
13
|
# fragment. It does not render anything.
|
16
14
|
#
|
17
15
|
# @private
|
18
16
|
class Fragment
|
19
|
-
|
20
17
|
attr_reader :format_state, :text
|
21
18
|
attr_writer :width
|
22
19
|
attr_accessor :line_height, :descender, :ascender
|
@@ -257,7 +254,6 @@ module Prawn
|
|
257
254
|
string
|
258
255
|
end
|
259
256
|
end
|
260
|
-
|
261
257
|
end
|
262
258
|
end
|
263
259
|
end
|
@@ -11,10 +11,8 @@
|
|
11
11
|
module Prawn
|
12
12
|
module Text
|
13
13
|
module Formatted #:nodoc:
|
14
|
-
|
15
14
|
# @private
|
16
15
|
class LineWrap #:nodoc:
|
17
|
-
|
18
16
|
# The width of the last wrapped line
|
19
17
|
#
|
20
18
|
def width
|
@@ -122,11 +120,11 @@ module Prawn
|
|
122
120
|
# The pattern used to determine chunks of text to place on a given line
|
123
121
|
#
|
124
122
|
def scan_pattern
|
125
|
-
pattern = "[^#{break_chars}]+#{soft_hyphen}|"
|
126
|
-
"[^#{break_chars}]+#{hyphen}+|"
|
127
|
-
"[^#{break_chars}]+|"
|
128
|
-
"[#{whitespace}]+|"
|
129
|
-
"#{hyphen}+[^#{break_chars}]*|"
|
123
|
+
pattern = "[^#{break_chars}]+#{soft_hyphen}|" \
|
124
|
+
"[^#{break_chars}]+#{hyphen}+|" \
|
125
|
+
"[^#{break_chars}]+|" \
|
126
|
+
"[#{whitespace}]+|" \
|
127
|
+
"#{hyphen}+[^#{break_chars}]*|" \
|
130
128
|
"#{soft_hyphen}"
|
131
129
|
|
132
130
|
Regexp.new(pattern)
|
@@ -152,13 +150,8 @@ module Prawn
|
|
152
150
|
"-"
|
153
151
|
end
|
154
152
|
|
155
|
-
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
|
-
def zero_width_space
|
160
|
-
@zero_width_space
|
161
|
-
end
|
153
|
+
attr_reader :soft_hyphen
|
154
|
+
attr_reader :zero_width_space
|
162
155
|
|
163
156
|
def line_empty?
|
164
157
|
@line_empty && @accumulated_width == 0
|
@@ -202,19 +195,15 @@ module Prawn
|
|
202
195
|
remember_this_fragment_for_backward_looking_ops
|
203
196
|
end
|
204
197
|
|
205
|
-
def update_output_based_on_last_fragment(fragment, normalized_soft_hyphen=nil)
|
198
|
+
def update_output_based_on_last_fragment(fragment, normalized_soft_hyphen = nil)
|
206
199
|
remaining_text = fragment.slice(@fragment_output.length..fragment.length)
|
207
|
-
|
208
|
-
@fragment_output.empty? && !fragment.strip.empty?
|
200
|
+
fail Prawn::Errors::CannotFit if line_finished? && line_empty? && @fragment_output.empty? && !fragment.strip.empty?
|
209
201
|
@arranger.update_last_string(@fragment_output, remaining_text, normalized_soft_hyphen)
|
210
202
|
end
|
211
203
|
|
212
204
|
def determine_whether_to_pull_preceding_fragment_to_join_this_one(current_fragment)
|
213
|
-
if @fragment_output.empty? &&
|
214
|
-
|
215
|
-
@line_contains_more_than_one_word
|
216
|
-
unless previous_fragment_ended_with_breakable? ||
|
217
|
-
fragment_begins_with_breakable?(current_fragment)
|
205
|
+
if @fragment_output.empty? && !current_fragment.empty? && @line_contains_more_than_one_word
|
206
|
+
unless previous_fragment_ended_with_breakable? || fragment_begins_with_breakable?(current_fragment)
|
218
207
|
@fragment_output = @previous_fragment_output_without_last_word
|
219
208
|
update_output_based_on_last_fragment(@previous_fragment)
|
220
209
|
end
|
@@ -255,11 +244,11 @@ module Prawn
|
|
255
244
|
def wrap_by_char(segment)
|
256
245
|
font = @document.font
|
257
246
|
segment.each_char do |char|
|
258
|
-
break unless append_char(char,font)
|
247
|
+
break unless append_char(char, font)
|
259
248
|
end
|
260
249
|
end
|
261
250
|
|
262
|
-
def append_char(char,font)
|
251
|
+
def append_char(char, font)
|
263
252
|
# kerning doesn't make sense in the context of a single character
|
264
253
|
char_width = font.compute_width_of(char)
|
265
254
|
|
@@ -11,24 +11,23 @@
|
|
11
11
|
module Prawn
|
12
12
|
module Text
|
13
13
|
module Formatted
|
14
|
-
|
15
14
|
class Parser
|
16
15
|
# @group Extension API
|
17
16
|
|
18
17
|
PARSER_REGEX = begin
|
19
|
-
regex_string = "\n|"
|
20
|
-
"<b>|</b>|"
|
21
|
-
"<i>|</i>|"
|
22
|
-
"<u>|</u>|"
|
23
|
-
"<strikethrough>|</strikethrough>|"
|
24
|
-
"<sub>|</sub>|"
|
25
|
-
"<sup>|</sup>|"
|
26
|
-
"<link[^>]*>|</link>|"
|
27
|
-
"<color[^>]*>|</color>|"
|
28
|
-
"<font[^>]*>|</font>|"
|
29
|
-
"<strong>|</strong>|"
|
30
|
-
"<em>|</em>|"
|
31
|
-
"<a[^>]*>|</a>|"
|
18
|
+
regex_string = "\n|" \
|
19
|
+
"<b>|</b>|" \
|
20
|
+
"<i>|</i>|" \
|
21
|
+
"<u>|</u>|" \
|
22
|
+
"<strikethrough>|</strikethrough>|" \
|
23
|
+
"<sub>|</sub>|" \
|
24
|
+
"<sup>|</sup>|" \
|
25
|
+
"<link[^>]*>|</link>|" \
|
26
|
+
"<color[^>]*>|</color>|" \
|
27
|
+
"<font[^>]*>|</font>|" \
|
28
|
+
"<strong>|</strong>|" \
|
29
|
+
"<em>|</em>|" \
|
30
|
+
"<a[^>]*>|</a>|" \
|
32
31
|
"[^<\n]+"
|
33
32
|
Regexp.new(regex_string, Regexp::MULTILINE)
|
34
33
|
end
|
@@ -82,9 +81,9 @@ module Prawn
|
|
82
81
|
|
83
82
|
if hash[:color]
|
84
83
|
if hash[:color].kind_of?(Array)
|
85
|
-
prefix = prefix + "<color c='#{hash[:color][0]}'"
|
86
|
-
" m='#{hash[:color][1]}'"
|
87
|
-
" y='#{hash[:color][2]}'"
|
84
|
+
prefix = prefix + "<color c='#{hash[:color][0]}'" \
|
85
|
+
" m='#{hash[:color][1]}'" \
|
86
|
+
" y='#{hash[:color][2]}'" \
|
88
87
|
" k='#{hash[:color][3]}'>"
|
89
88
|
else
|
90
89
|
prefix = prefix + "<color rgb='#{hash[:color]}'>"
|
@@ -118,8 +117,6 @@ module Prawn
|
|
118
117
|
paragraphs
|
119
118
|
end
|
120
119
|
|
121
|
-
private
|
122
|
-
|
123
120
|
def self.array_from_tokens(tokens)
|
124
121
|
array = []
|
125
122
|
styles = []
|
@@ -217,7 +214,6 @@ module Prawn
|
|
217
214
|
end
|
218
215
|
array
|
219
216
|
end
|
220
|
-
|
221
217
|
end
|
222
218
|
end
|
223
219
|
end
|
@@ -15,15 +15,13 @@ module Prawn
|
|
15
15
|
# @private
|
16
16
|
|
17
17
|
module Wrap #:nodoc:
|
18
|
-
|
19
18
|
def initialize(array, options)
|
20
19
|
@line_wrap = Prawn::Text::Formatted::LineWrap.new
|
21
20
|
@arranger = Prawn::Text::Formatted::Arranger.new(@document,
|
22
|
-
|
21
|
+
:kerning => options[:kerning])
|
23
22
|
@disable_wrap_by_char = options[:disable_wrap_by_char]
|
24
23
|
end
|
25
24
|
|
26
|
-
|
27
25
|
# See the developer documentation for PDF::Core::Text#wrap
|
28
26
|
#
|
29
27
|
# Formatted#wrap should set the following variables:
|
@@ -103,9 +101,7 @@ module Prawn
|
|
103
101
|
end
|
104
102
|
|
105
103
|
def word_spacing_for_this_line
|
106
|
-
if @align == :justify &&
|
107
|
-
@line_wrap.space_count > 0 &&
|
108
|
-
!@line_wrap.paragraph_finished?
|
104
|
+
if @align == :justify && @line_wrap.space_count > 0 && !@line_wrap.paragraph_finished?
|
109
105
|
(available_width - @line_wrap.width) / @line_wrap.space_count
|
110
106
|
else
|
111
107
|
0
|
@@ -153,7 +149,6 @@ module Prawn
|
|
153
149
|
line_width, word_spacing)
|
154
150
|
end
|
155
151
|
end
|
156
|
-
|
157
152
|
end
|
158
153
|
end
|
159
154
|
end
|
data/lib/prawn/utilities.rb
CHANGED
@@ -9,7 +9,6 @@
|
|
9
9
|
require 'thread'
|
10
10
|
|
11
11
|
module Prawn
|
12
|
-
|
13
12
|
# Throughout the Prawn codebase, repeated calculations which can benefit from caching are made
|
14
13
|
# In some cases, caching and reusing results can not only save CPU cycles but also greatly
|
15
14
|
# reduce memory requirements
|
@@ -23,10 +22,12 @@ module Prawn
|
|
23
22
|
@cache = {}
|
24
23
|
@mutex = Mutex.new
|
25
24
|
end
|
25
|
+
|
26
26
|
def [](key)
|
27
27
|
@mutex.synchronize { @cache[key] }
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
|
+
def []=(key, value)
|
30
31
|
@mutex.synchronize { @cache[key] = value }
|
31
32
|
end
|
32
33
|
end
|
@@ -36,10 +37,12 @@ module Prawn
|
|
36
37
|
def initialize
|
37
38
|
@cache_id = "cache_#{self.object_id}".to_sym
|
38
39
|
end
|
40
|
+
|
39
41
|
def [](key)
|
40
42
|
(Thread.current[@cache_id] ||= {})[key]
|
41
43
|
end
|
42
|
-
|
44
|
+
|
45
|
+
def []=(key, value)
|
43
46
|
(Thread.current[@cache_id] ||= {})[key] = value
|
44
47
|
end
|
45
48
|
end
|
data/lib/prawn/version.rb
CHANGED