3 // Simple font handeling
6 // Jordi Mas i Hernandez <jordi@ximian.com>
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Drawing.Text;
35 using System.Drawing.Imaging;
37 namespace Font1Sample {
38 public class FontDrawing {
40 public static void listFonts()
42 FontCollection ifc = new InstalledFontCollection();
43 foreach( FontFamily ffm in ifc.Families) {
46 Font f = new Font(ffm.Name,12);
47 Console.WriteLine("Family Name:" + ffm.Name + "," + f.Name);
49 catch (Exception ex) {}
53 public static void checkFontProperties()
55 Font f = new Font("Arial",12);
56 Console.WriteLine("Font:" + f.Name + " size:" + f.Size);
58 f = new Font("Verdana", 12);
59 Console.WriteLine("Font:" + f.Name + " size:" + f.Size);
61 f = new Font("Courier New", 12);
62 Console.WriteLine("Font:" + f.Name + " size:" + f.Size);
66 public static void Main( )
68 Console.WriteLine("Fonts--------------------");
71 Console.WriteLine("Propierties--------------------");
72 checkFontProperties();
74 Console.WriteLine("Draw--------------------");
76 float height = 650.0F;
79 Font f1 = new Font("Arial",12);
80 Font f2 = new Font("Verdana", 12, FontStyle.Bold);
81 Font f3 = new Font("Courier New", 12, FontStyle.Italic);
83 Font f4 = new Font(FontFamily.GenericSansSerif, 19, FontStyle.Regular, GraphicsUnit.Millimeter);
84 Console.WriteLine("Font:" + f4.Name + " size:" + f4.Size + "Points: " + f4.SizeInPoints);
86 Font f5 = new Font(FontFamily.GenericSerif, 15, FontStyle.Regular, GraphicsUnit.Point);
87 Console.WriteLine("Font:" + f5.Name + " size:" + f5.Size + "Points: " + f5.SizeInPoints);
89 Font f6 = new Font("Arial", 40, FontStyle.Regular, GraphicsUnit.Pixel);
90 Console.WriteLine("Font:" + f6.Name + " size:" + f6.Size + "Points: " + f6.SizeInPoints);
92 Font f7 = new Font("Courier New", 19, FontStyle.Regular, GraphicsUnit.World);
93 Console.WriteLine("Font:" + f7.Name + " size:" + f7.Size + "Points: " + f7.SizeInPoints);
95 Font f8 = new Font("Courier New", 19, FontStyle.Bold | FontStyle.Underline, GraphicsUnit.World);
96 Console.WriteLine("Font:" + f8.Name + " size:" + f8.Size + "Points: " + f8.SizeInPoints);
98 Font f9 = new Font("Courier New", 19, FontStyle.Bold | FontStyle.Underline| FontStyle.Italic, GraphicsUnit.World);
99 Console.WriteLine("Font:" + f9.Name + " size:" + f9.Size + "Points: " + f9.SizeInPoints);
101 Font f10 = new Font(FontFamily.GenericSansSerif, 14, FontStyle.Strikeout, GraphicsUnit.Millimeter);
102 Console.WriteLine("Font:" + f10.Name + " size:" + f10.Size + "Points: " + f10.SizeInPoints);
105 Bitmap bmp = new Bitmap((int)width, (int)height);
106 Graphics gr = Graphics.FromImage(bmp);
107 SolidBrush br = new SolidBrush(Color.White);
108 SolidBrush colorRed = new SolidBrush(Color.Red);
110 gr.FillRectangle(br, 0.0F, 0.0F, width, height);
112 br = new SolidBrush(Color.Black);
114 str = "This an " + f1.Name + " test string size: "+ f1.Height;
115 gr.DrawString (str, f1, br, 10, 10);
117 str = "This a " + f2.Name + " bold test string size: "+ f2.Height;
118 gr.DrawString( str, f2, colorRed, 10, 50);
120 str = "This a " + f3.Name + " italic test string size: "+ f3.Height;
121 gr.DrawString( str, f3, br, 10, 100);
123 str = "This an " + f4.Name + " test string size: "+ f4.Height;
124 gr.DrawString (str, f4, br, 10, 150);
126 str = "This a " + f5.Name + " test string size: "+ f5.Height;
127 gr.DrawString( str, f5, colorRed, 10, 250);
129 str = "This a " + f6.Name + " test string size: "+ f6.Height;
130 gr.DrawString( str, f6, br, new Rectangle(10,300,0,0));
132 str = "This a " + f7.Name + " test string size: "+ f7.Height;
133 gr.DrawString( str, f7, br, 10,350);
135 str = "This a " + f8.Name + " test (Underline/Bold) string size: "+ f8.Height;
136 gr.DrawString( str, f8, br, 10,400);
138 str = "This a " + f9.Name + " test (Underline/Bold/Italic) string size: "+ f9.Height;
139 gr.DrawString( str, f9, br, 10,450);
141 str = "This a " + f10.Name + " test (Strikeout) string size: "+ f10.Height;
142 gr.DrawString( str, f10, br, 10,500);
145 bmp.Save("FontDrawing.bmp", ImageFormat.Bmp);