prawn 0.15.0 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +2 -2
- data/LICENSE +1 -1
- data/README.md +96 -0
- data/Rakefile +27 -30
- 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.alpha +0 -0
- data/data/images/16bit.dat +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/page_white_text.alpha +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/data/pdfs/nested_pages.pdf +13 -13
- data/lib/prawn.rb +21 -85
- data/lib/prawn/compatibility.rb +51 -0
- data/lib/prawn/core.rb +85 -0
- data/lib/prawn/core/annotations.rb +61 -0
- data/lib/prawn/core/byte_string.rb +9 -0
- data/lib/prawn/core/destinations.rb +90 -0
- data/lib/prawn/core/document_state.rb +78 -0
- data/lib/prawn/core/literal_string.rb +16 -0
- data/lib/prawn/core/name_tree.rb +177 -0
- data/lib/prawn/core/object_store.rb +264 -0
- data/lib/prawn/core/page.rb +215 -0
- data/lib/prawn/core/pdf_object.rb +108 -0
- data/lib/prawn/core/reference.rb +115 -0
- data/lib/prawn/core/text.rb +268 -0
- data/lib/prawn/core/text/formatted/arranger.rb +294 -0
- data/lib/prawn/core/text/formatted/line_wrap.rb +273 -0
- data/lib/prawn/core/text/formatted/wrap.rb +153 -0
- data/lib/prawn/document.rb +122 -155
- data/lib/prawn/document/bounding_box.rb +7 -36
- data/lib/prawn/document/column_box.rb +10 -38
- data/lib/prawn/document/graphics_state.rb +74 -11
- data/lib/prawn/document/internals.rb +23 -24
- data/lib/prawn/document/page_geometry.rb +136 -0
- data/lib/prawn/document/snapshot.rb +6 -7
- data/lib/prawn/document/span.rb +10 -12
- data/lib/prawn/encoding.rb +10 -9
- data/lib/prawn/errors.rb +30 -15
- data/lib/prawn/font.rb +104 -136
- data/lib/prawn/font/afm.rb +44 -46
- data/lib/prawn/font/dfont.rb +3 -4
- data/lib/prawn/font/ttf.rb +50 -31
- data/lib/prawn/graphics.rb +57 -302
- data/lib/prawn/graphics/cap_style.rb +3 -4
- data/lib/prawn/graphics/color.rb +5 -13
- data/lib/prawn/graphics/dash.rb +31 -53
- data/lib/prawn/graphics/gradient.rb +84 -0
- data/lib/prawn/graphics/join_style.rb +7 -9
- data/lib/prawn/graphics/transformation.rb +9 -10
- data/lib/prawn/graphics/transparency.rb +1 -3
- data/lib/prawn/images.rb +59 -69
- data/lib/prawn/images/image.rb +22 -6
- data/lib/prawn/images/jpg.rb +14 -20
- data/lib/prawn/images/png.rb +118 -61
- data/lib/prawn/layout.rb +15 -10
- data/lib/prawn/layout/grid.rb +54 -66
- data/lib/prawn/measurement_extensions.rb +6 -10
- data/lib/prawn/measurements.rb +21 -27
- data/lib/prawn/outline.rb +308 -6
- data/lib/prawn/repeater.rb +8 -10
- data/lib/prawn/security.rb +33 -55
- data/lib/prawn/security/arcfour.rb +0 -1
- data/lib/prawn/stamp.rb +3 -5
- data/lib/prawn/table.rb +60 -188
- data/lib/prawn/table/cell.rb +44 -272
- data/lib/prawn/table/cell/image.rb +3 -2
- data/lib/prawn/table/cell/in_table.rb +2 -4
- data/lib/prawn/table/cell/subtable.rb +2 -2
- data/lib/prawn/table/cell/text.rb +18 -41
- data/lib/prawn/table/cells.rb +48 -142
- data/lib/prawn/text.rb +25 -32
- data/lib/prawn/text/box.rb +6 -12
- data/lib/prawn/text/formatted.rb +4 -5
- data/lib/prawn/text/formatted/box.rb +59 -96
- data/lib/prawn/text/formatted/fragment.rb +23 -34
- data/lib/prawn/text/formatted/parser.rb +5 -15
- data/prawn.gemspec +13 -24
- data/spec/annotations_spec.rb +32 -16
- data/spec/bounding_box_spec.rb +17 -119
- data/spec/cell_spec.rb +42 -112
- data/spec/destinations_spec.rb +5 -5
- data/spec/document_spec.rb +111 -155
- data/spec/extensions/mocha.rb +0 -1
- data/spec/font_spec.rb +99 -149
- data/spec/formatted_text_arranger_spec.rb +43 -43
- data/spec/formatted_text_box_spec.rb +44 -43
- data/spec/formatted_text_fragment_spec.rb +8 -8
- data/spec/graphics_spec.rb +68 -151
- data/spec/grid_spec.rb +15 -26
- data/spec/images_spec.rb +30 -51
- data/spec/inline_formatted_text_parser_spec.rb +20 -69
- data/spec/jpg_spec.rb +4 -4
- data/spec/line_wrap_spec.rb +28 -28
- data/spec/measurement_units_spec.rb +6 -6
- data/spec/name_tree_spec.rb +112 -0
- data/spec/object_store_spec.rb +106 -17
- data/spec/outline_spec.rb +63 -103
- data/spec/pdf_object_spec.rb +170 -0
- data/spec/png_spec.rb +25 -25
- data/spec/reference_spec.rb +65 -8
- data/spec/repeater_spec.rb +10 -10
- data/spec/security_spec.rb +12 -44
- data/spec/snapshot_spec.rb +7 -7
- data/spec/span_spec.rb +15 -10
- data/spec/spec_helper.rb +8 -32
- data/spec/stamp_spec.rb +30 -29
- data/spec/stroke_styles_spec.rb +18 -36
- data/spec/table_spec.rb +111 -706
- data/spec/template_spec.rb +297 -0
- data/spec/text_at_spec.rb +33 -19
- data/spec/text_box_spec.rb +64 -100
- data/spec/text_rendering_mode_spec.rb +5 -5
- data/spec/text_spacing_spec.rb +4 -4
- data/spec/text_spec.rb +64 -84
- data/spec/transparency_spec.rb +5 -5
- metadata +290 -463
- checksums.yaml +0 -7
- data/.yardopts +0 -10
- data/Gemfile +0 -11
- data/data/images/16bit.color +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/page_white_text.color +0 -0
- data/lib/prawn/font_metric_cache.rb +0 -47
- data/lib/prawn/graphics/patterns.rb +0 -138
- data/lib/prawn/image_handler.rb +0 -36
- data/lib/prawn/soft_mask.rb +0 -96
- data/lib/prawn/table/cell/span_dummy.rb +0 -93
- data/lib/prawn/table/column_width_calculator.rb +0 -61
- data/lib/prawn/text/formatted/arranger.rb +0 -290
- data/lib/prawn/text/formatted/line_wrap.rb +0 -266
- data/lib/prawn/text/formatted/wrap.rb +0 -150
- data/lib/prawn/utilities.rb +0 -46
- data/manual/basic_concepts/adding_pages.rb +0 -27
- data/manual/basic_concepts/basic_concepts.rb +0 -34
- data/manual/basic_concepts/creation.rb +0 -39
- data/manual/basic_concepts/cursor.rb +0 -33
- data/manual/basic_concepts/measurement.rb +0 -25
- data/manual/basic_concepts/origin.rb +0 -38
- data/manual/basic_concepts/other_cursor_helpers.rb +0 -40
- data/manual/bounding_box/bounding_box.rb +0 -39
- data/manual/bounding_box/bounds.rb +0 -49
- data/manual/bounding_box/canvas.rb +0 -24
- data/manual/bounding_box/creation.rb +0 -23
- data/manual/bounding_box/indentation.rb +0 -46
- data/manual/bounding_box/nesting.rb +0 -45
- data/manual/bounding_box/russian_boxes.rb +0 -40
- data/manual/bounding_box/stretchy.rb +0 -31
- data/manual/document_and_page_options/background.rb +0 -27
- data/manual/document_and_page_options/document_and_page_options.rb +0 -32
- data/manual/document_and_page_options/metadata.rb +0 -23
- data/manual/document_and_page_options/page_margins.rb +0 -38
- data/manual/document_and_page_options/page_size.rb +0 -34
- data/manual/document_and_page_options/print_scaling.rb +0 -20
- data/manual/example_file.rb +0 -111
- data/manual/example_helper.rb +0 -411
- data/manual/example_package.rb +0 -53
- data/manual/example_section.rb +0 -46
- data/manual/graphics/circle_and_ellipse.rb +0 -22
- data/manual/graphics/color.rb +0 -24
- data/manual/graphics/common_lines.rb +0 -30
- data/manual/graphics/fill_and_stroke.rb +0 -42
- data/manual/graphics/fill_rules.rb +0 -37
- data/manual/graphics/gradients.rb +0 -37
- data/manual/graphics/graphics.rb +0 -58
- data/manual/graphics/helper.rb +0 -24
- data/manual/graphics/line_width.rb +0 -35
- data/manual/graphics/lines_and_curves.rb +0 -41
- data/manual/graphics/polygon.rb +0 -29
- data/manual/graphics/rectangle.rb +0 -21
- data/manual/graphics/rotate.rb +0 -28
- data/manual/graphics/scale.rb +0 -41
- data/manual/graphics/soft_masks.rb +0 -46
- data/manual/graphics/stroke_cap.rb +0 -31
- data/manual/graphics/stroke_dash.rb +0 -48
- data/manual/graphics/stroke_join.rb +0 -30
- data/manual/graphics/translate.rb +0 -29
- data/manual/graphics/transparency.rb +0 -35
- data/manual/images/absolute_position.rb +0 -23
- data/manual/images/fit.rb +0 -21
- data/manual/images/horizontal.rb +0 -25
- data/manual/images/images.rb +0 -40
- data/manual/images/plain_image.rb +0 -18
- data/manual/images/scale.rb +0 -22
- data/manual/images/vertical.rb +0 -28
- data/manual/images/width_and_height.rb +0 -25
- data/manual/layout/boxes.rb +0 -27
- data/manual/layout/content.rb +0 -25
- data/manual/layout/layout.rb +0 -28
- data/manual/layout/simple_grid.rb +0 -23
- data/manual/manual/cover.rb +0 -36
- data/manual/manual/foreword.rb +0 -85
- data/manual/manual/how_to_read_this_manual.rb +0 -41
- data/manual/manual/manual.rb +0 -34
- data/manual/outline/add_subsection_to.rb +0 -61
- data/manual/outline/insert_section_after.rb +0 -47
- data/manual/outline/outline.rb +0 -32
- data/manual/outline/sections_and_pages.rb +0 -67
- data/manual/repeatable_content/page_numbering.rb +0 -54
- data/manual/repeatable_content/repeatable_content.rb +0 -31
- data/manual/repeatable_content/repeater.rb +0 -55
- data/manual/repeatable_content/stamp.rb +0 -41
- data/manual/security/encryption.rb +0 -31
- data/manual/security/permissions.rb +0 -38
- data/manual/security/security.rb +0 -28
- data/manual/syntax_highlight.rb +0 -52
- data/manual/table/basic_block.rb +0 -53
- data/manual/table/before_rendering_page.rb +0 -26
- data/manual/table/cell_border_lines.rb +0 -24
- data/manual/table/cell_borders_and_bg.rb +0 -31
- data/manual/table/cell_dimensions.rb +0 -30
- data/manual/table/cell_text.rb +0 -38
- data/manual/table/column_widths.rb +0 -30
- data/manual/table/content_and_subtables.rb +0 -39
- data/manual/table/creation.rb +0 -27
- data/manual/table/filtering.rb +0 -36
- data/manual/table/flow_and_header.rb +0 -17
- data/manual/table/image_cells.rb +0 -33
- data/manual/table/position.rb +0 -29
- data/manual/table/row_colors.rb +0 -20
- data/manual/table/span.rb +0 -30
- data/manual/table/style.rb +0 -22
- data/manual/table/table.rb +0 -52
- data/manual/table/width.rb +0 -27
- data/manual/text/alignment.rb +0 -44
- data/manual/text/color.rb +0 -24
- data/manual/text/column_box.rb +0 -32
- data/manual/text/fallback_fonts.rb +0 -37
- data/manual/text/font.rb +0 -41
- data/manual/text/font_size.rb +0 -45
- data/manual/text/font_style.rb +0 -23
- data/manual/text/formatted_callbacks.rb +0 -60
- data/manual/text/formatted_text.rb +0 -54
- data/manual/text/free_flowing_text.rb +0 -51
- data/manual/text/group.rb +0 -31
- data/manual/text/inline.rb +0 -43
- data/manual/text/kerning_and_character_spacing.rb +0 -39
- data/manual/text/leading.rb +0 -25
- data/manual/text/line_wrapping.rb +0 -41
- data/manual/text/paragraph_indentation.rb +0 -26
- data/manual/text/positioned_text.rb +0 -38
- data/manual/text/registering_families.rb +0 -48
- data/manual/text/rendering_and_color.rb +0 -37
- data/manual/text/right_to_left_text.rb +0 -43
- data/manual/text/rotation.rb +0 -43
- data/manual/text/single_usage.rb +0 -37
- data/manual/text/text.rb +0 -75
- data/manual/text/text_box_excess.rb +0 -32
- data/manual/text/text_box_extensions.rb +0 -45
- data/manual/text/text_box_overflow.rb +0 -44
- data/manual/text/utf8.rb +0 -28
- data/manual/text/win_ansi_charset.rb +0 -59
- data/spec/acceptance/png.rb +0 -23
- data/spec/column_box_spec.rb +0 -65
- data/spec/extensions/encoding_helpers.rb +0 -9
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/image_handler_spec.rb +0 -54
- data/spec/soft_mask_spec.rb +0 -117
- data/spec/table/span_dummy_spec.rb +0 -17
@@ -10,27 +10,39 @@ module Prawn
|
|
10
10
|
module Text
|
11
11
|
module Formatted
|
12
12
|
|
13
|
-
|
14
13
|
# Prawn::Text::Formatted::Fragment is a state store for a formatted text
|
15
14
|
# fragment. It does not render anything.
|
16
15
|
#
|
17
|
-
# @private
|
18
16
|
class Fragment
|
19
17
|
|
20
|
-
attr_reader :format_state
|
18
|
+
attr_reader :format_state
|
21
19
|
attr_writer :width
|
22
20
|
attr_accessor :line_height, :descender, :ascender
|
23
21
|
attr_accessor :word_spacing, :left, :baseline
|
24
22
|
|
25
23
|
def initialize(text, format_state, document)
|
24
|
+
@text = text
|
26
25
|
@format_state = format_state
|
27
26
|
@document = document
|
28
27
|
@word_spacing = 0
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
def text
|
31
|
+
string = strip_zero_width_spaces(@text)
|
32
|
+
if exclude_trailing_white_space?
|
33
|
+
string = string.rstrip
|
34
|
+
string = process_soft_hyphens(string)
|
35
|
+
end
|
36
|
+
case direction
|
37
|
+
when :rtl
|
38
|
+
if ruby_18 { true }
|
39
|
+
string.scan(/./mu).reverse.join
|
40
|
+
else
|
41
|
+
string.reverse
|
42
|
+
end
|
43
|
+
else
|
44
|
+
string
|
45
|
+
end
|
34
46
|
end
|
35
47
|
|
36
48
|
def width
|
@@ -93,10 +105,6 @@ module Prawn
|
|
93
105
|
@format_state[:anchor]
|
94
106
|
end
|
95
107
|
|
96
|
-
def local
|
97
|
-
@format_state[:local]
|
98
|
-
end
|
99
|
-
|
100
108
|
def color
|
101
109
|
@format_state[:color]
|
102
110
|
end
|
@@ -119,19 +127,16 @@ module Prawn
|
|
119
127
|
end
|
120
128
|
|
121
129
|
def default_direction=(direction)
|
122
|
-
unless @format_state[:direction]
|
123
|
-
@format_state[:direction] = direction
|
124
|
-
@text = process_text(@original_text)
|
125
|
-
end
|
130
|
+
@format_state[:direction] = direction unless @format_state[:direction]
|
126
131
|
end
|
127
132
|
|
128
133
|
def include_trailing_white_space!
|
129
134
|
@format_state.delete(:exclude_trailing_white_space)
|
130
|
-
@text = process_text(@original_text)
|
131
135
|
end
|
132
136
|
|
133
137
|
def space_count
|
134
|
-
@text.
|
138
|
+
string = exclude_trailing_white_space? ? @text.rstrip : @text
|
139
|
+
string.count(" ")
|
135
140
|
end
|
136
141
|
|
137
142
|
def callback_objects
|
@@ -207,19 +212,6 @@ module Prawn
|
|
207
212
|
|
208
213
|
private
|
209
214
|
|
210
|
-
def process_text(text)
|
211
|
-
string = strip_zero_width_spaces(text)
|
212
|
-
if exclude_trailing_white_space?
|
213
|
-
string = process_soft_hyphens(string.rstrip)
|
214
|
-
end
|
215
|
-
case direction
|
216
|
-
when :rtl
|
217
|
-
string.reverse
|
218
|
-
else
|
219
|
-
string
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
215
|
def exclude_trailing_white_space?
|
224
216
|
@format_state[:exclude_trailing_white_space]
|
225
217
|
end
|
@@ -230,9 +222,6 @@ module Prawn
|
|
230
222
|
|
231
223
|
def process_soft_hyphens(string)
|
232
224
|
if string.length > 0 && normalized_soft_hyphen
|
233
|
-
if string.encoding != normalized_soft_hyphen.encoding
|
234
|
-
string.force_encoding(normalized_soft_hyphen.encoding)
|
235
|
-
end
|
236
225
|
string[0..-2].gsub(normalized_soft_hyphen, "") + string[-1..-1]
|
237
226
|
else
|
238
227
|
string
|
@@ -240,7 +229,7 @@ module Prawn
|
|
240
229
|
end
|
241
230
|
|
242
231
|
def strip_zero_width_spaces(string)
|
243
|
-
if string.encoding ==
|
232
|
+
if !"".respond_to?(:encoding) || string.encoding.to_s == "UTF-8"
|
244
233
|
string.gsub(Prawn::Text::ZWSP, "")
|
245
234
|
else
|
246
235
|
string
|
@@ -13,9 +13,8 @@ module Prawn
|
|
13
13
|
module Formatted
|
14
14
|
|
15
15
|
class Parser
|
16
|
-
# @group Extension API
|
17
16
|
|
18
|
-
|
17
|
+
def self.to_array(string)
|
19
18
|
regex_string = "\n|" +
|
20
19
|
"<b>|</b>|" +
|
21
20
|
"<i>|</i>|" +
|
@@ -30,11 +29,8 @@ module Prawn
|
|
30
29
|
"<em>|</em>|" +
|
31
30
|
"<a[^>]*>|</a>|" +
|
32
31
|
"[^<\n]+"
|
33
|
-
Regexp.new(regex_string, Regexp::MULTILINE)
|
34
|
-
|
35
|
-
|
36
|
-
def self.format(string, *args)
|
37
|
-
tokens = string.gsub(/<br\s*\/?>/, "\n").scan(PARSER_REGEX)
|
32
|
+
regex = Regexp.new(regex_string, Regexp::MULTILINE)
|
33
|
+
tokens = string.gsub(/<br\s*\/?>/, "\n").scan(regex)
|
38
34
|
self.array_from_tokens(tokens)
|
39
35
|
end
|
40
36
|
|
@@ -126,11 +122,10 @@ module Prawn
|
|
126
122
|
colors = []
|
127
123
|
link = nil
|
128
124
|
anchor = nil
|
129
|
-
local = nil
|
130
125
|
fonts = []
|
131
126
|
sizes = []
|
132
127
|
character_spacings = []
|
133
|
-
|
128
|
+
|
134
129
|
while token = tokens.shift
|
135
130
|
case token
|
136
131
|
when "<b>", "<strong>"
|
@@ -160,7 +155,6 @@ module Prawn
|
|
160
155
|
when "</link>", "</a>"
|
161
156
|
link = nil
|
162
157
|
anchor = nil
|
163
|
-
local = nil
|
164
158
|
when "</color>"
|
165
159
|
colors.pop
|
166
160
|
when "</font>"
|
@@ -174,9 +168,6 @@ module Prawn
|
|
174
168
|
|
175
169
|
matches = /anchor="([^"]*)"/.match(token) || /anchor='([^']*)'/.match(token)
|
176
170
|
anchor = matches[1] unless matches.nil?
|
177
|
-
|
178
|
-
matches = /local="([^"]*)"/.match(token) || /local='([^']*)'/.match(token)
|
179
|
-
local = matches[1] unless matches.nil?
|
180
171
|
elsif token =~ /^<color[^>]*>$/
|
181
172
|
matches = /rgb="#?([^"]*)"/.match(token) || /rgb='#?([^']*)'/.match(token)
|
182
173
|
colors << matches[1] if matches
|
@@ -188,7 +179,7 @@ module Prawn
|
|
188
179
|
# intend to support rgb="#ffffff" or rgb='#ffffff',
|
189
180
|
# r="255" g="255" b="255" or r='255' g='255' b='255',
|
190
181
|
# and c="100" m="100" y="100" k="100" or
|
191
|
-
# c='100' m='100' y='100' k='100'
|
182
|
+
# c='100' m='100' y='100' k='100'
|
192
183
|
# color = { :rgb => "#ffffff" }
|
193
184
|
# color = { :r => 255, :g => 255, :b => 255 }
|
194
185
|
# color = { :c => 100, :m => 100, :y => 100, :k => 100 }
|
@@ -206,7 +197,6 @@ module Prawn
|
|
206
197
|
array << { :text => string,
|
207
198
|
:styles => styles.dup,
|
208
199
|
:color => colors.last,
|
209
|
-
:local => local,
|
210
200
|
:link => link,
|
211
201
|
:anchor => anchor,
|
212
202
|
:font => fonts.last,
|
data/prawn.gemspec
CHANGED
@@ -1,37 +1,26 @@
|
|
1
|
+
PRAWN_VERSION = "1.0.0.rc1"
|
2
|
+
|
1
3
|
Gem::Specification.new do |spec|
|
2
4
|
spec.name = "prawn"
|
3
|
-
spec.version =
|
5
|
+
spec.version = PRAWN_VERSION
|
4
6
|
spec.platform = Gem::Platform::RUBY
|
5
7
|
spec.summary = "A fast and nimble PDF generator for Ruby"
|
6
|
-
spec.files = Dir.glob("{examples,lib,spec,
|
7
|
-
|
8
|
-
Dir.glob("data/fonts/{MustRead.html,*.afm}") +
|
9
|
-
["data/shift_jis_text.txt"] +
|
10
|
-
["Rakefile", "prawn.gemspec", "Gemfile",
|
11
|
-
"COPYING", "LICENSE", "GPLv2", "GPLv3",
|
12
|
-
".yardopts"]
|
8
|
+
spec.files = Dir.glob("{examples,lib,spec,data}/**/**/*") +
|
9
|
+
["Rakefile", "prawn.gemspec", "COPYING", "LICENSE", "GPLv2", "GPLv3"]
|
13
10
|
spec.require_path = "lib"
|
14
|
-
spec.required_ruby_version = '>= 1.
|
11
|
+
spec.required_ruby_version = '>= 1.8.7'
|
15
12
|
spec.required_rubygems_version = ">= 1.3.6"
|
16
13
|
|
17
14
|
spec.test_files = Dir[ "spec/*_spec.rb" ]
|
15
|
+
spec.extra_rdoc_files = %w{README.md LICENSE COPYING GPLv2 GPLv3}
|
16
|
+
spec.rdoc_options << '--title' << 'Prawn Documentation' <<
|
17
|
+
'--main' << 'README.md' << '-q'
|
18
18
|
spec.authors = ["Gregory Brown","Brad Ediger","Daniel Nelson","Jonathan Greenberg","James Healy"]
|
19
19
|
spec.email = ["gregory.t.brown@gmail.com","brad@bradediger.com","dnelson@bluejade.com","greenberg@entryway.net","jimmy@deefa.com"]
|
20
20
|
spec.rubyforge_project = "prawn"
|
21
|
-
spec.
|
22
|
-
|
23
|
-
spec.
|
24
|
-
spec.add_dependency('pdf-core', "~> 0.1.3")
|
25
|
-
|
26
|
-
spec.add_development_dependency('pdf-inspector', '~> 1.1.0')
|
27
|
-
spec.add_development_dependency('coderay', '~> 1.0.7')
|
28
|
-
spec.add_development_dependency('yard')
|
29
|
-
spec.add_development_dependency('rspec')
|
30
|
-
spec.add_development_dependency('mocha')
|
31
|
-
spec.add_development_dependency('rake')
|
32
|
-
spec.add_development_dependency('simplecov')
|
33
|
-
spec.add_development_dependency('pdf-reader', '~>1.2')
|
34
|
-
|
21
|
+
spec.add_dependency('pdf-reader', '>=0.9.0')
|
22
|
+
spec.add_dependency('ttfunk', '~>1.0.3')
|
23
|
+
spec.add_development_dependency('pdf-inspector', '~> 1.0.1')
|
35
24
|
spec.homepage = "http://prawn.majesticseacreature.com"
|
36
25
|
spec.description = <<END_DESC
|
37
26
|
Prawn is a fast, tiny, and nimble PDF generator for Ruby
|
@@ -45,7 +34,7 @@ END_DESC
|
|
45
34
|
|
46
35
|
Please read the changelog for details:
|
47
36
|
|
48
|
-
https://github.com/
|
37
|
+
https://github.com/sandal/prawn/wiki/CHANGELOG
|
49
38
|
|
50
39
|
|
51
40
|
********************************************
|
data/spec/annotations_spec.rb
CHANGED
@@ -1,19 +1,35 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
class PageAnnotations
|
6
|
+
attr_reader :pages
|
7
|
+
|
8
|
+
def self.parse(document)
|
9
|
+
receiver = new
|
10
|
+
PDF::Reader.string(document.render, receiver)
|
11
|
+
return receiver
|
12
|
+
end
|
4
13
|
|
14
|
+
def initialize
|
15
|
+
@pages = []
|
16
|
+
end
|
5
17
|
|
6
|
-
|
18
|
+
def begin_page(params)
|
19
|
+
@pages << params
|
20
|
+
end
|
21
|
+
end
|
7
22
|
|
23
|
+
describe "When creating annotations" do
|
24
|
+
|
8
25
|
before(:each) { create_pdf }
|
9
|
-
|
10
|
-
it "should append annotation to current page" do
|
26
|
+
|
27
|
+
it "should append annotation to current page" do
|
11
28
|
@pdf.start_new_page
|
12
29
|
@pdf.annotate(:Rect => [0,0,10,10], :Subtype => :Text, :Contents => "Hello world!")
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
30
|
+
obj = PageAnnotations.parse(@pdf)
|
31
|
+
obj.pages[0][:Annots].nil?.should == true
|
32
|
+
obj.pages[1][:Annots].length.should == 1
|
17
33
|
end
|
18
34
|
|
19
35
|
it "should force :Type to be :Annot" do
|
@@ -26,14 +42,14 @@ describe "When creating annotations" do
|
|
26
42
|
end
|
27
43
|
|
28
44
|
describe "When creating text annotations" do
|
29
|
-
|
45
|
+
|
30
46
|
before(:each) do
|
31
47
|
@rect = [0,0,10,10]
|
32
48
|
@content = "Hello, world!"
|
33
49
|
create_pdf
|
34
50
|
end
|
35
|
-
|
36
|
-
it "should build appropriate annotation" do
|
51
|
+
|
52
|
+
it "should build appropriate annotation" do
|
37
53
|
opts = @pdf.text_annotation(@rect, @content)
|
38
54
|
opts[:Type].should == :Annot
|
39
55
|
opts[:Subtype].should == :Text
|
@@ -41,7 +57,7 @@ describe "When creating text annotations" do
|
|
41
57
|
opts[:Contents].should == @content
|
42
58
|
end
|
43
59
|
|
44
|
-
it "should merge extra options" do
|
60
|
+
it "should merge extra options" do
|
45
61
|
opts = @pdf.text_annotation(@rect, @content, :Open => true, :Subtype => :Bogus)
|
46
62
|
opts[:Subtype].should == :Text
|
47
63
|
opts[:Open].should == true
|
@@ -50,14 +66,14 @@ describe "When creating text annotations" do
|
|
50
66
|
end
|
51
67
|
|
52
68
|
describe "When creating link annotations" do
|
53
|
-
|
69
|
+
|
54
70
|
before(:each) do
|
55
71
|
@rect = [0,0,10,10]
|
56
72
|
@dest = "home"
|
57
73
|
create_pdf
|
58
74
|
end
|
59
|
-
|
60
|
-
it "should build appropriate annotation" do
|
75
|
+
|
76
|
+
it "should build appropriate annotation" do
|
61
77
|
opts = @pdf.link_annotation(@rect, :Dest => @dest)
|
62
78
|
opts[:Type].should == :Annot
|
63
79
|
opts[:Subtype].should == :Link
|
@@ -65,7 +81,7 @@ describe "When creating link annotations" do
|
|
65
81
|
opts[:Dest].should == @dest
|
66
82
|
end
|
67
83
|
|
68
|
-
it "should merge extra options" do
|
84
|
+
it "should merge extra options" do
|
69
85
|
opts = @pdf.link_annotation(@rect, :Dest => @dest, :Subtype => :Bogus)
|
70
86
|
opts[:Subtype].should == :Link
|
71
87
|
opts[:Dest].should == @dest
|
data/spec/bounding_box_spec.rb
CHANGED
@@ -84,14 +84,14 @@ describe "A bounding box" do
|
|
84
84
|
it "should require width to be set" do
|
85
85
|
lambda do
|
86
86
|
Prawn::Document::BoundingBox.new(nil, nil, [100,100])
|
87
|
-
end.should
|
87
|
+
end.should.raise(ArgumentError)
|
88
88
|
end
|
89
89
|
|
90
|
-
it "should
|
90
|
+
it "should raise an ArgumentError if a block is not passed" do
|
91
91
|
pdf = Prawn::Document.new
|
92
92
|
lambda do
|
93
93
|
pdf.bounding_box([0, 0], :width => 200)
|
94
|
-
end.should
|
94
|
+
end.should.raise(ArgumentError)
|
95
95
|
end
|
96
96
|
|
97
97
|
end
|
@@ -100,15 +100,6 @@ describe "drawing bounding boxes" do
|
|
100
100
|
|
101
101
|
before(:each) { create_pdf }
|
102
102
|
|
103
|
-
it "should not stomp on the arguments to bounding_box" do
|
104
|
-
pdf = Prawn::Document.new
|
105
|
-
x = [100, 500]
|
106
|
-
pdf.bounding_box x, :width => 100 do
|
107
|
-
pdf.text "bork-bork-bork"
|
108
|
-
end
|
109
|
-
x.should == [100, 500]
|
110
|
-
end
|
111
|
-
|
112
103
|
it "should restore the margin box when bounding box exits" do
|
113
104
|
margin_box = @pdf.bounds
|
114
105
|
|
@@ -144,7 +135,7 @@ describe "drawing bounding boxes" do
|
|
144
135
|
@pdf.text "The rain in Spain falls mainly on the plains."
|
145
136
|
end
|
146
137
|
|
147
|
-
@pdf.y.should
|
138
|
+
@pdf.y.should.be.close 458.384, 0.001
|
148
139
|
end
|
149
140
|
|
150
141
|
it "should keep track of the max height the box was stretched to" do
|
@@ -162,7 +153,7 @@ describe "drawing bounding boxes" do
|
|
162
153
|
:height => 30 do
|
163
154
|
@pdf.text "hello"
|
164
155
|
end
|
165
|
-
@pdf.y.should
|
156
|
+
@pdf.y.should.be.close(orig_y - 30, 0.001)
|
166
157
|
end
|
167
158
|
|
168
159
|
it "should not advance y-position if passed :hold_position => true" do
|
@@ -172,7 +163,7 @@ describe "drawing bounding boxes" do
|
|
172
163
|
@pdf.text "hello"
|
173
164
|
end
|
174
165
|
# y only advances by height of one line ("hello")
|
175
|
-
@pdf.y.should
|
166
|
+
@pdf.y.should.be.close(orig_y - @pdf.height_of("hello"), 0.001)
|
176
167
|
end
|
177
168
|
|
178
169
|
it "should not advance y-position of a stretchy bbox if it would stretch " +
|
@@ -188,8 +179,9 @@ describe "drawing bounding boxes" do
|
|
188
179
|
# the bottom of the page, which we don't want. This should be equivalent to
|
189
180
|
# a bbox with :hold_position => true, where we only advance by the amount
|
190
181
|
# that was actually drawn.
|
191
|
-
@pdf.y.should
|
192
|
-
@pdf.margin_box.absolute_top - @pdf.height_of("hello")
|
182
|
+
@pdf.y.should.be.close(
|
183
|
+
@pdf.margin_box.absolute_top - @pdf.height_of("hello"),
|
184
|
+
0.001
|
193
185
|
)
|
194
186
|
end
|
195
187
|
|
@@ -269,7 +261,7 @@ describe "Indentation" do
|
|
269
261
|
:height => 200, :columns => 2, :spacer => 20) do
|
270
262
|
width = @pdf.bounds.width
|
271
263
|
@pdf.indent(20) do
|
272
|
-
@pdf.bounds.width.should
|
264
|
+
@pdf.bounds.width.should.be.close(width - 20, 0.01)
|
273
265
|
end
|
274
266
|
end
|
275
267
|
end
|
@@ -279,93 +271,11 @@ describe "Indentation" do
|
|
279
271
|
:height => 200, :columns => 2, :spacer => 20) do
|
280
272
|
width = @pdf.bounds.width
|
281
273
|
@pdf.indent(20, 30) do
|
282
|
-
@pdf.bounds.width.should
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
it "should maintain the same left indentation across column breaks" do
|
288
|
-
@pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
|
289
|
-
3.times do |column|
|
290
|
-
x = @pdf.bounds.left_side
|
291
|
-
@pdf.indent(20) do
|
292
|
-
@pdf.bounds.left_side.should == x+20
|
293
|
-
end
|
294
|
-
@pdf.bounds.move_past_bottom
|
295
|
-
end
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
it "should not change the right margin if only left indentation is requested" do
|
300
|
-
@pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
|
301
|
-
3.times do |column|
|
302
|
-
x = @pdf.bounds.right_side
|
303
|
-
@pdf.indent(20) do
|
304
|
-
@pdf.bounds.right_side.should == x
|
305
|
-
end
|
306
|
-
@pdf.bounds.move_past_bottom
|
307
|
-
end
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
it "should maintain the same right indentation across columns" do
|
312
|
-
@pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
|
313
|
-
3.times do |column|
|
314
|
-
x = @pdf.bounds.right_side
|
315
|
-
@pdf.indent(20, 10) do
|
316
|
-
@pdf.bounds.right_side.should == x-10
|
317
|
-
end
|
318
|
-
@pdf.bounds.move_past_bottom
|
319
|
-
end
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
it "should keep the right indentation after nesting indents" do
|
324
|
-
@pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
|
325
|
-
3.times do |column|
|
326
|
-
# I am giving a right indent of 10...
|
327
|
-
@pdf.indent(20, 10) do
|
328
|
-
x = @pdf.bounds.right_side
|
329
|
-
# ...and no right indent here...
|
330
|
-
@pdf.indent(20) do
|
331
|
-
# right indent is inherited from the parent!
|
332
|
-
@pdf.bounds.right_side.should == x
|
333
|
-
end
|
334
|
-
end
|
335
|
-
@pdf.bounds.move_past_bottom
|
274
|
+
@pdf.bounds.width.should.be.close(width - 50, 0.01)
|
336
275
|
end
|
337
276
|
end
|
338
277
|
end
|
339
278
|
|
340
|
-
it "should revert the right indentation if negative indent is given in nested indent" do
|
341
|
-
@pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
|
342
|
-
3.times do |column|
|
343
|
-
x = @pdf.bounds.right_side
|
344
|
-
@pdf.indent(20, 10) do
|
345
|
-
# requesting a negative right-indent of equivalent size...
|
346
|
-
@pdf.indent(20, -10) do
|
347
|
-
# ...resets the right margin to that of the column!
|
348
|
-
@pdf.bounds.right_side.should == x
|
349
|
-
end
|
350
|
-
end
|
351
|
-
@pdf.bounds.move_past_bottom
|
352
|
-
end
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
it "should reduce the available column width by the sum of all nested indents" do
|
357
|
-
@pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
|
358
|
-
3.times do |column|
|
359
|
-
w = @pdf.bounds.width
|
360
|
-
@pdf.indent(20, 10) do
|
361
|
-
@pdf.indent(20, 10) do
|
362
|
-
@pdf.bounds.width.should == w - 60
|
363
|
-
end
|
364
|
-
end
|
365
|
-
@pdf.bounds.move_past_bottom
|
366
|
-
end
|
367
|
-
end
|
368
|
-
end
|
369
279
|
end
|
370
280
|
end
|
371
281
|
|
@@ -378,28 +288,16 @@ describe "A canvas" do
|
|
378
288
|
end
|
379
289
|
@pdf.y.should == 450
|
380
290
|
end
|
381
|
-
|
382
|
-
it "should restore the original ypos after execution", :issue => 523 do
|
383
|
-
doc = Prawn::Document.new(:skip_page_creation => true)
|
384
|
-
doc.start_new_page
|
385
|
-
|
386
|
-
original_ypos = doc.y
|
387
|
-
|
388
|
-
doc.canvas {}
|
389
|
-
|
390
|
-
doc.y.should == original_ypos
|
391
|
-
end
|
392
|
-
|
393
291
|
end
|
394
292
|
|
395
293
|
describe "Deep-copying" do
|
396
294
|
it "should create a new object that does not copy @document" do
|
397
|
-
Prawn::Document.new do
|
398
|
-
orig =
|
295
|
+
Prawn::Document.new do
|
296
|
+
orig = bounds
|
399
297
|
copy = orig.deep_copy
|
400
298
|
|
401
|
-
copy.
|
402
|
-
copy.document.should
|
299
|
+
copy.should.not == bounds
|
300
|
+
copy.document.should.be.nil
|
403
301
|
end
|
404
302
|
end
|
405
303
|
|
@@ -414,7 +312,7 @@ describe "Deep-copying" do
|
|
414
312
|
copy.parent.height.should == outside.height
|
415
313
|
|
416
314
|
# but should not be the same object
|
417
|
-
copy.parent.
|
315
|
+
copy.parent.should.not == outside
|
418
316
|
end
|
419
317
|
end
|
420
318
|
end
|
@@ -494,7 +392,7 @@ describe "BoundingBox#move_past_bottom" do
|
|
494
392
|
@pdf.text "Foo"
|
495
393
|
|
496
394
|
@pdf.bounds.move_past_bottom
|
497
|
-
@pdf.y.should
|
395
|
+
@pdf.y.should.be.close(top_y, 0.001) # we should be at the top
|
498
396
|
@pdf.text "Bar"
|
499
397
|
|
500
398
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|