From cd34b6db1f87bb8bd001e230aba2b47b488149d5 Mon Sep 17 00:00:00 2001 From: Thor181 Date: Tue, 12 Mar 2024 22:38:46 +0700 Subject: [PATCH] fix: alignment in matrix by baseline --- src/WpfMath/Fonts/WpfSystemFont.cs | 2 +- src/XamlMath.Shared/Atoms/MatrixAtom.cs | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/WpfMath/Fonts/WpfSystemFont.cs b/src/WpfMath/Fonts/WpfSystemFont.cs index 91a21afa..b7bfdea6 100644 --- a/src/WpfMath/Fonts/WpfSystemFont.cs +++ b/src/WpfMath/Fonts/WpfSystemFont.cs @@ -155,6 +155,6 @@ private static TeXFontMetrics GetFontMetrics(char c, Typeface typeface) var scalingFactor = typeface.FontFamily.LineSpacing / typeface.FontFamily.Baseline; height /= scalingFactor; - return new TeXFontMetrics(formattedText.Width, height, depth, 0, 1.0); + return new TeXFontMetrics(formattedText.Width, height, 0, 0, 1.0); } } diff --git a/src/XamlMath.Shared/Atoms/MatrixAtom.cs b/src/XamlMath.Shared/Atoms/MatrixAtom.cs index 2a163a50..b9168e74 100644 --- a/src/XamlMath.Shared/Atoms/MatrixAtom.cs +++ b/src/XamlMath.Shared/Atoms/MatrixAtom.cs @@ -65,14 +65,25 @@ protected override Box CreateBoxCore(TexEnvironment environment) var vFreeSpace = rowHeight - cell.TotalHeight; var tbGap = (VerticalPadding + vFreeSpace) / 2; + var cellContainer = new VerticalBox(); - cellContainer.Add(new StrutBox(0.0, tbGap, 0.0, 0.0)); - cellContainer.Add(cell); - cellContainer.Add(new StrutBox(0.0, tbGap, 0.0, 0.0)); + + if (cell.TotalHeight <= 0.54) + { + cellContainer.Add(new StrutBox(0.0, vFreeSpace, 0.0, 0.0)); + cellContainer.Add(cell); + cellContainer.Add(new StrutBox(0.0, VerticalPadding / 2, 0.0, 0.0)); + } + else + { + cellContainer.Add(new StrutBox(0.0, tbGap, 0.0, 0.0)); + cellContainer.Add(cell); + cellContainer.Add(new StrutBox(0.0, tbGap, 0.0, 0.0)); + } + cellContainer.Height = cellContainer.TotalHeight; cellContainer.Depth = 0; - var hFreeSpace = columnWidth - cell.TotalWidth; var (lGap, rGap) = GetLeftRightGap(hFreeSpace, j); rowContainer.Add(new StrutBox(lGap, 0.0, 0.0, 0.0));