From 49b3d926ea33f486468f0bc855585968eacca124 Mon Sep 17 00:00:00 2001 From: Jes Date: Wed, 6 Jan 2010 23:39:02 +0100 Subject: Ajout des sources de l'éditeur de script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-editor/FontFile.cs | 117 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 script-editor/FontFile.cs (limited to 'script-editor/FontFile.cs') diff --git a/script-editor/FontFile.cs b/script-editor/FontFile.cs new file mode 100644 index 0000000..8bbf61e --- /dev/null +++ b/script-editor/FontFile.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Xml; + +namespace VPScriptEditor +{ + public class FontFile + { + private Dictionary data; + private Symbol[] glyphs; + private Bitmap[] bitmaps; + + private class Symbol + { + private bool[,] data; + private int width; + private char text; + + public char getText() + { + return text; + } + + public bool getXY(int x, int y) + { + return data[x, y]; + } + + public int getWidth() + { + return width; + } + + public Symbol(XmlAttributeCollection attrs) + { + data = new bool[12, 12]; + + for (int i = 0; i < attrs.Count; i++) + { + switch (attrs[i].Name) + { + case "Width": + width = int.Parse(attrs[i].Value); + break; + + case "Data": + byte[] bdata = Convert.FromBase64String(attrs[i].Value); + + for (int y = 0; y < 12; y++) + { + int curr = bdata[y * 2 + 1] * 256 + bdata[y * 2]; + for (int x = 0; x < 12; x++) + if ((curr & (0x8000 >> x)) > 0) + data[x, y] = true; + else + data[x, y] = false; + } + + break; + + case "Text": + if (attrs[i].Value.Length != 1) + throw new Exception("Invalid database"); + + text = attrs[i].Value[0]; + break; + + default: + throw new Exception(("Wrong Font XML Format - Unknown attribute: " + attrs[i].Name)); + } + + } + } + } + + public FontFile(System.IO.StreamReader file, Color color) + { + XmlDocument fontXml = new XmlDocument(); + fontXml.Load(file); + XmlNodeList fontNode = fontXml.GetElementsByTagName("Symbol"); + glyphs = new Symbol[fontNode.Count + 1]; + bitmaps = new Bitmap[fontNode.Count + 1]; + data = new Dictionary(); + for (int i = 0; i < fontNode.Count; i++) + { + glyphs[i] = new Symbol(fontNode[i].Attributes); + data.Add(glyphs[i].getText(), i); + bitmaps[i] = new Bitmap(glyphs[i].getWidth(), 12); + for (int y = 0; y < 12; y++) + for (int x = 0; x < glyphs[i].getWidth(); x++) + if (glyphs[i].getXY(x, y)) + bitmaps[i].SetPixel(x, y, color); + } + } + + public bool containsSymbol(char symbol) + { + return data.ContainsKey(symbol); + } + + public int getSymbolWidth(char symbol) + { + return glyphs[data[symbol]].getWidth(); + } + + public bool getSymbolXY(char symbol, int x, int y) + { + return glyphs[data[symbol]].getXY(x, y); + } + + public Bitmap getBitmap(char symbol) + { + return bitmaps[data[symbol]]; + } + } +} \ No newline at end of file -- cgit v1.2.3