Files
Pilz/Pilz.UI/Symbols/BaseSymbolFactory.cs
2025-11-16 08:46:56 +01:00

30 lines
1.1 KiB
C#

using System.Drawing;
using System.Reflection;
namespace Pilz.UI.Symbols;
public abstract class BaseSymbolFactory<TSymbols> : IBaseSymbolFactory<TSymbols>
{
public abstract string GetImageRessourcePath(TSymbols svgImage);
public abstract Assembly GetImageResourceAssembly();
protected virtual Size ResolveCommonSize(SymbolSize size)
{
return size switch
{
SymbolSize.Default => Size.Empty,
SymbolSize.Small => new Size((int)SymbolGlobals.DefaultImageSmallSize, (int)SymbolGlobals.DefaultImageSmallSize),
SymbolSize.Medium => new Size((int)SymbolGlobals.DefaultImageMediumSize, (int)SymbolGlobals.DefaultImageMediumSize),
SymbolSize.Large => new Size((int)SymbolGlobals.DefaultImageLargeSize, (int)SymbolGlobals.DefaultImageLargeSize),
_ => new Size((int)size, (int)size),
};
}
public virtual Stream? GetImageRessourceStream(TSymbols svgImage)
{
var asm = GetImageResourceAssembly();
var path = GetImageRessourcePath(svgImage);
return asm.GetManifestResourceStream(path);
}
}