public SimpleFontAtlas CreateSimpleFontAtlas() { SimpleFontAtlas simpleFontAtlas = new SimpleFontAtlas(); simpleFontAtlas.TextureKind = this.TextureKind; simpleFontAtlas.OriginalFontSizePts = this.FontSizeInPoints; foreach (CacheGlyph cacheGlyph in glyphs.Values) { //convert char to hex string unicode = ("0x" + ((int)cacheGlyph.character).ToString("X"));//code point Rectangle area = cacheGlyph.area; TextureFontGlyphData glyphData = new TextureFontGlyphData(); area.Y += area.Height;//*** //set font matrix to glyph font data glyphData.Rect = Rectangle.FromLTRB(area.X, area.Top, area.Right, area.Bottom); glyphData.AdvanceY = 0;// cacheGlyph.glyphMatrix.advanceY; glyphData.ImgWidth = cacheGlyph.img.Width; glyphData.TextureXOffset = cacheGlyph.img.TextureOffsetX; glyphData.TextureYOffset = cacheGlyph.img.TextureOffsetY; simpleFontAtlas.AddGlyph(cacheGlyph.codePoint, glyphData); } return(simpleFontAtlas); }
public SimpleFontAtlas CreateSimpleFontAtlas() { SimpleFontAtlas simpleFontAtlas = new SimpleFontAtlas(); simpleFontAtlas.TextureKind = this.TextureKind; simpleFontAtlas.OriginalFontSizePts = this.FontSizeInPoints; foreach (CacheGlyph cacheGlyph in _glyphs.Values) { Rectangle area = cacheGlyph.area; TextureGlyphMapData glyphData = new TextureGlyphMapData(); glyphData.Width = cacheGlyph.img.Width; glyphData.Left = area.X; glyphData.Top = area.Top; glyphData.Height = area.Height; glyphData.TextureXOffset = cacheGlyph.img.TextureOffsetX; glyphData.TextureYOffset = cacheGlyph.img.TextureOffsetY; simpleFontAtlas.AddGlyph(cacheGlyph.glyphIndex, glyphData); } return(simpleFontAtlas); }
//read font info from xml document public SimpleFontAtlas LoadFontInfo(string filename) { SimpleFontAtlas simpleFontAtlas = new SimpleFontAtlas(); simpleFontAtlas.TextureKind = this.TextureKind; XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(filename); //read int total_W = 0; int total_H = 0; { foreach (XmlElement xmlelem in xmldoc.GetElementsByTagName("total_img")) { simpleFontAtlas.Width = total_W = int.Parse(xmlelem.GetAttribute("w")); simpleFontAtlas.Height = total_H = int.Parse(xmlelem.GetAttribute("h")); //only 1... break; } } foreach (XmlElement glyphElem in xmldoc.GetElementsByTagName("glyph")) { //read string unicodeHex = glyphElem.GetAttribute("uc"); int codepoint = int.Parse(glyphElem.GetAttribute("c")); char c = (char)int.Parse(unicodeHex.Substring(2), System.Globalization.NumberStyles.HexNumber); Rectangle area = ParseRect(glyphElem.GetAttribute("ltwh")); var glyphData = new TextureFontGlyphData(); area.Y += area.Height;//*** //glyphData.Rect = Rectangle.c((short)area.X, (short)area.Bottom, (short)area.Right, (short)area.Top); glyphData.Rect = Rectangle.FromLTRB(area.X, area.Top, area.Right, area.Bottom); float[] borderXY = ParseFloatArray(glyphElem.GetAttribute("borderXY")); float[] matrix = ParseFloatArray(glyphElem.GetAttribute("mat")); glyphData.BorderX = borderXY[0]; glyphData.BorderY = borderXY[1]; glyphData.AdvanceX = matrix[0]; glyphData.AdvanceY = matrix[1]; glyphData.BBoxXMin = matrix[2]; glyphData.BBoxXMax = matrix[3]; glyphData.BBoxYMin = matrix[4]; glyphData.BBoxYMax = matrix[5]; glyphData.ImgWidth = matrix[6]; glyphData.ImgHeight = matrix[7]; glyphData.HAdvance = matrix[8]; glyphData.HBearingX = matrix[9]; glyphData.HBearingY = matrix[10]; glyphData.VAdvance = matrix[11]; glyphData.VBearingX = matrix[12]; glyphData.VBearingY = matrix[13]; //--------------- simpleFontAtlas.AddGlyph(codepoint, glyphData); } return(simpleFontAtlas); }
//read font info from xml document public SimpleFontAtlas LoadAtlasInfo(System.IO.Stream inputStream) { SimpleFontAtlas simpleFontAtlas = new SimpleFontAtlas(); simpleFontAtlas.TextureKind = this.TextureKind; XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(inputStream); //read int total_W = 0; int total_H = 0; { foreach (XmlElement xmlelem in xmldoc.GetElementsByTagName("total_img")) { simpleFontAtlas.Width = total_W = int.Parse(xmlelem.GetAttribute("w")); simpleFontAtlas.Height = total_H = int.Parse(xmlelem.GetAttribute("h")); //only 1... break; } } foreach (XmlElement glyphElem in xmldoc.GetElementsByTagName("glyph")) { //read string unicodeHex = glyphElem.GetAttribute("uc"); int glyphIndex = int.Parse(glyphElem.GetAttribute("c")); //TODO: this should be codepoint char c = (char)int.Parse(unicodeHex.Substring(2), System.Globalization.NumberStyles.HexNumber); Rectangle area = ParseRect(glyphElem.GetAttribute("ltwh")); area.Y += area.Height;//*** var glyphData = new TextureFontGlyphData(); glyphData.Rect = Rectangle.FromLTRB(area.X, area.Top, area.Right, area.Bottom); float[] borderAndTransform = ParseFloatArray(glyphElem.GetAttribute("tx")); glyphData.ImgWidth = borderAndTransform[0]; glyphData.BorderX = borderAndTransform[1]; glyphData.BorderY = borderAndTransform[2]; glyphData.TextureXOffset = borderAndTransform[3]; glyphData.TextureYOffset = borderAndTransform[4]; //--------------- simpleFontAtlas.AddGlyph(glyphIndex, glyphData); } return(simpleFontAtlas); }
public SimpleFontAtlas CreateSimpleFontAtlas() { SimpleFontAtlas simpleFontAtlas = new SimpleFontAtlas(); foreach (CacheGlyph g in glyphs.Values) { //convert char to hex string unicode = ("0x" + ((int)g.character).ToString("X"));//code point Rectangle area = g.area; var glyphData = new TextureFontGlyphData(); area.Y += area.Height;//*** //set font matrix to glyph font data glyphData.Rect = Rectangle.FromLTRB(area.X, area.Top, area.Right, area.Bottom); glyphData.AdvanceY = g.glyphMatrix.advanceY; glyphData.ImgWidth = g.img.Width; simpleFontAtlas.AddGlyph(g.codePoint, glyphData); } return(simpleFontAtlas); }