/// <summary> /// Sets the formatting for the given range of characters in the line /// </summary> public void SetFormatting(int start, int end, GlyphFormat format, bool onlyChangeColor) { Vector4 bbColor = QuadBoard.GetQuadBoardColor(format.Data.Item4); for (int n = start; n <= end; n++) { if (onlyChangeColor) { var quadBoard = glyphBoards[n]; quadBoard.bbColor = bbColor; glyphBoards[n] = quadBoard; formattedGlyphs[n] = new FormattedGlyph(formattedGlyphs[n].glyph, format); } else if (!formattedGlyphs[n].format.Equals(format)) { IFontStyle fontStyle = FontManager.GetFontStyle(format.Data.Item3); float scale = format.Data.Item2 * fontStyle.FontScale; Glyph glyph = fontStyle[chars[n]]; Vector2 glyphSize = new Vector2(glyph.advanceWidth, fontStyle.Height) * scale; formattedGlyphs[n] = new FormattedGlyph(glyph, format); locData[n] = new GlyphLocData(glyph.MatFrame.Material.size * scale, glyphSize); glyphBoards[n] = glyph.GetQuadBoard(format, bbColor); } } }
/// <summary> /// Builds a list of <see cref="Line.RichChar"/>s from RichString data. /// </summary> protected static void GetRichChars(RichStringMembers richString, Line charBuffer, bool allowSpecialChars) { StringBuilder text = richString.Item1; GlyphFormatMembers formatData = richString.Item2; Color lastColor = default(Color); Vector4 bbColor = default(Vector4); charBuffer.EnsureCapacity(charBuffer.Count + text.Length); for (int n = 0; n < text.Length; n++) { if (formatData.Item4 != lastColor) { lastColor = formatData.Item4; bbColor = QuadBoard.GetQuadBoardColor(formatData.Item4); } if (text[n] >= ' ' || allowSpecialChars && (text[n] == '\n' || text[n] == '\t')) { charBuffer.InsertNew(charBuffer.Chars.Count, text[n], new GlyphFormat(formatData), bbColor); } } }
/// <summary> /// Generates underlines for underlined text /// </summary> private void UpdateUnderlines() { int visRange = endLine - startLine; underlines.Clear(); underlines.EnsureCapacity(visRange); for (int ln = startLine; ln <= endLine; ln++) { Line line = lines[ln]; if (line.Count > 0) { GlyphFormatMembers?formatData = line.FormattedGlyphs[0].format.Data; int startCh = 0; for (int ch = 0; ch < lines[ln].Count; ch++) { GlyphFormatMembers?nextFormat = null; if (ch != line.Count - 1) { nextFormat = line.FormattedGlyphs[ch + 1].format.Data; } bool formatEqual = nextFormat != null && formatData.Value.Item1 == nextFormat.Value.Item1 && formatData.Value.Item2 == nextFormat.Value.Item2 && formatData.Value.Item3 == nextFormat.Value.Item3 && formatData.Value.Item4 == nextFormat.Value.Item4; if (!formatEqual) { if (((FontStyles)formatData.Value.Item3.Y & FontStyles.Underline) > 0) { GlyphLocData start = line.LocData[startCh], end = line.LocData[ch]; Vector2 pos = new Vector2 ( (start.bbOffset.X + end.bbOffset.X) * .5f, end.bbOffset.Y - (end.chSize.Y * .5f - (1f * formatData.Value.Item2)) ); Vector2 size = new Vector2 ( (end.bbOffset.X - start.bbOffset.X) + (end.chSize.X + start.chSize.X) * .5f, Math.Max((int)formatData.Value.Item2, 1) ); Vector4 color = QuadBoard.GetQuadBoardColor(formatData.Value.Item4) * .9f; underlines.Add(new UnderlineBoard(size, pos, color)); } startCh = ch; formatData = nextFormat; } } } } if (visRange > 9 && underlines.Capacity > 3 * underlines.Count && underlines.Capacity > visRange) { underlines.TrimExcess(); } }