/// <summary> /// Measures fancy notated text strings. /// Note: Do not include newlines! /// </summary> /// <param name="line">The text to measure</param> /// <param name="set">The FontSet to get fonts from</param> /// <returns>the X-width of the text</returns> public static float MeasureFancyText(string line, FontSet set) { bool bold = false; bool italic = false; bool sub = false; float MeasWidth = 0; GLFont font = set.font_default; int start = 0; line = line.Replace("^q", "\""); for (int x = 0; x < line.Length; x++) { if ((line[x] == '^' && x + 1 < line.Length && IsColorSymbol(line[x + 1])) || (x + 1 == line.Length)) { string drawme = line.Substring(start, (x - start) + ((x + 1 < line.Length) ? 0 : 1)); start = x + 2; x++; if (drawme.Length > 0) { MeasWidth += font.MeasureString(drawme); } if (x < line.Length) { switch (line[x]) { case 'r': font = set.font_default; bold = false; sub = false; italic = false; break; case 'S': case 'l': font = bold && italic ? set.font_bolditalichalf : bold ? set.font_boldhalf : italic ? set.font_italichalf : set.font_half; sub = true; break; case 'i': italic = true; font = (sub) ? (bold ? set.font_bolditalichalf : set.font_italichalf) : (bold ? set.font_bolditalic : set.font_italic); break; case 'b': bold = true; font = (sub) ? (italic ? set.font_bolditalichalf : set.font_boldhalf) : (italic ? set.font_bolditalic : set.font_bold); break; default: break; } } } } return(MeasWidth); }
/// <summary> /// Prepares the FontSet system. /// </summary> public static void Init() { Standard = new FontSet("standard"); Standard.Load(GLFont.Standard.Name, GLFont.Standard.Size); Fonts.Add(Standard); SlightlyBigger = new FontSet("slightlybigger"); SlightlyBigger.Load(GLFont.Standard.Name, GLFont.Standard.Size + 5); Fonts.Add(SlightlyBigger); }
public static Location MeasureFancyLinesOfText(string text, FontSet set) { string[] data = text.Split('\n'); float len = 0; for (int i = 0; i < data.Length; i++) { float newlen = MeasureFancyText(data[i], set); if (newlen > len) { len = newlen; } } return(new Location(len, data.Length * set.font_default.Height, 0)); }
/// <summary> /// Gets a font by a specified name. /// </summary> /// <param name="fontname">The name of the font</param> /// <param name="fontsize">The size of the font</param> /// <returns>The specified font</returns> public static FontSet GetFont(string fontname, int fontsize) { string namelow = fontname.ToLower(); for (int i = 0; i < Fonts.Count; i++) { if (Fonts[i].font_default.Size == fontsize && Fonts[i].Name == namelow) { return(Fonts[i]); } } FontSet toret = new FontSet(fontname); toret.Load(fontname, fontsize); Fonts.Add(toret); return(toret); }