[Libreoffice-commits] .: editeng/inc editeng/source sc/inc sc/qa sc/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Jan 8 06:20:53 PST 2013
editeng/inc/editeng/editobj.hxx | 1
editeng/source/editeng/editobj.cxx | 21 +++
editeng/source/editeng/editobj2.hxx | 1
sc/inc/column.hxx | 1
sc/inc/document.hxx | 2
sc/inc/table.hxx | 1
sc/qa/unit/data/ods/rich-text-cells.ods |binary
sc/qa/unit/subsequent_filters-test.cxx | 183 ++++++++++++++++++++++++++++++++
sc/source/core/data/column3.cxx | 13 ++
sc/source/core/data/document.cxx | 8 +
sc/source/core/data/table2.cxx | 7 +
11 files changed, 238 insertions(+)
New commits:
commit 94874973769fee81f8ab35b2aeb0dc22812a2b48
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Tue Jan 8 01:20:22 2013 -0500
Add new ods import test for rich-text cell contents.
Change-Id: I23eb8d53b8a2c48514900a5ab07ed7ec71d3ef99
diff --git a/editeng/inc/editeng/editobj.hxx b/editeng/inc/editeng/editobj.hxx
index 2730b46..8e97b63 100644
--- a/editeng/inc/editeng/editobj.hxx
+++ b/editeng/inc/editeng/editobj.hxx
@@ -102,6 +102,7 @@ public:
virtual sal_Bool IsFieldObject() const;
virtual const SvxFieldItem* GetField() const;
virtual sal_Bool HasField( TypeId aType = NULL ) const;
+ virtual bool HasField( sal_Int32 nType ) const = 0;
virtual SfxItemSet GetParaAttribs(size_t nPara) const;
virtual void SetParaAttribs(size_t nPara, const SfxItemSet& rAttribs);
diff --git a/editeng/source/editeng/editobj.cxx b/editeng/source/editeng/editobj.cxx
index 275aa77..56effb9 100644
--- a/editeng/source/editeng/editobj.cxx
+++ b/editeng/source/editeng/editobj.cxx
@@ -878,6 +878,27 @@ sal_Bool BinTextObject::HasField( TypeId aType ) const
return false;
}
+bool BinTextObject::HasField( sal_Int32 nType ) const
+{
+ size_t nParagraphs = aContents.size();
+ for (size_t nPara = 0; nPara < nParagraphs; ++nPara)
+ {
+ const ContentInfo& rC = aContents[nPara];
+ size_t nAttrs = rC.aAttribs.size();
+ for (size_t nAttr = 0; nAttr < nAttrs; ++nAttr)
+ {
+ const XEditAttribute& rAttr = rC.aAttribs[nAttr];
+ if (rAttr.GetItem()->Which() != EE_FEATURE_FIELD)
+ continue;
+
+ const SvxFieldData* pFldData = static_cast<const SvxFieldItem*>(rAttr.GetItem())->GetField();
+ if (pFldData && pFldData->GetClassId() == nType)
+ return true;
+ }
+ }
+ return false;
+}
+
SfxItemSet BinTextObject::GetParaAttribs(size_t nPara) const
{
const ContentInfo& rC = aContents[nPara];
diff --git a/editeng/source/editeng/editobj2.hxx b/editeng/source/editeng/editobj2.hxx
index 4b89ade..52821c0 100644
--- a/editeng/source/editeng/editobj2.hxx
+++ b/editeng/source/editeng/editobj2.hxx
@@ -233,6 +233,7 @@ public:
virtual sal_Bool IsFieldObject() const;
virtual const SvxFieldItem* GetField() const;
virtual sal_Bool HasField( TypeId Type = NULL ) const;
+ virtual bool HasField( sal_Int32 nType ) const;
virtual SfxItemSet GetParaAttribs(size_t nPara) const;
virtual void SetParaAttribs(size_t nPara, const SfxItemSet& rAttribs);
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 7abce09..96df4d9 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 5b5a472..a72f759 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 512dee2..fa03a7f 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
new file mode 100644
index 0000000..d60747a
Binary files /dev/null and b/sc/qa/unit/data/ods/rich-text-cells.ods differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 04a7ffe..f56bd66 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 ad8444d..1e0ce3c 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 9d8a8c3..78ae823 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 073f726..6087841c 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 )
{
More information about the Libreoffice-commits
mailing list