Click here to Skip to main content
15,896,063 members
Articles / Programming Languages / C#

CooksMate

Rate me:
Please Sign up or sign in to vote.
3.32/5 (8 votes)
21 Jan 2008GPL32 min read 56.9K   1K   23  
A simple program to help get the timing of a roast dinner
/*
 * Created by SharpDevelop.
 * User: andy
 * Date: 27/12/2007
 * Time: 21:10
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.IO;
using System.Drawing.Text;
using System.Resources;
using System.Collections;

namespace uk.org.aspellclark.common
{
	/// <summary>
	/// Description of FontHandler.
	/// we can download more fonts from http://www.fontspace.com/category/futuristic?p=4
	/// </summary>
	public class FontHandler
	{
		// Create a logger for use in this class
		private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
		
		private PrivateFontCollection pfc = new PrivateFontCollection();
		
		private ArrayList fontNames = new ArrayList();

		public FontHandler()
		{
			fontNames.Add("AKEI____.TTF");
			fontNames.Add("Aunchanted.ttf");
			fontNames.Add("AunchantedBold.ttf");
			fontNames.Add("AunchantedBoldOblique.ttf");
			fontNames.Add("AunchantedCondense.ttf");
			fontNames.Add("AunchantedCondenseOblique.ttf");
			fontNames.Add("AunchantedExpanded.ttf");
			fontNames.Add("AunchantedExpandedBold.ttf");
			fontNames.Add("AunchantedExpandedBoldOblique.ttf");
			fontNames.Add("AunchantedExpandedOblique.ttf");
			fontNames.Add("AunchantedOblique.ttf");
			fontNames.Add("AunchantedThin.ttf");
			fontNames.Add("AunchantedThinExpanded.ttf");
			fontNames.Add("AunchantedThinExpandedOblique.ttf");
			fontNames.Add("AunchantedThinOblique.ttf");
			fontNames.Add("BlackWolf.ttf");
			fontNames.Add("cft.ttf");
			fontNames.Add("Crysta.ttf");
			fontNames.Add("D3Euronism.ttf");
			fontNames.Add("D3Euronism_b.ttf");
			fontNames.Add("D3Euronism_b_i.ttf");
			fontNames.Add("D3Euronism_i.ttf");
			fontNames.Add("Dina.fon");
			fontNames.Add("Futured.TTF");
			fontNames.Add("Munkeyshine.ttf");
			fontNames.Add("PIPED.TTF");
			fontNames.Add("PixelCarnageMono.ttf");
			fontNames.Add("PROFONT.FON");
			fontNames.Add("ProFontWindows.ttf");
			fontNames.Add("ProFW33.pfm");
			fontNames.Add("ProgFont.ttf");
			fontNames.Add("ProggyClean.ttf");
			fontNames.Add("ProggyCleanCE.ttf");
			fontNames.Add("ProggyCleanSZ.ttf");
			fontNames.Add("ProggyCleanSZBP.ttf");
			fontNames.Add("ProggySquare.ttf");
			fontNames.Add("ProggySquareSZ.ttf");
			fontNames.Add("ProggyTiny.ttf");
			fontNames.Add("ProggyTinySZ.ttf");
			fontNames.Add("sheldon.fon");
			fontNames.Add("sheldon4.fon");
		}
		
		private void LoadFonts()
		{
			string namespaceStr ="uk.org.aspellclark.common";

			log.Info("Loading fonts");

        	foreach (string fontname in fontNames)
        	{
        		Stream fontStream = this.GetType().Assembly.GetManifestResourceStream(String.Format("{0}.{1}", namespaceStr, fontname));
	
				byte[] fontdata = new byte[fontStream.Length];
				fontStream.Read(fontdata,0,(int)fontStream.Length);
				fontStream.Close();
				
				unsafe
				{
					fixed(byte * pFontData = fontdata)
					{
						pfc.AddMemoryFont((System.IntPtr)pFontData,fontdata.Length);
					}
				}
        	}
        }
		
		public static void DumpFontList()
		{
			ResourceReader rr=new ResourceReader("fonts.resx");
			IDictionaryEnumerator en = rr.GetEnumerator();

			while(en.MoveNext())
			{
				log.Info(String.Format("Font [{0}]", en.Key));
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior) Airbus Defense and Space
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions