| 1 |
/* |
| 2 |
* << Haru Free PDF Library 2.0.5 >> -- FontDemo.cs |
| 3 |
* |
| 4 |
* Copyright (c) 1999-2006 Takeshi Kanno <[email protected]> |
| 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 |
|
| 15 |
using System; |
| 16 |
using System.IO; |
| 17 |
using HPdf; |
| 18 |
|
| 19 |
|
| 20 |
public class FontDemo { |
| 21 |
public static void Main() { |
| 22 |
string[] font_list = new string[] { |
| 23 |
"Courier", |
| 24 |
"Courier-Bold", |
| 25 |
"Courier-Oblique", |
| 26 |
"Courier-BoldOblique", |
| 27 |
"Helvetica", |
| 28 |
"Helvetica-Bold", |
| 29 |
"Helvetica-Oblique", |
| 30 |
"Helvetica-BoldOblique", |
| 31 |
"Times-Roman", |
| 32 |
"Times-Bold", |
| 33 |
"Times-Italic", |
| 34 |
"Times-BoldItalic", |
| 35 |
"Symbol", |
| 36 |
"ZapfDingbats" |
| 37 |
}; |
| 38 |
|
| 39 |
Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion()); |
| 40 |
|
| 41 |
try { |
| 42 |
const string page_title = "FontDemo"; |
| 43 |
|
| 44 |
HPdfDoc pdf = new HPdfDoc(); |
| 45 |
|
| 46 |
HPdfPage page = pdf.AddPage(); |
| 47 |
|
| 48 |
float height = page.GetHeight(); |
| 49 |
float width = page.GetWidth(); |
| 50 |
|
| 51 |
/* Print the lines of the page. */ |
| 52 |
page.SetLineWidth(1); |
| 53 |
page.Rectangle(50, 50, width - 100, height - 110); |
| 54 |
page.Stroke(); |
| 55 |
|
| 56 |
/* Print the title of the page (with positioning center). */ |
| 57 |
HPdfFont def_font = pdf.GetFont ("Helvetica", null); |
| 58 |
page.SetFontAndSize(def_font, 24); |
| 59 |
|
| 60 |
float tw = page.TextWidth(page_title); |
| 61 |
page.BeginText(); |
| 62 |
page.TextOut((width - tw) / 2, height - 50, page_title); |
| 63 |
page.EndText(); |
| 64 |
|
| 65 |
/* output subtitle. */ |
| 66 |
page.BeginText(); |
| 67 |
page.SetFontAndSize(def_font, 16); |
| 68 |
page.TextOut(60, height - 80, "<Standerd Type1 fonts samples>"); |
| 69 |
page.EndText(); |
| 70 |
|
| 71 |
page.BeginText(); |
| 72 |
page.MoveTextPos(60, height - 105); |
| 73 |
|
| 74 |
for (int i = 0; i < font_list.Length; i++) { |
| 75 |
const string samp_text = "abcdefgABCDEFG12345!#$%&+-@?"; |
| 76 |
HPdfFont font = pdf.GetFont(font_list[i], null); |
| 77 |
|
| 78 |
/* print a label of text */ |
| 79 |
page.SetFontAndSize(def_font, 9); |
| 80 |
page.ShowText(font_list[i]); |
| 81 |
page.MoveTextPos(0, -18); |
| 82 |
|
| 83 |
/* print a sample text. */ |
| 84 |
page.SetFontAndSize(font, 20); |
| 85 |
page.ShowText(samp_text); |
| 86 |
page.MoveTextPos(0, -20); |
| 87 |
} |
| 88 |
|
| 89 |
page.EndText(); |
| 90 |
|
| 91 |
pdf.SaveToFile("FontDemo.pdf"); |
| 92 |
} catch (Exception e) { |
| 93 |
Console.Error.WriteLine(e.Message); |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|