[Libreoffice-commits] core.git: starmath/inc starmath/source
Frédéric Wang
fred.wang at free.fr
Fri Jun 28 02:56:56 PDT 2013
starmath/inc/node.hxx | 16 +++++++++++++++-
starmath/source/mathmlexport.cxx | 24 +++++++++++++++++++++++-
starmath/source/mathtype.cxx | 1 +
starmath/source/node.cxx | 1 +
starmath/source/ooxmlexport.cxx | 4 ++--
starmath/source/parse.cxx | 32 ++++++++++++++++++--------------
starmath/source/rtfexport.cxx | 4 ++--
starmath/source/visitors.cxx | 2 +-
starmath/source/wordexportbase.cxx | 1 +
9 files changed, 64 insertions(+), 21 deletions(-)
New commits:
commit 43cf39adff66d20862956869d11fbcc184eb5702
Author: Frédéric Wang <fred.wang at free.fr>
Date: Thu Jun 27 21:35:28 2013 +0200
fdo#66088 Export some math symbols as <mi> elements.
Change-Id: Ib08717c3d4d41abc7bce4cd6bc2e63bda7db6086
Reviewed-on: https://gerrit.libreoffice.org/4595
Reviewed-by: Fridrich Strba <fridrich at documentfoundation.org>
Tested-by: Fridrich Strba <fridrich at documentfoundation.org>
diff --git a/starmath/inc/node.hxx b/starmath/inc/node.hxx
index b1640a3..2416d6e 100644
--- a/starmath/inc/node.hxx
+++ b/starmath/inc/node.hxx
@@ -73,7 +73,7 @@ enum SmNodeType
/*10*/ NBINDIAGONAL, NSUBSUP, NMATRIX, NPLACE, NTEXT,
/*15*/ NSPECIAL, NGLYPH_SPECIAL, NMATH, NBLANK, NERROR,
/*20*/ NLINE, NEXPRESSION, NPOLYLINE, NROOT, NROOTSYMBOL,
-/*25*/ NRECTANGLE, NVERTICAL_BRACE
+/*25*/ NRECTANGLE, NVERTICAL_BRACE, NMATHIDENT
};
@@ -579,6 +579,20 @@ public:
void Accept(SmVisitor* pVisitor);
};
+////////////////////////////////////////////////////////////////////////////////
+
+/** Math Identifier
+ *
+ * This behaves essentially the same as SmMathSymbolNode and is only used to
+ * represent math symbols that should be exported as <mi> elements rather than
+ * <mo> elements.
+ */
+class SmMathIdentifierNode : public SmMathSymbolNode
+{
+public:
+ SmMathIdentifierNode(const SmToken &rNodeToken)
+ : SmMathSymbolNode(NMATHIDENT, rNodeToken) {}
+};
////////////////////////////////////////////////////////////////////////////////
diff --git a/starmath/source/mathmlexport.cxx b/starmath/source/mathmlexport.cxx
index d23662c..fb1e6c3 100644
--- a/starmath/source/mathmlexport.cxx
+++ b/starmath/source/mathmlexport.cxx
@@ -871,7 +871,26 @@ void SmXMLExport::ExportTable(const SmNode *pNode, int nLevel)
void SmXMLExport::ExportMath(const SmNode *pNode, int /*nLevel*/)
{
const SmMathSymbolNode *pTemp = static_cast<const SmMathSymbolNode *>(pNode);
- SvXMLElementExport aMath(*this, XML_NAMESPACE_MATH, XML_MO, sal_True, sal_False);
+ SvXMLElementExport *pMath = 0;
+
+ if (pNode->GetType() == NMATH)
+ {
+ // Export NMATH symbols as <mo> elements
+ pMath = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MO, sal_True, sal_False);
+ }
+ else
+ {
+ // Export NMATHIDENT and NPLACE symbols as <mi> elements:
+ // - These math symbols should not be drawn slanted. Hence we should
+ // attach a mathvariant="normal" attribute to single-char <mi> elements
+ // that are not mathematical alphanumeric symbol. For simplicity and to
+ // work around browser limitations, we always attach such an attribute.
+ // - The MathML specification suggests to use empty <mi> elements as
+ // placeholders but they won't be visible in most MathML rendering
+ // engines so let's use an empty square for NPLACE instead.
+ AddAttribute(XML_NAMESPACE_MATH, XML_MATHVARIANT, XML_NORMAL);
+ pMath = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MI, sal_True, sal_False);
+ }
sal_Unicode nArse[2];
nArse[0] = pTemp->GetText()[0];
sal_Unicode cTmp = ConvertMathToMathML( nArse[0] );
@@ -880,6 +899,8 @@ void SmXMLExport::ExportMath(const SmNode *pNode, int /*nLevel*/)
OSL_ENSURE(nArse[0] != 0xffff,"Non existent symbol");
nArse[1] = 0;
GetDocHandler()->characters(nArse);
+
+ delete pMath;
}
void SmXMLExport::ExportText(const SmNode *pNode, int /*nLevel*/)
@@ -1520,6 +1541,7 @@ void SmXMLExport::ExportNodes(const SmNode *pNode, int nLevel)
}
}
break;
+ case NMATHIDENT :
case NPLACE:
ExportMath(pNode, nLevel);
break;
diff --git a/starmath/source/mathtype.cxx b/starmath/source/mathtype.cxx
index 8b958a1..3de5817 100644
--- a/starmath/source/mathtype.cxx
+++ b/starmath/source/mathtype.cxx
@@ -1997,6 +1997,7 @@ sal_uInt8 MathType::HandleNodes(SmNode *pNode,int nLevel)
}
break;
case NMATH:
+ case NMATHIDENT:
HandleMath(pNode,nLevel);
break;
case NSUBSUP:
diff --git a/starmath/source/node.cxx b/starmath/source/node.cxx
index d3ae705..ccfc4b0 100644
--- a/starmath/source/node.cxx
+++ b/starmath/source/node.cxx
@@ -621,6 +621,7 @@ void SmNode::DumpAsDot(std::ostream &out, OUString* label, int number, int& id,
case NROOTSYMBOL: out<<"SmRootSymbolNode"; break;
case NRECTANGLE: out<<"SmRectangleNode"; break;
case NVERTICAL_BRACE: out<<"SmVerticalBraceNode"; break;
+ case NMATHIDENT: out<<"SmMathIdentifierNode"; break;
default:
out<<"Unknown Node";
}
diff --git a/starmath/source/ooxmlexport.cxx b/starmath/source/ooxmlexport.cxx
index 3cbdf45..c7ab7ff 100644
--- a/starmath/source/ooxmlexport.cxx
+++ b/starmath/source/ooxmlexport.cxx
@@ -236,7 +236,7 @@ void SmOoxmlExport::HandleRoot( const SmRootNode* pNode, int nLevel )
static OString mathSymbolToString( const SmNode* node )
{
- assert( node->GetType() == NMATH );
+ assert( node->GetType() == NMATH || node->GetType() == NMATHIDENT );
const SmTextNode* txtnode = static_cast< const SmTextNode* >( node );
assert( txtnode->GetText().getLength() == 1 );
sal_Unicode chr = SmTextNode::ConvertSymbolToUnicode( txtnode->GetText()[0] );
@@ -463,7 +463,7 @@ void SmOoxmlExport::HandleBrace( const SmBraceNode* pNode, int nLevel )
for( int i = 0; i < body->GetNumSubNodes(); ++i )
{
const SmNode* subnode = body->GetSubNode( i );
- if( subnode->GetType() == NMATH )
+ if (subnode->GetType() == NMATH || subnode->GetType() == NMATHIDENT)
{ // do not write, but write what separator it is
const SmMathSymbolNode* math = static_cast< const SmMathSymbolNode* >( subnode );
if( !separatorWritten )
diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx
index cdb6865..4477d10 100644
--- a/starmath/source/parse.cxx
+++ b/starmath/source/parse.cxx
@@ -1485,24 +1485,10 @@ void SmParser::Term(bool bGroupNumberIdent)
case TRIGHTARROW :
case TUPARROW :
case TDOWNARROW :
- case TSETN :
- case TSETZ :
- case TSETQ :
- case TSETR :
- case TSETC :
- case THBAR :
- case TLAMBDABAR :
case TCIRC :
case TDRARROW :
case TDLARROW :
case TDLRARROW :
- case TBACKEPSILON :
- case TALEPH :
- case TIM :
- case TRE :
- case TWP :
- case TEMPTYSET :
- case TINFINITY :
case TEXISTS :
case TNOTEXISTS :
case TFORALL :
@@ -1519,6 +1505,24 @@ void SmParser::Term(bool bGroupNumberIdent)
NextToken();
break;
+ case TSETN :
+ case TSETZ :
+ case TSETQ :
+ case TSETR :
+ case TSETC :
+ case THBAR :
+ case TLAMBDABAR :
+ case TBACKEPSILON :
+ case TALEPH :
+ case TIM :
+ case TRE :
+ case TWP :
+ case TEMPTYSET :
+ case TINFINITY :
+ m_aNodeStack.push(new SmMathIdentifierNode(m_aCurToken));
+ NextToken();
+ break;
+
case TPLACE:
m_aNodeStack.push(new SmPlaceNode(m_aCurToken));
NextToken();
diff --git a/starmath/source/rtfexport.cxx b/starmath/source/rtfexport.cxx
index fd6f6d0..9dffbcf 100644
--- a/starmath/source/rtfexport.cxx
+++ b/starmath/source/rtfexport.cxx
@@ -179,7 +179,7 @@ void SmRtfExport::HandleRoot(const SmRootNode* pNode, int nLevel)
namespace {
OString mathSymbolToString(const SmNode* node, rtl_TextEncoding nEncoding)
{
- assert(node->GetType() == NMATH);
+ assert(node->GetType() == NMATH || node->GetType() == NMATHIDENT);
const SmTextNode* txtnode = static_cast<const SmTextNode*>(node);
if (txtnode->GetText().isEmpty())
return OString();
@@ -403,7 +403,7 @@ void SmRtfExport::HandleBrace(const SmBraceNode* pNode, int nLevel)
for (int i = 0; i < body->GetNumSubNodes(); ++i)
{
const SmNode* subnode = body->GetSubNode(i);
- if (subnode->GetType() == NMATH)
+ if (subnode->GetType() == NMATH || subnode->GetType() == NMATHIDENT)
{ // do not write, but write what separator it is
const SmMathSymbolNode* math = static_cast<const SmMathSymbolNode*>(subnode);
if(!separatorWritten)
diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx
index fc0ffc8..91032b2 100644
--- a/starmath/source/visitors.cxx
+++ b/starmath/source/visitors.cxx
@@ -115,7 +115,7 @@ void SmVisitorTest::Visit( SmGlyphSpecialNode* pNode )
void SmVisitorTest::Visit( SmMathSymbolNode* pNode )
{
- OSL_ENSURE( pNode->GetType( ) == NMATH, "the visitor-patterns isn't implemented correctly" );
+ OSL_ENSURE( pNode->GetType( ) == NMATH || pNode->GetType( ) == NMATHIDENT, "the visitor-patterns isn't implemented correctly" );
VisitChildren( pNode );
}
diff --git a/starmath/source/wordexportbase.cxx b/starmath/source/wordexportbase.cxx
index 0a7a6b8..f0df05c 100644
--- a/starmath/source/wordexportbase.cxx
+++ b/starmath/source/wordexportbase.cxx
@@ -65,6 +65,7 @@ void SmWordExportBase::HandleNode( const SmNode* pNode, int nLevel )
break;
}
case NMATH:
+ case NMATHIDENT:
HandleMath(pNode,nLevel);
break;
case NSUBSUP:
More information about the Libreoffice-commits
mailing list