Switch to RichEdit math mode in EquationTextBox (#672)
* Use RichEdit Math Mode * Add comment Co-Authored-By: Stephanie Anderl <46726333+sanderl@users.noreply.github.com>
This commit is contained in:
committed by
Stephanie Anderl
parent
41fbcfe9c5
commit
b2dd55a64f
@@ -9,6 +9,9 @@ using namespace Windows::UI::Xaml;
|
||||
|
||||
namespace GraphControl
|
||||
{
|
||||
// Remove mml: formatting specific to RichEditBox control, which is not understood by the graph engine.
|
||||
static constexpr wstring_view s_mathPrefix = L"mml:";
|
||||
|
||||
DependencyProperty^ Equation::s_expressionProperty;
|
||||
static constexpr auto s_propertyName_Expression = L"Expression";
|
||||
|
||||
@@ -74,7 +77,7 @@ namespace GraphControl
|
||||
ss << GetRequestHeader()
|
||||
<< GetExpression()
|
||||
<< GetLineColor()
|
||||
<< L")";
|
||||
<< L"</mfenced></mrow>";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
@@ -82,19 +85,28 @@ namespace GraphControl
|
||||
wstring Equation::GetRequestHeader()
|
||||
{
|
||||
wstring expr{ Expression->Data() };
|
||||
if (expr.find(L"=") != wstring::npos)
|
||||
if (expr.find(L">=<") != wstring::npos)
|
||||
{
|
||||
return L"plotEq2d("s;
|
||||
return L"<mrow><mi>plotEq2d</mi><mfenced separators=\"\">"s;
|
||||
}
|
||||
else
|
||||
{
|
||||
return L"plot2d("s;
|
||||
return L"<mrow><mi>plot2d</mi><mfenced separators=\"\">"s;
|
||||
}
|
||||
}
|
||||
|
||||
wstring Equation::GetExpression()
|
||||
{
|
||||
return Expression->Data();
|
||||
wstring mathML = Expression->Data();
|
||||
|
||||
size_t mathPrefix = 0;
|
||||
while ((mathPrefix = mathML.find(s_mathPrefix, mathPrefix)) != std::string::npos)
|
||||
{
|
||||
mathML.replace(mathPrefix, s_mathPrefix.length(), L"");
|
||||
mathPrefix += s_mathPrefix.length();
|
||||
}
|
||||
|
||||
return mathML;
|
||||
}
|
||||
|
||||
wstring Equation::GetLineColor()
|
||||
|
@@ -55,7 +55,7 @@ namespace GraphControl
|
||||
: m_solver{ IMathSolver::CreateMathSolver() }
|
||||
, m_graph{ m_solver->CreateGrapher() }
|
||||
{
|
||||
m_solver->ParsingOptions().SetFormatType(FormatType::Linear);
|
||||
m_solver->ParsingOptions().SetFormatType(FormatType::MathML);
|
||||
|
||||
DefaultStyleKey = StringReference(s_defaultStyleKey);
|
||||
|
||||
@@ -365,20 +365,20 @@ namespace GraphControl
|
||||
if (!validEqs.empty())
|
||||
{
|
||||
wstringstream ss{};
|
||||
ss << L"show2d(";
|
||||
ss << L"<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow><mi>show2d</mi><mfenced separators=\"\">";
|
||||
|
||||
int numValidEquations = 0;
|
||||
for (Equation^ eq : validEqs)
|
||||
{
|
||||
if (numValidEquations++ > 0)
|
||||
{
|
||||
ss << L",";
|
||||
ss << L"<mo>,</mo>";
|
||||
}
|
||||
|
||||
ss << eq->GetRequest();
|
||||
}
|
||||
|
||||
ss << L")";
|
||||
ss << L"</mfenced></mrow></math>";
|
||||
|
||||
wstring request = ss.str();
|
||||
unique_ptr<IExpression> graphExpression;
|
||||
|
@@ -42,7 +42,7 @@
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
<AppContainerApplication>true</AppContainerApplication>
|
||||
<ApplicationType>Windows Store</ApplicationType>
|
||||
<WindowsTargetPlatformVersion Condition="'$(WindowsTargetPlatformVersion)' == ''">10.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion Condition="'$(WindowsTargetPlatformVersion)' == ''">10.0.18970.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformMinVersion>10.0.18362.0</WindowsTargetPlatformMinVersion>
|
||||
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
|
||||
</PropertyGroup>
|
||||
|
Reference in New Issue
Block a user