I am using FormattedText to render text with a custom resource font in WPF, but for some strange reason, the custom font is being ignored in HiDPI mode. The same code is working fine in normal DPI.
Here is a sample of my code, where BasicPoint and BasicColor are generic classes because I'm doing rendering on multiple platforms:
public void DrawText(string text, BasicPoint point, BasicColor color, string fontFace, float fontSize)
{
var formattedText = new FormattedText(text, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, new Typeface(fontFace), fontSize, new SolidColorBrush(GenericControlHelper.ToColor(color)));
_context.DrawText(formattedText, GenericControlHelper.ToPoint(point));
}
For example, here are the values passed to this method:
text: "Hello World"
point: (0, 0)
color: (255, 255, 255)
fontFace: "Roboto Light"
fontSize: 12
This font has been added to the project as a TTF and as a Resource. I usually refer to it successfully in XAML as such:
<TextBlock x:Name="lblLoopName" Text="{Binding Path=Name}" Margin="0" Padding="0,2,4,2" Foreground="Black" FontSize="11" FontFamily="/Resources/Fonts/#Roboto Regular" PreviewMouseDown="lblLoopName_OnPreviewMouseDown" />
I remind you that using FormattedText works fine without HiDPI, it is only defaulting to Arial in HiDPI.
Thanks for any help on this one, I've been looking for the solution for a long time!