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,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# There are two drawing primitives in Prawn: <code>fill</code> and
|
4
|
+
# <code>stroke</code>.
|
5
|
+
#
|
6
|
+
# These are the methods that actually draw stuff on the document. All the other
|
7
|
+
# drawing shapes like <code>rectangle</code>, <code>circle</code> or
|
8
|
+
# <code>line_to</code> define drawing paths. These paths need to be either
|
9
|
+
# stroked or filled to gain form on the document.
|
10
|
+
#
|
11
|
+
# Calling these methods without a block will act on the drawing path that
|
12
|
+
# has been defined prior to the call.
|
13
|
+
#
|
14
|
+
# Calling with a block will act on the drawing path set within the
|
15
|
+
# block.
|
16
|
+
#
|
17
|
+
# Most of the methods which define drawing paths have methods of the same name
|
18
|
+
# starting with stroke_ and fill_ which create the drawing path and then stroke
|
19
|
+
# or fill it.
|
20
|
+
#
|
21
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
22
|
+
%w[.. example_helper]))
|
23
|
+
|
24
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
25
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
26
|
+
stroke_axis
|
27
|
+
|
28
|
+
# No block
|
29
|
+
line [0, 200], [100, 150]
|
30
|
+
stroke
|
31
|
+
|
32
|
+
rectangle [0, 100], 100, 100
|
33
|
+
fill
|
34
|
+
|
35
|
+
# With block
|
36
|
+
stroke { line [200, 200], [300, 150] }
|
37
|
+
fill { rectangle [200, 100], 100, 100 }
|
38
|
+
|
39
|
+
# Method hook
|
40
|
+
stroke_line [400, 200], [500, 150]
|
41
|
+
fill_rectangle [400, 100], 100, 100
|
42
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Prawn's fill operators (<code>fill</code> and <code>fill_and_stroke</code>
|
4
|
+
# both accept a <code>:fill_rule</code> option. These rules determine which
|
5
|
+
# parts of the page are counted as "inside" vs. "outside" the path. There are
|
6
|
+
# two fill rules:
|
7
|
+
#
|
8
|
+
# * <code>:nonzero_winding_number</code> (default): a point is inside the path
|
9
|
+
# if a ray from that point to infinity crosses a nonzero "net number" of path
|
10
|
+
# segments, where path segments intersecting in one direction are counted as
|
11
|
+
# positive and those in the other direction negative.
|
12
|
+
#
|
13
|
+
# * <code>:even_odd</code>: A point is inside the path if a ray from that point
|
14
|
+
# to infinity crosses an odd number of path segments, regardless of direction.
|
15
|
+
#
|
16
|
+
# The differences between the fill rules only come into play with complex
|
17
|
+
# paths; they are identical for simple shapes.
|
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
|
+
pentagram = [[181, 95], [0, 36], [111, 190], [111, 0], [0, 154]]
|
25
|
+
|
26
|
+
stroke_color 'ff0000'
|
27
|
+
line_width 2
|
28
|
+
|
29
|
+
text_box "Nonzero Winding Number", :at => [50, 215], :width => 170,
|
30
|
+
:align => :center
|
31
|
+
polygon(*pentagram.map { |x, y| [x+50, y] })
|
32
|
+
fill_and_stroke
|
33
|
+
|
34
|
+
text_box "Even-Odd", :at => [330, 215], :width => 170, :align => :center
|
35
|
+
polygon(*pentagram.map { |x, y| [x+330, y] })
|
36
|
+
fill_and_stroke(:fill_rule => :even_odd)
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Note that because of the way PDF renders radial gradients in order to get
|
4
|
+
# solid fill your start circle must be fully inside your end circle.
|
5
|
+
# Otherwise you will get triangle fill like illustrated in the example below.
|
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
|
+
stroke_axis
|
13
|
+
self.line_width = 10
|
14
|
+
|
15
|
+
fill_gradient [50, 300], [150, 200], 'ff0000', '0000ff'
|
16
|
+
fill_rectangle [50, 300], 100, 100
|
17
|
+
|
18
|
+
stroke_gradient [200, 200], [300, 300], '00ffff', 'ffff00'
|
19
|
+
stroke_rectangle [200, 300], 100, 100
|
20
|
+
|
21
|
+
fill_gradient [350, 300], [450, 200], 'ff0000', '0000ff'
|
22
|
+
stroke_gradient [350, 200], [450, 300], '00ffff', 'ffff00'
|
23
|
+
fill_and_stroke_rectangle [350, 300], 100, 100
|
24
|
+
|
25
|
+
fill_gradient [100, 100], 0, [100, 100], 70.71, 'ff0000', '0000ff'
|
26
|
+
fill_rectangle [50, 150], 100, 100
|
27
|
+
|
28
|
+
stroke_gradient [250, 100], 45, [250, 100], 70.71, '00ffff', 'ffff00'
|
29
|
+
stroke_rectangle [200, 150], 100, 100
|
30
|
+
|
31
|
+
stroke_gradient [400, 100], 45, [400, 100], 70.71, '00ffff', 'ffff00'
|
32
|
+
fill_gradient [400, 100], 0, [400, 100], 70.71, 'ff0000', '0000ff'
|
33
|
+
fill_and_stroke_rectangle [350, 150], 100, 100
|
34
|
+
|
35
|
+
fill_gradient [500, 300], 15, [500, 50], 0, 'ff0000', '0000ff'
|
36
|
+
fill_rectangle [485, 300], 30, 250
|
37
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Examples for the Graphics package.
|
4
|
+
#
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
6
|
+
%w[.. example_helper]))
|
7
|
+
|
8
|
+
Prawn::ManualBuilder::Example.generate("graphics.pdf", :page_size => "FOLIO") do
|
9
|
+
|
10
|
+
package "graphics" do |p|
|
11
|
+
|
12
|
+
p.section "Basics" do |s|
|
13
|
+
s.example "helper"
|
14
|
+
s.example "fill_and_stroke"
|
15
|
+
end
|
16
|
+
|
17
|
+
p.section "Shapes" do |s|
|
18
|
+
s.example "lines_and_curves"
|
19
|
+
s.example "common_lines"
|
20
|
+
s.example "rectangle"
|
21
|
+
s.example "polygon"
|
22
|
+
s.example "circle_and_ellipse"
|
23
|
+
end
|
24
|
+
|
25
|
+
p.section "Fill and Stroke settings" do |s|
|
26
|
+
s.example "line_width"
|
27
|
+
s.example "stroke_cap"
|
28
|
+
s.example "stroke_join"
|
29
|
+
s.example "stroke_dash"
|
30
|
+
s.example "color"
|
31
|
+
s.example "gradients"
|
32
|
+
s.example "transparency"
|
33
|
+
s.example "soft_masks"
|
34
|
+
s.example "fill_rules"
|
35
|
+
end
|
36
|
+
|
37
|
+
p.section "Transformations" do |s|
|
38
|
+
s.example "rotate"
|
39
|
+
s.example "translate"
|
40
|
+
s.example "scale"
|
41
|
+
end
|
42
|
+
|
43
|
+
p.intro do
|
44
|
+
prose("Here we show all the drawing methods provided by Prawn. Use them to draw the most beautiful imaginable things.
|
45
|
+
|
46
|
+
Most of the content that you'll add to your pdf document will use the graphics package. Even text is rendered on a page just like a rectangle so even if you never use any of the shapes described here you should at least read the basic examples.
|
47
|
+
|
48
|
+
The examples show:")
|
49
|
+
|
50
|
+
list( "All the possible ways that you can fill or stroke shapes on a page",
|
51
|
+
"How to draw all the shapes that Prawn has to offer from a measly line to a mighty polygon or ellipse",
|
52
|
+
"The configuration options for stroking lines and filling shapes",
|
53
|
+
"How to apply transformations to your drawing space"
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# To produce this manual we use the <code>stroke_axis</code> helper method
|
4
|
+
# within the examples.
|
5
|
+
#
|
6
|
+
# <code>stroke_axis</code> prints the x and y axis for the current bounding box
|
7
|
+
# with markers in 100 increments. The defaults can be changed with various
|
8
|
+
# options.
|
9
|
+
#
|
10
|
+
# Note that the examples define a custom <code>:height</code> option so that
|
11
|
+
# only the example canvas is used (as seen with the output of the first line of
|
12
|
+
# the example 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
|
+
stroke_axis
|
20
|
+
stroke_axis(:at => [70, 70], :height => 200, :step_length => 50,
|
21
|
+
:negative_axes_length => 5, :color => '0000FF')
|
22
|
+
stroke_axis(:at => [140, 140], :width => 200, :height => cursor.to_i - 140,
|
23
|
+
:step_length => 20, :negative_axes_length => 40, :color => 'FF00')
|
24
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# The <code>line_width=</code> method sets the stroke width for subsequent
|
4
|
+
# stroke calls.
|
5
|
+
#
|
6
|
+
# Since Ruby assumes that an unknown variable on the left hand side of an
|
7
|
+
# assignment is a local temporary, rather than a setter method, if you are using
|
8
|
+
# the block call to <code>Prawn::Document.generate</code> without passing params
|
9
|
+
# you will need to call <code>line_width</code> on self.
|
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
|
+
stroke_axis
|
17
|
+
|
18
|
+
y = 250
|
19
|
+
|
20
|
+
3.times do |i|
|
21
|
+
case i
|
22
|
+
when 0 then line_width = 10 # This call will have no effect
|
23
|
+
when 1 then self.line_width = 10
|
24
|
+
when 2 then self.line_width = 25
|
25
|
+
end
|
26
|
+
|
27
|
+
stroke do
|
28
|
+
horizontal_line 50, 150, :at => y
|
29
|
+
rectangle [275, y + 25], 50, 50
|
30
|
+
circle [500, y], 25
|
31
|
+
end
|
32
|
+
|
33
|
+
y -= 100
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Prawn supports drawing both lines and curves starting either at the current
|
4
|
+
# position, or from a specified starting position.
|
5
|
+
#
|
6
|
+
# <code>line_to</code> and <code>curve_to</code> set the drawing path from the
|
7
|
+
# current drawing position to the specified point. The initial drawing position
|
8
|
+
# can be set with <code>move_to</code>. They are useful when you want to chain
|
9
|
+
# successive calls because the drawing position will be set to the specified
|
10
|
+
# point afterwards.
|
11
|
+
#
|
12
|
+
# <code>line</code> and <code>curve</code> set the drawing path between the two
|
13
|
+
# specified points.
|
14
|
+
#
|
15
|
+
# Both curve methods define a Bezier curve bounded by two aditional points
|
16
|
+
# provided as the <code>:bounds</code> param.
|
17
|
+
#
|
18
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
19
|
+
%w[.. example_helper]))
|
20
|
+
|
21
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
22
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
23
|
+
stroke_axis
|
24
|
+
|
25
|
+
# line_to and curve_to
|
26
|
+
stroke do
|
27
|
+
move_to 0, 0
|
28
|
+
|
29
|
+
line_to 100, 100
|
30
|
+
line_to 0, 100
|
31
|
+
|
32
|
+
curve_to [150, 250], :bounds => [[20, 200], [120, 200]]
|
33
|
+
curve_to [200, 0], :bounds => [[150, 200], [450, 10]]
|
34
|
+
end
|
35
|
+
|
36
|
+
# line and curve
|
37
|
+
stroke do
|
38
|
+
line [300,200], [400,50]
|
39
|
+
curve [500, 0], [400, 200], :bounds => [[600, 300], [300, 390]]
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Drawing polygons in Prawn is easy, just pass a sequence of points to one of
|
4
|
+
# the polygon family of methods.
|
5
|
+
#
|
6
|
+
# Just like <code>rounded_rectangle</code> we also have
|
7
|
+
# <code>rounded_polygon</code>. The only difference is the radius param comes
|
8
|
+
# before the polygon points.
|
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
|
+
stroke_axis
|
16
|
+
|
17
|
+
# Triangle
|
18
|
+
stroke_polygon [50, 200], [50, 300], [150, 300]
|
19
|
+
|
20
|
+
# Hexagon
|
21
|
+
fill_polygon [50, 150], [150, 200], [250, 150],
|
22
|
+
[250, 50], [150, 0], [50, 50]
|
23
|
+
|
24
|
+
# Pentagram
|
25
|
+
pentagon_points = [500, 100], [430, 5], [319, 41], [319, 159], [430, 195]
|
26
|
+
pentagram_points = [0, 2, 4, 1, 3].map{ |i| pentagon_points[i] }
|
27
|
+
|
28
|
+
stroke_rounded_polygon(20, *pentagram_points)
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# To draw a rectangle, just provide the upper-left corner, width and height to
|
4
|
+
# the <code>rectangle</code> method.
|
5
|
+
#
|
6
|
+
# There's also <code>rounded_rectangle</code>. Just provide an additional radius
|
7
|
+
# value for the rounded corners.
|
8
|
+
#
|
9
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
10
|
+
%w[.. example_helper]))
|
11
|
+
|
12
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
13
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
14
|
+
stroke_axis
|
15
|
+
|
16
|
+
stroke do
|
17
|
+
rectangle [100, 300], 100, 200
|
18
|
+
|
19
|
+
rounded_rectangle [300, 300], 100, 200, 20
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This transformation is used to rotate the user space. Give it an angle
|
4
|
+
# and an <code>:origin</code> point about which to rotate and a block.
|
5
|
+
# Everything inside the block will be drawn with the rotated coordinates.
|
6
|
+
#
|
7
|
+
# The angle is in degrees.
|
8
|
+
#
|
9
|
+
# If you omit the <code>:origin</code> option the page origin will be used.
|
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
|
+
stroke_axis
|
17
|
+
|
18
|
+
fill_circle [250, 200], 2
|
19
|
+
|
20
|
+
12.times do |i|
|
21
|
+
|
22
|
+
rotate(i * 30, :origin => [250, 200]) do
|
23
|
+
|
24
|
+
stroke_rectangle [350, 225], 100, 50
|
25
|
+
draw_text "Rotated #{i * 30}°", :size => 10, :at => [360, 205]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This transformation is used to scale the user space. Give it an scale factor
|
4
|
+
# and an <code>:origin</code> point and everything inside the block will be
|
5
|
+
# scaled using the origin point as reference.
|
6
|
+
#
|
7
|
+
# If you omit the <code>:origin</code> option the page origin will be used.
|
8
|
+
#
|
9
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
10
|
+
%w[.. example_helper]))
|
11
|
+
|
12
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
13
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
14
|
+
stroke_axis
|
15
|
+
|
16
|
+
width = 100
|
17
|
+
height = 50
|
18
|
+
|
19
|
+
x = 50
|
20
|
+
y = 200
|
21
|
+
|
22
|
+
stroke_rectangle [x, y], width, height
|
23
|
+
text_box "reference rectangle", :at => [x + 10, y - 10], :width => width - 20
|
24
|
+
|
25
|
+
scale(2, :origin => [x, y]) do
|
26
|
+
stroke_rectangle [x, y], width, height
|
27
|
+
text_box "rectangle scaled from upper-left corner",
|
28
|
+
:at => [x, y - height - 5], :width => width
|
29
|
+
end
|
30
|
+
|
31
|
+
x = 350
|
32
|
+
|
33
|
+
stroke_rectangle [x, y], width, height
|
34
|
+
text_box "reference rectangle", :at => [x + 10, y - 10], :width => width - 20
|
35
|
+
|
36
|
+
scale(2, :origin => [x + width / 2, y - height / 2]) do
|
37
|
+
stroke_rectangle [x, y], width, height
|
38
|
+
text_box "rectangle scaled from center",
|
39
|
+
:at => [x, y - height - 5], :width => width
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Soft masks are user for more complex alpha channel manipulations. You can use
|
4
|
+
# arbitrary drawing functions for creation of soft masks. The resulting alpha
|
5
|
+
# channel is made of greyscale version of the drawing (luminosity channel to be
|
6
|
+
# precise). So while you can use any combination of colors for soft masks it's
|
7
|
+
# easier to use greyscales. Black will result in full transparency and white
|
8
|
+
# will make region fully opaque.
|
9
|
+
#
|
10
|
+
# Soft mask is a part of page graphic state. So if you want to apply soft mask
|
11
|
+
# only to a part of page you need to enclose drawing instructions in
|
12
|
+
# <code>save_graphics_state</code> block.
|
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
|
+
save_graphics_state do
|
20
|
+
soft_mask do
|
21
|
+
0.upto 15 do |i|
|
22
|
+
fill_color 0, 0, 0, 100.0 / 16.0 * (15 - i)
|
23
|
+
fill_circle [75 + i * 25, 100], 60
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
fill_color '009ddc'
|
28
|
+
fill_rectangle [0, 60], 600, 20
|
29
|
+
|
30
|
+
fill_color '963d97'
|
31
|
+
fill_rectangle [0, 80], 600, 20
|
32
|
+
|
33
|
+
fill_color 'e03a3e'
|
34
|
+
fill_rectangle [0, 100], 600, 20
|
35
|
+
|
36
|
+
fill_color 'f5821f'
|
37
|
+
fill_rectangle [0, 120], 600, 20
|
38
|
+
|
39
|
+
fill_color 'fdb827'
|
40
|
+
fill_rectangle [0, 140], 600, 20
|
41
|
+
|
42
|
+
fill_color '61bb46'
|
43
|
+
fill_rectangle [0, 160], 600, 20
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|