/// <summary>Enable or disable kerning.</summary> /// <remarks> /// Enable or disable kerning. /// Some fonts may specify kern pairs, i.e. pair of glyphs, between which the amount of horizontal space is adjusted. /// This adjustment is typically negative, e.g. in "AV" pair the glyphs will typically be moved closer to each other. /// </remarks> /// <param name="fontKerning">an enum value as a boolean wrapper specifying whether or not to apply kerning</param> /// <returns>this Element.</returns> public virtual T SetFontKerning(FontKerning fontKerning) { SetProperty(Property.FONT_KERNING, fontKerning); return((T)(Object)this); }
public static FontData LoadFontFromXmlFile(TextAsset fontLayout) { FontData font = new FontData(); XmlDocument document = new XmlDocument(); document.LoadXml(fontLayout.text); XmlNode root = document.DocumentElement; // load the basic attributes XmlNode secton = root.SelectSingleNode("info"); font.Info.Face = ParseString(secton, "face"); font.Info.Size = ParseInt(secton, "size"); font.Info.Bold = ParseBool(secton, "bold"); font.Info.Italic = ParseBool(secton, "italic"); font.Info.Unicode = ParseBool(secton, "unicode"); font.Info.StretchHeight = ParseInt(secton, "stretchH"); font.Info.Charset = ParseString(secton, "charset"); font.Info.Smooth = ParseBool(secton, "smooth"); font.Info.SuperSampling = ParseInt(secton, "aa"); font.Info.Padding = ParseRect(secton, "padding"); font.Info.Spacing = ParseVector2(secton, "spacing"); font.Info.Outline = ParseInt(secton, "outline"); // common attributes secton = root.SelectSingleNode("common"); font.Common.LineHeight = ParseInt(secton, "lineHeight"); font.Common.Base = ParseInt(secton, "base"); font.Common.ScaleW = ParseInt(secton, "scaleW"); font.Common.ScaleH = ParseInt(secton, "scaleH"); font.Common.Pages = ParseInt(secton, "pages"); font.Common.Packed = ParseBool(secton, "packed"); font.Common.AlphaChannel = ParseInt(secton, "alphaChnl"); font.Common.RedChannel = ParseInt(secton, "redChnl"); font.Common.GreenChannel = ParseInt(secton, "greenChnl"); font.Common.BlueChannel = ParseInt(secton, "blueChnl"); // load texture information font.Pages.Clear(); foreach (XmlNode node in root.SelectNodes("pages/page")) { FontPage page = new FontPage(); page.Id = ParseInt(node, "id"); page.File = ParseString(node, "file"); font.Pages.Add(page); } // load character information font.Chars.Clear(); foreach (XmlNode node in root.SelectNodes("chars/char")) { FontChar ch = new FontChar(); ch.Id = ParseInt(node, "id"); ch.X = ParseInt(node, "x"); ch.Y = ParseInt(node, "y"); ch.Width = ParseInt(node, "width"); ch.Height = ParseInt(node, "height"); ch.XOffset = ParseInt(node, "xoffset"); ch.YOffset = ParseInt(node, "yoffset"); ch.XAdvance = ParseInt(node, "xadvance"); ch.Page = ParseInt(node, "page"); ch.Channel = ParseInt(node, "chnl"); ch.Description = string.Format("Char: [{0}]; Code: [{1}]", (char)ch.Id, ch.Id); font.Chars.Add(ch); } // loading kerning information font.Kernings.Clear(); foreach (XmlNode node in root.SelectNodes("kernings/kerning")) { FontKerning key = new FontKerning(); key.First = ParseInt(node, "first"); key.Second = ParseInt(node, "second"); key.Amount = ParseInt(node, "amount"); key.Description = string.Format("[{0}] [{1}] Amout: [{2}]", (char)key.First, (char)key.Second, key.Amount); font.Kernings.Add(key); } return font; }
public void LowPrint( VertexBufferWriter vertexWriter, IndexBufferWriter indexWriter, float x, float y, float z, string text ) { if (string.IsNullOrEmpty(text) == true) { return; } y += common.Base; FontChar fontChar = null; for (int i = 0; i < text.Length; ++i) { char c = text[i]; fontChar = chars[c]; if (fontChar == null) { continue; } float a = fontChar.XAdvance; float w = fontChar.Width; float h = fontChar.Height; float ox = fontChar.XOffset; float oy = fontChar.YOffset; indexWriter.Quad( vertexWriter.CurrentIndex, vertexWriter.CurrentIndex + 1, vertexWriter.CurrentIndex + 2, vertexWriter.CurrentIndex + 3 ); indexWriter.CurrentIndex += 6; vertexWriter.Set(position, x + ox, y - oy, z); vertexWriter.Set(texCoord, fontChar.U, fontChar.V); vertexWriter.Set(color, 1.0f, 1.0f, 1.0f); ++vertexWriter.CurrentIndex; Bounds.Extend(x + ox, y - oy); vertexWriter.Set(position, x + w + ox, y - oy, z); vertexWriter.Set(texCoord, fontChar.U2, fontChar.V); vertexWriter.Set(color, 1.0f, 1.0f, 1.0f); ++vertexWriter.CurrentIndex; Bounds.Extend(x + w + ox, y - oy); vertexWriter.Set(position, x + w + ox, y - h - oy, z); vertexWriter.Set(texCoord, fontChar.U2, fontChar.V2); vertexWriter.Set(color, 1.0f, 1.0f, 1.0f); ++vertexWriter.CurrentIndex; Bounds.Extend(x + w + ox, y - h - oy); vertexWriter.Set(position, x + ox, y - h - oy, z); vertexWriter.Set(texCoord, fontChar.U, fontChar.V2); vertexWriter.Set(color, 1.0f, 1.0f, 1.0f); ++vertexWriter.CurrentIndex; Bounds.Extend(x + ox, y - h - oy); x += a; if ( (i + 1 < text.Length - 1) && (fontChar.Kernings != null) ) { char next = text[i + 1]; FontKerning compare = new FontKerning((short)next); int index = fontChar.Kernings.BinarySearch(compare); if (index >= 0) { short amount = fontChar.Kernings[index].Amount; x += (float)(amount); } } } }
public static FontData LoadFontFromTextFile(TextAsset fontLayout) { FontData font = new FontData(); string[] lines = fontLayout.text.Split('\n'); font.Pages.Clear(); font.Chars.Clear(); font.Kernings.Clear(); foreach (string line in lines) { Dictionary<string, string> table = ParseLine(line); if (table.Count == 0) { continue; } switch (table["section"]) { case "info": font.Info.Face = ParseString(table, "face"); font.Info.Size = ParseInt(table, "size"); font.Info.Bold = ParseBool(table, "bold"); font.Info.Italic = ParseBool(table, "italic"); font.Info.Charset = ParseString(table, "charset"); font.Info.Unicode = ParseBool(table, "unicode"); font.Info.StretchHeight = ParseInt(table, "stretchH"); font.Info.Smooth = ParseBool(table, "smooth"); font.Info.SuperSampling = ParseInt(table, "aa"); font.Info.Padding = ParseRect(table, "padding"); font.Info.Spacing = ParseVector2(table, "spacing"); font.Info.Outline = ParseInt(table, "outline"); break; case "common": font.Common.LineHeight = ParseInt(table, "lineHeight"); font.Common.Base = ParseInt(table, "base"); font.Common.ScaleW = ParseInt(table, "scaleW"); font.Common.ScaleH = ParseInt(table, "scaleW"); font.Common.Pages = ParseInt(table, "pages"); font.Common.Packed = ParseBool(table, "packed"); font.Common.AlphaChannel = ParseInt(table, "alphaChnl"); font.Common.RedChannel = ParseInt(table, "redChnl"); font.Common.GreenChannel = ParseInt(table, "greenChnl"); font.Common.BlueChannel = ParseInt(table, "blueChnl"); break; case "page": FontPage page = new FontPage(); page.Id = ParseInt(table, "id"); page.File = ParseString(table, "file"); font.Pages.Add(page); break; case "char": FontChar ch = new FontChar(); ch.Id = ParseInt(table, "id"); ch.X = ParseInt(table, "x"); ch.Y = ParseInt(table, "y"); ch.Width = ParseInt(table, "width"); ch.Height = ParseInt(table, "height"); ch.XOffset = ParseInt(table, "xoffset"); ch.YOffset = ParseInt(table, "yoffset"); ch.XAdvance = ParseInt(table, "xadvance"); ch.Page = ParseInt(table, "page"); ch.Channel = ParseInt(table, "chnl"); ch.Description = string.Format("Char: [{0}]; Code: [{1}]", (char)ch.Id, ch.Id); font.Chars.Add(ch); break; case "kerning": FontKerning key = new FontKerning(); key.First = ParseInt(table, "first"); key.Second = ParseInt(table, "second"); key.Amount = ParseInt(table, "amount"); key.Description = string.Format("[{0}] [{1}] Amout: [{2}]", (char)key.First, (char)key.Second, key.Amount); font.Kernings.Add(key); break; } } return font; }