diff --git a/maui/src/Core/Extensions/CanvasExtensions.Windows.cs b/maui/src/Core/Extensions/CanvasExtensions.Windows.cs
index ac528be7..e68a2bf8 100644
--- a/maui/src/Core/Extensions/CanvasExtensions.Windows.cs
+++ b/maui/src/Core/Extensions/CanvasExtensions.Windows.cs
@@ -12,10 +12,38 @@
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
+using Windows.ApplicationModel;
+using Font = Microsoft.Maui.Font;
using Windows.UI.ViewManagement;
namespace Syncfusion.Maui.Toolkit.Graphics.Internals
{
+ ///
+ /// Provides helper methods for determining if the current application is running as a packaged app.
+ ///
+ ///
+ public static class PackagedAppHelper
+ {
+ ///
+ /// Gets or sets a value indicating whether the application is running as a packaged or unpackaged.
+ /// Returns `true` if the application is packaged, otherwise `false`.
+ ///
+ /// A boolean indicating if the application is packaged.
+ ///
+ public static bool IsPackaged()
+ {
+ try
+ {
+ var _ = Package.Current;
+ return true;
+ }
+ catch (InvalidOperationException)
+ {
+ return false;
+ }
+ }
+ }
+
///
/// Provides extension methods for the interface on the windows platfrom.
///
@@ -40,8 +68,7 @@ public static void DrawText(this ICanvas canvas, string value, float x, float y,
var font = textElement.Font;
if (fontManager != null)
{
- var fontFamily = fontManager.GetFontFamily(font);
- format.FontFamily = fontFamily.Source;
+ format.FontFamily = GetFontFamily(textElement, fontManager, font);
UpdateFontSize(textElement, format);
format.FontStyle = font.ToFontStyle();
format.FontWeight = font.ToFontWeight();
@@ -70,8 +97,7 @@ public static void DrawText(this ICanvas canvas, string value, Rect rect, Horizo
var font = textElement.Font;
if (fontManager != null)
{
- var fontFamily = fontManager.GetFontFamily(font);
- format.FontFamily = fontFamily.Source;
+ format.FontFamily = GetFontFamily(textElement, fontManager, font);
if (!double.IsNaN(textElement.FontSize))
{
UpdateFontSize(textElement, format);
@@ -108,6 +134,56 @@ public static void DrawText(this ICanvas canvas, string value, Rect rect, Horizo
}
}
+ ///
+ /// Get the font family of the font
+ ///
+ /// The text element
+ /// The font manager
+ /// The font
+ /// A string representing the local path or URI source of the font family. Defaults to "Segoe UI" if retrieval fails.
+ private static string GetFontFamily(ITextElement textElement, IFontManager fontManager, Font font)
+ {
+ string fontPath = string.Empty;
+
+ if (fontManager is null)
+ return "Segoe UI";
+
+ var fontFamily = fontManager.GetFontFamily(font);
+
+ if (fontFamily is null)
+ return "Segoe UI";
+
+ string path = fontFamily.Source;
+ string prefix = "ms-appx:///";
+ string fontName = path.StartsWith(prefix) ? path.Substring(prefix.Length) : path;
+
+ if (!string.IsNullOrEmpty(textElement.Font.Family))
+ {
+ try
+ {
+ fontPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{fontName}");
+ }
+ catch (Exception)
+ {
+ fontPath = string.Empty;
+ }
+ }
+
+ if (!string.IsNullOrEmpty(fontPath))
+ {
+ if (!PackagedAppHelper.IsPackaged())
+ {
+ return $@"{fontPath}";
+ }
+ else
+ {
+ return fontFamily.Source;
+ }
+ }
+
+ return "Segoe UI";
+ }
+
private static void UpdateFontSize(ITextElement textElement, CanvasTextFormat format)
{
var uiSettings = new UISettings();
diff --git a/maui/tests/Syncfusion.Maui.Toolkit.UnitTest/Navigation/SfTabViewUnitTests.cs b/maui/tests/Syncfusion.Maui.Toolkit.UnitTest/Navigation/SfTabViewUnitTests.cs
index 8e762572..a9d88cfd 100644
--- a/maui/tests/Syncfusion.Maui.Toolkit.UnitTest/Navigation/SfTabViewUnitTests.cs
+++ b/maui/tests/Syncfusion.Maui.Toolkit.UnitTest/Navigation/SfTabViewUnitTests.cs
@@ -3252,7 +3252,7 @@ public void TestVelocityValueCheck()
var value1 = GetPrivateField(horizontal, "_velocityX");
Assert.NotNull(value1);
double val = (double)value1;
- Assert.Equal(0.15658, Math.Round(val, 5));
+ Assert.Equal(0.15657, Math.Round(val, 5));
}
[Fact]
@@ -3850,4 +3850,4 @@ public string? SubName
}
}
}
-}
\ No newline at end of file
+}