prawn 2.4.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 +213 -141
- data/lib/prawn/document/column_box.rb +61 -26
- data/lib/prawn/document/internals.rb +25 -16
- data/lib/prawn/document/span.rb +20 -18
- data/lib/prawn/document.rb +257 -171
- data/lib/prawn/encoding.rb +2 -5
- data/lib/prawn/errors.rb +23 -34
- data/lib/prawn/font.rb +248 -135
- data/lib/prawn/font_metric_cache.rb +11 -10
- data/lib/prawn/fonts/afm.rb +85 -45
- 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 +305 -93
- 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 +57 -34
- data/lib/prawn/graphics/dash.rb +45 -42
- data/lib/prawn/graphics/join_style.rb +17 -11
- data/lib/prawn/graphics/patterns.rb +190 -69
- data/lib/prawn/graphics/transformation.rb +48 -41
- data/lib/prawn/graphics/transparency.rb +16 -40
- data/lib/prawn/graphics.rb +363 -253
- data/lib/prawn/grid.rb +184 -57
- data/lib/prawn/image_handler.rb +27 -10
- data/lib/prawn/images/image.rb +8 -10
- data/lib/prawn/images/jpg.rb +42 -19
- data/lib/prawn/images/png.rb +92 -41
- data/lib/prawn/images.rb +44 -57
- data/lib/prawn/measurement_extensions.rb +39 -8
- data/lib/prawn/measurements.rb +60 -5
- data/lib/prawn/outline.rb +114 -108
- data/lib/prawn/repeater.rb +51 -35
- data/lib/prawn/security/arcfour.rb +4 -4
- data/lib/prawn/security.rb +75 -70
- data/lib/prawn/soft_mask.rb +42 -30
- data/lib/prawn/stamp.rb +38 -42
- data/lib/prawn/text/box.rb +146 -96
- data/lib/prawn/text/formatted/arranger.rb +87 -26
- data/lib/prawn/text/formatted/box.rb +221 -150
- data/lib/prawn/text/formatted/fragment.rb +130 -14
- data/lib/prawn/text/formatted/line_wrap.rb +33 -24
- data/lib/prawn/text/formatted/parser.rb +112 -72
- data/lib/prawn/text/formatted/wrap.rb +12 -17
- data/lib/prawn/text/formatted.rb +75 -0
- data/lib/prawn/text.rb +441 -196
- 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 +68 -53
- data/lib/prawn.rb +23 -18
- data.tar.gz.sig +0 -0
- metadata +54 -177
- metadata.gz.sig +0 -0
- data/.yardopts +0 -10
- data/Gemfile +0 -5
- data/Rakefile +0 -25
- 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 -29
- 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 -23
- 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 -38
- data/manual/graphics/gradients.rb +0 -43
- data/manual/graphics/graphics.rb +0 -64
- data/manual/graphics/helper.rb +0 -34
- 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 -29
- 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 -30
- 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 -43
- 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 -25
- data/manual/text/formatted_callbacks.rb +0 -70
- data/manual/text/formatted_text.rb +0 -61
- 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 -31
- 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 -52
- 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 -51
- data/manual/text/utf8.rb +0 -27
- data/manual/text/win_ansi_charset.rb +0 -62
- data/prawn.gemspec +0 -51
- data/spec/data/curves.pdf +0 -66
- data/spec/extensions/encoding_helpers.rb +0 -11
- data/spec/prawn/document/bounding_box_spec.rb +0 -550
- 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 -44
- data/spec/prawn/document_spec.rb +0 -805
- data/spec/prawn/font_metric_cache_spec.rb +0 -54
- data/spec/prawn/font_spec.rb +0 -544
- 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 -872
- 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 -229
- data/spec/prawn/measurements_extensions_spec.rb +0 -24
- data/spec/prawn/outline_spec.rb +0 -512
- data/spec/prawn/repeater_spec.rb +0 -166
- data/spec/prawn/soft_mask_spec.rb +0 -74
- data/spec/prawn/stamp_spec.rb +0 -173
- data/spec/prawn/text/box_spec.rb +0 -1110
- data/spec/prawn/text/formatted/arranger_spec.rb +0 -466
- data/spec/prawn/text/formatted/box_spec.rb +0 -849
- data/spec/prawn/text/formatted/fragment_spec.rb +0 -343
- data/spec/prawn/text/formatted/line_wrap_spec.rb +0 -495
- data/spec/prawn/text/formatted/parser_spec.rb +0 -697
- data/spec/prawn/text_draw_text_spec.rb +0 -150
- 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,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# The join style defines how the intersection between two lines is drawn. There
|
4
|
-
# are three types: <code>:miter</code> (the default), <code>:round</code> and
|
5
|
-
# <code>:bevel</code>
|
6
|
-
#
|
7
|
-
# Just like <code>cap_style</code>, the difference between styles is better
|
8
|
-
# seen with thicker lines.
|
9
|
-
|
10
|
-
require_relative '../example_helper'
|
11
|
-
|
12
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
13
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
14
|
-
stroke_axis
|
15
|
-
|
16
|
-
self.line_width = 25
|
17
|
-
|
18
|
-
%i[miter round bevel].each_with_index do |style, i|
|
19
|
-
self.join_style = style
|
20
|
-
|
21
|
-
y = 200 - i * 100
|
22
|
-
stroke do
|
23
|
-
move_to(100, y)
|
24
|
-
line_to(200, y + 100)
|
25
|
-
line_to(300, y)
|
26
|
-
end
|
27
|
-
stroke_rectangle [400, y + 75], 50, 50
|
28
|
-
end
|
29
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# This transformation is used to translate the user space. Just provide the
|
4
|
-
# x and y coordinates for the new origin.
|
5
|
-
|
6
|
-
require_relative '../example_helper'
|
7
|
-
|
8
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
9
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
10
|
-
stroke_axis
|
11
|
-
|
12
|
-
1.upto(3) do |i|
|
13
|
-
x = i * 50
|
14
|
-
y = i * 100
|
15
|
-
translate(x, y) do
|
16
|
-
# Draw a point on the new origin
|
17
|
-
fill_circle [0, 0], 2
|
18
|
-
draw_text "New origin after translation to [#{x}, #{y}]",
|
19
|
-
at: [5, -2],
|
20
|
-
size: 8
|
21
|
-
|
22
|
-
stroke_rectangle [100, 75], 100, 50
|
23
|
-
text_box 'Top left corner at [100,75]',
|
24
|
-
at: [110, 65],
|
25
|
-
width: 80,
|
26
|
-
size: 8
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Although the name of the method is <code>transparency</code>, what we are
|
4
|
-
# actually setting is the opacity for fill and stroke. So <code>0</code> means
|
5
|
-
# completely transparent and <code>1.0</code> means completely opaque
|
6
|
-
#
|
7
|
-
# You may call it providing one or two values. The first value sets fill opacity
|
8
|
-
# and the second value sets stroke opacity. If the second value is omitted fill
|
9
|
-
# and stroke will have the same opacity.
|
10
|
-
|
11
|
-
require_relative '../example_helper'
|
12
|
-
|
13
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
14
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
15
|
-
stroke_axis
|
16
|
-
|
17
|
-
self.line_width = 5
|
18
|
-
fill_color 'ff0000'
|
19
|
-
fill_rectangle [0, 100], 500, 100
|
20
|
-
|
21
|
-
fill_color '000000'
|
22
|
-
stroke_color 'ffffff'
|
23
|
-
|
24
|
-
base_x = 100
|
25
|
-
[[0.5, 1], 0.5, [1, 0.5]].each do |args|
|
26
|
-
transparent(*args) do
|
27
|
-
fill_circle [base_x, 100], 50
|
28
|
-
stroke_rectangle [base_x - 20, 100], 40, 80
|
29
|
-
end
|
30
|
-
|
31
|
-
base_x += 150
|
32
|
-
end
|
33
|
-
end
|
@@ -1,39 +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
|
-
header('How to read this manual')
|
10
|
-
|
11
|
-
prose <<-END_TEXT
|
12
|
-
This manual is a collection of examples categorized by theme and organized from the least to the most complex. While it covers most of the common use cases it is not a comprehensive guide.
|
13
|
-
|
14
|
-
The best way to read it depends on your previous knowledge of Prawn and what you need to accomplish.
|
15
|
-
|
16
|
-
If you are beginning with Prawn the first chapter will teach you the most basic concepts and how to create pdf documents. For an overview of the other features each chapter beyond the first either has a Basics section (which offer enough insight on the feature without showing all the advanced stuff you might never use) or is simple enough with only a few examples.
|
17
|
-
|
18
|
-
Once you understand the basics you might want to come back to this manual looking for examples that accomplish tasks you need.
|
19
|
-
|
20
|
-
Advanced users are encouraged to go beyond this manual and read the source code directly if any doubt is not directly covered on this manual.
|
21
|
-
END_TEXT
|
22
|
-
|
23
|
-
move_down(Prawn::ManualBuilder::Example::BOX_MARGIN)
|
24
|
-
header('Reading the examples')
|
25
|
-
|
26
|
-
prose <<-END_TEXT
|
27
|
-
The title of each example is the relative path from the Prawn source manual/ folder.
|
28
|
-
|
29
|
-
The first body of text is the introductory text for the example. Generally it is a short description of the features illustrated by the example.
|
30
|
-
|
31
|
-
Next comes the example source code block in fixed width font.
|
32
|
-
|
33
|
-
Most of the example snippets illustrate features that alter the page in place. The effect of these snippets is shown right below a dashed line. If it doesn't make sense to evaluate the snippet inline, a box with the link for the example file is shown instead.
|
34
|
-
|
35
|
-
Note that the <code>stroke_axis</code> method used throughout the manual is part of standard Prawn. It is defined in this file:
|
36
|
-
|
37
|
-
https://github.com/prawnpdf/prawn/blob/master/lib/prawn/graphics.rb
|
38
|
-
END_TEXT
|
39
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# One of the options that the <code>image</code> method accepts is
|
4
|
-
# <code>:at</code>. If you've read some of the graphics examples you are
|
5
|
-
# probably already familiar with it. Just provide it the upper-left corner where
|
6
|
-
# you want the image placed.
|
7
|
-
#
|
8
|
-
# While sometimes useful this option won't be practical. Notice that the cursor
|
9
|
-
# won't be moved after the image is rendered and there is nothing forbidding the
|
10
|
-
# text to overlap with the image.
|
11
|
-
|
12
|
-
require_relative '../example_helper'
|
13
|
-
|
14
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
15
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
16
|
-
y_position = cursor
|
17
|
-
text "The image won't go below this line of text."
|
18
|
-
|
19
|
-
image "#{Prawn::DATADIR}/images/fractal.jpg", at: [200, y_position]
|
20
|
-
|
21
|
-
text 'And this line of text will go just below the previous one.'
|
22
|
-
end
|
data/manual/images/fit.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# <code>:fit</code> option is useful when you want the image to have the
|
4
|
-
# maximum size within a container preserving the aspect ratio without
|
5
|
-
# overlapping.
|
6
|
-
#
|
7
|
-
# Just provide the container width and height pair.
|
8
|
-
|
9
|
-
require_relative '../example_helper'
|
10
|
-
|
11
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
12
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
13
|
-
size = 300
|
14
|
-
|
15
|
-
text 'Using the fit option'
|
16
|
-
bounding_box([0, cursor], width: size, height: size) do
|
17
|
-
image "#{Prawn::DATADIR}/images/pigs.jpg", fit: [size, size]
|
18
|
-
stroke_bounds
|
19
|
-
end
|
20
|
-
end
|
data/manual/images/horizontal.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# The image may be positioned relatively to the current bounding box. The
|
4
|
-
# horizontal position may be set with the <code>:position</code> option.
|
5
|
-
#
|
6
|
-
# It may be <code>:left</code>, <code>:center</code>, <code>:right</code> or a
|
7
|
-
# number representing an x-offset from the left boundary.
|
8
|
-
|
9
|
-
require_relative '../example_helper'
|
10
|
-
|
11
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
12
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
13
|
-
bounding_box([50, cursor], width: 400, height: 450) do
|
14
|
-
stroke_bounds
|
15
|
-
|
16
|
-
%i[left center right].each do |position|
|
17
|
-
text "Image aligned to the #{position}."
|
18
|
-
image "#{Prawn::DATADIR}/images/stef.jpg", position: position
|
19
|
-
end
|
20
|
-
|
21
|
-
text 'The next image has a 50 point offset from the left boundary'
|
22
|
-
image "#{Prawn::DATADIR}/images/stef.jpg", position: 50
|
23
|
-
end
|
24
|
-
end
|
data/manual/images/images.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Examples for embedding images.
|
4
|
-
|
5
|
-
require_relative '../example_helper'
|
6
|
-
|
7
|
-
Prawn::ManualBuilder::Example.generate('images.pdf', page_size: 'FOLIO') do
|
8
|
-
package 'images' do |p|
|
9
|
-
p.section 'Basics' do |s|
|
10
|
-
s.example 'plain_image'
|
11
|
-
s.example 'absolute_position'
|
12
|
-
end
|
13
|
-
|
14
|
-
p.section 'Relative Positioning' do |s|
|
15
|
-
s.example 'horizontal'
|
16
|
-
s.example 'vertical'
|
17
|
-
end
|
18
|
-
|
19
|
-
p.section 'Size' do |s|
|
20
|
-
s.example 'width_and_height'
|
21
|
-
s.example 'scale'
|
22
|
-
s.example 'fit'
|
23
|
-
end
|
24
|
-
|
25
|
-
p.intro do
|
26
|
-
prose <<-TEXT
|
27
|
-
Embedding images on PDF documents is fairly easy. Prawn supports both
|
28
|
-
JPG and PNG images.
|
29
|
-
|
30
|
-
The examples show:
|
31
|
-
TEXT
|
32
|
-
|
33
|
-
list(
|
34
|
-
'How to add an image to a page',
|
35
|
-
'How place the image on a specific position',
|
36
|
-
'How to configure the image dimensions by setting the width and '\
|
37
|
-
'height or by scaling it'
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# To embed images onto your PDF file use the <code>image</code> method.
|
4
|
-
# It accepts the file path of the image to be loaded and some optional
|
5
|
-
# arguments.
|
6
|
-
#
|
7
|
-
# If only the image path is provided the image will be rendered starting on
|
8
|
-
# the cursor position. No manipulation is done with the image even if it doesn't
|
9
|
-
# fit entirely on the page like the following snippet.
|
10
|
-
|
11
|
-
require_relative '../example_helper'
|
12
|
-
|
13
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
14
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
15
|
-
text 'The image will go right below this line of text.'
|
16
|
-
image "#{Prawn::DATADIR}/images/pigs.jpg"
|
17
|
-
end
|
data/manual/images/scale.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# To scale an image use the <code>:scale</code> option.
|
4
|
-
#
|
5
|
-
# It scales the image proportionally given the provided value.
|
6
|
-
|
7
|
-
require_relative '../example_helper'
|
8
|
-
|
9
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
10
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
11
|
-
text 'Normal size'
|
12
|
-
image "#{Prawn::DATADIR}/images/stef.jpg"
|
13
|
-
move_down 20
|
14
|
-
|
15
|
-
text 'Scaled to 50%'
|
16
|
-
image "#{Prawn::DATADIR}/images/stef.jpg", scale: 0.5
|
17
|
-
move_down 20
|
18
|
-
|
19
|
-
text 'Scaled to 200%'
|
20
|
-
image "#{Prawn::DATADIR}/images/stef.jpg", scale: 2
|
21
|
-
end
|
data/manual/images/vertical.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# To set the vertical position of an image use the <code>:vposition</code>
|
4
|
-
# option.
|
5
|
-
#
|
6
|
-
# It may be <code>:top</code>, <code>:center</code>, <code>:bottom</code> or a
|
7
|
-
# number representing the y-offset from the top boundary.
|
8
|
-
|
9
|
-
require_relative '../example_helper'
|
10
|
-
|
11
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
12
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
13
|
-
bounding_box([0, cursor], width: 500, height: 450) do
|
14
|
-
stroke_bounds
|
15
|
-
|
16
|
-
%i[top center bottom].each do |vposition|
|
17
|
-
text "Image vertically aligned to the #{vposition}.", valign: vposition
|
18
|
-
image "#{Prawn::DATADIR}/images/stef.jpg",
|
19
|
-
position: 250,
|
20
|
-
vposition: vposition
|
21
|
-
end
|
22
|
-
|
23
|
-
text_box 'The next image has a 100 point offset from the top boundary',
|
24
|
-
at: [bounds.width - 110, bounds.top - 10],
|
25
|
-
width: 100
|
26
|
-
image "#{Prawn::DATADIR}/images/stef.jpg",
|
27
|
-
position: :right,
|
28
|
-
vposition: 100
|
29
|
-
end
|
30
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# The image size can be set with the <code>:width</code> and
|
4
|
-
# <code>:height</code> options.
|
5
|
-
#
|
6
|
-
# If only one of those is provided, the image will be scaled proportionally.
|
7
|
-
# When both are provided, the image will be stretched to fit the dimensions
|
8
|
-
# without maintaining the aspect ratio.
|
9
|
-
|
10
|
-
require_relative '../example_helper'
|
11
|
-
|
12
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
13
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
14
|
-
text 'Scale by setting only the width'
|
15
|
-
image "#{Prawn::DATADIR}/images/pigs.jpg", width: 150
|
16
|
-
move_down 20
|
17
|
-
|
18
|
-
text 'Scale by setting only the height'
|
19
|
-
image "#{Prawn::DATADIR}/images/pigs.jpg", height: 100
|
20
|
-
move_down 20
|
21
|
-
|
22
|
-
text 'Stretch to fit the width and height provided'
|
23
|
-
image "#{Prawn::DATADIR}/images/pigs.jpg", width: 500, height: 100
|
24
|
-
end
|
data/manual/layout/boxes.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# After defined the grid is there but nothing happens. To start taking effect
|
4
|
-
# we need to use the grid boxes.
|
5
|
-
#
|
6
|
-
# <code>grid</code> has three different return values based on the arguments
|
7
|
-
# received. With no arguments it will return the grid itself. With integers it
|
8
|
-
# will return the grid box at those indices. With two arrays it will return a
|
9
|
-
# multi-box spanning the region of the two grid boxes at the arrays indices.
|
10
|
-
|
11
|
-
require_relative '../example_helper'
|
12
|
-
|
13
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
14
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
15
|
-
# The grid only need to be defined once, but since all the examples should be
|
16
|
-
# able to run alone we are repeating it on every example
|
17
|
-
define_grid(columns: 5, rows: 8, gutter: 10)
|
18
|
-
|
19
|
-
grid(4, 0).show
|
20
|
-
grid(5, 1).show
|
21
|
-
|
22
|
-
grid([6, 2], [7, 3]).show
|
23
|
-
|
24
|
-
grid([4, 4], [7, 4]).show
|
25
|
-
grid([7, 0], [7, 1]).show
|
26
|
-
end
|
data/manual/layout/content.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Now that we know how to access the boxes we might as well add some content
|
4
|
-
# to them.
|
5
|
-
#
|
6
|
-
# This can be done by taping into the bounding box for a given grid box or
|
7
|
-
# multi-box with the <code>bounding_box</code> method.
|
8
|
-
|
9
|
-
require_relative '../example_helper'
|
10
|
-
|
11
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
12
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
13
|
-
# The grid only need to be defined once, but since all the examples should be
|
14
|
-
# able to run alone we are repeating it on every example
|
15
|
-
define_grid(columns: 5, rows: 8, gutter: 10)
|
16
|
-
|
17
|
-
grid([5, 0], [7, 1]).bounding_box do
|
18
|
-
text "Adding some content to this multi_box.\n#{' _ ' * 200}"
|
19
|
-
end
|
20
|
-
|
21
|
-
grid(6, 3).bounding_box do
|
22
|
-
text "Just a little snippet here.\n#{' _ ' * 10}"
|
23
|
-
end
|
24
|
-
end
|
data/manual/layout/layout.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Examples for using grid layouts.
|
4
|
-
|
5
|
-
require_relative '../example_helper'
|
6
|
-
|
7
|
-
Prawn::ManualBuilder::Example.generate('layout.pdf', page_size: 'FOLIO') do
|
8
|
-
package 'layout' do |p|
|
9
|
-
p.example 'simple_grid'
|
10
|
-
p.example 'boxes'
|
11
|
-
p.example 'content'
|
12
|
-
|
13
|
-
p.intro do
|
14
|
-
prose <<-TEXT
|
15
|
-
Prawn has support for two-dimensional grid based layouts out of the box.
|
16
|
-
|
17
|
-
The examples show:
|
18
|
-
TEXT
|
19
|
-
|
20
|
-
list(
|
21
|
-
'How to define the document grid',
|
22
|
-
'How to configure the grid rows and columns gutters',
|
23
|
-
'How to create boxes according to the grid'
|
24
|
-
)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# The document grid on Prawn is just a table-like structure with a defined
|
4
|
-
# number of rows and columns. There are some helpers to create boxes of content
|
5
|
-
# based on the grid coordinates.
|
6
|
-
#
|
7
|
-
# <code>define_grid</code> accepts the following options which are pretty much
|
8
|
-
# self-explanatory: <code>:rows</code>, <code>:columns</code>,
|
9
|
-
# <code>:gutter</code>, <code>:row_gutter</code>, <code>:column_gutter</code>
|
10
|
-
|
11
|
-
require_relative '../example_helper'
|
12
|
-
|
13
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
14
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
15
|
-
# The grid only need to be defined once, but since all the examples should be
|
16
|
-
# able to run alone we are repeating it on every example
|
17
|
-
define_grid(columns: 5, rows: 8, gutter: 10)
|
18
|
-
text 'We defined the grid, roll over to the next page to see its outline'
|
19
|
-
|
20
|
-
start_new_page
|
21
|
-
grid.show_all
|
22
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# We have already seen how to define an outline tree sequentially.
|
4
|
-
#
|
5
|
-
# If you'd like to add nodes to the middle of an outline tree the
|
6
|
-
# <code>add_subsection_to</code> may help you.
|
7
|
-
#
|
8
|
-
# It allows you to insert sections to the outline tree at any point. Just
|
9
|
-
# provide the <code>title</code> of the parent section, the
|
10
|
-
# <code>position</code> you want the new subsection to be inserted
|
11
|
-
# <code>:first</code> or <code>:last</code> (defaults to <code>:last</code>)
|
12
|
-
# and a block to declare the subsection.
|
13
|
-
#
|
14
|
-
# The <code>add_subsection_to</code> block doesn't necessarily create new
|
15
|
-
# sections, it may also create new pages.
|
16
|
-
#
|
17
|
-
# If the parent title provided is the title of a page. The page will be
|
18
|
-
# converted into a section to receive the subsection created.
|
19
|
-
|
20
|
-
require_relative '../example_helper'
|
21
|
-
|
22
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
23
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
24
|
-
# First we create 10 pages and some default outline
|
25
|
-
(1..10).each do |index|
|
26
|
-
text "Page #{index}"
|
27
|
-
start_new_page
|
28
|
-
end
|
29
|
-
|
30
|
-
outline.define do
|
31
|
-
section('Section 1', destination: 1) do
|
32
|
-
page title: 'Page 2', destination: 2
|
33
|
-
page title: 'Page 3', destination: 3
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Now we will start adding nodes to the previous outline
|
38
|
-
outline.add_subsection_to('Section 1', :first) do
|
39
|
-
outline.section('Added later - first position') do
|
40
|
-
outline.page title: 'Page 4', destination: 4
|
41
|
-
outline.page title: 'Page 5', destination: 5
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
outline.add_subsection_to('Section 1') do
|
46
|
-
outline.page title: 'Added later - last position',
|
47
|
-
destination: 6
|
48
|
-
end
|
49
|
-
|
50
|
-
outline.add_subsection_to('Added later - first position') do
|
51
|
-
outline.page title: 'Another page added later',
|
52
|
-
destination: 7
|
53
|
-
end
|
54
|
-
|
55
|
-
# The title provided is for a page which will be converted into a section
|
56
|
-
outline.add_subsection_to('Page 3') do
|
57
|
-
outline.page title: 'Last page added',
|
58
|
-
destination: 8
|
59
|
-
end
|
60
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Another way to insert nodes into an existing outline is the
|
4
|
-
# <code>insert_section_after</code> method.
|
5
|
-
#
|
6
|
-
# It accepts the title of the node that the new section will go after and a
|
7
|
-
# block declaring the new section.
|
8
|
-
#
|
9
|
-
# As is the case with <code>add_subsection_to</code> the section added
|
10
|
-
# doesn't need to be a section, it may be just a page.
|
11
|
-
|
12
|
-
require_relative '../example_helper'
|
13
|
-
|
14
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
15
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
16
|
-
# First we create 10 pages and some default outline
|
17
|
-
(1..10).each do |index|
|
18
|
-
text "Page #{index}"
|
19
|
-
start_new_page
|
20
|
-
end
|
21
|
-
|
22
|
-
outline.define do
|
23
|
-
section('Section 1', destination: 1) do
|
24
|
-
page title: 'Page 2', destination: 2
|
25
|
-
page title: 'Page 3', destination: 3
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# Now we will start adding nodes to the previous outline
|
30
|
-
outline.insert_section_after('Page 2') do
|
31
|
-
outline.section('Section after Page 2') do
|
32
|
-
outline.page title: 'Page 4', destination: 4
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
outline.insert_section_after('Section 1') do
|
37
|
-
outline.section('Section after Section 1') do
|
38
|
-
outline.page title: 'Page 5', destination: 5
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Adding just a page
|
43
|
-
outline.insert_section_after('Page 3') do
|
44
|
-
outline.page title: 'Page after Page 3', destination: 6
|
45
|
-
end
|
46
|
-
end
|
data/manual/outline/outline.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Examples for defining the document outline.
|
4
|
-
|
5
|
-
require_relative '../example_helper'
|
6
|
-
|
7
|
-
Prawn::ManualBuilder::Example.generate('outline.pdf', page_size: 'FOLIO') do
|
8
|
-
package 'outline' do |p|
|
9
|
-
p.section 'Basics' do |s|
|
10
|
-
s.example 'sections_and_pages', eval_source: false
|
11
|
-
end
|
12
|
-
|
13
|
-
p.section 'Adding nodes later' do |s|
|
14
|
-
s.example 'add_subsection_to', eval_source: false
|
15
|
-
s.example 'insert_section_after', eval_source: false
|
16
|
-
end
|
17
|
-
|
18
|
-
p.intro do
|
19
|
-
prose <<-TEXT
|
20
|
-
The outline of a PDF document is the table of contents tab you see to
|
21
|
-
the right or left of your PDF viewer.
|
22
|
-
|
23
|
-
The examples include:
|
24
|
-
TEXT
|
25
|
-
|
26
|
-
list(
|
27
|
-
'How to define sections and pages',
|
28
|
-
'How to insert sections and/or pages to a previously defined outline '\
|
29
|
-
'structure'
|
30
|
-
)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# The document outline tree is the set of links used to navigate through the
|
4
|
-
# various document sections and pages.
|
5
|
-
#
|
6
|
-
# To define the document outline we first use the <code>outline</code>
|
7
|
-
# method to lazily instantiate an outline object. Then we use the
|
8
|
-
# <code>define</code> method with a block to start the outline tree.
|
9
|
-
#
|
10
|
-
# The basic methods for creating outline nodes are <code>section</code> and
|
11
|
-
# <code>page</code>. The only difference between the two is that
|
12
|
-
# <code>page</code> doesn't accept a block and will only create leaf nodes
|
13
|
-
# while <code>section</code> accepts a block to create nested nodes.
|
14
|
-
#
|
15
|
-
# <code>section</code> accepts the title of the section and two options:
|
16
|
-
# <code>:destination</code> - a page number to link and <code>:closed</code> -
|
17
|
-
# a boolean value that defines if the nested outline nodes are shown when the
|
18
|
-
# document is open (defaults to true).
|
19
|
-
#
|
20
|
-
# <code>page</code> is very similar to section. It requires a
|
21
|
-
# <code>:title</code> option to be set and accepts a <code>:destination</code>.
|
22
|
-
#
|
23
|
-
# <code>section</code> and <code>page</code> may also be used without the
|
24
|
-
# <code>define</code> method but they will need to instantiate the
|
25
|
-
# <code>outline</code> object every time.
|
26
|
-
|
27
|
-
require_relative '../example_helper'
|
28
|
-
|
29
|
-
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
30
|
-
Prawn::ManualBuilder::Example.generate(filename) do
|
31
|
-
# First we create 10 pages just to have something to link to
|
32
|
-
(1..10).each do |index|
|
33
|
-
text "Page #{index}"
|
34
|
-
start_new_page
|
35
|
-
end
|
36
|
-
|
37
|
-
outline.define do
|
38
|
-
section('Section 1', destination: 1) do
|
39
|
-
page title: 'Page 2', destination: 2
|
40
|
-
page title: 'Page 3', destination: 3
|
41
|
-
end
|
42
|
-
|
43
|
-
section('Section 2', destination: 4) do
|
44
|
-
page title: 'Page 5', destination: 5
|
45
|
-
|
46
|
-
section('Subsection 2.1', destination: 6, closed: true) do
|
47
|
-
page title: 'Page 7', destination: 7
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# Outside of the define block
|
53
|
-
outline.section('Section 3', destination: 8) do
|
54
|
-
outline.page title: 'Page 9', destination: 9
|
55
|
-
end
|
56
|
-
|
57
|
-
outline.page title: 'Page 10', destination: 10
|
58
|
-
|
59
|
-
# Section and Pages without links. While a section without a link may be
|
60
|
-
# useful to group some pages, a page without a link is useless
|
61
|
-
outline.update do # update is an alias to define
|
62
|
-
section('Section without link') do
|
63
|
-
page title: 'Page without link'
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|