Kaydet (Commit) 2bad9f1c authored tarafından Takeshi Abe's avatar Takeshi Abe

tdf#103430 Apply mathvariant attribute to <mi> and <mo>

by emulating it with SmFontNode.
In case of <mo>, current implementation supports only the one named
with an alphabet.

Change-Id: I827a7e80f5aa94e243098a6e50eb758cf915c282
Reviewed-on: https://gerrit.libreoffice.org/31240Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTakeshi Abe <tabe@fixedpoint.jp>
üst 9abc547e
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mfrac>
<mrow>
<msup>
<mo form="prefix" rspace="0">d</mo>
<mn>2</mn>
</msup>
<mi mathvariant="normal" mathcolor="blue">y</mi>
</mrow>
<mrow>
<mo fontstyle="italic" fontweight="bold" mathvariant="normal" form="prefix" rspace="0">d</mo>
<mi fontfamily="serif" mathvariant="sans-serif-bold-italic" mathcolor="red">x</mi>
</mrow>
</mfrac>
</math>
...@@ -34,6 +34,7 @@ public: ...@@ -34,6 +34,7 @@ public:
void testMaction(); void testMaction();
void testMspace(); void testMspace();
void testtdf99556(); void testtdf99556();
void testTdf103430();
void testTdf103500(); void testTdf103500();
CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST_SUITE(Test);
...@@ -42,6 +43,7 @@ public: ...@@ -42,6 +43,7 @@ public:
CPPUNIT_TEST(testMaction); CPPUNIT_TEST(testMaction);
CPPUNIT_TEST(testMspace); CPPUNIT_TEST(testMspace);
CPPUNIT_TEST(testtdf99556); CPPUNIT_TEST(testtdf99556);
CPPUNIT_TEST(testTdf103430);
CPPUNIT_TEST(testTdf103500); CPPUNIT_TEST(testTdf103500);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
...@@ -122,10 +124,17 @@ void Test::testtdf99556() ...@@ -122,10 +124,17 @@ void Test::testtdf99556()
CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", sExpected, mxDocShell->GetText()); CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", sExpected, mxDocShell->GetText());
} }
void Test::testTdf103430()
{
loadURL(m_directories.getURLFromSrc("starmath/qa/extras/data/tdf103430.mml"));
CPPUNIT_ASSERT_EQUAL(OUString("{{nitalic d}^2 {nitalic {color blue y}}} over {{nitalic d} {font sans {bold {italic {color red x}}}}}"),
mxDocShell->GetText());
}
void Test::testTdf103500() void Test::testTdf103500()
{ {
loadURL(m_directories.getURLFromSrc("starmath/qa/extras/data/tdf103500.mml")); loadURL(m_directories.getURLFromSrc("starmath/qa/extras/data/tdf103500.mml"));
CPPUNIT_ASSERT_EQUAL(OUString("{{ int csub a csup b {1 over x ` d x}} = {intd csub a csup b {1 over y ` d y}}}"), CPPUNIT_ASSERT_EQUAL(OUString("{{ int csub a csup b {1 over x ` {nitalic d} x}} = {intd csub a csup b {1 over y ` {nitalic d} y}}}"),
mxDocShell->GetText()); mxDocShell->GetText());
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "mathmlattr.hxx" #include "mathmlattr.hxx"
#include <cassert> #include <cassert>
#include <unordered_map>
namespace { namespace {
...@@ -144,4 +145,38 @@ sal_Int32 ParseMathMLAttributeLengthValue(const OUString &rStr, MathMLAttributeL ...@@ -144,4 +145,38 @@ sal_Int32 ParseMathMLAttributeLengthValue(const OUString &rStr, MathMLAttributeL
return nIdx; return nIdx;
} }
bool GetMathMLMathvariantValue(const OUString &rStr, MathMLMathvariantValue *pV)
{
static const std::unordered_map<OUString, MathMLMathvariantValue, OUStringHash> aMap{
{"normal", MathMLMathvariantValue::Normal},
{"bold", MathMLMathvariantValue::Bold},
{"italic", MathMLMathvariantValue::Italic},
{"bold-italic", MathMLMathvariantValue::BoldItalic},
{"double-struck", MathMLMathvariantValue::DoubleStruck},
{"bold-fraktur", MathMLMathvariantValue::BoldFraktur},
{"script", MathMLMathvariantValue::Script},
{"bold-script", MathMLMathvariantValue::BoldScript},
{"fraktur", MathMLMathvariantValue::Fraktur},
{"sans-serif", MathMLMathvariantValue::SansSerif},
{"bold-sans-serif", MathMLMathvariantValue::BoldSansSerif},
{"sans-serif-italic", MathMLMathvariantValue::SansSerifItalic},
{"sans-serif-bold-italic", MathMLMathvariantValue::SansSerifBoldItalic},
{"monospace", MathMLMathvariantValue::Monospace},
{"initial", MathMLMathvariantValue::Initial},
{"tailed", MathMLMathvariantValue::Tailed},
{"looped", MathMLMathvariantValue::Looped},
{"stretched", MathMLMathvariantValue::Stretched}
};
assert(pV);
auto it = aMap.find(rStr);
if (it != aMap.end())
{
*pV = it->second;
return true;
}
return false;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
...@@ -47,6 +47,33 @@ struct MathMLAttributeLengthValue ...@@ -47,6 +47,33 @@ struct MathMLAttributeLengthValue
sal_Int32 ParseMathMLAttributeLengthValue(const OUString &rStr, MathMLAttributeLengthValue *pV); sal_Int32 ParseMathMLAttributeLengthValue(const OUString &rStr, MathMLAttributeLengthValue *pV);
// MathML 3: 3.2.2 Mathematics style attributes common to token elements
// <https://www.w3.org/TR/MathML3/chapter3.html#presm.commatt>
enum class MathMLMathvariantValue {
Normal,
Bold,
Italic,
BoldItalic,
DoubleStruck,
BoldFraktur,
Script,
BoldScript,
Fraktur,
SansSerif,
BoldSansSerif,
SansSerifItalic,
SansSerifBoldItalic,
Monospace,
Initial,
Tailed,
Looped,
Stretched
};
bool GetMathMLMathvariantValue(const OUString &rStr, MathMLMathvariantValue *pV);
#endif #endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
...@@ -286,7 +286,8 @@ enum SmXMLPresLayoutAttrTokenMap ...@@ -286,7 +286,8 @@ enum SmXMLPresLayoutAttrTokenMap
XML_TOK_FONTSIZE, XML_TOK_FONTSIZE,
XML_TOK_FONTFAMILY, XML_TOK_FONTFAMILY,
XML_TOK_COLOR, XML_TOK_COLOR,
XML_TOK_MATHCOLOR XML_TOK_MATHCOLOR,
XML_TOK_MATHVARIANT
}; };
......
...@@ -1710,6 +1710,8 @@ void SmAttributNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat) ...@@ -1710,6 +1710,8 @@ void SmAttributNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
void SmFontNode::CreateTextFromNode(OUString &rText) void SmFontNode::CreateTextFromNode(OUString &rText)
{ {
rText += "{";
switch (GetToken().eType) switch (GetToken().eType)
{ {
case TBOLD: case TBOLD:
...@@ -1823,6 +1825,9 @@ void SmFontNode::CreateTextFromNode(OUString &rText) ...@@ -1823,6 +1825,9 @@ void SmFontNode::CreateTextFromNode(OUString &rText)
} }
if(GetNumSubNodes() > 1) if(GetNumSubNodes() > 1)
GetSubNode(1)->CreateTextFromNode(rText); GetSubNode(1)->CreateTextFromNode(rText);
rText = comphelper::string::stripEnd(rText, ' ');
rText += "} ";
} }
void SmFontNode::Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell) void SmFontNode::Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment