Commits

Kohei Yoshida  committed 353a1f4

Export phonetic data using the new xml structure.

  • Participants
  • Parent commits dafb3bd

Comments (0)

Files changed (3)

File sc/inc/phonetic.hxx

 
 	/** Returns True if no phonetic information. */
 	bool IsEmpty() const;
-	/** Returns the text for phonetic information. */
+    /** Get all phonetic strings concatenated into a single string. */
 	const String& GetString() const;
     /** Returns the portion for phonetic information. */
 	const PortionVec& GetPortions() const;

File sc/source/filter/xml/xmlexprt.cxx

 using namespace com::sun::star;
 using namespace xmloff::token;
 using ::std::vector;
+using ::std::for_each;
 
 //----------------------------------------------------------------------------
 
     return sal_True;
 }
 
-void ScXMLExport::WriteRubyText (ScMyCell& rMyCell)
+namespace {
+
+class WriteRubySpan : public ::std::unary_function<void, ScPhonetic::Portion>
 {
-    if (rMyCell.aPhoneticData.IsEmpty())
+public:
+    explicit WriteRubySpan(ScXMLExport& rExport) : mrExport(rExport) {}
+
+    void operator() (const ScPhonetic::Portion& rPortion)
+    {
+        OUStringBuffer aBuf;
+        aBuf.append(static_cast<sal_Int32>(rPortion.mnPosBase));
+        mrExport.AddAttribute(XML_NAMESPACE_TEXT, XML_BASE_POSITION, aBuf.makeStringAndClear());
+        aBuf.append(static_cast<sal_Int32>(rPortion.mnBaseLen));
+        mrExport.AddAttribute(XML_NAMESPACE_TEXT, XML_BASE_LENGTH,   aBuf.makeStringAndClear());
+        aBuf.append(static_cast<sal_Int32>(rPortion.mnPosRuby));
+        mrExport.AddAttribute(XML_NAMESPACE_TEXT, XML_RUBY_POSITION, aBuf.makeStringAndClear());
+        SvXMLElementExport aRubySpanElem(mrExport, XML_NAMESPACE_TEXT, XML_RUBY_SPAN, sal_True, sal_False);
+    }
+
+private:
+    ScXMLExport& mrExport;
+};
+
+}
+
+void ScXMLExport::WriteRubyProperties(ScMyCell& rCell)
+{
+    if (rCell.aPhoneticData.IsEmpty())
+        // No phonetic data to write.  Bail out.
         return;
 
-    const OUString& rBaseStr = rMyCell.sStringValue;
-    const OUString& rRubyStr = rMyCell.aPhoneticData.GetString();
-    sal_uInt16 nCurBasePos = 0; // current base text position.
-
-    const ScPhonetic::PortionVec& rParts = rMyCell.aPhoneticData.GetPortions();
-    ScPhonetic::PortionVec::const_iterator itr = rParts.begin(), itrEnd = rParts.end();
-    for (; itr != itrEnd; ++itr)
-    {
-        if (nCurBasePos < itr->mnPosBase)
-        {
-            // Previous base text portion has no phonetic data.  Export as normal text.
-            OUString aBasePart = rBaseStr.copy(nCurBasePos, itr->mnPosBase - nCurBasePos);
-            Characters(aBasePart);
-        }
-
-        OUString aBasePart = rBaseStr.copy(itr->mnPosBase, itr->mnBaseLen);
-        OUString aRubyPart;
-        if (itr+1 == itrEnd)
-            // Last phonetic portion.  Get all the remaining string.
-            aRubyPart = rRubyStr.copy(itr->mnPosRuby);
-        else
-        {    
-            // There is another phonetic portion that follows.  Use the 
-            // position of the next portion to calculate the size of the
-            // current portion.
-            sal_uInt16 nThisPos = itr->mnPosRuby;
-            sal_uInt16 nNextPos = (itr+1)->mnPosRuby;
-            aRubyPart = rRubyStr.copy(nThisPos, nNextPos - nThisPos);
-        }
-
-        SvXMLElementExport aRubyElem(*this, XML_NAMESPACE_TEXT, XML_RUBY, sal_True, sal_False);
-        {
-            SvXMLElementExport aRubyBaseElem(*this, XML_NAMESPACE_TEXT, XML_RUBY_BASE, sal_True, sal_False);
-            Characters(aBasePart);
-        }
-        {
-            SvXMLElementExport aRubyBaseElem(*this, XML_NAMESPACE_TEXT, XML_RUBY_TEXT, sal_True, sal_False);
-            Characters(aRubyPart);
-        }
-        
-        nCurBasePos = itr->mnPosBase + itr->mnBaseLen;
-    }
-
-    if (nCurBasePos < rBaseStr.getLength())
-    {
-        // Tail end of the base string has no phonetic data.  Export as normal text.
-        OUString aBasePart = rBaseStr.copy(nCurBasePos);
-        Characters(aBasePart);
-    }
+    const ScPhonetic& rData = rCell.aPhoneticData;
+    AddAttribute(XML_NAMESPACE_TEXT, XML_RUBY_TEXT, rData.GetString());
+    SvXMLElementExport aRubyBaseElem(*this, XML_NAMESPACE_TEXT, XML_RUBY_PROPERTIES, sal_True, sal_False);
+    const ScPhonetic::PortionVec& rPortions = rData.GetPortions();
+    for_each(rPortions.begin(), rPortions.end(), WriteRubySpan(*this));
 }
 
 void ScXMLExport::WriteCell (ScMyCell& aCell)
 
 	if (!bIsEmpty)
 	{
+        WriteRubyProperties(aCell);
         if ((aCell.nType == table::CellContentType_TEXT && IsEditCell(aCell)) || 
             (aCell.nType == table::CellContentType_FORMULA && IsMultiLineFormulaCell(aCell)))
 		{
+            // edit cell
             bEditCell = sal_True;
             uno::Reference<text::XText> xText(xCurrentTableCellRange->getCellByPosition(aCell.aCellAddress.Column, aCell.aCellAddress.Row), uno::UNO_QUERY);
 			if ( xText.is())
 				GetTextParagraphExport()->exportText(xText, sal_False, sal_False);
-            if (GetCellText( aCell, aCellPos ) && !aCell.aPhoneticData.IsEmpty())
-                WriteRubyText( aCell );
 		}
 		else
 		{
+            // string cell
 			SvXMLElementExport aElemP(*this, sElemP, sal_True, sal_False);
 			sal_Bool bPrevCharWasSpace(sal_True);
 	  		if (GetCellText(aCell, aCellPos))
-            {
-                if ( !aCell.aPhoneticData.IsEmpty() )
-                    WriteRubyText( aCell );
-                else 
-                    GetTextParagraphExport()->exportText( aCell.sStringValue, bPrevCharWasSpace );
-           }
+                GetTextParagraphExport()->exportText( aCell.sStringValue, bPrevCharWasSpace );
 		}
 	}
 	WriteShapes(aCell);

File sc/source/filter/xml/xmlexprt.hxx

 	void ExportShape(const com::sun::star::uno::Reference < com::sun::star::drawing::XShape >& xShape, com::sun::star::awt::Point* pPoint);
 	void WriteShapes(const ScMyCell& rMyCell);
 	void WriteTableShapes();
+    void WriteRubyProperties(ScMyCell& rCell);
 
-    /**
-     * Write phonetic text
-     * @param aCell the cell reference which has phonetic text.
-     */
-    void WriteRubyText (ScMyCell& aCell);
 	void SetRepeatAttribute (const sal_Int32 nEqualCellCount);
 
 	sal_Bool IsCellTypeEqual (const ScMyCell& aCell1, const ScMyCell& aCell2) const;