Пример #1
0
        public override void OnRender(Media.DrawingContext dc)
        {
            if (_lineCache == null || _lineCache.Count == 0)
            {
                return;
            }

            int nLines = _lineCache.Count;
            int top = 0;

            int width, height;
            GetRenderSize(out width, out height);

            // Draw each line of Text
            //
            int lineNumber = _currentLine;
            while (lineNumber < nLines)
            {
                TextLine line = (TextLine)_lineCache[lineNumber];
                if (top + line.Height > height)
                {
                    break;
                }

                TextRun[] runs = line.Runs;

                int x;
                switch (_alignment)
                {
                    case TextAlignment.Left:
                        x = 0;
                        break;

                    case TextAlignment.Center:
                        x = (width - line.Width) >> 1; // >> 1 is the same as div by 2
                        break;

                    case TextAlignment.Right:
                        x = width - line.Width;
                        break;

                    default:
                        throw new NotSupportedException();
                }

                for (int i = 0; i < runs.Length; i++)
                {
                    TextRun run = runs[i];
                    int w, h;
                    run.GetSize(out w, out h);
                    int y = top + line.Baseline - run.Font.Ascent;
                    dc.DrawText(run.Text, run.Font, run.ForeColor, x, y);
                    x += w;
                }

                top += line.Height;
                lineNumber++;
            }
        }