public QFont(IFontRenderer renderer, Font font, QFontBuilderConfiguration config = null) : this(renderer) { if (config == null) config = new QFontBuilderConfiguration(); fontData = BuildFont(font, config, null); LoadTextures(fontData); if (config.ShadowConfig != null) Options.DropShadowActive = true; }
public static float MeasureText(string text, IFontRenderer font, IFontRenderer padFont, float scaleX, float xAdjust) { var cursor = 0; var length = 0f; var size = 32; while (cursor < text.Length) { var c = text[cursor]; if (c == '<') { var tag = Regex.Match(text.Substring(cursor), @"</?(\w+) ?(.*?)>").Value; var code = Regex.Match(tag, @"(?<=</?)\w+").Value; var isCloser = Regex.Match(tag, @"</\w+").Value.StartsWith("</"); switch (code) { case "SIZE": if (isCloser) { size = 46; } else { size = Convert.ToInt32(Regex.Match(tag, @"(?<= )\d+").Value); } break; case "ICON": var icon = Regex.Match(tag, @"(?<= )\w+").Value; var scale = size * 0.02173913043478260869565217391304f; length += padFont.GetCharWidthInfo('a').GlyphWidth *scale; break; } cursor += Regex.Match(text.Substring(cursor), @"</?(\w+) ?(.*?)>").Value.Length - 1; } else { length += font.GetCharWidthInfo(c).GlyphWidth *scaleX + xAdjust; } cursor++; } return(length); }
public void Render(IFontRenderer ren, string txt, float x, float y, float s) { s = s / _size; int lns = 0; using (StringReader sr = new StringReader(txt)) { string ln = null; while ((ln = sr.ReadLine()) != null) { float offset = 0; foreach (Glyph g in ln.Select(i => _map[i])) { ren.RenderChar(g.Texture, x + offset + g.Offset.X * s, y + (lns * _lineHeight * s) + g.Offset.Y * s, g.Size.X * s, g.Size.Y * s); offset += g.Spacing * s; } lns++; } } }
private QFont(IFontRenderer renderer) { this.renderer = renderer; }
internal QFont(IFontRenderer renderer, QFontData fontData) : this(renderer) { this.fontData = fontData; }
public QFont(IFontRenderer renderer, string fileName, float size, FontStyle style = FontStyle.Regular, QFontBuilderConfiguration config = null) { this.renderer = renderer; fontLoadDescription = new FontLoadDescription(fileName, size, style, config); LoadQFontFromFontFile(fontLoadDescription); }
public static QFont FromQFontFile(IFontRenderer renderer, string filePath, float downSampleFactor = 1.0f, QFontLoaderConfiguration loaderConfig = null) { QFont qfont = new QFont(renderer); qfont.fontLoadDescription = new FontLoadDescription(filePath,downSampleFactor,loaderConfig); qfont.LoadQFontFromQFontFile(qfont.fontLoadDescription); return qfont; }
public PlayerSlotRenderer(IFontRenderer fontRenderer) { this.fontRenderer = fontRenderer; }
public static TextWrappingResults WrapText(string text, IFontRenderer font, IFontRenderer padFont, RectangleF textBox, float scaleX, float xAdjust, string newLine = "\r\n") { if (text.Length == 0) { return(new TextWrappingResults()); } // Nav var cursor = 0; var wordStart = -1; var word = string.Empty; var line = string.Empty; var lineCount = 1; var result = string.Empty; while (cursor < text.Length) { var c = text[cursor]; // New Lines if (c == '\n') { // Render the current word if (word.Length > 0) { if (MeasureText(line + word, font, padFont, scaleX, xAdjust) <= textBox.Width) { line += word; } else // Next line { line += newLine; result += line; // Reset lineCount++; line = word; } wordStart = -1; word = string.Empty; } // Add the new line line += newLine; result += line; // Reset lineCount++; line = string.Empty; } // Spaces else if (Regex.IsMatch(c.ToString(), @"\s")) { // Render the current word if (word.Length > 0) { // Add the word and the space if they fit if (MeasureText(line + word + c, font, padFont, scaleX, xAdjust) <= textBox.Width) { line += word + c; } // Add the word if it fits else if (MeasureText(line + word, font, padFont, scaleX, xAdjust) <= textBox.Width) { line += word + newLine; result += line; // Reset lineCount++; line = string.Empty; } // Add a new line if nothing fits else { line += newLine; result += line; // Reset lineCount++; line = word + c; } wordStart = -1; word = string.Empty; } // Render the space else { if (MeasureText(line + c, font, padFont, scaleX, xAdjust) <= textBox.Width) { line += c; } else { line += newLine; result += line; // Reset lineCount++; line = c.ToString(); } } } // Tags else if (c == '<') { // Render the current word if (word.Length > 0) { // Add the word if it fits if (MeasureText(line + word, font, padFont, scaleX, xAdjust) <= textBox.Width) { line += word; } // Add a new line if nothing fits else { line += newLine; result += line; // Reset lineCount++; line = word + c; } wordStart = -1; word = string.Empty; } // Deal with the tag var tag = Regex.Match(text.Substring(cursor), @"</?(\w+) ?(.*?)>").Value; line += tag; cursor += tag.Length - 1; wordStart = -1; } // Words else { if (wordStart == -1) { wordStart = cursor; } word += c; // Single word exceeds line width if (MeasureText(word, font, padFont, scaleX, xAdjust) > textBox.Width) { // Might need to be just > for (var i = cursor; i > wordStart; i--) { word = word.Substring(0, i - wordStart); if (MeasureText(line + word, font, padFont, scaleX, xAdjust) <= textBox.Width) { cursor = i - 1; break; } } line += word + newLine; result += line; // Reset lineCount++; line = string.Empty; wordStart = -1; word = string.Empty; } // If the final word doesn't fit at the end of the line if (cursor == text.Length - 1 && MeasureText(line + word, font, padFont, scaleX, xAdjust) > textBox.Width) { line += newLine; result += line; // Reset lineCount++; line = string.Empty; } } cursor++; } // Add the final word/line line += word; result += line; return(new TextWrappingResults { Text = result, LineCount = lineCount }); }