Browse Source

add headless fontmanager.

pull/2847/head
Dan Walmsley 6 years ago
parent
commit
0d1c691576
  1. 3
      src/Avalonia.Headless/AvaloniaHeadlessPlatform.cs
  2. 5
      src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs
  3. 88
      src/Avalonia.Headless/HeadlessPlatformStubs.cs

3
src/Avalonia.Headless/AvaloniaHeadlessPlatform.cs

@ -65,7 +65,8 @@ namespace Avalonia.Headless
.Bind<IKeyboardDevice>().ToConstant(new KeyboardDevice())
.Bind<IRenderLoop>().ToConstant(new RenderLoop())
.Bind<IRenderTimer>().ToConstant(new RenderTimer(60))
.Bind<IFontManagerImpl>().ToSingleton<HeadlessFontManagerStub>()
.Bind<ITextShaperImpl>().ToSingleton<HeadlessTextShaperStub>()
.Bind<IWindowingPlatform>().ToConstant(new HeadlessWindowingPlatform())
.Bind<PlatformHotkeyConfiguration>().ToSingleton<PlatformHotkeyConfiguration>();
}

5
src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs

@ -104,6 +104,11 @@ namespace Avalonia.Headless
public Rect GetRenderBounds(IPen pen)
{
if(pen is null)
{
return Bounds;
}
return Bounds.Inflate(pen.Thickness / 2);
}

88
src/Avalonia.Headless/HeadlessPlatformStubs.cs

@ -1,12 +1,18 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Controls.Platform;
using Avalonia.Input;
using Avalonia.Input.Platform;
using Avalonia.Media;
using Avalonia.Media.Fonts;
using Avalonia.Media.TextFormatting;
using Avalonia.Platform;
using Avalonia.Utility;
namespace Avalonia.Headless
{
@ -74,6 +80,88 @@ namespace Avalonia.Headless
}
}
class HeadlessGlyphTypefaceImpl : IGlyphTypefaceImpl
{
public short DesignEmHeight => 10;
public int Ascent => 5;
public int Descent => 5;
public int LineGap => 2;
public int UnderlinePosition => 5;
public int UnderlineThickness => 5;
public int StrikethroughPosition => 5;
public int StrikethroughThickness => 2;
public bool IsFixedPitch => true;
public void Dispose()
{
}
public ushort GetGlyph(uint codepoint)
{
return 1;
}
public int GetGlyphAdvance(ushort glyph)
{
return 1;
}
public int[] GetGlyphAdvances(ReadOnlySpan<ushort> glyphs)
{
return glyphs.ToArray().Select(x => (int)x).ToArray();
}
public ushort[] GetGlyphs(ReadOnlySpan<uint> codepoints)
{
return codepoints.ToArray().Select(x => (ushort)x).ToArray();
}
}
class HeadlessTextShaperStub : ITextShaperImpl
{
public GlyphRun ShapeText(ReadOnlySlice<char> text, TextFormat textFormat)
{
return new GlyphRun(new GlyphTypeface(new Typeface("Arial")), textFormat.FontRenderingEmSize,
new ReadOnlySlice<ushort>(new ushort[] { 1, 2, 3 }),
new ReadOnlySlice<double>(new double[] { 1, 2, 3 }),
new ReadOnlySlice<Vector>(new Vector[] { new Vector(1, 1), new Vector(2, 2), new Vector(3, 3) }),
text,
new ReadOnlySlice<ushort>(new ushort[] { 1, 2, 3 }));
}
}
class HeadlessFontManagerStub : IFontManagerImpl
{
public IGlyphTypefaceImpl CreateGlyphTypeface(Typeface typeface)
{
return new HeadlessGlyphTypefaceImpl();
}
public string GetDefaultFontFamilyName()
{
return "Arial";
}
public IEnumerable<string> GetInstalledFontFamilyNames(bool checkForUpdates = false)
{
return new List<string> { "Arial" };
}
public bool TryMatchCharacter(int codepoint, FontWeight fontWeight, FontStyle fontStyle, FontFamily fontFamily, CultureInfo culture, out FontKey fontKey)
{
fontKey = new FontKey("Arial", fontWeight, fontStyle);
return true;
}
}
class HeadlessIconLoaderStub : IPlatformIconLoader
{

Loading…
Cancel
Save