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,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Rotating text is best avoided on free flowing text, so this example
|
4
|
+
# will only use the <code>text_box</code> method as we can have much more
|
5
|
+
# control over its output.
|
6
|
+
#
|
7
|
+
# To rotate text all we need to do is use the <code>:rotate</code> option
|
8
|
+
# passing an angle in degrees and an optional <code>:rotate_around</code> to
|
9
|
+
# indicate the origin of the rotation (the default is <code>:upper_left</code>).
|
10
|
+
#
|
11
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
12
|
+
%w[.. example_helper]))
|
13
|
+
|
14
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
15
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
16
|
+
width = 100
|
17
|
+
height = 60
|
18
|
+
angle = 30
|
19
|
+
x = 200
|
20
|
+
y = cursor - 30
|
21
|
+
|
22
|
+
stroke_rectangle [0, y], width, height
|
23
|
+
text_box("This text was not rotated",
|
24
|
+
:at => [0, y], :width => width, :height => height)
|
25
|
+
|
26
|
+
stroke_rectangle [0, y - 100], width, height
|
27
|
+
text_box("This text was rotated around the center",
|
28
|
+
:at => [0, y - 100], :width => width, :height => height,
|
29
|
+
:rotate => angle, :rotate_around => :center)
|
30
|
+
|
31
|
+
[:lower_left, :upper_left,
|
32
|
+
:lower_right, :upper_right].each_with_index do |corner, index|
|
33
|
+
|
34
|
+
y = y - 100 if index == 2
|
35
|
+
stroke_rectangle [x + (index % 2) * 200, y], width, height
|
36
|
+
text_box("This text was rotated around the #{corner} corner.",
|
37
|
+
:at => [x + (index % 2) * 200, y],
|
38
|
+
:width => width,
|
39
|
+
:height => height,
|
40
|
+
:rotate => angle,
|
41
|
+
:rotate_around => corner)
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# The PDF format has some built-in font support. If you want to use other fonts
|
4
|
+
# in Prawn you need to embed the font file.
|
5
|
+
#
|
6
|
+
# Doing this for a single font is extremely simple. Remember the Styling font
|
7
|
+
# example? Another use of the <code>font</code> method is to provide a font file
|
8
|
+
# path and the font will be embedded in the document and set as the current
|
9
|
+
# font.
|
10
|
+
#
|
11
|
+
# This is reasonable if a font is used only once, but, if a font used several
|
12
|
+
# times, providing the path each time it is used becomes cumbersome. The example
|
13
|
+
# on the next page shows a better way to deal with fonts which are used several
|
14
|
+
# times in a document.
|
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
|
+
# Using a TTF font file
|
22
|
+
font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf") do
|
23
|
+
text "Written with the DejaVu Sans TTF font."
|
24
|
+
end
|
25
|
+
move_down 20
|
26
|
+
|
27
|
+
text "Written with the default font."
|
28
|
+
move_down 20
|
29
|
+
|
30
|
+
# Using an DFONT font file
|
31
|
+
font("#{Prawn::DATADIR}/fonts/Panic+Sans.dfont") do
|
32
|
+
text "Written with the Panic Sans DFONT font"
|
33
|
+
end
|
34
|
+
move_down 20
|
35
|
+
|
36
|
+
text "Written with the default font once more."
|
37
|
+
end
|
data/manual/text/text.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Examples for text rendering.
|
4
|
+
#
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
6
|
+
%w[.. example_helper]))
|
7
|
+
|
8
|
+
Prawn::ManualBuilder::Example.generate("text.pdf", :page_size => "FOLIO") do
|
9
|
+
|
10
|
+
package "text" do |p|
|
11
|
+
|
12
|
+
p.section "Basics" do |s|
|
13
|
+
s.example "free_flowing_text"
|
14
|
+
s.example "positioned_text"
|
15
|
+
s.example "text_box_overflow"
|
16
|
+
s.example "text_box_excess"
|
17
|
+
s.example "column_box"
|
18
|
+
end
|
19
|
+
|
20
|
+
p.section "Styling" do |s|
|
21
|
+
s.example "font"
|
22
|
+
s.example "font_size"
|
23
|
+
s.example "font_style"
|
24
|
+
s.example "color"
|
25
|
+
s.example "alignment"
|
26
|
+
s.example "leading"
|
27
|
+
s.example "kerning_and_character_spacing"
|
28
|
+
s.example "paragraph_indentation"
|
29
|
+
s.example "rotation"
|
30
|
+
end
|
31
|
+
|
32
|
+
p.section "Advanced Styling" do |s|
|
33
|
+
s.example "inline"
|
34
|
+
s.example "formatted_text"
|
35
|
+
s.example "formatted_callbacks"
|
36
|
+
s.example "rendering_and_color"
|
37
|
+
s.example "text_box_extensions"
|
38
|
+
end
|
39
|
+
|
40
|
+
p.section "External Fonts" do |s|
|
41
|
+
s.example "single_usage"
|
42
|
+
s.example "registering_families"
|
43
|
+
end
|
44
|
+
|
45
|
+
p.section "Multilingualization" do |s|
|
46
|
+
s.example "utf8"
|
47
|
+
s.example "line_wrapping"
|
48
|
+
s.example "right_to_left_text"
|
49
|
+
s.example "fallback_fonts"
|
50
|
+
s.example "win_ansi_charset"
|
51
|
+
end
|
52
|
+
|
53
|
+
p.intro do
|
54
|
+
prose("This is probably the feature people will use the most. There is no shortage of options when it comes to text. You'll be hard pressed to find a use case that is not covered by one of the text methods and configurable options.
|
55
|
+
|
56
|
+
The examples show:")
|
57
|
+
|
58
|
+
list( "Text that flows from page to page automatically starting new pages when necessary",
|
59
|
+
"How to use text boxes and place them on specific positions",
|
60
|
+
"What to do when a text box is too small to fit its content",
|
61
|
+
"Flowing text in columns",
|
62
|
+
"How to change the text style configuring font, size, alignment and many other settings",
|
63
|
+
"How to style specific portions of a text with inline styling and formatted text",
|
64
|
+
"How to define formatted callbacks to reuse common styling definitions",
|
65
|
+
"How to use the different rendering modes available for the text methods",
|
66
|
+
"How to create your custom text box extensions",
|
67
|
+
"How to use external fonts on your pdfs",
|
68
|
+
"What happens when rendering text in different languages"
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Whenever the <code>text_box</code> method truncates text, this truncated bit
|
4
|
+
# is not lost, it is the method return value and we can take advantage of that.
|
5
|
+
#
|
6
|
+
# We just need to take some precautions.
|
7
|
+
#
|
8
|
+
# This example renders as much of the text as will fit in a larger font inside
|
9
|
+
# one text_box and then proceeds to render the remaining text in the default
|
10
|
+
# size in a second text_box.
|
11
|
+
#
|
12
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
13
|
+
%w[.. example_helper]))
|
14
|
+
|
15
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
16
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
17
|
+
string = "This is the beginning of the text. It will be cut somewhere and " +
|
18
|
+
"the rest of the text will procede to be rendered this time by " +
|
19
|
+
"calling another method." + " . " * 50
|
20
|
+
|
21
|
+
y_position = cursor - 20
|
22
|
+
excess_text = text_box string,
|
23
|
+
:width => 300,
|
24
|
+
:height => 50,
|
25
|
+
:overflow => :truncate,
|
26
|
+
:at => [100, y_position],
|
27
|
+
:size => 18
|
28
|
+
|
29
|
+
text_box excess_text,
|
30
|
+
:width => 300,
|
31
|
+
:at => [100, y_position - 100]
|
32
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# We've already seen one way of using text boxes with the <code>text_box</code>
|
4
|
+
# method. Turns out this method is just a convenience for using the
|
5
|
+
# <code>Prawn::Text::Box</code> class as it creates a new object and call
|
6
|
+
# <code>render</code> on it.
|
7
|
+
#
|
8
|
+
# Knowing that any extensions we add to <code>Prawn::Text::Box</code> will take
|
9
|
+
# effect when we use the <code>text_box</code> method. To add an extension all
|
10
|
+
# we need to do is append the <code>Prawn::Text::Box.extensions</code> array
|
11
|
+
# with a module.
|
12
|
+
#
|
13
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
14
|
+
%w[.. example_helper]))
|
15
|
+
|
16
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
17
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
18
|
+
module TriangleBox
|
19
|
+
def available_width
|
20
|
+
height + 25
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
y_position = cursor - 10
|
25
|
+
width = 100
|
26
|
+
height = 100
|
27
|
+
|
28
|
+
Prawn::Text::Box.extensions << TriangleBox
|
29
|
+
stroke_rectangle([0, y_position], width, height)
|
30
|
+
text_box("A" * 100,
|
31
|
+
:at => [0, y_position],
|
32
|
+
:width => width,
|
33
|
+
:height => height)
|
34
|
+
|
35
|
+
Prawn::Text::Formatted::Box.extensions << TriangleBox
|
36
|
+
stroke_rectangle([200, y_position], width, height)
|
37
|
+
formatted_text_box([:text => "A" * 100, :color => "009900"],
|
38
|
+
:at => [200, y_position],
|
39
|
+
:width => width,
|
40
|
+
:height => height)
|
41
|
+
|
42
|
+
# Here we clear the extensions array
|
43
|
+
Prawn::Text::Box.extensions.clear
|
44
|
+
Prawn::Text::Formatted::Box.extensions.clear
|
45
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# The <code>text_box</code> method accepts both <code>:width</code> and
|
4
|
+
# <code>:height</code> options. So what happens if the text doesn't fit the box?
|
5
|
+
#
|
6
|
+
# The default behavior is to truncate the text but this can be changed with
|
7
|
+
# the <code>:overflow</code> option. Available modes are <code>:expand</code>
|
8
|
+
# (the box will increase to fit the text) and <code>:shrink_to_fit</code>
|
9
|
+
# (the text font size will be shrunk to fit).
|
10
|
+
#
|
11
|
+
# If <code>:shrink_to_fit</code> mode is used with the
|
12
|
+
# <code>:min_font_size</code> option set, the font size will not be reduced to
|
13
|
+
# less than the value provided even if it means truncating some text.
|
14
|
+
#
|
15
|
+
# If the <code>:disable_wrap_by_char</code> is set to <code>true</code>
|
16
|
+
# then any text wrapping done while using the <code>:shrink_to_fit</code>
|
17
|
+
# mode will not break up the middle of words.
|
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
|
+
string = "This is the sample text used for the text boxes. See how it " +
|
25
|
+
"behave with the various overflow options used."
|
26
|
+
|
27
|
+
text string
|
28
|
+
|
29
|
+
y_position = cursor - 20
|
30
|
+
[:truncate, :expand, :shrink_to_fit].each_with_index do |mode, i|
|
31
|
+
text_box string, :at => [i * 150, y_position],
|
32
|
+
:width => 100, :height => 50,
|
33
|
+
:overflow => mode
|
34
|
+
end
|
35
|
+
|
36
|
+
string = "If the box is too small for the text, :shrink_to_fit " +
|
37
|
+
"can render the text in a really small font size."
|
38
|
+
|
39
|
+
move_down 120
|
40
|
+
text string
|
41
|
+
y_position = cursor - 20
|
42
|
+
[nil, 8, 10, 12].each_with_index do |value, index|
|
43
|
+
text_box string, :at => [index * 150, y_position],
|
44
|
+
:width => 50, :height => 50,
|
45
|
+
:overflow => :shrink_to_fit,
|
46
|
+
:min_font_size => value
|
47
|
+
end
|
48
|
+
end
|
data/manual/text/utf8.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Multilingualization isn't much of a problem on Prawn as its default encoding
|
4
|
+
# is UTF-8. The only thing you need to worry about is if the font support the
|
5
|
+
# glyphs of your language.
|
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
|
+
text "Take this example, a simple Euro sign:"
|
13
|
+
text "€", :size => 32
|
14
|
+
move_down 20
|
15
|
+
|
16
|
+
text "This works, because € is one of the few "+
|
17
|
+
"non-ASCII glyphs supported in PDF built-in fonts."
|
18
|
+
|
19
|
+
move_down 20
|
20
|
+
|
21
|
+
text "For full internationalized text support, we need to use TTF fonts:"
|
22
|
+
move_down 20
|
23
|
+
|
24
|
+
font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf") do
|
25
|
+
text "ὕαλον ϕαγεῖν δύναμαι· τοῦτο οὔ με βλάπτει."
|
26
|
+
text "There you go."
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Prints a list of all of the glyphs that can be rendered by Adobe's built
|
4
|
+
# in fonts, along with their character widths and WinAnsi codes. Be sure
|
5
|
+
# to pass these glyphs as UTF-8, and Prawn will transcode them for you.
|
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
|
+
FONT_SIZE = 9.5
|
13
|
+
|
14
|
+
x = 0
|
15
|
+
y = bounds.top
|
16
|
+
|
17
|
+
fields = [[20, :right], [8, :left], [12, :center], [30, :right], [8, :left],
|
18
|
+
[0, :left]]
|
19
|
+
|
20
|
+
font "Helvetica", :size => FONT_SIZE
|
21
|
+
|
22
|
+
move_down 30
|
23
|
+
text "(See next page for WinAnsi table)", :align => :center
|
24
|
+
start_new_page
|
25
|
+
|
26
|
+
Prawn::Encoding::WinAnsi::CHARACTERS.each_with_index do |name, index|
|
27
|
+
next if name == ".notdef"
|
28
|
+
y -= FONT_SIZE
|
29
|
+
|
30
|
+
if y < FONT_SIZE
|
31
|
+
y = bounds.top - FONT_SIZE
|
32
|
+
x += 170
|
33
|
+
end
|
34
|
+
|
35
|
+
code = "%d." % index
|
36
|
+
char = index.chr
|
37
|
+
|
38
|
+
width = 1000 * width_of(char, :size => FONT_SIZE) / FONT_SIZE
|
39
|
+
size = "%d" % width
|
40
|
+
|
41
|
+
data = [code, nil, char, size, nil, name]
|
42
|
+
dx = x
|
43
|
+
fields.zip(data).each do |(total_width, align), field|
|
44
|
+
if field
|
45
|
+
width = width_of(field, :size => FONT_SIZE)
|
46
|
+
|
47
|
+
case align
|
48
|
+
when :left then offset = 0
|
49
|
+
when :right then offset = total_width - width
|
50
|
+
when :center then offset = (total_width - width)/2
|
51
|
+
end
|
52
|
+
|
53
|
+
text_box(field.force_encoding("windows-1252").encode("UTF-8"),
|
54
|
+
:at => [dx + offset, y])
|
55
|
+
end
|
56
|
+
|
57
|
+
dx += total_width
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/prawn.gemspec
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
basedir = File.expand_path(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require "#{basedir}/lib/prawn/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "prawn-git"
|
7
|
+
spec.version = Prawn::VERSION
|
8
|
+
spec.platform = Gem::Platform::RUBY
|
9
|
+
spec.summary = "A fast and nimble PDF generator for Ruby"
|
10
|
+
spec.files = Dir.glob("{examples,lib,spec,manual}/**/**/*") +
|
11
|
+
Dir.glob("data/{encodings,images,pdfs}/*") +
|
12
|
+
Dir.glob("data/fonts/{MustRead.html,*.afm}") +
|
13
|
+
["data/shift_jis_text.txt"] +
|
14
|
+
["Rakefile", "prawn.gemspec", "Gemfile",
|
15
|
+
"COPYING", "LICENSE", "GPLv2", "GPLv3",
|
16
|
+
".yardopts"]
|
17
|
+
spec.require_path = "lib"
|
18
|
+
spec.required_ruby_version = '>= 2.0.0'
|
19
|
+
spec.required_rubygems_version = ">= 1.3.6"
|
20
|
+
|
21
|
+
spec.test_files = Dir[ "spec/*_spec.rb" ]
|
22
|
+
spec.authors = ["Gregory Brown","Brad Ediger","Daniel Nelson","Jonathan Greenberg","James Healy"]
|
23
|
+
spec.email = ["gregory.t.brown@gmail.com","brad@bradediger.com","dnelson@bluejade.com","greenberg@entryway.net","jimmy@deefa.com"]
|
24
|
+
spec.rubyforge_project = "prawn"
|
25
|
+
spec.licenses = ['RUBY', 'GPL-2', 'GPL-3']
|
26
|
+
|
27
|
+
spec.add_dependency('ttfunk', '~> 1.4.0')
|
28
|
+
spec.add_dependency('pdf-core', "~> 0.5.1")
|
29
|
+
|
30
|
+
spec.add_development_dependency('pdf-inspector', '~> 1.2.0')
|
31
|
+
spec.add_development_dependency('yard')
|
32
|
+
spec.add_development_dependency('rspec', '2.14.1')
|
33
|
+
spec.add_development_dependency('mocha')
|
34
|
+
spec.add_development_dependency('rake')
|
35
|
+
spec.add_development_dependency('simplecov')
|
36
|
+
spec.add_development_dependency('prawn-manual_builder', ">= 0.2.0")
|
37
|
+
spec.add_development_dependency('pdf-reader', '~>1.2')
|
38
|
+
spec.add_development_dependency('rubocop', '0.28.0')
|
39
|
+
spec.add_development_dependency('code_statistics', '0.2.13')
|
40
|
+
|
41
|
+
spec.homepage = "http://prawn.majesticseacreature.com"
|
42
|
+
spec.description = <<END_DESC
|
43
|
+
Prawn is a fast, tiny, and nimble PDF generator for Ruby
|
44
|
+
END_DESC
|
45
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative "../../lib/prawn"
|
4
|
+
|
5
|
+
images = [
|
6
|
+
["Type 0", "#{Prawn::BASEDIR}/data/images/web-links.png"],
|
7
|
+
["Type 2", "#{Prawn::BASEDIR}/data/images/ruport.png"],
|
8
|
+
["Type 3", "#{Prawn::BASEDIR}/data/images/indexed_color.png"],
|
9
|
+
["Type 4", "#{Prawn::BASEDIR}/data/images/page_white_text.png"],
|
10
|
+
["Type 6", "#{Prawn::BASEDIR}/data/images/dice.png"],
|
11
|
+
]
|
12
|
+
|
13
|
+
Prawn::Document.generate("png_types.pdf", :page_size => "A5") do
|
14
|
+
images.each do |header, file|
|
15
|
+
start_new_page unless header.include?("0")
|
16
|
+
|
17
|
+
fill_color "FF0000"
|
18
|
+
|
19
|
+
fill_rectangle bounds.top_left, bounds.width, bounds.height
|
20
|
+
text header
|
21
|
+
|
22
|
+
image file, :at => [50,450]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|