prawn 1.0.0.rc2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +9 -0
- data/COPYING +2 -2
- data/Gemfile +8 -15
- data/LICENSE +1 -1
- data/Rakefile +25 -16
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/license.md +8 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/lib/prawn.rb +85 -23
- data/lib/prawn/document.rb +134 -116
- data/lib/prawn/document/bounding_box.rb +33 -4
- data/lib/prawn/document/column_box.rb +18 -6
- data/lib/prawn/document/graphics_state.rb +11 -74
- data/lib/prawn/document/internals.rb +24 -23
- data/lib/prawn/document/span.rb +12 -10
- data/lib/prawn/encoding.rb +8 -9
- data/lib/prawn/errors.rb +13 -32
- data/lib/prawn/font.rb +137 -105
- data/lib/prawn/font/afm.rb +76 -32
- data/lib/prawn/font/dfont.rb +4 -3
- data/lib/prawn/font/ttf.rb +33 -25
- data/lib/prawn/font_metric_cache.rb +47 -0
- data/lib/prawn/graphics.rb +177 -57
- data/lib/prawn/graphics/cap_style.rb +4 -3
- data/lib/prawn/graphics/color.rb +5 -4
- data/lib/prawn/graphics/dash.rb +53 -31
- data/lib/prawn/graphics/join_style.rb +9 -7
- data/lib/prawn/graphics/patterns.rb +4 -15
- data/lib/prawn/graphics/transformation.rb +10 -9
- data/lib/prawn/graphics/transparency.rb +3 -1
- data/lib/prawn/{layout/grid.rb → grid.rb} +72 -54
- data/lib/prawn/image_handler.rb +42 -0
- data/lib/prawn/images.rb +58 -54
- data/lib/prawn/images/image.rb +6 -22
- data/lib/prawn/images/jpg.rb +20 -14
- data/lib/prawn/images/png.rb +58 -121
- data/lib/prawn/layout.rb +12 -15
- data/lib/prawn/measurement_extensions.rb +10 -6
- data/lib/prawn/measurements.rb +27 -21
- data/lib/prawn/outline.rb +108 -147
- data/lib/prawn/repeater.rb +10 -8
- data/lib/prawn/security.rb +59 -40
- data/lib/prawn/security/arcfour.rb +52 -0
- data/lib/prawn/soft_mask.rb +4 -4
- data/lib/prawn/stamp.rb +5 -3
- data/lib/prawn/table.rb +83 -60
- data/lib/prawn/table/cell.rb +17 -21
- data/lib/prawn/table/cell/image.rb +2 -3
- data/lib/prawn/table/cell/in_table.rb +8 -2
- data/lib/prawn/table/cell/span_dummy.rb +5 -0
- data/lib/prawn/table/cell/subtable.rb +3 -2
- data/lib/prawn/table/cell/text.rb +14 -12
- data/lib/prawn/table/cells.rb +58 -14
- data/lib/prawn/table/column_width_calculator.rb +61 -0
- data/lib/prawn/text.rb +27 -26
- data/lib/prawn/text/box.rb +12 -6
- data/lib/prawn/text/formatted.rb +5 -4
- data/lib/prawn/text/formatted/arranger.rb +290 -0
- data/lib/prawn/text/formatted/box.rb +85 -57
- data/lib/prawn/text/formatted/fragment.rb +11 -11
- data/lib/prawn/text/formatted/line_wrap.rb +266 -0
- data/lib/prawn/text/formatted/parser.rb +11 -4
- data/lib/prawn/text/formatted/wrap.rb +156 -0
- data/lib/prawn/utilities.rb +5 -3
- data/manual/document_and_page_options/document_and_page_options.rb +2 -1
- data/manual/document_and_page_options/metadata.rb +3 -3
- data/manual/document_and_page_options/page_size.rb +2 -2
- data/manual/document_and_page_options/print_scaling.rb +20 -0
- data/manual/example_file.rb +2 -7
- data/manual/example_helper.rb +62 -81
- data/manual/graphics/common_lines.rb +2 -0
- data/manual/graphics/helper.rb +11 -4
- data/manual/graphics/stroke_dash.rb +19 -14
- data/manual/manual/cover.rb +16 -0
- data/manual/manual/manual.rb +1 -5
- data/manual/text/fallback_fonts.rb +4 -4
- data/manual/text/formatted_text.rb +5 -5
- data/manual/text/inline.rb +2 -4
- data/manual/text/registering_families.rb +12 -12
- data/manual/text/single_usage.rb +4 -4
- data/manual/text/text.rb +0 -2
- data/prawn.gemspec +21 -13
- data/spec/acceptance/png.rb +23 -0
- data/spec/annotations_spec.rb +16 -32
- data/spec/bounding_box_spec.rb +22 -5
- data/spec/cell_spec.rb +49 -5
- data/spec/column_box_spec.rb +32 -0
- data/spec/destinations_spec.rb +5 -5
- data/spec/document_spec.rb +112 -118
- data/spec/extensions/encoding_helpers.rb +5 -2
- data/spec/font_metric_cache_spec.rb +52 -0
- data/spec/font_spec.rb +121 -120
- data/spec/formatted_text_arranger_spec.rb +24 -24
- data/spec/formatted_text_box_spec.rb +31 -32
- data/spec/formatted_text_fragment_spec.rb +2 -2
- data/spec/graphics_spec.rb +63 -45
- data/spec/grid_spec.rb +24 -13
- data/spec/image_handler_spec.rb +54 -0
- data/spec/images_spec.rb +34 -21
- data/spec/inline_formatted_text_parser_spec.rb +69 -20
- data/spec/jpg_spec.rb +3 -3
- data/spec/line_wrap_spec.rb +25 -14
- data/spec/measurement_units_spec.rb +5 -5
- data/spec/outline_spec.rb +68 -64
- data/spec/png_spec.rb +15 -18
- data/spec/reference_spec.rb +2 -82
- data/spec/repeater_spec.rb +1 -1
- data/spec/security_spec.rb +41 -9
- data/spec/soft_mask_spec.rb +0 -40
- data/spec/span_spec.rb +6 -11
- data/spec/spec_helper.rb +20 -2
- data/spec/stamp_spec.rb +19 -20
- data/spec/stroke_styles_spec.rb +31 -13
- data/spec/table/span_dummy_spec.rb +17 -0
- data/spec/table_spec.rb +268 -43
- data/spec/text_at_spec.rb +13 -27
- data/spec/text_box_spec.rb +35 -30
- data/spec/text_spec.rb +56 -40
- data/spec/transparency_spec.rb +5 -5
- metadata +214 -217
- data/README.md +0 -98
- data/data/fonts/Action Man.dfont +0 -0
- data/data/fonts/Activa.ttf +0 -0
- data/data/fonts/Chalkboard.ttf +0 -0
- data/data/fonts/DejaVuSans.ttf +0 -0
- data/data/fonts/Dustismo_Roman.ttf +0 -0
- data/data/fonts/comicsans.ttf +0 -0
- data/data/fonts/gkai00mp.ttf +0 -0
- data/data/images/16bit.dat +0 -0
- data/data/images/barcode_issue.png +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/page_white_text.dat +0 -0
- data/data/images/rails.dat +0 -0
- data/data/images/rails.png +0 -0
- data/lib/prawn/compatibility.rb +0 -87
- data/lib/prawn/core.rb +0 -87
- data/lib/prawn/core/annotations.rb +0 -61
- data/lib/prawn/core/byte_string.rb +0 -9
- data/lib/prawn/core/destinations.rb +0 -90
- data/lib/prawn/core/document_state.rb +0 -79
- data/lib/prawn/core/literal_string.rb +0 -16
- data/lib/prawn/core/name_tree.rb +0 -177
- data/lib/prawn/core/object_store.rb +0 -320
- data/lib/prawn/core/page.rb +0 -212
- data/lib/prawn/core/pdf_object.rb +0 -125
- data/lib/prawn/core/reference.rb +0 -119
- data/lib/prawn/core/text.rb +0 -268
- data/lib/prawn/core/text/formatted/arranger.rb +0 -294
- data/lib/prawn/core/text/formatted/line_wrap.rb +0 -288
- data/lib/prawn/core/text/formatted/wrap.rb +0 -153
- data/lib/prawn/document/page_geometry.rb +0 -136
- data/lib/prawn/document/snapshot.rb +0 -89
- data/manual/manual/foreword.rb +0 -13
- data/manual/templates/full_template.rb +0 -23
- data/manual/templates/page_template.rb +0 -47
- data/manual/templates/templates.rb +0 -26
- data/manual/text/group.rb +0 -29
- data/spec/name_tree_spec.rb +0 -112
- data/spec/object_store_spec.rb +0 -170
- data/spec/pdf_object_spec.rb +0 -172
- data/spec/snapshot_spec.rb +0 -186
- data/spec/template_spec.rb +0 -351
@@ -1,288 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
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
|
-
module Prawn
|
12
|
-
module Core
|
13
|
-
module Text
|
14
|
-
module Formatted #:nodoc:
|
15
|
-
|
16
|
-
class LineWrap #:nodoc:
|
17
|
-
|
18
|
-
# The width of the last wrapped line
|
19
|
-
#
|
20
|
-
def width
|
21
|
-
@accumulated_width || 0
|
22
|
-
end
|
23
|
-
|
24
|
-
# The number of spaces in the last wrapped line
|
25
|
-
attr_reader :space_count
|
26
|
-
|
27
|
-
# Whether this line is the last line in the paragraph
|
28
|
-
def paragraph_finished?
|
29
|
-
@newline_encountered || is_next_string_newline? || @arranger.finished?
|
30
|
-
end
|
31
|
-
|
32
|
-
# Work in conjunction with the Prawn::Core::Formatted::Arranger
|
33
|
-
# defined in the :arranger option to determine what formatted text
|
34
|
-
# will fit within the width defined by the :width option
|
35
|
-
#
|
36
|
-
def wrap_line(options)
|
37
|
-
initialize_line(options)
|
38
|
-
|
39
|
-
while fragment = @arranger.next_string
|
40
|
-
@fragment_output = ""
|
41
|
-
|
42
|
-
fragment.lstrip! if first_fragment_on_this_line?(fragment)
|
43
|
-
next if empty_line?(fragment)
|
44
|
-
|
45
|
-
unless apply_font_settings_and_add_fragment_to_line(fragment)
|
46
|
-
break
|
47
|
-
end
|
48
|
-
end
|
49
|
-
@arranger.finalize_line
|
50
|
-
@accumulated_width = @arranger.line_width
|
51
|
-
@space_count = @arranger.space_count
|
52
|
-
@arranger.line
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def first_fragment_on_this_line?(fragment)
|
58
|
-
line_empty? && fragment != "\n"
|
59
|
-
end
|
60
|
-
|
61
|
-
def empty_line?(fragment)
|
62
|
-
empty = line_empty? && fragment.empty? && is_next_string_newline?
|
63
|
-
@arranger.update_last_string("", "", soft_hyphen) if empty
|
64
|
-
empty
|
65
|
-
end
|
66
|
-
|
67
|
-
def is_next_string_newline?
|
68
|
-
@arranger.preview_next_string == "\n"
|
69
|
-
end
|
70
|
-
|
71
|
-
def apply_font_settings_and_add_fragment_to_line(fragment)
|
72
|
-
result = nil
|
73
|
-
@arranger.apply_font_settings do
|
74
|
-
# if font has changed from Unicode to non-Unicode, or vice versa, the characters used for soft hyphens
|
75
|
-
# and zero-width spaces will be different
|
76
|
-
set_soft_hyphen_and_zero_width_space
|
77
|
-
result = add_fragment_to_line(fragment)
|
78
|
-
end
|
79
|
-
result
|
80
|
-
end
|
81
|
-
|
82
|
-
# returns true iff all text was printed without running into the end of
|
83
|
-
# the line
|
84
|
-
#
|
85
|
-
def add_fragment_to_line(fragment)
|
86
|
-
if fragment == ""
|
87
|
-
true
|
88
|
-
elsif fragment == "\n"
|
89
|
-
@newline_encountered = true
|
90
|
-
false
|
91
|
-
else
|
92
|
-
fragment.scan(scan_pattern).each do |segment|
|
93
|
-
if segment == zero_width_space
|
94
|
-
segment_width = 0
|
95
|
-
else
|
96
|
-
segment_width = @document.width_of(segment, :kerning => @kerning)
|
97
|
-
end
|
98
|
-
|
99
|
-
if @accumulated_width + segment_width <= @width
|
100
|
-
@accumulated_width += segment_width
|
101
|
-
@fragment_output += segment
|
102
|
-
else
|
103
|
-
end_of_the_line_reached(segment)
|
104
|
-
fragment_finished(fragment)
|
105
|
-
return false
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
fragment_finished(fragment)
|
110
|
-
true
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
# The pattern used to determine chunks of text to place on a given line
|
115
|
-
#
|
116
|
-
def scan_pattern
|
117
|
-
pattern = "[^#{break_chars}]+#{soft_hyphen}|" +
|
118
|
-
"[^#{break_chars}]+#{hyphen}+|" +
|
119
|
-
"[^#{break_chars}]+|" +
|
120
|
-
"[#{whitespace}]+|" +
|
121
|
-
"#{hyphen}+[^#{break_chars}]*|" +
|
122
|
-
"#{soft_hyphen}"
|
123
|
-
new_regexp(pattern)
|
124
|
-
end
|
125
|
-
|
126
|
-
# The pattern used to determine whether any word breaks exist on a
|
127
|
-
# current line, which in turn determines whether character level
|
128
|
-
# word breaking is needed
|
129
|
-
#
|
130
|
-
def word_division_scan_pattern
|
131
|
-
new_regexp("\\s|[#{zero_width_space}#{soft_hyphen}#{hyphen}]")
|
132
|
-
end
|
133
|
-
|
134
|
-
def break_chars
|
135
|
-
"#{whitespace}#{soft_hyphen}#{hyphen}"
|
136
|
-
end
|
137
|
-
|
138
|
-
def whitespace
|
139
|
-
" \\t#{zero_width_space}"
|
140
|
-
end
|
141
|
-
|
142
|
-
def hyphen
|
143
|
-
"-"
|
144
|
-
end
|
145
|
-
|
146
|
-
def soft_hyphen
|
147
|
-
@soft_hyphen
|
148
|
-
end
|
149
|
-
|
150
|
-
def zero_width_space
|
151
|
-
@zero_width_space
|
152
|
-
end
|
153
|
-
|
154
|
-
def line_empty?
|
155
|
-
@line_empty && @accumulated_width == 0
|
156
|
-
end
|
157
|
-
|
158
|
-
def initialize_line(options)
|
159
|
-
@document = options[:document]
|
160
|
-
@kerning = options[:kerning]
|
161
|
-
@width = options[:width]
|
162
|
-
|
163
|
-
@accumulated_width = 0
|
164
|
-
@line_empty = true
|
165
|
-
@line_contains_more_than_one_word = false
|
166
|
-
|
167
|
-
@arranger = options[:arranger]
|
168
|
-
@arranger.initialize_line
|
169
|
-
|
170
|
-
@newline_encountered = false
|
171
|
-
@line_full = false
|
172
|
-
end
|
173
|
-
|
174
|
-
def set_soft_hyphen_and_zero_width_space
|
175
|
-
# this is done once per fragment, after the font settings for the fragment are applied --
|
176
|
-
# it could actually be skipped if the font hasn't changed
|
177
|
-
font = @document.font
|
178
|
-
@soft_hyphen = font.normalize_encoding(Prawn::Text::SHY)
|
179
|
-
@zero_width_space = font.unicode? ? Prawn::Text::ZWSP : ""
|
180
|
-
end
|
181
|
-
|
182
|
-
def fragment_finished(fragment)
|
183
|
-
if fragment == "\n"
|
184
|
-
@newline_encountered = true
|
185
|
-
@line_empty = false
|
186
|
-
else
|
187
|
-
update_output_based_on_last_fragment(fragment, soft_hyphen)
|
188
|
-
update_line_status_based_on_last_output
|
189
|
-
determine_whether_to_pull_preceding_fragment_to_join_this_one(fragment)
|
190
|
-
end
|
191
|
-
remember_this_fragment_for_backward_looking_ops
|
192
|
-
end
|
193
|
-
|
194
|
-
def update_output_based_on_last_fragment(fragment, normalized_soft_hyphen=nil)
|
195
|
-
remaining_text = fragment.slice(@fragment_output.length..fragment.length)
|
196
|
-
raise Errors::CannotFit if line_finished? && line_empty? &&
|
197
|
-
@fragment_output.empty? && !fragment.strip.empty?
|
198
|
-
@arranger.update_last_string(@fragment_output, remaining_text, normalized_soft_hyphen)
|
199
|
-
end
|
200
|
-
|
201
|
-
def determine_whether_to_pull_preceding_fragment_to_join_this_one(current_fragment)
|
202
|
-
if @fragment_output.empty? &&
|
203
|
-
!current_fragment.empty? &&
|
204
|
-
@line_contains_more_than_one_word
|
205
|
-
unless previous_fragment_ended_with_breakable? ||
|
206
|
-
fragment_begins_with_breakable?(current_fragment)
|
207
|
-
@fragment_output = @previous_fragment_output_without_last_word
|
208
|
-
update_output_based_on_last_fragment(@previous_fragment)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
def remember_this_fragment_for_backward_looking_ops
|
214
|
-
@previous_fragment = @fragment_output.dup
|
215
|
-
pf = @previous_fragment
|
216
|
-
@previous_fragment_ended_with_breakable = pf =~ /[#{break_chars}]$/
|
217
|
-
last_word = pf.slice(/[^#{break_chars}]*$/)
|
218
|
-
last_word_length = last_word.nil? ? 0 : last_word.length
|
219
|
-
@previous_fragment_output_without_last_word = pf.slice(0, pf.length - last_word_length)
|
220
|
-
end
|
221
|
-
|
222
|
-
def previous_fragment_ended_with_breakable?
|
223
|
-
@previous_fragment_ended_with_breakable
|
224
|
-
end
|
225
|
-
|
226
|
-
def fragment_begins_with_breakable?(fragment)
|
227
|
-
fragment =~ /^[#{break_chars}]/
|
228
|
-
end
|
229
|
-
|
230
|
-
def line_finished?
|
231
|
-
@line_full || paragraph_finished?
|
232
|
-
end
|
233
|
-
|
234
|
-
def update_line_status_based_on_last_output
|
235
|
-
@line_contains_more_than_one_word = true if @fragment_output =~ word_division_scan_pattern
|
236
|
-
end
|
237
|
-
|
238
|
-
def end_of_the_line_reached(segment)
|
239
|
-
update_line_status_based_on_last_output
|
240
|
-
wrap_by_char(segment) unless @line_contains_more_than_one_word
|
241
|
-
@line_full = true
|
242
|
-
end
|
243
|
-
|
244
|
-
def wrap_by_char(segment)
|
245
|
-
# this conditional is only necessary for Ruby 1.8 compatibility
|
246
|
-
# String#unicode_characters is a helper which iterates over UTF-8 characters
|
247
|
-
# under Ruby 1.9, it is implemented simply by aliasing #each_char
|
248
|
-
font = @document.font
|
249
|
-
if font.unicode?
|
250
|
-
segment.unicode_characters do |char|
|
251
|
-
break unless append_char(char,font)
|
252
|
-
end
|
253
|
-
else
|
254
|
-
segment.each_char do |char|
|
255
|
-
break unless append_char(char,font)
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
def append_char(char,font)
|
261
|
-
# kerning doesn't make sense in the context of a single character
|
262
|
-
char_width = font.compute_width_of(char)
|
263
|
-
|
264
|
-
if @accumulated_width + char_width <= @width
|
265
|
-
@accumulated_width += char_width
|
266
|
-
@fragment_output << char
|
267
|
-
true
|
268
|
-
else
|
269
|
-
false
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
def new_regexp(pattern)
|
274
|
-
regexp = ruby_19 {
|
275
|
-
Regexp.new(pattern)
|
276
|
-
}
|
277
|
-
regexp = regexp || ruby_18 {
|
278
|
-
lang = @document.font.unicode? ? 'U' : 'N'
|
279
|
-
Regexp.new(pattern, 0, lang)
|
280
|
-
}
|
281
|
-
regexp
|
282
|
-
end
|
283
|
-
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
end
|
288
|
-
end
|
@@ -1,153 +0,0 @@
|
|
1
|
-
require "prawn/core/text/formatted/line_wrap"
|
2
|
-
require "prawn/core/text/formatted/arranger"
|
3
|
-
|
4
|
-
module Prawn
|
5
|
-
module Core
|
6
|
-
module Text
|
7
|
-
module Formatted #:nodoc:
|
8
|
-
module Wrap #:nodoc:
|
9
|
-
|
10
|
-
def initialize(array, options)
|
11
|
-
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
12
|
-
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@document,
|
13
|
-
:kerning => options[:kerning])
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
# See the developer documentation for Prawn::Core::Text#wrap
|
18
|
-
#
|
19
|
-
# Formatted#wrap should set the following variables:
|
20
|
-
# <tt>@line_height</tt>::
|
21
|
-
# the height of the tallest fragment in the last printed line
|
22
|
-
# <tt>@descender</tt>::
|
23
|
-
# the descender height of the tallest fragment in the last
|
24
|
-
# printed line
|
25
|
-
# <tt>@ascender</tt>::
|
26
|
-
# the ascender heigth of the tallest fragment in the last
|
27
|
-
# printed line
|
28
|
-
# <tt>@baseline_y</tt>::
|
29
|
-
# the baseline of the current line
|
30
|
-
# <tt>@nothing_printed</tt>::
|
31
|
-
# set to true until something is printed, then false
|
32
|
-
# <tt>@everything_printed</tt>::
|
33
|
-
# set to false until everything printed, then true
|
34
|
-
#
|
35
|
-
# Returns any formatted text that was not printed
|
36
|
-
#
|
37
|
-
def wrap(array) #:nodoc:
|
38
|
-
initialize_wrap(array)
|
39
|
-
|
40
|
-
stop = false
|
41
|
-
while !stop
|
42
|
-
# wrap before testing if enough height for this line because the
|
43
|
-
# height of the highest fragment on this line will be used to
|
44
|
-
# determine the line height
|
45
|
-
@line_wrap.wrap_line(:document => @document,
|
46
|
-
:kerning => @kerning,
|
47
|
-
:width => available_width,
|
48
|
-
:arranger => @arranger)
|
49
|
-
|
50
|
-
if enough_height_for_this_line?
|
51
|
-
move_baseline_down
|
52
|
-
print_line
|
53
|
-
else
|
54
|
-
stop = true
|
55
|
-
end
|
56
|
-
|
57
|
-
stop ||= @single_line || @arranger.finished?
|
58
|
-
end
|
59
|
-
@text = @printed_lines.join("\n")
|
60
|
-
@everything_printed = @arranger.finished?
|
61
|
-
@arranger.unconsumed
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
def print_line
|
67
|
-
@nothing_printed = false
|
68
|
-
printed_fragments = []
|
69
|
-
fragments_this_line = []
|
70
|
-
|
71
|
-
word_spacing = word_spacing_for_this_line
|
72
|
-
while fragment = @arranger.retrieve_fragment
|
73
|
-
fragment.word_spacing = word_spacing
|
74
|
-
if fragment.text == "\n"
|
75
|
-
printed_fragments << "\n" if @printed_lines.last == ""
|
76
|
-
break
|
77
|
-
end
|
78
|
-
printed_fragments << fragment.text
|
79
|
-
fragments_this_line << fragment
|
80
|
-
end
|
81
|
-
|
82
|
-
accumulated_width = 0
|
83
|
-
fragments_this_line.reverse! if @direction == :rtl
|
84
|
-
fragments_this_line.each do |fragment|
|
85
|
-
fragment.default_direction = @direction
|
86
|
-
format_and_draw_fragment(fragment, accumulated_width,
|
87
|
-
@line_wrap.width, word_spacing)
|
88
|
-
accumulated_width += fragment.width
|
89
|
-
end
|
90
|
-
|
91
|
-
if "".respond_to?(:force_encoding)
|
92
|
-
printed_fragments.map! { |s| s.force_encoding("utf-8") }
|
93
|
-
end
|
94
|
-
@printed_lines << printed_fragments.join
|
95
|
-
end
|
96
|
-
|
97
|
-
def word_spacing_for_this_line
|
98
|
-
if @align == :justify &&
|
99
|
-
@line_wrap.space_count > 0 &&
|
100
|
-
!@line_wrap.paragraph_finished?
|
101
|
-
(available_width - @line_wrap.width) / @line_wrap.space_count
|
102
|
-
else
|
103
|
-
0
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def enough_height_for_this_line?
|
108
|
-
@line_height = @arranger.max_line_height
|
109
|
-
@descender = @arranger.max_descender
|
110
|
-
@ascender = @arranger.max_ascender
|
111
|
-
if @baseline_y == 0
|
112
|
-
diff = @ascender + @descender
|
113
|
-
else
|
114
|
-
diff = @descender + @line_height + @leading
|
115
|
-
end
|
116
|
-
required_total_height = @baseline_y.abs + diff
|
117
|
-
if required_total_height > @height + 0.0001
|
118
|
-
# no room for the full height of this line
|
119
|
-
@arranger.repack_unretrieved
|
120
|
-
false
|
121
|
-
else
|
122
|
-
true
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def initialize_wrap(array)
|
127
|
-
@text = nil
|
128
|
-
@arranger.format_array = array
|
129
|
-
|
130
|
-
# these values will depend on the maximum value within a given line
|
131
|
-
@line_height = 0
|
132
|
-
@descender = 0
|
133
|
-
@ascender = 0
|
134
|
-
@baseline_y = 0
|
135
|
-
|
136
|
-
@printed_lines = []
|
137
|
-
@nothing_printed = true
|
138
|
-
@everything_printed = false
|
139
|
-
end
|
140
|
-
|
141
|
-
def format_and_draw_fragment(fragment, accumulated_width,
|
142
|
-
line_width, word_spacing)
|
143
|
-
@arranger.apply_color_and_font_settings(fragment) do
|
144
|
-
draw_fragment(fragment, accumulated_width,
|
145
|
-
line_width, word_spacing)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
@@ -1,136 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# page_geometry.rb : Describes PDF page geometries
|
4
|
-
#
|
5
|
-
# Copyright April 2008, Gregory Brown. All Rights Reserved.
|
6
|
-
#
|
7
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
-
|
9
|
-
module Prawn
|
10
|
-
class Document
|
11
|
-
|
12
|
-
# Dimensions pulled from PDF::Writer, rubyforge.org/projects/ruby-pdf
|
13
|
-
#
|
14
|
-
# All of these dimensions are in PDF Points, see Prawn::Measurements for
|
15
|
-
# conversion utilities.
|
16
|
-
#
|
17
|
-
# Additionally, if the size you are after is not listed below, you can always
|
18
|
-
# specify your size by passing an array of width and height to Prawn::Document.new
|
19
|
-
# like:
|
20
|
-
#
|
21
|
-
# Prawn::Document.new(:page_size => [1000, 20000])
|
22
|
-
#
|
23
|
-
# The sizes below can be used by passing the appropriate string to :size:
|
24
|
-
#
|
25
|
-
# Prawn::Document.new(:page_size => '2A0')
|
26
|
-
#
|
27
|
-
# ===Inbuilt Sizes:
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# 4A0:: => 4767.87 x 6740.79
|
31
|
-
# 2A0:: => 3370.39 x 4767.87
|
32
|
-
# A0:: => 2383.94 x 3370.39
|
33
|
-
# A1:: => 1683.78 x 2383.94
|
34
|
-
# A2:: => 1190.55 x 1683.78
|
35
|
-
# A3:: => 841.89 x 1190.55
|
36
|
-
# A4:: => 595.28 x 841.89
|
37
|
-
# A5:: => 419.53 x 595.28
|
38
|
-
# A6:: => 297.64 x 419.53
|
39
|
-
# A7:: => 209.76 x 297.64
|
40
|
-
# A8:: => 147.40 x 209.76
|
41
|
-
# A9:: => 104.88 x 147.40
|
42
|
-
# A10:: => 73.70 x 104.88
|
43
|
-
# B0:: => 2834.65 x 4008.19
|
44
|
-
# B1:: => 2004.09 x 2834.65
|
45
|
-
# B2:: => 1417.32 x 2004.09
|
46
|
-
# B3:: => 1000.63 x 1417.32
|
47
|
-
# B4:: => 708.66 x 1000.63
|
48
|
-
# B5:: => 498.90 x 708.66
|
49
|
-
# B6:: => 354.33 x 498.90
|
50
|
-
# B7:: => 249.45 x 354.33
|
51
|
-
# B8:: => 175.75 x 249.45
|
52
|
-
# B9:: => 124.72 x 175.75
|
53
|
-
# B10:: => 87.87 x 124.72
|
54
|
-
# C0:: => 2599.37 x 3676.54
|
55
|
-
# C1:: => 1836.85 x 2599.37
|
56
|
-
# C2:: => 1298.27 x 1836.85
|
57
|
-
# C3:: => 918.43 x 1298.27
|
58
|
-
# C4:: => 649.13 x 918.43
|
59
|
-
# C5:: => 459.21 x 649.13
|
60
|
-
# C6:: => 323.15 x 459.21
|
61
|
-
# C7:: => 229.61 x 323.15
|
62
|
-
# C8:: => 161.57 x 229.61
|
63
|
-
# C9:: => 113.39 x 161.57
|
64
|
-
# C10:: => 79.37 x 113.39
|
65
|
-
# RA0:: => 2437.80 x 3458.27
|
66
|
-
# RA1:: => 1729.13 x 2437.80
|
67
|
-
# RA2:: => 1218.90 x 1729.13
|
68
|
-
# RA3:: => 864.57 x 1218.90
|
69
|
-
# RA4:: => 609.45 x 864.57
|
70
|
-
# SRA0:: => 2551.18 x 3628.35
|
71
|
-
# SRA1:: => 1814.17 x 2551.18
|
72
|
-
# SRA2:: => 1275.59 x 1814.17
|
73
|
-
# SRA3:: => 907.09 x 1275.59
|
74
|
-
# SRA4:: => 637.80 x 907.09
|
75
|
-
# EXECUTIVE:: => 521.86 x 756.00
|
76
|
-
# FOLIO:: => 612.00 x 936.00
|
77
|
-
# LEGAL:: => 612.00 x 1008.00
|
78
|
-
# LETTER:: => 612.00 x 792.00
|
79
|
-
# TABLOID:: => 792.00 x 1224.00
|
80
|
-
#
|
81
|
-
module PageGeometry
|
82
|
-
|
83
|
-
SIZES = { "4A0" => [4767.87, 6740.79],
|
84
|
-
"2A0" => [3370.39, 4767.87],
|
85
|
-
"A0" => [2383.94, 3370.39],
|
86
|
-
"A1" => [1683.78, 2383.94],
|
87
|
-
"A2" => [1190.55, 1683.78],
|
88
|
-
"A3" => [841.89, 1190.55],
|
89
|
-
"A4" => [595.28, 841.89],
|
90
|
-
"A5" => [419.53, 595.28],
|
91
|
-
"A6" => [297.64, 419.53],
|
92
|
-
"A7" => [209.76, 297.64],
|
93
|
-
"A8" => [147.40, 209.76],
|
94
|
-
"A9" => [104.88, 147.40],
|
95
|
-
"A10" => [73.70, 104.88],
|
96
|
-
"B0" => [2834.65, 4008.19],
|
97
|
-
"B1" => [2004.09, 2834.65],
|
98
|
-
"B2" => [1417.32, 2004.09],
|
99
|
-
"B3" => [1000.63, 1417.32],
|
100
|
-
"B4" => [708.66, 1000.63],
|
101
|
-
"B5" => [498.90, 708.66],
|
102
|
-
"B6" => [354.33, 498.90],
|
103
|
-
"B7" => [249.45, 354.33],
|
104
|
-
"B8" => [175.75, 249.45],
|
105
|
-
"B9" => [124.72, 175.75],
|
106
|
-
"B10" => [87.87, 124.72],
|
107
|
-
"C0" => [2599.37, 3676.54],
|
108
|
-
"C1" => [1836.85, 2599.37],
|
109
|
-
"C2" => [1298.27, 1836.85],
|
110
|
-
"C3" => [918.43, 1298.27],
|
111
|
-
"C4" => [649.13, 918.43],
|
112
|
-
"C5" => [459.21, 649.13],
|
113
|
-
"C6" => [323.15, 459.21],
|
114
|
-
"C7" => [229.61, 323.15],
|
115
|
-
"C8" => [161.57, 229.61],
|
116
|
-
"C9" => [113.39, 161.57],
|
117
|
-
"C10" => [79.37, 113.39],
|
118
|
-
"RA0" => [2437.80, 3458.27],
|
119
|
-
"RA1" => [1729.13, 2437.80],
|
120
|
-
"RA2" => [1218.90, 1729.13],
|
121
|
-
"RA3" => [864.57, 1218.90],
|
122
|
-
"RA4" => [609.45, 864.57],
|
123
|
-
"SRA0" => [2551.18, 3628.35],
|
124
|
-
"SRA1" => [1814.17, 2551.18],
|
125
|
-
"SRA2" => [1275.59, 1814.17],
|
126
|
-
"SRA3" => [907.09, 1275.59],
|
127
|
-
"SRA4" => [637.80, 907.09],
|
128
|
-
"EXECUTIVE" => [521.86, 756.00],
|
129
|
-
"FOLIO" => [612.00, 936.00],
|
130
|
-
"LEGAL" => [612.00, 1008.00],
|
131
|
-
"LETTER" => [612.00, 792.00],
|
132
|
-
"TABLOID" => [792.00, 1224.00] }
|
133
|
-
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|