sc/qa/unit/subsequent_export-test.cxx | 113 ++++++++++++++++++++++++++++------ sc/source/filter/xml/xmlexprt.cxx | 14 +++- 2 files changed, 107 insertions(+), 20 deletions(-)
New commits: commit 48eccfb812284f43ba24c3be3903537ce954944d Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Thu May 15 20:32:05 2014 -0400 fdo#77537: Exporting font names in edit text needs special handling. Change-Id: Ia9c29d37eaf962e0245920e50f534dd779af72dc diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx index b1f831d..737a881 100644 --- a/sc/source/filter/xml/xmlexprt.cxx +++ b/sc/source/filter/xml/xmlexprt.cxx @@ -1116,10 +1116,18 @@ const SvxFieldData* toXMLPropertyStates( case EE_CHAR_FONTINFO_CJK: case EE_CHAR_FONTINFO_CTL: { - if (!static_cast<const SvxFontItem*>(p)->QueryValue(aAny, pEntry->mnFlag)) - continue; + // Apparently font info needs special handling. + const SvxFontItem* pItem = static_cast<const SvxFontItem*>(p); - rPropStates.push_back(XMLPropertyState(nIndex, aAny)); + sal_Int32 nIndexFontName = xMapper->GetEntryIndex(XML_NAMESPACE_STYLE, "font-name", 0); + + if (nIndexFontName == -1 || nIndexFontName >= nEntryCount) + break; + + if (!pItem->QueryValue(aAny, MID_FONT_FAMILY_NAME)) + break; + + rPropStates.push_back(XMLPropertyState(nIndexFontName, aAny)); } break; case EE_CHAR_WEIGHT: commit 90f7bd61fb1c4665051f721bb7721277a79eb267 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Thu May 15 20:27:44 2014 -0400 fdo#77537: Write export test for this. Change-Id: I2960713b1005c5f91fe78d12e33f1786978eac67 diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index f984e69..ab25140 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -44,6 +44,7 @@ #include <editeng/section.hxx> #include <editeng/crossedoutitem.hxx> #include <editeng/borderline.hxx> +#include <editeng/fontitem.hxx> #include <formula/grammar.hxx> #include <com/sun/star/table/BorderLineStyle.hpp> @@ -441,6 +442,19 @@ void setAttribute( ScFieldEditEngine& rEE, sal_Int32 nPara, sal_Int32 nStart, sa } } +void setFont( ScFieldEditEngine& rEE, sal_Int32 nPara, sal_Int32 nStart, sal_Int32 nEnd, const OUString& rFontName ) +{ + ESelection aSel; + aSel.nStartPara = aSel.nEndPara = nPara; + aSel.nStartPos = nStart; + aSel.nEndPos = nEnd; + + SfxItemSet aItemSet = rEE.GetEmptyItemSet(); + SvxFontItem aItem(FAMILY_MODERN, rFontName, "", PITCH_VARIABLE, RTL_TEXTENCODING_UTF8, EE_CHAR_FONTINFO); + aItemSet.Put(aItem); + rEE.QuickSetAttribs(aItemSet, aSel); +} + } void ScExportTest::testNamedRangeBugfdo62729() @@ -525,6 +539,23 @@ void ScExportTest::testRichTextExportODS() return false; } + static bool isFont(const editeng::Section& rAttr, const OUString& rFontName) + { + if (rAttr.maAttributes.empty()) + return false; + + std::vector<const SfxPoolItem*>::const_iterator it = rAttr.maAttributes.begin(), itEnd = rAttr.maAttributes.end(); + for (; it != itEnd; ++it) + { + const SfxPoolItem* p = *it; + if (p->Which() != EE_CHAR_FONTINFO) + continue; + + return static_cast<const SvxFontItem*>(p)->GetFamilyName() == rFontName; + } + return false; + } + bool checkB2(const EditTextObject* pText) const { if (!pText) @@ -649,27 +680,62 @@ void ScExportTest::testRichTextExportODS() return true; } + bool checkB7(const EditTextObject* pText) const + { + if (!pText) + return false; + + if (pText->GetParagraphCount() != 1) + return false; + + if (pText->GetText(0) != "Font1 and Font2") + return false; + + std::vector<editeng::Section> aSecAttrs; + pText->GetAllSections(aSecAttrs); + if (aSecAttrs.size() != 3) + return false; + + // First section should have "Courier" font applied. + const editeng::Section* pAttr = &aSecAttrs[0]; + if (pAttr->mnParagraph != 0 ||pAttr->mnStart != 0 || pAttr->mnEnd != 5) + return false; + + if (pAttr->maAttributes.size() != 1 || !isFont(*pAttr, "Courier")) + return false; + + // Last section should have "Luxi Mono" applied. + pAttr = &aSecAttrs[2]; + if (pAttr->mnParagraph != 0 ||pAttr->mnStart != 10 || pAttr->mnEnd != 15) + return false; + + if (pAttr->maAttributes.size() != 1 || !isFont(*pAttr, "Luxi Mono")) + return false; + + return true; + } + } aCheckFunc; // Start with an empty document, put one edit text cell, and make sure it // survives the save and reload. - ScDocShellRef xOrigDocSh = loadDoc("empty.", ODS); + ScDocShellRef xOrigDocSh = loadDoc("empty.", ODS, true); ScDocument* pDoc = xOrigDocSh->GetDocument(); CPPUNIT_ASSERT(pDoc); CPPUNIT_ASSERT_MESSAGE("This document should at least have one sheet.", pDoc->GetTableCount() > 0); // Insert an edit text cell. - ScFieldEditEngine& rEE = pDoc->GetEditEngine(); - rEE.SetText("Bold and Italic"); + ScFieldEditEngine* pEE = &pDoc->GetEditEngine(); + pEE->SetText("Bold and Italic"); // Set the 'Bold' part bold. - setAttribute(rEE, 0, 0, 4, EE_CHAR_WEIGHT); + setAttribute(*pEE, 0, 0, 4, EE_CHAR_WEIGHT); // Set the 'Italic' part italic. - setAttribute(rEE, 0, 9, 15, EE_CHAR_ITALIC); + setAttribute(*pEE, 0, 9, 15, EE_CHAR_ITALIC); ESelection aSel; aSel.nStartPara = aSel.nEndPara = 0; // Set this edit text to cell B2. - pDoc->SetEditText(ScAddress(1,1,0), rEE.CreateTextObject()); + pDoc->SetEditText(ScAddress(1,1,0), pEE->CreateTextObject()); const EditTextObject* pEditText = pDoc->GetEditText(ScAddress(1,1,0)); CPPUNIT_ASSERT_MESSAGE("Incorret B2 value.", aCheckFunc.checkB2(pEditText)); @@ -680,20 +746,22 @@ void ScExportTest::testRichTextExportODS() pDoc = xNewDocSh->GetDocument(); CPPUNIT_ASSERT(pDoc); CPPUNIT_ASSERT_MESSAGE("Reloaded document should at least have one sheet.", pDoc->GetTableCount() > 0); + pEE = &pDoc->GetEditEngine(); // Make sure the content of B2 is still intact. CPPUNIT_ASSERT_MESSAGE("Incorret B2 value.", aCheckFunc.checkB2(pEditText)); // Insert a multi-line content to B4. - rEE.Clear(); - rEE.SetText("One\nTwo\nThree"); - pDoc->SetEditText(ScAddress(3,1,0), rEE.CreateTextObject()); + pEE->Clear(); + pEE->SetText("One\nTwo\nThree"); + pDoc->SetEditText(ScAddress(3,1,0), pEE->CreateTextObject()); pEditText = pDoc->GetEditText(ScAddress(3,1,0)); CPPUNIT_ASSERT_MESSAGE("Incorret B4 value.", aCheckFunc.checkB4(pEditText)); // Reload the doc again, and check the content of B2 and B4. ScDocShellRef xNewDocSh2 = saveAndReload(xNewDocSh, ODS); pDoc = xNewDocSh2->GetDocument(); + pEE = &pDoc->GetEditEngine(); xNewDocSh->DoClose(); pEditText = pDoc->GetEditText(ScAddress(1,1,0)); @@ -702,22 +770,31 @@ void ScExportTest::testRichTextExportODS() CPPUNIT_ASSERT_MESSAGE("Incorret B4 value.", aCheckFunc.checkB4(pEditText)); // Insert a multi-line content to B5, but this time, set some empty paragraphs. - rEE.Clear(); - rEE.SetText("\nTwo\nThree\n\nFive\n"); - pDoc->SetEditText(ScAddress(4,1,0), rEE.CreateTextObject()); + pEE->Clear(); + pEE->SetText("\nTwo\nThree\n\nFive\n"); + pDoc->SetEditText(ScAddress(4,1,0), pEE->CreateTextObject()); pEditText = pDoc->GetEditText(ScAddress(4,1,0)); CPPUNIT_ASSERT_MESSAGE("Incorret B5 value.", aCheckFunc.checkB5(pEditText)); // Insert a text with strikethrough in B6. - rEE.Clear(); - rEE.SetText("Strike Me"); + pEE->Clear(); + pEE->SetText("Strike Me"); // Set the 'Strike' part strikethrough. - setAttribute(rEE, 0, 0, 6, EE_CHAR_STRIKEOUT); - pDoc->SetEditText(ScAddress(5,1,0), rEE.CreateTextObject()); + setAttribute(*pEE, 0, 0, 6, EE_CHAR_STRIKEOUT); + pDoc->SetEditText(ScAddress(5,1,0), pEE->CreateTextObject()); pEditText = pDoc->GetEditText(ScAddress(5,1,0)); CPPUNIT_ASSERT_MESSAGE("Incorret B6 value.", aCheckFunc.checkB6(pEditText)); - // Reload the doc again, and check the content of B2, B4 and B6. + // Insert a text with different font segments in B7. + pEE->Clear(); + pEE->SetText("Font1 and Font2"); + setFont(*pEE, 0, 0, 5, "Courier"); + setFont(*pEE, 0, 10, 15, "Luxi Mono"); + pDoc->SetEditText(ScAddress(6,1,0), pEE->CreateTextObject()); + pEditText = pDoc->GetEditText(ScAddress(6,1,0)); + CPPUNIT_ASSERT_MESSAGE("Incorret B7 value.", aCheckFunc.checkB7(pEditText)); + + // Reload the doc again, and check the content of B2, B4, B6 and B7. ScDocShellRef xNewDocSh3 = saveAndReload(xNewDocSh2, ODS); pDoc = xNewDocSh3->GetDocument(); xNewDocSh2->DoClose(); @@ -730,6 +807,8 @@ void ScExportTest::testRichTextExportODS() CPPUNIT_ASSERT_MESSAGE("Incorret B5 value.", aCheckFunc.checkB5(pEditText)); pEditText = pDoc->GetEditText(ScAddress(5,1,0)); CPPUNIT_ASSERT_MESSAGE("Incorret B6 value.", aCheckFunc.checkB6(pEditText)); + pEditText = pDoc->GetEditText(ScAddress(6,1,0)); + CPPUNIT_ASSERT_MESSAGE("Incorret B7 value.", aCheckFunc.checkB7(pEditText)); xNewDocSh3->DoClose(); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits