Exemplo n.º 1
0
    private void LayoutAndDrawVanilla(
        Span <char> text,
        TigFont font,
        ref Rectangle extents,
        TigTextStyle style)
    {
        var extentsWidth  = extents.Width;
        var extentsHeight = extents.Height;

        if (extentsWidth == 0)
        {
            var metrics = new TigFontMetrics();
            metrics.width  = extents.Width;
            metrics.height = extents.Height;
            Tig.Fonts.Measure(style, text, ref metrics);

            extents.Width  = metrics.width;
            extents.Height = metrics.height;
            extentsWidth   = metrics.width;
            extentsHeight  = metrics.height;
        }

        if ((style.flags & (TigTextStyleFlag.TTSF_BACKGROUND | TigTextStyleFlag.TTSF_BORDER)) != 0)
        {
            var rect = new Rectangle(
                extents.X,
                extents.Y,
                Math.Max(extentsWidth, extents.Width),
                Math.Max(extentsHeight, extents.Height)
                );
            DrawBackgroundOrOutline(rect, style);
        }

        var iterator = new LayoutRunIterator(text, font, extents, style);

        while (iterator.MoveToNextRun(out var run))
        {
            if (run.Truncated)
            {
                _renderer.RenderRun(
                    "...",
                    run.X,
                    run.Y,
                    run.Bounds,
                    style,
                    font);
            }
            else
            {
                _renderer.RenderRun(
                    text.Slice(run.Start, run.End - run.Start),
                    run.X,
                    run.Y,
                    run.Bounds,
                    style,
                    font);
            }
        }
    }