[Libreoffice-commits] core.git: sw/qa writerfilter/source

SJacobi Sven-Jacobi at gmx.de
Wed Apr 3 06:15:34 PDT 2013


 sw/qa/extras/ooxmlimport/data/conditionalstyles-tbllook.docx |binary
 writerfilter/source/dmapper/DomainMapperTableHandler.cxx     |  102 ++++++++---
 writerfilter/source/dmapper/DomainMapperTableManager.cxx     |   21 --
 writerfilter/source/dmapper/PropertyIds.cxx                  |    4 
 writerfilter/source/dmapper/PropertyIds.hxx                  |    2 
 writerfilter/source/dmapper/StyleSheetTable.cxx              |   49 ++---
 6 files changed, 110 insertions(+), 68 deletions(-)

New commits:
commit 35b75ed510f49ff64cd86b38e228c2b5b9a9f3fc
Author: SJacobi <Sven-Jacobi at gmx.de>
Date:   Tue Apr 2 18:33:34 2013 +0200

    ooxmlimport: conditional table styles fixed
    
    Change-Id: I84f1d7c718dfc120b76364479ca68f63d2549b9f
    Reviewed-on: https://gerrit.libreoffice.org/3175
    Reviewed-by: Thorsten Behrens <tbehrens at suse.com>
    Tested-by: Thorsten Behrens <tbehrens at suse.com>

diff --git a/sw/qa/extras/ooxmlimport/data/conditionalstyles-tbllook.docx b/sw/qa/extras/ooxmlimport/data/conditionalstyles-tbllook.docx
new file mode 100644
index 0000000..4222d63
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/conditionalstyles-tbllook.docx differ
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index 176f3c9..6a0609b 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -263,6 +263,7 @@ struct WRITERFILTER_DLLPRIVATE TableInfo
     sal_Int32 nRightBorderDistance;
     sal_Int32 nTopBorderDistance;
     sal_Int32 nBottomBorderDistance;
+    sal_Int32 nTblLook;
     sal_Int32 nNestLevel;
     PropertyMapPtr pTableDefaults;
     PropertyMapPtr pTableBorders;
@@ -274,6 +275,7 @@ struct WRITERFILTER_DLLPRIVATE TableInfo
     , nRightBorderDistance(DEF_BORDER_DIST)
     , nTopBorderDistance(0)
     , nBottomBorderDistance(0)
+    , nTblLook(0x4a0)
     , nNestLevel(0)
     , pTableDefaults(new PropertyMap)
     , pTableBorders(new PropertyMap)
@@ -360,6 +362,14 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo
             }
         }
 
+        PropertyMap::iterator aTblLookIter =
+        aTblLookIter = m_aTableProperties->find( PropertyDefinition( PROP_TBL_LOOK, false ) );
+        if(aTblLookIter != m_aTableProperties->end())
+        {
+            aTblLookIter->second >>= rInfo.nTblLook;
+            m_aTableProperties->erase( aTblLookIter );
+        }
+
         // Set the table default attributes for the cells
         rInfo.pTableDefaults->InsertProps(m_aTableProperties);
 
@@ -494,6 +504,19 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo
     return pTableStyle;
 }
 
+#define CNF_FIRST_ROW               0x800
+#define CNF_LAST_ROW                0x400
+#define CNF_FIRST_COLUMN            0x200
+#define CNF_LAST_COLUMN             0x100
+#define CNF_ODD_VBAND               0x080
+#define CNF_EVEN_VBAND              0x040
+#define CNF_ODD_HBAND               0x020
+#define CNF_EVEN_HBAND              0x010
+#define CNF_FIRST_ROW_LAST_COLUMN   0x008
+#define CNF_FIRST_ROW_FIRST_COLUMN  0x004
+#define CNF_LAST_ROW_LAST_COLUMN    0x002
+#define CNF_LAST_ROW_FIRST_COLUMN   0x001
+
 CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(TableInfo & rInfo)
 {
 #ifdef DEBUG_DMAPPER_TABLE_HANDLER
@@ -523,21 +546,30 @@ CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(Tabl
         PropertyMapVector1::const_iterator aCellIterator = aRowOfCellsIterator->begin();
         PropertyMapVector1::const_iterator aCellIteratorEnd = aRowOfCellsIterator->end();
 
-        // Get the row style properties
-        sal_Int32 nRowStyleMask = sal_Int32( 0 );
-        PropertyMapPtr pRowProps = m_aRowProperties[nRow];
-        if ( pRowProps.get( ) )
+        sal_Int32 nRowStyleMask = 0;
+
+        if (aRowOfCellsIterator==m_aCellProperties.begin())
         {
-            PropertyMap::iterator pTcCnfStyleIt = pRowProps->find( PropertyDefinition( PROP_CNF_STYLE, true ) );
-            if ( pTcCnfStyleIt != pRowProps->end( ) )
-            {
-                if ( rInfo.pTableStyle )
-                {
-                    OUString sMask;
-                    pTcCnfStyleIt->second >>= sMask;
-                    nRowStyleMask = sMask.toInt32( 2 );
-                }
-                pRowProps->erase( pTcCnfStyleIt );
+            if(rInfo.nTblLook&0x20)
+                nRowStyleMask |= CNF_FIRST_ROW;     // first row style used
+        }
+        else if (aRowOfCellsIterator==aLastRowIterator)
+        {
+            if(rInfo.nTblLook&0x40)
+                nRowStyleMask |= CNF_LAST_ROW;      // last row style used
+        }
+        if(!nRowStyleMask)                          // if no row style used yet
+        {
+            // banding used only if not first and or last row style used
+            if(!(rInfo.nTblLook&0x200))
+            {   // hbanding used
+                int n = nRow + 1;
+                if(rInfo.nTblLook&0x20)
+                    n++;
+                if(n & 1)
+                    nRowStyleMask = CNF_ODD_HBAND;
+                else
+                    nRowStyleMask = CNF_EVEN_HBAND;
             }
         }
 
@@ -558,24 +590,44 @@ CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(Tabl
                 if ( rInfo.pTableDefaults->size( ) )
                     pAllCellProps->InsertProps(rInfo.pTableDefaults);
 
-                // Fill the cell properties with the ones of the style
                 sal_Int32 nCellStyleMask = 0;
-                const PropertyMap::iterator aCnfStyleIter =
-                    aCellIterator->get()->find( PropertyDefinition( PROP_CNF_STYLE, false ) );
-                if ( aCnfStyleIter != aCellIterator->get( )->end( ) )
+                if (aCellIterator==aRowOfCellsIterator->begin())
+                {
+                    if(rInfo.nTblLook&0x80)
+                        nCellStyleMask = CNF_FIRST_COLUMN;      // first col style used
+                }
+                else if (bIsEndCol)
+                {
+                    if(rInfo.nTblLook&0x100)
+                        nCellStyleMask = CNF_LAST_COLUMN;       // last col style used
+                }
+                if(!nCellStyleMask)                 // if no cell style is used yet
                 {
-                    if ( rInfo.pTableStyle ) {
-                        OUString sMask;
-                        aCnfStyleIter->second >>= sMask;
-                        nCellStyleMask = sMask.toInt32( 2 );
+                    if(!(rInfo.nTblLook&0x400))
+                    {   // vbanding used
+                        int n = nCell + 1;
+                        if(rInfo.nTblLook&0x80)
+                            n++;
+                        if(n & 1)
+                            nCellStyleMask = CNF_ODD_VBAND;
+                        else
+                            nCellStyleMask = CNF_EVEN_VBAND;
                     }
-                    aCellIterator->get( )->erase( aCnfStyleIter );
                 }
+                sal_Int32 nCnfStyleMask = nCellStyleMask + nRowStyleMask;
+                if(nCnfStyleMask == CNF_FIRST_COLUMN + CNF_FIRST_ROW)
+                    nCnfStyleMask |= CNF_FIRST_ROW_FIRST_COLUMN;
+                else if(nCnfStyleMask == CNF_FIRST_COLUMN + CNF_LAST_ROW)
+                    nCnfStyleMask |= CNF_LAST_ROW_FIRST_COLUMN;
+                else if(nCnfStyleMask == CNF_LAST_COLUMN + CNF_FIRST_ROW)
+                    nCnfStyleMask |= CNF_FIRST_ROW_LAST_COLUMN;
+                else if(nCnfStyleMask == CNF_LAST_COLUMN + CNF_LAST_ROW)
+                    nCnfStyleMask |= CNF_LAST_ROW_LAST_COLUMN;
 
                 if ( rInfo.pTableStyle )
                 {
-                    PropertyMapPtr pStyleProps = rInfo.pTableStyle->GetProperties( nCellStyleMask + nRowStyleMask );
-                    pAllCellProps->InsertProps(pStyleProps);
+                    PropertyMapPtr pStyleProps = rInfo.pTableStyle->GetProperties( nCnfStyleMask );
+                    pAllCellProps->InsertProps( pStyleProps );
                 }
 
                 // Remove properties from style/row that aren't allowed in cells
diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.cxx b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
index cb96046..bbdb53d 100644
--- a/writerfilter/source/dmapper/DomainMapperTableManager.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
@@ -267,7 +267,12 @@ bool DomainMapperTableManager::sprm(Sprm & rSprm)
             }
             break;
             case NS_ooxml::LN_CT_TblPrBase_tblLook:
-                break; //todo: table look specifier
+            {
+                TablePropertyMapPtr pPropMap( new TablePropertyMap );
+                pPropMap->Insert( PROP_TBL_LOOK, false, uno::makeAny( nIntValue ));
+                insertTableProps(pPropMap);
+            }
+            break;
             case NS_ooxml::LN_CT_TcPrBase_textDirection:
             {
                 TablePropertyMapPtr pPropMap( new TablePropertyMap );
@@ -328,22 +333,12 @@ bool DomainMapperTableManager::sprm(Sprm & rSprm)
                 }
                 break;
             case NS_ooxml::LN_CT_TrPrBase_cnfStyle:
-                {
-                    TablePropertyMapPtr pProps( new TablePropertyMap );
-                    pProps->Insert( PROP_CNF_STYLE, true, uno::makeAny( pValue->getString( ) ) );
-                    insertRowProps( pProps );
-                }
-                break;
+                break;  // the cnfStyle doesn't matter, instead the tblLook property is used to specify conditional styles that are to be used
             case NS_ooxml::LN_CT_PPrBase_cnfStyle:
                 // TODO cnfStyle on a paragraph
                 break;
             case NS_ooxml::LN_CT_TcPrBase_cnfStyle:
-                {
-                    TablePropertyMapPtr pProps( new TablePropertyMap );
-                    pProps->Insert( PROP_CNF_STYLE, true, uno::makeAny( pValue->getString( ) ) );
-                    cellProps( pProps );
-                }
-                break;
+                break;  // the cnfStyle doesn't matter, instead the tblLook property is used to specify conditional styles that are to be used
             case NS_ooxml::LN_CT_TblPrBase_tblpPr:
                 {
                     writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
diff --git a/writerfilter/source/dmapper/PropertyIds.cxx b/writerfilter/source/dmapper/PropertyIds.cxx
index 1d432fc..1ad4c11 100644
--- a/writerfilter/source/dmapper/PropertyIds.cxx
+++ b/writerfilter/source/dmapper/PropertyIds.cxx
@@ -279,7 +279,8 @@ const OUString& PropertyNameSupplier::GetName( PropertyIds eId ) const
             case PROP_SOURCE_NAME:    sName = "SourceName"; break;
             case PROP_REFERENCE_FIELD_SOURCE :    sName = "ReferenceFieldSource"; break;
             case PROP_WIDTH_TYPE :    sName = "WidthType"; break;
-            case  PROP_TEXT_RANGE:    sName = "TextRange"; break;
+            case PROP_TBL_LOOK : sName = "TblLook"; break;
+            case PROP_TEXT_RANGE:    sName = "TextRange"; break;
             case PROP_SERVICE_CHAR_STYLE       :    sName = "com.sun.star.style.CharacterStyle"; break;
             case PROP_SERVICE_PARA_STYLE       :    sName = "com.sun.star.style.ParagraphStyle"; break;
             case PROP_CHARACTER_STYLES :    sName = "CharacterStyles"; break;
@@ -302,7 +303,6 @@ const OUString& PropertyNameSupplier::GetName( PropertyIds eId ) const
             case PROP_BITMAP :    sName = "Bitmap"; break;
             case PROP_IS_DATE :   sName = "IsDate"; break;
             case PROP_TAB_STOP_DISTANCE :    sName = "TabStopDistance"; break;
-            case PROP_CNF_STYLE  :    sName = "CnfStyle"; break;
             case PROP_INDENT_AT :    sName = "IndentAt"; break;
             case PROP_FIRST_LINE_INDENT :    sName = "FirstLineIndent"; break;
             case PROP_NUMBERING_STYLE_NAME  :    sName = "NumberingStyleName"; break;
diff --git a/writerfilter/source/dmapper/PropertyIds.hxx b/writerfilter/source/dmapper/PropertyIds.hxx
index c61283c..460ff33 100644
--- a/writerfilter/source/dmapper/PropertyIds.hxx
+++ b/writerfilter/source/dmapper/PropertyIds.hxx
@@ -107,7 +107,6 @@ enum PropertyIds
         ,PROP_CHAR_WEIGHT_ASIAN
         ,PROP_CHAR_WEIGHT_COMPLEX
         ,PROP_CHAR_WORD_MODE
-        ,PROP_CNF_STYLE
         ,PROP_CONTENT
         ,PROP_CONTOUR_OUTSIDE
         ,PROP_CONTOUR_POLY_POLYGON
@@ -283,6 +282,7 @@ enum PropertyIds
         ,PROP_VERT_ORIENT_RELATION
         ,PROP_WIDTH
         ,PROP_WIDTH_TYPE
+        ,PROP_TBL_LOOK
         ,PROP_WRITING_MODE
 /*253*/ ,PROP_FRM_DIRECTION
         ,PROP_EMBEDDED_OBJECT
diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx b/writerfilter/source/dmapper/StyleSheetTable.cxx
index 6e38673..2a216fe 100644
--- a/writerfilter/source/dmapper/StyleSheetTable.cxx
+++ b/writerfilter/source/dmapper/StyleSheetTable.cxx
@@ -217,40 +217,35 @@ void lcl_mergeProps( PropertyMapPtr pToFill,  PropertyMapPtr pToAdd, TblStyleTyp
 PropertyMapPtr TableStyleSheetEntry::GetLocalPropertiesFromMask( sal_Int32 nMask )
 {
     // Order from right to left
-    static const TblStyleType aBitsOrder[] =
+    struct TblStyleTypeAndMask {
+        sal_Int32       mask;
+        TblStyleType    type;
+    };
+
+    static const TblStyleTypeAndMask aOrderedStyleTable[] =
     {
-        TBL_STYLE_SWCELL,
-        TBL_STYLE_SECELL,
-        TBL_STYLE_NWCELL,
-        TBL_STYLE_NECELL,
-        TBL_STYLE_BAND2HORZ,
-        TBL_STYLE_BAND1HORZ,
-        TBL_STYLE_BAND2VERT,
-        TBL_STYLE_BAND1VERT,
-        TBL_STYLE_LASTCOL,
-        TBL_STYLE_FIRSTCOL,
-        TBL_STYLE_LASTROW,
-        TBL_STYLE_FIRSTROW,
-        TBL_STYLE_UNKNOWN
+        { 0x010, TBL_STYLE_BAND2HORZ },
+        { 0x020, TBL_STYLE_BAND1HORZ },
+        { 0x040, TBL_STYLE_BAND2VERT },
+        { 0x080, TBL_STYLE_BAND1VERT },
+        { 0x100, TBL_STYLE_LASTCOL  },
+        { 0x200, TBL_STYLE_FIRSTCOL },
+        { 0x400, TBL_STYLE_LASTROW  },
+        { 0x800, TBL_STYLE_FIRSTROW },
+        { 0x001, TBL_STYLE_SWCELL },
+        { 0x002, TBL_STYLE_SECELL },
+        { 0x004, TBL_STYLE_NWCELL },
+        { 0x008, TBL_STYLE_NECELL }
     };
 
     // Get the properties applying according to the mask
     PropertyMapPtr pProps( new PropertyMap( ) );
-    short nBit = 0;
-    do
+    for( int i = 0; i < sizeof( aOrderedStyleTable ); i++ )
     {
-        TblStyleType nStyleId = aBitsOrder[nBit];
-        TblStylePrs::iterator pIt = m_aStyles.find( nStyleId );
-
-        short nTestBit = 1 << nBit;
-        sal_Int32 nBitMask = sal_Int32( nTestBit );
-        if ( ( nMask & nBitMask ) && ( pIt != m_aStyles.end( ) ) )
-            lcl_mergeProps( pProps, pIt->second, nStyleId );
-
-        nBit++;
+        TblStylePrs::iterator pIt = m_aStyles.find( aOrderedStyleTable[ i ].type );
+        if ( ( nMask & aOrderedStyleTable[ i ].mask ) && ( pIt != m_aStyles.end( ) ) )
+            lcl_mergeProps( pProps, pIt->second, aOrderedStyleTable[ i ].type );
     }
-    while ( nBit < 13 );
-
     return pProps;
 }
 


More information about the Libreoffice-commits mailing list