hpdf 2.0.8-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/History +57 -0
- data/License +25 -0
- data/README +136 -0
- data/docs/annotation_handling.html +503 -0
- data/docs/api.css +115 -0
- data/docs/api_reference.html +112 -0
- data/docs/bindings.html +242 -0
- data/docs/compile_your_program.html +365 -0
- data/docs/default.css +115 -0
- data/docs/destination_handling.html +620 -0
- data/docs/document_handling.html +4751 -0
- data/docs/documentation.html +110 -0
- data/docs/encoder_handling.html +428 -0
- data/docs/error_handling.html +1609 -0
- data/docs/examples.html +702 -0
- data/docs/ext_gstate.html +407 -0
- data/docs/font_handling.html +669 -0
- data/docs/fonts.html +978 -0
- data/docs/graphics.html +1210 -0
- data/docs/handles.html +204 -0
- data/docs/how_to_use.html +371 -0
- data/docs/image/Thumbs.db +0 -0
- data/docs/image/character_map.png +0 -0
- data/docs/image/encoding_list.png +0 -0
- data/docs/image/extgtate.png +0 -0
- data/docs/image/figure1.png +0 -0
- data/docs/image/figure10.png +0 -0
- data/docs/image/figure11.png +0 -0
- data/docs/image/figure12.png +0 -0
- data/docs/image/figure13.png +0 -0
- data/docs/image/figure14.png +0 -0
- data/docs/image/figure15.png +0 -0
- data/docs/image/figure16.png +0 -0
- data/docs/image/figure17.png +0 -0
- data/docs/image/figure18.png +0 -0
- data/docs/image/figure19.png +0 -0
- data/docs/image/figure2.png +0 -0
- data/docs/image/figure20.png +0 -0
- data/docs/image/figure21.png +0 -0
- data/docs/image/figure22.png +0 -0
- data/docs/image/figure23.png +0 -0
- data/docs/image/figure24.png +0 -0
- data/docs/image/figure25.png +0 -0
- data/docs/image/figure26.png +0 -0
- data/docs/image/figure27.png +0 -0
- data/docs/image/figure28.png +0 -0
- data/docs/image/figure3.png +0 -0
- data/docs/image/figure4.png +0 -0
- data/docs/image/figure5.png +0 -0
- data/docs/image/figure6.png +0 -0
- data/docs/image/figure7.png +0 -0
- data/docs/image/figure8.png +0 -0
- data/docs/image/figure9.png +0 -0
- data/docs/image/font_demo.png +0 -0
- data/docs/image/harulogo.png +0 -0
- data/docs/image/image_demo.png +0 -0
- data/docs/image/jpfont_demo.png +0 -0
- data/docs/image/line_demo.png +0 -0
- data/docs/image/png_demo.png +0 -0
- data/docs/image/text_annot.png +0 -0
- data/docs/image/text_demo.png +0 -0
- data/docs/image/text_demo2.png +0 -0
- data/docs/image/tt_font.png +0 -0
- data/docs/image_handling.html +505 -0
- data/docs/index.html +305 -0
- data/docs/install.html +243 -0
- data/docs/outline_handling.html +229 -0
- data/docs/page_handling.html +2647 -0
- data/docs/page_operator.html +2640 -0
- data/docs/useful_links.html +203 -0
- data/examples/arc_demo.rb +82 -0
- data/examples/demo.rb +91 -0
- data/examples/encryption.rb +41 -0
- data/examples/ext_gstater_demo.rb +171 -0
- data/examples/font_demo.rb +67 -0
- data/examples/jpfont_demo.rb +122 -0
- data/examples/line_demo.rb +301 -0
- data/examples/slide_show_demo.rb +139 -0
- data/examples/text_demo2.rb +189 -0
- data/examples/ttfont_demo.rb +106 -0
- data/lib/hpdf.so +0 -0
- data/tests/arc_demo.rb +82 -0
- data/tests/demo.rb +91 -0
- data/tests/encryption.rb +41 -0
- data/tests/ext_gstater_demo.rb +171 -0
- data/tests/font_demo.rb +67 -0
- data/tests/line_demo.rb +301 -0
- data/tests/slide_show_demo.rb +139 -0
- data/tests/test_all_examples.rb +31 -0
- data/tests/text_demo2.rb +189 -0
- metadata +137 -0
data/tests/demo.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
#
|
2
|
+
# << Haru Free PDF Library 2.0.0 >> -- demo.rb
|
3
|
+
#
|
4
|
+
# Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
|
5
|
+
#
|
6
|
+
# Permission to use, copy, modify, distribute and sell this software
|
7
|
+
# and its documentation for any purpose is hereby granted without fee,
|
8
|
+
# provided that the above copyright notice appear in all copies and
|
9
|
+
# that both that copyright notice and this permission notice appear
|
10
|
+
# in supporting documentation.
|
11
|
+
# It is provided "as is" without express or implied warranty.
|
12
|
+
#
|
13
|
+
|
14
|
+
require "hpdf"
|
15
|
+
|
16
|
+
if ARGV.empty?
|
17
|
+
line = 'Ruby Rocks'
|
18
|
+
else
|
19
|
+
line = ARGV.join(" ")
|
20
|
+
end
|
21
|
+
|
22
|
+
pdf = HPDFDoc.new
|
23
|
+
|
24
|
+
page = pdf.add_page
|
25
|
+
|
26
|
+
x = 578
|
27
|
+
r1 = 25
|
28
|
+
|
29
|
+
40.step(1, -3) do |xw|
|
30
|
+
tone = 1.0 - (xw / 40.0) * 0.2
|
31
|
+
|
32
|
+
page.set_line_width(xw.to_f)
|
33
|
+
page.set_rgb_stroke(tone, 1.0, tone)
|
34
|
+
page.circle(50.0, 750.0, r1.to_f)
|
35
|
+
page.stroke
|
36
|
+
r1 += xw
|
37
|
+
end
|
38
|
+
|
39
|
+
40.step(1, -3) do |xw|
|
40
|
+
tone = 1.0 - (xw / 40.0) * 0.2
|
41
|
+
|
42
|
+
page.set_line_width(xw.to_f)
|
43
|
+
page.set_rgb_stroke(tone, tone, 1.0)
|
44
|
+
page.move_to(x.to_f, 0.0)
|
45
|
+
page.line_to(x.to_f, 842.0)
|
46
|
+
page.stroke
|
47
|
+
x = (x - xw - 2)
|
48
|
+
end
|
49
|
+
|
50
|
+
page.set_rgb_stroke(0.0, 0.0, 0.0)
|
51
|
+
page.set_line_width(1.0)
|
52
|
+
page.rectangle(20.0, 20.0, 558.0, 802.0)
|
53
|
+
page.stroke
|
54
|
+
|
55
|
+
font = pdf.get_font("Helvetica", nil)
|
56
|
+
bbox = font.get_bbox
|
57
|
+
|
58
|
+
y = 800
|
59
|
+
50.step(5, -5) do |size|
|
60
|
+
height = (bbox[3] - bbox[1]) / 1000 * size
|
61
|
+
y = y - height
|
62
|
+
|
63
|
+
page.begin_text
|
64
|
+
page.set_font_and_size(font, size.to_f)
|
65
|
+
page.text_out(30.0, y.to_f, line)
|
66
|
+
page.end_text
|
67
|
+
end
|
68
|
+
|
69
|
+
(0...360).step(20) do |angle|
|
70
|
+
page.set_rgb_fill(rand, rand, rand)
|
71
|
+
|
72
|
+
page.begin_text
|
73
|
+
rad = angle / 180.0 * 3.141592
|
74
|
+
page.set_font_and_size(font, 20.0)
|
75
|
+
page.set_text_matrix(Math.cos(rad),
|
76
|
+
Math.sin(rad),
|
77
|
+
-Math.sin(rad),
|
78
|
+
Math.cos(rad),
|
79
|
+
300 + Math.cos(rad) * 40,
|
80
|
+
300 + Math.sin(rad) * 40)
|
81
|
+
page.show_text(line)
|
82
|
+
page.end_text
|
83
|
+
end
|
84
|
+
|
85
|
+
if $demo_output_filename
|
86
|
+
file_name= $demo_output_filename
|
87
|
+
else
|
88
|
+
file_name= $0 + ".pdf"
|
89
|
+
end
|
90
|
+
|
91
|
+
pdf.save_to_file(file_name)
|
data/tests/encryption.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#
|
2
|
+
# << Haru Free PDF Library 2.0.0 >> -- encryption.rb
|
3
|
+
#
|
4
|
+
# Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
|
5
|
+
#
|
6
|
+
# Permission to use, copy, modify, distribute and sell this software
|
7
|
+
# and its documentation for any purpose is hereby granted without fee,
|
8
|
+
# provided that the above copyright notice appear in all copies and
|
9
|
+
# that both that copyright notice and this permission notice appear
|
10
|
+
# in supporting documentation.
|
11
|
+
# It is provided "as is" without express or implied warranty.
|
12
|
+
#
|
13
|
+
|
14
|
+
require "hpdf"
|
15
|
+
|
16
|
+
pdf = HPDFDoc.new
|
17
|
+
|
18
|
+
text = "This is an encrypt document example."
|
19
|
+
owner_passwd = "owner"
|
20
|
+
user_passwd = "user"
|
21
|
+
|
22
|
+
font1 = pdf.get_font("Helvetica", nil)
|
23
|
+
|
24
|
+
page = pdf.add_page
|
25
|
+
|
26
|
+
page.set_size(HPDFDoc::HPDF_PAGE_SIZE_B5, HPDFDoc::HPDF_PAGE_LANDSCAPE)
|
27
|
+
|
28
|
+
page.begin_text
|
29
|
+
page.set_font_and_size(font1, 20)
|
30
|
+
page.text_rect(0, page.get_height / 2 + 20, page.get_width, page.get_height / 2 -10, text, HPDFDoc::HPDF_TALIGN_CENTER)
|
31
|
+
page.end_text
|
32
|
+
|
33
|
+
pdf.set_password(owner_passwd, user_passwd)
|
34
|
+
|
35
|
+
if $demo_output_filename
|
36
|
+
file_name= $demo_output_filename
|
37
|
+
else
|
38
|
+
file_name= $0 + ".pdf"
|
39
|
+
end
|
40
|
+
|
41
|
+
pdf.save_to_file(file_name)
|
@@ -0,0 +1,171 @@
|
|
1
|
+
#
|
2
|
+
# << Haru Free PDF Library 2.0.6 >> -- ext_gstate_demo.rb
|
3
|
+
#
|
4
|
+
# http://libharu.sourceforge.net/
|
5
|
+
#
|
6
|
+
# Copyright (c) 1999-2006 Takeshi Kanno
|
7
|
+
#
|
8
|
+
# Permission to use, copy, modify, distribute and sell this software
|
9
|
+
# and its documentation for any purpose is hereby granted without fee,
|
10
|
+
# provided that the above copyright notice appear in all copies and
|
11
|
+
# that both that copyright notice and this permission notice appear
|
12
|
+
# in supporting documentation.
|
13
|
+
# It is provided "as is" without express or implied warranty.
|
14
|
+
#
|
15
|
+
|
16
|
+
require "hpdf"
|
17
|
+
|
18
|
+
def draw_circles(page, description, x, y)
|
19
|
+
page.set_line_width(1)
|
20
|
+
page.set_rgb_stroke(0, 0, 0)
|
21
|
+
|
22
|
+
page.set_rgb_fill(1, 0, 0)
|
23
|
+
page.circle(x + 40, y + 40, 40)
|
24
|
+
page.close_path_fill_stroke()
|
25
|
+
|
26
|
+
page.set_rgb_fill(0, 1, 0)
|
27
|
+
page.circle(x + 100, y + 40, 40)
|
28
|
+
page.close_path_fill_stroke()
|
29
|
+
|
30
|
+
page.set_rgb_fill(0, 0, 1)
|
31
|
+
page.circle(x + 70, y + 74.64, 40)
|
32
|
+
page.close_path_fill_stroke()
|
33
|
+
|
34
|
+
page.set_rgb_fill(0, 0, 0)
|
35
|
+
page.begin_text()
|
36
|
+
page.text_out(x + 0.0, y + 130.0, description)
|
37
|
+
page.end_text()
|
38
|
+
end
|
39
|
+
|
40
|
+
pdf = HPDFDoc.new
|
41
|
+
|
42
|
+
PAGE_WIDTH = 600
|
43
|
+
PAGE_HEIGHT = 900
|
44
|
+
|
45
|
+
# add a new page object. #
|
46
|
+
page = pdf.add_page
|
47
|
+
page.set_height(PAGE_HEIGHT)
|
48
|
+
page.set_width(PAGE_WIDTH)
|
49
|
+
|
50
|
+
font = pdf.get_font("Helvetica-Bold", nil)
|
51
|
+
|
52
|
+
page.set_font_and_size(font, 10)
|
53
|
+
|
54
|
+
# normal
|
55
|
+
page.gsave()
|
56
|
+
draw_circles(page, "normal", 40, PAGE_HEIGHT - 170)
|
57
|
+
page.grestore()
|
58
|
+
|
59
|
+
# transparency (0.8)
|
60
|
+
page.gsave()
|
61
|
+
gstate = pdf.create_ext_gstate()
|
62
|
+
gstate.set_alpha_fill(0.8)
|
63
|
+
gstate.set_alpha_stroke(0.8)
|
64
|
+
page.set_ext_gstate(gstate)
|
65
|
+
draw_circles(page, "alpha fill = 0.8", 230, PAGE_HEIGHT - 170)
|
66
|
+
page.grestore()
|
67
|
+
|
68
|
+
# transparency (0.4)
|
69
|
+
page.gsave()
|
70
|
+
gstate = pdf.create_ext_gstate()
|
71
|
+
gstate.set_alpha_fill(0.4)
|
72
|
+
gstate.set_alpha_stroke(0.4)
|
73
|
+
page.set_ext_gstate(gstate)
|
74
|
+
draw_circles(page, "alpha fill = 0.4", 420, PAGE_HEIGHT - 170)
|
75
|
+
page.grestore()
|
76
|
+
|
77
|
+
# blend-mode=HPDF_BM_MULTIPLY
|
78
|
+
page.gsave()
|
79
|
+
gstate = pdf.create_ext_gstate()
|
80
|
+
gstate.set_blend_mode(HPDFDoc::HPDF_BM_MULTIPLY)
|
81
|
+
page.set_ext_gstate(gstate)
|
82
|
+
draw_circles(page, "HPDF_BM_MULTIPLY", 40, PAGE_HEIGHT - 340)
|
83
|
+
page.grestore()
|
84
|
+
|
85
|
+
# blend-mode=HPDF_BM_SCREEN
|
86
|
+
page.gsave()
|
87
|
+
gstate = pdf.create_ext_gstate()
|
88
|
+
gstate.set_blend_mode(HPDFDoc::HPDF_BM_SCREEN)
|
89
|
+
page.set_ext_gstate(gstate)
|
90
|
+
draw_circles(page, "HPDF_BM_SCREEN", 230, PAGE_HEIGHT - 340)
|
91
|
+
page.grestore()
|
92
|
+
|
93
|
+
# blend-mode=HPDF_BM_OVERLAY
|
94
|
+
page.gsave()
|
95
|
+
gstate = pdf.create_ext_gstate()
|
96
|
+
gstate.set_blend_mode(HPDFDoc::HPDF_BM_OVERLAY)
|
97
|
+
page.set_ext_gstate(gstate)
|
98
|
+
draw_circles(page, "HPDF_BM_OVERLAY", 420, PAGE_HEIGHT - 340)
|
99
|
+
page.grestore()
|
100
|
+
|
101
|
+
# blend-mode=HPDF_BM_DARKEN
|
102
|
+
page.gsave()
|
103
|
+
gstate = pdf.create_ext_gstate()
|
104
|
+
gstate.set_blend_mode(HPDFDoc::HPDF_BM_DARKEN)
|
105
|
+
page.set_ext_gstate(gstate)
|
106
|
+
draw_circles(page, "HPDF_BM_DARKEN", 40, PAGE_HEIGHT - 510)
|
107
|
+
page.grestore()
|
108
|
+
|
109
|
+
# blend-mode=HPDF_BM_LIGHTEN
|
110
|
+
page.gsave()
|
111
|
+
gstate = pdf.create_ext_gstate()
|
112
|
+
gstate.set_blend_mode(HPDFDoc::HPDF_BM_LIGHTEN)
|
113
|
+
page.set_ext_gstate(gstate)
|
114
|
+
draw_circles(page, "HPDF_BM_LIGHTEN", 230, PAGE_HEIGHT - 510)
|
115
|
+
page.grestore()
|
116
|
+
|
117
|
+
# blend-mode=HPDF_BM_COLOR_DODGE
|
118
|
+
page.gsave()
|
119
|
+
gstate = pdf.create_ext_gstate()
|
120
|
+
gstate.set_blend_mode(HPDFDoc::HPDF_BM_COLOR_DODGE)
|
121
|
+
page.set_ext_gstate(gstate)
|
122
|
+
draw_circles(page, "HPDF_BM_COLOR_DODGE", 420, PAGE_HEIGHT - 510)
|
123
|
+
page.grestore()
|
124
|
+
|
125
|
+
# blend-mode=HPDF_BM_COLOR_BUM
|
126
|
+
page.gsave()
|
127
|
+
gstate = pdf.create_ext_gstate()
|
128
|
+
gstate.set_blend_mode(HPDFDoc::HPDF_BM_COLOR_BUM)
|
129
|
+
page.set_ext_gstate(gstate)
|
130
|
+
draw_circles(page, "HPDF_BM_COLOR_BUM", 40, PAGE_HEIGHT - 680)
|
131
|
+
page.grestore()
|
132
|
+
|
133
|
+
# blend-mode=HPDF_BM_HARD_LIGHT
|
134
|
+
page.gsave()
|
135
|
+
gstate = pdf.create_ext_gstate()
|
136
|
+
gstate.set_blend_mode(HPDFDoc::HPDF_BM_HARD_LIGHT)
|
137
|
+
page.set_ext_gstate(gstate)
|
138
|
+
draw_circles(page, "HPDF_BM_HARD_LIGHT", 230, PAGE_HEIGHT - 680)
|
139
|
+
page.grestore()
|
140
|
+
|
141
|
+
# blend-mode=HPDF_BM_SOFT_LIGHT
|
142
|
+
page.gsave()
|
143
|
+
gstate = pdf.create_ext_gstate()
|
144
|
+
gstate.set_blend_mode(HPDFDoc::HPDF_BM_SOFT_LIGHT)
|
145
|
+
page.set_ext_gstate(gstate)
|
146
|
+
draw_circles(page, "HPDF_BM_SOFT_LIGHT", 420, PAGE_HEIGHT - 680)
|
147
|
+
page.grestore()
|
148
|
+
|
149
|
+
# blend-mode=HPDF_BM_DIFFERENCE
|
150
|
+
page.gsave()
|
151
|
+
gstate = pdf.create_ext_gstate()
|
152
|
+
gstate.set_blend_mode(HPDFDoc::HPDF_BM_DIFFERENCE)
|
153
|
+
page.set_ext_gstate(gstate)
|
154
|
+
draw_circles(page, "HPDF_BM_DIFFERENCE", 40, PAGE_HEIGHT - 850)
|
155
|
+
page.grestore()
|
156
|
+
|
157
|
+
# blend-mode=HPDF_BM_EXCLUSHON
|
158
|
+
page.gsave()
|
159
|
+
gstate = pdf.create_ext_gstate()
|
160
|
+
gstate.set_blend_mode(HPDFDoc::HPDF_BM_EXCLUSHON)
|
161
|
+
page.set_ext_gstate(gstate)
|
162
|
+
draw_circles(page, "HPDF_BM_EXCLUSHON", 230, PAGE_HEIGHT - 850)
|
163
|
+
page.grestore()
|
164
|
+
|
165
|
+
if $demo_output_filename
|
166
|
+
file_name= $demo_output_filename
|
167
|
+
else
|
168
|
+
file_name= $0 + ".pdf"
|
169
|
+
end
|
170
|
+
|
171
|
+
pdf.save_to_file(file_name)
|
data/tests/font_demo.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
#
|
2
|
+
# << Haru Free PDF Library 2.0.0 >> -- font_example.rb
|
3
|
+
#
|
4
|
+
# Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
|
5
|
+
#
|
6
|
+
# Permission to use, copy, modify, distribute and sell this software
|
7
|
+
# and its documentation for any purpose is hereby granted without fee,
|
8
|
+
# provided that the above copyright notice appear in all copies and
|
9
|
+
# that both that copyright notice and this permission notice appear
|
10
|
+
# in supporting documentation.
|
11
|
+
# It is provided "as is" without express or implied warranty.
|
12
|
+
#
|
13
|
+
|
14
|
+
require "hpdf"
|
15
|
+
|
16
|
+
font_list = ["Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique", "Helvetica", "Helvetica-Bold", "Helvetica-Oblique", "Helvetica-BoldOblique", "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic", "Symbol", "ZapfDingbats", nil]
|
17
|
+
|
18
|
+
pdf = HPDFDoc.new
|
19
|
+
|
20
|
+
page = pdf.add_page
|
21
|
+
height = page.get_height
|
22
|
+
width = page.get_width
|
23
|
+
|
24
|
+
page.set_line_width(1.0)
|
25
|
+
page.rectangle(50.0, 50.0, width - 100.0, height - 110.0)
|
26
|
+
page.stroke
|
27
|
+
|
28
|
+
font1 = pdf.get_font("Helvetica", nil)
|
29
|
+
|
30
|
+
title = "Font Example"
|
31
|
+
page.set_font_and_size(font1, 24.0)
|
32
|
+
tw = page.text_width(title)
|
33
|
+
page.begin_text
|
34
|
+
page.text_out((width - tw) / 2, height - 50.0, title)
|
35
|
+
page.set_font_and_size(font1, 16.0)
|
36
|
+
page.text_out(60.0, height - 80.0, "<Standerd Type1 fonts samples>")
|
37
|
+
page.end_text
|
38
|
+
|
39
|
+
samp_text = "abcdefgABCDEFG12345!#$\%&+-@?"
|
40
|
+
|
41
|
+
page.begin_text
|
42
|
+
page.move_text_pos(60.0, height - 105.0)
|
43
|
+
|
44
|
+
i = 0
|
45
|
+
while font_list[i]
|
46
|
+
font2 = pdf.get_font(font_list[i], nil)
|
47
|
+
|
48
|
+
page.set_font_and_size(font1, 9.0)
|
49
|
+
page.show_text(font_list[i])
|
50
|
+
page.move_text_pos(0.0, -18.0)
|
51
|
+
|
52
|
+
page.set_font_and_size(font2, 20.0)
|
53
|
+
page.show_text(samp_text)
|
54
|
+
page.move_text_pos(0.0, -20.0)
|
55
|
+
|
56
|
+
i = i + 1
|
57
|
+
end
|
58
|
+
|
59
|
+
page.end_text
|
60
|
+
|
61
|
+
if $demo_output_filename
|
62
|
+
file_name= $demo_output_filename
|
63
|
+
else
|
64
|
+
file_name= $0 + ".pdf"
|
65
|
+
end
|
66
|
+
|
67
|
+
pdf.save_to_file(file_name)
|
data/tests/line_demo.rb
ADDED
@@ -0,0 +1,301 @@
|
|
1
|
+
#
|
2
|
+
# << Haru Free PDF Library 2.0.2 >> -- line_demo.rb
|
3
|
+
#
|
4
|
+
# http://libharu.sourceforge.net/
|
5
|
+
#
|
6
|
+
# Copyright (c) 1999-2006 Takeshi Kanno
|
7
|
+
#
|
8
|
+
# Permission to use, copy, modify, distribute and sell this software
|
9
|
+
# and its documentation for any purpose is hereby granted without fee,
|
10
|
+
# provided that the above copyright notice appear in all copies and
|
11
|
+
# that both that copyright notice and this permission notice appear
|
12
|
+
# in supporting documentation.
|
13
|
+
# It is provided "as is" without express or implied warranty.
|
14
|
+
#
|
15
|
+
|
16
|
+
require "hpdf"
|
17
|
+
|
18
|
+
def draw_line(page, x, y, text)
|
19
|
+
page.begin_text
|
20
|
+
page.move_text_pos(x, y - 10)
|
21
|
+
page.show_text(text)
|
22
|
+
page.end_text
|
23
|
+
|
24
|
+
page.move_to(x, y - 15)
|
25
|
+
page.line_to(x + 220, y - 15)
|
26
|
+
page.stroke
|
27
|
+
end
|
28
|
+
|
29
|
+
def draw_line2(page, x, y, text)
|
30
|
+
page.begin_text
|
31
|
+
page.move_text_pos(x, y)
|
32
|
+
page.show_text(text)
|
33
|
+
page.end_text
|
34
|
+
|
35
|
+
page.move_to(x + 30, y - 25)
|
36
|
+
page.line_to(x + 160, y - 25)
|
37
|
+
page.stroke
|
38
|
+
end
|
39
|
+
|
40
|
+
def draw_rect(page, x, y, text)
|
41
|
+
page.begin_text
|
42
|
+
page.move_text_pos(x, y - 10)
|
43
|
+
page.show_text(text)
|
44
|
+
page.end_text
|
45
|
+
|
46
|
+
page.rectangle(x, y - 40, 220, 25)
|
47
|
+
end
|
48
|
+
|
49
|
+
pdf = HPDFDoc.new
|
50
|
+
|
51
|
+
pdf.set_compression_mode(HPDFDoc::HPDF_COMP_ALL)
|
52
|
+
|
53
|
+
font = pdf.get_font("Helvetica", nil)
|
54
|
+
|
55
|
+
page = pdf.add_page
|
56
|
+
|
57
|
+
#print the lines of the page.#
|
58
|
+
page.set_line_width(1)
|
59
|
+
x = page.get_width - 100
|
60
|
+
y = page.get_height - 110
|
61
|
+
page.rectangle(50, 50, x, y)
|
62
|
+
page.stroke
|
63
|
+
|
64
|
+
#print the title of the page (with positioning center).#
|
65
|
+
page.set_font_and_size(font, 24)
|
66
|
+
tw = page.text_width('Line Demo')
|
67
|
+
page.begin_text
|
68
|
+
|
69
|
+
x =(page.get_width - tw) / 2
|
70
|
+
y = page.get_height - 50
|
71
|
+
page.move_text_pos(x, y)
|
72
|
+
|
73
|
+
page.show_text('Line Demo')
|
74
|
+
page.end_text
|
75
|
+
|
76
|
+
page.set_font_and_size(font, 10)
|
77
|
+
|
78
|
+
#Draw verious widths of lines.#
|
79
|
+
page.set_line_width(0)
|
80
|
+
draw_line(page, 60, 770, 'line width = 0')
|
81
|
+
|
82
|
+
page.set_line_width(1.0)
|
83
|
+
draw_line(page, 60, 740, 'line width = 1.0')
|
84
|
+
|
85
|
+
page.set_line_width(2.0)
|
86
|
+
draw_line(page, 60, 710, 'line width = 2.0')
|
87
|
+
|
88
|
+
#Line dash pattern#
|
89
|
+
page.set_line_width(1.0)
|
90
|
+
|
91
|
+
page.set_dash([3], 1)
|
92
|
+
draw_line(page, 60, 680, 'dash_ptn=[3], phase=1 -- 2 on, 3 off, 3 on...')
|
93
|
+
|
94
|
+
page.set_dash([7, 3], 2)
|
95
|
+
draw_line(page, 60, 650, 'dash_ptn=[7, 3], phase=2 -- 5 on 3 off, 7 on,...')
|
96
|
+
|
97
|
+
page.set_dash([8, 7, 2, 7], 0)
|
98
|
+
draw_line(page, 60, 620, 'dash_ptn=[8, 7, 2, 7], phase=0')
|
99
|
+
|
100
|
+
page.set_dash([], 0)
|
101
|
+
|
102
|
+
page.set_line_width(30)
|
103
|
+
page.set_rgb_stroke(0.0, 0.5, 0.0)
|
104
|
+
|
105
|
+
#Line Cap Style#
|
106
|
+
page.set_line_cap(HPDFDoc::HPDF_BUTT_END)
|
107
|
+
draw_line2(page, 60, 570, 'HPDF_BUTT_END')
|
108
|
+
|
109
|
+
page.set_line_cap(HPDFDoc::HPDF_ROUND_END)
|
110
|
+
draw_line2(page, 60, 505, 'HPDF_ROUND_END')
|
111
|
+
|
112
|
+
page.set_line_cap(HPDFDoc::HPDF_PROJECTING_SCUARE_END)
|
113
|
+
draw_line2(page, 60, 440, 'HPDF_PROJECTING_SCUARE_END')
|
114
|
+
|
115
|
+
#Line Join Style#
|
116
|
+
page.set_line_width(30)
|
117
|
+
page.set_rgb_stroke(0.0, 0.0, 0.5)
|
118
|
+
|
119
|
+
page.set_line_join(HPDFDoc::HPDF_MITER_JOIN)
|
120
|
+
page.move_to(120, 300)
|
121
|
+
page.line_to(160, 340)
|
122
|
+
page.line_to(200, 300)
|
123
|
+
page.stroke
|
124
|
+
|
125
|
+
page.begin_text
|
126
|
+
page.move_text_pos(60, 360)
|
127
|
+
page.show_text('HPDF_MITER_JOIN')
|
128
|
+
page.end_text
|
129
|
+
|
130
|
+
page.set_line_join(HPDFDoc::HPDF_ROUND_JOIN)
|
131
|
+
page.move_to(120, 195)
|
132
|
+
page.line_to(160, 235)
|
133
|
+
page.line_to(200, 195)
|
134
|
+
page.stroke
|
135
|
+
|
136
|
+
page.begin_text
|
137
|
+
page.move_text_pos(60, 255)
|
138
|
+
page.show_text('HPDF_ROUND_JOIN')
|
139
|
+
page.end_text
|
140
|
+
|
141
|
+
page.set_line_join(HPDFDoc::HPDF_BEVEL_JOIN)
|
142
|
+
page.move_to(120, 90)
|
143
|
+
page.line_to(160, 130)
|
144
|
+
page.line_to(200, 90)
|
145
|
+
page.stroke
|
146
|
+
|
147
|
+
page.begin_text
|
148
|
+
page.move_text_pos(60, 150)
|
149
|
+
page.show_text('HPDF_BEVEL_JOIN')
|
150
|
+
page.end_text
|
151
|
+
|
152
|
+
# Draw rectangle #
|
153
|
+
page.set_line_width(2)
|
154
|
+
page.set_rgb_stroke(0, 0, 0)
|
155
|
+
page.set_rgb_fill(0.75, 0.0, 0.0)
|
156
|
+
|
157
|
+
draw_rect(page, 300, 770, 'stroke')
|
158
|
+
page.stroke
|
159
|
+
|
160
|
+
draw_rect(page, 300, 720, 'Fill')
|
161
|
+
page.fill
|
162
|
+
|
163
|
+
draw_rect(page, 300, 670, 'Fill then stroke')
|
164
|
+
page.fill_stroke
|
165
|
+
|
166
|
+
#clip Rect#
|
167
|
+
page.gsave # Save the current graphic state#
|
168
|
+
draw_rect(page, 300, 620, 'Clip rectangle')
|
169
|
+
page.clip
|
170
|
+
page.stroke
|
171
|
+
page.set_font_and_size(font, 13)
|
172
|
+
|
173
|
+
page.begin_text
|
174
|
+
page.move_text_pos(290, 600)
|
175
|
+
page.set_text_leading(12)
|
176
|
+
page.show_text('Clip Clip Clip Clip Clip Clipi Clip Clip Clip')
|
177
|
+
page.show_text_next_line('Clip Clip Clip Clip Clip Clip Clip Clip Clip')
|
178
|
+
page.show_text_next_line('Clip Clip Clip Clip Clip Clip Clip Clip Clip')
|
179
|
+
page.end_text
|
180
|
+
page.grestore
|
181
|
+
|
182
|
+
x0 = 330
|
183
|
+
y0 = 440
|
184
|
+
x1 = 430
|
185
|
+
y1 = 530
|
186
|
+
x2 = 480
|
187
|
+
y2 = 470
|
188
|
+
x3 = 480
|
189
|
+
y3 = 90
|
190
|
+
|
191
|
+
#Curve Example(curve_to2)#
|
192
|
+
page.set_rgb_fill(0, 0, 0)
|
193
|
+
|
194
|
+
page.begin_text
|
195
|
+
page.move_text_pos(300, 540)
|
196
|
+
page.show_text('curve_to2(x1, y1, x2. y2)')
|
197
|
+
page.end_text
|
198
|
+
|
199
|
+
page.begin_text
|
200
|
+
page.move_text_pos(x0 + 5, y0 - 5)
|
201
|
+
page.show_text('Current point')
|
202
|
+
page.move_text_pos(x1 - x0, y1 - y0)
|
203
|
+
page.show_text('(x1, y1)')
|
204
|
+
page.move_text_pos(x2 - x1, y2 - y1)
|
205
|
+
page.show_text('(x2, y2)')
|
206
|
+
page.end_text
|
207
|
+
|
208
|
+
page.set_dash([], 0)
|
209
|
+
|
210
|
+
page.set_line_width(0.5)
|
211
|
+
page.move_to(x1, y1)
|
212
|
+
page.line_to(x2, y2)
|
213
|
+
page.stroke
|
214
|
+
|
215
|
+
page.set_dash([], 0)
|
216
|
+
|
217
|
+
page.set_line_width(1.5)
|
218
|
+
|
219
|
+
page.move_to(x0, y0)
|
220
|
+
page.curve_to2(x1, y1, x2, y2)
|
221
|
+
page.stroke
|
222
|
+
|
223
|
+
#Curve Example(curve_to3)#
|
224
|
+
y0 = y0 - 150
|
225
|
+
y1 = y1 - 150
|
226
|
+
y2 = y2 - 150
|
227
|
+
|
228
|
+
page.begin_text
|
229
|
+
page.move_text_pos(300, 390)
|
230
|
+
page.show_text('curve_to3(x1, y1, x2. y2)')
|
231
|
+
page.end_text
|
232
|
+
|
233
|
+
page.begin_text
|
234
|
+
page.move_text_pos(x0 + 5, y0 - 5)
|
235
|
+
page.show_text('Current point')
|
236
|
+
page.move_text_pos(x1 - x0, y1 - y0)
|
237
|
+
page.show_text('(x1, y1)')
|
238
|
+
page.move_text_pos(x2 - x1, y2 - y1)
|
239
|
+
page.show_text('(x2, y2)')
|
240
|
+
page.end_text
|
241
|
+
|
242
|
+
page.set_dash([3], 1)
|
243
|
+
|
244
|
+
page.set_line_width(0.5)
|
245
|
+
page.move_to(x0, y0)
|
246
|
+
page.line_to(x1, y1)
|
247
|
+
page.stroke
|
248
|
+
|
249
|
+
page.set_dash([], 0)
|
250
|
+
|
251
|
+
page.set_line_width(1.5)
|
252
|
+
page.move_to(x0, y0)
|
253
|
+
page.curve_to3(x1, y1, x2, y2)
|
254
|
+
page.stroke
|
255
|
+
|
256
|
+
# Curve Example(curve_to)
|
257
|
+
y0 = y0 - 150
|
258
|
+
y1 = y1 - 160
|
259
|
+
y2 = y2 - 130
|
260
|
+
x2 = x2 + 10
|
261
|
+
|
262
|
+
page.begin_text
|
263
|
+
page.move_text_pos(300, 240)
|
264
|
+
page.show_text('curve_to(x1, y1, x2. y2, x3, y3)')
|
265
|
+
page.end_text
|
266
|
+
|
267
|
+
page.begin_text
|
268
|
+
page.move_text_pos(x0 + 5, y0 - 5)
|
269
|
+
page.show_text('Current point')
|
270
|
+
page.move_text_pos(x1 - x0, y1 - y0)
|
271
|
+
page.show_text('(x1, y1)')
|
272
|
+
page.move_text_pos(x2 - x1, y2 - y1)
|
273
|
+
page.show_text('(x2, y2)')
|
274
|
+
page.move_text_pos(x3 - x2, y3 - y2)
|
275
|
+
page.show_text('(x3, y3)')
|
276
|
+
page.end_text
|
277
|
+
|
278
|
+
page.set_dash([3], 1)
|
279
|
+
|
280
|
+
page.set_line_width(0.5)
|
281
|
+
page.move_to(x0, y0)
|
282
|
+
page.line_to(x1, y1)
|
283
|
+
page.stroke
|
284
|
+
page.move_to(x2, y2)
|
285
|
+
page.line_to(x3, y3)
|
286
|
+
page.stroke
|
287
|
+
|
288
|
+
page.set_dash([], 0)
|
289
|
+
|
290
|
+
page.set_line_width(1.5)
|
291
|
+
page.move_to(x0, y0)
|
292
|
+
page.curve_to(x1, y1, x2, y2, x3, y3)
|
293
|
+
page.stroke
|
294
|
+
|
295
|
+
if $demo_output_filename
|
296
|
+
file_name= $demo_output_filename
|
297
|
+
else
|
298
|
+
file_name= $0 + ".pdf"
|
299
|
+
end
|
300
|
+
|
301
|
+
pdf.save_to_file(file_name)
|