# HG changeset patch
# User Michael Stahl <mst@openoffice.org>
# Date 1288106338 -7200
# Node ID b13a680ed6e8ee3eaab27d7f115872c40788971e
# Parent  c6e5d8f80513e0f64d1135de58c4d958f2a71fe6
rtftok01: cell colors are attributes within sprms... argh...

diff --git a/writerfilter/source/rtftok/RTFDestination.hxx b/writerfilter/source/rtftok/RTFDestination.hxx
--- a/writerfilter/source/rtftok/RTFDestination.hxx
+++ b/writerfilter/source/rtftok/RTFDestination.hxx
@@ -323,11 +323,15 @@
     void SetParagraphSprm(Id const id, RTFValue::Pointer_t const& pValue);
     void SetSectionSprm(Id const id, RTFValue::Pointer_t const& pValue);
     void SetTableRowSprm(Id const id, RTFValue::Pointer_t const& pValue);
+    void SetTableRowNestedAttribute(Id const parent, Id const id,
+            RTFValue::Pointer_t const& pValue);
     void SetTableRowNestedSprm(Id const parent, Id const id,
             RTFValue::Pointer_t const& pValue);
     void SetTableRowDoubleNestedAttribute(Id const grandparent,
             Id const parent, Id const id, RTFValue::Pointer_t const& pValue);
     void SetTableCellSprm(Id const id, RTFValue::Pointer_t const& pValue);
+    void SetTableCellNestedAttribute(Id const parent, Id const id,
+            RTFValue::Pointer_t const& pValue);
     void SetTableCellNestedSprm(Id const parent, Id const id,
             RTFValue::Pointer_t const& pValue);
     void SetTableCellDoubleNestedAttribute(Id const grandparent,
@@ -349,7 +353,8 @@
 };
 
 
-sal_Int32 MapTblWidthUnit(sal_Int32 const n);
+sal_uInt32 MapTblWidthUnit(sal_Int32 const n);
+sal_uInt32 MapShadingPercentage(sal_Int32 const n);
 
 } // namespace writerfilter
 } // namespace rtftok
diff --git a/writerfilter/source/rtftok/RTFDocumentImpl.cxx b/writerfilter/source/rtftok/RTFDocumentImpl.cxx
--- a/writerfilter/source/rtftok/RTFDocumentImpl.cxx
+++ b/writerfilter/source/rtftok/RTFDocumentImpl.cxx
@@ -68,7 +68,7 @@
 
 
 
-sal_Int32 MapTblWidthUnit(sal_Int32 const n)
+sal_uInt32 MapTblWidthUnit(sal_Int32 const n)
 {
     switch (n)
     {
@@ -82,6 +82,36 @@
     }
 }
 
+sal_uInt32 MapShadingPercentage(sal_Int32 const n)
+{
+    static struct { sal_Int32 const limit; sal_uInt32 const value; } s_Map[] =
+    {
+        {    0,  0 },
+        {   50,  2 },
+        {  100,  3 },
+        {  200,  4 },
+        {  250,  5 },
+        {  300,  6 },
+        {  400,  7 },
+        {  500,  8 },
+        {  600,  9 },
+        {  700, 10 },
+        {  750, 11 },
+        {  800, 12 },
+        {  900, 13 },
+        { 1000,  1 },
+    };
+    static size_t const s_Map_size(sizeof(s_Map)/sizeof(s_Map[0]));
+    for (size_t i = 0; i < s_Map_size; ++i)
+    {
+        if (n <= s_Map[i].limit) {
+            return s_Map[i].value;
+        }
+    }
+    OSL_TRACE("MapShadingPercentage: invalid value: %" SAL_PRIdINT32, n);
+    return 1;
+}
+
 
 /** Implementation of Reference<Properties>.
  */
@@ -745,6 +775,28 @@
 }
 
 static RTFValue::Pointer_t
+lcl_SetNestedAttribute(RTFGroup::Attributes_t rSprms, Id const parent,
+        Id const id, RTFValue::Pointer_t const& pValue)
+{
+    RTFGroup::Attributes_t::iterator const iter(rSprms.find(parent));
+    RTFValue::Pointer_t const pParent( (iter != rSprms.end())
+        ?   iter->second
+        :   RTFValue::Pointer_t(new RTFValueAttributes()) );
+    dynamic_cast<RTFValueAttributes*>(pParent.get())->SetAttribute(id, pValue);
+    return pParent;
+}
+
+void
+RTFDestination::SetTableRowNestedAttribute(Id const parent, Id const id,
+        RTFValue::Pointer_t const& pValue)
+{
+    RTFGroup & rGroup( GetHandler().GetCurrentGroup() );
+    RTFValue::Pointer_t const pParent( lcl_SetNestedAttribute(
+        rGroup.m_TableRowProperties.m_Sprms, parent, id, pValue) );
+    GetHandler().SetTableRowSprm(parent, pParent);
+}
+
+static RTFValue::Pointer_t
 lcl_SetNestedSprm(RTFGroup::Attributes_t rSprms, Id const parent,
         Id const id, RTFValue::Pointer_t const& pValue)
 {
@@ -804,6 +856,16 @@
 }
 
 void
+RTFDestination::SetTableCellNestedAttribute(Id const parent, Id const id,
+        RTFValue::Pointer_t const& pValue)
+{
+    RTFGroup & rGroup( GetHandler().GetCurrentGroup() );
+    RTFValue::Pointer_t const pParent( lcl_SetNestedAttribute(
+        rGroup.m_TableCellProperties.m_Sprms, parent, id, pValue) );
+    GetHandler().SetTableCellSprm(parent, pParent);
+}
+
+void
 RTFDestination::SetTableCellNestedSprm(Id const parent, Id const id,
         RTFValue::Pointer_t const& pValue)
 {
diff --git a/writerfilter/source/rtftok/rtfactions.xml b/writerfilter/source/rtftok/rtfactions.xml
--- a/writerfilter/source/rtftok/rtfactions.xml
+++ b/writerfilter/source/rtftok/rtfactions.xml
@@ -647,23 +647,53 @@
     <ref name="tblindtype"
       parent="ooxml:CT_TblPrBase_tblInd" tokenid="rtf:unit"/>
 
-    <!-- ooxml::LN_CT_TblPrBase_shd: how does this work -->
-    <!-- <ref name="trcbpat"/> -->
-    <!-- <ref name="trcfpat"/> -->
+    <ref name="trcbpat"
+      parent="ooxml:CT_TblPrBase_shd"
+      tokenid="ooxml:CT_Shd_fill" attribute="true"/>
+    <ref name="trcfpat"
+      parent="ooxml:CT_TblPrBase_shd"
+      tokenid="ooxml:CT_Shd_color" attribute="true"/>
     <!-- <ref name="trpat"/> -->
-    <!-- <ref name="trshdng"/> -->
-    <!-- <ref name="trbgbdiag"/> -->
-    <!-- <ref name="trbgcross"/> -->
-    <!-- <ref name="trbgdcross"/> -->
-    <!-- <ref name="trbgdkbdiag"/> -->
-    <!-- <ref name="trbgdkcross"/> -->
-    <!-- <ref name="trbgdkdcross"/> -->
-    <!-- <ref name="trbgdkfdiag"/> -->
-    <!-- <ref name="trbgdkhor"/> -->
-    <!-- <ref name="trbgdkvert"/> -->
-    <!-- <ref name="trbgfdiag"/> -->
-    <!-- <ref name="trbghoriz"/> -->
-    <!-- <ref name="trbgvert"/> -->
+    <ref name="trshdng"
+      parent="ooxml:CT_TblPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true"
+      shadingpercentage="true"/>
+    <ref name="trbgbdiag"
+      parent="ooxml:CT_TblPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="23"/>
+    <ref name="trbgcross"
+      parent="ooxml:CT_TblPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="24"/>
+    <ref name="trbgdcross"
+      parent="ooxml:CT_TblPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="25"/>
+    <ref name="trbgdkbdiag"
+      parent="ooxml:CT_TblPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="17"/>
+    <ref name="trbgdkcross"
+      parent="ooxml:CT_TblPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="18"/>
+    <ref name="trbgdkdcross"
+      parent="ooxml:CT_TblPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="19"/>
+    <ref name="trbgdkfdiag"
+      parent="ooxml:CT_TblPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="16"/>
+    <ref name="trbgdkhor"
+      parent="ooxml:CT_TblPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="14"/>
+    <ref name="trbgdkvert"
+      parent="ooxml:CT_TblPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="15"/>
+    <ref name="trbgfdiag"
+      parent="ooxml:CT_TblPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="22"/>
+    <ref name="trbghoriz"
+      parent="ooxml:CT_TblPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="20"/>
+    <ref name="trbgvert"
+      parent="ooxml:CT_TblPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="21"/>
 
     <!-- <ref name="tdfrmtxtLeft"/> -->
     <!-- <ref name="tdfrmtxtRight"/> -->
@@ -773,37 +803,69 @@
     <!-- <ref name="cldglu"/> -->
     <!-- <ref name="cldgll"/> -->
 
-    <!-- ooxml::CT_TcPrBase_shd looks somehow different? -->
-    <!-- <ref name="clshdrawnil"/> -->
-    <!-- <ref name="clshdng"/> -->
+    <ref name="clshdrawnil"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="0"/>
+    <ref name="clshdng"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true"
+      shadingpercentage="true"/>
     <!-- <ref name="clshdngraw"/> -->
-    <!-- <ref name="clbghoriz"/> -->
+    <ref name="clbghoriz"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="20"/>
     <!-- <ref name="rawclbghoriz"/> -->
-    <!-- <ref name="clbgvert"/> -->
+    <ref name="clbgvert"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="21"/>
     <!-- <ref name="rawclbgvert"/> -->
-    <!-- <ref name="clbgfdiag"/> -->
+    <ref name="clbgfdiag"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="22"/>
     <!-- <ref name="rawclbgfdiag"/> -->
-    <!-- <ref name="clbgbdiag"/> -->
+    <ref name="clbgbdiag"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="23"/>
     <!-- <ref name="rawclbgbdiag"/> -->
-    <!-- <ref name="clbgcross"/> -->
+    <ref name="clbgcross"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="24"/>
     <!-- <ref name="rawclbgcross"/> -->
-    <!-- <ref name="clbgdcross"/> -->
+    <ref name="clbgdcross"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="25"/>
     <!-- <ref name="rawclbgdcross"/> -->
-    <!-- <ref name="clbgdkhor"/> -->
+    <ref name="clbgdkhor"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="14"/>
     <!-- <ref name="rawclbgdkhor"/> -->
-    <!-- <ref name="clbgdkvert"/> -->
+    <ref name="clbgdkvert"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="15"/>
     <!-- <ref name="rawclbgdkvert"/> -->
-    <!-- <ref name="clbgdkfdiag"/> -->
+    <ref name="clbgdkfdiag"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="16"/>
     <!-- <ref name="rawclbgdkfdiag"/> -->
-    <!-- <ref name="clbgdkbdiag"/> -->
+    <ref name="clbgdkbdiag"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="17"/>
     <!-- <ref name="rawclbgdkbdiag"/> -->
-    <!-- <ref name="clbgdkcross"/> -->
+    <ref name="clbgdkcross"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="18"/>
     <!-- <ref name="rawclbgdkcross"/> -->
-    <!-- <ref name="clbgdkdcross"/> -->
+    <ref name="clbgdkdcross"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_val" attribute="true" value="19"/>
     <!-- <ref name="rawclbgdkdcross"/> -->
-    <!-- <ref name="clcfpat"/> -->
+    <ref name="clcfpat"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_color" attribute="true"/>
     <!-- <ref name="clcfpatraw"/> -->
-    <!-- <ref name="clcbpat"/> -->
+    <ref name="clcbpat"
+      parent="ooxml:CT_TcPrBase_shd"
+      tokenid="ooxml:CT_Shd_fill" attribute="true"/>
     <!-- <ref name="clcbpatraw"/> -->
 
     <ref name="clvertalt" tokenid="ooxml:CT_TcPrBase_vAlign" value="0"/>
diff --git a/writerfilter/source/rtftok/rtfcontrols.xsl b/writerfilter/source/rtftok/rtfcontrols.xsl
--- a/writerfilter/source/rtftok/rtfcontrols.xsl
+++ b/writerfilter/source/rtftok/rtfcontrols.xsl
@@ -121,6 +121,10 @@
               <xsl:text>sal_uInt32 const unit(MapTblWidthUnit(n));&#xA;</xsl:text>
               <xsl:text>RTFValue::Pointer_t const pValue(new RTFValueInt(unit));&#xA;</xsl:text>
             </xsl:when>
+            <xsl:when test="@shadingpercentage">
+              <xsl:text>sal_uInt32 const shading(MapShadingPercentage(n));&#xA;</xsl:text>
+              <xsl:text>RTFValue::Pointer_t const pValue(new RTFValueInt(shading));&#xA;</xsl:text>
+            </xsl:when>
             <xsl:otherwise>
               <xsl:text>RTFValue::Pointer_t const pValue(new RTFValueInt(n));&#xA;</xsl:text>
             </xsl:otherwise>
@@ -174,15 +178,36 @@
             </xsl:call-template>
           </xsl:variable>
           <xsl:choose>
-            <xsl:when test="$kind='tablerow'">
-              <xsl:text>rDestination.SetTableRowNestedSprm(</xsl:text>
+            <xsl:when test="@attribute">
+              <xsl:choose>
+                <xsl:when test="$kind='tablerow'">
+                  <xsl:text>rDestination.SetTableRowNestedAttribute(</xsl:text>
+                </xsl:when>
+                <xsl:when test="$kind='tablecell'">
+                  <xsl:text>rDestination.SetTableCellNestedAttribute(</xsl:text>
+                </xsl:when>
+                <xsl:otherwise>
+                  <xsl:text>UNKNOWN KIND: </xsl:text>
+                  <xsl:value-of select="$kind"/>
+                </xsl:otherwise>
+              </xsl:choose>
             </xsl:when>
-            <xsl:when test="$kind='tablecell'">
-              <xsl:text>rDestination.SetTableCellNestedSprm(</xsl:text>
+            <xsl:when test="@tokenid">
+              <xsl:choose>
+                <xsl:when test="$kind='tablerow'">
+                  <xsl:text>rDestination.SetTableRowNestedSprm(</xsl:text>
+                </xsl:when>
+                <xsl:when test="$kind='tablecell'">
+                  <xsl:text>rDestination.SetTableCellNestedSprm(</xsl:text>
+                </xsl:when>
+                <xsl:otherwise>
+                  <xsl:text>UNKNOWN KIND: </xsl:text>
+                  <xsl:value-of select="$kind"/>
+                </xsl:otherwise>
+              </xsl:choose>
             </xsl:when>
             <xsl:otherwise>
-              <xsl:text>UNKNOWN KIND: </xsl:text>
-              <xsl:value-of select="$kind"/>
+              <xsl:text>ERROR no tokenid or attribute</xsl:text>
             </xsl:otherwise>
           </xsl:choose>
           <xsl:value-of select="$parent"/>
