Re: bafna_p - r31561 - in abiword/branches/gsoc2012math/plugins/openxml: common/xp exp/xp

Jean Brefort <[email protected]>
Newsgroups gmane.editors.abiword.devel
Message-ID <[email protected]>
Hi Prashant,

Nice work! We now can export equations to docx, and import them back!

Cheers,
Jean

Le mercredi 25 juillet 2012 à 16:44 +0200, [email protected] a écrit :
> Author: bafna_p
> Date: 2012-07-25 16:44:25 +0200 (Wed, 25 Jul 2012)
> New Revision: 31561
> 
> Modified:
>    abiword/branches/gsoc2012math/plugins/openxml/common/xp/OXML_Element_Math.cpp
>    abiword/branches/gsoc2012math/plugins/openxml/common/xp/OXML_Element_Math.h
>    abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML.cpp
>    abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML.h
>    abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML_Listener.cpp
>    abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML_Listener.h
> Log:
> Implementing Math export to Docx
> 
> Modified: abiword/branches/gsoc2012math/plugins/openxml/common/xp/OXML_Element_Math.cpp
> ===================================================================
> --- abiword/branches/gsoc2012math/plugins/openxml/common/xp/OXML_Element_Math.cpp	2012-07-25 13:59:21 UTC (rev 31560)
> +++ abiword/branches/gsoc2012math/plugins/openxml/common/xp/OXML_Element_Math.cpp	2012-07-25 14:44:25 UTC (rev 31561)
> @@ -40,12 +40,32 @@
>      m_MathML = sMathML;
>  }
>  
> +const char * OXML_Element_Math::getMathML()
> +{
> +    UT_return_val_if_fail(!m_MathML.empty(), NULL);
> +    return m_MathML.c_str();
> +}
> +
>  UT_Error OXML_Element_Math::serialize(IE_Exp_OpenXML* exporter)
>  {
> -    //TO DO: serialize math here
>      UT_Error err = UT_OK;
> +	
> +    err = exporter->startMath();
> +    if(err != UT_OK)
> +        return err;
> +    
> +    std::string sMathML;
> +    sMathML.assign(getMathML());
> +    std::string sOMML;
>  
> -    return UT_OK;
> +    if(convertMathMLtoOMML(sMathML, sOMML))
> +    {
> +        err = exporter->writeMath(sOMML.c_str());
> +        if(err != UT_OK)
> +            return err;
> +    }
> +    
> +    return exporter->finishMath();
>  }
>  
>  UT_Error OXML_Element_Math::addToPT(PD_Document * pDocument)
> 
> Modified: abiword/branches/gsoc2012math/plugins/openxml/common/xp/OXML_Element_Math.h
> ===================================================================
> --- abiword/branches/gsoc2012math/plugins/openxml/common/xp/OXML_Element_Math.h	2012-07-25 13:59:21 UTC (rev 31560)
> +++ abiword/branches/gsoc2012math/plugins/openxml/common/xp/OXML_Element_Math.h	2012-07-25 14:44:25 UTC (rev 31561)
> @@ -40,6 +40,7 @@
>      virtual UT_Error addToPT(PD_Document * pDocument);
>  
>      void setMathML(const std::string & sMathML);
> +    const char * getMathML();
>  
>  private:
>      std::string m_MathML;
> 
> Modified: abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML.cpp
> ===================================================================
> --- abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML.cpp	2012-07-25 13:59:21 UTC (rev 31560)
> +++ abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML.cpp	2012-07-25 14:44:25 UTC (rev 31561)
> @@ -304,6 +304,32 @@
>  }
>  
>  /**
> + * Starts exporting the OXML_Element_Math object
> + */
> +UT_Error IE_Exp_OpenXML::startMath()
> +{
> +    return writeTargetStream(TARGET_DOCUMENT, "<m:oMathPara>");
> +}
> +
> +/**
> + * Writes the actual content of OXML_Element_Math object
> + */
> +UT_Error IE_Exp_OpenXML::writeMath(const char* omml)
> +{
> +    std::string str;
> +    str.assign(omml);
> +    return writeTargetStream(TARGET_DOCUMENT, str.c_str());
> +}
> +
> +/**
> + * Finishes exporting the OXML_Element_Math object
> + */
> +UT_Error IE_Exp_OpenXML::finishMath()
> +{
> +    return writeTargetStream(TARGET_DOCUMENT, "</m:oMathPara>");
> +}
> +
> +/**
>   * Starts exporting the OXML_Element_Run object
>   */
>  UT_Error IE_Exp_OpenXML::startRun(int target)
> @@ -2373,6 +2399,7 @@
>  	str += "xmlns:v=\"urn:schemas-microsoft-com:vml\" ";
>  	str += "xmlns:wx=\"http://schemas.microsoft.com/office/word/2003/auxHint\" ";
>  	str += "xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" ";
> +	str += "xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" ";
>  	str += "xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" ";
>  	str += "xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\" ";
>  	str += "xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:body>";
> 
> Modified: abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML.h
> ===================================================================
> --- abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML.h	2012-07-25 13:59:21 UTC (rev 31560)
> +++ abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML.h	2012-07-25 14:44:25 UTC (rev 31561)
> @@ -78,6 +78,9 @@
>  	UT_Error startText(int target);
>  	UT_Error writeText(int target, const UT_UCS4Char* text);
>  	UT_Error finishText(int target);
> +	UT_Error startMath();
> +	UT_Error writeMath(const char* omml);
> +	UT_Error finishMath();
>  	UT_Error startRun(int target);
>  	UT_Error finishRun(int target);
>  	UT_Error startRunProperties(int target);
> 
> Modified: abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML_Listener.cpp
> ===================================================================
> --- abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML_Listener.cpp	2012-07-25 13:59:21 UTC (rev 31560)
> +++ abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML_Listener.cpp	2012-07-25 14:44:25 UTC (rev 31561)
> @@ -322,6 +322,32 @@
>  					return element_run->appendElement(shared_element_image) == UT_OK;
>  				}
>  
> +				case PTO_Math:
> +				{
> +					if(bHaveProp && pAP)
> +					{
> +						if(!pAP->getAttribute("dataid", szValue))
> +						{
> +							return true;
> +						}
> +
> +						const UT_ByteBuf * pByteBuf = NULL;
> +						bool bOK = pdoc->getDataItemDataByName(szValue, const_cast<const UT_ByteBuf **>(&pByteBuf), NULL, NULL);
> +						if(!bOK) return bOK;
> +                                            
> +						std::string mathml;
> +						mathml.assign((const char*)(pByteBuf->getPointer(0)));
> +				    
> +						OXML_Element_Math* math = new OXML_Element_Math(getNextId());
> +						OXML_SharedElement shared_element_math(static_cast<OXML_Element*>(math));
> +						math->setMathML(mathml);
> +
> +						return paragraph->appendElement(shared_element_math) == UT_OK;
> +					}                                   
> +				    
> +					return true;
> +				}                 
> +
>  				case PTO_Bookmark:
>  				{
>  					if(bHaveProp && pAP)
> 
> Modified: abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML_Listener.h
> ===================================================================
> --- abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML_Listener.h	2012-07-25 13:59:21 UTC (rev 31560)
> +++ abiword/branches/gsoc2012math/plugins/openxml/exp/xp/ie_exp_OpenXML_Listener.h	2012-07-25 14:44:25 UTC (rev 31561)
> @@ -45,6 +45,7 @@
>  #include <OXML_Element_Bookmark.h>
>  #include <OXML_Element_Field.h>
>  #include <OXML_Element_TextBox.h>
> +#include <OXML_Element_Math.h>
>  #include <OXML_List.h>
>  #include <OXML_Image.h>
>  #include <ie_Table.h>
> 
> -----------------------------------------------
> To unsubscribe from this list, send a message to
> [email protected] with the word
> unsubscribe in the message body.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.