using Avalonia;
using Avalonia.Headless;
using Avalonia.Media;
using DodoSSH.Client.App.Layout.Tests;
[assembly: AvaloniaTestApplication(typeof(HeadlessApp))]
namespace DodoSSH.Client.App.Layout.Tests;
///
/// Builds the real application for a headless renderer.
///
///
///
/// itself, not a stand-in, because the thing being measured is how the shipped
/// styles lay out — a harness with its own theme would measure a window nobody sees. Its
/// OnFrameworkInitializationCompleted only composes the object graph when the lifetime is a classic
/// desktop one, and a headless session's is not, so loading it here brings the Fluent theme and the dark
/// variant and starts no vault, no listener and no browser.
///
///
/// Skia rather than the headless drawing stub, which is the one deliberate cost in this file. The stub's
/// font manager returns invented glyph metrics, and text height is an input to every stacked panel in this
/// window — measuring against it would produce numbers that are self-consistent and unrelated to the
/// application. With Skia and the same Inter font the application registers, a measured height is the
/// height a user gets.
///
///
internal static class HeadlessApp
{
/// Found by name; is the contract.
///
///
/// The default family is named explicitly, because the paragraph above was describing an intention
/// rather than what happened. WithInterFont registers a font collection; it does not make it
/// the default. Avalonia resolves that from the platform — which is to say from whatever the machine
/// has installed — so a suite whose whole job is measuring text was measuring Segoe UI on a
/// developer's Windows and DejaVu on their Linux, and treating the two numbers as one.
///
///
/// On a machine with no fonts at all it does not merely differ, it stops: FontManager throws
/// "Default font family name can't be null or empty" during AppBuilder.SetupUnsafe, before any
/// test body runs. That is how a container CI runner reports all sixty-eight of these as failures with
/// not one assertion among them. Naming a font costs the runner nothing, because it travels inside the
/// package rather than on the host — true of Inter before this and of Montserrat now.
///
///
public static AppBuilder BuildAvaloniaApp() =>
AppBuilder.Configure()
.UseSkia()
.UseHeadless(new AvaloniaHeadlessPlatformOptions { UseHeadlessDrawing = false })
.WithInterFont()
.With(new FontManagerOptions
{
DefaultFamilyName = DefaultFamily,
FontFallbacks = [new FontFallback { FontFamily = new FontFamily(InterFamily) }],
});
/// The family Program.BuildAvaloniaApp asks the font manager to default to.
///
/// Kept in step with Program.BuildAvaloniaApp by hand, and it matters that they agree: a
/// harness pinning a different default from the one the application runs with would certify heights
/// for a window nobody sees, which is the failure the opening paragraph of this file is about. It was
/// Inter until the v3 design; now it is Montserrat, embedded the same way, and Inter moves down to
/// as the fallback both BuildAvaloniaApp methods name it as.
///
internal const string DefaultFamily = "avares://DodoSSH.Client.Shell/Assets/Fonts#Montserrat";
/// The family WithInterFont registers.
///
/// No longer the default — see — but still registered and still named
/// here, because it is still the fallback both heads' BuildAvaloniaApp fall back to, and a test
/// measuring a glyph Montserrat does not cover has to fall back to the same font the application does.
///
internal const string InterFamily = "avares://Avalonia.Fonts.Inter/Assets#Inter";
}