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
@@ -8,7 +8,6 @@
|
|
8
8
|
|
9
9
|
module Prawn
|
10
10
|
class Document
|
11
|
-
# @group Stable API
|
12
11
|
|
13
12
|
# :call-seq:
|
14
13
|
# bounding_box(point, options={}, &block)
|
@@ -155,10 +154,10 @@ module Prawn
|
|
155
154
|
# Of course, if you use canvas, you will be responsible for ensuring that
|
156
155
|
# you remain within the printable area of your document.
|
157
156
|
#
|
158
|
-
def bounding_box(
|
157
|
+
def bounding_box(*args, &block)
|
159
158
|
init_bounding_box(block) do |parent_box|
|
160
|
-
|
161
|
-
@bounding_box = BoundingBox.new(self, parent_box,
|
159
|
+
map_to_absolute!(args[0])
|
160
|
+
@bounding_box = BoundingBox.new(self, parent_box, *args)
|
162
161
|
end
|
163
162
|
end
|
164
163
|
|
@@ -189,21 +188,10 @@ module Prawn
|
|
189
188
|
|
190
189
|
parent_box = @bounding_box
|
191
190
|
|
192
|
-
original_ypos = y
|
193
|
-
|
194
191
|
init_block.call(parent_box)
|
195
192
|
|
196
193
|
self.y = @bounding_box.absolute_top
|
197
194
|
user_block.call
|
198
|
-
|
199
|
-
# If the user actions did not modify the y position
|
200
|
-
# restore the original y position before the bounding
|
201
|
-
# box was created.
|
202
|
-
|
203
|
-
if y == @bounding_box.absolute_top
|
204
|
-
self.y = original_ypos
|
205
|
-
end
|
206
|
-
|
207
195
|
unless options[:hold_position] || @bounding_box.stretchy?
|
208
196
|
self.y = @bounding_box.absolute_bottom
|
209
197
|
end
|
@@ -220,7 +208,7 @@ module Prawn
|
|
220
208
|
#
|
221
209
|
class BoundingBox
|
222
210
|
|
223
|
-
def initialize(document, parent, point, options={})
|
211
|
+
def initialize(document, parent, point, options={}) #:nodoc:
|
224
212
|
unless options[:width]
|
225
213
|
raise ArgumentError, "BoundingBox needs the :width option to be set"
|
226
214
|
end
|
@@ -234,22 +222,15 @@ module Prawn
|
|
234
222
|
@stretched_height = nil
|
235
223
|
end
|
236
224
|
|
237
|
-
# @private
|
238
|
-
|
239
225
|
attr_reader :document, :parent
|
240
|
-
|
241
|
-
# @private
|
242
226
|
# The current indentation of the left side of the bounding box.
|
243
227
|
attr_reader :total_left_padding
|
244
|
-
|
245
|
-
# @private
|
246
228
|
# The current indentation of the right side of the bounding box.
|
247
229
|
attr_reader :total_right_padding
|
248
230
|
|
249
231
|
# The translated origin (x,y-height) which describes the location
|
250
232
|
# of the bottom left corner of the bounding box
|
251
233
|
#
|
252
|
-
# @private
|
253
234
|
def anchor
|
254
235
|
[@x, @y - height]
|
255
236
|
end
|
@@ -280,7 +261,6 @@ module Prawn
|
|
280
261
|
# text "indented on both sides"
|
281
262
|
# end
|
282
263
|
#
|
283
|
-
# @private
|
284
264
|
def indent(left_padding, right_padding = 0, &block)
|
285
265
|
add_left_padding(left_padding)
|
286
266
|
add_right_padding(right_padding)
|
@@ -291,7 +271,6 @@ module Prawn
|
|
291
271
|
end
|
292
272
|
|
293
273
|
# Increase the left padding of the bounding box.
|
294
|
-
# @private
|
295
274
|
def add_left_padding(left_padding)
|
296
275
|
@total_left_padding += left_padding
|
297
276
|
@x += left_padding
|
@@ -299,7 +278,6 @@ module Prawn
|
|
299
278
|
end
|
300
279
|
|
301
280
|
# Decrease the left padding of the bounding box.
|
302
|
-
# @private
|
303
281
|
def subtract_left_padding(left_padding)
|
304
282
|
@total_left_padding -= left_padding
|
305
283
|
@x -= left_padding
|
@@ -307,14 +285,12 @@ module Prawn
|
|
307
285
|
end
|
308
286
|
|
309
287
|
# Increase the right padding of the bounding box.
|
310
|
-
# @private
|
311
288
|
def add_right_padding(right_padding)
|
312
289
|
@total_right_padding += right_padding
|
313
290
|
@width -= right_padding
|
314
291
|
end
|
315
292
|
|
316
293
|
# Decrease the right padding of the bounding box.
|
317
|
-
# @private
|
318
294
|
def subtract_right_padding(right_padding)
|
319
295
|
@total_right_padding -= right_padding
|
320
296
|
@width += right_padding
|
@@ -465,19 +441,15 @@ module Prawn
|
|
465
441
|
end
|
466
442
|
|
467
443
|
# an alias for absolute_left
|
468
|
-
# @private
|
469
444
|
def left_side
|
470
445
|
absolute_left
|
471
446
|
end
|
472
447
|
|
473
448
|
# an alias for absolute_right
|
474
|
-
# @private
|
475
449
|
def right_side
|
476
450
|
absolute_right
|
477
451
|
end
|
478
452
|
|
479
|
-
# @group Extension API
|
480
|
-
|
481
453
|
# Moves to the top of the next page of the document, starting a new page
|
482
454
|
# if necessary.
|
483
455
|
#
|
@@ -489,6 +461,9 @@ module Prawn
|
|
489
461
|
end
|
490
462
|
end
|
491
463
|
|
464
|
+
|
465
|
+
alias_method :update_height, :height
|
466
|
+
|
492
467
|
# Returns +false+ when the box has a defined height, +true+ when the height
|
493
468
|
# is being calculated on the fly based on the current vertical position.
|
494
469
|
#
|
@@ -507,12 +482,9 @@ module Prawn
|
|
507
482
|
end
|
508
483
|
end
|
509
484
|
|
510
|
-
alias_method :update_height, :height
|
511
|
-
|
512
485
|
# Returns a deep copy of these bounds (including all parent bounds but
|
513
486
|
# not copying the reference to the Document).
|
514
487
|
#
|
515
|
-
# @private
|
516
488
|
def deep_copy
|
517
489
|
copy = dup
|
518
490
|
# Deep-copy the parent bounds
|
@@ -527,7 +499,6 @@ module Prawn
|
|
527
499
|
# context of the given +document+. Does *not* set the bounds of the
|
528
500
|
# document to the resulting BoundingBox, only returns it.
|
529
501
|
#
|
530
|
-
# @private
|
531
502
|
def self.restore_deep_copy(bounds, document)
|
532
503
|
bounds.instance_variable_set("@document", document)
|
533
504
|
bounds
|
@@ -4,28 +4,22 @@
|
|
4
4
|
#
|
5
5
|
# Author Paul Ostazeski.
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
require "prawn/document/bounding_box"
|
9
8
|
module Prawn
|
10
9
|
class Document
|
11
10
|
|
12
|
-
# @group Experimental API
|
13
|
-
|
14
11
|
# A column box is a bounding box with the additional property that when
|
15
12
|
# text flows past the bottom, it will wrap first to another column on the
|
16
13
|
# same page, and only flow to the next page when all the columns are
|
17
14
|
# filled.
|
18
15
|
#
|
19
16
|
# column_box accepts the same parameters as bounding_box, as well as the
|
20
|
-
# number of :columns and a :spacer (in points) between columns.
|
21
|
-
# the top margin is desired on a new page (e.g. to allow for initial page
|
22
|
-
# wide column titles) the option :reflow_margins => true can be set.
|
17
|
+
# number of :columns and a :spacer (in points) between columns.
|
23
18
|
#
|
24
|
-
# Defaults are :columns = 3
|
25
|
-
# :reflow_margins => false
|
19
|
+
# Defaults are :columns = 3 and :spacer = font_size
|
26
20
|
#
|
27
21
|
# Under PDF::Writer, "spacer" was known as "gutter"
|
28
|
-
#
|
22
|
+
#
|
29
23
|
def column_box(*args, &block)
|
30
24
|
init_column_box(block) do |parent_box|
|
31
25
|
map_to_absolute!(args[0])
|
@@ -46,7 +40,7 @@ module Prawn
|
|
46
40
|
|
47
41
|
@bounding_box = parent_box
|
48
42
|
end
|
49
|
-
|
43
|
+
|
50
44
|
# Implements the necessary functionality to allow Document#column_box to
|
51
45
|
# work.
|
52
46
|
#
|
@@ -57,26 +51,19 @@ module Prawn
|
|
57
51
|
@columns = options[:columns] || 3
|
58
52
|
@spacer = options[:spacer] || @document.font_size
|
59
53
|
@current_column = 0
|
60
|
-
@reflow_margins = options[:reflow_margins]
|
61
|
-
end
|
62
|
-
|
63
|
-
# The column width, not the width of the whole box,
|
64
|
-
# before left and/or right padding
|
65
|
-
def bare_column_width
|
66
|
-
(@width - @spacer * (@columns - 1)) / @columns
|
67
54
|
end
|
68
55
|
|
69
|
-
# The column width
|
70
|
-
#
|
56
|
+
# The column width, not the width of the whole box. Used to calculate
|
57
|
+
# how long a line of text can be.
|
71
58
|
#
|
72
59
|
def width
|
73
|
-
|
60
|
+
super / @columns - @spacer - @total_left_padding - @total_right_padding
|
74
61
|
end
|
75
62
|
|
76
63
|
# Column width including the spacer.
|
77
64
|
#
|
78
65
|
def width_of_column
|
79
|
-
|
66
|
+
width + @spacer
|
80
67
|
end
|
81
68
|
|
82
69
|
# x coordinate of the left edge of the current column
|
@@ -85,12 +72,6 @@ module Prawn
|
|
85
72
|
absolute_left + (width_of_column * @current_column)
|
86
73
|
end
|
87
74
|
|
88
|
-
# Relative position of the left edge of the current column
|
89
|
-
#
|
90
|
-
def left
|
91
|
-
width_of_column * @current_column
|
92
|
-
end
|
93
|
-
|
94
75
|
# x co-orordinate of the right edge of the current column
|
95
76
|
#
|
96
77
|
def right_side
|
@@ -98,21 +79,12 @@ module Prawn
|
|
98
79
|
absolute_right - (width_of_column * columns_from_right)
|
99
80
|
end
|
100
81
|
|
101
|
-
# Relative position of the right edge of the current column.
|
102
|
-
#
|
103
|
-
def right
|
104
|
-
left + width
|
105
|
-
end
|
106
|
-
|
107
82
|
# Moves to the next column or starts a new page if currently positioned at
|
108
83
|
# the rightmost column.
|
109
|
-
def move_past_bottom
|
84
|
+
def move_past_bottom
|
110
85
|
@current_column = (@current_column + 1) % @columns
|
111
86
|
@document.y = @y
|
112
87
|
if 0 == @current_column
|
113
|
-
if @reflow_margins
|
114
|
-
@y = @parent.absolute_top
|
115
|
-
end
|
116
88
|
@document.start_new_page
|
117
89
|
end
|
118
90
|
end
|
@@ -8,8 +8,71 @@
|
|
8
8
|
#
|
9
9
|
|
10
10
|
module Prawn
|
11
|
+
class GraphicStateStack
|
12
|
+
attr_accessor :stack
|
13
|
+
|
14
|
+
def initialize(previous_state = nil)
|
15
|
+
self.stack = [GraphicState.new(previous_state)]
|
16
|
+
end
|
17
|
+
|
18
|
+
def save_graphic_state(graphic_state = nil)
|
19
|
+
stack.push(GraphicState.new(graphic_state || current_state))
|
20
|
+
end
|
21
|
+
|
22
|
+
def restore_graphic_state
|
23
|
+
if stack.empty?
|
24
|
+
raise Prawn::Errors::EmptyGraphicStateStack,
|
25
|
+
"\n You have reached the end of the graphic state stack"
|
26
|
+
end
|
27
|
+
stack.pop
|
28
|
+
end
|
29
|
+
|
30
|
+
def current_state
|
31
|
+
stack.last
|
32
|
+
end
|
33
|
+
|
34
|
+
def present?
|
35
|
+
stack.size > 0
|
36
|
+
end
|
37
|
+
|
38
|
+
def empty?
|
39
|
+
stack.empty?
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
class GraphicState
|
45
|
+
attr_accessor :color_space, :dash, :cap_style, :join_style, :line_width, :fill_color, :stroke_color
|
46
|
+
|
47
|
+
def initialize(previous_state = nil)
|
48
|
+
@color_space = previous_state ? previous_state.color_space.dup : {}
|
49
|
+
@fill_color = previous_state ? previous_state.fill_color : "000000"
|
50
|
+
@stroke_color = previous_state ? previous_state.stroke_color : "000000"
|
51
|
+
@dash = previous_state ? previous_state.dash : { :dash => nil, :space => nil, :phase => 0 }
|
52
|
+
@cap_style = previous_state ? previous_state.cap_style : :butt
|
53
|
+
@join_style = previous_state ? previous_state.join_style : :miter
|
54
|
+
@line_width = previous_state ? previous_state.line_width : 1
|
55
|
+
end
|
56
|
+
|
57
|
+
def dash_setting
|
58
|
+
"[#{@dash[:dash]} #{@dash[:space]}] #{@dash[:phase]} d"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
module Core
|
63
|
+
class Page
|
64
|
+
module GraphicsState
|
65
|
+
|
66
|
+
def graphic_state
|
67
|
+
stack.current_state
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
11
74
|
class Document
|
12
|
-
module GraphicsState
|
75
|
+
module GraphicsState
|
13
76
|
|
14
77
|
# Pushes the current graphics state on to the graphics state stack so we
|
15
78
|
# can restore it when finished with a change we want to isolate (such as
|
@@ -30,15 +93,15 @@ module Prawn
|
|
30
93
|
# text "rotated text"
|
31
94
|
# end
|
32
95
|
#
|
33
|
-
|
96
|
+
|
34
97
|
def open_graphics_state
|
35
98
|
add_content "q"
|
36
99
|
end
|
37
|
-
|
100
|
+
|
38
101
|
def close_graphics_state
|
39
102
|
add_content "Q"
|
40
103
|
end
|
41
|
-
|
104
|
+
|
42
105
|
def save_graphics_state(graphic_state = nil)
|
43
106
|
graphic_stack.save_graphic_state(graphic_state)
|
44
107
|
open_graphics_state
|
@@ -52,22 +115,22 @@ module Prawn
|
|
52
115
|
# restores the state to those values
|
53
116
|
def restore_graphics_state
|
54
117
|
if graphic_stack.empty?
|
55
|
-
raise
|
56
|
-
"\n You have reached the end of the graphic state stack"
|
118
|
+
raise Prawn::Errors::EmptyGraphicStateStack,
|
119
|
+
"\n You have reached the end of the graphic state stack"
|
57
120
|
end
|
58
|
-
close_graphics_state
|
121
|
+
close_graphics_state
|
59
122
|
graphic_stack.restore_graphic_state
|
60
123
|
end
|
61
|
-
|
124
|
+
|
62
125
|
def graphic_stack
|
63
126
|
state.page.stack
|
64
127
|
end
|
65
|
-
|
128
|
+
|
66
129
|
def graphic_state
|
67
130
|
save_graphics_state unless graphic_stack.current_state
|
68
|
-
graphic_stack.current_state
|
131
|
+
graphic_stack.current_state
|
69
132
|
end
|
70
|
-
|
133
|
+
|
71
134
|
end
|
72
135
|
end
|
73
136
|
end
|
@@ -7,26 +7,26 @@
|
|
7
7
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
8
|
|
9
9
|
module Prawn
|
10
|
-
class Document
|
11
|
-
|
10
|
+
class Document
|
11
|
+
|
12
12
|
# This module exposes a few low-level PDF features for those who want
|
13
13
|
# to extend Prawn's core functionality. If you are not comfortable with
|
14
14
|
# low level PDF functionality as defined by Adobe's specification, chances
|
15
|
-
# are you won't need anything you find here.
|
15
|
+
# are you won't need anything you find here.
|
16
16
|
#
|
17
|
-
|
18
|
-
|
17
|
+
module Internals
|
18
|
+
|
19
19
|
# Creates a new Prawn::Reference and adds it to the Document's object
|
20
|
-
# list. The +data+ argument is anything that Prawn::PdfObject() can convert.
|
21
|
-
#
|
22
|
-
# Returns the identifier which points to the reference in the ObjectStore
|
20
|
+
# list. The +data+ argument is anything that Prawn::PdfObject() can convert.
|
23
21
|
#
|
22
|
+
# Returns the identifier which points to the reference in the ObjectStore
|
23
|
+
#
|
24
24
|
def ref(data)
|
25
25
|
ref!(data).identifier
|
26
|
-
end
|
26
|
+
end
|
27
27
|
|
28
28
|
# Like ref, but returns the actual reference instead of its identifier.
|
29
|
-
#
|
29
|
+
#
|
30
30
|
# While you can use this to build up nested references within the object
|
31
31
|
# tree, it is recommended to persist only identifiers, and them provide
|
32
32
|
# helper methods to look up the actual references in the ObjectStore
|
@@ -42,21 +42,21 @@ module Prawn
|
|
42
42
|
# of if it's hidden behind a Prawn::Reference, wrap it in deref().
|
43
43
|
#
|
44
44
|
def deref(obj)
|
45
|
-
obj.is_a?(
|
45
|
+
obj.is_a?(Prawn::Core::Reference) ? obj.data : obj
|
46
46
|
end
|
47
47
|
|
48
48
|
# Appends a raw string to the current page content.
|
49
|
-
#
|
50
|
-
# # Raw line drawing example:
|
49
|
+
#
|
50
|
+
# # Raw line drawing example:
|
51
51
|
# x1,y1,x2,y2 = 100,500,300,550
|
52
|
-
# pdf.add_content("%.3f %.3f m" % [ x1, y1 ]) # move
|
52
|
+
# pdf.add_content("%.3f %.3f m" % [ x1, y1 ]) # move
|
53
53
|
# pdf.add_content("%.3f %.3f l" % [ x2, y2 ]) # draw path
|
54
|
-
# pdf.add_content("S") # stroke
|
54
|
+
# pdf.add_content("S") # stroke
|
55
55
|
#
|
56
56
|
def add_content(str)
|
57
57
|
save_graphics_state if graphic_state.nil?
|
58
58
|
state.page.content << str << "\n"
|
59
|
-
end
|
59
|
+
end
|
60
60
|
|
61
61
|
# The Name dictionary (PDF spec 3.6.3) for this document. It is
|
62
62
|
# lazily initialized, so that documents that do not need a name
|
@@ -67,7 +67,7 @@ module Prawn
|
|
67
67
|
end
|
68
68
|
|
69
69
|
# Returns true if the Names dictionary is in use for this document.
|
70
|
-
#
|
70
|
+
#
|
71
71
|
def names?
|
72
72
|
state.store.root.data[:Names]
|
73
73
|
end
|
@@ -87,8 +87,8 @@ module Prawn
|
|
87
87
|
state.on_page_create_callback = nil
|
88
88
|
end
|
89
89
|
end
|
90
|
-
|
91
|
-
private
|
90
|
+
|
91
|
+
private
|
92
92
|
|
93
93
|
# adds a new, empty content stream to each page. Used in templating so
|
94
94
|
# that imported content streams can be left pristine
|
@@ -100,7 +100,6 @@ module Prawn
|
|
100
100
|
apply_margin_options(options)
|
101
101
|
generate_margin_box
|
102
102
|
use_graphic_settings(options[:template])
|
103
|
-
forget_text_rendering_mode!
|
104
103
|
end
|
105
104
|
end
|
106
105
|
|
@@ -157,18 +156,18 @@ module Prawn
|
|
157
156
|
# Write out the PDF Trailer, as per spec 3.4.4
|
158
157
|
#
|
159
158
|
def render_trailer(output)
|
160
|
-
trailer_hash = {:Size => state.store.size + 1,
|
159
|
+
trailer_hash = {:Size => state.store.size + 1,
|
161
160
|
:Root => state.store.root,
|
162
161
|
:Info => state.store.info}
|
163
162
|
trailer_hash.merge!(state.trailer) if state.trailer
|
164
163
|
|
165
164
|
output << "trailer\n"
|
166
|
-
output <<
|
167
|
-
output << "startxref\n"
|
165
|
+
output << Prawn::Core::PdfObject(trailer_hash) << "\n"
|
166
|
+
output << "startxref\n"
|
168
167
|
output << @xref_offset << "\n"
|
169
168
|
output << "%%EOF" << "\n"
|
170
169
|
end
|
171
|
-
|
170
|
+
|
172
171
|
end
|
173
172
|
end
|
174
173
|
end
|