Commits

Anonymous committed 86fc8c6

rtftok01: import unfinished patch to handle borders

Comments (0)

Files changed (3)

writerfilter/source/rtftok/RTFDestination.hxx

     void HandleSymbol(sal_Unicode const c);
     void SetAttribute(Id const id, RTFValue::Pointer_t const& pValue);
     void SetCharacterSprm(Id const id, RTFValue::Pointer_t const& pValue);
+    void SetParagraphBorder(Id const id);
     void SetParagraphSprm(Id const id, RTFValue::Pointer_t const& pValue);
     void SetSectionSprm(Id const id, RTFValue::Pointer_t const& pValue);
+    void SetTableRowBorder(Id const id);
     void SetTableRowSprm(Id const id, RTFValue::Pointer_t const& pValue);
     void SetTableRowNestedAttribute(Id const parent, Id const id,
             RTFValue::Pointer_t const& pValue);
             RTFValue::Pointer_t const& pValue);
     void SetTableRowDoubleNestedAttribute(Id const grandparent,
             Id const parent, Id const id, RTFValue::Pointer_t const& pValue);
+    void SetTableCellBorder(Id const id);
     void SetTableCellSprm(Id const id, RTFValue::Pointer_t const& pValue);
     void SetTableCellNestedAttribute(Id const parent, Id const id,
             RTFValue::Pointer_t const& pValue);

writerfilter/source/rtftok/RTFDocumentImpl.cxx

     }
     virtual ::std::string toString() const
     {
-        ::std::string ret("[");
+        ::rtl::OStringBuffer buf("[");
         for (Attributes_t::const_iterator iter = m_Value.begin();
-                iter < m_Value.end(); ++iter)
+                iter != m_Value.end(); )
         {
-            ret += iter->first;
-            ret += ::std::string(" -> ");
-            ret += iter->second->toString();
-            ret += ::std::string(",");
+            buf.append(static_cast<sal_Int32>(iter->first), 16);
+            buf.append(" -> ");
+            buf.append(iter->second->toString().c_str());
+            ++iter;
+            if (iter != m_Value.end()) {
+                buf.append(", ");
+            }
         }
-        ret += ::std::string("]");
-        return ret;
+        buf.append("]");
+        return ::std::string(buf.getStr());
     }
 
     void SetSprm(Id const id, RTFValue::Pointer_t const& pValue)
     }
     virtual ::std::string toString() const
     {
-        ::std::string ret("[");
+        ::rtl::OStringBuffer buf("[");
         for (Attributes_t::const_iterator iter = m_Value.begin();
-                iter < m_Value.end(); ++iter)
+                iter != m_Value.end(); )
         {
-            ret += iter->first;
-            ret += ::std::string(" -> ");
-            ret += iter->second->toString();
-            ret += ::std::string(",");
+            buf.append(static_cast<sal_Int32>(iter->first), 16);
+            buf.append(" -> ");
+            buf.append(iter->second->toString().c_str());
+            ++iter;
+            if (iter != m_Value.end()) {
+                buf.append(", ");
+            }
         }
-        ret += ::std::string("]");
-        return ret;
+        buf.append("]");
+        return ::std::string(buf.getStr());
     }
 
     void SetAttribute(Id const id, RTFValue::Pointer_t const& pValue)
         return ((0 <= i) && (static_cast<size_t>(i) < m_ColorTable.size()))
             ? m_ColorTable[i] : 0;
     }
+    RTFValue::Pointer_t GetCurrentBorder() const {
+        return m_pCurrentBorder;
+    }
+    void SetCurrentBorder(RTFValue::Pointer_t const pBorder) {
+        m_pCurrentBorder = pBorder;
+    }
     void SetAttribute(Id const id, RTFValue::Pointer_t const& pValue) {
         GetCurrentGroup().m_CharacterProperties.m_Attributes[id] = pValue;
     }
     FontTable_t m_FontTable;
     ColorTable_t m_ColorTable;
     RTFGroup::Attributes_t m_Defaults;
+    // borders are weird: there are lots of different ones, but they're not
+    // destinations; store the currently active one here...
+    RTFValue::Pointer_t m_pCurrentBorder;
 };
 
 
     GetHandler().addCharU(c);
 }
 
+
+static RTFValue::Pointer_t
+lcl_SetBorder(RTFGroup::Attributes_t & rSprms,
+        Id const grandparent, Id const border)
+{
+    RTFGroup::Attributes_t::iterator const iter2(rSprms.find(grandparent));
+    RTFValue::Pointer_t const pGrandParent( (iter2 != rSprms.end())
+        ?   iter2->second
+        :   RTFValue::Pointer_t(new RTFValueSprms()) );
+    RTFGroup::Attributes_t & rParentSprms(
+        dynamic_cast<RTFValueSprms *>(pGrandParent.get())->GetSprms());
+    RTFGroup::Attributes_t::iterator const iter(rParentSprms.find(border));
+    RTFValue::Pointer_t const pBorder( (iter != rParentSprms.end())
+        ?   iter->second
+        :   RTFValue::Pointer_t(new RTFValueAttributes()) );
+    dynamic_cast<RTFValueSprms *>(pGrandParent.get())->SetSprm(border, pBorder);
+    rSprms[grandparent] = pGrandParent;
+    return pBorder;
+}
+
+void
+RTFDestination::SetParagraphBorder(Id const id)
+{
+    RTFValue::Pointer_t const pBorder( lcl_SetBorder(
+        GetHandler().GetCurrentGroup().m_ParagraphProperties.m_Sprms,
+        NS_ooxml::LN_CT_PrBase_pBdr, id));
+    GetHandler().SetCurrentBorder(pBorder);
+}
+
+void
+RTFDestination::SetTableCellBorder(Id const id)
+{
+    RTFValue::Pointer_t const pBorder( lcl_SetBorder(
+        GetHandler().GetCurrentGroup().m_TableCellProperties.m_Sprms,
+        NS_ooxml::LN_CT_TcPrBase_tcBorders, id));
+    GetHandler().SetCurrentBorder(pBorder);
+}
+
+void
+RTFDestination::SetTableRowBorder(Id const id)
+{
+    RTFValue::Pointer_t const pBorder( lcl_SetBorder(
+        GetHandler().GetCurrentGroup().m_TableRowProperties.m_Sprms,
+        NS_ooxml::LN_CT_TblPrBase_tblBorders, id));
+    GetHandler().SetCurrentBorder(pBorder);
+}
+
+
 void
 RTFDestination::SetAttribute(Id const id, RTFValue::Pointer_t const& pValue)
 {

writerfilter/source/rtftok/rtfactions.xml

     <!--    <ref name="webhidden"/>-->
   </charprops>
 
+  <paraborders>
+    <!-- <ref name="brdrt" /> -->
+    <!-- <ref name="brdrb"/> -->
+    <!-- <ref name="brdrl"/> -->
+    <!-- <ref name="brdrr"/> -->
+    <!-- <ref name="brdrbtw"/> -->
+    <!-- <ref name="brdrbar"/> -->
+    <!-- <ref name="box"/> -->
+    <!-- <ref name="brdrs"/> -->
+    <!-- <ref name="brdrth"/> -->
+    <!-- <ref name="brdrsh"/> -->
+    <!-- <ref name="brdrdb"/> -->
+    <!-- <ref name="brdrdot"/> -->
+    <!-- <ref name="brdrdash"/> -->
+    <!-- <ref name="brdrhair"/> -->
+    <!-- <ref name="brdrdashsm"/> -->
+    <!-- <ref name="brdrdashd"/> -->
+    <!-- <ref name="brdrdashdd"/> -->
+    <!-- <ref name="brdrdashdot"/> -->
+    <!-- <ref name="brdrdashdotdot"/> -->
+    <!-- <ref name="brdrinset"/> -->
+    <!-- <ref name="brdrnone"/> -->
+    <!-- <ref name="brdroutset"/> -->
+    <!-- <ref name="brdrtriple"/> -->
+    <!-- <ref name="brdrtnthsg"/> -->
+    <!-- <ref name="brdrthtnsg"/> -->
+    <!-- <ref name="brdrtnthtnsg"/> -->
+    <!-- <ref name="brdrtnthmg"/> -->
+    <!-- <ref name="brdrthtnmg"/> -->
+    <!-- <ref name="brdrtnthtnmg"/> -->
+    <!-- <ref name="brdrtnthlg"/> -->
+    <!-- <ref name="brdrthtnlg"/> -->
+    <!-- <ref name="brdrtnthtnlg"/> -->
+    <!-- <ref name="brdrwavy"/> -->
+    <!-- <ref name="brdrwavydb"/> -->
+    <!-- <ref name="brdrdashdotstr"/> -->
+    <!-- <ref name="brdremboss"/> -->
+    <!-- <ref name="brdrengrave"/> -->
+    <!-- <ref name="brdrframe"/> -->
+    <!-- <ref name="brdrw"/> -->
+    <!-- <ref name="brdrcf"/> -->
+    <!-- <ref name="brsp"/> -->
+    <!-- <ref name="brdrnil"/> -->
+    <!-- <ref name="brdrtbl"/> -->
+  </paraborders>
+
   <paraprops>
     <ref name="par" action="ParagraphBreak()"/>
     <ref name="pard" action="ResetParagraphProperties()"/>
     <!-- <ref name="rtlrow"/> -->
     <!-- <ref name="ltrrow"/> -->
 
-    <!-- ooxml::LN_CT_TblPrBase_tblBorders: how does this work -->
-    <!-- <ref name="trbrdrt"/> -->
-    <!-- <ref name="trbrdrl"/> -->
-    <!-- <ref name="trbrdrb"/> -->
-    <!-- <ref name="trbrdrr"/> -->
-    <!-- <ref name="trbrdrh"/> -->
-    <!-- <ref name="trbrdrv"/> -->
+    <ref name="trbrdrt"
+      action="SetTableRowBorder(NS_ooxml::LN_CT_TblBorders_top)"/>
+    <ref name="trbrdrl"
+      action="SetTableRowBorder(NS_ooxml::LN_CT_TblBorders_left)"/>
+    <ref name="trbrdrb"
+      action="SetTableRowBorder(NS_ooxml::LN_CT_TblBorders_bottom)"/>
+    <ref name="trbrdrr"
+      action="SetTableRowBorder(NS_ooxml::LN_CT_TblBorders_right)"/>
+    <ref name="trbrdrh"
+      action="SetTableRowBorder(NS_ooxml::LN_CT_TblBorders_insideH)"/>
+    <ref name="trbrdrv"
+      action="SetTableRowBorder(NS_ooxml::LN_CT_TblBorders_insideV)"/>
+  </trowprops>
 
-
-  </trowprops>
   <tcellprops>
     <ref name="tcelld" action="ResetTableRowProperties()"/>
     <ref name="nestcell" action="TableCellBreak()"/>
 
     <!-- ooxml::LN_CT_TcPrBase_tcBorders: how does this work -->
     <!-- <ref name="brdrnil"/> -->
-    <!-- <ref name="clbrdrb"/> -->
-    <!-- <ref name="clbrdrt"/> -->
-    <!-- <ref name="clbrdrl"/> -->
-    <!-- <ref name="clbrdrr"/> -->
+    <ref name="clbrdrb"
+      action="SetTableCellBorder(NS_ooxml::LN_CT_TcBorders_bottom)"/>
+    <ref name="clbrdrt"
+      action="SetTableCellBorder(NS_ooxml::LN_CT_TcBorders_top)"/>
+    <ref name="clbrdrl"
+      action="SetTableCellBorder(NS_ooxml::LN_CT_TcBorders_left)"/>
+    <ref name="clbrdrr"
+      action="SetTableCellBorder(NS_ooxml::LN_CT_TcBorders_right)"/>
     <!-- <ref name="cldglu"/> -->
     <!-- <ref name="cldgll"/> -->