Image size: Italic support [PATCH]

Bug #1046669 reported by Marc Palmans
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
WPF-Math
New
Undecided
Unassigned

Bug Description

Image size is incorrectly calculated when using italic.
I'm not sure if this patch 100% correct but it seems to work for the samples I tested.

diff --git a/WpfMath/Box.cs b/WpfMath/Box.cs
index 59311b4..17e0006 100644
--- a/WpfMath/Box.cs
+++ b/WpfMath/Box.cs
@@ -54,6 +54,17 @@ namespace WpfMath
             get { return this.Height + this.Depth; }
         }

+ public double TotalWidth
+ {
+ get { return this.Width + this.Italic; }
+ }
+
+ public double Italic
+ {
+ get;
+ set;
+ }
+
         public double Width
         {
             get;
@@ -84,7 +95,7 @@ namespace WpfMath
             {
                 // Fill background of box with color.
                 drawingContext.DrawRectangle(this.Background, null, new Rect(x * scale, (y - Height) * scale,
- this.Width * scale, (this.Height + this.Depth) * scale));
+ (this.Width + this.Italic) * scale, (this.Height + this.Depth) * scale));
             }
         }

diff --git a/WpfMath/CharBox.cs b/WpfMath/CharBox.cs
index 0e3d877..66d6ce4 100644
--- a/WpfMath/CharBox.cs
+++ b/WpfMath/CharBox.cs
@@ -17,6 +17,7 @@ namespace WpfMath
             this.Width = charInfo.Metrics.Width;
             this.Height = charInfo.Metrics.Height;
             this.Depth = charInfo.Metrics.Depth;
+ this.Italic = charInfo.Metrics.Italic;
         }

         public CharInfo Character
diff --git a/WpfMath/HorizontalBox.cs b/WpfMath/HorizontalBox.cs
index bf049d1..7b69ae1 100644
--- a/WpfMath/HorizontalBox.cs
+++ b/WpfMath/HorizontalBox.cs
@@ -59,6 +59,7 @@ namespace WpfMath
             this.Width = Math.Max(this.Width, childBoxesTotalWidth);
             this.Height = Math.Max((this.Children.Count == 0 ? double.NegativeInfinity : Height), box.Height - box.Shift);
             this.Depth = Math.Max((this.Children.Count == 0 ? double.NegativeInfinity : Depth), box.Depth + box.Shift);
+ this.Italic = Math.Max((this.Children.Count == 0 ? double.NegativeInfinity : Italic), box.Italic);
         }

         public override void Draw(DrawingContext drawingContext, double scale, double x, double y)
diff --git a/WpfMath/TexRenderer.cs b/WpfMath/TexRenderer.cs
index fa2d7d7..b00cbf2 100644
--- a/WpfMath/TexRenderer.cs
+++ b/WpfMath/TexRenderer.cs
@@ -33,7 +33,7 @@ namespace WpfMath
         {
             get
             {
- return new Size(this.Box.Width * this.Scale, this.Box.TotalHeight * this.Scale);
+ return new Size(this.Box.TotalWidth * this.Scale, this.Box.TotalHeight * this.Scale);
             }
         }

Revision history for this message
Friedrich von Never (friedrich-v) wrote :

Hello, Marc!

Your patch has been merged into a project fork: https://github.com/ForNeVeR/wpf-math/pull/16

Thank you!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.