diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-02-26 12:04:46 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-04-08 09:02:13 +0200 |
commit | 4208d95a292674c80592a7b0b69e5417939b31c1 (patch) | |
tree | 7534efda9a0fd1f34db4a6c9d9297938ddfc56f2 | |
parent | dad60bd52a25c1997d3724361ea81c0fe99b1872 (diff) |
oox: add FormatScheme test case and make sure FillStyle is imorted
Extends ThemeTest in sw with the use cases relevant for import of
FormatScheme into the model::Theme (as much as it is implemented
currently).
Change-Id: I888f64c24ba455913d688be256f095d9c298dc2f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147693
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | include/docmodel/theme/FormatScheme.hxx | 31 | ||||
-rw-r--r-- | oox/source/drawingml/themeelementscontext.cxx | 21 | ||||
-rw-r--r-- | sw/qa/core/theme/ThemeTest.cxx | 54 |
3 files changed, 94 insertions, 12 deletions
diff --git a/include/docmodel/theme/FormatScheme.hxx b/include/docmodel/theme/FormatScheme.hxx index 39fa5d36ae0b..07829c866162 100644 --- a/include/docmodel/theme/FormatScheme.hxx +++ b/include/docmodel/theme/FormatScheme.hxx @@ -213,18 +213,12 @@ public: std::shared_ptr<Fill> mpFill; }; -class DOCMODEL_DLLPUBLIC BackgroundFillStyle -{ -public: - std::shared_ptr<Fill> mpFill; -}; - class DOCMODEL_DLLPUBLIC FormatScheme { private: OUString maName; std::vector<FillStyle> maFillStyleList; - std::vector<BackgroundFillStyle> maBackgroundFillStyleList; + std::vector<FillStyle> maBackgroundFillStyleList; public: FormatScheme() = default; @@ -235,6 +229,29 @@ public: } const OUString& getName() const { return maName; } + + std::vector<FillStyle> const& getFillStyleList() const { return maFillStyleList; } + + FillStyle* addFillStyle() + { + if (maFillStyleList.size() > 3) + return nullptr; + auto& rFillStyle = maFillStyleList.emplace_back(); + return &rFillStyle; + } + + std::vector<FillStyle> const& getBackgroundFillStyleList() const + { + return maBackgroundFillStyleList; + } + + FillStyle* addBackgroundFillStyle() + { + if (maBackgroundFillStyleList.size() > 3) + return nullptr; + auto& rBackgroundFillStyle = maBackgroundFillStyleList.emplace_back(); + return &rBackgroundFillStyle; + } }; } // end of namespace svx diff --git a/oox/source/drawingml/themeelementscontext.cxx b/oox/source/drawingml/themeelementscontext.cxx index 7d37145661cf..ae38d3eb8d43 100644 --- a/oox/source/drawingml/themeelementscontext.cxx +++ b/oox/source/drawingml/themeelementscontext.cxx @@ -45,17 +45,21 @@ public: FillStyleListContext(ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList, model::FormatScheme& rFormatScheme); virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override; -private: +protected: FillStyleList& mrFillStyleList; - //model::FormatScheme& mrFormatScheme; + model::FormatScheme& mrFormatScheme; + virtual model::FillStyle* createAndAddFillStyle() + { + return mrFormatScheme.addFillStyle(); + } }; } -FillStyleListContext::FillStyleListContext(ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList, model::FormatScheme& /*rFormatScheme*/) +FillStyleListContext::FillStyleListContext(ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList, model::FormatScheme& rFormatScheme) : ContextHandler2(rParent) , mrFillStyleList(rFillStyleList) - //, mrFormatScheme(rFormatScheme) + , mrFormatScheme(rFormatScheme) { } @@ -71,7 +75,8 @@ ContextHandlerRef FillStyleListContext::onCreateContext( sal_Int32 nElement, con case A_TOKEN( grpFill ): { mrFillStyleList.push_back(std::make_shared<FillProperties>()); - return FillPropertiesContext::createFillContext(*this, nElement, rAttribs, *mrFillStyleList.back(), nullptr); + model::FillStyle* pFillStyle = createAndAddFillStyle(); + return FillPropertiesContext::createFillContext(*this, nElement, rAttribs, *mrFillStyleList.back(), pFillStyle); } } return nullptr; @@ -86,6 +91,12 @@ public: BackgroundFillStyleListContext(ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList, model::FormatScheme& rFormatScheme) : FillStyleListContext(rParent, rFillStyleList, rFormatScheme) {} + +protected: + model::FillStyle* createAndAddFillStyle() override + { + return mrFormatScheme.addBackgroundFillStyle(); + } }; } // end anonymous ns diff --git a/sw/qa/core/theme/ThemeTest.cxx b/sw/qa/core/theme/ThemeTest.cxx index f13063bc30ac..c94b195eef0e 100644 --- a/sw/qa/core/theme/ThemeTest.cxx +++ b/sw/qa/core/theme/ThemeTest.cxx @@ -82,6 +82,60 @@ CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testDrawPageThemeExistsDOCX) rFontScheme.findMajorSupplementalTypeface(u"Thai")); CPPUNIT_ASSERT_EQUAL(OUString(u"Cordia New"), rFontScheme.findMinorSupplementalTypeface(u"Thai")); + + model::FormatScheme const& rFormatScheme = pTheme->getFormatScheme(); + CPPUNIT_ASSERT_EQUAL(size_t(3), rFormatScheme.getFillStyleList().size()); + CPPUNIT_ASSERT_EQUAL(size_t(3), rFormatScheme.getBackgroundFillStyleList().size()); + + { + model::FillStyle const& rFillStyle = rFormatScheme.getFillStyleList().at(0); + CPPUNIT_ASSERT(rFillStyle.mpFill); + CPPUNIT_ASSERT_EQUAL(model::FillType::Solid, rFillStyle.mpFill->meType); + auto* pSolidFill = static_cast<model::SolidFill*>(rFillStyle.mpFill.get()); + CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, pSolidFill->maColorDefinition.meType); + } + + { + model::FillStyle const& rFillStyle = rFormatScheme.getFillStyleList().at(1); + CPPUNIT_ASSERT(rFillStyle.mpFill); + CPPUNIT_ASSERT_EQUAL(model::FillType::Gradient, rFillStyle.mpFill->meType); + auto* pGradientFill = static_cast<model::GradientFill*>(rFillStyle.mpFill.get()); + CPPUNIT_ASSERT_EQUAL(model::GradientType::Linear, pGradientFill->meGradientType); + CPPUNIT_ASSERT_EQUAL(size_t(3), pGradientFill->maGradientStops.size()); + + CPPUNIT_ASSERT_EQUAL(0.0, pGradientFill->maGradientStops[0].mfPosition); + CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, + pGradientFill->maGradientStops[0].maColor.meType); + + CPPUNIT_ASSERT_EQUAL(0.5, pGradientFill->maGradientStops[1].mfPosition); + CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, + pGradientFill->maGradientStops[1].maColor.meType); + + CPPUNIT_ASSERT_EQUAL(1.0, pGradientFill->maGradientStops[2].mfPosition); + CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, + pGradientFill->maGradientStops[2].maColor.meType); + } + + { + model::FillStyle const& rFillStyle = rFormatScheme.getFillStyleList().at(2); + CPPUNIT_ASSERT(rFillStyle.mpFill); + CPPUNIT_ASSERT_EQUAL(model::FillType::Gradient, rFillStyle.mpFill->meType); + auto* pGradientFill = static_cast<model::GradientFill*>(rFillStyle.mpFill.get()); + CPPUNIT_ASSERT_EQUAL(model::GradientType::Linear, pGradientFill->meGradientType); + CPPUNIT_ASSERT_EQUAL(size_t(3), pGradientFill->maGradientStops.size()); + + CPPUNIT_ASSERT_EQUAL(0.0, pGradientFill->maGradientStops[0].mfPosition); + CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, + pGradientFill->maGradientStops[0].maColor.meType); + + CPPUNIT_ASSERT_EQUAL(0.5, pGradientFill->maGradientStops[1].mfPosition); + CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, + pGradientFill->maGradientStops[1].maColor.meType); + + CPPUNIT_ASSERT_EQUAL(1.0, pGradientFill->maGradientStops[2].mfPosition); + CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, + pGradientFill->maGradientStops[2].maColor.meType); + } } CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testDrawPageThemeExistsODT) |