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

Katarina Behrens Katarina.Behrens at cib.de
Fri Mar 4 11:17:09 UTC 2016


 sc/qa/unit/data/xls/cellformat.xls    |binary
 sc/qa/unit/subsequent_export-test.cxx |   39 ++++++++++++++++++++++++++++++++++
 sc/source/filter/excel/xestring.cxx   |   11 ++++++++-
 sc/source/filter/excel/xetable.cxx    |   25 ++++++++++++---------
 sc/source/filter/inc/xestring.hxx     |    4 ++-
 5 files changed, 66 insertions(+), 13 deletions(-)

New commits:
commit ff45bc33465d54253f9e3da2e24b1b2b09c2b1d9
Author: Katarina Behrens <Katarina.Behrens at cib.de>
Date:   Mon Feb 29 11:23:33 2016 +0100

    tdf#98083: Always save cell format
    
    it was pretty bad idea not to save it for rich-formatted cells
    (tdf#92296) as there is more to cell format than just a font
    
    Change-Id: I0e5e7d7187c69519bb8f4de2b627e385fccd3d46
    Reviewed-on: https://gerrit.libreoffice.org/22762
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>

diff --git a/sc/qa/unit/data/xls/cellformat.xls b/sc/qa/unit/data/xls/cellformat.xls
new file mode 100644
index 0000000..bdb6c30
Binary files /dev/null and b/sc/qa/unit/data/xls/cellformat.xls differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index ba14452..4c6e6d8 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -101,6 +101,7 @@ public:
     void testMiscRowHeightExport();
     void testNamedRangeBugfdo62729();
     void testRichTextExportODS();
+    void testRichTextCellFormat();
     void testFormulaRefSheetNameODS();
 
     void testCellValuesExportODS();
@@ -177,6 +178,7 @@ public:
     CPPUNIT_TEST(testMiscRowHeightExport);
     CPPUNIT_TEST(testNamedRangeBugfdo62729);
     CPPUNIT_TEST(testRichTextExportODS);
+    CPPUNIT_TEST(testRichTextCellFormat);
     CPPUNIT_TEST(testFormulaRefSheetNameODS);
     CPPUNIT_TEST(testCellValuesExportODS);
     CPPUNIT_TEST(testCellNoteExportODS);
@@ -1093,6 +1095,43 @@ void ScExportTest::testRichTextExportODS()
     xNewDocSh3->DoClose();
 }
 
+void ScExportTest::testRichTextCellFormat()
+{
+    ScDocShellRef xDocSh = loadDoc("cellformat.", FORMAT_XLS);
+    CPPUNIT_ASSERT(xDocSh.Is());
+
+    xmlDocPtr pSheet = XPathHelper::parseExport(&(*xDocSh), m_xSFactory, "xl/worksheets/sheet1.xml", FORMAT_XLSX);
+    CPPUNIT_ASSERT(pSheet);
+
+    // make sure the only cell in this doc is assigned some formatting record
+    OUString aCellFormat = getXPath(pSheet, "/x:worksheet/x:sheetData/x:row/x:c", "s");
+    CPPUNIT_ASSERT_MESSAGE("Cell format is missing", !aCellFormat.isEmpty());
+
+    xDocSh->DoClose();
+    //FIXME: this shouldn't be necessary, but for some reason 2nd and every consecutive call
+    //to parseExport() (different stream name within the same doc, of course) doesn't find
+    //the stream anymore. I have neither knowledge nor time to debug it
+    ScDocShellRef xNewDocSh = loadDoc("cellformat.", FORMAT_XLS);
+
+    xmlDocPtr pStyles = XPathHelper::parseExport(&(*xNewDocSh), m_xSFactory, "xl/styles.xml", FORMAT_XLSX);
+    CPPUNIT_ASSERT(pStyles);
+
+    OString nFormatIdx = OString::number( aCellFormat.toInt32() + 1 );
+    const OString xPath1( "/x:styleSheet/x:cellXfs/x:xf[" + nFormatIdx + "]/x:alignment" );
+    // formatting record is set to wrap text
+    assertXPath(pStyles, xPath1, "wrapText", "true");
+
+    // see what font it references
+    const OString xPath2( "/x:styleSheet/x:cellXfs/x:xf[" + nFormatIdx +"]" );
+    OUString aFontId = getXPath(pStyles, xPath2, "fontId");
+    OString nFontIdx = OString::number( aFontId.toInt32() + 1 );
+
+    // that font should be bold
+    const OString xPath3("/x:styleSheet/x:fonts/x:font[" + nFontIdx + "]/x:b");
+    assertXPath(pStyles, xPath3, "val", "true");
+
+}
+
 void ScExportTest::testFormulaRefSheetNameODS()
 {
     ScDocShellRef xDocSh = loadDoc("formula-quote-in-sheet-name.", FORMAT_ODS, true);
diff --git a/sc/source/filter/excel/xestring.cxx b/sc/source/filter/excel/xestring.cxx
index ca271fc..cdb1601 100644
--- a/sc/source/filter/excel/xestring.cxx
+++ b/sc/source/filter/excel/xestring.cxx
@@ -178,12 +178,21 @@ void XclExpString::LimitFormatCount( sal_uInt16 nMaxCount )
         maFormats.erase( maFormats.begin() + nMaxCount, maFormats.end() );
 }
 
-sal_uInt16 XclExpString::RemoveLeadingFont()
+sal_uInt16 XclExpString::GetLeadingFont()
 {
     sal_uInt16 nFontIdx = EXC_FONT_NOTFOUND;
     if( !maFormats.empty() && (maFormats.front().mnChar == 0) )
     {
         nFontIdx = maFormats.front().mnFontIdx;
+    }
+    return nFontIdx;
+}
+
+sal_uInt16 XclExpString::RemoveLeadingFont()
+{
+    sal_uInt16 nFontIdx = GetLeadingFont();
+    if( nFontIdx != EXC_FONT_NOTFOUND )
+    {
         maFormats.erase( maFormats.begin() );
     }
     return nFontIdx;
diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx
index cfc3fa7..0302c9e 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -724,18 +724,21 @@ void XclExpLabelCell::Init( const XclExpRoot& rRoot,
     mnSstIndex = 0;
 
     const XclFormatRunVec& rFormats = mxText->GetFormats();
-    // Create the cell format and remove formatting of the leading run
-    // if the entire string is equally formatted
+    // remove formatting of the leading run if the entire string
+    // is equally formatted
+    sal_uInt16 nXclFont = EXC_FONT_NOTFOUND;
     if( rFormats.size() == 1 )
-    {
-        sal_uInt16 nXclFont = mxText->RemoveLeadingFont();
-        if( GetXFId() == EXC_XFID_NOTFOUND )
-        {
-            OSL_ENSURE( nXclFont != EXC_FONT_NOTFOUND, "XclExpLabelCell::Init - leading font not found" );
-            bool bForceLineBreak = mxText->IsWrapped();
-            SetXFId( rRoot.GetXFBuffer().InsertWithFont( pPattern, ApiScriptType::WEAK, nXclFont, bForceLineBreak ) );
-        }
-    }
+        nXclFont = mxText->RemoveLeadingFont();
+    else
+        nXclFont = mxText->GetLeadingFont();
+
+   // create cell format
+   if( GetXFId() == EXC_XFID_NOTFOUND )
+   {
+       OSL_ENSURE( nXclFont != EXC_FONT_NOTFOUND, "XclExpLabelCell::Init - leading font not found" );
+       bool bForceLineBreak = mxText->IsWrapped();
+       SetXFId( rRoot.GetXFBuffer().InsertWithFont( pPattern, ApiScriptType::WEAK, nXclFont, bForceLineBreak ) );
+   }
 
     // get auto-wrap attribute from cell format
     const XclExpXF* pXF = rRoot.GetXFBuffer().GetXFById( GetXFId() );
diff --git a/sc/source/filter/inc/xestring.hxx b/sc/source/filter/inc/xestring.hxx
index c1fb351..60956b6 100644
--- a/sc/source/filter/inc/xestring.hxx
+++ b/sc/source/filter/inc/xestring.hxx
@@ -103,7 +103,9 @@ public:
     void                AppendTrailingFormat( sal_uInt16 nFontIdx );
     /** Removes formatting runs at the end, if the string contains too much. */
     void                LimitFormatCount( sal_uInt16 nMaxCount );
-    /** Removes and returns the font index for the first char from the formatting runs, otherwise EXC_FONT_NOTFOUND. */
+    /** Returns the font index of the first char in the formatting run, or EXC_FONT_NOTFOUND. */
+    sal_uInt16          GetLeadingFont();
+    /** The same as above + additionally remove the given font from the formatting run*/
     sal_uInt16          RemoveLeadingFont();
 
     // get data ---------------------------------------------------------------


More information about the Libreoffice-commits mailing list