using RioJoy.Core.Overlay;

namespace RioJoy.Core.Tests.Overlay;

/// <summary>
/// Deterministic fake <see cref="ITextMeasurer"/> for layout tests: width grows
/// linearly with character count and font size, height with font size. Lets the
/// font-fit and placement math be asserted exactly without a real font/rasterizer.
/// </summary>
internal sealed class LinearTextMeasurer : ITextMeasurer
{
    private readonly double _charWidthPerPx;
    private readonly double _heightPerPx;

    public LinearTextMeasurer(double charWidthPerPx = 0.6, double heightPerPx = 1.2)
    {
        _charWidthPerPx = charWidthPerPx;
        _heightPerPx = heightPerPx;
    }

    public TextExtent Measure(string text, string fontFamily, double fontSizePx) =>
        new(text.Length * fontSizePx * _charWidthPerPx, fontSizePx * _heightPerPx);
}
