2 # << Haru Free PDF Library 2.0.2 >> -- line_demo.rb
6 # Copyright (c) 1999-2006 Takeshi Kanno
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.
18 def draw_line(page, x, y, text)
20 page.move_text_pos(x, y - 10)
24 page.move_to(x, y - 15)
25 page.line_to(x + 220, y - 15)
29 def draw_line2(page, x, y, text)
31 page.move_text_pos(x, y)
35 page.move_to(x + 30, y - 25)
36 page.line_to(x + 160, y - 25)
40 def draw_rect(page, x, y, text)
42 page.move_text_pos(x, y - 10)
46 page.rectangle(x, y - 40, 220, 25)
51 pdf.set_compression_mode(HPDFDoc::HPDF_COMP_ALL)
53 font = pdf.get_font("Helvetica", nil)
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)
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')
69 x =(page.get_width - tw) / 2
70 y = page.get_height - 50
71 page.move_text_pos(x, y)
73 page.show_text('Line Demo')
76 page.set_font_and_size(font, 10)
78 #Draw verious widths of lines.#
79 page.set_line_width(0)
80 draw_line(page, 60, 770, 'line width = 0')
82 page.set_line_width(1.0)
83 draw_line(page, 60, 740, 'line width = 1.0')
85 page.set_line_width(2.0)
86 draw_line(page, 60, 710, 'line width = 2.0')
89 page.set_line_width(1.0)
92 draw_line(page, 60, 680, 'dash_ptn=[3], phase=1 -- 2 on, 3 off, 3 on...')
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,...')
97 page.set_dash([8, 7, 2, 7], 0)
98 draw_line(page, 60, 620, 'dash_ptn=[8, 7, 2, 7], phase=0')
102 page.set_line_width(30)
103 page.set_rgb_stroke(0.0, 0.5, 0.0)
106 page.set_line_cap(HPDFDoc::HPDF_BUTT_END)
107 draw_line2(page, 60, 570, 'HPDF_BUTT_END')
109 page.set_line_cap(HPDFDoc::HPDF_ROUND_END)
110 draw_line2(page, 60, 505, 'HPDF_ROUND_END')
112 page.set_line_cap(HPDFDoc::HPDF_PROJECTING_SCUARE_END)
113 draw_line2(page, 60, 440, 'HPDF_PROJECTING_SCUARE_END')
116 page.set_line_width(30)
117 page.set_rgb_stroke(0.0, 0.0, 0.5)
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)
126 page.move_text_pos(60, 360)
127 page.show_text('HPDF_MITER_JOIN')
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)
137 page.move_text_pos(60, 255)
138 page.show_text('HPDF_ROUND_JOIN')
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)
148 page.move_text_pos(60, 150)
149 page.show_text('HPDF_BEVEL_JOIN')
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)
157 draw_rect(page, 300, 770, 'stroke')
160 draw_rect(page, 300, 720, 'Fill')
163 draw_rect(page, 300, 670, 'Fill then stroke')
167 page.gsave # Save the current graphic state#
168 draw_rect(page, 300, 620, 'Clip rectangle')
171 page.set_font_and_size(font, 13)
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')
191 #Curve Example(curve_to2)#
192 page.set_rgb_fill(0, 0, 0)
195 page.move_text_pos(300, 540)
196 page.show_text('curve_to2(x1, y1, x2. y2)')
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)')
210 page.set_line_width(0.5)
217 page.set_line_width(1.5)
220 page.curve_to2(x1, y1, x2, y2)
223 #Curve Example(curve_to3)#
229 page.move_text_pos(300, 390)
230 page.show_text('curve_to3(x1, y1, x2. y2)')
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)')
242 page.set_dash([3], 1)
244 page.set_line_width(0.5)
251 page.set_line_width(1.5)
253 page.curve_to3(x1, y1, x2, y2)
256 # Curve Example(curve_to)
263 page.move_text_pos(300, 240)
264 page.show_text('curve_to(x1, y1, x2. y2, x3, y3)')
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)')
278 page.set_dash([3], 1)
280 page.set_line_width(0.5)
290 page.set_line_width(1.5)
292 page.curve_to(x1, y1, x2, y2, x3, y3)
295 pdf.save_to_file($0 + ".pdf")