prawn 2.0.2 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/GPLv2 +20 -21
- data/Gemfile +3 -9
- data/Rakefile +20 -23
- data/lib/prawn.rb +37 -49
- data/lib/prawn/document.rb +181 -133
- data/lib/prawn/document/bounding_box.rb +41 -29
- data/lib/prawn/document/column_box.rb +7 -7
- data/lib/prawn/document/internals.rb +18 -8
- data/lib/prawn/document/span.rb +21 -16
- data/lib/prawn/encoding.rb +69 -68
- data/lib/prawn/errors.rb +12 -7
- data/lib/prawn/font.rb +115 -69
- data/lib/prawn/font_metric_cache.rb +14 -8
- data/lib/prawn/{font → fonts}/afm.rb +102 -68
- data/lib/prawn/{font → fonts}/dfont.rb +5 -11
- data/lib/prawn/fonts/otf.rb +11 -0
- data/lib/prawn/fonts/ttc.rb +36 -0
- data/lib/prawn/{font → fonts}/ttf.rb +87 -68
- data/lib/prawn/graphics.rb +120 -80
- data/lib/prawn/graphics/blend_mode.rb +65 -0
- data/lib/prawn/graphics/cap_style.rb +3 -3
- data/lib/prawn/graphics/color.rb +27 -25
- data/lib/prawn/graphics/dash.rb +23 -11
- data/lib/prawn/graphics/join_style.rb +9 -3
- data/lib/prawn/graphics/patterns.rb +197 -67
- data/lib/prawn/graphics/transformation.rb +17 -8
- data/lib/prawn/graphics/transparency.rb +17 -13
- data/lib/prawn/grid.rb +48 -47
- data/lib/prawn/image_handler.rb +5 -5
- data/lib/prawn/images.rb +39 -30
- data/lib/prawn/images/image.rb +2 -1
- data/lib/prawn/images/jpg.rb +28 -22
- data/lib/prawn/images/png.rb +107 -66
- data/lib/prawn/measurement_extensions.rb +10 -9
- data/lib/prawn/measurements.rb +19 -15
- data/lib/prawn/outline.rb +97 -77
- data/lib/prawn/repeater.rb +14 -10
- data/lib/prawn/security.rb +81 -61
- data/lib/prawn/security/arcfour.rb +2 -2
- data/lib/prawn/soft_mask.rb +26 -26
- data/lib/prawn/stamp.rb +20 -13
- data/lib/prawn/text.rb +68 -52
- data/lib/prawn/text/box.rb +11 -8
- data/lib/prawn/text/formatted.rb +5 -5
- data/lib/prawn/text/formatted/arranger.rb +78 -49
- data/lib/prawn/text/formatted/box.rb +134 -100
- data/lib/prawn/text/formatted/fragment.rb +11 -14
- data/lib/prawn/text/formatted/line_wrap.rb +121 -63
- data/lib/prawn/text/formatted/parser.rb +139 -117
- data/lib/prawn/text/formatted/wrap.rb +43 -31
- data/lib/prawn/transformation_stack.rb +44 -0
- data/lib/prawn/utilities.rb +7 -22
- data/lib/prawn/version.rb +2 -2
- data/lib/prawn/view.rb +17 -7
- data/manual/basic_concepts/adding_pages.rb +6 -7
- data/manual/basic_concepts/basic_concepts.rb +31 -22
- data/manual/basic_concepts/creation.rb +10 -11
- data/manual/basic_concepts/cursor.rb +4 -5
- data/manual/basic_concepts/measurement.rb +6 -7
- data/manual/basic_concepts/origin.rb +5 -6
- data/manual/basic_concepts/other_cursor_helpers.rb +11 -12
- data/manual/basic_concepts/view.rb +22 -16
- data/manual/bounding_box/bounding_box.rb +29 -24
- data/manual/bounding_box/bounds.rb +11 -12
- data/manual/bounding_box/canvas.rb +4 -5
- data/manual/bounding_box/creation.rb +6 -7
- data/manual/bounding_box/indentation.rb +14 -15
- data/manual/bounding_box/nesting.rb +24 -17
- data/manual/bounding_box/russian_boxes.rb +14 -13
- data/manual/bounding_box/stretchy.rb +12 -13
- data/manual/contents.rb +28 -22
- data/manual/cover.rb +33 -28
- data/manual/document_and_page_options/background.rb +11 -13
- data/manual/document_and_page_options/document_and_page_options.rb +25 -20
- data/manual/document_and_page_options/metadata.rb +18 -16
- data/manual/document_and_page_options/page_margins.rb +18 -20
- data/manual/document_and_page_options/page_size.rb +13 -12
- data/manual/document_and_page_options/print_scaling.rb +17 -15
- data/manual/example_helper.rb +5 -4
- data/manual/graphics/blend_mode.rb +52 -0
- data/manual/graphics/circle_and_ellipse.rb +4 -5
- data/manual/graphics/color.rb +7 -9
- data/manual/graphics/common_lines.rb +7 -8
- data/manual/graphics/fill_and_stroke.rb +4 -5
- data/manual/graphics/fill_rules.rb +9 -10
- data/manual/graphics/gradients.rb +27 -21
- data/manual/graphics/graphics.rb +48 -39
- data/manual/graphics/helper.rb +12 -9
- data/manual/graphics/line_width.rb +8 -7
- data/manual/graphics/lines_and_curves.rb +7 -8
- data/manual/graphics/polygon.rb +6 -8
- data/manual/graphics/rectangle.rb +4 -5
- data/manual/graphics/rotate.rb +6 -7
- data/manual/graphics/scale.rb +14 -15
- data/manual/graphics/soft_masks.rb +4 -5
- data/manual/graphics/stroke_cap.rb +6 -7
- data/manual/graphics/stroke_dash.rb +11 -12
- data/manual/graphics/stroke_join.rb +5 -6
- data/manual/graphics/translate.rb +9 -10
- data/manual/graphics/transparency.rb +7 -8
- data/manual/how_to_read_this_manual.rb +6 -6
- data/manual/images/absolute_position.rb +6 -7
- data/manual/images/fit.rb +7 -8
- data/manual/images/horizontal.rb +9 -10
- data/manual/images/images.rb +28 -24
- data/manual/images/plain_image.rb +5 -6
- data/manual/images/scale.rb +9 -10
- data/manual/images/vertical.rb +13 -14
- data/manual/images/width_and_height.rb +10 -11
- data/manual/layout/boxes.rb +5 -6
- data/manual/layout/content.rb +7 -8
- data/manual/layout/layout.rb +18 -16
- data/manual/layout/simple_grid.rb +6 -7
- data/manual/outline/add_subsection_to.rb +20 -21
- data/manual/outline/insert_section_after.rb +15 -16
- data/manual/outline/outline.rb +21 -17
- data/manual/outline/sections_and_pages.rb +17 -18
- data/manual/repeatable_content/alternate_page_numbering.rb +21 -17
- data/manual/repeatable_content/page_numbering.rb +17 -16
- data/manual/repeatable_content/repeatable_content.rb +25 -19
- data/manual/repeatable_content/repeater.rb +14 -15
- data/manual/repeatable_content/stamp.rb +14 -15
- data/manual/security/encryption.rb +9 -10
- data/manual/security/permissions.rb +19 -14
- data/manual/security/security.rb +19 -16
- data/manual/table.rb +3 -3
- data/manual/text/alignment.rb +16 -17
- data/manual/text/color.rb +12 -11
- data/manual/text/column_box.rb +9 -10
- data/manual/text/fallback_fonts.rb +25 -21
- data/manual/text/font.rb +11 -12
- data/manual/text/font_size.rb +13 -14
- data/manual/text/font_style.rb +7 -8
- data/manual/text/formatted_callbacks.rb +25 -21
- data/manual/text/formatted_text.rb +33 -25
- data/manual/text/free_flowing_text.rb +20 -21
- data/manual/text/inline.rb +18 -19
- data/manual/text/kerning_and_character_spacing.rb +14 -15
- data/manual/text/leading.rb +7 -8
- data/manual/text/line_wrapping.rb +37 -18
- data/manual/text/paragraph_indentation.rb +13 -14
- data/manual/text/positioned_text.rb +15 -16
- data/manual/text/registering_families.rb +20 -21
- data/manual/text/rendering_and_color.rb +9 -10
- data/manual/text/right_to_left_text.rb +26 -19
- data/manual/text/rotation.rb +28 -23
- data/manual/text/single_usage.rb +8 -9
- data/manual/text/text.rb +57 -52
- data/manual/text/text_box_excess.rb +20 -17
- data/manual/text/text_box_extensions.rb +18 -15
- data/manual/text/text_box_overflow.rb +18 -19
- data/manual/text/utf8.rb +11 -12
- data/manual/text/win_ansi_charset.rb +21 -19
- data/prawn.gemspec +45 -33
- data/spec/extensions/encoding_helpers.rb +3 -3
- data/spec/prawn/document/bounding_box_spec.rb +546 -0
- data/spec/prawn/document/column_box_spec.rb +75 -0
- data/spec/prawn/document/security_spec.rb +176 -0
- data/spec/prawn/document_annotations_spec.rb +76 -0
- data/spec/prawn/document_destinations_spec.rb +15 -0
- data/spec/prawn/document_grid_spec.rb +99 -0
- data/spec/prawn/document_reference_spec.rb +27 -0
- data/spec/prawn/document_span_spec.rb +36 -0
- data/spec/prawn/document_spec.rb +802 -0
- data/spec/prawn/font_metric_cache_spec.rb +54 -0
- data/spec/prawn/font_spec.rb +542 -0
- data/spec/prawn/graphics/blend_mode_spec.rb +63 -0
- data/spec/prawn/graphics/transparency_spec.rb +81 -0
- data/spec/prawn/graphics_spec.rb +837 -0
- data/spec/prawn/graphics_stroke_styles_spec.rb +229 -0
- data/spec/prawn/image_handler_spec.rb +53 -0
- data/spec/prawn/images/jpg_spec.rb +20 -0
- data/spec/prawn/images/png_spec.rb +283 -0
- data/spec/prawn/images_spec.rb +224 -0
- data/spec/prawn/measurements_extensions_spec.rb +24 -0
- data/spec/prawn/outline_spec.rb +412 -0
- data/spec/prawn/repeater_spec.rb +165 -0
- data/spec/prawn/soft_mask_spec.rb +74 -0
- data/spec/prawn/stamp_spec.rb +172 -0
- data/spec/prawn/text/box_spec.rb +1112 -0
- data/spec/prawn/text/formatted/arranger_spec.rb +466 -0
- data/spec/prawn/text/formatted/box_spec.rb +846 -0
- data/spec/prawn/text/formatted/fragment_spec.rb +343 -0
- data/spec/prawn/text/formatted/line_wrap_spec.rb +494 -0
- data/spec/prawn/text/formatted/parser_spec.rb +697 -0
- data/spec/prawn/text_draw_text_spec.rb +149 -0
- data/spec/prawn/text_rendering_mode_spec.rb +48 -0
- data/spec/prawn/text_spacing_spec.rb +95 -0
- data/spec/prawn/text_spec.rb +603 -0
- data/spec/prawn/text_with_inline_formatting_spec.rb +35 -0
- data/spec/prawn/transformation_stack_spec.rb +66 -0
- data/spec/prawn/view_spec.rb +63 -0
- data/spec/prawn_manual_spec.rb +35 -0
- data/spec/spec_helper.rb +19 -23
- metadata +145 -185
- metadata.gz.sig +4 -0
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/16bit.png +0 -0
- data/data/images/arrow.png +0 -0
- data/data/images/arrow2.png +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/dice.png +0 -0
- data/data/images/dice_interlaced.png +0 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/data/images/license.md +0 -8
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/data/images/page_white_text.png +0 -0
- data/data/images/pal_bk.png +0 -0
- data/data/images/pigs.jpg +0 -0
- data/data/images/prawn.png +0 -0
- data/data/images/ruport.png +0 -0
- data/data/images/ruport_data.dat +0 -0
- data/data/images/ruport_transparent.png +0 -0
- data/data/images/ruport_type0.png +0 -0
- data/data/images/stef.jpg +0 -0
- data/data/images/tru256.bmp +0 -0
- data/data/images/web-links.dat +0 -1
- data/data/images/web-links.png +0 -0
- data/data/pdfs/complex_template.pdf +0 -0
- data/data/pdfs/contains_ttf_font.pdf +0 -0
- data/data/pdfs/encrypted.pdf +0 -0
- data/data/pdfs/form.pdf +1 -819
- data/data/pdfs/hexagon.pdf +0 -61
- data/data/pdfs/indirect_reference.pdf +0 -86
- data/data/pdfs/multipage_template.pdf +0 -127
- data/data/pdfs/nested_pages.pdf +0 -118
- data/data/pdfs/page_without_mediabox.pdf +0 -193
- data/data/pdfs/resources_as_indirect_object.pdf +0 -83
- data/data/pdfs/two_hexagons.pdf +0 -90
- data/data/pdfs/version_1_6.pdf +0 -61
- data/data/shift_jis_text.txt +0 -1
- data/spec/acceptance/png.rb +0 -24
- data/spec/annotations_spec.rb +0 -67
- data/spec/bounding_box_spec.rb +0 -501
- data/spec/column_box_spec.rb +0 -59
- data/spec/destinations_spec.rb +0 -13
- data/spec/document_spec.rb +0 -742
- data/spec/extensions/mocha.rb +0 -45
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/font_spec.rb +0 -475
- data/spec/formatted_text_arranger_spec.rb +0 -423
- data/spec/formatted_text_box_spec.rb +0 -716
- data/spec/formatted_text_fragment_spec.rb +0 -299
- data/spec/graphics_spec.rb +0 -666
- data/spec/grid_spec.rb +0 -95
- data/spec/image_handler_spec.rb +0 -53
- data/spec/images_spec.rb +0 -167
- data/spec/inline_formatted_text_parser_spec.rb +0 -568
- data/spec/jpg_spec.rb +0 -23
- data/spec/line_wrap_spec.rb +0 -366
- data/spec/measurement_units_spec.rb +0 -22
- data/spec/outline_spec.rb +0 -409
- data/spec/png_spec.rb +0 -235
- data/spec/reference_spec.rb +0 -25
- data/spec/repeater_spec.rb +0 -154
- data/spec/security_spec.rb +0 -151
- data/spec/soft_mask_spec.rb +0 -78
- data/spec/span_spec.rb +0 -43
- data/spec/stamp_spec.rb +0 -179
- data/spec/stroke_styles_spec.rb +0 -208
- data/spec/text_at_spec.rb +0 -142
- data/spec/text_box_spec.rb +0 -1038
- data/spec/text_rendering_mode_spec.rb +0 -45
- data/spec/text_spacing_spec.rb +0 -93
- data/spec/text_spec.rb +0 -549
- data/spec/text_with_inline_formatting_spec.rb +0 -35
- data/spec/transparency_spec.rb +0 -91
- data/spec/view_spec.rb +0 -42
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# bounding_box.rb : Implements a mechanism for shifting the coordinate space
|
4
4
|
#
|
@@ -155,10 +155,10 @@ module Prawn
|
|
155
155
|
# Of course, if you use canvas, you will be responsible for ensuring that
|
156
156
|
# you remain within the printable area of your document.
|
157
157
|
#
|
158
|
-
def bounding_box(
|
158
|
+
def bounding_box(point, *args, &block)
|
159
159
|
init_bounding_box(block) do |parent_box|
|
160
|
-
|
161
|
-
@bounding_box = BoundingBox.new(self, parent_box,
|
160
|
+
point = map_to_absolute(point)
|
161
|
+
@bounding_box = BoundingBox.new(self, parent_box, point, *args)
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
@@ -170,29 +170,29 @@ module Prawn
|
|
170
170
|
# end
|
171
171
|
#
|
172
172
|
def canvas(&block)
|
173
|
-
init_bounding_box(block, :
|
173
|
+
init_bounding_box(block, hold_position: true) do |_|
|
174
174
|
# Canvas bbox acts like margin_box in that its parent bounds are unset.
|
175
175
|
@bounding_box = BoundingBox.new(
|
176
176
|
self, nil, [0, page.dimensions[3]],
|
177
|
-
:
|
178
|
-
:
|
177
|
+
width: page.dimensions[2],
|
178
|
+
height: page.dimensions[3]
|
179
179
|
)
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
183
183
|
private
|
184
184
|
|
185
|
-
def init_bounding_box(user_block, options = {}
|
185
|
+
def init_bounding_box(user_block, options = {})
|
186
186
|
unless user_block
|
187
|
-
|
188
|
-
|
187
|
+
raise ArgumentError,
|
188
|
+
'bounding boxes require a block to be drawn within the box'
|
189
189
|
end
|
190
190
|
|
191
191
|
parent_box = @bounding_box
|
192
192
|
|
193
193
|
original_ypos = y
|
194
194
|
|
195
|
-
|
195
|
+
yield(parent_box)
|
196
196
|
|
197
197
|
self.y = @bounding_box.absolute_top
|
198
198
|
user_block.call
|
@@ -209,9 +209,10 @@ module Prawn
|
|
209
209
|
self.y = @bounding_box.absolute_bottom
|
210
210
|
end
|
211
211
|
|
212
|
-
created_box
|
212
|
+
created_box = @bounding_box
|
213
|
+
@bounding_box = parent_box
|
213
214
|
|
214
|
-
|
215
|
+
created_box
|
215
216
|
end
|
216
217
|
|
217
218
|
# Low level layout helper that simplifies coordinate math.
|
@@ -220,15 +221,17 @@ module Prawn
|
|
220
221
|
# is used for.
|
221
222
|
#
|
222
223
|
class BoundingBox
|
223
|
-
|
224
|
+
# @private
|
225
|
+
def initialize(document, parent, point, options = {})
|
224
226
|
unless options[:width]
|
225
|
-
|
227
|
+
raise ArgumentError, 'BoundingBox needs the :width option to be set'
|
226
228
|
end
|
227
229
|
|
228
230
|
@document = document
|
229
231
|
@parent = parent
|
230
232
|
@x, @y = point
|
231
|
-
@width
|
233
|
+
@width = options[:width]
|
234
|
+
@height = options[:height]
|
232
235
|
@total_left_padding = 0
|
233
236
|
@total_right_padding = 0
|
234
237
|
@stretched_height = nil
|
@@ -280,7 +283,7 @@ module Prawn
|
|
280
283
|
# end
|
281
284
|
#
|
282
285
|
# @private
|
283
|
-
def indent(left_padding, right_padding = 0
|
286
|
+
def indent(left_padding, right_padding = 0)
|
284
287
|
add_left_padding(left_padding)
|
285
288
|
add_right_padding(right_padding)
|
286
289
|
yield
|
@@ -319,7 +322,8 @@ module Prawn
|
|
319
322
|
@width += right_padding
|
320
323
|
end
|
321
324
|
|
322
|
-
# Relative right x-coordinate of the bounding box. (Equal to the box
|
325
|
+
# Relative right x-coordinate of the bounding box. (Equal to the box
|
326
|
+
# width)
|
323
327
|
#
|
324
328
|
# Example, position some text 3 pts from the right of the containing box:
|
325
329
|
#
|
@@ -456,8 +460,11 @@ module Prawn
|
|
456
460
|
#
|
457
461
|
def height
|
458
462
|
return @height if @height
|
459
|
-
|
460
|
-
|
463
|
+
|
464
|
+
@stretched_height = [
|
465
|
+
(absolute_top - @document.y),
|
466
|
+
@stretched_height.to_f
|
467
|
+
].max
|
461
468
|
end
|
462
469
|
|
463
470
|
# an alias for absolute_left
|
@@ -485,8 +492,9 @@ module Prawn
|
|
485
492
|
end
|
486
493
|
end
|
487
494
|
|
488
|
-
# Returns +false+ when the box has a defined height, +true+ when the
|
489
|
-
# is being calculated on the fly based on the current vertical
|
495
|
+
# Returns +false+ when the box has a defined height, +true+ when the
|
496
|
+
# height is being calculated on the fly based on the current vertical
|
497
|
+
# position.
|
490
498
|
#
|
491
499
|
def stretchy?
|
492
500
|
!@height
|
@@ -496,14 +504,15 @@ module Prawn
|
|
496
504
|
#
|
497
505
|
def reference_bounds
|
498
506
|
if stretchy?
|
499
|
-
|
507
|
+
raise "Can't find reference bounds: my parent is unset" unless @parent
|
508
|
+
|
500
509
|
@parent.reference_bounds
|
501
510
|
else
|
502
511
|
self
|
503
512
|
end
|
504
513
|
end
|
505
514
|
|
506
|
-
|
515
|
+
alias update_height height
|
507
516
|
|
508
517
|
# Returns a deep copy of these bounds (including all parent bounds but
|
509
518
|
# not copying the reference to the Document).
|
@@ -512,10 +521,13 @@ module Prawn
|
|
512
521
|
def deep_copy
|
513
522
|
copy = dup
|
514
523
|
# Deep-copy the parent bounds
|
515
|
-
copy.instance_variable_set(
|
516
|
-
|
517
|
-
|
518
|
-
|
524
|
+
copy.instance_variable_set(
|
525
|
+
'@parent',
|
526
|
+
if @parent.is_a?(BoundingBox)
|
527
|
+
@parent.deep_copy
|
528
|
+
end
|
529
|
+
)
|
530
|
+
copy.instance_variable_set('@document', nil)
|
519
531
|
copy
|
520
532
|
end
|
521
533
|
|
@@ -525,7 +537,7 @@ module Prawn
|
|
525
537
|
#
|
526
538
|
# @private
|
527
539
|
def self.restore_deep_copy(bounds, document)
|
528
|
-
bounds.instance_variable_set(
|
540
|
+
bounds.instance_variable_set('@document', document)
|
529
541
|
bounds
|
530
542
|
end
|
531
543
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
3
|
# column_box.rb: Extends BoundingBox to allow for columns of text
|
4
4
|
#
|
5
5
|
# Author Paul Ostazeski.
|
6
6
|
#
|
7
7
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
8
|
|
9
|
-
require_relative
|
9
|
+
require_relative 'bounding_box'
|
10
10
|
|
11
11
|
module Prawn
|
12
12
|
class Document
|
@@ -36,10 +36,10 @@ module Prawn
|
|
36
36
|
|
37
37
|
private
|
38
38
|
|
39
|
-
def init_column_box(user_block, options = {}
|
39
|
+
def init_column_box(user_block, options = {})
|
40
40
|
parent_box = @bounding_box
|
41
41
|
|
42
|
-
|
42
|
+
yield(parent_box)
|
43
43
|
|
44
44
|
self.y = @bounding_box.absolute_top
|
45
45
|
user_block.call
|
@@ -55,7 +55,7 @@ module Prawn
|
|
55
55
|
def initialize(document, parent, point, options = {}) #:nodoc:
|
56
56
|
super
|
57
57
|
@columns = options[:columns] || 3
|
58
|
-
@spacer
|
58
|
+
@spacer = options[:spacer] || @document.font_size
|
59
59
|
@current_column = 0
|
60
60
|
@reflow_margins = options[:reflow_margins]
|
61
61
|
end
|
@@ -109,7 +109,7 @@ module Prawn
|
|
109
109
|
def move_past_bottom
|
110
110
|
@current_column = (@current_column + 1) % @columns
|
111
111
|
@document.y = @y
|
112
|
-
if
|
112
|
+
if @current_column.zero?
|
113
113
|
if @reflow_margins
|
114
114
|
@y = @parent.absolute_top
|
115
115
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
3
|
# internals.rb : Implements document internals for Prawn
|
4
4
|
#
|
5
5
|
# Copyright August 2008, Gregory Brown. All Rights Reserved.
|
6
6
|
#
|
7
7
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
8
|
|
9
|
-
require
|
9
|
+
require 'forwardable'
|
10
10
|
|
11
11
|
module Prawn
|
12
12
|
class Document
|
@@ -23,10 +23,20 @@ module Prawn
|
|
23
23
|
# but they are used in documentation and possibly in extensions.
|
24
24
|
# Perhaps they will become part of the extension API?
|
25
25
|
# Anyway, for now it's not clear what we should do w. them.
|
26
|
-
delegate [
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
delegate %i[
|
27
|
+
graphic_state
|
28
|
+
on_page_create
|
29
|
+
] => :renderer
|
30
|
+
|
31
|
+
def save_graphics_state(state = nil, &block)
|
32
|
+
save_transformation_stack
|
33
|
+
renderer.save_graphics_state(state, &block)
|
34
|
+
end
|
35
|
+
|
36
|
+
def restore_graphics_state
|
37
|
+
restore_transformation_stack
|
38
|
+
renderer.restore_graphics_state
|
39
|
+
end
|
30
40
|
|
31
41
|
# FIXME: This is a circular reference, because in theory Prawn should
|
32
42
|
# be passing instances of renderer to PDF::Core::Page, but it's
|
@@ -37,7 +47,7 @@ module Prawn
|
|
37
47
|
delegate [:compression_enabled?] => :renderer
|
38
48
|
|
39
49
|
# FIXME: More circular references in PDF::Core::Page.
|
40
|
-
delegate [
|
50
|
+
delegate %i[ref ref! deref] => :renderer
|
41
51
|
|
42
52
|
# FIXME: Another circular reference, because we mix in a module from
|
43
53
|
# PDF::Core to provide destinations, which in theory should not
|
data/lib/prawn/document/span.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# span.rb : Implements text columns
|
4
4
|
#
|
@@ -28,26 +28,31 @@ module Prawn
|
|
28
28
|
#
|
29
29
|
def span(width, options = {})
|
30
30
|
Prawn.verify_options [:position], options
|
31
|
-
original_position =
|
31
|
+
original_position = y
|
32
32
|
|
33
33
|
# FIXME: Any way to move this upstream?
|
34
|
-
left_boundary =
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
34
|
+
left_boundary =
|
35
|
+
case options.fetch(:position, :left)
|
36
|
+
when :left
|
37
|
+
margin_box.absolute_left
|
38
|
+
when :center
|
39
|
+
margin_box.absolute_left + margin_box.width / 2.0 - width / 2.0
|
40
|
+
when :right
|
41
|
+
margin_box.absolute_right - width
|
42
|
+
when Numeric
|
43
|
+
margin_box.absolute_left + options[:position]
|
44
|
+
else
|
45
|
+
raise ArgumentError, 'Invalid option for :position'
|
46
|
+
end
|
46
47
|
|
47
48
|
# we need to bust out of whatever nested bounding boxes we're in.
|
48
49
|
canvas do
|
49
|
-
bounding_box(
|
50
|
-
|
50
|
+
bounding_box(
|
51
|
+
[
|
52
|
+
left_boundary,
|
53
|
+
margin_box.absolute_top
|
54
|
+
], width: width
|
55
|
+
) do
|
51
56
|
self.y = original_position
|
52
57
|
yield
|
53
58
|
end
|
data/lib/prawn/encoding.rb
CHANGED
@@ -1,87 +1,88 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
3
|
# Copyright September 2008, Gregory Brown, James Healy All Rights Reserved.
|
4
4
|
#
|
5
5
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
6
6
|
#
|
7
7
|
module Prawn
|
8
|
-
|
8
|
+
# @private
|
9
|
+
module Encoding
|
9
10
|
# Map between unicode and WinAnsiEnoding
|
10
11
|
#
|
11
12
|
class WinAnsi #:nodoc:
|
12
13
|
CHARACTERS = %w[
|
13
|
-
.notdef
|
14
|
-
.notdef
|
15
|
-
.notdef
|
16
|
-
.notdef
|
17
|
-
.notdef
|
18
|
-
.notdef
|
19
|
-
.notdef
|
20
|
-
.notdef
|
14
|
+
.notdef .notdef .notdef .notdef
|
15
|
+
.notdef .notdef .notdef .notdef
|
16
|
+
.notdef .notdef .notdef .notdef
|
17
|
+
.notdef .notdef .notdef .notdef
|
18
|
+
.notdef .notdef .notdef .notdef
|
19
|
+
.notdef .notdef .notdef .notdef
|
20
|
+
.notdef .notdef .notdef .notdef
|
21
|
+
.notdef .notdef .notdef .notdef
|
21
22
|
|
22
|
-
space
|
23
|
-
dollar
|
24
|
-
parenleft
|
25
|
-
comma
|
26
|
-
zero
|
27
|
-
four
|
28
|
-
eight
|
29
|
-
less
|
23
|
+
space exclam quotedbl numbersign
|
24
|
+
dollar percent ampersand quotesingle
|
25
|
+
parenleft parenright asterisk plus
|
26
|
+
comma hyphen period slash
|
27
|
+
zero one two three
|
28
|
+
four five six seven
|
29
|
+
eight nine colon semicolon
|
30
|
+
less equal greater question
|
30
31
|
|
31
|
-
at
|
32
|
-
D
|
33
|
-
H
|
34
|
-
L
|
35
|
-
P
|
36
|
-
T
|
37
|
-
X
|
38
|
-
backslash
|
32
|
+
at A B C
|
33
|
+
D E F G
|
34
|
+
H I J K
|
35
|
+
L M N O
|
36
|
+
P Q R S
|
37
|
+
T U V W
|
38
|
+
X Y Z bracketleft
|
39
|
+
backslash bracketright asciicircum underscore
|
39
40
|
|
40
|
-
grave
|
41
|
-
d
|
42
|
-
h
|
43
|
-
l
|
44
|
-
p
|
45
|
-
t
|
46
|
-
x
|
47
|
-
bar
|
41
|
+
grave a b c
|
42
|
+
d e f g
|
43
|
+
h i j k
|
44
|
+
l m n o
|
45
|
+
p q r s
|
46
|
+
t u v w
|
47
|
+
x y z braceleft
|
48
|
+
bar braceright asciitilde .notdef
|
48
49
|
|
49
|
-
Euro
|
50
|
-
quotedblbase
|
51
|
-
circumflex
|
52
|
-
OE
|
53
|
-
.notdef
|
54
|
-
quotedblright bullet
|
55
|
-
tilde
|
56
|
-
oe
|
50
|
+
Euro .notdef quotesinglbase florin
|
51
|
+
quotedblbase ellipsis dagger daggerdbl
|
52
|
+
circumflex perthousand Scaron guilsinglleft
|
53
|
+
OE .notdef Zcaron .notdef
|
54
|
+
.notdef quoteleft quoteright quotedblleft
|
55
|
+
quotedblright bullet endash emdash
|
56
|
+
tilde trademark scaron guilsinglright
|
57
|
+
oe .notdef zcaron ydieresis
|
57
58
|
|
58
|
-
space
|
59
|
-
currency
|
60
|
-
dieresis
|
61
|
-
logicalnot
|
62
|
-
degree
|
63
|
-
acute
|
64
|
-
cedilla
|
65
|
-
onequarter
|
59
|
+
space exclamdown cent sterling
|
60
|
+
currency yen brokenbar section
|
61
|
+
dieresis copyright ordfeminine guillemotleft
|
62
|
+
logicalnot hyphen registered macron
|
63
|
+
degree plusminus twosuperior threesuperior
|
64
|
+
acute mu paragraph periodcentered
|
65
|
+
cedilla onesuperior ordmasculine guillemotright
|
66
|
+
onequarter onehalf threequarters questiondown
|
66
67
|
|
67
|
-
Agrave
|
68
|
-
Adieresis
|
69
|
-
Egrave
|
70
|
-
Igrave
|
71
|
-
Eth
|
72
|
-
Ocircumflex
|
73
|
-
Oslash
|
74
|
-
Udieresis
|
68
|
+
Agrave Aacute Acircumflex Atilde
|
69
|
+
Adieresis Aring AE Ccedilla
|
70
|
+
Egrave Eacute Ecircumflex Edieresis
|
71
|
+
Igrave Iacute Icircumflex Idieresis
|
72
|
+
Eth Ntilde Ograve Oacute
|
73
|
+
Ocircumflex Otilde Odieresis multiply
|
74
|
+
Oslash Ugrave Uacute Ucircumflex
|
75
|
+
Udieresis Yacute Thorn germandbls
|
75
76
|
|
76
|
-
agrave
|
77
|
-
adieresis
|
78
|
-
egrave
|
79
|
-
igrave
|
80
|
-
eth
|
81
|
-
ocircumflex
|
82
|
-
oslash
|
83
|
-
udieresis
|
84
|
-
]
|
77
|
+
agrave aacute acircumflex atilde
|
78
|
+
adieresis aring ae ccedilla
|
79
|
+
egrave eacute ecircumflex edieresis
|
80
|
+
igrave iacute icircumflex idieresis
|
81
|
+
eth ntilde ograve oacute
|
82
|
+
ocircumflex otilde odieresis divide
|
83
|
+
oslash ugrave uacute ucircumflex
|
84
|
+
udieresis yacute thorn ydieresis
|
85
|
+
].freeze
|
85
86
|
end
|
86
87
|
end
|
87
88
|
end
|