diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-02-27 22:03:59 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-04-12 05:37:33 +0200 |
commit | 17167dbede715de4792a48149b8603f384555f80 (patch) | |
tree | a3fa45df32c183c093ca55ef512bf8735757ecf1 | |
parent | 1b06f35de68a555b85bceb5fc29d1a5f426f4bb7 (diff) |
oox: add model::PatternFill and import pattern fill elements
Change-Id: I49ef33fd81509599f4081e6a913b05dae1e4a642
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147953
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | include/docmodel/theme/FormatScheme.hxx | 72 | ||||
-rw-r--r-- | oox/inc/drawingml/misccontexts.hxx | 8 | ||||
-rw-r--r-- | oox/source/drawingml/colorchoicecontext.cxx | 12 | ||||
-rw-r--r-- | oox/source/drawingml/misccontexts.cxx | 108 |
4 files changed, 182 insertions, 18 deletions
diff --git a/include/docmodel/theme/FormatScheme.hxx b/include/docmodel/theme/FormatScheme.hxx index 07829c866162..fea08ee50d1e 100644 --- a/include/docmodel/theme/FormatScheme.hxx +++ b/include/docmodel/theme/FormatScheme.hxx @@ -205,6 +205,78 @@ public: } }; +enum class PatternPreset +{ + Unused, + Percent_5, + Percent_10, + Percent_20, + Percent_25, + Percent_30, + Percent_40, + Percent_50, + Percent_60, + Percent_70, + Percent_75, + Percent_80, + Percent_90, + Horizontal, + Vertical, + LightHorizontal, + LightVertical, + DarkHorizontal, + DarkVertical, + NarrowHorizontal, + NarrowVertical, + DashedHorizontal, + DashedVertical, + Cross, + DownwardDiagonal, + UpwardDiagonal, + LightDownwardDiagonal, + LightUpwardDiagonal, + DarkDownwardDiagonal, + DarkUpwardDiagonal, + WideDownwardDiagonal, + WideUpwardDiagonal, + DashedDownwardDiagonal, + DashedUpwardDiagonal, + DiagonalCross, + SmallCheckerBoard, + LargeCheckerBoard, + SmallGrid, + LargeGrid, + DottedGrid, + SmallConfetti, + LargeConfetti, + HorizontalBrick, + DiagonalBrick, + SolidDiamond, + OpenDiamond, + DottedDiamond, + Plaid, + Sphere, + Weave, + Divot, + Shingle, + Wave, + Trellis, + ZigZag +}; + +class DOCMODEL_DLLPUBLIC PatternFill : public Fill +{ +public: + PatternPreset mePatternPreset = PatternPreset::Unused; + ColorDefinition maForegroundColor; + ColorDefinition maBackgroundColor; + + PatternFill() + : Fill(FillType::Pattern) + { + } +}; + // Format Scheme class DOCMODEL_DLLPUBLIC FillStyle diff --git a/oox/inc/drawingml/misccontexts.hxx b/oox/inc/drawingml/misccontexts.hxx index 6bbaa74efcf2..10977df87d99 100644 --- a/oox/inc/drawingml/misccontexts.hxx +++ b/oox/inc/drawingml/misccontexts.hxx @@ -60,10 +60,9 @@ private: class PatternFillContext final : public ::oox::core::ContextHandler2 { public: - explicit PatternFillContext( - ::oox::core::ContextHandler2Helper const & rParent, - const ::oox::AttributeList& rAttribs, - PatternFillProperties& rPatternProps ); + explicit PatternFillContext(::oox::core::ContextHandler2Helper const& rParent, + const ::oox::AttributeList& rAttribs, PatternFillProperties& rPatternProps, + model::PatternFill* pPatternFill); virtual ::oox::core::ContextHandlerRef onCreateContext( @@ -71,6 +70,7 @@ public: const ::oox::AttributeList& rAttribs ) override; private: + model::PatternFill* mpPatternFill; PatternFillProperties& mrPatternProps; }; diff --git a/oox/source/drawingml/colorchoicecontext.cxx b/oox/source/drawingml/colorchoicecontext.cxx index 1ee6b9afacad..d3fff573a711 100644 --- a/oox/source/drawingml/colorchoicecontext.cxx +++ b/oox/source/drawingml/colorchoicecontext.cxx @@ -159,13 +159,15 @@ void ColorValueContext::onStartElement( const AttributeList& rAttribs ) mrColor.setSysClr(nToken, nLastColor); - auto aIterator = constSystemColorMap.find(nToken); - if (aIterator != constSystemColorMap.end()) + if (mpColorDefinition) { - auto const& aPair = *aIterator; - model::SystemColorType eType = aPair.second; - if (mpColorDefinition) + auto aIterator = constSystemColorMap.find(nToken); + if (aIterator != constSystemColorMap.end()) + { + auto const& aPair = *aIterator; + model::SystemColorType eType = aPair.second; mpColorDefinition->setSystemColor(eType, nLastColor); + } } } break; diff --git a/oox/source/drawingml/misccontexts.cxx b/oox/source/drawingml/misccontexts.cxx index e72e6ea40d74..20cb60e953de 100644 --- a/oox/source/drawingml/misccontexts.cxx +++ b/oox/source/drawingml/misccontexts.cxx @@ -27,6 +27,7 @@ #include <oox/token/tokens.hxx> #include <vcl/GraphicExternalLink.hxx> #include <vcl/graph.hxx> +#include <unordered_map> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -138,23 +139,105 @@ ContextHandlerRef GradientFillContext::onCreateContext( return nullptr; } -PatternFillContext::PatternFillContext( ContextHandler2Helper const & rParent, - const AttributeList& rAttribs, PatternFillProperties& rPatternProps ) : - ContextHandler2( rParent ), - mrPatternProps( rPatternProps ) + +namespace +{ + +std::unordered_map<sal_Int32, model::PatternPreset> constPatternPresetMap = { - mrPatternProps.moPattPreset = rAttribs.getToken( XML_prst ); + { XML_pct5, model::PatternPreset::Percent_5 }, + { XML_pct10, model::PatternPreset::Percent_10 }, + { XML_pct20, model::PatternPreset::Percent_20 }, + { XML_pct25, model::PatternPreset::Percent_25 }, + { XML_pct30, model::PatternPreset::Percent_30 }, + { XML_pct40, model::PatternPreset::Percent_40 }, + { XML_pct50, model::PatternPreset::Percent_50 }, + { XML_pct60, model::PatternPreset::Percent_60 }, + { XML_pct70, model::PatternPreset::Percent_70 }, + { XML_pct75, model::PatternPreset::Percent_75 }, + { XML_pct80, model::PatternPreset::Percent_80 }, + { XML_pct90, model::PatternPreset::Percent_90 }, + { XML_horz, model::PatternPreset::Horizontal }, + { XML_vert, model::PatternPreset::Vertical }, + { XML_ltHorz, model::PatternPreset::LightHorizontal }, + { XML_ltVert, model::PatternPreset::LightVertical }, + { XML_dkHorz, model::PatternPreset::DarkHorizontal }, + { XML_dkVert, model::PatternPreset::DarkVertical }, + { XML_narHorz, model::PatternPreset::NarrowHorizontal }, + { XML_narVert, model::PatternPreset::NarrowVertical }, + { XML_dashHorz, model::PatternPreset::DashedHorizontal }, + { XML_dashVert, model::PatternPreset::DashedVertical }, + { XML_cross, model::PatternPreset::Cross }, + { XML_dnDiag, model::PatternPreset::DownwardDiagonal }, + { XML_upDiag, model::PatternPreset::UpwardDiagonal }, + { XML_ltDnDiag, model::PatternPreset::LightDownwardDiagonal }, + { XML_ltUpDiag, model::PatternPreset::LightUpwardDiagonal }, + { XML_dkDnDiag, model::PatternPreset::DarkDownwardDiagonal }, + { XML_dkUpDiag, model::PatternPreset::DarkUpwardDiagonal }, + { XML_wdDnDiag, model::PatternPreset::WideDownwardDiagonal }, + { XML_wdUpDiag, model::PatternPreset::WideUpwardDiagonal }, + { XML_dashDnDiag, model::PatternPreset::DashedDownwardDiagonal }, + { XML_dashUpDiag, model::PatternPreset::DashedUpwardDiagonal }, + { XML_diagCross, model::PatternPreset::DiagonalCross }, + { XML_smCheck, model::PatternPreset::SmallCheckerBoard }, + { XML_lgCheck, model::PatternPreset::LargeCheckerBoard }, + { XML_smGrid, model::PatternPreset::SmallGrid }, + { XML_lgGrid, model::PatternPreset::LargeGrid }, + { XML_dotGrid, model::PatternPreset::DottedGrid }, + { XML_smConfetti, model::PatternPreset::SmallConfetti }, + { XML_lgConfetti, model::PatternPreset::LargeConfetti }, + { XML_horzBrick, model::PatternPreset::HorizontalBrick }, + { XML_diagBrick, model::PatternPreset::DiagonalBrick }, + { XML_solidDmnd, model::PatternPreset::SolidDiamond }, + { XML_openDmnd, model::PatternPreset::OpenDiamond }, + { XML_dotDmnd, model::PatternPreset::DottedDiamond }, + { XML_plaid, model::PatternPreset::Plaid }, + { XML_sphere, model::PatternPreset::Sphere }, + { XML_weave, model::PatternPreset::Weave }, + { XML_divot, model::PatternPreset::Divot }, + { XML_shingle, model::PatternPreset::Shingle }, + { XML_wave, model::PatternPreset::Wave }, + { XML_trellis, model::PatternPreset::Trellis }, + { XML_zigZag, model::PatternPreset::ZigZag } +}; + +} // end anonymous namespace +PatternFillContext::PatternFillContext(ContextHandler2Helper const & rParent, + const AttributeList& rAttribs, PatternFillProperties& rPatternProps, model::PatternFill* pPatternFill) + : ContextHandler2(rParent) + , mpPatternFill(pPatternFill) + , mrPatternProps(rPatternProps) +{ + mrPatternProps.moPattPreset = rAttribs.getToken(XML_prst); + + if (mpPatternFill) + { + sal_Int32 nToken = rAttribs.getToken(XML_prst, XML_TOKEN_INVALID); + + auto aIterator = constPatternPresetMap.find(nToken); + if (aIterator != constPatternPresetMap.end()) + { + auto const& aPair = *aIterator; + model::PatternPreset ePatternPreset = aPair.second; + mpPatternFill->mePatternPreset = ePatternPreset; + } + } } ContextHandlerRef PatternFillContext::onCreateContext( sal_Int32 nElement, const AttributeList& ) { + model::ColorDefinition* pColorDefinition = nullptr; switch( nElement ) { case A_TOKEN( bgClr ): - return new ColorContext(*this, mrPatternProps.maPattBgColor, nullptr); + if (mpPatternFill) + pColorDefinition = &mpPatternFill->maBackgroundColor; + return new ColorContext(*this, mrPatternProps.maPattBgColor, pColorDefinition); case A_TOKEN( fgClr ): - return new ColorContext(*this, mrPatternProps.maPattFgColor, nullptr); + if (mpPatternFill) + pColorDefinition = &mpPatternFill->maForegroundColor; + return new ColorContext(*this, mrPatternProps.maPattFgColor, pColorDefinition); } return nullptr; } @@ -357,7 +440,7 @@ ContextHandlerRef FillPropertiesContext::createFillContext( model::GradientFill* pGradientFill = nullptr; if (pFillStyle) { - pFillStyle->mpFill = std::make_unique<model::GradientFill>(); + pFillStyle->mpFill = std::make_shared<model::GradientFill>(); pGradientFill = static_cast<model::GradientFill*>(pFillStyle->mpFill.get()); } return new GradientFillContext(rParent, rAttribs, rFillProps.maGradientProps, pGradientFill); @@ -365,7 +448,14 @@ ContextHandlerRef FillPropertiesContext::createFillContext( case A_TOKEN( pattFill ): { rFillProps.moFillType = getBaseToken( nElement ); - return new PatternFillContext( rParent, rAttribs, rFillProps.maPatternProps ); + model::PatternFill* pPatternFill = nullptr; + if (pFillStyle) + { + auto pFill = std::make_shared<model::PatternFill>(); + pPatternFill = pFill.get(); + pFillStyle->mpFill = pFill; + } + return new PatternFillContext(rParent, rAttribs, rFillProps.maPatternProps, pPatternFill); } case A_TOKEN( blipFill ): { |