diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-01-08 01:20:22 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-01-08 09:21:11 -0500 |
commit | 94874973769fee81f8ab35b2aeb0dc22812a2b48 (patch) | |
tree | fe49d0ed7b71b76fcef49bf6d1dffac920a4c3b9 /sc | |
parent | d7853c1fab14c943b6b2535580f64810b22e225d (diff) |
Add new ods import test for rich-text cell contents.
Change-Id: I23eb8d53b8a2c48514900a5ab07ed7ec71d3ef99
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/column.hxx | 1 | ||||
-rw-r--r-- | sc/inc/document.hxx | 2 | ||||
-rw-r--r-- | sc/inc/table.hxx | 1 | ||||
-rw-r--r-- | sc/qa/unit/data/ods/rich-text-cells.ods | bin | 0 -> 11904 bytes | |||
-rw-r--r-- | sc/qa/unit/subsequent_filters-test.cxx | 183 | ||||
-rw-r--r-- | sc/source/core/data/column3.cxx | 13 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 8 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 7 |
8 files changed, 215 insertions, 0 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 7abce092966a..96df4d99403f 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -228,6 +228,7 @@ public: void GetString( SCROW nRow, rtl::OUString& rString ) const; void GetInputString( SCROW nRow, rtl::OUString& rString ) const; double GetValue( SCROW nRow ) const; + const EditTextObject* GetEditText( SCROW nRow ) const; void GetFormula( SCROW nRow, rtl::OUString& rFormula ) const; CellType GetCellType( SCROW nRow ) const; SCSIZE GetCellCount() const; diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 5b5a472d95a7..a72f7596cd2d 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -144,6 +144,7 @@ class ScProgress; class SvtListener; class ScNotes; class ScEditDataArray; +class EditTextObject; namespace com { namespace sun { namespace star { namespace lang { @@ -772,6 +773,7 @@ public: SC_DLLPUBLIC double GetValue( const ScAddress& ); SC_DLLPUBLIC double GetValue( const SCCOL nCol, SCROW nRow, SCTAB nTab) { ScAddress aAdr(nCol, nRow, nTab); return GetValue(aAdr);} SC_DLLPUBLIC void GetValue( SCCOL nCol, SCROW nRow, SCTAB nTab, double& rValue ); + SC_DLLPUBLIC const EditTextObject* GetEditText( const ScAddress& rPos ) const; SC_DLLPUBLIC double RoundValueAsShown( double fVal, sal_uLong nFormat ); SC_DLLPUBLIC void GetNumberFormat( SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt32& rFormat ) const; diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 512dee2b87cc..fa03a7f1e292 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -310,6 +310,7 @@ public: 0.0; } double GetValue( SCCOL nCol, SCROW nRow ) const; + const EditTextObject* GetEditText( SCCOL nCol, SCROW nRow ) const; void GetFormula( SCCOL nCol, SCROW nRow, rtl::OUString& rFormula ); CellType GetCellType( const ScAddress& rPos ) const diff --git a/sc/qa/unit/data/ods/rich-text-cells.ods b/sc/qa/unit/data/ods/rich-text-cells.ods Binary files differnew file mode 100644 index 000000000000..d60747a05c53 --- /dev/null +++ b/sc/qa/unit/data/ods/rich-text-cells.ods diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx index 04a7ffeee618..f56bd6676e47 100644 --- a/sc/qa/unit/subsequent_filters-test.cxx +++ b/sc/qa/unit/subsequent_filters-test.cxx @@ -40,6 +40,10 @@ #include <svl/stritem.hxx> #include "svx/svdpage.hxx" +#include "editeng/wghtitem.hxx" +#include "editeng/postitem.hxx" +#include "editeng/udlnitem.hxx" +#include "editeng/editobj.hxx" #include <editeng/brshitem.hxx> #include <editeng/justifyitem.hxx> #include <editeng/borderline.hxx> @@ -59,6 +63,7 @@ #include <com/sun/star/sheet/GeneralFunction.hpp> #include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/text/textfield/Type.hpp> #define CALC_DEBUG_OUTPUT 0 #define TEST_BUG_FILES 0 @@ -171,6 +176,7 @@ public: void testFormulaDependency(); void testRowHeightODS(); + void testRichTextContentODS(); CPPUNIT_TEST_SUITE(ScFiltersTest); CPPUNIT_TEST(testRangeNameXLS); @@ -215,6 +221,7 @@ public: CPPUNIT_TEST(testPivotTableBasicODS); CPPUNIT_TEST(testRowHeightODS); CPPUNIT_TEST(testFormulaDependency); + CPPUNIT_TEST(testRichTextContentODS); //disable testPassword on MacOSX due to problems with libsqlite3 //also crashes on DragonFly due to problems with nss/nspr headers @@ -1516,6 +1523,182 @@ void ScFiltersTest::testRowHeightODS() xDocSh->DoClose(); } +void ScFiltersTest::testRichTextContentODS() +{ + ScDocShellRef xDocSh = loadDoc("rich-text-cells.", ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to load rich-text-cells.ods", xDocSh.Is()); + ScDocument* pDoc = xDocSh->GetDocument(); + + OUString aTabName; + CPPUNIT_ASSERT_MESSAGE("Failed to get the name of the first sheet.", pDoc->GetName(0, aTabName)); + + // All tested cells are in the first column. + ScAddress aPos(0, 0, 0); + + // Normal simple string with no formatting. + aPos.IncRow(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString("Normal"), pDoc->GetString(aPos.Col(), aPos.Row(), aPos.Tab())); + + // Normal string with bold applied to the whole cell. + { + aPos.IncRow(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString("All bold"), pDoc->GetString(aPos.Col(), aPos.Row(), aPos.Tab())); + const ScPatternAttr* pAttr = pDoc->GetPattern(aPos.Col(), aPos.Row(), aPos.Tab()); + CPPUNIT_ASSERT_MESSAGE("Failed to get cell attribute.", pAttr); + const SvxWeightItem& rWeightItem = + static_cast<const SvxWeightItem&>(pAttr->GetItem(ATTR_FONT_WEIGHT)); + CPPUNIT_ASSERT_EQUAL(WEIGHT_BOLD, rWeightItem.GetWeight()); + } + + // This cell has an unformatted but multi-line content. Multi-line text is + // stored in edit cell even if it has no formatting applied. + aPos.IncRow(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_EDIT, pDoc->GetCellType(aPos)); + const EditTextObject* pEditText = pDoc->GetEditText(aPos); + CPPUNIT_ASSERT_MESSAGE("Failed to retrieve edit text object.", pEditText); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), pEditText->GetParagraphCount()); + OUString aParaText = pEditText->GetText(0); + CPPUNIT_ASSERT_EQUAL(OUString("one"), aParaText); + aParaText = pEditText->GetText(1); + CPPUNIT_ASSERT_EQUAL(OUString("two"), aParaText); + aParaText = pEditText->GetText(2); + CPPUNIT_ASSERT_EQUAL(OUString("three"), aParaText); + + // Cell with sheet name field item. + aPos.IncRow(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_EDIT, pDoc->GetCellType(aPos)); + pEditText = pDoc->GetEditText(aPos); + CPPUNIT_ASSERT_MESSAGE("Failed to retrieve edit text object.", pEditText); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pEditText->GetParagraphCount()); + aParaText = pEditText->GetText(0); + CPPUNIT_ASSERT_MESSAGE("Unexpected text.", aParaText.indexOf("Sheet name is ") == 0); + CPPUNIT_ASSERT_MESSAGE("Sheet name field item not found.", pEditText->HasField(text::textfield::Type::TABLE)); + + // Cell with URL field item. + aPos.IncRow(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_EDIT, pDoc->GetCellType(aPos)); + pEditText = pDoc->GetEditText(aPos); + CPPUNIT_ASSERT_MESSAGE("Failed to retrieve edit text object.", pEditText); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pEditText->GetParagraphCount()); + aParaText = pEditText->GetText(0); + CPPUNIT_ASSERT_MESSAGE("Unexpected text.", aParaText.indexOf("URL: ") == 0); + CPPUNIT_ASSERT_MESSAGE("URL field item not found.", pEditText->HasField(text::textfield::Type::URL)); + + // Cell with Date field item. + aPos.IncRow(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_EDIT, pDoc->GetCellType(aPos)); + pEditText = pDoc->GetEditText(aPos); + CPPUNIT_ASSERT_MESSAGE("Failed to retrieve edit text object.", pEditText); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pEditText->GetParagraphCount()); + aParaText = pEditText->GetText(0); + CPPUNIT_ASSERT_MESSAGE("Unexpected text.", aParaText.indexOf("Date: ") == 0); + CPPUNIT_ASSERT_MESSAGE("Date field item not found.", pEditText->HasField(text::textfield::Type::DATE)); + + // Cell with DocInfo title field item. + aPos.IncRow(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_EDIT, pDoc->GetCellType(aPos)); + pEditText = pDoc->GetEditText(aPos); + CPPUNIT_ASSERT_MESSAGE("Failed to retrieve edit text object.", pEditText); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pEditText->GetParagraphCount()); + aParaText = pEditText->GetText(0); + CPPUNIT_ASSERT_MESSAGE("Unexpected text.", aParaText.indexOf("Title: ") == 0); + CPPUNIT_ASSERT_MESSAGE("DocInfo title field item not found.", pEditText->HasField(text::textfield::Type::DOCINFO_TITLE)); + + // Cell with sentence with both bold and italic sequences. + aPos.IncRow(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_EDIT, pDoc->GetCellType(aPos)); + pEditText = pDoc->GetEditText(aPos); + CPPUNIT_ASSERT_MESSAGE("Failed to retrieve edit text object.", pEditText); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pEditText->GetParagraphCount()); + aParaText = pEditText->GetText(0); + CPPUNIT_ASSERT_EQUAL(OUString("Sentence with bold and italic."), aParaText); + std::vector<EECharAttrib> aAttribs; + pEditText->GetCharAttribs(0, aAttribs); + std::vector<EECharAttrib>::const_iterator it = aAttribs.begin(), itEnd = aAttribs.end(); + { + bool bHasBold = false, bHasItalic = false; + for (; it != itEnd; ++it) + { + OUString aSeg = aParaText.copy(it->nStart, it->nEnd - it->nStart); + const SfxPoolItem* pAttr = it->pAttr; + if (aSeg == "bold" && pAttr->Which() == EE_CHAR_WEIGHT && !bHasBold) + { + const SvxWeightItem& rItem = static_cast<const SvxWeightItem&>(*pAttr); + bHasBold = (rItem.GetWeight() == WEIGHT_BOLD); + } + else if (aSeg == "italic" && pAttr->Which() == EE_CHAR_ITALIC && !bHasItalic) + { + const SvxPostureItem& rItem = static_cast<const SvxPostureItem&>(*pAttr); + bHasItalic = (rItem.GetPosture() == ITALIC_NORMAL); + + } + } + CPPUNIT_ASSERT_MESSAGE("This sentence is expected to have both bold and italic sequences.", bHasBold && bHasItalic); + } + + // Cell with multi-line content with formatting applied. + aPos.IncRow(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_EDIT, pDoc->GetCellType(aPos)); + pEditText = pDoc->GetEditText(aPos); + CPPUNIT_ASSERT_MESSAGE("Failed to retrieve edit text object.", pEditText); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), pEditText->GetParagraphCount()); + aParaText = pEditText->GetText(0); + CPPUNIT_ASSERT_EQUAL(OUString("bold"), aParaText); + aParaText = pEditText->GetText(1); + CPPUNIT_ASSERT_EQUAL(OUString("italic"), aParaText); + aParaText = pEditText->GetText(2); + CPPUNIT_ASSERT_EQUAL(OUString("underlined"), aParaText); + + // first line is bold. + pEditText->GetCharAttribs(0, aAttribs); + bool bHasBold = false; + for (it = aAttribs.begin(), itEnd = aAttribs.end(); it != itEnd; ++it) + { + if (it->pAttr->Which() == EE_CHAR_WEIGHT) + { + const SvxWeightItem& rItem = static_cast<const SvxWeightItem&>(*it->pAttr); + bHasBold = (rItem.GetWeight() == WEIGHT_BOLD); + if (bHasBold) + break; + } + } + CPPUNIT_ASSERT_MESSAGE("First line should be bold.", bHasBold); + + // second line is italic. + pEditText->GetCharAttribs(1, aAttribs); + bool bHasItalic = false; + for (it = aAttribs.begin(), itEnd = aAttribs.end(); it != itEnd; ++it) + { + if (it->pAttr->Which() == EE_CHAR_ITALIC) + { + const SvxPostureItem& rItem = static_cast<const SvxPostureItem&>(*it->pAttr); + bHasItalic = (rItem.GetPosture() == ITALIC_NORMAL); + if (bHasItalic) + break; + } + } + CPPUNIT_ASSERT_MESSAGE("Second line should be italic.", bHasItalic); + + // third line is underlined. + pEditText->GetCharAttribs(2, aAttribs); + bool bHasUnderline = false; + for (it = aAttribs.begin(), itEnd = aAttribs.end(); it != itEnd; ++it) + { + if (it->pAttr->Which() == EE_CHAR_UNDERLINE) + { + const SvxUnderlineItem& rItem = static_cast<const SvxUnderlineItem&>(*it->pAttr); + bHasUnderline = (rItem.GetLineStyle() == UNDERLINE_SINGLE); + if (bHasUnderline) + break; + } + } + CPPUNIT_ASSERT_MESSAGE("Second line should be underlined.", bHasUnderline); + + xDocSh->DoClose(); +} + namespace { void testColorScaleFormat_Impl(const rtl::OUString& rFilePath, const ScConditionalFormat* pFormat) diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index ad8444d5741d..1e0ce3c51653 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -1730,6 +1730,19 @@ double ScColumn::GetValue( SCROW nRow ) const return 0.0; } +const EditTextObject* ScColumn::GetEditText( SCROW nRow ) const +{ + SCSIZE nIndex; + if (!Search(nRow, nIndex)) + return NULL; + + const ScBaseCell* pCell = maItems[nIndex].pCell; + if (pCell->GetCellType() != CELLTYPE_EDIT) + return NULL; + + const ScEditCell* pEditCell = static_cast<const ScEditCell*>(pCell); + return pEditCell->GetData(); +} void ScColumn::GetFormula( SCROW nRow, rtl::OUString& rFormula ) const { diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 9d8a8c387db0..78ae82355230 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -3015,6 +3015,14 @@ void ScDocument::GetValue( SCCOL nCol, SCROW nRow, SCTAB nTab, double& rValue ) rValue = 0.0; } +const EditTextObject* ScDocument::GetEditText( const ScAddress& rPos ) const +{ + SCTAB nTab = rPos.Tab(); + if (!ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab]) + return NULL; + + return maTabs[nTab]->GetEditText(rPos.Col(), rPos.Row()); +} double ScDocument::GetValue( const ScAddress& rPos ) { diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 073f7263f60e..6087841ce86d 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1297,6 +1297,13 @@ double ScTable::GetValue( SCCOL nCol, SCROW nRow ) const return 0.0; } +const EditTextObject* ScTable::GetEditText( SCCOL nCol, SCROW nRow ) const +{ + if (!ValidColRow(nCol, nRow)) + return NULL; + + return aCol[nCol].GetEditText(nRow); +} void ScTable::GetFormula( SCCOL nCol, SCROW nRow, rtl::OUString& rFormula ) { |