Ejemplo n.º 1
0
 public TextLayoutGlyph(TextLayoutLine line, FontGlyph glyph, int index, float x)
 {
     this.line  = line;
     this.glyph = glyph;
     this.index = index;
     this.x     = x;
 }
Ejemplo n.º 2
0
        public TextLayout(string text, TextFont font, BoxAlignment alignment, StringTrimming trimming, Vector2 maxSize)
        {
            textLines = LineBreaker.Split(text, (int)Math.Ceiling(maxSize.X), c => font.GetGlyph(c).Width);

            var glyphIndex = 0;
            var width      = 0.0f;
            var height     = 0.0f;

            foreach (var textLine in textLines)
            {
                var line = new TextLayoutLine(this, height, alignment, lines.Count == 0);
                foreach (var c in textLine)
                {
                    line.Add(font.GetGlyph(c), glyphIndex++);
                }

                // trimming != StringTrimming.None &&
                //if (maxSize.Y > 0 && height + line.Height > maxSize.Y)
                //    break;

                lines.Add(line);
                width   = Math.Max(width, line.Width);
                height += line.Height;
            }

            if (lines.Count == 0)
            {
                lines.Add(new TextLayoutLine(this, 0, alignment, true));
            }
            var lastLine = lines[lines.Count - 1];

            if (lastLine.GlyphCount == 0)
            {
                height += font.LineHeight;
            }
            lastLine.Add(new FontGlyph(null, 0, font.LineHeight), glyphIndex++);

            size = new Vector2(width, height);
        }