mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-01 17:47:24 +02:00
* [Dependency] source generator No more reflection, no more codegen at runtime Also various changes to Roslyn helpers to make this easier to write. Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback. No fallback is available for [field: Dependency] properties, due to a Roslyn bug. Code Fixes exist. We love Roslyn * Apply dependencies generator changes to all code * Release notes * Preprocessor got hands * Handle nullable dependencies These are bad but gotta deal with it. * Apply suggestions from code review Co-authored-by: Moony <moony@hellomouse.net> * Fine, let's not use collection expressions --------- Co-authored-by: Moony <moony@hellomouse.net>
90 lines
2.8 KiB
C#
90 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Robust.Client.Graphics.FontManagement;
|
|
using Robust.Shared;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Log;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Robust.Client.Graphics;
|
|
|
|
/// <summary>
|
|
/// Implementation of <see cref="ISystemFontManager"/> that proxies to platform-specific implementations,
|
|
/// and adds additional logging.
|
|
/// </summary>
|
|
internal sealed partial class SystemFontManager : ISystemFontManagerInternal, IPostInjectInit
|
|
{
|
|
[Dependency] private IFontManagerInternal _fontManager = default!;
|
|
[Dependency] private ILogManager _logManager = default!;
|
|
[Dependency] private IConfigurationManager _cfg = default!;
|
|
|
|
private ISawmill _sawmill = default!;
|
|
|
|
private ISystemFontManagerInternal _implementation = default!;
|
|
|
|
public bool IsSupported => _implementation.IsSupported;
|
|
public IEnumerable<ISystemFontFace> SystemFontFaces => _implementation.SystemFontFaces;
|
|
|
|
public void Initialize()
|
|
{
|
|
_implementation = GetImplementation();
|
|
_sawmill.Verbose($"Using {_implementation.GetType()}");
|
|
|
|
_sawmill.Debug("Initializing system font manager implementation");
|
|
try
|
|
{
|
|
var sw = RStopwatch.StartNew();
|
|
_implementation.Initialize();
|
|
_sawmill.Debug($"Done initializing system font manager in {sw.Elapsed}");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
// This is a non-critical engine system that has to parse significant amounts of external data.
|
|
// Best to fail gracefully to avoid full startup failures.
|
|
|
|
_sawmill.Error($"Error while initializing system font manager, resorting to fallback: {e}");
|
|
_implementation = new SystemFontManagerFallback();
|
|
}
|
|
}
|
|
|
|
public void Shutdown()
|
|
{
|
|
_sawmill.Verbose("Shutting down system font manager");
|
|
|
|
try
|
|
{
|
|
_implementation.Shutdown();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_sawmill.Error($"Exception shutting down system font manager: {e}");
|
|
return;
|
|
}
|
|
|
|
_sawmill.Verbose("Successfully shut down system font manager");
|
|
}
|
|
|
|
private ISystemFontManagerInternal GetImplementation()
|
|
{
|
|
if (!_cfg.GetCVar(CVars.FontSystem))
|
|
return new SystemFontManagerFallback();
|
|
|
|
#if WINDOWS
|
|
return new SystemFontManagerDirectWrite(_logManager, _cfg, _fontManager);
|
|
#elif FREEDESKTOP
|
|
return new SystemFontManagerFontconfig(_logManager, _fontManager);
|
|
#elif MACOS
|
|
return new SystemFontManagerCoreText(_logManager, _fontManager);
|
|
#else
|
|
return new SystemFontManagerFallback();
|
|
#endif
|
|
}
|
|
|
|
void IPostInjectInit.PostInject()
|
|
{
|
|
_sawmill = _logManager.GetSawmill("font.system");
|
|
// _sawmill.Level = LogLevel.Verbose;
|
|
}
|
|
}
|