Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested solution #484 #485

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Suggested solution #484 #485

wants to merge 2 commits into from

Conversation

Thor181
Copy link
Contributor

@Thor181 Thor181 commented Mar 12, 2024

No description provided.

@ForNeVeR
Copy link
Owner

Your current solution yields the following result for a simple matrix \matrix{x & y \\ z & y}:
image

As you can see, y is lifted.

I would prefer something like this:
image
(with better following the vertical free space, though)

This view has been achieved using the following patch (apply on top of your current changes):

Index: src/XamlMath.Shared/Atoms/MatrixAtom.cs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/XamlMath.Shared/Atoms/MatrixAtom.cs b/src/XamlMath.Shared/Atoms/MatrixAtom.cs
--- a/src/XamlMath.Shared/Atoms/MatrixAtom.cs	(revision Staged)
+++ b/src/XamlMath.Shared/Atoms/MatrixAtom.cs	(date 1710274735726)
@@ -56,33 +56,25 @@
         foreach (var row in cells)
         {
             var rowContainer = new HorizontalBox();
-            var rowHeight = row.Length > 0 ? row.Max(cell => cell.TotalHeight) : 0.0;
+            var rowHeight = row.Length > 0 ? row.Max(cell => cell.Height) : 0.0;
 
             for (var j = 0; j < columnCount; ++j)
             {
                 var cell = row[j];
                 var columnWidth = columnWidths[j];
 
-                var vFreeSpace = rowHeight - cell.TotalHeight;
+                var vFreeSpace = rowHeight - cell.Height;
                 var tbGap = (VerticalPadding + vFreeSpace) / 2;
 
                 var cellContainer = new VerticalBox();
+                var depth = cell.Depth;
 
-                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.Add(new StrutBox(0.0, tbGap, 0.0, 0.0));
+                cellContainer.Add(cell);
+                cellContainer.Add(new StrutBox(0.0, tbGap - depth, 0.0, 0.0));
 
-                cellContainer.Height = cellContainer.TotalHeight;
-                cellContainer.Depth = 0;
+                cellContainer.Height = cell.Height;
+                cellContainer.Depth = cell.Depth;
 
                 var hFreeSpace = columnWidth - cell.TotalWidth;
                 var (lGap, rGap) = GetLeftRightGap(hFreeSpace, j);

Could you please investigate this patch and try applying it?

@@ -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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you reverted this? It seems wrong: it will stop preserving the "depth" of the system font characters. Example:
image
(see how the selection box is wrong now)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your solution doesn't solve the problem. In addition, it breaks other types of matrices.
image
image

Why have you reverted this? It seems wrong: it will stop preserving the "depth" of the system font characters.

Because the letters overhang is under the baseline. If an alignment by the baseline, then the overhang must be below the baseline (seems logic). Otherwise a characters will be above the required line (in this case will be need substract depth at boxes placing - it is also seems logic 🤔).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants