add fontfamily

This commit is contained in:
bluepilledgreat 2024-10-24 22:58:23 +01:00
parent 88c47cabaa
commit 1985ae6c87

View File

@ -239,6 +239,14 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
string resourceName = text[1..^1]; string resourceName = text[1..^1];
return Strings.ResourceManager.GetStringSafe(resourceName); return Strings.ResourceManager.GetStringSafe(resourceName);
} }
private static string? GetSourcePath(CustomDialog dialog, string? sourcePath)
{
if (sourcePath == null)
return null;
return sourcePath.Replace("theme://", $"{dialog.ThemeDir}\\");
}
#endregion #endregion
#region Transformation Elements #region Transformation Elements
@ -401,8 +409,7 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
if (viewport is Rect) if (viewport is Rect)
imageBrush.Viewport = (Rect)viewport; imageBrush.Viewport = (Rect)viewport;
string sourcePath = GetXmlAttribute(xmlElement, "ImageSource"); string sourcePath = GetSourcePath(dialog, GetXmlAttribute(xmlElement, "ImageSource"))!;
sourcePath = sourcePath.Replace("theme://", $"{dialog.ThemeDir}\\");
if (sourcePath == "{Icon}") if (sourcePath == "{Icon}")
{ {
@ -618,6 +625,11 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
uiElement.FontSize = (double)fontSize; uiElement.FontSize = (double)fontSize;
uiElement.FontWeight = GetFontWeightFromXElement(xmlElement); uiElement.FontWeight = GetFontWeightFromXElement(xmlElement);
uiElement.FontStyle = GetFontStyleFromXElement(xmlElement); uiElement.FontStyle = GetFontStyleFromXElement(xmlElement);
// NOTE: font family can both be the name of the font or a uri
string? fontFamily = GetSourcePath(dialog, xmlElement.Attribute("FontFamily")?.Value);
if (fontFamily != null)
uiElement.FontFamily = new System.Windows.Media.FontFamily(fontFamily);
} }
private static UIElement HandleXmlElement_BloxstrapCustomBootstrapper(CustomDialog dialog, XElement xmlElement) private static UIElement HandleXmlElement_BloxstrapCustomBootstrapper(CustomDialog dialog, XElement xmlElement)
@ -830,6 +842,11 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
textBlock.IsHyphenationEnabled = ParseXmlAttribute<bool>(xmlElement, "IsHyphenationEnabled", false); textBlock.IsHyphenationEnabled = ParseXmlAttribute<bool>(xmlElement, "IsHyphenationEnabled", false);
textBlock.BaselineOffset = ParseXmlAttribute<double>(xmlElement, "BaselineOffset", double.NaN); textBlock.BaselineOffset = ParseXmlAttribute<double>(xmlElement, "BaselineOffset", double.NaN);
// NOTE: font family can both be the name of the font or a uri
string? fontFamily = GetSourcePath(dialog, xmlElement.Attribute("FontFamily")?.Value);
if (fontFamily != null)
textBlock.FontFamily = new System.Windows.Media.FontFamily(fontFamily);
object? padding = GetThicknessFromXElement(xmlElement, "Padding"); object? padding = GetThicknessFromXElement(xmlElement, "Padding");
if (padding != null) if (padding != null)
textBlock.Padding = (Thickness)padding; textBlock.Padding = (Thickness)padding;
@ -869,8 +886,7 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
image.Stretch = ParseXmlAttribute<Stretch>(xmlElement, "Stretch", Stretch.Uniform); image.Stretch = ParseXmlAttribute<Stretch>(xmlElement, "Stretch", Stretch.Uniform);
image.StretchDirection = ParseXmlAttribute<StretchDirection>(xmlElement, "StretchDirection", StretchDirection.Both); image.StretchDirection = ParseXmlAttribute<StretchDirection>(xmlElement, "StretchDirection", StretchDirection.Both);
string sourcePath = GetXmlAttribute(xmlElement, "Source"); string sourcePath = GetSourcePath(dialog, GetXmlAttribute(xmlElement, "Source"))!;
sourcePath = sourcePath.Replace("theme://", $"{dialog.ThemeDir}\\");
RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.HighQuality); // should this be modifiable by the user? RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.HighQuality); // should this be modifiable by the user?