2 # << Haru Free PDF Library 2.0.2 >> -- ttfont_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 SAMP_TXT = "The quick brown fox jumps over the lazy dog."
20 font_name = ARGV.shift
24 print 'usage: ttfont_demo.rb [path to font file] -E(embedding font).'
30 pdf.set_compression_mode(HPDFDoc::HPDF_COMP_ALL)
32 # Add a new page object. #
35 title_font = pdf.get_font("Helvetica", nil)
38 embed = HPDFDoc::HPDF_TRUE
40 embed = HPDFDoc::HPDF_FALSE
43 detail_font_name = pdf.load_ttfont_from_file(font_name, embed)
44 print font_name, ' load OK.[', detail_font_name, ']'
46 detail_font = pdf.get_font(detail_font_name, nil)
48 page.set_font_and_size(title_font, 10)
52 # Move the position of the text to top of the page. #
53 page.move_text_pos(10, 190)
54 page.show_text(detail_font_name)
57 page.show_text("(Embedded Subset)")
60 page.set_font_and_size(detail_font, 15)
61 page.move_text_pos(10, -20)
62 page.show_text("abcdefghijklmnopqrstuvwxyz")
63 page.move_text_pos(0, -20)
64 page.show_text("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
65 page.move_text_pos(0, -20)
66 page.show_text("1234567890")
67 page.move_text_pos(0, -20)
69 page.set_font_and_size(detail_font, 10)
70 page.show_text(SAMP_TXT)
71 page.move_text_pos(0, -18)
73 page.set_font_and_size(detail_font, 16)
74 page.show_text(SAMP_TXT)
75 page.move_text_pos(0, -27)
77 page.set_font_and_size(detail_font, 23)
78 page.show_text(SAMP_TXT)
79 page.move_text_pos(0, -36)
81 page.set_font_and_size(detail_font, 30)
82 page.show_text(SAMP_TXT)
83 page.move_text_pos(0, -36)
85 tw = page.text_width(SAMP_TXT)
89 page.set_width(page_width)
90 page.set_height(page_height)
92 # Finish to print text. #
95 page.set_line_width(0.5)
97 page.move_to(10, page_height - 25)
98 page.line_to(page_width - 10, page_height - 25)
101 page.move_to(10, page_height - 85)
102 page.line_to(page_width - 10, page_height - 85)
105 pdf.save_to_file($0 + ".pdf")