OSDN Git Service

binding with libharu.
[putex/putex.git] / src / texsourc / lib / libhpdf / if / ruby / demo / font_demo.rb
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 pdf.save_to_file($0 + ".pdf")
61