1#
2# << Haru Free PDF Library 2.0.2 >> -- arc_demo.rb
3#
4# http://libharu.org/
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
16require "hpdf"
17
18pdf = HPDFDoc.new
19
20# add a new page object. #
21page = pdf.add_page
22
23page.set_height(220)
24page.set_width(200)
25
26# draw pie chart
27#
28#   A: 45% Red
29#   B: 25% Blue
30#   C: 15% green
31#   D: other yellow
32#
33
34# A #
35page.set_rgb_fill(1.0, 0, 0)
36page.move_to(100, 100)
37page.line_to(100, 180)
38page.arc(100, 100, 80, 0, 360 * 0.45)
39pos = page.get_current_pos
40page.line_to(100, 100)
41page.fill
42
43# B #
44page.set_rgb_fill(0, 0, 1.0)
45page.move_to(100, 100)
46page.line_to(pos[0], pos[1])
47page.arc(100, 100, 80, 360 * 0.45, 360 * 0.7)
48pos = page.get_current_pos
49page.line_to(100, 100)
50page.fill
51
52# C #
53page.set_rgb_fill(0, 1.0, 0)
54page.move_to(100, 100)
55page.line_to(pos[0], pos[1])
56page.arc(100, 100, 80, 360 * 0.7, 360 * 0.85)
57pos = page.get_current_pos
58page.line_to(100, 100)
59page.fill
60
61# D #
62page.set_rgb_fill(1.0, 1.0, 0)
63page.move_to(100, 100)
64page.line_to(pos[0], pos[1])
65page.arc(100, 100, 80, 360 * 0.85, 360)
66pos = page.get_current_pos
67page.line_to(100, 100)
68page.fill
69
70# draw center circle #
71page.set_gray_stroke(0)
72page.set_gray_fill(1)
73page.circle(100, 100, 30)
74page.fill
75
76pdf.save_to_file($0 + ".pdf")
77
78