summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@suse.cz>2012-07-25 18:20:17 +0200
committerMiklos Vajna <vmiklos@suse.cz>2012-07-26 09:44:16 +0200
commit4f08fcb8e337f79f1282966bf726f82ddadf24a3 (patch)
tree63117dc93947f1219eaa07003aa15d5338ac3260 /starmath
parent189ad9186cb905ff9830319fd86be4e183a30be4 (diff)
export RTF_MSSU{B,P} and related keywords
Change-Id: Ida24beda4d961db068279e81711e10c3d87b0ac1
Diffstat (limited to 'starmath')
-rw-r--r--starmath/source/rtfexport.cxx119
1 files changed, 115 insertions, 4 deletions
diff --git a/starmath/source/rtfexport.cxx b/starmath/source/rtfexport.cxx
index 32c441a70d30..2031fe05c876 100644
--- a/starmath/source/rtfexport.cxx
+++ b/starmath/source/rtfexport.cxx
@@ -86,6 +86,9 @@ void SmRtfExport::HandleNode(const SmNode* pNode, int nLevel)
case NMATH:
HandleMath(pNode, nLevel);
break;
+ case NSUBSUP:
+ HandleSubSupScript(static_cast<const SmSubSupNode*>(pNode), nLevel);
+ break;
case NEXPRESSION:
HandleAllSubNodes(pNode, nLevel);
break;
@@ -381,14 +384,122 @@ void SmRtfExport::HandleOperator(const SmOperNode* pNode, int nLevel)
}
}
-void SmRtfExport::HandleSubSupScript(const SmSubSupNode* /*pNode*/, int /*nLevel*/)
+void SmRtfExport::HandleSubSupScript(const SmSubSupNode* pNode, int nLevel)
{
- SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC);
+ // set flags to a bitfield of which sub/sup items exists
+ int flags = (pNode->GetSubSup(CSUB) ? (1 << CSUB) : 0)
+ | (pNode->GetSubSup(CSUP) ? (1 << CSUP) : 0)
+ | (pNode->GetSubSup(RSUB) ? (1 << RSUB) : 0)
+ | (pNode->GetSubSup(RSUP) ? (1 << RSUP) : 0)
+ | (pNode->GetSubSup(LSUB) ? (1 << LSUB) : 0)
+ | (pNode->GetSubSup(LSUP) ? (1 << LSUP) : 0);
+ HandleSubSupScriptInternal(pNode, nLevel, flags);
}
-void SmRtfExport::HandleSubSupScriptInternal(const SmSubSupNode* /*pNode*/, int /*nLevel*/, int /*flags*/)
+void SmRtfExport::HandleSubSupScriptInternal(const SmSubSupNode* pNode, int nLevel, int flags)
{
- SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC);
+// rtf supports only a certain combination of sub/super scripts, but LO can have any,
+// so try to merge it using several tags if necessary
+ if (flags == 0) // none
+ return;
+ if ((flags & (1 << RSUP | 1 << RSUB)) == (1 << RSUP | 1 << RSUB))
+ { // m:sSubSup
+ m_pBuffer->append("{\\msSubSup ");
+ m_pBuffer->append("{\\me ");
+ flags &= ~(1 << RSUP | 1 << RSUB);
+ if (flags == 0)
+ HandleNode(pNode->GetBody(), nLevel + 1);
+ else
+ HandleSubSupScriptInternal(pNode, nLevel, flags);
+ m_pBuffer->append("}"); // me
+ m_pBuffer->append("{\\msub ");
+ HandleNode(pNode->GetSubSup(RSUB), nLevel + 1);
+ m_pBuffer->append("}"); // msub
+ m_pBuffer->append("{\\msup ");
+ HandleNode(pNode->GetSubSup(RSUP ), nLevel + 1);
+ m_pBuffer->append("}"); // msup
+ m_pBuffer->append("}"); // msubSup
+ }
+ else if ((flags & (1 << RSUB)) == 1 << RSUB)
+ { // m:sSub
+ m_pBuffer->append("{\\msSub ");
+ m_pBuffer->append("{\\me ");
+ flags &= ~(1 << RSUB);
+ if (flags == 0)
+ HandleNode(pNode->GetBody(), nLevel + 1);
+ else
+ HandleSubSupScriptInternal(pNode, nLevel, flags);
+ m_pBuffer->append("}"); // me
+ m_pBuffer->append("{\\msub ");
+ HandleNode(pNode->GetSubSup(RSUB), nLevel + 1);
+ m_pBuffer->append("}"); // msub
+ m_pBuffer->append("}"); // msSub
+ }
+ else if ((flags & (1 << RSUP)) == 1 << RSUP)
+ { // m:sSup
+ m_pBuffer->append("{\\msSup ");
+ m_pBuffer->append("{\\me ");
+ flags &= ~(1 << RSUP);
+ if (flags == 0)
+ HandleNode(pNode->GetBody(), nLevel + 1);
+ else
+ HandleSubSupScriptInternal(pNode, nLevel, flags);
+ m_pBuffer->append("}"); // me
+ m_pBuffer->append("{\\msup ");
+ HandleNode(pNode->GetSubSup(RSUP), nLevel + 1);
+ m_pBuffer->append("}"); // msup
+ m_pBuffer->append("}"); // msSup
+ }
+ else if ((flags & (1 << LSUP | 1 << LSUB)) == (1 << LSUP | 1 << LSUB))
+ { // m:sPre
+ m_pBuffer->append("{\\msPre ");
+ m_pBuffer->append("{\\msub ");
+ HandleNode(pNode->GetSubSup(LSUB ), nLevel + 1);
+ m_pBuffer->append("}"); // msub
+ m_pBuffer->append("{\\msup ");
+ HandleNode(pNode->GetSubSup(LSUP), nLevel + 1);
+ m_pBuffer->append("}"); // msup
+ m_pBuffer->append("{\\me ");
+ flags &= ~(1 << LSUP | 1 << LSUB);
+ if (flags == 0)
+ HandleNode(pNode->GetBody(), nLevel + 1);
+ else
+ HandleSubSupScriptInternal(pNode, nLevel, flags);
+ m_pBuffer->append("}"); // me
+ m_pBuffer->append("}"); // msPre
+ }
+ else if ((flags & (1 << CSUB)) == (1 << CSUB))
+ { // m:limLow looks like a good element for central superscript
+ m_pBuffer->append("{\\mlimLow ");
+ m_pBuffer->append("{\\me ");
+ flags &= ~(1 << CSUB);
+ if (flags == 0)
+ HandleNode(pNode->GetBody(), nLevel + 1);
+ else
+ HandleSubSupScriptInternal(pNode, nLevel, flags);
+ m_pBuffer->append("}"); // me
+ m_pBuffer->append("{\\mlim ");
+ HandleNode(pNode->GetSubSup(CSUB), nLevel + 1);
+ m_pBuffer->append("}"); // mlim
+ m_pBuffer->append("}"); // mlimLow
+ }
+ else if ((flags & (1 << CSUP)) == (1 << CSUP))
+ { // m:limUpp looks like a good element for central superscript
+ m_pBuffer->append("{\\mlimUpp ");
+ m_pBuffer->append("{\\me ");
+ flags &= ~(1 << CSUP);
+ if (flags == 0)
+ HandleNode(pNode->GetBody(), nLevel + 1);
+ else
+ HandleSubSupScriptInternal(pNode, nLevel, flags);
+ m_pBuffer->append("}"); // me
+ m_pBuffer->append("{\\mlim ");
+ HandleNode(pNode->GetSubSup(CSUP), nLevel + 1);
+ m_pBuffer->append("}"); // mlim
+ m_pBuffer->append("}"); // mlimUpp
+ }
+ else
+ SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC << " unhandled subsup type");
}
void SmRtfExport::HandleMatrix(const SmMatrixNode* pNode, int nLevel)