prawn-git 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +10 -0
- data/COPYING +2 -0
- data/GPLv2 +340 -0
- data/GPLv3 +674 -0
- data/Gemfile +11 -0
- data/LICENSE +56 -0
- data/Rakefile +55 -0
- data/data/fonts/Courier-Bold.afm +342 -0
- data/data/fonts/Courier-BoldOblique.afm +342 -0
- data/data/fonts/Courier-Oblique.afm +342 -0
- data/data/fonts/Courier.afm +342 -0
- data/data/fonts/Helvetica-Bold.afm +2827 -0
- data/data/fonts/Helvetica-BoldOblique.afm +2827 -0
- data/data/fonts/Helvetica-Oblique.afm +3051 -0
- data/data/fonts/Helvetica.afm +3051 -0
- data/data/fonts/MustRead.html +19 -0
- data/data/fonts/Symbol.afm +213 -0
- data/data/fonts/Times-Bold.afm +2588 -0
- data/data/fonts/Times-BoldItalic.afm +2384 -0
- data/data/fonts/Times-Italic.afm +2667 -0
- data/data/fonts/Times-Roman.afm +2419 -0
- data/data/fonts/ZapfDingbats.afm +225 -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 +8 -0
- 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 +1 -0
- 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 +820 -0
- data/data/pdfs/hexagon.pdf +61 -0
- data/data/pdfs/indirect_reference.pdf +86 -0
- data/data/pdfs/multipage_template.pdf +127 -0
- data/data/pdfs/nested_pages.pdf +118 -0
- data/data/pdfs/page_without_mediabox.pdf +193 -0
- data/data/pdfs/resources_as_indirect_object.pdf +83 -0
- data/data/pdfs/two_hexagons.pdf +90 -0
- data/data/pdfs/version_1_6.pdf +61 -0
- data/data/shift_jis_text.txt +1 -0
- data/lib/prawn.rb +89 -0
- data/lib/prawn/document.rb +706 -0
- data/lib/prawn/document/bounding_box.rb +539 -0
- data/lib/prawn/document/column_box.rb +144 -0
- data/lib/prawn/document/internals.rb +58 -0
- data/lib/prawn/document/span.rb +57 -0
- data/lib/prawn/encoding.rb +87 -0
- data/lib/prawn/errors.rb +80 -0
- data/lib/prawn/font.rb +413 -0
- data/lib/prawn/font/afm.rb +256 -0
- data/lib/prawn/font/dfont.rb +43 -0
- data/lib/prawn/font/ttf.rb +355 -0
- data/lib/prawn/font_metric_cache.rb +46 -0
- data/lib/prawn/graphics.rb +646 -0
- data/lib/prawn/graphics/cap_style.rb +47 -0
- data/lib/prawn/graphics/color.rb +232 -0
- data/lib/prawn/graphics/dash.rb +109 -0
- data/lib/prawn/graphics/join_style.rb +49 -0
- data/lib/prawn/graphics/patterns.rb +126 -0
- data/lib/prawn/graphics/transformation.rb +157 -0
- data/lib/prawn/graphics/transparency.rb +101 -0
- data/lib/prawn/grid.rb +279 -0
- data/lib/prawn/image_handler.rb +44 -0
- data/lib/prawn/images.rb +199 -0
- data/lib/prawn/images/image.rb +49 -0
- data/lib/prawn/images/jpg.rb +91 -0
- data/lib/prawn/images/png.rb +290 -0
- data/lib/prawn/measurement_extensions.rb +50 -0
- data/lib/prawn/measurements.rb +77 -0
- data/lib/prawn/outline.rb +289 -0
- data/lib/prawn/repeater.rb +124 -0
- data/lib/prawn/security.rb +288 -0
- data/lib/prawn/security/arcfour.rb +54 -0
- data/lib/prawn/soft_mask.rb +94 -0
- data/lib/prawn/stamp.rb +136 -0
- data/lib/prawn/text.rb +437 -0
- data/lib/prawn/text/box.rb +141 -0
- data/lib/prawn/text/formatted.rb +7 -0
- data/lib/prawn/text/formatted/arranger.rb +290 -0
- data/lib/prawn/text/formatted/box.rb +614 -0
- data/lib/prawn/text/formatted/fragment.rb +264 -0
- data/lib/prawn/text/formatted/line_wrap.rb +277 -0
- data/lib/prawn/text/formatted/parser.rb +224 -0
- data/lib/prawn/text/formatted/wrap.rb +160 -0
- data/lib/prawn/utilities.rb +46 -0
- data/lib/prawn/version.rb +5 -0
- data/lib/prawn/view.rb +91 -0
- data/manual/absolute_position.pdf +0 -0
- data/manual/basic_concepts/adding_pages.rb +27 -0
- data/manual/basic_concepts/basic_concepts.rb +36 -0
- data/manual/basic_concepts/creation.rb +39 -0
- data/manual/basic_concepts/cursor.rb +33 -0
- data/manual/basic_concepts/measurement.rb +25 -0
- data/manual/basic_concepts/origin.rb +38 -0
- data/manual/basic_concepts/other_cursor_helpers.rb +40 -0
- data/manual/basic_concepts/view.rb +42 -0
- data/manual/bounding_box/bounding_box.rb +39 -0
- data/manual/bounding_box/bounds.rb +49 -0
- data/manual/bounding_box/canvas.rb +24 -0
- data/manual/bounding_box/creation.rb +23 -0
- data/manual/bounding_box/indentation.rb +46 -0
- data/manual/bounding_box/nesting.rb +45 -0
- data/manual/bounding_box/russian_boxes.rb +40 -0
- data/manual/bounding_box/stretchy.rb +31 -0
- data/manual/contents.rb +29 -0
- data/manual/cover.rb +39 -0
- data/manual/document_and_page_options/background.rb +27 -0
- data/manual/document_and_page_options/document_and_page_options.rb +32 -0
- data/manual/document_and_page_options/metadata.rb +23 -0
- data/manual/document_and_page_options/page_margins.rb +38 -0
- data/manual/document_and_page_options/page_size.rb +34 -0
- data/manual/document_and_page_options/print_scaling.rb +20 -0
- data/manual/example_helper.rb +7 -0
- data/manual/graphics/circle_and_ellipse.rb +22 -0
- data/manual/graphics/color.rb +24 -0
- data/manual/graphics/common_lines.rb +30 -0
- data/manual/graphics/fill_and_stroke.rb +42 -0
- data/manual/graphics/fill_rules.rb +37 -0
- data/manual/graphics/gradients.rb +37 -0
- data/manual/graphics/graphics.rb +58 -0
- data/manual/graphics/helper.rb +24 -0
- data/manual/graphics/line_width.rb +35 -0
- data/manual/graphics/lines_and_curves.rb +41 -0
- data/manual/graphics/polygon.rb +29 -0
- data/manual/graphics/rectangle.rb +21 -0
- data/manual/graphics/rotate.rb +28 -0
- data/manual/graphics/scale.rb +41 -0
- data/manual/graphics/soft_masks.rb +46 -0
- data/manual/graphics/stroke_cap.rb +31 -0
- data/manual/graphics/stroke_dash.rb +48 -0
- data/manual/graphics/stroke_join.rb +30 -0
- data/manual/graphics/translate.rb +29 -0
- data/manual/graphics/transparency.rb +35 -0
- data/manual/how_to_read_this_manual.rb +40 -0
- data/manual/images/absolute_position.rb +23 -0
- data/manual/images/fit.rb +21 -0
- data/manual/images/horizontal.rb +25 -0
- data/manual/images/images.rb +40 -0
- data/manual/images/plain_image.rb +18 -0
- data/manual/images/scale.rb +22 -0
- data/manual/images/vertical.rb +28 -0
- data/manual/images/width_and_height.rb +25 -0
- data/manual/layout/boxes.rb +27 -0
- data/manual/layout/content.rb +25 -0
- data/manual/layout/layout.rb +28 -0
- data/manual/layout/simple_grid.rb +23 -0
- data/manual/outline/add_subsection_to.rb +61 -0
- data/manual/outline/insert_section_after.rb +47 -0
- data/manual/outline/outline.rb +32 -0
- data/manual/outline/sections_and_pages.rb +67 -0
- data/manual/repeatable_content/alternate_page_numbering.rb +32 -0
- data/manual/repeatable_content/page_numbering.rb +54 -0
- data/manual/repeatable_content/repeatable_content.rb +32 -0
- data/manual/repeatable_content/repeater.rb +55 -0
- data/manual/repeatable_content/stamp.rb +41 -0
- data/manual/security/encryption.rb +31 -0
- data/manual/security/permissions.rb +38 -0
- data/manual/security/security.rb +28 -0
- data/manual/table.rb +16 -0
- data/manual/text/alignment.rb +44 -0
- data/manual/text/color.rb +24 -0
- data/manual/text/column_box.rb +32 -0
- data/manual/text/fallback_fonts.rb +37 -0
- data/manual/text/font.rb +41 -0
- data/manual/text/font_size.rb +45 -0
- data/manual/text/font_style.rb +23 -0
- data/manual/text/formatted_callbacks.rb +60 -0
- data/manual/text/formatted_text.rb +50 -0
- data/manual/text/free_flowing_text.rb +51 -0
- data/manual/text/inline.rb +41 -0
- data/manual/text/kerning_and_character_spacing.rb +39 -0
- data/manual/text/leading.rb +25 -0
- data/manual/text/line_wrapping.rb +41 -0
- data/manual/text/paragraph_indentation.rb +34 -0
- data/manual/text/positioned_text.rb +38 -0
- data/manual/text/registering_families.rb +48 -0
- data/manual/text/rendering_and_color.rb +37 -0
- data/manual/text/right_to_left_text.rb +47 -0
- data/manual/text/rotation.rb +43 -0
- data/manual/text/single_usage.rb +37 -0
- data/manual/text/text.rb +73 -0
- data/manual/text/text_box_excess.rb +32 -0
- data/manual/text/text_box_extensions.rb +45 -0
- data/manual/text/text_box_overflow.rb +48 -0
- data/manual/text/utf8.rb +28 -0
- data/manual/text/win_ansi_charset.rb +60 -0
- data/prawn.gemspec +45 -0
- data/spec/acceptance/png.rb +25 -0
- data/spec/annotations_spec.rb +74 -0
- data/spec/bounding_box_spec.rb +510 -0
- data/spec/column_box_spec.rb +65 -0
- data/spec/data/curves.pdf +66 -0
- data/spec/destinations_spec.rb +15 -0
- data/spec/document_spec.rb +748 -0
- data/spec/extensions/encoding_helpers.rb +11 -0
- data/spec/extensions/mocha.rb +46 -0
- data/spec/font_metric_cache_spec.rb +52 -0
- data/spec/font_spec.rb +474 -0
- data/spec/formatted_text_arranger_spec.rb +421 -0
- data/spec/formatted_text_box_spec.rb +705 -0
- data/spec/formatted_text_fragment_spec.rb +298 -0
- data/spec/graphics_spec.rb +683 -0
- data/spec/grid_spec.rb +96 -0
- data/spec/image_handler_spec.rb +54 -0
- data/spec/images_spec.rb +153 -0
- data/spec/inline_formatted_text_parser_spec.rb +564 -0
- data/spec/jpg_spec.rb +25 -0
- data/spec/line_wrap_spec.rb +367 -0
- data/spec/measurement_units_spec.rb +25 -0
- data/spec/outline_spec.rb +430 -0
- data/spec/png_spec.rb +245 -0
- data/spec/reference_spec.rb +25 -0
- data/spec/repeater_spec.rb +160 -0
- data/spec/security_spec.rb +158 -0
- data/spec/soft_mask_spec.rb +79 -0
- data/spec/span_spec.rb +44 -0
- data/spec/spec_helper.rb +54 -0
- data/spec/stamp_spec.rb +160 -0
- data/spec/stroke_styles_spec.rb +211 -0
- data/spec/text_at_spec.rb +143 -0
- data/spec/text_box_spec.rb +1043 -0
- data/spec/text_rendering_mode_spec.rb +45 -0
- data/spec/text_spacing_spec.rb +93 -0
- data/spec/text_spec.rb +557 -0
- data/spec/text_with_inline_formatting_spec.rb +35 -0
- data/spec/transparency_spec.rb +91 -0
- data/spec/view_spec.rb +43 -0
- metadata +509 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Stamps should be used when you have content that will be included multiple
|
4
|
+
# times in a document. Its advantages over creating the content anew each time
|
5
|
+
# are:
|
6
|
+
# 1. Faster document creation
|
7
|
+
# 2. Smaller final document
|
8
|
+
# 3. Faster display on subsequent displays of the repeated
|
9
|
+
# element because the viewer application can cache the rendered
|
10
|
+
# results
|
11
|
+
#
|
12
|
+
# The <code>create_stamp</code> method does just what it says. Pass it a block
|
13
|
+
# with the content that should be generated and the stamp will be created.
|
14
|
+
#
|
15
|
+
# There are two methods to render the stamp on a page <code>stamp</code> and
|
16
|
+
# <code>stamp_at</code>. The first will render the stamp as is while the
|
17
|
+
# second accepts a point to serve as an offset to the stamp content.
|
18
|
+
#
|
19
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
20
|
+
%w[.. example_helper]))
|
21
|
+
|
22
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
23
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
24
|
+
create_stamp("approved") do
|
25
|
+
rotate(30, :origin => [-5, -5]) do
|
26
|
+
stroke_color "FF3333"
|
27
|
+
stroke_ellipse [0, 0], 29, 15
|
28
|
+
stroke_color "000000"
|
29
|
+
|
30
|
+
fill_color "993333"
|
31
|
+
font("Times-Roman") do
|
32
|
+
draw_text "Approved", :at => [-23, -3]
|
33
|
+
end
|
34
|
+
fill_color "000000"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
stamp "approved"
|
39
|
+
|
40
|
+
stamp_at "approved", [200, 200]
|
41
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# The <code>encrypt_document</code> method, as you might have already guessed,
|
4
|
+
# is used to encrypt the PDF document.
|
5
|
+
#
|
6
|
+
# Once encrypted whoever is using the document will need the user password to
|
7
|
+
# read the document. This password can be set with the
|
8
|
+
# <code>:user_password</code> option. If this is not set the document will be
|
9
|
+
# encrypted but a password will not be needed to read the document.
|
10
|
+
#
|
11
|
+
# There are some caveats when encrypting your PDFs. Be sure to read the source
|
12
|
+
# documentation (you can find it here:
|
13
|
+
# https://github.com/prawnpdf/prawn/blob/master/lib/prawn/security.rb ) before
|
14
|
+
# using this for anything super serious.
|
15
|
+
#
|
16
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
17
|
+
%w[.. example_helper]))
|
18
|
+
|
19
|
+
|
20
|
+
# Bare encryption. No password needed.
|
21
|
+
Prawn::ManualBuilder::Example.generate("bare_encryption.pdf") do
|
22
|
+
text "See, no password was asked but the document is still encrypted."
|
23
|
+
encrypt_document
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
# Simple password. All permissions granted.
|
28
|
+
Prawn::ManualBuilder::Example.generate("simple_password.pdf") do
|
29
|
+
text "You was asked for a password."
|
30
|
+
encrypt_document(:user_password => 'foo', :owner_password => 'bar')
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Some permissions may be set for the regular user with the following options:
|
4
|
+
# <code>:print_document</code>, <code>:modify_contents</code>,
|
5
|
+
# <code>:copy_contents</code>, <code>:modify_annotations</code>. All this
|
6
|
+
# options default to true, so if you'd like to revoke just set them to false.
|
7
|
+
#
|
8
|
+
# A user may bypass all permissions if he provides the owner password which
|
9
|
+
# may be set with the <code>:owner_password</code> option. This option may be
|
10
|
+
# set to <code>:random</code> so that users will never be able to bypass
|
11
|
+
# permissions.
|
12
|
+
#
|
13
|
+
# There are some caveats when encrypting your PDFs. Be sure to read the source
|
14
|
+
# documentation (you can find it here:
|
15
|
+
# https://github.com/prawnpdf/prawn/blob/master/lib/prawn/security.rb ) before
|
16
|
+
# using this for anything super serious.
|
17
|
+
#
|
18
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
19
|
+
%w[.. example_helper]))
|
20
|
+
|
21
|
+
|
22
|
+
# User cannot print the document.
|
23
|
+
Prawn::ManualBuilder::Example.generate("cannot_print.pdf") do
|
24
|
+
text "If you used the user password you won't be able to print the doc."
|
25
|
+
encrypt_document(:user_password => 'foo', :owner_password => 'bar',
|
26
|
+
:permissions => { :print_document => false })
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
# All permissions revoked and owner password set to random
|
31
|
+
Prawn::ManualBuilder::Example.generate("no_permissions.pdf") do
|
32
|
+
text "You may only view this and won't be able to use the owner password."
|
33
|
+
encrypt_document(:user_password => 'foo', :owner_password => :random,
|
34
|
+
:permissions => { :print_document => false,
|
35
|
+
:modify_contents => false,
|
36
|
+
:copy_contents => false,
|
37
|
+
:modify_annotations => false })
|
38
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Examples for document encryption.
|
4
|
+
#
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
6
|
+
%w[.. example_helper]))
|
7
|
+
|
8
|
+
Prawn::ManualBuilder::Example.generate("security.pdf", :page_size => "FOLIO") do
|
9
|
+
|
10
|
+
package "security" do |p|
|
11
|
+
|
12
|
+
p.example "encryption", :eval_source => false, :full_source => true
|
13
|
+
p.example "permissions", :eval_source => false, :full_source => true
|
14
|
+
|
15
|
+
p.intro do
|
16
|
+
prose("Security lets you control who can read the document by defining a password.
|
17
|
+
|
18
|
+
The examples include:")
|
19
|
+
|
20
|
+
list( "How to encrypt the document without the need for a password",
|
21
|
+
"How to configure the regular user permissions",
|
22
|
+
"How to require a password for the regular user",
|
23
|
+
"How to set a owner password that bypass the document permissions"
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
data/manual/table.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative "example_helper"
|
4
|
+
|
5
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
6
|
+
|
7
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
8
|
+
header("Prawn::Table")
|
9
|
+
|
10
|
+
prose <<-END_TEXT
|
11
|
+
As of Prawn 1.2.0, Prawn::Table has been extracted into its own
|
12
|
+
semi-officially supported gem.
|
13
|
+
|
14
|
+
Please see https://github.com/prawnpdf/prawn-table for more details.
|
15
|
+
END_TEXT
|
16
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Horizontal text alignment can be achieved by supplying the <code>:align</code>
|
4
|
+
# option to the text methods. Available options are <code>:left</code>
|
5
|
+
# (default), <code>:right</code>, <code>:center</code>, and
|
6
|
+
# <code>:justify</code>.
|
7
|
+
#
|
8
|
+
# Vertical text alignment can be achieved using the <code>:valign</code> option
|
9
|
+
# with the text methods. Available options are <code>:top</code> (default),
|
10
|
+
# <code>:center</code>, and <code>:bottom</code>.
|
11
|
+
#
|
12
|
+
# Both forms of alignment will be evaluated in the context of the current
|
13
|
+
# bounding_box.
|
14
|
+
#
|
15
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
16
|
+
%w[.. example_helper]))
|
17
|
+
|
18
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
19
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
20
|
+
text "This text should be left aligned"
|
21
|
+
text "This text should be centered", :align => :center
|
22
|
+
text "This text should be right aligned", :align => :right
|
23
|
+
|
24
|
+
bounding_box([0, 220], :width => 250, :height => 220) do
|
25
|
+
text "This text is flowing from the left. " * 4
|
26
|
+
|
27
|
+
move_down 15
|
28
|
+
text "This text is flowing from the center. " * 3, :align => :center
|
29
|
+
|
30
|
+
move_down 15
|
31
|
+
text "This text is flowing from the right. " * 4, :align => :right
|
32
|
+
|
33
|
+
move_down 15
|
34
|
+
text "This text is justified. " * 6, :align => :justify
|
35
|
+
transparent(0.5) { stroke_bounds }
|
36
|
+
end
|
37
|
+
|
38
|
+
bounding_box([300, 220], :width => 250, :height => 220) do
|
39
|
+
text "This text should be vertically top aligned"
|
40
|
+
text "This text should be vertically centered", :valign => :center
|
41
|
+
text "This text should be vertically bottom aligned", :valign => :bottom
|
42
|
+
transparent(0.5) { stroke_bounds }
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# The <code>:color</code> attribute can give a block of text a default color,
|
4
|
+
# in RGB hex format or 4-value CMYK.
|
5
|
+
#
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
7
|
+
%w[.. example_helper]))
|
8
|
+
|
9
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
10
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
11
|
+
text "Default color is black"
|
12
|
+
move_down 25
|
13
|
+
|
14
|
+
text "Changed to red", :color => "FF0000"
|
15
|
+
move_down 25
|
16
|
+
|
17
|
+
text "CMYK color", :color => [22, 55, 79, 30]
|
18
|
+
move_down 25
|
19
|
+
|
20
|
+
text "Also works with <color rgb='ff0000'>inline</color> formatting",
|
21
|
+
:color => "0000FF",
|
22
|
+
:inline_format => true
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# The <code>column_box</code> method allows you to define columns that flow
|
4
|
+
# their contents from one section to the next. You can have a number of columns
|
5
|
+
# on the page, and only when the last column overflows will a new page be
|
6
|
+
# created.
|
7
|
+
#
|
8
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
9
|
+
%w[.. example_helper]))
|
10
|
+
|
11
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
12
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
13
|
+
text "The Prince", :align => :center, :size => 18
|
14
|
+
text "Niccolò Machiavelli", :align => :center, :size => 14
|
15
|
+
move_down 12
|
16
|
+
|
17
|
+
column_box([0, cursor], :columns => 2, :width => bounds.width) do
|
18
|
+
text((<<-END.gsub(/\s+/, ' ') + "\n\n") * 3)
|
19
|
+
All the States and Governments by which men are or ever have been ruled,
|
20
|
+
have been and are either Republics or Princedoms. Princedoms are either
|
21
|
+
hereditary, in which the sovereignty is derived through an ancient line
|
22
|
+
of ancestors, or they are new. New Princedoms are either wholly new, as
|
23
|
+
that of Milan to Francesco Sforza; or they are like limbs joined on to
|
24
|
+
the hereditary possessions of the Prince who acquires them, as the
|
25
|
+
Kingdom of Naples to the dominions of the King of Spain. The States thus
|
26
|
+
acquired have either been used to live under a Prince or have been free;
|
27
|
+
and he who acquires them does so either by his own arms or by the arms of
|
28
|
+
others, and either by good fortune or by merit.
|
29
|
+
END
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Prawn enables the declaration of fallback fonts for those glyphs that may not
|
4
|
+
# be present in the desired font. Use the <code>:fallback_fonts</code> option
|
5
|
+
# with any of the text or text box methods, or set fallback_fonts document-wide.
|
6
|
+
#
|
7
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
8
|
+
%w[.. example_helper]))
|
9
|
+
|
10
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
11
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
12
|
+
file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
|
13
|
+
font_families["Kai"] = {
|
14
|
+
:normal => { :file => file, :font => "Kai" }
|
15
|
+
}
|
16
|
+
|
17
|
+
file = "#{Prawn::DATADIR}/fonts/Panic+Sans.dfont"
|
18
|
+
font_families["Panic Sans"] = {
|
19
|
+
:normal => { :file => file, :font => "PanicSans" },
|
20
|
+
}
|
21
|
+
|
22
|
+
font("Panic Sans") do
|
23
|
+
text("When fallback fonts are included, each glyph will be rendered " +
|
24
|
+
"using the first font that includes the glyph, starting with the " +
|
25
|
+
"current font and then moving through the fallback fonts from left " +
|
26
|
+
"to right." +
|
27
|
+
"\n\n" +
|
28
|
+
"hello ƒ 你好\n再见 ƒ goodbye",
|
29
|
+
:fallback_fonts => ["Times-Roman", "Kai"])
|
30
|
+
end
|
31
|
+
move_down 20
|
32
|
+
|
33
|
+
formatted_text([ { :text => "Fallback fonts can even override" },
|
34
|
+
{ :text => "fragment fonts (你好)", :font => "Times-Roman" },
|
35
|
+
],
|
36
|
+
:fallback_fonts => ["Times-Roman", "Kai"])
|
37
|
+
end
|
data/manual/text/font.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# The <code>font</code> method can be used in three different ways.
|
4
|
+
#
|
5
|
+
# If we don't pass it any arguments it will return the current font being used
|
6
|
+
# to render text.
|
7
|
+
#
|
8
|
+
# If we just pass it a font name it will use that font for rendering text
|
9
|
+
# through the rest of the document.
|
10
|
+
#
|
11
|
+
# It can also be used by passing a font name and a block. In this case the
|
12
|
+
# specified font will only be used to render text inside the block.
|
13
|
+
#
|
14
|
+
# The default font is Helvetica.
|
15
|
+
#
|
16
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
17
|
+
%w[.. example_helper]))
|
18
|
+
|
19
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
20
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
21
|
+
text "Let's see which font we are using: #{font.inspect}"
|
22
|
+
|
23
|
+
move_down 20
|
24
|
+
font "Times-Roman"
|
25
|
+
text "Written in Times."
|
26
|
+
|
27
|
+
move_down 20
|
28
|
+
font("Courier") do
|
29
|
+
text "Written in Courier because we are inside the block."
|
30
|
+
end
|
31
|
+
|
32
|
+
move_down 20
|
33
|
+
text "Written in Times again as we left the previous block."
|
34
|
+
|
35
|
+
move_down 20
|
36
|
+
text "Let's see which font we are using again: #{font.inspect}"
|
37
|
+
|
38
|
+
move_down 20
|
39
|
+
font "Helvetica"
|
40
|
+
text "Back to normal."
|
41
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# The <code>font_size</code> method works just like the <code>font</code>
|
4
|
+
# method.
|
5
|
+
#
|
6
|
+
# In fact we can even use <code>font</code> with the <code>:size</code> option
|
7
|
+
# to declare which size we want.
|
8
|
+
#
|
9
|
+
# Another way to change the font size is by supplying the <code>:size</code>
|
10
|
+
# option to the text methods.
|
11
|
+
#
|
12
|
+
# The default font size is <code>12</code>.
|
13
|
+
#
|
14
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
15
|
+
%w[.. example_helper]))
|
16
|
+
|
17
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
18
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
19
|
+
text "Let's see which is the current font_size: #{font_size.inspect}"
|
20
|
+
|
21
|
+
move_down 10
|
22
|
+
font_size 16
|
23
|
+
text "Yeah, something bigger!"
|
24
|
+
|
25
|
+
move_down 10
|
26
|
+
font_size(25) { text "Even bigger!" }
|
27
|
+
|
28
|
+
move_down 10
|
29
|
+
text "Back to 16 again."
|
30
|
+
|
31
|
+
move_down 10
|
32
|
+
text "Single line on 20 using the :size option.", :size => 20
|
33
|
+
|
34
|
+
move_down 10
|
35
|
+
text "Back to 16 once more."
|
36
|
+
|
37
|
+
move_down 10
|
38
|
+
font("Courier", :size => 10) do
|
39
|
+
text "Yeah, using Courier 10 courtesy of the font method."
|
40
|
+
end
|
41
|
+
|
42
|
+
move_down 10
|
43
|
+
font("Helvetica", :size => 12)
|
44
|
+
text "Back to normal"
|
45
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Most font families come with some styles other than normal. Most common are
|
4
|
+
# <code>bold</code>, <code>italic</code> and <code>bold_italic</code>.
|
5
|
+
#
|
6
|
+
# The style can be set the using the <code>:style</code> option, with either the
|
7
|
+
# <code>font</code> method which will set the font and style for rest of the
|
8
|
+
# document, or with the inline text methods.
|
9
|
+
#
|
10
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
11
|
+
%w[.. example_helper]))
|
12
|
+
|
13
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
14
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
15
|
+
["Courier", "Helvetica", "Times-Roman"].each do |example_font|
|
16
|
+
move_down 20
|
17
|
+
|
18
|
+
[:bold, :bold_italic, :italic, :normal].each do |style|
|
19
|
+
font example_font, :style => style
|
20
|
+
text "I'm writing in #{example_font} (#{style})"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# The <code>:callback</code> option is also available for the formatted text
|
4
|
+
# methods.
|
5
|
+
#
|
6
|
+
# This option accepts an object (or array of objects) on which two methods
|
7
|
+
# will be called if defined: <code>render_behind</code> and
|
8
|
+
# <code>render_in_front</code>. They are called before and after rendering the
|
9
|
+
# text fragment and are passed the fragment as an argument.
|
10
|
+
#
|
11
|
+
# This example defines two new callback classes and provide callback objects
|
12
|
+
# for the formatted_text
|
13
|
+
#
|
14
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
15
|
+
%w[.. example_helper]))
|
16
|
+
|
17
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
18
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
19
|
+
class HighlightCallback
|
20
|
+
def initialize(options)
|
21
|
+
@color = options[:color]
|
22
|
+
@document = options[:document]
|
23
|
+
end
|
24
|
+
|
25
|
+
def render_behind(fragment)
|
26
|
+
original_color = @document.fill_color
|
27
|
+
@document.fill_color = @color
|
28
|
+
@document.fill_rectangle(fragment.top_left, fragment.width,
|
29
|
+
fragment.height)
|
30
|
+
@document.fill_color = original_color
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class ConnectedBorderCallback
|
35
|
+
def initialize(options)
|
36
|
+
@radius = options[:radius]
|
37
|
+
@document = options[:document]
|
38
|
+
end
|
39
|
+
|
40
|
+
def render_in_front(fragment)
|
41
|
+
@document.stroke_polygon(fragment.top_left, fragment.top_right,
|
42
|
+
fragment.bottom_right, fragment.bottom_left)
|
43
|
+
|
44
|
+
@document.fill_circle(fragment.top_left, @radius)
|
45
|
+
@document.fill_circle(fragment.top_right, @radius)
|
46
|
+
@document.fill_circle(fragment.bottom_right, @radius)
|
47
|
+
@document.fill_circle(fragment.bottom_left, @radius)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
highlight = HighlightCallback.new(:color => 'ffff00', :document => self)
|
52
|
+
border = ConnectedBorderCallback.new(:radius => 2.5, :document => self)
|
53
|
+
|
54
|
+
formatted_text [ { :text => "hello", :callback => highlight },
|
55
|
+
{ :text => " " },
|
56
|
+
{ :text => "world", :callback => border },
|
57
|
+
{ :text => " " },
|
58
|
+
{ :text => "hello world", :callback => [highlight, border] }
|
59
|
+
], :size => 20
|
60
|
+
end
|