forked from libharu/libharu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arc_demo.rb
executable file
·77 lines (65 loc) · 1.65 KB
/
arc_demo.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#
# << Haru Free PDF Library 2.0.2 >> -- arc_demo.rb
#
# http://libharu.sourceforge.net/
#
# Copyright (c) 1999-2006 Takeshi Kanno
#
# Permission to use, copy, modify, distribute and sell this software
# and its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear
# in supporting documentation.
# It is provided "as is" without express or implied warranty.
#
require "hpdf"
pdf = HPDFDoc.new
# add a new page object. #
page = pdf.add_page
page.set_height(220)
page.set_width(200)
# draw pie chart
#
# A: 45% Red
# B: 25% Blue
# C: 15% green
# D: other yellow
#
# A #
page.set_rgb_fill(1.0, 0, 0)
page.move_to(100, 100)
page.line_to(100, 180)
page.arc(100, 100, 80, 0, 360 * 0.45)
pos = page.get_current_pos
page.line_to(100, 100)
page.fill
# B #
page.set_rgb_fill(0, 0, 1.0)
page.move_to(100, 100)
page.line_to(pos[0], pos[1])
page.arc(100, 100, 80, 360 * 0.45, 360 * 0.7)
pos = page.get_current_pos
page.line_to(100, 100)
page.fill
# C #
page.set_rgb_fill(0, 1.0, 0)
page.move_to(100, 100)
page.line_to(pos[0], pos[1])
page.arc(100, 100, 80, 360 * 0.7, 360 * 0.85)
pos = page.get_current_pos
page.line_to(100, 100)
page.fill
# D #
page.set_rgb_fill(1.0, 1.0, 0)
page.move_to(100, 100)
page.line_to(pos[0], pos[1])
page.arc(100, 100, 80, 360 * 0.85, 360)
pos = page.get_current_pos
page.line_to(100, 100)
page.fill
# draw center circle #
page.set_gray_stroke(0)
page.set_gray_fill(1)
page.circle(100, 100, 30)
page.fill
pdf.save_to_file($0 + ".pdf")