prawn 2.3.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/prawn/document/bounding_box.rb +223 -143
- data/lib/prawn/document/column_box.rb +61 -26
- data/lib/prawn/document/internals.rb +25 -16
- data/lib/prawn/document/span.rb +21 -18
- data/lib/prawn/document.rb +273 -182
- data/lib/prawn/encoding.rb +2 -5
- data/lib/prawn/errors.rb +23 -34
- data/lib/prawn/font.rb +254 -139
- data/lib/prawn/font_metric_cache.rb +18 -16
- data/lib/prawn/fonts/afm.rb +99 -57
- data/lib/prawn/fonts/dfont.rb +7 -1
- data/lib/prawn/fonts/otf.rb +4 -1
- data/lib/prawn/fonts/to_unicode_cmap.rb +151 -0
- data/lib/prawn/fonts/ttc.rb +7 -2
- data/lib/prawn/fonts/ttf.rb +345 -107
- data/lib/prawn/fonts.rb +14 -0
- data/lib/prawn/graphics/blend_mode.rb +25 -28
- data/lib/prawn/graphics/cap_style.rb +9 -12
- data/lib/prawn/graphics/color.rb +75 -50
- data/lib/prawn/graphics/dash.rb +45 -42
- data/lib/prawn/graphics/join_style.rb +18 -12
- data/lib/prawn/graphics/patterns.rb +239 -110
- data/lib/prawn/graphics/transformation.rb +51 -44
- data/lib/prawn/graphics/transparency.rb +16 -40
- data/lib/prawn/graphics.rb +370 -260
- data/lib/prawn/grid.rb +219 -57
- data/lib/prawn/image_handler.rb +27 -10
- data/lib/prawn/images/image.rb +8 -10
- data/lib/prawn/images/jpg.rb +46 -20
- data/lib/prawn/images/png.rb +94 -42
- data/lib/prawn/images.rb +70 -81
- data/lib/prawn/measurement_extensions.rb +39 -8
- data/lib/prawn/measurements.rb +60 -5
- data/lib/prawn/outline.rb +120 -113
- data/lib/prawn/repeater.rb +52 -36
- data/lib/prawn/security/arcfour.rb +4 -4
- data/lib/prawn/security.rb +106 -98
- data/lib/prawn/soft_mask.rb +42 -30
- data/lib/prawn/stamp.rb +38 -42
- data/lib/prawn/text/box.rb +156 -105
- data/lib/prawn/text/formatted/arranger.rb +121 -41
- data/lib/prawn/text/formatted/box.rb +239 -163
- data/lib/prawn/text/formatted/fragment.rb +130 -14
- data/lib/prawn/text/formatted/line_wrap.rb +49 -38
- data/lib/prawn/text/formatted/parser.rb +116 -74
- data/lib/prawn/text/formatted/wrap.rb +25 -26
- data/lib/prawn/text/formatted.rb +75 -0
- data/lib/prawn/text.rb +456 -211
- data/lib/prawn/transformation_stack.rb +29 -10
- data/lib/prawn/utilities.rb +13 -13
- data/lib/prawn/version.rb +2 -1
- data/lib/prawn/view.rb +69 -54
- data/lib/prawn.rb +24 -18
- data.tar.gz.sig +0 -0
- metadata +55 -262
- metadata.gz.sig +3 -4
- data/.yardopts +0 -10
- data/Gemfile +0 -5
- data/Rakefile +0 -54
- data/manual/absolute_position.pdf +0 -0
- data/manual/basic_concepts/adding_pages.rb +0 -26
- data/manual/basic_concepts/basic_concepts.rb +0 -43
- data/manual/basic_concepts/creation.rb +0 -38
- data/manual/basic_concepts/cursor.rb +0 -32
- data/manual/basic_concepts/measurement.rb +0 -24
- data/manual/basic_concepts/origin.rb +0 -37
- data/manual/basic_concepts/other_cursor_helpers.rb +0 -39
- data/manual/basic_concepts/view.rb +0 -48
- data/manual/bounding_box/bounding_box.rb +0 -41
- data/manual/bounding_box/bounds.rb +0 -48
- data/manual/bounding_box/canvas.rb +0 -23
- data/manual/bounding_box/creation.rb +0 -22
- data/manual/bounding_box/indentation.rb +0 -45
- data/manual/bounding_box/nesting.rb +0 -52
- data/manual/bounding_box/russian_boxes.rb +0 -40
- data/manual/bounding_box/stretchy.rb +0 -29
- data/manual/contents.rb +0 -35
- data/manual/cover.rb +0 -43
- data/manual/document_and_page_options/background.rb +0 -25
- data/manual/document_and_page_options/document_and_page_options.rb +0 -34
- data/manual/document_and_page_options/metadata.rb +0 -25
- data/manual/document_and_page_options/page_margins.rb +0 -36
- data/manual/document_and_page_options/page_size.rb +0 -34
- data/manual/document_and_page_options/print_scaling.rb +0 -22
- data/manual/example_helper.rb +0 -8
- data/manual/graphics/blend_mode.rb +0 -52
- data/manual/graphics/circle_and_ellipse.rb +0 -21
- data/manual/graphics/color.rb +0 -22
- data/manual/graphics/common_lines.rb +0 -29
- data/manual/graphics/fill_and_stroke.rb +0 -41
- data/manual/graphics/fill_rules.rb +0 -37
- data/manual/graphics/gradients.rb +0 -43
- data/manual/graphics/graphics.rb +0 -64
- data/manual/graphics/helper.rb +0 -27
- data/manual/graphics/line_width.rb +0 -36
- data/manual/graphics/lines_and_curves.rb +0 -40
- data/manual/graphics/polygon.rb +0 -27
- data/manual/graphics/rectangle.rb +0 -20
- data/manual/graphics/rotate.rb +0 -25
- data/manual/graphics/scale.rb +0 -42
- data/manual/graphics/soft_masks.rb +0 -44
- data/manual/graphics/stroke_cap.rb +0 -30
- data/manual/graphics/stroke_dash.rb +0 -47
- data/manual/graphics/stroke_join.rb +0 -29
- data/manual/graphics/translate.rb +0 -28
- data/manual/graphics/transparency.rb +0 -33
- data/manual/how_to_read_this_manual.rb +0 -39
- data/manual/images/absolute_position.rb +0 -22
- data/manual/images/fit.rb +0 -20
- data/manual/images/horizontal.rb +0 -24
- data/manual/images/images.rb +0 -41
- data/manual/images/plain_image.rb +0 -17
- data/manual/images/scale.rb +0 -21
- data/manual/images/vertical.rb +0 -27
- data/manual/images/width_and_height.rb +0 -24
- data/manual/layout/boxes.rb +0 -26
- data/manual/layout/content.rb +0 -24
- data/manual/layout/layout.rb +0 -27
- data/manual/layout/simple_grid.rb +0 -22
- data/manual/outline/add_subsection_to.rb +0 -60
- data/manual/outline/insert_section_after.rb +0 -46
- data/manual/outline/outline.rb +0 -33
- data/manual/outline/sections_and_pages.rb +0 -66
- data/manual/repeatable_content/alternate_page_numbering.rb +0 -36
- data/manual/repeatable_content/page_numbering.rb +0 -55
- data/manual/repeatable_content/repeatable_content.rb +0 -35
- data/manual/repeatable_content/repeater.rb +0 -54
- data/manual/repeatable_content/stamp.rb +0 -40
- data/manual/security/encryption.rb +0 -28
- data/manual/security/permissions.rb +0 -41
- data/manual/security/security.rb +0 -28
- data/manual/table.rb +0 -16
- data/manual/text/alignment.rb +0 -43
- data/manual/text/color.rb +0 -24
- data/manual/text/column_box.rb +0 -30
- data/manual/text/fallback_fonts.rb +0 -41
- data/manual/text/font.rb +0 -40
- data/manual/text/font_size.rb +0 -44
- data/manual/text/font_style.rb +0 -22
- data/manual/text/formatted_callbacks.rb +0 -65
- data/manual/text/formatted_text.rb +0 -58
- data/manual/text/free_flowing_text.rb +0 -50
- data/manual/text/inline.rb +0 -40
- data/manual/text/kerning_and_character_spacing.rb +0 -38
- data/manual/text/leading.rb +0 -24
- data/manual/text/line_wrapping.rb +0 -60
- data/manual/text/paragraph_indentation.rb +0 -32
- data/manual/text/positioned_text.rb +0 -37
- data/manual/text/registering_families.rb +0 -51
- data/manual/text/rendering_and_color.rb +0 -36
- data/manual/text/right_to_left_text.rb +0 -54
- data/manual/text/rotation.rb +0 -47
- data/manual/text/single_usage.rb +0 -36
- data/manual/text/text.rb +0 -75
- data/manual/text/text_box_excess.rb +0 -35
- data/manual/text/text_box_extensions.rb +0 -48
- data/manual/text/text_box_overflow.rb +0 -49
- data/manual/text/utf8.rb +0 -27
- data/manual/text/win_ansi_charset.rb +0 -62
- data/prawn.gemspec +0 -57
- data/spec/data/curves.pdf +0 -66
- data/spec/extensions/encoding_helpers.rb +0 -11
- data/spec/prawn/document/bounding_box_spec.rb +0 -546
- data/spec/prawn/document/column_box_spec.rb +0 -75
- data/spec/prawn/document/security_spec.rb +0 -176
- data/spec/prawn/document_annotations_spec.rb +0 -76
- data/spec/prawn/document_destinations_spec.rb +0 -15
- data/spec/prawn/document_grid_spec.rb +0 -99
- data/spec/prawn/document_reference_spec.rb +0 -27
- data/spec/prawn/document_span_spec.rb +0 -36
- data/spec/prawn/document_spec.rb +0 -802
- data/spec/prawn/font_metric_cache_spec.rb +0 -54
- data/spec/prawn/font_spec.rb +0 -542
- data/spec/prawn/graphics/blend_mode_spec.rb +0 -63
- data/spec/prawn/graphics/transparency_spec.rb +0 -81
- data/spec/prawn/graphics_spec.rb +0 -837
- data/spec/prawn/graphics_stroke_styles_spec.rb +0 -229
- data/spec/prawn/image_handler_spec.rb +0 -53
- data/spec/prawn/images/jpg_spec.rb +0 -20
- data/spec/prawn/images/png_spec.rb +0 -283
- data/spec/prawn/images_spec.rb +0 -224
- data/spec/prawn/measurements_extensions_spec.rb +0 -24
- data/spec/prawn/outline_spec.rb +0 -412
- data/spec/prawn/repeater_spec.rb +0 -165
- data/spec/prawn/soft_mask_spec.rb +0 -74
- data/spec/prawn/stamp_spec.rb +0 -172
- data/spec/prawn/text/box_spec.rb +0 -1112
- data/spec/prawn/text/formatted/arranger_spec.rb +0 -466
- data/spec/prawn/text/formatted/box_spec.rb +0 -846
- data/spec/prawn/text/formatted/fragment_spec.rb +0 -343
- data/spec/prawn/text/formatted/line_wrap_spec.rb +0 -494
- data/spec/prawn/text/formatted/parser_spec.rb +0 -697
- data/spec/prawn/text_draw_text_spec.rb +0 -149
- data/spec/prawn/text_rendering_mode_spec.rb +0 -48
- data/spec/prawn/text_spacing_spec.rb +0 -95
- data/spec/prawn/text_spec.rb +0 -603
- data/spec/prawn/text_with_inline_formatting_spec.rb +0 -35
- data/spec/prawn/transformation_stack_spec.rb +0 -66
- data/spec/prawn/view_spec.rb +0 -63
- data/spec/prawn_manual_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -48
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# This is the most important concept you need to learn about Prawn:
|
4
|
-
#
|
5
|
-
# PDF documents have the origin <code>[0,0]</code> at the bottom-left corner of
|
6
|
-
# the page.
|
7
|
-
#
|
8
|
-
# A bounding box is a structure which provides boundaries for inserting content.
|
9
|
-
# A bounding box also has the property of relocating the origin to its relative
|
10
|
-
# bottom-left corner. However, be aware that the location specified when
|
11
|
-
# creating a bounding box is its top-left corner, not bottom-left (hence the
|
12
|
-
# <code>[100, 300]</code> coordinates below).
|
13
|
-
#
|
14
|
-
# Even if you never create a bounding box explictly, each document already comes
|
15
|
-
# with one called the margin box. This initial bounding box is the one
|
16
|
-
# responsible for the document margins.
|
17
|
-
#
|
18
|
-
# So practically speaking the origin of a page on a default generated document
|
19
|
-
# isn't the absolute bottom left corner but the bottom left corner of the margin
|
20
|
-
# box.
|
21
|
-
#
|
22
|
-
# The following snippet strokes a circle on the margin box origin. Then strokes
|
23
|
-
# the boundaries of a bounding box and a circle on its origin.
|
24
|
-
|
25
|
-
require_relative '../example_helper'
|
26
|
-
|
27
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
28
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
29
|
-
stroke_axis
|
30
|
-
|
31
|
-
stroke_circle [0, 0], 10
|
32
|
-
|
33
|
-
bounding_box([100, 300], width: 300, height: 200) do
|
34
|
-
stroke_bounds
|
35
|
-
stroke_circle [0, 0], 10
|
36
|
-
end
|
37
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Another group of helpers for changing the cursor position are the pad methods.
|
4
|
-
# They accept a numeric value and a block. <code>pad</code> will use the numeric
|
5
|
-
# value to move the cursor down both before and after the block content.
|
6
|
-
# <code>pad_top</code> will only move the cursor before the block while
|
7
|
-
# <code>pad_bottom</code> will only move after.
|
8
|
-
#
|
9
|
-
# <code>float</code> is a method for not changing the cursor. Pass it a block
|
10
|
-
# and the cursor will remain on the same place when the block returns.
|
11
|
-
|
12
|
-
require_relative '../example_helper'
|
13
|
-
|
14
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
15
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
16
|
-
stroke_horizontal_rule
|
17
|
-
pad(20) { text 'Text padded both before and after.' }
|
18
|
-
|
19
|
-
stroke_horizontal_rule
|
20
|
-
pad_top(20) { text 'Text padded on the top.' }
|
21
|
-
|
22
|
-
stroke_horizontal_rule
|
23
|
-
pad_bottom(20) { text 'Text padded on the bottom.' }
|
24
|
-
|
25
|
-
stroke_horizontal_rule
|
26
|
-
move_down 30
|
27
|
-
|
28
|
-
text 'Text written before the float block.'
|
29
|
-
|
30
|
-
float do
|
31
|
-
move_down 30
|
32
|
-
bounding_box([0, cursor], width: 200) do
|
33
|
-
text 'Text written inside the float block.'
|
34
|
-
stroke_bounds
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
text 'Text written after the float block.'
|
39
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# The recommended way to extend Prawn's functionality is to include the
|
4
|
-
# <code>Prawn::View</code> mixin in your own class, which will make all
|
5
|
-
# <code>Prawn::Document</code> methods available to your custom objects.
|
6
|
-
#
|
7
|
-
# This approach is preferred over inheriting from
|
8
|
-
# <code>Prawn::Document</code>, as your state will be kept completely separate
|
9
|
-
# from <code>Prawn::Document</code>'s, thus avoiding accidental method
|
10
|
-
# collisions.
|
11
|
-
#
|
12
|
-
# Note that <code>Prawn::View</code> lazily instantiates a
|
13
|
-
# <code>Prawn::Document</code> with default initialization settings, such as
|
14
|
-
# page size, layout, margins, etc.
|
15
|
-
#
|
16
|
-
# By defining your own <code>document</code> method, as shown in the example,
|
17
|
-
# you will be able to override those settings and initialize a
|
18
|
-
# <code>Prawn::Document</code> to your heart's content. This method will be
|
19
|
-
# called repeatedly by <code>Prawn::View</code>, so be sure to memoize the
|
20
|
-
# object by assigning it to an instance variable via the <code>||=</code>
|
21
|
-
# operator.
|
22
|
-
|
23
|
-
require_relative '../example_helper'
|
24
|
-
|
25
|
-
class Greeter
|
26
|
-
include Prawn::View
|
27
|
-
|
28
|
-
def initialize(name)
|
29
|
-
@name = name
|
30
|
-
end
|
31
|
-
|
32
|
-
def say_hello
|
33
|
-
text "Hello, #{@name}!"
|
34
|
-
end
|
35
|
-
|
36
|
-
def say_goodbye
|
37
|
-
font('Courier') do
|
38
|
-
text "Goodbye, #{@name}!"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
greeter = Greeter.new('Gregory')
|
44
|
-
|
45
|
-
greeter.say_hello
|
46
|
-
greeter.say_goodbye
|
47
|
-
|
48
|
-
greeter.save_as('greetings.pdf')
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Examples for bounding boxes.
|
4
|
-
|
5
|
-
require_relative '../example_helper'
|
6
|
-
|
7
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
8
|
-
Prawn::ManualBuilder::Example.generate(filename, page_size: 'FOLIO') do
|
9
|
-
package 'bounding_box' do |p|
|
10
|
-
p.section 'Basics' do |s|
|
11
|
-
s.example 'creation'
|
12
|
-
s.example 'bounds'
|
13
|
-
end
|
14
|
-
|
15
|
-
p.section 'Advanced' do |s|
|
16
|
-
s.example 'stretchy'
|
17
|
-
s.example 'nesting'
|
18
|
-
s.example 'indentation'
|
19
|
-
s.example 'canvas'
|
20
|
-
s.example 'russian_boxes'
|
21
|
-
end
|
22
|
-
|
23
|
-
p.intro do
|
24
|
-
prose <<-TEXT
|
25
|
-
Bounding boxes are the basic containers for structuring the content
|
26
|
-
flow. Even being low level building blocks sometimes their simplicity is
|
27
|
-
very welcome.
|
28
|
-
|
29
|
-
The examples show:
|
30
|
-
TEXT
|
31
|
-
|
32
|
-
list(
|
33
|
-
'How to create bounding boxes with specific dimensions',
|
34
|
-
'How to inspect the current bounding box for its coordinates',
|
35
|
-
'Stretchy bounding boxes',
|
36
|
-
'Nested bounding boxes',
|
37
|
-
'Indent blocks'
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# The <code>bounds</code> method returns the current bounding box. This is
|
4
|
-
# useful because the <code>Prawn::BoundingBox</code> exposes some nice boundary
|
5
|
-
# helpers.
|
6
|
-
#
|
7
|
-
# <code>top</code>, <code>bottom</code>, <code>left</code> and
|
8
|
-
# <code>right</code> methods return the bounding box boundaries relative to its
|
9
|
-
# translated origin. <code>top_left</code>, <code>top_right</code>,
|
10
|
-
# <code>bottom_left</code> and <code>bottom_right</code> return those boundaries
|
11
|
-
# pairs inside arrays.
|
12
|
-
#
|
13
|
-
# All these methods have an "absolute" version like <code>absolute_right</code>.
|
14
|
-
# The absolute version returns the same boundary relative to the page absolute
|
15
|
-
# coordinates.
|
16
|
-
#
|
17
|
-
# The following snippet shows the boundaries for the margin box side by side
|
18
|
-
# with the boundaries for a custom bounding box.
|
19
|
-
|
20
|
-
require_relative '../example_helper'
|
21
|
-
|
22
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
23
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
24
|
-
def print_coordinates
|
25
|
-
text "top: #{bounds.top}"
|
26
|
-
text "bottom: #{bounds.bottom}"
|
27
|
-
text "left: #{bounds.left}"
|
28
|
-
text "right: #{bounds.right}"
|
29
|
-
|
30
|
-
move_down 10
|
31
|
-
|
32
|
-
text "absolute top: #{bounds.absolute_top.to_f.round(2)}"
|
33
|
-
text "absolute bottom: #{bounds.absolute_bottom.to_f.round(2)}"
|
34
|
-
text "absolute left: #{bounds.absolute_left.to_f.round(2)}"
|
35
|
-
text "absolute right: #{bounds.absolute_right.to_f.round(2)}"
|
36
|
-
end
|
37
|
-
|
38
|
-
text 'Margin box bounds:'
|
39
|
-
move_down 5
|
40
|
-
print_coordinates
|
41
|
-
|
42
|
-
bounding_box([250, cursor + 140], width: 200, height: 150) do
|
43
|
-
text 'This bounding box bounds:'
|
44
|
-
move_down 5
|
45
|
-
print_coordinates
|
46
|
-
transparent(0.5) { stroke_bounds }
|
47
|
-
end
|
48
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# The origin example already mentions that a new document already comes with
|
4
|
-
# a margin box whose bottom left corner is used as the origin for calculating
|
5
|
-
# coordinates.
|
6
|
-
#
|
7
|
-
# What has not been told is that there is one helper for "bypassing" the margin
|
8
|
-
# box: <code>canvas</code>. This method is a shortcut for creating a bounding
|
9
|
-
# box mapped to the absolute coordinates and evaluating the code inside it.
|
10
|
-
#
|
11
|
-
# The following snippet draws a circle on each of the four absolute corners.
|
12
|
-
|
13
|
-
require_relative '../example_helper'
|
14
|
-
|
15
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
16
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
17
|
-
canvas do
|
18
|
-
fill_circle [bounds.left, bounds.top], 30
|
19
|
-
fill_circle [bounds.right, bounds.top], 30
|
20
|
-
fill_circle [bounds.right, bounds.bottom], 30
|
21
|
-
fill_circle [0, 0], 30
|
22
|
-
end
|
23
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# If you've read the basic concepts examples you probably know that the origin
|
4
|
-
# of a page is on the bottom left corner and that the content flows from top to
|
5
|
-
# bottom.
|
6
|
-
#
|
7
|
-
# You also know that a Bounding Box is a structure for helping the content flow.
|
8
|
-
#
|
9
|
-
# A bounding box can be created with the <code>bounding_box</code> method. Just
|
10
|
-
# provide the top left corner, a required <code>:width</code> option and an
|
11
|
-
# optional <code>:height</code>.
|
12
|
-
|
13
|
-
require_relative '../example_helper'
|
14
|
-
|
15
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
16
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
17
|
-
bounding_box([200, cursor - 100], width: 200, height: 100) do
|
18
|
-
text 'Just your regular bounding box'
|
19
|
-
|
20
|
-
transparent(0.5) { stroke_bounds }
|
21
|
-
end
|
22
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Sometimes you just need to indent a portion of the contents of a bounding box,
|
4
|
-
# and using a nested bounding box is pure overkill. The <code>indent</code>
|
5
|
-
# method is what you might need.
|
6
|
-
#
|
7
|
-
# Just provide a number for it to indent all content generated inside the
|
8
|
-
# block.
|
9
|
-
|
10
|
-
require_relative '../example_helper'
|
11
|
-
|
12
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
13
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
14
|
-
text 'No indentation on the margin box.'
|
15
|
-
indent(20) do
|
16
|
-
text 'Some indentation inside an indent block.'
|
17
|
-
end
|
18
|
-
move_down 20
|
19
|
-
|
20
|
-
bounding_box([50, cursor], width: 400, height: cursor) do
|
21
|
-
transparent(0.5) { stroke_bounds }
|
22
|
-
|
23
|
-
move_down 10
|
24
|
-
text 'No indentation inside this bounding box.'
|
25
|
-
indent(40) do
|
26
|
-
text 'Inside an indent block. And so is this horizontal line:'
|
27
|
-
|
28
|
-
stroke_horizontal_rule
|
29
|
-
end
|
30
|
-
move_down 10
|
31
|
-
text 'No indentation'
|
32
|
-
|
33
|
-
move_down 20
|
34
|
-
indent(60) do
|
35
|
-
text 'Another indent block.'
|
36
|
-
|
37
|
-
bounding_box([0, cursor], width: 200) do
|
38
|
-
text 'Note that this bounding box coordinates are relative to the ' \
|
39
|
-
'indent block'
|
40
|
-
|
41
|
-
transparent(0.5) { stroke_bounds }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Normally when we provide the top left corner of a bounding box we
|
4
|
-
# express the coordinates relative to the margin box. This is not the
|
5
|
-
# case when we have nested bounding boxes. Once nested the inner bounding box
|
6
|
-
# coordinates are relative to the outter bounding box.
|
7
|
-
#
|
8
|
-
# This example shows some nested bounding boxes with fixed and stretchy heights.
|
9
|
-
# Note how the <code>cursor</code> method returns coordinates relative to
|
10
|
-
# the current bounding box.
|
11
|
-
|
12
|
-
require_relative '../example_helper'
|
13
|
-
|
14
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
15
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
16
|
-
def box_content(string)
|
17
|
-
text string
|
18
|
-
transparent(0.5) { stroke_bounds }
|
19
|
-
end
|
20
|
-
|
21
|
-
gap = 20
|
22
|
-
bounding_box([50, cursor], width: 400, height: 200) do
|
23
|
-
box_content('Fixed height')
|
24
|
-
|
25
|
-
bounding_box([gap, cursor - gap], width: 300) do
|
26
|
-
text 'Stretchy height'
|
27
|
-
|
28
|
-
bounding_box([gap, bounds.top - gap], width: 100) do
|
29
|
-
text 'Stretchy height'
|
30
|
-
transparent(0.5) do
|
31
|
-
dash(1)
|
32
|
-
stroke_bounds
|
33
|
-
undash
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
bounding_box([gap * 7, bounds.top - gap], width: 100, height: 50) do
|
38
|
-
box_content('Fixed height')
|
39
|
-
end
|
40
|
-
|
41
|
-
transparent(0.5) do
|
42
|
-
dash(1)
|
43
|
-
stroke_bounds
|
44
|
-
undash
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
bounding_box([gap, cursor - gap], width: 300, height: 50) do
|
49
|
-
box_content('Fixed height')
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# This example is mostly just for fun, and shows how nested bounding boxes
|
4
|
-
# can simplify calculations. See the "Bounding Box" section of the manual
|
5
|
-
# for more basic uses.
|
6
|
-
|
7
|
-
require_relative '../example_helper'
|
8
|
-
|
9
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
10
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
11
|
-
def combine(horizontal_span, vertical_span)
|
12
|
-
output = []
|
13
|
-
horizontal_span.each do |x|
|
14
|
-
vertical_span.each do |y|
|
15
|
-
output += [[x, y]]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
output
|
19
|
-
end
|
20
|
-
|
21
|
-
def recurse_bounding_box(max_depth = 4, depth = 1)
|
22
|
-
width = (bounds.width - 15) / 2
|
23
|
-
height = (bounds.height - 15) / 2
|
24
|
-
left_top_corners = combine(
|
25
|
-
[5, bounds.right - width - 5],
|
26
|
-
[bounds.top - 5, height + 5]
|
27
|
-
)
|
28
|
-
left_top_corners.each do |lt|
|
29
|
-
bounding_box(lt, width: width, height: height) do
|
30
|
-
stroke_bounds
|
31
|
-
recurse_bounding_box(max_depth, depth + 1) if depth < max_depth
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Set up a bbox from the dashed line to the bottom of the page
|
37
|
-
bounding_box([0, cursor], width: bounds.width, height: cursor) do
|
38
|
-
recurse_bounding_box
|
39
|
-
end
|
40
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Bounding Boxes accept an optional <code>:height</code> parameter. Unless it
|
4
|
-
# is provided the bounding box will be stretchy. It will expand the height to
|
5
|
-
# fit all content generated inside it.
|
6
|
-
|
7
|
-
require_relative '../example_helper'
|
8
|
-
|
9
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
10
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
11
|
-
y_position = cursor
|
12
|
-
bounding_box([0, y_position], width: 200, height: 100) do
|
13
|
-
text 'This bounding box has a height of 100. If this text gets too large ' \
|
14
|
-
'it will flow to the next page.'
|
15
|
-
|
16
|
-
transparent(0.5) { stroke_bounds }
|
17
|
-
end
|
18
|
-
|
19
|
-
bounding_box([300, y_position], width: 200) do
|
20
|
-
text 'This bounding box has variable height. No matter how much text is ' \
|
21
|
-
'written here, the height will expand to fit.'
|
22
|
-
|
23
|
-
text ' _' * 100
|
24
|
-
|
25
|
-
text ' *' * 100
|
26
|
-
|
27
|
-
transparent(0.5) { stroke_bounds }
|
28
|
-
end
|
29
|
-
end
|
data/manual/contents.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Generates the Prawn by example manual.
|
4
|
-
|
5
|
-
require_relative 'example_helper'
|
6
|
-
|
7
|
-
def prawn_manual_document
|
8
|
-
old_default_external_encoding = Encoding.default_external
|
9
|
-
Encoding.default_external = Encoding::UTF_8
|
10
|
-
|
11
|
-
Prawn::ManualBuilder::Example.new(
|
12
|
-
skip_page_creation: true,
|
13
|
-
page_size: 'FOLIO'
|
14
|
-
) do
|
15
|
-
load_page '', 'cover'
|
16
|
-
load_page '', 'how_to_read_this_manual'
|
17
|
-
|
18
|
-
# Core chapters
|
19
|
-
load_package 'basic_concepts'
|
20
|
-
load_package 'graphics'
|
21
|
-
load_package 'text'
|
22
|
-
load_package 'bounding_box'
|
23
|
-
|
24
|
-
# Remaining chapters
|
25
|
-
load_package 'layout'
|
26
|
-
load_page '', 'table'
|
27
|
-
load_package 'images'
|
28
|
-
load_package 'document_and_page_options'
|
29
|
-
load_package 'outline'
|
30
|
-
load_package 'repeatable_content'
|
31
|
-
load_package 'security'
|
32
|
-
end
|
33
|
-
ensure
|
34
|
-
Encoding.default_external = old_default_external_encoding
|
35
|
-
end
|
data/manual/cover.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Prawn manual how to read this manual page.
|
4
|
-
|
5
|
-
require_relative 'example_helper'
|
6
|
-
|
7
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
8
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
9
|
-
move_down 200
|
10
|
-
|
11
|
-
image "#{Prawn::DATADIR}/images/prawn.png",
|
12
|
-
scale: 0.9,
|
13
|
-
at: [10, cursor]
|
14
|
-
|
15
|
-
formatted_text_box(
|
16
|
-
[{ text: "Prawn\n", styles: [:bold], size: 100 }],
|
17
|
-
at: [170, cursor - 50]
|
18
|
-
)
|
19
|
-
|
20
|
-
formatted_text_box(
|
21
|
-
[{ text: 'by example', font: 'Courier', size: 60 }],
|
22
|
-
at: [170, cursor - 160]
|
23
|
-
)
|
24
|
-
|
25
|
-
unless ENV['CI']
|
26
|
-
git_commit =
|
27
|
-
if Dir.exist?("#{Prawn::BASEDIR}/.git")
|
28
|
-
commit = `git show --pretty=%h`
|
29
|
-
"git commit: #{commit.lines.first}"
|
30
|
-
else
|
31
|
-
''
|
32
|
-
end
|
33
|
-
|
34
|
-
formatted_text_box(
|
35
|
-
[{
|
36
|
-
text: "Last Update: #{Time.now.strftime('%Y-%m-%d')}\n" \
|
37
|
-
"Prawn Version: #{Prawn::VERSION}\n#{git_commit}",
|
38
|
-
size: 12
|
39
|
-
}],
|
40
|
-
at: [390, cursor - 620]
|
41
|
-
)
|
42
|
-
end
|
43
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Pass an image path to the <code>:background</code> option and it will be used
|
4
|
-
# as the background for all pages.
|
5
|
-
# This option can only be used on document creation.
|
6
|
-
|
7
|
-
require_relative '../example_helper'
|
8
|
-
|
9
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
10
|
-
|
11
|
-
img = "#{Prawn::DATADIR}/images/letterhead.jpg"
|
12
|
-
|
13
|
-
Prawn::Document.generate(filename, background: img, margin: 100) do
|
14
|
-
text 'My report caption', size: 18, align: :right
|
15
|
-
|
16
|
-
move_down font.height * 2
|
17
|
-
|
18
|
-
text 'Here is my text explaning this report. ' * 20,
|
19
|
-
size: 12, align: :left, leading: 2
|
20
|
-
|
21
|
-
move_down font.height
|
22
|
-
|
23
|
-
text "I'm using a soft background. " * 40,
|
24
|
-
size: 12, align: :left, leading: 2
|
25
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Examples for stamps and repeaters.
|
4
|
-
|
5
|
-
require_relative '../example_helper'
|
6
|
-
|
7
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
8
|
-
Prawn::ManualBuilder::Example.generate(filename, page_size: 'FOLIO') do
|
9
|
-
package 'document_and_page_options' do |p|
|
10
|
-
p.example 'page_size', eval_source: false, full_source: true
|
11
|
-
p.example 'page_margins', eval_source: false, full_source: true
|
12
|
-
p.example 'background', eval_source: false, full_source: true
|
13
|
-
p.example 'metadata', eval_source: false, full_source: true
|
14
|
-
p.example 'print_scaling', eval_source: false, full_source: true
|
15
|
-
|
16
|
-
p.intro do
|
17
|
-
prose <<-TEXT
|
18
|
-
So far we've already seen how to create new documents and start new
|
19
|
-
pages. This chapter expands on the previous examples by showing other
|
20
|
-
options avialable. Some of the options are only available when creating
|
21
|
-
new documents.
|
22
|
-
|
23
|
-
The examples show:
|
24
|
-
TEXT
|
25
|
-
|
26
|
-
list(
|
27
|
-
'How to configure page size',
|
28
|
-
'How to configure page margins',
|
29
|
-
'How to use a background image',
|
30
|
-
'How to add metadata to the generated PDF'
|
31
|
-
)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# To set the document metadata just pass a hash to the <code>:info</code>
|
4
|
-
# option when creating new documents.
|
5
|
-
# The keys in the example below are arbitrary, so you may add whatever keys you
|
6
|
-
# want.
|
7
|
-
|
8
|
-
require_relative '../example_helper'
|
9
|
-
|
10
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
11
|
-
|
12
|
-
info = {
|
13
|
-
Title: 'My title',
|
14
|
-
Author: 'John Doe',
|
15
|
-
Subject: 'My Subject',
|
16
|
-
Keywords: 'test metadata ruby pdf dry',
|
17
|
-
Creator: 'ACME Soft App',
|
18
|
-
Producer: 'Prawn',
|
19
|
-
CreationDate: Time.now
|
20
|
-
}
|
21
|
-
|
22
|
-
Prawn::Document.generate(filename, info: info) do
|
23
|
-
text 'This is a test of setting metadata properties via the info option.'
|
24
|
-
text 'While the keys are arbitrary, the above example sets common attributes.'
|
25
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# The default margin for pages is 0.5 inch but you can change that with the
|
4
|
-
# <code>:margin</code> option or if you'd like to have different margins you
|
5
|
-
# can use the <code>:left_margin</code>, <code>:right_margin</code>,
|
6
|
-
# <code>:top_margin</code>, <code>:bottom_margin</code> options.
|
7
|
-
#
|
8
|
-
# These options are available both for starting new pages and creating new
|
9
|
-
# documents.
|
10
|
-
|
11
|
-
require_relative '../example_helper'
|
12
|
-
|
13
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
14
|
-
Prawn::Document.generate(filename, margin: 100) do
|
15
|
-
text '100 pts margins.'
|
16
|
-
stroke_bounds
|
17
|
-
|
18
|
-
start_new_page(left_margin: 300)
|
19
|
-
text '300 pts margin on the left.'
|
20
|
-
stroke_bounds
|
21
|
-
|
22
|
-
start_new_page(top_margin: 300)
|
23
|
-
text '300 pts margin both on the top and on the left. Notice that whenever ' \
|
24
|
-
'you set an option for a new page it will remain the default for the ' \
|
25
|
-
'following pages.'
|
26
|
-
stroke_bounds
|
27
|
-
|
28
|
-
start_new_page(margin: 50)
|
29
|
-
text '50 pts margins. Using the margin option will reset previous specific ' \
|
30
|
-
'calls to left, right, top and bottom margins.'
|
31
|
-
stroke_bounds
|
32
|
-
|
33
|
-
start_new_page(margin: [50, 100, 150, 200])
|
34
|
-
text 'There is also the shorthand CSS like syntax used here.'
|
35
|
-
stroke_bounds
|
36
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Prawn comes with support for most of the common page sizes so you'll only need
|
4
|
-
# to provide specific values if your intended format is not supported. To see a
|
5
|
-
# list with all supported sizes take a look at PDF::Core::PageGeometry
|
6
|
-
#
|
7
|
-
# # To define the size use <code>:page_size</code> when creating new documents
|
8
|
-
# and <code>:size</code> when starting new pages. The default page size for new
|
9
|
-
# documents is LETTER (612.00 x 792.00).
|
10
|
-
#
|
11
|
-
# You may also define the orientation of the page to be either portrait
|
12
|
-
# (default) or landscape. Use <code>:page_layout</code> when creating new
|
13
|
-
# documents and <code>:layout</code> when starting new pages.
|
14
|
-
|
15
|
-
require_relative '../example_helper'
|
16
|
-
|
17
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
18
|
-
Prawn::Document.generate(
|
19
|
-
filename,
|
20
|
-
page_size: 'EXECUTIVE',
|
21
|
-
page_layout: :landscape
|
22
|
-
) do
|
23
|
-
text 'EXECUTIVE landscape page.'
|
24
|
-
|
25
|
-
custom_size = [275, 326]
|
26
|
-
|
27
|
-
['A4', 'TABLOID', 'B7', custom_size].each do |size|
|
28
|
-
start_new_page(size: size, layout: :portrait)
|
29
|
-
text "#{size} portrait page."
|
30
|
-
|
31
|
-
start_new_page(size: size, layout: :landscape)
|
32
|
-
text "#{size} landscape page."
|
33
|
-
end
|
34
|
-
end
|