Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/avalonia' into avalonia
Browse files Browse the repository at this point in the history
  • Loading branch information
jgcodes2020 committed Nov 8, 2023
2 parents c76f486 + 9f34c41 commit 6a292dc
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions M64RPFW.ViewModels/Scripting/LuaEnvironment_D2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private void DrawText(float x, float y, float right, float bottom, float red, fl

// Cache laid-out text blocks. Unfortunately, I have to key with
// colour, though I wish I didn't need to.
// FIXME: Caching produced collisions, so it was disabled
var cacheKey = new TextLayoutParameters(
MaxWidth: right - x,
MaxHeight: bottom - y,
Expand All @@ -110,35 +111,31 @@ private void DrawText(float x, float y, float right, float bottom, float red, fl
HorizontalAlignment: horizontalAlignment,
Color: SkiaExtensions.ColorFromFloats(red, green, blue, alpha)
);
var block = _textLayoutCache.GetOrAdd(cacheKey, key =>

var block = new TextBlock
{
MaxWidth = cacheKey.MaxWidth,
Alignment = cacheKey.HorizontalAlignment switch
{
0 => TextAlignment.Left,
1 => TextAlignment.Right,
2 => TextAlignment.Center,
_ => throw new ArgumentException("Invalid horizontal alignment")
},
};
block.AddText(text, new Style
{
var block = new TextBlock
FontFamily = cacheKey.FontName,
FontSize = cacheKey.FontSize,
FontWeight = cacheKey.FontWeight,
FontItalic = cacheKey.FontStyle switch
{
MaxWidth = key.MaxWidth,
Alignment = key.HorizontalAlignment switch
{
0 => TextAlignment.Left,
1 => TextAlignment.Right,
2 => TextAlignment.Center,
_ => throw new ArgumentException("Invalid horizontal alignment")
},
};
block.AddText(text, new Style
{
FontFamily = key.FontName,
FontSize = key.FontSize,
FontWeight = key.FontWeight,
FontItalic = key.FontStyle switch
{
0 => false,
1 => true,
2 => true, // oblique != italic sometimes, but oh well
_ => throw new ArgumentException("Invalid font italic")
},
TextColor = key.Color
}
);
return block;
0 => false,
1 => true,
2 => true, // oblique != italic sometimes, but oh well
_ => throw new ArgumentException("Invalid font italic")
},
TextColor = cacheKey.Color
}
);

Expand Down

0 comments on commit 6a292dc

Please sign in to comment.