From f0507e6371d2677f25c279b667e67abd0dd52ccf Mon Sep 17 00:00:00 2001 From: Friedrich von Never Date: Tue, 28 Nov 2017 23:27:51 +0700 Subject: [PATCH] #92: extract common code from the RenderTo method --- src/WpfMath/OverUnderBox.cs | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/WpfMath/OverUnderBox.cs b/src/WpfMath/OverUnderBox.cs index 76d46c0c..de1e6534 100644 --- a/src/WpfMath/OverUnderBox.cs +++ b/src/WpfMath/OverUnderBox.cs @@ -66,34 +66,26 @@ public override void RenderTo(IElementRenderer renderer, double x, double y) var translationX = x + DelimeterBox.Width / 2; var translationY = centerY + DelimeterBox.Width / 2; - var transforms = new Transform[] - { - new TranslateTransform(translationX, translationY), - new RotateTransform(90) - }; - - renderer.RenderTransformed( - DelimeterBox, - transforms, - -DelimeterBox.Width / 2, - -DelimeterBox.Depth + DelimeterBox.Width / 2); + RenderDelimiter(centerY, translationX, translationY); // Draw script box as superscript. - if (ScriptBox != null) - { - renderer.RenderElement(ScriptBox, x, centerY - Kern - ScriptBox.Depth); - } + RenderScriptBox(centerY - Kern - ScriptBox.Depth); } else { - // TODO[F]: It seems like this could be generalized with the block above. The only differences are - // translationY and the ScriptBox's Y position? - // Draw delimeter and script boxes under base box. var centerY = y + BaseBox.Depth + DelimeterBox.Width; var translationX = x + DelimeterBox.Width / 2; var translationY = centerY - DelimeterBox.Width / 2; + RenderDelimiter(centerY, translationX, translationY); + + // Draw script box as subscript. + RenderScriptBox(centerY + Kern + ScriptBox.Height); + } + + void RenderDelimiter(double centerY, double translationX, double translationY) + { var transforms = new Transform[] { new TranslateTransform(translationX, translationY), @@ -105,11 +97,13 @@ public override void RenderTo(IElementRenderer renderer, double x, double y) transforms, -DelimeterBox.Width / 2, -DelimeterBox.Depth + DelimeterBox.Width / 2); + } - // Draw script box as subscript. + void RenderScriptBox(double yPosition) + { if (ScriptBox != null) { - renderer.RenderElement(ScriptBox, x, centerY + Kern + ScriptBox.Height); + renderer.RenderElement(ScriptBox, x, yPosition); } } }