Commits

Anonymous committed 04d8a9a

Reverted the old import code to baseline, since we don't use it anymore.

Comments (0)

Files changed (5)

sc/source/filter/xml/XMLTextPContext.cxx

 #include "XMLTextPContext.hxx"
 #include "xmlimprt.hxx"
 #include "xmlcelli.hxx"
-#include "xmlrubyi.hxx"
 #include <xmloff/xmlnmspe.hxx>
 #include <xmloff/xmltoken.hxx>
 #include <xmloff/nmspmap.hxx>
 									  	::com::sun::star::xml::sax::XAttributeList>& xTempAttrList )
 {
 	SvXMLImportContext *pContext(NULL);
+	if (!pTextPContext &&
+		(nTempPrefix == XML_NAMESPACE_TEXT) &&
+		IsXMLToken(rLName, XML_S))
+		pContext = new ScXMLTextTContext( GetScImport(), nTempPrefix, rLName, xTempAttrList, this);
+	else
+	{
+		if (!pTextPContext)
+		{
+            rtl::OUString sSetString;
+            if ( pContentBuffer )
+                sSetString = pContentBuffer->makeStringAndClear();
+            else
+                sSetString = sSimpleContent;
 
-    if ( !pTextPContext )
-	{
-        const SvXMLTokenMap& rTokenMap = GetScImport().GetTableRowCellElemTextTokenMap();
-        switch( rTokenMap.Get( nTempPrefix, rLName ) )
-		{
-        case XML_TOK_TABLE_ROW_CELL_TEXT_S:
-            pContext = new ScXMLTextTContext( GetScImport(), nTempPrefix, rLName, xTempAttrList, this);
-            break;
-        case XML_TOK_TABLE_ROW_CELL_TEXT_RUBY:
-            pContext = new ScXMLRubyContext( GetScImport(), nTempPrefix, rLName, xTempAttrList, this );
-            break;
-        default:
+            sal_Unicode cNonSpace(0);
+            
+            sal_Int32 nLength = sSetString.getLength();
+            if ( nLength > 0 )
             {
-                rtl::OUString sSetString;
-                if ( pContentBuffer )
-                    sSetString = pContentBuffer->makeStringAndClear();
-                else
-                    sSetString = sSimpleContent;
+                sal_Unicode cLast = sSetString.getStr()[ nLength - 1 ];
+                if ( cLast != (sal_Unicode)' ' )
+                {
+                    // #i53253# To keep XMLParaContext's whitespace handling in sync,
+                    // if there's a non-space character at the end of the existing string,
+                    // it has to be processed by XMLParaContext.
 
-                sal_Unicode cNonSpace(0);
-
-                sal_Int32 nLength = sSetString.getLength();
-                if ( nLength > 0 )
-                {
-                    sal_Unicode cLast = sSetString.getStr()[ nLength - 1 ];
-                    if ( cLast != (sal_Unicode)' ' )
-                    {
-                        // #i53253# To keep XMLParaContext's whitespace handling in sync,
-                        // if there's a non-space character at the end of the existing string,
-                        // it has to be processed by XMLParaContext.
-
-                        cNonSpace = cLast;
-                        sSetString = sSetString.copy( 0, nLength - 1 );  // remove from the string for SetCursorOnTextImport
-                    }
-                }
-
-                pCellContext->SetCursorOnTextImport( sSetString );
-
-                pTextPContext = GetScImport().GetTextImport()->CreateTextChildContext(
-                        GetScImport(), nPrefix, sLName, xAttrList);
-
-                if ( cNonSpace != 0 )
-                {
-                    // pass non-space character through XMLParaContext, so a following space isn't ignored
-                    pTextPContext->Characters( rtl::OUString( cNonSpace ) );
+                    cNonSpace = cLast;
+                    sSetString = sSetString.copy( 0, nLength - 1 );  // remove from the string for SetCursorOnTextImport
                 }
             }
-            break;
+
+            pCellContext->SetCursorOnTextImport( sSetString );
+
+			pTextPContext = GetScImport().GetTextImport()->CreateTextChildContext(
+									GetScImport(), nPrefix, sLName, xAttrList);
+
+            if ( cNonSpace != 0 )
+            {
+                // pass non-space character through XMLParaContext, so a following space isn't ignored
+                pTextPContext->Characters( rtl::OUString( cNonSpace ) );
+            }
 		}
+		if (pTextPContext)
+			pContext = pTextPContext->CreateChildContext(nTempPrefix, rLName, xTempAttrList);
 	}
 
-    if ( pTextPContext )
-        pContext = pTextPContext->CreateChildContext(nTempPrefix, rLName, xTempAttrList);
-
 	if( !pContext )
 		pContext = new SvXMLImportContext( GetScImport(), nTempPrefix, rLName );
 
 		pTextPContext->EndElement();
 		GetScImport().SetRemoveLastChar(sal_True);
 	}
-    if ( sOURubyText )
-        pCellContext->SetPhoneticText( sOURubyText.makeStringAndClear(), aPhoneticPortions );
 }
 
-void ScXMLTextPContext::GetContent( rtl::OUString& rContent )
-{
-    if (!pTextPContext)
-    {
-        if ( pContentBuffer )
-        {
-            rtl::OUStringBuffer tmpBuffer( *pContentBuffer );
-            rContent = tmpBuffer.makeStringAndClear();
-        }
-        else
-        {
-            rContent = sSimpleContent;
-        }
-    }
-}
-
-void ScXMLTextPContext::AddRubyText( const ::rtl::OUString &rBaseText, const ::rtl::OUString& rRubyText )
-{
-    rtl::OUString aContent;
-    GetContent( aContent );
-
-    sal_uInt16 startIdx = aContent.getLength();
-    sal_uInt16 endIdx = rBaseText.getLength();
-
-    ScPhonetic::Portion portion( sOURubyText.getLength(), startIdx, endIdx );
-    sOURubyText.append( rRubyText );
-    aPhoneticPortions.push_back( portion );
-
-    Characters ( rBaseText );
-}
-

sc/source/filter/xml/XMLTextPContext.hxx

 #include <xmloff/xmlictxt.hxx>
 #include <rtl/ustrbuf.hxx>
 
-#include "phonetic.hxx"
-
 class ScXMLImport;
 class ScXMLTableRowCellContext;
 
     rtl::OUStringBuffer*        pContentBuffer;     // used if there's more than one string
 	USHORT						nPrefix;
 	sal_Bool					bIsOwn;
-    rtl::OUStringBuffer         sOURubyText;
-    ScPhonetic::PortionVec      aPhoneticPortions;
 
 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
-    void GetContent( rtl::OUString& rContent );
 
 public:
 	ScXMLTextPContext( ScXMLImport& rImport, USHORT nPrfx,
 	virtual void EndElement();
 
 	void AddSpaces(sal_Int32 nSpaceCount);
-
-    /**
-     * Add phonetic and base text into cell. 
-     *  
-     * @param rBaseText the base string.
-     * @param rRubyText the phonetic text.
-     */
-    void AddRubyText( const ::rtl::OUString& rBaseText, const ::rtl::OUString& rRubyText );
 };
 
 #endif

sc/source/filter/xml/xmlcelli.cxx

 using namespace com::sun::star;
 using namespace xmloff::token;
 
+
+#include <stdio.h>
+#include <string>
+#include <sys/time.h>
+
+namespace {
+
+class StackPrinter
+{
+public:
+    explicit StackPrinter(const char* msg) :
+        msMsg(msg)
+    {
+        fprintf(stdout, "%s: --begin\n", msMsg.c_str());
+        mfStartTime = getTime();
+    }
+
+    ~StackPrinter()
+    {
+        double fEndTime = getTime();
+        fprintf(stdout, "%s: --end (duration: %g sec)\n", msMsg.c_str(), (fEndTime-mfStartTime));
+    }
+
+private:
+    double getTime() const
+    {
+        timeval tv;
+        gettimeofday(&tv, NULL);
+        return tv.tv_sec + tv.tv_usec / 1000000.0;
+    }
+
+    ::std::string msMsg;
+    double mfStartTime;
+};
+
+}
+
 //------------------------------------------------------------------
 
 ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
                                         const ::boost::optional< ::rtl::OUString >& pPhoneticText,
                                         const ScPhonetic::PortionVec& rPortions )
 {
+    StackPrinter __stack_printer__("::lcl_CreateTextCell");
     ScBaseCell *pCell = 0;
 
     if ( pPhoneticText && pPhoneticText->getLength() )
     {
+        fprintf(stdout, "lcl_CreateTextCell:   phonetic data exists\n");
         sal_uInt16 aKanaType = lcl_GetKanaType ( pPhoneticText );
         ScPhonetic aPhonetic ( 0, 0x30 | aKanaType , 0, *pPhoneticText, rPortions );
         pCell = new ScAsianStringCell( rString, aPhonetic );
     }
     else
     {
+        fprintf(stdout, "lcl_CreateTextCell:   no phonetic data\n");
         pCell = ScBaseCell::CreateTextCell( rString, pDoc );
     }
 
 
 void ScXMLTableRowCellContext::EndElement()
 {
+    StackPrinter __stack_printer__("ScXMLTableRowCellContext::EndElement");
 	if (!bHasSubTable)
 	{
 		if (bHasTextImport && rXMLImport.GetRemoveLastChar())

sc/source/filter/xml/xmlrubyi.cxx

         mpParent->InsertRubyPortion(mnPosRuby, mnPosBase, mnBaseLen);
 }
 
-// ============================================================================
-
-ScXMLRubyContext::ScXMLRubyContext( ScXMLImport& rImport, USHORT nPrfx, const OUString& rLName,
-                                      const ::com::sun::star::uno::Reference<
-                                      ::com::sun::star::xml::sax::XAttributeList>& xTempAttrList,
-                                      ScXMLTextPContext* pTempTextContext) :
-    SvXMLImportContext( rImport, nPrfx, rLName ),
-    pCellContext( NULL ),
-    pTextContext( pTempTextContext )
-{
-    sal_Int16 nAttrCount(xTempAttrList.is() ? xTempAttrList->getLength() : 0);
-
-    const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableRowCellElemTextRubyAttrTokenMap();
-    for( sal_Int16 i=0; i < nAttrCount; ++i )
-    {
-        const rtl::OUString& sAttrName(xTempAttrList->getNameByIndex( i ));
-        rtl::OUString aLocalName;
-        USHORT nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
-                       sAttrName, &aLocalName ));
-        const rtl::OUString& sValue(xTempAttrList->getValueByIndex( i ));
-
-        switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
-        {
-        case XML_TOK_TABLE_ROW_CELL_TEXT_RUBY_ATTR_STYLE_NAME:
-            sStyleName = sValue;
-            break;
-        }
-    }
-}
-
-ScXMLRubyContext::ScXMLRubyContext( ScXMLImport& rImport,
-                                      USHORT nPrfx,
-                                      const ::rtl::OUString& rLName,
-                                      const ::com::sun::star::uno::Reference<
-                                      ::com::sun::star::xml::sax::XAttributeList>& xTempAttrList,
-                                      ScXMLTableRowCellContext* pTempContext) :
-    SvXMLImportContext( rImport, nPrfx, rLName ),
-    pCellContext( pTempContext ),
-    pTextContext( NULL )
-{
-    sal_Int16 nAttrCount(xTempAttrList.is() ? xTempAttrList->getLength() : 0);
-    const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableRowCellElemTextRubyAttrTokenMap();
-    for( sal_Int16 i=0; i < nAttrCount; ++i )
-    {
-        const rtl::OUString& sAttrName(xTempAttrList->getNameByIndex( i ));
-        rtl::OUString aLocalName;
-        USHORT nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
-                       sAttrName, &aLocalName ));
-        const rtl::OUString& sValue(xTempAttrList->getValueByIndex( i ));
-
-        switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
-        {
-        case XML_TOK_TABLE_ROW_CELL_TEXT_RUBY_ATTR_STYLE_NAME:
-            sStyleName = sValue;
-            break;
-        }
-    }
-}
-
-SvXMLImportContext *ScXMLRubyContext::CreateChildContext( USHORT nPrefix,
-                                            const ::rtl::OUString& rLName,
-                                            const ::com::sun::star::uno::Reference<
-                                        ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
-{
-    SvXMLImportContext *pContext(NULL);
-
-    const SvXMLTokenMap& rTokenMap = GetScImport().GetTableRowCellElemTextRubyAttrTokenMap();
-    switch( rTokenMap.Get( nPrefix, rLName ) )
-    {
-    case XML_TOK_TABLE_ROW_CELL_TEXT_RUBY_BASE:
-        pContext = new ScXMLRubyBaseContext( GetScImport(), nPrefix, rLName, xAttrList, this);
-        break;
-    case XML_TOK_TABLE_ROW_CELL_TEXT_RUBY_TEXT:
-        pContext = new ScXMLRubyTextContext( GetScImport(), nPrefix, rLName, xAttrList, this);
-        break;
-    }
-
-    if( !pContext )
-        pContext = new SvXMLImportContext( GetScImport(), nPrefix, rLName );
-
-    return pContext;
-}
-
-void ScXMLRubyContext::EndElement()
-{
-    if ( pTextContext )
-        pTextContext->AddRubyText( sBaseText.makeStringAndClear(), sRubyText.makeStringAndClear() );
-    else if ( pCellContext )
-        pCellContext->SetPhoneticText( sRubyText.makeStringAndClear(), ScPhonetic::PortionVec() );
-}
-
-void ScXMLRubyContext::AddBaseText( const ::rtl::OUString& rText )
-{
-    sBaseText.append( rText );
-}
-
-void ScXMLRubyContext::AddRubyText( const ::rtl::OUString& rText )
-{
-    sRubyText.append( rText );
-}
-
-ScXMLRubyBaseContext::ScXMLRubyBaseContext( ScXMLImport& rImport,
-                                      USHORT nPrfx,
-                                      const ::rtl::OUString& rLName,
-                                      const ::com::sun::star::uno::Reference<
-                                      ::com::sun::star::xml::sax::XAttributeList>& /*xTempAttrList*/,
-                                      ScXMLRubyContext* pTempRubyContext) :
-    SvXMLImportContext( rImport, nPrfx, rLName ),
-    pRubyContext( pTempRubyContext )
-{
-    // here are no attributes
-}
-
-void ScXMLRubyBaseContext::Characters( const ::rtl::OUString& rChars )
-{
-    pRubyContext->AddBaseText( rChars );
-}
-
-ScXMLRubyTextContext::ScXMLRubyTextContext( ScXMLImport& rImport,
-                                      USHORT nPrfx,
-                                      const ::rtl::OUString& rLName,
-                                      const ::com::sun::star::uno::Reference<
-                                      ::com::sun::star::xml::sax::XAttributeList>& /*xTempAttrList*/,
-                                      ScXMLRubyContext* pTempRubyContext) :
-    SvXMLImportContext( rImport, nPrfx, rLName ),
-    pRubyContext( pTempRubyContext )
-{
-    // here are no attributes
-}
-
-void ScXMLRubyTextContext::Characters( const ::rtl::OUString& rChars )
-{
-    pRubyContext->AddRubyText( rChars );
-}
-
-

sc/source/filter/xml/xmlrubyi.hxx

     ScXMLRubyPropertiesContext* mpParent;
 };
 
-// ============================================================================
-
-/**
- * A class for representing Asian phonetic guide information while loading ODF file.
- */
-class ScXMLRubyContext : public SvXMLImportContext
-{
-    rtl::OUString       sStyleName;
-    rtl::OUStringBuffer sBaseText;
-    rtl::OUStringBuffer sRubyText;
-    ScXMLTableRowCellContext*   pCellContext;
-    ScXMLTextPContext*  pTextContext;
-
-    const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
-    ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
-
-public:
-
-    /**
-     * A constructor of ScXMLRubyContext.
-     * @param rImport a reference of ScXMLImport.
-     * @param nPrfx the number of the element prefix.
-     * @param rLName the string of the element.
-     * @param xAttrList attribute list of the element.
-     * @param pContext a pointer of ScXMLTextPContext.
-     */
-    ScXMLRubyContext( ScXMLImport& rImport, USHORT nPrfx,
-                        const ::rtl::OUString& rLName,
-                        const ::com::sun::star::uno::Reference<
-                                        ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
-                        ScXMLTextPContext* pContext);
-    /**
-     * A constructor of ScXMLRubyContext.
-     * @param rImport a reference of ScXMLImport.
-     * @param nPrfx the number of the element prefix.
-     * @param rLName the string of the element.
-     * @param xAttrList attribute list of the element.
-     * @param pContext a pointer of ScXMLTableRowCellContext.
-     */
-    ScXMLRubyContext( ScXMLImport& rImport, USHORT nPrfx,
-                        const ::rtl::OUString& rLName,
-                        const ::com::sun::star::uno::Reference<
-                                        ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
-                        ScXMLTableRowCellContext* pContext);
-
-    virtual ~ScXMLRubyContext() {};
-
-    /**
-     * Create a childs element context. By default, the import's
-     * CreateContext method is called to create a new default context.
-     * @return a new default context.
-     */
-    virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix,
-                                     const ::rtl::OUString& rLocalName,
-                                     const ::com::sun::star::uno::Reference<
-                                        ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
-    /**
-     * EndElement is called before a context will be destructed, but
-     * after a elements context has been parsed. It may be used for actions
-     * that require virtual methods. The default is to do nothing.
-     */
-    virtual void EndElement();
-
-    /**
-     * Adds string into cell string as base string of phonetic infrmation
-     * @param rText the base string.
-     */
-    void AddBaseText(const ::rtl::OUString& rText);
-    /**
-     * Adds string into cell string as phonetic text
-     * @param rText the phonetic text.
-     */
-    void AddRubyText(const ::rtl::OUString& rText);
-};
-
-/**
- * A class for representing base text of phonetic guide information while loading ODF file.
- */
-class ScXMLRubyBaseContext : public SvXMLImportContext
-{
-    ScXMLRubyContext*   pRubyContext;
-
-    const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
-    ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
-
-public:
-
-    /**
-     * A constructor of ScXMLRubyBaseContext.
-     * @param rImport a reference of ScXMLImport.
-     * @param nPrfx the number of the element prefix.
-     * @param rLName the string of the element.
-     * @param xAttrList attribute list of the element.
-     * @param pContext a pointer of ScXMLRubyContext.
-     */
-    ScXMLRubyBaseContext( ScXMLImport& rImport, USHORT nPrfx,
-                        const ::rtl::OUString& rLName,
-                        const ::com::sun::star::uno::Reference<
-                                        ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
-                        ScXMLRubyContext* pContext);
-
-    virtual ~ScXMLRubyBaseContext() {};
-
-    /**
-     * This method is called for all characters that are contained in the
-     * current element. The default is to ignore them.
-     * @param rChars the character reference
-     */ 
-    virtual void Characters( const ::rtl::OUString& rChars );
-};
-
-
-/**
- * A class for representing phonetic text of phonetic guide information while loading ODF file.
- */
-class ScXMLRubyTextContext : public SvXMLImportContext
-{
-    ScXMLRubyContext*   pRubyContext;
-
-    const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
-    ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
-
-public:
-
-    /**
-     * A constructor of ScXMLRubyTextContext.
-     * @param rImport a reference of ScXMLImport.
-     * @param nPrfx the number of the element prefix.
-     * @param rLName the string of the element.
-     * @param xAttrList attribute list of the element.
-     * @param pContext a pointer of ScXMLRubyContext.
-     */
-    ScXMLRubyTextContext( ScXMLImport& rImport, USHORT nPrfx,
-                        const ::rtl::OUString& rLName,
-                        const ::com::sun::star::uno::Reference<
-                                        ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
-                        ScXMLRubyContext* pContext);
-
-    virtual ~ScXMLRubyTextContext() {};
-
-    /**
-     * This method is called for all characters that are contained in the
-     * current element. The default is to ignore them.
-     * @param rChars the character reference
-     */ 
-    virtual void Characters( const ::rtl::OUString& rChars );
-};
-
 #endif