pdf-writer 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +44 -0
- data/LICENCE +118 -0
- data/README +32 -0
- data/bin/loader +54 -0
- data/bin/manual +22 -0
- data/bin/manual.bat +2 -0
- data/demo/chunkybacon.rb +28 -0
- data/demo/code.rb +63 -0
- data/demo/colornames.rb +843 -0
- data/demo/demo.rb +65 -0
- data/demo/gettysburg.rb +58 -0
- data/demo/hello.rb +18 -0
- data/demo/individual-i.rb +81 -0
- data/demo/pac.rb +62 -0
- data/demo/pagenumber.rb +67 -0
- data/demo/qr-language.rb +573 -0
- data/demo/qr-library.rb +371 -0
- data/images/chunkybacon.jpg +0 -0
- data/images/chunkybacon.png +0 -0
- data/images/pdfwriter-icon.jpg +0 -0
- data/images/pdfwriter-small.jpg +0 -0
- data/lib/pdf/charts.rb +13 -0
- data/lib/pdf/charts/stddev.rb +431 -0
- data/lib/pdf/grid.rb +135 -0
- data/lib/pdf/math.rb +108 -0
- data/lib/pdf/quickref.rb +330 -0
- data/lib/pdf/simpletable.rb +946 -0
- data/lib/pdf/techbook.rb +890 -0
- data/lib/pdf/writer.rb +2661 -0
- data/lib/pdf/writer/arc4.rb +63 -0
- data/lib/pdf/writer/fontmetrics.rb +201 -0
- data/lib/pdf/writer/fonts/Courier-Bold.afm +342 -0
- data/lib/pdf/writer/fonts/Courier-BoldOblique.afm +342 -0
- data/lib/pdf/writer/fonts/Courier-Oblique.afm +342 -0
- data/lib/pdf/writer/fonts/Courier.afm +342 -0
- data/lib/pdf/writer/fonts/Helvetica-Bold.afm +2827 -0
- data/lib/pdf/writer/fonts/Helvetica-BoldOblique.afm +2827 -0
- data/lib/pdf/writer/fonts/Helvetica-Oblique.afm +3051 -0
- data/lib/pdf/writer/fonts/Helvetica.afm +3051 -0
- data/lib/pdf/writer/fonts/MustRead.html +1 -0
- data/lib/pdf/writer/fonts/Symbol.afm +213 -0
- data/lib/pdf/writer/fonts/Times-Bold.afm +2588 -0
- data/lib/pdf/writer/fonts/Times-BoldItalic.afm +2384 -0
- data/lib/pdf/writer/fonts/Times-Italic.afm +2667 -0
- data/lib/pdf/writer/fonts/Times-Roman.afm +2419 -0
- data/lib/pdf/writer/fonts/ZapfDingbats.afm +225 -0
- data/lib/pdf/writer/graphics.rb +727 -0
- data/lib/pdf/writer/graphics/imageinfo.rb +365 -0
- data/lib/pdf/writer/lang.rb +43 -0
- data/lib/pdf/writer/lang/en.rb +77 -0
- data/lib/pdf/writer/object.rb +23 -0
- data/lib/pdf/writer/object/action.rb +40 -0
- data/lib/pdf/writer/object/annotation.rb +42 -0
- data/lib/pdf/writer/object/catalog.rb +39 -0
- data/lib/pdf/writer/object/contents.rb +68 -0
- data/lib/pdf/writer/object/destination.rb +40 -0
- data/lib/pdf/writer/object/encryption.rb +53 -0
- data/lib/pdf/writer/object/font.rb +76 -0
- data/lib/pdf/writer/object/fontdescriptor.rb +34 -0
- data/lib/pdf/writer/object/fontencoding.rb +39 -0
- data/lib/pdf/writer/object/image.rb +168 -0
- data/lib/pdf/writer/object/info.rb +55 -0
- data/lib/pdf/writer/object/outline.rb +30 -0
- data/lib/pdf/writer/object/outlines.rb +30 -0
- data/lib/pdf/writer/object/page.rb +195 -0
- data/lib/pdf/writer/object/pages.rb +115 -0
- data/lib/pdf/writer/object/procset.rb +46 -0
- data/lib/pdf/writer/object/viewerpreferences.rb +74 -0
- data/lib/pdf/writer/ohash.rb +58 -0
- data/lib/pdf/writer/oreader.rb +25 -0
- data/lib/pdf/writer/state.rb +48 -0
- data/lib/pdf/writer/strokestyle.rb +138 -0
- data/manual.pwd +5151 -0
- metadata +147 -0
data/demo/demo.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# $Id: demo.rb,v 1.4 2005/06/07 04:19:57 austin Exp $
|
10
|
+
#++
|
11
|
+
load '../bin/loader'
|
12
|
+
ClassLoader.new('pdf/writer')
|
13
|
+
|
14
|
+
if ARGV.empty?
|
15
|
+
line = 'Ruby Rocks'
|
16
|
+
else
|
17
|
+
line = ARGV.join(" ")
|
18
|
+
end
|
19
|
+
|
20
|
+
pdf = PDF::Writer.new
|
21
|
+
|
22
|
+
# Do some funky stuff in the background, in a nice light blue, which is
|
23
|
+
# bound to clash with something and some red for the hell of it
|
24
|
+
x = 578
|
25
|
+
r1 = 25
|
26
|
+
|
27
|
+
40.step(1, -3) do |xw|
|
28
|
+
tone = 1.0 - (xw / 40.0) * 0.2
|
29
|
+
|
30
|
+
pdf.stroke_style(PDF::Writer::StrokeStyle.new(xw))
|
31
|
+
pdf.stroke_color(Color::RGB.from_fraction(tone, 1, tone))
|
32
|
+
pdf.circle_at(50, 750, r1).stroke
|
33
|
+
r1 += xw
|
34
|
+
end
|
35
|
+
|
36
|
+
40.step(1, -3) do |xw|
|
37
|
+
tone = 1.0 - (xw / 40.0) * 0.2
|
38
|
+
|
39
|
+
pdf.stroke_style(PDF::Writer::StrokeStyle.new(xw))
|
40
|
+
pdf.stroke_color(Color::RGB.from_fraction(tone, tone, 1))
|
41
|
+
pdf.line(x, 0, x, 842)
|
42
|
+
x = (x - xw - 2)
|
43
|
+
end
|
44
|
+
|
45
|
+
pdf.stroke_color(Color::Black)
|
46
|
+
pdf.stroke_style(PDF::Writer::StrokeStyle.new(1))
|
47
|
+
pdf.rectangle(20, 20, 558, 802)
|
48
|
+
|
49
|
+
y = 800
|
50
|
+
50.step(5, -5) do |size|
|
51
|
+
height = pdf.font_height(size)
|
52
|
+
y = y - height
|
53
|
+
|
54
|
+
pdf.add_text(30, y, size, line)
|
55
|
+
end
|
56
|
+
|
57
|
+
(0...360).step(20) do |angle|
|
58
|
+
pdf.fill_color(Color::RGB.from_fraction(rand, rand, rand))
|
59
|
+
|
60
|
+
pdf.add_text(300 + Math.cos(PDF::Math.deg2rad(angle)) * 40,
|
61
|
+
300 - Math.sin(PDF::Math.deg2rad(angle)) * 40,
|
62
|
+
20, line, angle)
|
63
|
+
end
|
64
|
+
|
65
|
+
pdf.save_as("demo.pdf", true)
|
data/demo/gettysburg.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# $Id: gettysburg.rb,v 1.3 2005/06/07 04:19:57 austin Exp $
|
10
|
+
#++
|
11
|
+
load '../bin/loader'
|
12
|
+
ClassLoader.new('pdf/writer')
|
13
|
+
|
14
|
+
pdf = PDF::Writer.new
|
15
|
+
|
16
|
+
GETTYSBURG = <<-'EOS'
|
17
|
+
Four score and seven years ago our fathers brought forth on this
|
18
|
+
continent a new nation, conceived in liberty and dedicated to the
|
19
|
+
proposition that all men are created equal. Now we are engaged in
|
20
|
+
a great civil war, testing whether that nation or any nation so
|
21
|
+
conceived and so dedicated can long endure. We are met on a great
|
22
|
+
battlefield of that war. We have come to dedicate a portion of
|
23
|
+
that field as a final resting-place for those who here gave their
|
24
|
+
lives that that nation might live. It is altogether fitting and
|
25
|
+
proper that we should do this. But in a larger sense, we cannot
|
26
|
+
dedicate, we cannot consecrate, we cannot hallow this ground.
|
27
|
+
The brave men, living and dead who struggled here have consecrated
|
28
|
+
it far above our poor power to add or detract. The world will
|
29
|
+
little note nor long remember what we say here, but it can never
|
30
|
+
forget what they did here. It is for us the living rather to be
|
31
|
+
dedicated here to the unfinished work which they who fought here
|
32
|
+
have thus far so nobly advanced. It is rather for us to be here
|
33
|
+
dedicated to the great task remaining before us�that from these
|
34
|
+
honored dead we take increased devotion to that cause for which
|
35
|
+
they gave the last full measure of devotion�that we here highly
|
36
|
+
resolve that these dead shall not have died in vain, that this
|
37
|
+
nation under God shall have a new birth of freedom, and that
|
38
|
+
government of the people, by the people, for the people shall
|
39
|
+
not perish from the earth.
|
40
|
+
EOS
|
41
|
+
|
42
|
+
gba = GETTYSBURG.split($/).join(" ").squeeze
|
43
|
+
|
44
|
+
pdf.text "The Gettysburg Address\n\n", :font_size => 36,
|
45
|
+
:justification => :center
|
46
|
+
|
47
|
+
y0 = pdf.y + 18
|
48
|
+
pdf.text gba, :justification => :full, :font_size => 14, :left => 50,
|
49
|
+
:right => 50
|
50
|
+
pdf.move_pointer(36)
|
51
|
+
pdf.text "U.S. President Abraham Lincoln, 19 November 1863",
|
52
|
+
:justification => :right, :right => 100
|
53
|
+
pdf.text "Gettysburg, Pennsylvania", :justification => :right, :right => 100
|
54
|
+
|
55
|
+
pdf.rounded_rectangle(pdf.left_margin + 25, y0, pdf.margin_width - 50,
|
56
|
+
y0 - pdf.y + 18, 10).stroke
|
57
|
+
|
58
|
+
pdf.save_as("gettysburg.pdf")
|
data/demo/hello.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# $Id: hello.rb,v 1.5 2005/06/07 04:19:57 austin Exp $
|
10
|
+
#++
|
11
|
+
load '../bin/loader'
|
12
|
+
ClassLoader.new('pdf/writer')
|
13
|
+
|
14
|
+
pdf = PDF::Writer.new
|
15
|
+
pdf.select_font "Times-Roman"
|
16
|
+
pdf.text "Hello, Ruby.", :font_size => 72, :justification => :center
|
17
|
+
|
18
|
+
pdf.save_as("hello.pdf")
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# $Id: individual-i.rb,v 1.3 2005/06/07 04:19:57 austin Exp $
|
10
|
+
#++
|
11
|
+
load '../bin/loader'
|
12
|
+
ClassLoader.new('pdf/writer')
|
13
|
+
|
14
|
+
require 'color/palette/monocontrast'
|
15
|
+
|
16
|
+
class IndividualI
|
17
|
+
def initialize(size = 100)
|
18
|
+
@size = size
|
19
|
+
end
|
20
|
+
|
21
|
+
# The size of the "i" in points.
|
22
|
+
attr_accessor :size
|
23
|
+
|
24
|
+
def half_i(pdf)
|
25
|
+
pdf.move_to(0, 82)
|
26
|
+
pdf.line_to(0, 78)
|
27
|
+
pdf.line_to(9, 78)
|
28
|
+
pdf.line_to(9, 28)
|
29
|
+
pdf.line_to(0, 28)
|
30
|
+
pdf.line_to(0, 23)
|
31
|
+
pdf.line_to(18, 23)
|
32
|
+
pdf.line_to(18, 82)
|
33
|
+
pdf.fill
|
34
|
+
end
|
35
|
+
private :half_i
|
36
|
+
|
37
|
+
def draw(pdf, x, y)
|
38
|
+
pdf.save_state
|
39
|
+
pdf.translate_axis(x, y)
|
40
|
+
pdf.scale_axis(1 * (@size / 100.0), -1 * (@size / 100.0))
|
41
|
+
|
42
|
+
pdf.circle_at(20, 10, 7.5)
|
43
|
+
pdf.fill
|
44
|
+
|
45
|
+
half_i(pdf)
|
46
|
+
|
47
|
+
pdf.translate_axis(40, 0)
|
48
|
+
pdf.scale_axis(-1, 1)
|
49
|
+
|
50
|
+
half_i(pdf)
|
51
|
+
|
52
|
+
pdf.restore_state
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
pdf = PDF::Writer.new
|
57
|
+
ii = IndividualI.new(24)
|
58
|
+
|
59
|
+
x = pdf.absolute_left_margin
|
60
|
+
y = pdf.absolute_top_margin
|
61
|
+
|
62
|
+
bg = Color::RGB.from_fraction(rand, rand, rand)
|
63
|
+
fg = Color::RGB.from_fraction(rand, rand, rand)
|
64
|
+
pal = Color::Palette::MonoContrast.new(bg, fg)
|
65
|
+
|
66
|
+
sz = 24
|
67
|
+
|
68
|
+
(-5..5).each do |col|
|
69
|
+
pdf.fill_color pal.background[col]
|
70
|
+
ii.draw(pdf, x, y)
|
71
|
+
ii.size += sz
|
72
|
+
x += sz / 2.0
|
73
|
+
y -= sz / 2.0
|
74
|
+
pdf.fill_color pal.foreground[col]
|
75
|
+
ii.draw(pdf, x, y)
|
76
|
+
x += sz / 2.0
|
77
|
+
y -= sz / 2.0
|
78
|
+
ii.size += sz
|
79
|
+
end
|
80
|
+
|
81
|
+
pdf.save_as("individual-i.pdf")
|
data/demo/pac.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# $Id: pac.rb,v 1.3 2005/06/07 04:19:57 austin Exp $
|
10
|
+
#++
|
11
|
+
load '../bin/loader'
|
12
|
+
ClassLoader.new('pdf/writer')
|
13
|
+
|
14
|
+
pdf = PDF::Writer.new(:orientation => :landscape)
|
15
|
+
|
16
|
+
pdf.fill_color Color::Black
|
17
|
+
pdf.rectangle(0, 0, pdf.page_width, pdf.page_height).fill
|
18
|
+
|
19
|
+
# Wall
|
20
|
+
pdf.fill_color Color::Magenta
|
21
|
+
pdf.stroke_color Color::Cyan
|
22
|
+
pdf.rounded_rectangle(20, 500, 750, 20, 10).close_fill_stroke
|
23
|
+
pdf.rounded_rectangle(20, 200, 750, 20, 10).close_fill_stroke
|
24
|
+
|
25
|
+
# Body
|
26
|
+
pdf.fill_color Color::Yellow
|
27
|
+
pdf.stroke_color Color::Black
|
28
|
+
pdf.circle_at(150, 350, 100).fill_stroke
|
29
|
+
|
30
|
+
# Mouth
|
31
|
+
pdf.fill_color Color::Black
|
32
|
+
pdf.segment_at(150, 350, 100, 100, 30, -30).close_fill_stroke
|
33
|
+
|
34
|
+
# Dot
|
35
|
+
pdf.fill_color Color::Yellow
|
36
|
+
pdf.circle_at(250, 350, 20).fill_stroke
|
37
|
+
pdf.circle_at(300, 350, 10).fill_stroke
|
38
|
+
pdf.circle_at(350, 350, 10).fill_stroke
|
39
|
+
pdf.circle_at(400, 350, 10).fill_stroke
|
40
|
+
pdf.circle_at(450, 350, 10).fill_stroke
|
41
|
+
|
42
|
+
pdf.fill_color Color::Blue
|
43
|
+
pdf.stroke_color Color::Cyan
|
44
|
+
pdf.move_to(500, 250)
|
45
|
+
pdf.line_to(500, 425)
|
46
|
+
pdf.curve_to(550, 475, 600, 475, 650, 425)
|
47
|
+
pdf.line_to(650, 250)
|
48
|
+
pdf.line_to(625, 275)
|
49
|
+
pdf.line_to(600, 250)
|
50
|
+
pdf.line_to(575, 275)
|
51
|
+
pdf.line_to(550, 250)
|
52
|
+
pdf.line_to(525, 275)
|
53
|
+
pdf.line_to(500, 250).fill_stroke
|
54
|
+
|
55
|
+
pdf.fill_color Color::White
|
56
|
+
pdf.rectangle(525, 375, 25, 25).fill
|
57
|
+
pdf.rectangle(575, 375, 25, 25).fill
|
58
|
+
pdf.fill_color Color::Black
|
59
|
+
pdf.rectangle(525, 375, 10, 10).fill
|
60
|
+
pdf.rectangle(575, 375, 10, 10).fill
|
61
|
+
|
62
|
+
pdf.save_as("pac.pdf")
|
data/demo/pagenumber.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# $Id: pagenumber.rb,v 1.4 2005/06/07 04:19:57 austin Exp $
|
10
|
+
#++
|
11
|
+
load '../bin/loader'
|
12
|
+
ClassLoader.new('pdf/writer')
|
13
|
+
|
14
|
+
def grey_page(pdf)
|
15
|
+
@page_num ||= 0
|
16
|
+
@page_num += 1
|
17
|
+
pdf.save_state
|
18
|
+
pdf.fill_color Color::Grey90
|
19
|
+
x = pdf.absolute_x_middle - (pdf.text_width(48, @page_num) / 2.0)
|
20
|
+
y = pdf.absolute_y_middle - (pdf.font_height(48) / 2.0)
|
21
|
+
pdf.add_text(x, y, 48, @page_num)
|
22
|
+
pdf.restore_state
|
23
|
+
end
|
24
|
+
|
25
|
+
def make_page(pdf)
|
26
|
+
pdf.start_new_page
|
27
|
+
grey_page(pdf)
|
28
|
+
end
|
29
|
+
|
30
|
+
pdf = PDF::Writer.new(:paper => "A10")
|
31
|
+
pdf.margins_pt 0
|
32
|
+
pdf.select_font "Helvetica"
|
33
|
+
|
34
|
+
grey_page(pdf) # Page 1: blank
|
35
|
+
sa = pdf.start_page_numbering(5, 60, 9, nil, nil, 1)
|
36
|
+
make_page(pdf) # Page 2: 1 of 2
|
37
|
+
make_page(pdf) # Page 3: 2 of 2
|
38
|
+
pdf.stop_page_numbering(true, :current, sa)
|
39
|
+
make_page(pdf) # Page 4: blank
|
40
|
+
sb = pdf.start_page_numbering(5, 50, 9, :center, nil, 10)
|
41
|
+
make_page(pdf) # Page 5: 10 of 12
|
42
|
+
make_page(pdf) # Page 6: 11 of 12
|
43
|
+
pdf.stop_page_numbering(true, :next, sb)
|
44
|
+
make_page(pdf) # Page 7: 12 of 12
|
45
|
+
sc = pdf.start_page_numbering(5, 40, 9, nil, nil, 1)
|
46
|
+
make_page(pdf) # Page 8: 1 of 3
|
47
|
+
make_page(pdf) # Page 9: 2 of 3
|
48
|
+
make_page(pdf) # Page 10: 3 of 3
|
49
|
+
pdf.stop_page_numbering(true, :current, sc)
|
50
|
+
make_page(pdf) # Page 11: blank
|
51
|
+
sd = pdf.start_page_numbering(5, 30, 9, nil, nil, 1)
|
52
|
+
make_page(pdf) # Page 12: 1 of 6
|
53
|
+
make_page(pdf) # Page 13: 2 of 6
|
54
|
+
se = pdf.start_page_numbering(5, 20, 9, nil, nil, 5)
|
55
|
+
sf = pdf.start_page_numbering(5, 10, 9, :right, nil, 1)
|
56
|
+
make_page(pdf) # Page 14: 3 of 6, 5 of 10, 1 of 8
|
57
|
+
make_page(pdf) # Page 15: 4 of 6, 6 of 10, 2 of 8
|
58
|
+
make_page(pdf) # Page 16: 5 of 6, 7 of 10, 3 of 8
|
59
|
+
pdf.stop_page_numbering(true, :next, sd)
|
60
|
+
make_page(pdf) # Page 17: 6 of 6, 8 of 10, 4 of 8
|
61
|
+
make_page(pdf) # Page 18: 9 of 10, 5 of 8
|
62
|
+
pdf.stop_page_numbering(true, :next, se)
|
63
|
+
pdf.stop_page_numbering(false, :current, sf)
|
64
|
+
make_page(pdf) # Page 19: 10 of 10
|
65
|
+
make_page(pdf) # Page 20: blank
|
66
|
+
|
67
|
+
pdf.save_as("pagenumber.pdf")
|
data/demo/qr-language.rb
ADDED
@@ -0,0 +1,573 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# This Quick Reference card program is copyright 2003�2005 Ryan
|
7
|
+
# Davis and is licensed under the Creative Commons Attribution
|
8
|
+
# NonCommercial
|
9
|
+
# ShareAlike[http://creativecommons.org/licenses/by-nc-sa/2.0/] licence.
|
10
|
+
#
|
11
|
+
# See LICENCE in the main distribution for full licensing information.
|
12
|
+
#
|
13
|
+
# $Id: qr-language.rb,v 1.10 2005/06/02 21:20:35 austin Exp $
|
14
|
+
#++
|
15
|
+
load '../bin/loader'
|
16
|
+
ClassLoader.new 'pdf/writer'
|
17
|
+
|
18
|
+
require 'pdf/quickref'
|
19
|
+
|
20
|
+
if ARGV[0].nil?
|
21
|
+
paper = "LETTER"
|
22
|
+
else
|
23
|
+
if PDF::Writer::PAGE_SIZES.has_key?(ARGV[0])
|
24
|
+
paper = ARGV[0]
|
25
|
+
else
|
26
|
+
puts <<-EOS
|
27
|
+
usage: #{File.basename($0)} [paper-size]
|
28
|
+
|
29
|
+
paper-size must be one of the standard PDF::Writer page sizes.
|
30
|
+
Default paper-size is LETTER.
|
31
|
+
EOS
|
32
|
+
exit 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
PDF::QuickRef.make(paper, 3) do
|
37
|
+
pdf.info.author = "Ryan Davis"
|
38
|
+
pdf.info.title = "Ruby Language Quick Reference"
|
39
|
+
pdf.info.subject = "The Ruby Programming Language"
|
40
|
+
|
41
|
+
self.title_font_size = 13
|
42
|
+
self.h1_font_size = 10
|
43
|
+
self.h2_font_size = 8
|
44
|
+
self.h3_font_size = 7
|
45
|
+
self.h4_font_size = 6
|
46
|
+
self.body_font_size = 5
|
47
|
+
|
48
|
+
enc = {
|
49
|
+
:encoding => 'WinAnsiEncoding',
|
50
|
+
:differences => {
|
51
|
+
148 => "copyright",
|
52
|
+
}
|
53
|
+
}
|
54
|
+
self.title_font_encoding = enc
|
55
|
+
self.heading_font_encoding = enc
|
56
|
+
self.body_font_encoding = enc
|
57
|
+
self.code_font_encoding = enc
|
58
|
+
|
59
|
+
title "Ruby Language QuickRef"
|
60
|
+
h1 "General Syntax Rules"
|
61
|
+
lines <<-'EOS'
|
62
|
+
Comments start with a pound/sharp (#) character and go to EOL.
|
63
|
+
Lines between �=begin� and �=end� are skipped by the interpreter.
|
64
|
+
Ruby programs are sequence of expressions.
|
65
|
+
Each expression is delimited by semicolons (;) or newlines unless obviously incomplete (e.g. trailing �+�).
|
66
|
+
Backslashes at the end of line does not terminate expression.
|
67
|
+
EOS
|
68
|
+
|
69
|
+
h1 "Reserved Words"
|
70
|
+
codelines <<-'EOS'
|
71
|
+
alias and BEGIN begin break case
|
72
|
+
class def defined do else elsif
|
73
|
+
END end ensure false for if
|
74
|
+
in module next nil not or
|
75
|
+
redo rescue retry return self super
|
76
|
+
then true undef unless until when
|
77
|
+
while yield
|
78
|
+
EOS
|
79
|
+
|
80
|
+
h1 "Types"
|
81
|
+
body <<-'EOS'
|
82
|
+
Basic types are numbers, strings, ranges, regexen, symbols, arrays, and
|
83
|
+
hashes. Also included are files because they are used so often.
|
84
|
+
EOS
|
85
|
+
|
86
|
+
h2 "Numbers"
|
87
|
+
lines <<-'EOS'
|
88
|
+
123 1_234 123.45 1.2e-3
|
89
|
+
0xffff (hex) 0b01011 (binary) 0377 (octal)
|
90
|
+
?a ASCII character
|
91
|
+
?\C-a Control-a
|
92
|
+
?\M-a Meta-a
|
93
|
+
?\M-\C-a Meta-Control-a
|
94
|
+
EOS
|
95
|
+
|
96
|
+
h2 "Strings"
|
97
|
+
body <<-'EOS'
|
98
|
+
In all of the %() cases below, you may use any matching characters or any
|
99
|
+
single character for delimiters. %[], %!!, %@@, etc.
|
100
|
+
EOS
|
101
|
+
codelines <<-'EOS'
|
102
|
+
'no interpolation'
|
103
|
+
"#{interpolation} and backslashes\n"
|
104
|
+
%q(no interpolation)
|
105
|
+
%Q(interpolation and backslashes)
|
106
|
+
%(interpolation and backslashes)
|
107
|
+
`echo command interpretation with interpolation and backslashes`
|
108
|
+
%x(echo command interpretation with interpolation and backslashes)
|
109
|
+
EOS
|
110
|
+
|
111
|
+
h3 "Backslashes"
|
112
|
+
pre <<-'EOS'
|
113
|
+
\t (tab), \n (newline), \r (carriage return),
|
114
|
+
\f (form feed), \b (backspace), \a (bell),
|
115
|
+
\e (escape), \s (whitespace), \nnn (octal),
|
116
|
+
\xnn (hexadecimal), \cx (control x),
|
117
|
+
\C-x (control x), \M-x (meta x),
|
118
|
+
\M-\C-x (meta control x)
|
119
|
+
EOS
|
120
|
+
|
121
|
+
h3 "Here Docs"
|
122
|
+
pre <<-'EOS'
|
123
|
+
<<identifier # interpolation
|
124
|
+
<<"identifier" # interpolation
|
125
|
+
<<'identifier' # no interpolation
|
126
|
+
<<-identifier # interpolation, indented end
|
127
|
+
<<-"identifier" # interpolation, indented end
|
128
|
+
<<-'identifier' # no interpolation, indented end
|
129
|
+
EOS
|
130
|
+
|
131
|
+
h2 "Symbols"
|
132
|
+
body <<-'EOS'
|
133
|
+
A symbol (:symbol) is an immutable name used for identifiers,
|
134
|
+
variables, and operators.
|
135
|
+
EOS
|
136
|
+
|
137
|
+
h2 "Ranges"
|
138
|
+
pre <<-'EOS'
|
139
|
+
1..10
|
140
|
+
'a'..'z'
|
141
|
+
(1..10) === 5 -> true
|
142
|
+
(1..10) === 15 -> false
|
143
|
+
|
144
|
+
# prints lines starting at 'start' and
|
145
|
+
# ending at 'end'
|
146
|
+
while gets
|
147
|
+
print if /start/../end/
|
148
|
+
end
|
149
|
+
|
150
|
+
class RangeThingy
|
151
|
+
def <=>(rhs)
|
152
|
+
# ...
|
153
|
+
end
|
154
|
+
def succ
|
155
|
+
# ...
|
156
|
+
end
|
157
|
+
end
|
158
|
+
range = RangeThingy.new(lower_bound) .. RangeThingy.new(upper_bound)
|
159
|
+
EOS
|
160
|
+
|
161
|
+
h2 "Regexen"
|
162
|
+
pre <<-'EOS'
|
163
|
+
/normal regex/[xim]
|
164
|
+
%r|alternate form|[xim]
|
165
|
+
Regex.new(pattern, options)
|
166
|
+
EOS
|
167
|
+
pairs <<-'EOS'
|
168
|
+
. any character except newline
|
169
|
+
[set] any single character of set
|
170
|
+
[^set] any single character NOT of set
|
171
|
+
* 0 or more previous regular expression
|
172
|
+
*? 0 or more previous regular expression (non greedy)
|
173
|
+
+ 1 or more previous regular expression
|
174
|
+
+? 1 or more previous regular expression (non greedy)
|
175
|
+
? 0 or 1 previous regular expression
|
176
|
+
| alternation
|
177
|
+
( ) grouping regular expressions
|
178
|
+
^ beginning of a line or string
|
179
|
+
$ end of a line or string
|
180
|
+
#{m,n} at least m but most n previous regular expression
|
181
|
+
#{m,n}? at least m but most n previous regular expression (non greedy)
|
182
|
+
\A beginning of a string
|
183
|
+
\b backspace (0x08, inside [] only)
|
184
|
+
\B non-word boundary
|
185
|
+
\b word boundary (outside [] only)
|
186
|
+
\d digit, same as[0-9]
|
187
|
+
\D non-digit
|
188
|
+
\S non-whitespace character
|
189
|
+
\s whitespace character[ \t\n\r\f]
|
190
|
+
\W non-word character
|
191
|
+
\w word character[0-9A-Za-z_]
|
192
|
+
\z end of a string
|
193
|
+
\Z end of a string, or before newline at the end
|
194
|
+
(?# ) comment
|
195
|
+
(?: ) grouping without backreferences
|
196
|
+
(?= ) zero-width positive look-ahead assertion (?! ) zero-width negative look-ahead assertion
|
197
|
+
(?ix-ix) turns on/off i/x options, localized in group if any.
|
198
|
+
(?ix-ix: ) turns on/off i/x options, localized in non-capturing group.
|
199
|
+
EOS
|
200
|
+
|
201
|
+
h2 "Arrays"
|
202
|
+
pre <<-'EOS'
|
203
|
+
[1, 2, 3]
|
204
|
+
%w(foo bar baz) # no interpolation
|
205
|
+
%W(foo #{bar} baz) # interpolation
|
206
|
+
EOS
|
207
|
+
body <<-'EOS'
|
208
|
+
Indexes may be negative, and they index backwards (-1 is the last element).
|
209
|
+
EOS
|
210
|
+
|
211
|
+
h2 "Hashes"
|
212
|
+
pre <<-'EOS'
|
213
|
+
{ 1 => 2, 2 => 4, 3 => 6 }
|
214
|
+
{ expr => expr, ... }
|
215
|
+
EOS
|
216
|
+
|
217
|
+
h2 "Files"
|
218
|
+
body "Common methods include:"
|
219
|
+
lines <<-'EOS'
|
220
|
+
File.join(p1, p2, ... pN) => �p1/p2/.../pN� platform independent paths
|
221
|
+
File.new(path, mode_string="r") => file
|
222
|
+
File.new(path, mode_num [, perm_num]) => file
|
223
|
+
File.open(filename, mode_string="r") {|file| block} -> nil
|
224
|
+
File.open(filename [, mode_num [, perm_num ]]) {|file| block} -> nil
|
225
|
+
IO.foreach(path, sepstring=$/) {|line| block}
|
226
|
+
IO.readlines(path) => array
|
227
|
+
EOS
|
228
|
+
|
229
|
+
h3 "Mode Strings"
|
230
|
+
pairs <<-'EOS'
|
231
|
+
r Read-only, starts at beginning of file (default mode).
|
232
|
+
r+ Read-write, starts at beginning of file.
|
233
|
+
w Write-only, truncates existing file to zero length or creates a new file for writing.
|
234
|
+
w+ Read-write, truncates existing file to zero length or creates a new file for reading and writing.
|
235
|
+
a Write-only, starts at end of file if file exists, otherwise creates a new file for writing.
|
236
|
+
a+ Read-write, starts at end of file if file exists, otherwise creates a new file for reading and writing.
|
237
|
+
b Binary file mode (may appear with any of the key letters listed above). Only <b>necessary</b> for DOS/Windows.
|
238
|
+
EOS
|
239
|
+
|
240
|
+
h1 "Variables and Constants"
|
241
|
+
pre <<-'EOS'
|
242
|
+
$global_variable
|
243
|
+
@instance_variable
|
244
|
+
[OtherClass::]CONSTANT
|
245
|
+
local_variable
|
246
|
+
EOS
|
247
|
+
|
248
|
+
h1 "Pseudo-variables"
|
249
|
+
pairs <<-'EOS'
|
250
|
+
self the receiver of the current method
|
251
|
+
nil the sole instance of NilClass (represents false)
|
252
|
+
true the sole instance of TrueClass (typical true value)
|
253
|
+
false the sole instance of FalseClass (represents false)
|
254
|
+
__FILE__ the current source file name.
|
255
|
+
__LINE__ the current line number in the source file.
|
256
|
+
EOS
|
257
|
+
|
258
|
+
h1 "Pre-defined Variables"
|
259
|
+
pairs <<-'EOS'
|
260
|
+
$! The exception information message set by �raise�.
|
261
|
+
$@ Array of backtrace of the last exception thrown.
|
262
|
+
$& The string matched by the last successful pattern match in this scope.
|
263
|
+
$` The string to the left of the last successful match.
|
264
|
+
$' The string to the right of the last successful match.
|
265
|
+
$+ The last bracket matched by the last successful match.
|
266
|
+
$1 The Nth group of the last successful match. May be > 1.
|
267
|
+
$~ The information about the last match in the current scope.
|
268
|
+
$= The flag for case insensitive, nil by default.
|
269
|
+
$/ The input record separator, newline by default.
|
270
|
+
$\ The output record separator for the print and IO#write. Default is nil.
|
271
|
+
$, The output field separator for the print and Array#join.
|
272
|
+
$; The default separator for String#split.
|
273
|
+
$. The current input line number of the last file that was read.
|
274
|
+
$< The virtual concatenation file of the files given on command line.
|
275
|
+
$> The default output for print, printf. $stdout by default.
|
276
|
+
$_ The last input line of string by gets or readline.
|
277
|
+
$0 Contains the name of the script being executed. May be assignable.
|
278
|
+
$* Command line arguments given for the script sans args.
|
279
|
+
$$ The process number of the Ruby running this script.
|
280
|
+
$? The status of the last executed child process.
|
281
|
+
$: Load path for scripts and binary modules by load or require.
|
282
|
+
$" The array contains the module names loaded by require.
|
283
|
+
$DEBUG The status of the -d switch.
|
284
|
+
$FILENAME Current input file from $<. Same as $<.filename.
|
285
|
+
$LOAD_PATH The alias to the $:.
|
286
|
+
$stderr The current standard error output.
|
287
|
+
$stdin The current standard input.
|
288
|
+
$stdout The current standard output.
|
289
|
+
$VERBOSE The verbose flag, which is set by the -v switch.
|
290
|
+
$-0 The alias to $/.
|
291
|
+
$-a True if option -a is set. Read-only variable.
|
292
|
+
$-d The alias to $DEBUG.
|
293
|
+
$-F The alias to $;.
|
294
|
+
$-i In in-place-edit mode, this variable holds the extention, otherwise nil.
|
295
|
+
$-I The alias to $:.
|
296
|
+
$-l True if option -l is set. Read-only variable.
|
297
|
+
$-p True if option -p is set. Read-only variable.
|
298
|
+
$-v The alias to $VERBOSE.
|
299
|
+
EOS
|
300
|
+
|
301
|
+
h1 "Pre-defined Global Constants"
|
302
|
+
pairs <<-'EOS'
|
303
|
+
TRUE The typical true value.
|
304
|
+
FALSE The false itself.
|
305
|
+
NIL The nil itself.
|
306
|
+
STDIN The standard input. The default value for $stdin.
|
307
|
+
STDOUT The standard output. The default value for $stdout.
|
308
|
+
STDERR The standard error output. The default value for $stderr.
|
309
|
+
ENV The hash contains current environment variables.
|
310
|
+
ARGF The alias to the $<.
|
311
|
+
ARGV The alias to the $*.
|
312
|
+
DATA The file object of the script, pointing just after __END__.
|
313
|
+
RUBY_VERSION The ruby version string (VERSION was depricated).
|
314
|
+
RUBY_RELEASE_DATE The relase date string.
|
315
|
+
RUBY_PLATFORM The platform identifier.
|
316
|
+
EOS
|
317
|
+
|
318
|
+
h1 "Expressions"
|
319
|
+
h2 "Terms"
|
320
|
+
body <<-'EOS'
|
321
|
+
Terms are expressions that may be a basic type (listed above), a shell
|
322
|
+
command, variable reference, constant reference, or method invocation.
|
323
|
+
EOS
|
324
|
+
|
325
|
+
h2 "Operators and Precedence"
|
326
|
+
codelines <<-'EOS'
|
327
|
+
::
|
328
|
+
[]
|
329
|
+
**
|
330
|
+
- (unary) + (unary) ! ~
|
331
|
+
* / %
|
332
|
+
+ -
|
333
|
+
<< >>
|
334
|
+
&
|
335
|
+
| ^
|
336
|
+
> >= < <=
|
337
|
+
<=> == === != =~ !~
|
338
|
+
&&
|
339
|
+
||
|
340
|
+
.. ...
|
341
|
+
= (+=, -=, ...)
|
342
|
+
not
|
343
|
+
and or
|
344
|
+
EOS
|
345
|
+
|
346
|
+
h2 "Control Expressions"
|
347
|
+
pre <<-'EOS'
|
348
|
+
if bool-expr [then]
|
349
|
+
body
|
350
|
+
elsif bool-expr [then]
|
351
|
+
body
|
352
|
+
else
|
353
|
+
body
|
354
|
+
end
|
355
|
+
|
356
|
+
unless bool-expr [then]
|
357
|
+
body
|
358
|
+
else
|
359
|
+
body
|
360
|
+
end
|
361
|
+
|
362
|
+
expr if bool-expr
|
363
|
+
expr unless bool-expr
|
364
|
+
|
365
|
+
case target-expr
|
366
|
+
# (comparisons may be regexen)
|
367
|
+
when comparison [, comparison]... [then]
|
368
|
+
body
|
369
|
+
when comparison [, comparison]... [then]
|
370
|
+
body
|
371
|
+
...
|
372
|
+
[else
|
373
|
+
body]
|
374
|
+
end
|
375
|
+
|
376
|
+
while bool-expr [do]
|
377
|
+
body
|
378
|
+
end
|
379
|
+
|
380
|
+
until bool-expr [do]
|
381
|
+
body
|
382
|
+
end
|
383
|
+
|
384
|
+
begin
|
385
|
+
body
|
386
|
+
end while bool-expr
|
387
|
+
|
388
|
+
begin
|
389
|
+
body
|
390
|
+
end until bool-expr
|
391
|
+
|
392
|
+
for name[, name]... in expr [do]
|
393
|
+
body
|
394
|
+
end
|
395
|
+
|
396
|
+
expr.each do | name[, name]... |
|
397
|
+
body
|
398
|
+
end
|
399
|
+
|
400
|
+
expr while bool-expr
|
401
|
+
expr until bool-expr
|
402
|
+
EOS
|
403
|
+
pairs <<-'EOS'
|
404
|
+
break terminates loop immediately.
|
405
|
+
redo immediately repeats w/o rerunning the condition.
|
406
|
+
next starts the next iteration through the loop.
|
407
|
+
retry restarts the loop, rerunning the condition.
|
408
|
+
EOS
|
409
|
+
|
410
|
+
h1 "Invoking a Method"
|
411
|
+
body <<-'EOS'
|
412
|
+
Nearly everything available in a method invocation is optional, consequently
|
413
|
+
the syntax is very difficult to follow. Here are some examples:
|
414
|
+
EOS
|
415
|
+
lines <<-'EOS'
|
416
|
+
method
|
417
|
+
obj.method
|
418
|
+
Class::method
|
419
|
+
method(arg1, arg2)
|
420
|
+
method(arg1, key1 => val1, key2 => val2, aval1, aval2) { block }
|
421
|
+
method(arg1, *[arg2, arg3]) becomes: method(arg1, arg2, arg3)
|
422
|
+
EOS
|
423
|
+
pre <<-'EOS'
|
424
|
+
call := [receiver ('::' | '.')] name [params] [block]
|
425
|
+
params := ( [param]* [, hash] [*arr] [&proc] )
|
426
|
+
block := { body } | do body end
|
427
|
+
EOS
|
428
|
+
|
429
|
+
h1 "Defining a Class"
|
430
|
+
body "Class names begin with capital characters."
|
431
|
+
pre <<-'EOS'
|
432
|
+
class Identifier [ < Superclass ]; ... ; end
|
433
|
+
|
434
|
+
# Singleton classes, or idioclasses;
|
435
|
+
# add methods to a single instance
|
436
|
+
# obj can be self
|
437
|
+
class << obj; ...; end
|
438
|
+
EOS
|
439
|
+
|
440
|
+
h1 "Defining a Module"
|
441
|
+
body "Module names begin with capital characters."
|
442
|
+
pre "module Identifier; ...; end"
|
443
|
+
|
444
|
+
h1 "Defining a Method"
|
445
|
+
pre <<-'EOS'
|
446
|
+
def method_name(arg_list); ...; end
|
447
|
+
def expr.method_name(arg_list); ...; end
|
448
|
+
EOS
|
449
|
+
lines <<-'EOS'
|
450
|
+
arg_list := ['('] [varname*] ['*' listname] ['&' blockname] [')']
|
451
|
+
Arguments may have default values (varname = expr).
|
452
|
+
Method definitions may not be nested.
|
453
|
+
method_name may be an operator: <=>, ==, ===, =~, <, <=, > >=, +, -, *, /, %, **, <<, >>, ~, +@, -@, [], []= (the last takes two arguments)
|
454
|
+
EOS
|
455
|
+
|
456
|
+
h2 "Access Restriction"
|
457
|
+
pairs <<-'EOS'
|
458
|
+
public totally accessable.
|
459
|
+
protected accessable only by instances of class and direct descendants. Even through hasA relationships. (see below)
|
460
|
+
private accessable only by instances of class.
|
461
|
+
EOS
|
462
|
+
body <<-'EOS'
|
463
|
+
Restriction used without arguments set the default access control. Used with
|
464
|
+
arguments, sets the access of the named methods and constants.
|
465
|
+
EOS
|
466
|
+
pre <<-'EOS'
|
467
|
+
class A
|
468
|
+
protected
|
469
|
+
def protected_method; ...; end
|
470
|
+
end
|
471
|
+
class B < A
|
472
|
+
public
|
473
|
+
def test_protected
|
474
|
+
myA = A.new
|
475
|
+
myA.protected_method
|
476
|
+
end
|
477
|
+
end
|
478
|
+
b = B.new.test_protected
|
479
|
+
EOS
|
480
|
+
|
481
|
+
h3 "Accessors"
|
482
|
+
body "Module provides the following utility methods:"
|
483
|
+
pairs <<-'EOS'
|
484
|
+
attr_reader <attribute>[, <attribute>]... Creates a read-only accessor for each <attribute>.
|
485
|
+
attr_writer <attribute>[, <attribute>]... Creates a write-only accessor for each <attribute>.
|
486
|
+
attr <attribute> [, <writable>] Equivalent to "attr_reader <attribute>; attr_writer <attribute> if <writable>"
|
487
|
+
attr_accessor <attribute>[, <attribute>]... Equivalent to "attr <attribute>, true" for each argument.
|
488
|
+
EOS
|
489
|
+
|
490
|
+
h2 "Aliasing"
|
491
|
+
pre "alias <old> <new>"
|
492
|
+
body <<-'EOS'
|
493
|
+
Creates a new reference to whatever old referred to. old can be any existing
|
494
|
+
method, operator, global. It may not be a local, instance, constant, or
|
495
|
+
class variable.
|
496
|
+
EOS
|
497
|
+
|
498
|
+
h1 "Blocks, Closures, and Procs"
|
499
|
+
h2 "Blocks/Closures"
|
500
|
+
body "Blocks must follow a method invocation:"
|
501
|
+
pre <<-'EOS'
|
502
|
+
invocation do ... end
|
503
|
+
invocation do || ... end
|
504
|
+
invocation do |arg_list| ... end
|
505
|
+
invocation { ... }
|
506
|
+
invocation { || ... }
|
507
|
+
invocation { |arg_list| ... }
|
508
|
+
EOS
|
509
|
+
lines <<-'EOS'
|
510
|
+
Blocks are full closures, remembering their variable context.
|
511
|
+
Blocks are invoked via yield and may be passed arguments.
|
512
|
+
Block arguments may not have default parameters.
|
513
|
+
Brace form ({/}) has higher precedence and will bind to the last parameter if the invocation is made without parentheses.
|
514
|
+
do/end form has lower precedence and will bind to the invocation even without parentheses.
|
515
|
+
EOS
|
516
|
+
|
517
|
+
h2 "Proc Objects"
|
518
|
+
body "See class Proc for more information. Created via:"
|
519
|
+
pre <<-'EOS'
|
520
|
+
Kernel#proc (or Kernel#lambda)
|
521
|
+
Proc#new
|
522
|
+
&block argument on a method
|
523
|
+
EOS
|
524
|
+
|
525
|
+
h2 "Exceptions"
|
526
|
+
pre <<-'EOS'
|
527
|
+
begin
|
528
|
+
expr
|
529
|
+
[ rescue [ exception_class [ => var ], ... ]
|
530
|
+
expr ]
|
531
|
+
[ else
|
532
|
+
expr ]
|
533
|
+
[ ensure
|
534
|
+
expr ]
|
535
|
+
end
|
536
|
+
|
537
|
+
raise [ exception_class, ] [ message ]
|
538
|
+
EOS
|
539
|
+
body <<-'EOS'
|
540
|
+
The default exception_class for rescue is StandardError, not Exception.
|
541
|
+
Raise without an exception_class raises a RuntimeError. All exception
|
542
|
+
classes must inherit from Exception or one of its children (listed below).
|
543
|
+
EOS
|
544
|
+
pairs <<-'EOS'
|
545
|
+
StandardError LocalJumpError, SystemStackError, ZeroDivisionError, RangeError (FloatDomainError), SecurityError, ThreadError, IOError (EOFError), ArgumentError, IndexError, RuntimeError, TypeError, SystemCallError (Errno::*), RegexpError
|
546
|
+
SignalException
|
547
|
+
Interrupt
|
548
|
+
NoMemoryError
|
549
|
+
ScriptError LoadError, NameError, SyntaxError, NotImplementedError
|
550
|
+
SystemExit
|
551
|
+
EOS
|
552
|
+
|
553
|
+
h2 "Catch and Throw"
|
554
|
+
pre <<-'EOS'
|
555
|
+
catch :label do
|
556
|
+
expr
|
557
|
+
throw :label
|
558
|
+
end
|
559
|
+
EOS
|
560
|
+
|
561
|
+
hline
|
562
|
+
|
563
|
+
x = pdf.absolute_right_margin + pdf.font_height(5)
|
564
|
+
y = pdf.absolute_bottom_margin
|
565
|
+
memo = %Q(Copyright � 2005 Ryan Davis with Austin Ziegler. PDF version by Austin Ziegler. Licensed under the <c:alink uri="http://creativecommons.org/licenses/by-nc-sa/2.0/">Creative Commons Attribution-NonCommercial-ShareAlike</c:alink> Licence. The original HTML version is at <c:alink uri="http://www.zenspider.com/Languages/Ruby/QuickRef.html">Zen Spider</c:alink>. Generated by <c:alink uri="http://rubyforge.org/projects/ruby-pdf/">PDF::Writer</c:alink> #{PDF::Writer::VERSION} and PDF::QuickRef #{PDF::QuickRef::VERSION}.)
|
566
|
+
pdf.add_text(x, y, 5, memo, -90)
|
567
|
+
x = pdf.absolute_right_margin - 32
|
568
|
+
y = pdf.absolute_bottom_margin + 24
|
569
|
+
|
570
|
+
pdf.add_image_from_file("../images/pdfwriter-icon.jpg", x, y)
|
571
|
+
|
572
|
+
save_as "Ruby-Language-QuickRef.pdf"
|
573
|
+
end
|