prawn 0.11.1.pre → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +2 -340
- data/HACKING +1 -1
- data/LICENSE +3 -3
- data/Rakefile +17 -6
- data/data/encodings/win_ansi.txt +1 -1
- data/data/images/prawn.png +0 -0
- data/data/pdfs/form.pdf +820 -0
- data/data/pdfs/multipage_template.pdf +127 -0
- data/examples/bounding_box/bounding_boxes.rb +4 -3
- data/examples/bounding_box/indentation.rb +2 -1
- data/examples/bounding_box/russian_boxes.rb +3 -2
- data/examples/bounding_box/stretched_nesting.rb +2 -1
- data/examples/general/background.rb +2 -1
- data/examples/general/canvas.rb +2 -1
- data/examples/general/context_sensitive_headers.rb +2 -1
- data/examples/general/float.rb +2 -1
- data/examples/general/margin.rb +2 -1
- data/examples/general/measurement_units.rb +2 -1
- data/examples/general/metadata-info.rb +2 -1
- data/examples/general/multi_page_layout.rb +2 -1
- data/examples/general/outlines.rb +2 -1
- data/examples/general/page_geometry.rb +2 -1
- data/examples/general/page_numbering.rb +27 -2
- data/examples/general/page_templates.rb +20 -0
- data/examples/general/repeaters.rb +2 -1
- data/examples/general/stamp.rb +4 -3
- data/examples/general/templates.rb +2 -1
- data/examples/graphics/basic_images.rb +2 -1
- data/examples/graphics/cmyk.rb +2 -1
- data/examples/graphics/curves.rb +4 -3
- data/examples/graphics/gradient.rb +23 -0
- data/examples/graphics/hexagon.rb +3 -2
- data/examples/graphics/image_fit.rb +3 -2
- data/examples/graphics/image_flow.rb +2 -1
- data/examples/graphics/image_position.rb +3 -2
- data/examples/graphics/line.rb +2 -1
- data/examples/graphics/png_types.rb +3 -2
- data/examples/graphics/polygons.rb +3 -2
- data/examples/graphics/remote_images.rb +2 -1
- data/examples/graphics/rounded_polygons.rb +2 -1
- data/examples/graphics/rounded_rectangle.rb +2 -1
- data/examples/graphics/ruport_style_helpers.rb +3 -2
- data/examples/graphics/stroke_bounds.rb +2 -1
- data/examples/graphics/stroke_cap_and_join.rb +2 -1
- data/examples/graphics/stroke_dash.rb +2 -1
- data/examples/graphics/transformations.rb +2 -1
- data/examples/graphics/transparency.rb +4 -3
- data/examples/grid/bounding_boxes.rb +2 -1
- data/examples/grid/column_gutter_grid.rb +2 -1
- data/examples/grid/multi_boxes.rb +2 -1
- data/examples/grid/show_grid.rb +2 -1
- data/examples/grid/simple_grid.rb +2 -1
- data/examples/m17n/chinese_text_wrapping.rb +2 -1
- data/examples/m17n/euro.rb +3 -2
- data/examples/m17n/full_win_ansi_character_list.rb +20 -0
- data/examples/m17n/sjis.rb +2 -1
- data/examples/m17n/utf8.rb +3 -2
- data/examples/m17n/win_ansi_charset.rb +2 -1
- data/examples/security/hello_foo.rb +2 -1
- data/examples/table/bill.rb +2 -1
- data/examples/table/borders.rb +25 -0
- data/examples/table/cell.rb +3 -2
- data/examples/table/checkerboard.rb +2 -1
- data/examples/table/header.rb +3 -2
- data/examples/table/inline_format_table.rb +2 -1
- data/examples/table/multi_page_table.rb +2 -1
- data/examples/table/simple_table.rb +2 -1
- data/examples/table/subtable.rb +2 -1
- data/examples/table/widths.rb +2 -1
- data/examples/text/alignment.rb +2 -1
- data/examples/text/character_spacing.rb +2 -1
- data/examples/text/dfont.rb +2 -1
- data/examples/text/family_based_styling.rb +3 -2
- data/examples/text/font_calculations.rb +2 -1
- data/examples/text/font_size.rb +2 -1
- data/examples/text/hyphenation.rb +2 -2
- data/examples/text/indent_paragraphs.rb +7 -5
- data/examples/text/inline_format.rb +7 -6
- data/examples/text/kerning.rb +2 -1
- data/examples/text/rendering_mode.rb +21 -0
- data/examples/text/rotated.rb +2 -1
- data/examples/text/shaped_text_box.rb +2 -1
- data/examples/text/simple_text.rb +2 -1
- data/examples/text/simple_text_ttf.rb +2 -1
- data/examples/text/span.rb +3 -2
- data/examples/text/text_box.rb +7 -5
- data/examples/text/text_box_returning_excess.rb +4 -3
- data/examples/text/text_flow.rb +2 -1
- data/lib/prawn.rb +1 -1
- data/lib/prawn/core/object_store.rb +42 -14
- data/lib/prawn/core/page.rb +22 -8
- data/lib/prawn/core/text.rb +141 -13
- data/lib/prawn/core/text/formatted/arranger.rb +39 -12
- data/lib/prawn/core/text/formatted/line_wrap.rb +205 -60
- data/lib/prawn/core/text/formatted/wrap.rb +72 -35
- data/lib/prawn/document.rb +174 -70
- data/lib/prawn/document/bounding_box.rb +122 -83
- data/lib/prawn/document/column_box.rb +113 -0
- data/lib/prawn/document/graphics_state.rb +90 -2
- data/lib/prawn/document/internals.rb +5 -3
- data/lib/prawn/errors.rb +5 -0
- data/lib/prawn/font.rb +4 -4
- data/lib/prawn/font/afm.rb +11 -0
- data/lib/prawn/font/ttf.rb +5 -0
- data/lib/prawn/graphics.rb +77 -14
- data/lib/prawn/graphics/cap_style.rb +13 -5
- data/lib/prawn/graphics/color.rb +54 -35
- data/lib/prawn/graphics/dash.rb +27 -16
- data/lib/prawn/graphics/gradient.rb +84 -0
- data/lib/prawn/graphics/join_style.rb +12 -3
- data/lib/prawn/graphics/transparency.rb +4 -4
- data/lib/prawn/images.rb +18 -160
- data/lib/prawn/images/jpg.rb +39 -0
- data/lib/prawn/images/png.rb +130 -0
- data/lib/prawn/repeater.rb +6 -13
- data/lib/prawn/security.rb +6 -1
- data/lib/prawn/stamp.rb +12 -4
- data/lib/prawn/table.rb +36 -4
- data/lib/prawn/table/cell.rb +224 -63
- data/lib/prawn/table/cell/text.rb +20 -10
- data/lib/prawn/table/cells.rb +23 -6
- data/lib/prawn/text.rb +54 -91
- data/lib/prawn/text/box.rb +29 -283
- data/lib/prawn/text/formatted/box.rb +349 -24
- data/lib/prawn/text/formatted/fragment.rb +63 -2
- data/lib/prawn/text/formatted/parser.rb +2 -1
- data/prawn.gemspec +21 -5
- data/spec/bounding_box_spec.rb +61 -28
- data/spec/cell_spec.rb +168 -30
- data/spec/document_spec.rb +187 -3
- data/spec/extensions/mocha.rb +45 -0
- data/spec/font_spec.rb +32 -1
- data/spec/formatted_text_arranger_spec.rb +35 -40
- data/spec/formatted_text_box_spec.rb +287 -443
- data/spec/formatted_text_fragment_spec.rb +87 -0
- data/spec/graphics_spec.rb +128 -12
- data/spec/grid_spec.rb +1 -1
- data/spec/images_spec.rb +11 -3
- data/spec/inline_formatted_text_parser_spec.rb +8 -0
- data/spec/line_wrap_spec.rb +200 -208
- data/spec/object_store_spec.rb +10 -0
- data/spec/outline_spec.rb +7 -3
- data/spec/repeater_spec.rb +58 -10
- data/spec/security_spec.rb +6 -0
- data/spec/spec_helper.rb +12 -8
- data/spec/stamp_spec.rb +52 -1
- data/spec/stroke_styles_spec.rb +30 -0
- data/spec/table_spec.rb +93 -3
- data/spec/template_spec.rb +132 -6
- data/spec/text_at_spec.rb +14 -4
- data/spec/text_box_spec.rb +309 -70
- data/spec/text_rendering_mode_spec.rb +45 -0
- data/spec/text_spec.rb +60 -17
- data/spec/text_with_inline_formatting_spec.rb +4 -162
- metadata +241 -241
- data/lib/prawn/core/text/line_wrap.rb +0 -211
- data/lib/prawn/core/text/wrap.rb +0 -82
- data/vendor/pdf-inspector/README +0 -18
- data/vendor/pdf-inspector/lib/pdf/inspector.rb +0 -26
- data/vendor/pdf-inspector/lib/pdf/inspector/extgstate.rb +0 -18
- data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +0 -131
- data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +0 -25
- data/vendor/pdf-inspector/lib/pdf/inspector/text.rb +0 -46
- data/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +0 -19
- data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
- data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
- data/vendor/ttfunk/example.rb +0 -45
- data/vendor/ttfunk/lib/ttfunk.rb +0 -102
- data/vendor/ttfunk/lib/ttfunk/directory.rb +0 -17
- data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +0 -88
- data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +0 -69
- data/vendor/ttfunk/lib/ttfunk/reader.rb +0 -44
- data/vendor/ttfunk/lib/ttfunk/resource_file.rb +0 -78
- data/vendor/ttfunk/lib/ttfunk/subset.rb +0 -18
- data/vendor/ttfunk/lib/ttfunk/subset/base.rb +0 -141
- data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +0 -50
- data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +0 -48
- data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +0 -63
- data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +0 -55
- data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +0 -72
- data/vendor/ttfunk/lib/ttfunk/table.rb +0 -46
- data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +0 -34
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +0 -54
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +0 -126
- data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +0 -79
- data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +0 -64
- data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +0 -81
- data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +0 -37
- data/vendor/ttfunk/lib/ttfunk/table/head.rb +0 -44
- data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +0 -41
- data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +0 -47
- data/vendor/ttfunk/lib/ttfunk/table/kern.rb +0 -79
- data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +0 -62
- data/vendor/ttfunk/lib/ttfunk/table/loca.rb +0 -43
- data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +0 -40
- data/vendor/ttfunk/lib/ttfunk/table/name.rb +0 -125
- data/vendor/ttfunk/lib/ttfunk/table/os2.rb +0 -78
- data/vendor/ttfunk/lib/ttfunk/table/post.rb +0 -91
- data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +0 -43
- data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +0 -35
- data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +0 -23
- data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +0 -17
- data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +0 -17
- data/vendor/ttfunk/lib/ttfunk/table/simple.rb +0 -14
@@ -1,211 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# core/text/line_wrap.rb : Implements individual line wrapping
|
4
|
-
#
|
5
|
-
# Copyright January 2010, Daniel Nelson. All Rights Reserved.
|
6
|
-
#
|
7
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
-
#
|
9
|
-
|
10
|
-
module Prawn
|
11
|
-
module Core
|
12
|
-
module Text
|
13
|
-
|
14
|
-
class LineWrap #:nodoc:
|
15
|
-
|
16
|
-
# The width of the last wrapped line
|
17
|
-
#
|
18
|
-
def width
|
19
|
-
@accumulated_width || 0
|
20
|
-
end
|
21
|
-
|
22
|
-
# The number of spaces in the last wrapped line
|
23
|
-
#
|
24
|
-
def space_count
|
25
|
-
@space_count
|
26
|
-
end
|
27
|
-
|
28
|
-
# The number of characters consumed from the last line passed into
|
29
|
-
# wrap_line. This may differ from the number of characters in the
|
30
|
-
# returned line because trailing white spaces are removed
|
31
|
-
#
|
32
|
-
def consumed_char_count
|
33
|
-
@consumed_char_count
|
34
|
-
end
|
35
|
-
|
36
|
-
# The pattern used to determine chunks of text to place on a given line
|
37
|
-
#
|
38
|
-
def scan_pattern
|
39
|
-
pattern = "[^#{break_chars}]+#{soft_hyphen}|" +
|
40
|
-
"[^#{break_chars}]+#{hyphen}+|" +
|
41
|
-
"[^#{break_chars}]+|" +
|
42
|
-
"[#{whitespace}]+|" +
|
43
|
-
"#{hyphen}+[^#{break_chars}]*|" +
|
44
|
-
"#{soft_hyphen}"
|
45
|
-
new_regexp(pattern)
|
46
|
-
end
|
47
|
-
|
48
|
-
# The pattern used to determine whether any word breaks exist on a
|
49
|
-
# current line, which in turn determines whether character level
|
50
|
-
# word breaking is needed
|
51
|
-
#
|
52
|
-
def word_division_scan_pattern
|
53
|
-
new_regexp("\\s|[#{hyphen}#{soft_hyphen}]")
|
54
|
-
end
|
55
|
-
|
56
|
-
# Take a single line and deterimine what part of it fits within the
|
57
|
-
# width defined by the :width option
|
58
|
-
#
|
59
|
-
def wrap_line(line, options)
|
60
|
-
initialize_line(options)
|
61
|
-
|
62
|
-
previous_segment = nil
|
63
|
-
whitespace_pattern = new_regexp("[#{whitespace}]")
|
64
|
-
|
65
|
-
line.scan(@scan_pattern).each do |segment|
|
66
|
-
|
67
|
-
# Don't let leading white space count against available space
|
68
|
-
if @output.empty? && segment =~ whitespace_pattern
|
69
|
-
@discarded_char_count += segment.length
|
70
|
-
next
|
71
|
-
end
|
72
|
-
|
73
|
-
segment_width = @document.width_of(segment, :kerning => @kerning)
|
74
|
-
|
75
|
-
if @accumulated_width + segment_width <= @width
|
76
|
-
@accumulated_width += segment_width
|
77
|
-
@output += segment
|
78
|
-
else
|
79
|
-
end_of_the_line(segment)
|
80
|
-
break
|
81
|
-
end
|
82
|
-
previous_segment = segment
|
83
|
-
end
|
84
|
-
raise Errors::CannotFit if @output.empty? && !line.strip.empty?
|
85
|
-
|
86
|
-
finalize_line
|
87
|
-
|
88
|
-
@space_count = @output.count(" ")
|
89
|
-
@output
|
90
|
-
end
|
91
|
-
|
92
|
-
private
|
93
|
-
|
94
|
-
def initialize_line(options)
|
95
|
-
@document = options[:document]
|
96
|
-
@kerning = options[:kerning]
|
97
|
-
@width = options[:width]
|
98
|
-
|
99
|
-
@scan_pattern = scan_pattern
|
100
|
-
@word_division_scan_pattern = word_division_scan_pattern
|
101
|
-
|
102
|
-
@discarded_char_count = 0
|
103
|
-
@accumulated_width = 0
|
104
|
-
@output = ""
|
105
|
-
end
|
106
|
-
|
107
|
-
def break_chars
|
108
|
-
"#{whitespace}#{soft_hyphen}#{hyphen}"
|
109
|
-
end
|
110
|
-
|
111
|
-
def whitespace
|
112
|
-
" \\t"
|
113
|
-
end
|
114
|
-
|
115
|
-
def hyphen
|
116
|
-
"-"
|
117
|
-
end
|
118
|
-
|
119
|
-
def soft_hyphen
|
120
|
-
@document.font.normalize_encoding("")
|
121
|
-
end
|
122
|
-
|
123
|
-
# If there is more than one word on the line, then clean up the last
|
124
|
-
# word on the line; otherwise, wrap by character
|
125
|
-
#
|
126
|
-
def end_of_the_line(segment)
|
127
|
-
if @output =~ @word_division_scan_pattern
|
128
|
-
if segment =~ new_regexp("^#{hyphen}") &&
|
129
|
-
@output !~ new_regexp("[#{break_chars}]$")
|
130
|
-
remove_last_output_word
|
131
|
-
end
|
132
|
-
else
|
133
|
-
wrap_by_char(segment)
|
134
|
-
# since when adding characters individually, kerning has no effect,
|
135
|
-
# recompute width of the output after adding characters
|
136
|
-
# IMPORTANT: leave this computation here, rather than moving it into
|
137
|
-
# append_char because append_char is more general than
|
138
|
-
# end_of_the_line, so while end_of_the_line is likely to be
|
139
|
-
# overridden, wrap_by_char may not be, and we don't want to
|
140
|
-
# recompute line width except where necessary (for example, see
|
141
|
-
# Prawn::Core::Text::Formatted::LineWrap)
|
142
|
-
@accumulated_width = compute_output_width
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def remove_last_output_word
|
147
|
-
segments = []
|
148
|
-
regexp = new_regexp("[^#{break_chars}]+|[#{break_chars}]+")
|
149
|
-
@output.scan(regexp).each { |segment| segments << segment }
|
150
|
-
segments.pop
|
151
|
-
@output = segments.join("")
|
152
|
-
end
|
153
|
-
|
154
|
-
def finalize_line
|
155
|
-
@consumed_char_count = @output.length + @discarded_char_count
|
156
|
-
|
157
|
-
unless @output.empty?
|
158
|
-
@output = @output[0..-2].gsub(soft_hyphen, "") + @output[-1..-1]
|
159
|
-
end
|
160
|
-
|
161
|
-
strip_trailing_whitespace
|
162
|
-
end
|
163
|
-
|
164
|
-
def strip_trailing_whitespace
|
165
|
-
@accumulated_width = compute_output_width if @output.strip!
|
166
|
-
end
|
167
|
-
|
168
|
-
def compute_output_width
|
169
|
-
@document.width_of(@output, :kerning => @kerning)
|
170
|
-
end
|
171
|
-
|
172
|
-
def wrap_by_char(segment)
|
173
|
-
if @document.font.unicode?
|
174
|
-
segment.unpack("U*").each do |char_int|
|
175
|
-
break unless append_char([char_int].pack("U"))
|
176
|
-
end
|
177
|
-
else
|
178
|
-
segment.each_char do |char|
|
179
|
-
break unless append_char(char)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
def append_char(char)
|
185
|
-
# kerning doesn't make sense in the context of a single character
|
186
|
-
char_width = @document.width_of(char)
|
187
|
-
@accumulated_width += char_width
|
188
|
-
|
189
|
-
if @accumulated_width >= @width
|
190
|
-
false
|
191
|
-
else
|
192
|
-
@output << char
|
193
|
-
true
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
def new_regexp(pattern)
|
198
|
-
regexp = ruby_19 {
|
199
|
-
Regexp.new(pattern)
|
200
|
-
}
|
201
|
-
regexp = regexp || ruby_18 {
|
202
|
-
lang = @document.font.unicode? ? 'U' : 'N'
|
203
|
-
Regexp.new(pattern, 0, lang)
|
204
|
-
}
|
205
|
-
regexp
|
206
|
-
end
|
207
|
-
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
data/lib/prawn/core/text/wrap.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
require "prawn/core/text/line_wrap"
|
2
|
-
|
3
|
-
module Prawn
|
4
|
-
module Core
|
5
|
-
module Text
|
6
|
-
module Wrap #:nodoc:
|
7
|
-
|
8
|
-
def initialize(text, options)
|
9
|
-
@line_wrap = Prawn::Core::Text::LineWrap.new
|
10
|
-
end
|
11
|
-
|
12
|
-
# #wrap is part of the developer API. Override it in extensions to Prawn
|
13
|
-
# that inherit Text::Box but need a different placement algorithm.
|
14
|
-
# #wrap is where the actual placement of text happens. If @inked is
|
15
|
-
# false, then all the placement computations should be performed, and
|
16
|
-
# unprinted text returned, but no text should actually be drawn to the
|
17
|
-
# PDF. This enables look-ahead computations that need to know whether all
|
18
|
-
# the text was printed under a set of conditions or how tall the text was
|
19
|
-
# under certain conditions.
|
20
|
-
#
|
21
|
-
# #wrap is called from several places within box.rb and relies on
|
22
|
-
# certain conditions established by render. Do not call #wrap from
|
23
|
-
# outside of Text::Box or its descendants.
|
24
|
-
#
|
25
|
-
# #wrap should set the following instance variables:
|
26
|
-
# <tt>@text</tt>:: the text that was printed
|
27
|
-
# <tt>@line_height</tt>:: the height of the last printed line
|
28
|
-
# <tt>@descender</tt>:: the descender height of the last printed line
|
29
|
-
# <tt>@ascender</tt>:: the ascender heigth of the last printed line
|
30
|
-
# <tt>@baseline_y</tt>:: the base line of the last printed line
|
31
|
-
#
|
32
|
-
# Returns any unprinted text
|
33
|
-
#
|
34
|
-
def wrap(text) #:nodoc:
|
35
|
-
@text = nil
|
36
|
-
remaining_text = text
|
37
|
-
@line_height = @document.font.height
|
38
|
-
@descender = @document.font.descender
|
39
|
-
@ascender = @document.font.ascender
|
40
|
-
@baseline_y = -@ascender
|
41
|
-
|
42
|
-
printed_lines = []
|
43
|
-
|
44
|
-
while remaining_text &&
|
45
|
-
remaining_text.length > 0 &&
|
46
|
-
@baseline_y.abs + @descender <= @height
|
47
|
-
line_to_print = @line_wrap.wrap_line(remaining_text.first_line,
|
48
|
-
:document => @document,
|
49
|
-
:kerning => @kerning,
|
50
|
-
:width => available_width)
|
51
|
-
|
52
|
-
remaining_text = remaining_text.slice(@line_wrap.consumed_char_count..
|
53
|
-
remaining_text.length)
|
54
|
-
include_ellipses = (@overflow == :ellipses && last_line? &&
|
55
|
-
remaining_text.length > 0)
|
56
|
-
printed_lines << draw_line(line_to_print, @line_wrap.width,
|
57
|
-
word_spacing_for_this_line, include_ellipses)
|
58
|
-
@baseline_y -= (@line_height + @leading)
|
59
|
-
break if @single_line
|
60
|
-
end
|
61
|
-
|
62
|
-
@text = printed_lines.join("\n")
|
63
|
-
|
64
|
-
remaining_text
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def word_spacing_for_this_line
|
70
|
-
if @align == :justify &&
|
71
|
-
@line_wrap.space_count > 0 &&
|
72
|
-
@line_wrap.width.to_f / available_width.to_f >= 0.75
|
73
|
-
(available_width - @line_wrap.width) / @line_wrap.space_count
|
74
|
-
else
|
75
|
-
0
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
data/vendor/pdf-inspector/README
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
PDF::Inspector : A tool for analyzing PDF output
|
2
|
-
|
3
|
-
This library provides a number of PDF::Reader[0] based tools for use in testing
|
4
|
-
PDF output. Presently, the primary purpose of this tool is to support the
|
5
|
-
tests found in Prawn[1], a pure Ruby PDF generation library.
|
6
|
-
|
7
|
-
However, it may be useful to others, so we have made it available on Github[2]
|
8
|
-
|
9
|
-
Questions can be directed to the Prawn mailing list[3], but please remember
|
10
|
-
that this code is not necessarily suitable for production and has no officially
|
11
|
-
planned release date.
|
12
|
-
|
13
|
-
That having been said, patches are welcome!
|
14
|
-
|
15
|
-
[0] http://github.com/yob/pdf-reader
|
16
|
-
[1] http://github.com/sandal/prawn
|
17
|
-
[2] http://github.com/sandal/pdf-inspector
|
18
|
-
[3] http://groups.google.com/group/prawn-ruby
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "pdf/reader"
|
3
|
-
require "pdf/inspector/text"
|
4
|
-
require "pdf/inspector/xobject"
|
5
|
-
require "pdf/inspector/extgstate"
|
6
|
-
require "pdf/inspector/graphics"
|
7
|
-
require "pdf/inspector/page"
|
8
|
-
|
9
|
-
module PDF
|
10
|
-
class Inspector
|
11
|
-
def self.analyze(output,*args,&block)
|
12
|
-
obs = self.new(*args, &block)
|
13
|
-
PDF::Reader.string(output,obs)
|
14
|
-
obs
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.analyze_file(filename,*args,&block)
|
18
|
-
analyze(File.open(filename, "rb") { |f| f.read },*args,&block)
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.parse(obj)
|
22
|
-
PDF::Reader::Parser.new(
|
23
|
-
PDF::Reader::Buffer.new(StringIO.new(obj)), nil).parse_token
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module PDF
|
2
|
-
class Inspector
|
3
|
-
class ExtGState < Inspector
|
4
|
-
attr_accessor :extgstates
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@extgstates = []
|
8
|
-
end
|
9
|
-
|
10
|
-
def resource_extgstate(*params)
|
11
|
-
@extgstates << {
|
12
|
-
:opacity => params[1][:ca],
|
13
|
-
:stroke_opacity => params[1][:CA]
|
14
|
-
}
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,131 +0,0 @@
|
|
1
|
-
module PDF
|
2
|
-
class Inspector
|
3
|
-
module Graphics
|
4
|
-
class Line < Inspector
|
5
|
-
attr_accessor :points, :widths
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@points = []
|
9
|
-
@widths = []
|
10
|
-
end
|
11
|
-
|
12
|
-
def append_line(*params)
|
13
|
-
@points << params
|
14
|
-
end
|
15
|
-
|
16
|
-
def begin_new_subpath(*params)
|
17
|
-
@points << params
|
18
|
-
end
|
19
|
-
|
20
|
-
def set_line_width(params)
|
21
|
-
@widths << params
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
class Rectangle < Inspector
|
27
|
-
attr_reader :rectangles
|
28
|
-
|
29
|
-
def initialize
|
30
|
-
@rectangles = []
|
31
|
-
end
|
32
|
-
|
33
|
-
def append_rectangle(*params)
|
34
|
-
@rectangles << { :point => params[0..1],
|
35
|
-
:width => params[2],
|
36
|
-
:height => params[3] }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class Curve < Inspector
|
41
|
-
|
42
|
-
attr_reader :coords
|
43
|
-
|
44
|
-
def initialize
|
45
|
-
@coords = []
|
46
|
-
end
|
47
|
-
|
48
|
-
def begin_new_subpath(*params)
|
49
|
-
@coords += params
|
50
|
-
end
|
51
|
-
|
52
|
-
def append_curved_segment(*params)
|
53
|
-
@coords += params
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
class Color < Inspector
|
59
|
-
attr_reader :stroke_color, :fill_color, :stroke_color_count,
|
60
|
-
:fill_color_count
|
61
|
-
|
62
|
-
def initialize
|
63
|
-
@stroke_color_count = 0
|
64
|
-
@fill_color_count = 0
|
65
|
-
end
|
66
|
-
|
67
|
-
def set_color_for_stroking_and_special(*params)
|
68
|
-
@stroke_color_count += 1
|
69
|
-
@stroke_color = params
|
70
|
-
end
|
71
|
-
|
72
|
-
def set_color_for_nonstroking_and_special(*params)
|
73
|
-
@fill_color_count += 1
|
74
|
-
@fill_color = params
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
class Dash < Inspector
|
79
|
-
attr_reader :stroke_dash, :stroke_dash_count
|
80
|
-
|
81
|
-
def initialize
|
82
|
-
@stroke_dash_count = 0
|
83
|
-
end
|
84
|
-
|
85
|
-
def set_line_dash(*params)
|
86
|
-
@stroke_dash_count += 1
|
87
|
-
@stroke_dash = params
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
class CapStyle < Inspector
|
92
|
-
attr_reader :cap_style, :cap_style_count
|
93
|
-
|
94
|
-
def initialize
|
95
|
-
@cap_style_count = 0
|
96
|
-
end
|
97
|
-
|
98
|
-
def set_line_cap_style(*params)
|
99
|
-
@cap_style_count += 1
|
100
|
-
@cap_style = params[0]
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
class JoinStyle < Inspector
|
105
|
-
attr_reader :join_style, :join_style_count
|
106
|
-
|
107
|
-
def initialize
|
108
|
-
@join_style_count = 0
|
109
|
-
end
|
110
|
-
|
111
|
-
def set_line_join_style(*params)
|
112
|
-
@join_style_count += 1
|
113
|
-
@join_style = params[0]
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
class Matrix < Inspector
|
118
|
-
attr_reader :matrices
|
119
|
-
|
120
|
-
def initialize
|
121
|
-
@matrices = []
|
122
|
-
end
|
123
|
-
|
124
|
-
def concatenate_matrix(*values)
|
125
|
-
@matrices << values
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|