prawn 1.0.0.rc1 → 1.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +18 -0
- data/README.md +5 -3
- data/Rakefile +8 -14
- data/data/pdfs/nested_pages.pdf +13 -13
- data/lib/prawn.rb +3 -1
- data/lib/prawn/compatibility.rb +46 -10
- data/lib/prawn/core.rb +3 -1
- data/lib/prawn/core/document_state.rb +2 -1
- data/lib/prawn/core/object_store.rb +61 -5
- data/lib/prawn/core/page.rb +3 -6
- data/lib/prawn/core/pdf_object.rb +21 -4
- data/lib/prawn/core/reference.rb +6 -2
- data/lib/prawn/core/text.rb +4 -4
- data/lib/prawn/core/text/formatted/line_wrap.rb +23 -8
- data/lib/prawn/document.rb +21 -15
- data/lib/prawn/document/bounding_box.rb +3 -3
- data/lib/prawn/document/column_box.rb +22 -4
- data/lib/prawn/document/snapshot.rb +1 -1
- data/lib/prawn/encoding.rb +1 -1
- data/lib/prawn/errors.rb +4 -0
- data/lib/prawn/font.rb +1 -1
- data/lib/prawn/font/afm.rb +30 -72
- data/lib/prawn/font/ttf.rb +6 -33
- data/lib/prawn/graphics.rb +148 -23
- data/lib/prawn/graphics/color.rb +8 -1
- data/lib/prawn/graphics/patterns.rb +137 -0
- data/lib/prawn/images.rb +25 -19
- data/lib/prawn/images/jpg.rb +4 -4
- data/lib/prawn/images/png.rb +18 -12
- data/lib/prawn/security.rb +6 -4
- data/lib/prawn/soft_mask.rb +94 -0
- data/lib/prawn/table.rb +136 -31
- data/lib/prawn/table/cell.rb +260 -29
- data/lib/prawn/table/cell/span_dummy.rb +88 -0
- data/lib/prawn/table/cell/text.rb +36 -14
- data/lib/prawn/table/cells.rb +91 -41
- data/lib/prawn/text.rb +3 -2
- data/lib/prawn/text/formatted/box.rb +14 -5
- data/lib/prawn/text/formatted/fragment.rb +33 -22
- data/lib/prawn/text/formatted/parser.rb +5 -2
- data/lib/prawn/utilities.rb +44 -0
- data/manual/basic_concepts/adding_pages.rb +27 -0
- data/manual/basic_concepts/basic_concepts.rb +34 -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/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/document_and_page_options/background.rb +27 -0
- data/manual/document_and_page_options/document_and_page_options.rb +31 -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/example_file.rb +116 -0
- data/manual/example_helper.rb +430 -0
- data/manual/example_package.rb +53 -0
- data/manual/example_section.rb +46 -0
- data/manual/graphics/circle_and_ellipse.rb +22 -0
- data/manual/graphics/color.rb +24 -0
- data/manual/graphics/common_lines.rb +28 -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 +17 -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 +43 -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/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/manual/cover.rb +26 -0
- data/manual/manual/foreword.rb +13 -0
- data/manual/manual/how_to_read_this_manual.rb +41 -0
- data/manual/manual/manual.rb +36 -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/page_numbering.rb +54 -0
- data/manual/repeatable_content/repeatable_content.rb +31 -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/syntax_highlight.rb +52 -0
- data/manual/table/basic_block.rb +53 -0
- data/manual/table/before_rendering_page.rb +26 -0
- data/manual/table/cell_border_lines.rb +24 -0
- data/manual/table/cell_borders_and_bg.rb +31 -0
- data/manual/table/cell_dimensions.rb +30 -0
- data/manual/table/cell_text.rb +38 -0
- data/manual/table/column_widths.rb +30 -0
- data/manual/table/content_and_subtables.rb +39 -0
- data/manual/table/creation.rb +27 -0
- data/manual/table/filtering.rb +36 -0
- data/manual/table/flow_and_header.rb +17 -0
- data/manual/table/image_cells.rb +33 -0
- data/manual/table/position.rb +29 -0
- data/manual/table/row_colors.rb +20 -0
- data/manual/table/span.rb +30 -0
- data/manual/table/style.rb +22 -0
- data/manual/table/table.rb +52 -0
- data/manual/table/width.rb +27 -0
- data/manual/templates/full_template.rb +23 -0
- data/manual/templates/page_template.rb +47 -0
- data/manual/templates/templates.rb +26 -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/group.rb +29 -0
- data/manual/text/inline.rb +43 -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 +26 -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 +43 -0
- data/manual/text/rotation.rb +43 -0
- data/manual/text/single_usage.rb +37 -0
- data/manual/text/text.rb +75 -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 +44 -0
- data/manual/text/utf8.rb +28 -0
- data/manual/text/win_ansi_charset.rb +59 -0
- data/prawn.gemspec +10 -7
- data/spec/bounding_box_spec.rb +107 -17
- data/spec/cell_spec.rb +66 -40
- data/spec/column_box_spec.rb +33 -0
- data/spec/document_spec.rb +45 -24
- data/spec/extensions/encoding_helpers.rb +6 -0
- data/spec/extensions/mocha.rb +1 -0
- data/spec/font_spec.rb +71 -53
- data/spec/formatted_text_arranger_spec.rb +19 -19
- data/spec/formatted_text_box_spec.rb +16 -16
- data/spec/formatted_text_fragment_spec.rb +6 -6
- data/spec/graphics_spec.rb +96 -31
- data/spec/grid_spec.rb +2 -2
- data/spec/images_spec.rb +18 -10
- data/spec/jpg_spec.rb +1 -1
- data/spec/line_wrap_spec.rb +14 -14
- data/spec/measurement_units_spec.rb +2 -2
- data/spec/name_tree_spec.rb +6 -6
- data/spec/object_store_spec.rb +17 -17
- data/spec/outline_spec.rb +35 -17
- data/spec/pdf_object_spec.rb +3 -1
- data/spec/png_spec.rb +22 -19
- data/spec/reference_spec.rb +24 -1
- data/spec/repeater_spec.rb +9 -9
- data/spec/security_spec.rb +3 -3
- data/spec/snapshot_spec.rb +3 -3
- data/spec/soft_mask_spec.rb +117 -0
- data/spec/span_spec.rb +4 -4
- data/spec/spec_helper.rb +12 -6
- data/spec/stamp_spec.rb +12 -12
- data/spec/stroke_styles_spec.rb +5 -5
- data/spec/table_spec.rb +458 -88
- data/spec/template_spec.rb +108 -54
- data/spec/text_at_spec.rb +17 -17
- data/spec/text_box_spec.rb +76 -45
- data/spec/text_rendering_mode_spec.rb +5 -5
- data/spec/text_spacing_spec.rb +4 -4
- data/spec/text_spec.rb +44 -40
- metadata +419 -250
- data/lib/prawn/graphics/gradient.rb +0 -84
- data/lib/prawn/security/arcfour.rb +0 -51
@@ -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::Example.generate(filename) do
|
21
|
+
# Using a TTF font file
|
22
|
+
font("#{Prawn::DATADIR}/fonts/Chalkboard.ttf") do
|
23
|
+
text "Written with the Chalkboard 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/Action Man.dfont") do
|
32
|
+
text "Written with the Action Man 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,75 @@
|
|
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::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 "group"
|
18
|
+
s.example "column_box"
|
19
|
+
end
|
20
|
+
|
21
|
+
p.section "Styling" do |s|
|
22
|
+
s.example "font"
|
23
|
+
s.example "font_size"
|
24
|
+
s.example "font_style"
|
25
|
+
s.example "color"
|
26
|
+
s.example "alignment"
|
27
|
+
s.example "leading"
|
28
|
+
s.example "kerning_and_character_spacing"
|
29
|
+
s.example "paragraph_indentation"
|
30
|
+
s.example "rotation"
|
31
|
+
end
|
32
|
+
|
33
|
+
p.section "Advanced Styling" do |s|
|
34
|
+
s.example "inline"
|
35
|
+
s.example "formatted_text"
|
36
|
+
s.example "formatted_callbacks"
|
37
|
+
s.example "rendering_and_color"
|
38
|
+
s.example "text_box_extensions"
|
39
|
+
end
|
40
|
+
|
41
|
+
p.section "External Fonts" do |s|
|
42
|
+
s.example "single_usage"
|
43
|
+
s.example "registering_families"
|
44
|
+
end
|
45
|
+
|
46
|
+
p.section "M17n" do |s|
|
47
|
+
s.example "utf8"
|
48
|
+
s.example "line_wrapping"
|
49
|
+
s.example "right_to_left_text"
|
50
|
+
s.example "fallback_fonts"
|
51
|
+
s.example "win_ansi_charset"
|
52
|
+
end
|
53
|
+
|
54
|
+
p.intro do
|
55
|
+
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.
|
56
|
+
|
57
|
+
The examples show:")
|
58
|
+
|
59
|
+
list( "Text that flows from page to page automatically starting new pages when necessary",
|
60
|
+
"How to use text boxes and place them on specific positions",
|
61
|
+
"What to do when a text box is too small to fit its content",
|
62
|
+
"How to proceed when you want to prevent paragraphs from splitting between pages",
|
63
|
+
"Flowing text in columns",
|
64
|
+
"How to change the text style configuring font, size, alignment and many other settings",
|
65
|
+
"How to style specific portions of a text with inline styling and formatted text",
|
66
|
+
"How to define formatted callbacks to reuse common styling definitions",
|
67
|
+
"How to use the different rendering modes available for the text methods",
|
68
|
+
"How to create your custom text box extensions",
|
69
|
+
"How to use external fonts on your pdfs",
|
70
|
+
"What happens when rendering text in different languages"
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
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::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::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,44 @@
|
|
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
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
16
|
+
%w[.. example_helper]))
|
17
|
+
|
18
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
19
|
+
Prawn::Example.generate(filename) do
|
20
|
+
string = "This is the sample text used for the text boxes. See how it " +
|
21
|
+
"behave with the various overflow options used."
|
22
|
+
|
23
|
+
text string
|
24
|
+
|
25
|
+
y_position = cursor - 20
|
26
|
+
[:truncate, :expand, :shrink_to_fit].each_with_index do |mode, i|
|
27
|
+
text_box string, :at => [i * 150, y_position],
|
28
|
+
:width => 100, :height => 50,
|
29
|
+
:overflow => mode
|
30
|
+
end
|
31
|
+
|
32
|
+
string = "If the box is too small for the text, :shrink_to_fit " +
|
33
|
+
"can render the text in a really small font size."
|
34
|
+
|
35
|
+
move_down 120
|
36
|
+
text string
|
37
|
+
y_position = cursor - 20
|
38
|
+
[nil, 8, 10, 12].each_with_index do |value, index|
|
39
|
+
text_box string, :at => [index * 150, y_position],
|
40
|
+
:width => 50, :height => 50,
|
41
|
+
:overflow => :shrink_to_fit,
|
42
|
+
:min_font_size => value
|
43
|
+
end
|
44
|
+
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::Example.generate(filename) do
|
12
|
+
text "Take this example, a simple Euro sign:"
|
13
|
+
text "€", :size => 32
|
14
|
+
move_down 20
|
15
|
+
|
16
|
+
text "Seems ok. Now let's try something more complex:"
|
17
|
+
text "ὕαλον ϕαγεῖν δύναμαι· τοῦτο οὔ με βλάπτει."
|
18
|
+
move_down 20
|
19
|
+
|
20
|
+
text "Looks like the current font (#{font.inspect}) doesn't support those."
|
21
|
+
text "Let's try them with another font."
|
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,59 @@
|
|
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::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, :at => [dx + offset, y], :skip_encoding => true)
|
54
|
+
end
|
55
|
+
|
56
|
+
dx += total_width
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/prawn.gemspec
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
PRAWN_VERSION = "1.0.0.rc1"
|
2
|
-
|
3
1
|
Gem::Specification.new do |spec|
|
4
2
|
spec.name = "prawn"
|
5
|
-
spec.version =
|
3
|
+
spec.version = File.read(File.expand_path('VERSION', File.dirname(__FILE__))).strip
|
6
4
|
spec.platform = Gem::Platform::RUBY
|
7
5
|
spec.summary = "A fast and nimble PDF generator for Ruby"
|
8
|
-
spec.files = Dir.glob("{examples,lib,spec,data}/**/**/*") +
|
9
|
-
["Rakefile", "prawn.gemspec", "COPYING", "LICENSE", "GPLv2", "GPLv3"
|
6
|
+
spec.files = Dir.glob("{examples,lib,spec,data,manual}/**/**/*") +
|
7
|
+
["Rakefile", "prawn.gemspec", "COPYING", "LICENSE", "GPLv2", "GPLv3",
|
8
|
+
"Gemfile"]
|
10
9
|
spec.require_path = "lib"
|
11
10
|
spec.required_ruby_version = '>= 1.8.7'
|
12
11
|
spec.required_rubygems_version = ">= 1.3.6"
|
@@ -18,9 +17,13 @@ Gem::Specification.new do |spec|
|
|
18
17
|
spec.authors = ["Gregory Brown","Brad Ediger","Daniel Nelson","Jonathan Greenberg","James Healy"]
|
19
18
|
spec.email = ["gregory.t.brown@gmail.com","brad@bradediger.com","dnelson@bluejade.com","greenberg@entryway.net","jimmy@deefa.com"]
|
20
19
|
spec.rubyforge_project = "prawn"
|
21
|
-
spec.add_dependency('pdf-reader', '>=0.9.0')
|
20
|
+
spec.add_dependency('pdf-reader', '>=0.9.0', '<2.0')
|
22
21
|
spec.add_dependency('ttfunk', '~>1.0.3')
|
22
|
+
spec.add_dependency('ruby-rc4')
|
23
|
+
spec.add_dependency('afm')
|
23
24
|
spec.add_development_dependency('pdf-inspector', '~> 1.0.1')
|
25
|
+
spec.add_development_dependency('coderay', '~> 1.0.7')
|
26
|
+
spec.add_development_dependency('rdoc')
|
24
27
|
spec.homepage = "http://prawn.majesticseacreature.com"
|
25
28
|
spec.description = <<END_DESC
|
26
29
|
Prawn is a fast, tiny, and nimble PDF generator for Ruby
|
@@ -34,7 +37,7 @@ END_DESC
|
|
34
37
|
|
35
38
|
Please read the changelog for details:
|
36
39
|
|
37
|
-
https://github.com/
|
40
|
+
https://github.com/prawnpdf/prawn/wiki/CHANGELOG
|
38
41
|
|
39
42
|
|
40
43
|
********************************************
|
data/spec/bounding_box_spec.rb
CHANGED
@@ -84,14 +84,14 @@ describe "A bounding box" do
|
|
84
84
|
it "should require width to be set" do
|
85
85
|
lambda do
|
86
86
|
Prawn::Document::BoundingBox.new(nil, nil, [100,100])
|
87
|
-
end.should
|
87
|
+
end.should raise_error(ArgumentError)
|
88
88
|
end
|
89
89
|
|
90
|
-
it "should
|
90
|
+
it "should raise_error an ArgumentError if a block is not passed" do
|
91
91
|
pdf = Prawn::Document.new
|
92
92
|
lambda do
|
93
93
|
pdf.bounding_box([0, 0], :width => 200)
|
94
|
-
end.should
|
94
|
+
end.should raise_error(ArgumentError)
|
95
95
|
end
|
96
96
|
|
97
97
|
end
|
@@ -100,6 +100,15 @@ describe "drawing bounding boxes" do
|
|
100
100
|
|
101
101
|
before(:each) { create_pdf }
|
102
102
|
|
103
|
+
it "should not stomp on the arguments to bounding_box" do
|
104
|
+
pdf = Prawn::Document.new
|
105
|
+
x = [100, 500]
|
106
|
+
pdf.bounding_box x, :width => 100 do
|
107
|
+
pdf.text "bork-bork-bork"
|
108
|
+
end
|
109
|
+
x.should == [100, 500]
|
110
|
+
end
|
111
|
+
|
103
112
|
it "should restore the margin box when bounding box exits" do
|
104
113
|
margin_box = @pdf.bounds
|
105
114
|
|
@@ -135,7 +144,7 @@ describe "drawing bounding boxes" do
|
|
135
144
|
@pdf.text "The rain in Spain falls mainly on the plains."
|
136
145
|
end
|
137
146
|
|
138
|
-
@pdf.y.should.
|
147
|
+
@pdf.y.should be_within(0.001).of(458.384)
|
139
148
|
end
|
140
149
|
|
141
150
|
it "should keep track of the max height the box was stretched to" do
|
@@ -153,7 +162,7 @@ describe "drawing bounding boxes" do
|
|
153
162
|
:height => 30 do
|
154
163
|
@pdf.text "hello"
|
155
164
|
end
|
156
|
-
@pdf.y.should.
|
165
|
+
@pdf.y.should be_within(0.001).of(orig_y - 30)
|
157
166
|
end
|
158
167
|
|
159
168
|
it "should not advance y-position if passed :hold_position => true" do
|
@@ -163,7 +172,7 @@ describe "drawing bounding boxes" do
|
|
163
172
|
@pdf.text "hello"
|
164
173
|
end
|
165
174
|
# y only advances by height of one line ("hello")
|
166
|
-
@pdf.y.should.
|
175
|
+
@pdf.y.should be_within(0.001).of(orig_y - @pdf.height_of("hello"))
|
167
176
|
end
|
168
177
|
|
169
178
|
it "should not advance y-position of a stretchy bbox if it would stretch " +
|
@@ -179,9 +188,8 @@ describe "drawing bounding boxes" do
|
|
179
188
|
# the bottom of the page, which we don't want. This should be equivalent to
|
180
189
|
# a bbox with :hold_position => true, where we only advance by the amount
|
181
190
|
# that was actually drawn.
|
182
|
-
@pdf.y.should.
|
183
|
-
@pdf.margin_box.absolute_top - @pdf.height_of("hello")
|
184
|
-
0.001
|
191
|
+
@pdf.y.should be_within(0.001).of(
|
192
|
+
@pdf.margin_box.absolute_top - @pdf.height_of("hello")
|
185
193
|
)
|
186
194
|
end
|
187
195
|
|
@@ -261,7 +269,7 @@ describe "Indentation" do
|
|
261
269
|
:height => 200, :columns => 2, :spacer => 20) do
|
262
270
|
width = @pdf.bounds.width
|
263
271
|
@pdf.indent(20) do
|
264
|
-
@pdf.bounds.width.should.
|
272
|
+
@pdf.bounds.width.should be_within(0.01).of(width - 20)
|
265
273
|
end
|
266
274
|
end
|
267
275
|
end
|
@@ -271,11 +279,93 @@ describe "Indentation" do
|
|
271
279
|
:height => 200, :columns => 2, :spacer => 20) do
|
272
280
|
width = @pdf.bounds.width
|
273
281
|
@pdf.indent(20, 30) do
|
274
|
-
@pdf.bounds.width.should.
|
282
|
+
@pdf.bounds.width.should be_within(0.01).of(width - 50)
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should maintain the same left indentation across column breaks" do
|
288
|
+
@pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
|
289
|
+
3.times do |column|
|
290
|
+
x = @pdf.bounds.left_side
|
291
|
+
@pdf.indent(20) do
|
292
|
+
@pdf.bounds.left_side.should == x+20
|
293
|
+
end
|
294
|
+
@pdf.bounds.move_past_bottom
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should not change the right margin if only left indentation is requested" do
|
300
|
+
@pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
|
301
|
+
3.times do |column|
|
302
|
+
x = @pdf.bounds.right_side
|
303
|
+
@pdf.indent(20) do
|
304
|
+
@pdf.bounds.right_side.should == x
|
305
|
+
end
|
306
|
+
@pdf.bounds.move_past_bottom
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should maintain the same right indentation across columns" do
|
312
|
+
@pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
|
313
|
+
3.times do |column|
|
314
|
+
x = @pdf.bounds.right_side
|
315
|
+
@pdf.indent(20, 10) do
|
316
|
+
@pdf.bounds.right_side.should == x-10
|
317
|
+
end
|
318
|
+
@pdf.bounds.move_past_bottom
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should keep the right indentation after nesting indents" do
|
324
|
+
@pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
|
325
|
+
3.times do |column|
|
326
|
+
# I am giving a right indent of 10...
|
327
|
+
@pdf.indent(20, 10) do
|
328
|
+
x = @pdf.bounds.right_side
|
329
|
+
# ...and no right indent here...
|
330
|
+
@pdf.indent(20) do
|
331
|
+
# right indent is inherited from the parent!
|
332
|
+
@pdf.bounds.right_side.should == x
|
333
|
+
end
|
334
|
+
end
|
335
|
+
@pdf.bounds.move_past_bottom
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should revert the right indentation if negative indent is given in nested indent" do
|
341
|
+
@pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
|
342
|
+
3.times do |column|
|
343
|
+
x = @pdf.bounds.right_side
|
344
|
+
@pdf.indent(20, 10) do
|
345
|
+
# requesting a negative right-indent of equivalent size...
|
346
|
+
@pdf.indent(20, -10) do
|
347
|
+
# ...resets the right margin to that of the column!
|
348
|
+
@pdf.bounds.right_side.should == x
|
349
|
+
end
|
350
|
+
end
|
351
|
+
@pdf.bounds.move_past_bottom
|
275
352
|
end
|
276
353
|
end
|
277
354
|
end
|
278
355
|
|
356
|
+
it "should reduce the available column width by the sum of all nested indents" do
|
357
|
+
@pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
|
358
|
+
3.times do |column|
|
359
|
+
w = @pdf.bounds.width
|
360
|
+
@pdf.indent(20, 10) do
|
361
|
+
@pdf.indent(20, 10) do
|
362
|
+
@pdf.bounds.width.should == w - 60
|
363
|
+
end
|
364
|
+
end
|
365
|
+
@pdf.bounds.move_past_bottom
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
279
369
|
end
|
280
370
|
end
|
281
371
|
|
@@ -292,12 +382,12 @@ end
|
|
292
382
|
|
293
383
|
describe "Deep-copying" do
|
294
384
|
it "should create a new object that does not copy @document" do
|
295
|
-
Prawn::Document.new do
|
296
|
-
orig = bounds
|
385
|
+
Prawn::Document.new do |pdf|
|
386
|
+
orig = pdf.bounds
|
297
387
|
copy = orig.deep_copy
|
298
388
|
|
299
|
-
copy.
|
300
|
-
copy.document.should
|
389
|
+
copy.should_not == pdf.bounds
|
390
|
+
copy.document.should be_nil
|
301
391
|
end
|
302
392
|
end
|
303
393
|
|
@@ -312,7 +402,7 @@ describe "Deep-copying" do
|
|
312
402
|
copy.parent.height.should == outside.height
|
313
403
|
|
314
404
|
# but should not be the same object
|
315
|
-
copy.parent.
|
405
|
+
copy.parent.should_not == outside
|
316
406
|
end
|
317
407
|
end
|
318
408
|
end
|
@@ -392,7 +482,7 @@ describe "BoundingBox#move_past_bottom" do
|
|
392
482
|
@pdf.text "Foo"
|
393
483
|
|
394
484
|
@pdf.bounds.move_past_bottom
|
395
|
-
@pdf.y.should
|
485
|
+
@pdf.y.should be_within(0.001).of(top_y)
|
396
486
|
@pdf.text "Bar"
|
397
487
|
|
398
488
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|