Skip to content
Permalink
Browse files

[Fonts] Fix how matrix is computed and compute realVirtualResolutionR…

…atio depending on actual requestedFontSize (fixes #314) (fixes #364)
  • Loading branch information
xen2 committed Oct 22, 2019
1 parent e8c8e4a commit eafa92f99d5978316b9394f4c3d4e25ae8a1b5d0
Showing with 11 additions and 5 deletions.
  1. +11 −5 sources/engine/Xenko.Graphics/SpriteFont.cs
@@ -263,10 +263,12 @@ internal void InternalUIDrawGlyph(ref InternalUIDrawCommand parameters, ref Vect
if (char.IsWhiteSpace((char)glyph.Character))
return;

var realVirtualResolutionRatio = requestedFontSize / parameters.RequestedFontSize;

// Skip items with null size
var elementSize = new Vector2(
auxiliaryScaling.X * glyph.Subrect.Width / parameters.RealVirtualResolutionRatio.X,
auxiliaryScaling.Y * glyph.Subrect.Height / parameters.RealVirtualResolutionRatio.Y);
auxiliaryScaling.X * glyph.Subrect.Width / realVirtualResolutionRatio.X,
auxiliaryScaling.Y * glyph.Subrect.Height / realVirtualResolutionRatio.Y);
if (elementSize.Length() < MathUtil.ZeroTolerance)
return;

@@ -277,20 +279,24 @@ internal void InternalUIDrawGlyph(ref InternalUIDrawCommand parameters, ref Vect
xShift = (float)Math.Round(xShift);
yShift = (float)Math.Round(yShift);
}
var xScaledShift = xShift / parameters.RealVirtualResolutionRatio.X;
var yScaledShift = yShift / parameters.RealVirtualResolutionRatio.Y;
var xScaledShift = xShift / realVirtualResolutionRatio.X;
var yScaledShift = yShift / realVirtualResolutionRatio.Y;

var worldMatrix = parameters.Matrix;

worldMatrix.M41 += worldMatrix.M11 * xScaledShift + worldMatrix.M21 * yScaledShift;
worldMatrix.M42 += worldMatrix.M12 * xScaledShift + worldMatrix.M22 * yScaledShift;
worldMatrix.M43 += worldMatrix.M13 * xScaledShift + worldMatrix.M23 * yScaledShift;

worldMatrix.M44 += worldMatrix.M14 * xScaledShift + worldMatrix.M24 * yScaledShift;

worldMatrix.M11 *= elementSize.X;
worldMatrix.M12 *= elementSize.X;
worldMatrix.M13 *= elementSize.X;
worldMatrix.M14 *= elementSize.X;
worldMatrix.M21 *= elementSize.Y;
worldMatrix.M22 *= elementSize.Y;
worldMatrix.M23 *= elementSize.Y;
worldMatrix.M24 *= elementSize.Y;

RectangleF sourceRectangle = glyph.Subrect;
parameters.Batch.DrawCharacter(Textures[glyph.BitmapIndex], ref worldMatrix, ref sourceRectangle, ref parameters.Color, parameters.DepthBias, swizzle);

0 comments on commit eafa92f

Please sign in to comment.
You can’t perform that action at this time.