summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--starmath/qa/extras/data/maction.mml10
-rw-r--r--starmath/qa/extras/mmlimport-test.cxx9
-rw-r--r--starmath/source/mathmlimport.cxx70
-rw-r--r--starmath/source/mathmlimport.hxx6
4 files changed, 89 insertions, 6 deletions
diff --git a/starmath/qa/extras/data/maction.mml b/starmath/qa/extras/data/maction.mml
new file mode 100644
index 000000000000..3650087999a1
--- /dev/null
+++ b/starmath/qa/extras/data/maction.mml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<math xmlns="http://www.w3.org/1998/Math/MathML">
+ <mrow>
+ <mtable>
+ <mtr><maction actiontype="toggle"><mn>1</mn><mn>0</mn><mn>0</mn></maction></mtr>
+ <mtr><maction actiontype="toggle" selection="2"><mn>0</mn><mn>2</mn><mn>0</mn></maction></mtr>
+ <mtr><maction actiontype="toggle" selection="3"><mn>0</mn><mn>0</mn><mn>3</mn></maction></mtr>
+ </mtable>
+ </mrow>
+</math>
diff --git a/starmath/qa/extras/mmlimport-test.cxx b/starmath/qa/extras/mmlimport-test.cxx
index 2fbeda7928dc..adf80aabf7b2 100644
--- a/starmath/qa/extras/mmlimport-test.cxx
+++ b/starmath/qa/extras/mmlimport-test.cxx
@@ -30,9 +30,11 @@ public:
virtual void tearDown() SAL_OVERRIDE;
void testSimple();
+ void testMaction();
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testSimple);
+ CPPUNIT_TEST(testMaction);
CPPUNIT_TEST_SUITE_END();
private:
@@ -83,6 +85,13 @@ void Test::testSimple()
loadURL(getURLFromSrc("starmath/qa/extras/data/simple.mml"));
}
+void Test::testMaction()
+{
+ loadURL(getURLFromSrc("starmath/qa/extras/data/maction.mml"));
+ OUString sExpected("matrix {italic \"1\" ## italic \"2\" ## italic \"3\"}");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", sExpected, mxDocShell->GetText());
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}
diff --git a/starmath/source/mathmlimport.cxx b/starmath/source/mathmlimport.cxx
index 488797ebdc76..8a42bafe7091 100644
--- a/starmath/source/mathmlimport.cxx
+++ b/starmath/source/mathmlimport.cxx
@@ -1756,12 +1756,16 @@ public:
class SmXMLActionContext_Impl : public SmXMLRowContext_Impl
{
+ size_t mnSelection; // 1-based
+
public:
SmXMLActionContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
const OUString& rLName) :
SmXMLRowContext_Impl(rImport,nPrefix,rLName)
+ , mnSelection(1)
{}
+ void StartElement(const uno::Reference<xml::sax::XAttributeList> &xAttrList) SAL_OVERRIDE;
void EndElement() SAL_OVERRIDE;
};
@@ -1957,6 +1961,13 @@ static const SvXMLTokenMapEntry aColorTokenMap[] =
XML_TOKEN_MAP_END
};
+static const SvXMLTokenMapEntry aActionAttrTokenMap[] =
+{
+ { XML_NAMESPACE_MATH, XML_SELECTION, XML_TOK_SELECTION },
+ XML_TOKEN_MAP_END
+};
+
+
const SvXMLTokenMap& SmXMLImport::GetPresLayoutElemTokenMap()
{
if (!pPresLayoutElemTokenMap)
@@ -2022,6 +2033,12 @@ const SvXMLTokenMap& SmXMLImport::GetColorTokenMap()
return *pColorTokenMap;
}
+const SvXMLTokenMap& SmXMLImport::GetActionAttrTokenMap()
+{
+ if (!pActionAttrTokenMap)
+ pActionAttrTokenMap = new SvXMLTokenMap(aActionAttrTokenMap);
+ return *pActionAttrTokenMap;
+}
SvXMLImportContext *SmXMLDocContext_Impl::CreateChildContext(
@@ -2589,18 +2606,58 @@ void SmXMLMultiScriptsContext_Impl::EndElement()
ProcessSubSupPairs(bHasPrescripts);
}
-void SmXMLActionContext_Impl::EndElement()
+void SmXMLActionContext_Impl::StartElement(const uno::Reference<xml::sax::XAttributeList> & xAttrList)
{
- /*For now we will just assume that the
- selected attribute is one, and then just display
- that expression alone, i.e. remove all expect the
- first pushed one*/
+ sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
+ for (sal_Int16 i=0;i<nAttrCount;i++)
+ {
+ OUString sAttrName = xAttrList->getNameByIndex(i);
+ OUString aLocalName;
+ sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
+ GetKeyByAttrName(sAttrName,&aLocalName);
+ OUString sValue = xAttrList->getValueByIndex(i);
+ const SvXMLTokenMap &rAttrTokenMap =
+ GetSmImport().GetActionAttrTokenMap();
+ switch(rAttrTokenMap.Get(nPrefix,aLocalName))
+ {
+ case XML_TOK_SELECTION:
+ {
+ sal_uInt32 n = sValue.toUInt32();
+ if (n > 0) mnSelection = static_cast<size_t>(n);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+void SmXMLActionContext_Impl::EndElement()
+{
SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
- for (auto i=rNodeStack.size()-nElementCount;i > 1;i--)
+ auto nSize = rNodeStack.size();
+ if (nSize <= nElementCount) {
+ // not compliant to maction's specification, e.g., no subexpressions
+ return;
+ }
+ assert(mnSelection > 0);
+ if (nSize < nElementCount + mnSelection) {
+ // No selected subexpression exists, which is a MathML error;
+ // fallback to selecting the first
+ mnSelection = 1;
+ }
+ assert(nSize >= nElementCount + mnSelection);
+ for (auto i=nSize-(nElementCount+mnSelection); i > 0; i--)
+ {
+ rNodeStack.pop_front();
+ }
+ auto pSelected = rNodeStack.pop_front();
+ for (auto i=rNodeStack.size()-nElementCount; i > 0; i--)
{
rNodeStack.pop_front();
}
+ rNodeStack.push_front(pSelected.release());
}
SvXMLImportContext *SmXMLImport::CreateContext(sal_uInt16 nPrefix,
@@ -2858,6 +2915,7 @@ SmXMLImport::~SmXMLImport() throw ()
delete pColorTokenMap;
delete pOperatorAttrTokenMap;
delete pAnnotationAttrTokenMap;
+ delete pActionAttrTokenMap;
}
void SmXMLImport::SetViewSettings(const Sequence<PropertyValue>& aViewProps)
diff --git a/starmath/source/mathmlimport.hxx b/starmath/source/mathmlimport.hxx
index 0a1e700759c2..c46742b899f9 100644
--- a/starmath/source/mathmlimport.hxx
+++ b/starmath/source/mathmlimport.hxx
@@ -80,6 +80,7 @@ class SmXMLImport : public SvXMLImport
SvXMLTokenMap *pPresScriptEmptyElemTokenMap;
SvXMLTokenMap *pPresTableElemTokenMap;
SvXMLTokenMap *pColorTokenMap;
+ SvXMLTokenMap *pActionAttrTokenMap;
SmNodeStack aNodeStack;
bool bSuccess;
@@ -241,6 +242,7 @@ public:
const SvXMLTokenMap &GetPresScriptEmptyElemTokenMap();
const SvXMLTokenMap &GetPresTableElemTokenMap();
const SvXMLTokenMap &GetColorTokenMap();
+ const SvXMLTokenMap &GetActionAttrTokenMap();
SmNodeStack & GetNodeStack() { return aNodeStack; }
SmNode *GetTree()
@@ -339,6 +341,10 @@ enum SmXMLAnnotationAttrTokenMap
XML_TOK_ENCODING
};
+enum SmXMLActionAttrTokenMap
+{
+ XML_TOK_SELECTION
+};
#endif