Skip to content

Commit

Permalink
#92: extract common code from the RenderTo method
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Nov 28, 2017
1 parent 80ed8f7 commit f0507e6
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/WpfMath/OverUnderBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit f0507e6

Please sign in to comment.