Ejemplo 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);
            }
        }
    }
Ejemplo n.º 2
0
    private void MeasureVanilla(TigFont font,
                                TigTextStyle style,
                                ReadOnlySpan <char> text,
                                ref TigFontMetrics metrics)
    {
        if (metrics.width == 0 && text.Contains('\n'))
        {
            metrics.width = MeasureVanillaParagraph(font, style, text);
        }

        var largestHeight = font.FontFace.LargestHeight;

        if (metrics.width == 0)
        {
            metrics.width      = MeasureVanillaLine(font, style, text);
            metrics.height     = largestHeight;
            metrics.lines      = 1;
            metrics.lineheight = largestHeight;
            return;
        }

        metrics.lines = 1; // Default
        if (metrics.height != 0)
        {
            var maxLines = metrics.height / largestHeight;
            if (!(style.flags.HasFlag(TigTextStyleFlag.TTSF_TRUNCATE)))
            {
                maxLines++;
            }

            if (maxLines != 1)
            {
                metrics.lines = CountLinesVanilla(metrics.width, maxLines, text, font, style);
            }
        }
        else
        {
            if (!(style.flags.HasFlag(TigTextStyleFlag.TTSF_TRUNCATE)))
            {
                metrics.lines = CountLinesVanilla(metrics.width, 0, text, font, style);
            }
        }

        if (metrics.height == 0)
        {
            metrics.height  = metrics.lines * largestHeight;
            metrics.height -= -(font.FontFace.BaseLine - largestHeight);
        }

        metrics.lineheight = largestHeight;
    }
Ejemplo n.º 3
0
 public void Measure(TigFont font, TigTextStyle style, ReadOnlySpan <char> text, ref TigFontMetrics metrics)
 {
     // use the old font drawing algorithm
     MeasureVanilla(font, style, text, ref metrics);
 }