1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <swmodeltestbase.hxx>
12 #include <com/sun/star/datatransfer/XTransferableSupplier.hpp>
13 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
17 #include <unotxdoc.hxx>
19 #include <drawdoc.hxx>
20 #include <IDocumentDrawModelAccess.hxx>
22 #include <comphelper/classids.hxx>
23 #include <comphelper/processfactory.hxx>
24 #include <svx/svdpage.hxx>
25 #include <docmodel/uno/UnoComplexColor.hxx>
26 #include <docmodel/theme/Theme.hxx>
27 #include <ThemeColorChanger.hxx>
28 #include <sot/exchange.hxx>
29 #include <svx/ColorSets.hxx>
30 #include <vcl/transfer.hxx>
36 class SwCoreThemeTest
: public SwModelTestBase
40 : SwModelTestBase(u
"/sw/qa/core/theme/data/"_ustr
)
45 CPPUNIT_TEST_FIXTURE(SwCoreThemeTest
, testThemeColorInHeading
)
47 createSwDoc("ThemeColorInHeading.docx");
49 auto xComplexColor
= getProperty
<uno::Reference
<util::XComplexColor
>>(getParagraph(1),
50 u
"CharComplexColor"_ustr
);
51 auto aComplexColor
= model::color::getFromXComplexColor(xComplexColor
);
52 CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent1
, aComplexColor
.getThemeColorType());
55 CPPUNIT_TEST_FIXTURE(SwCoreThemeTest
, testThemeColorInHeadingODT
)
57 createSwDoc("ThemeColorInHeading.fodt");
59 auto xComplexColor
= getProperty
<uno::Reference
<util::XComplexColor
>>(getParagraph(1),
60 u
"CharComplexColor"_ustr
);
61 auto aComplexColor
= model::color::getFromXComplexColor(xComplexColor
);
62 CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent1
, aComplexColor
.getThemeColorType());
65 void checkFillStyles(std::vector
<model::FillStyle
> const& rStyleList
)
67 CPPUNIT_ASSERT_EQUAL(size_t(3), rStyleList
.size());
70 model::FillStyle
const& rFillStyle
= rStyleList
.at(0);
71 CPPUNIT_ASSERT(rFillStyle
.mpFill
);
72 CPPUNIT_ASSERT_EQUAL(model::FillType::Solid
, rFillStyle
.mpFill
->meType
);
73 auto* pSolidFill
= static_cast<model::SolidFill
*>(rFillStyle
.mpFill
.get());
74 CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder
, pSolidFill
->maColor
.getType());
75 CPPUNIT_ASSERT_EQUAL(size_t(0), pSolidFill
->maColor
.getTransformations().size());
80 model::FillStyle
const& rFillStyle
= rStyleList
.at(1);
81 CPPUNIT_ASSERT(rFillStyle
.mpFill
);
82 CPPUNIT_ASSERT_EQUAL(model::FillType::Gradient
, rFillStyle
.mpFill
->meType
);
83 auto* pGradientFill
= static_cast<model::GradientFill
*>(rFillStyle
.mpFill
.get());
85 // Gradient Properties
86 CPPUNIT_ASSERT_EQUAL(model::GradientType::Linear
, pGradientFill
->meGradientType
);
87 CPPUNIT_ASSERT_EQUAL(sal_Int32(5400000), pGradientFill
->maLinearGradient
.mnAngle
);
88 CPPUNIT_ASSERT_EQUAL(false, pGradientFill
->maLinearGradient
.mbScaled
);
91 CPPUNIT_ASSERT_EQUAL(size_t(3), pGradientFill
->maGradientStops
.size());
93 auto const& rGradientStop
= pGradientFill
->maGradientStops
[0];
94 CPPUNIT_ASSERT_EQUAL(0.0, rGradientStop
.mfPosition
);
95 CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder
, rGradientStop
.maColor
.getType());
96 CPPUNIT_ASSERT_EQUAL(size_t(3), rGradientStop
.maColor
.getTransformations().size());
99 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[0];
100 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod
, rTrasnsformation
.meType
);
101 CPPUNIT_ASSERT_EQUAL(sal_Int16(11000), rTrasnsformation
.mnValue
);
104 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[1];
105 CPPUNIT_ASSERT_EQUAL(model::TransformationType::SatMod
, rTrasnsformation
.meType
);
106 CPPUNIT_ASSERT_EQUAL(sal_Int16(10500), rTrasnsformation
.mnValue
);
109 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[2];
110 CPPUNIT_ASSERT_EQUAL(model::TransformationType::Tint
, rTrasnsformation
.meType
);
111 CPPUNIT_ASSERT_EQUAL(sal_Int16(6700), rTrasnsformation
.mnValue
);
115 auto const& rGradientStop
= pGradientFill
->maGradientStops
[1];
116 CPPUNIT_ASSERT_EQUAL(0.5, rGradientStop
.mfPosition
);
117 CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder
, rGradientStop
.maColor
.getType());
118 CPPUNIT_ASSERT_EQUAL(size_t(3), rGradientStop
.maColor
.getTransformations().size());
121 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[0];
122 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod
, rTrasnsformation
.meType
);
123 CPPUNIT_ASSERT_EQUAL(sal_Int16(10500), rTrasnsformation
.mnValue
);
126 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[1];
127 CPPUNIT_ASSERT_EQUAL(model::TransformationType::SatMod
, rTrasnsformation
.meType
);
128 CPPUNIT_ASSERT_EQUAL(sal_Int16(10300), rTrasnsformation
.mnValue
);
131 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[2];
132 CPPUNIT_ASSERT_EQUAL(model::TransformationType::Tint
, rTrasnsformation
.meType
);
133 CPPUNIT_ASSERT_EQUAL(sal_Int16(7300), rTrasnsformation
.mnValue
);
137 auto const& rGradientStop
= pGradientFill
->maGradientStops
[2];
138 CPPUNIT_ASSERT_EQUAL(1.0, rGradientStop
.mfPosition
);
139 CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder
, rGradientStop
.maColor
.getType());
140 CPPUNIT_ASSERT_EQUAL(size_t(3), rGradientStop
.maColor
.getTransformations().size());
143 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[0];
144 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod
, rTrasnsformation
.meType
);
145 CPPUNIT_ASSERT_EQUAL(sal_Int16(10500), rTrasnsformation
.mnValue
);
148 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[1];
149 CPPUNIT_ASSERT_EQUAL(model::TransformationType::SatMod
, rTrasnsformation
.meType
);
150 CPPUNIT_ASSERT_EQUAL(sal_Int16(10900), rTrasnsformation
.mnValue
);
153 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[2];
154 CPPUNIT_ASSERT_EQUAL(model::TransformationType::Tint
, rTrasnsformation
.meType
);
155 CPPUNIT_ASSERT_EQUAL(sal_Int16(8100), rTrasnsformation
.mnValue
);
162 model::FillStyle
const& rFillStyle
= rStyleList
.at(2);
163 CPPUNIT_ASSERT(rFillStyle
.mpFill
);
164 CPPUNIT_ASSERT_EQUAL(model::FillType::Gradient
, rFillStyle
.mpFill
->meType
);
165 auto* pGradientFill
= static_cast<model::GradientFill
*>(rFillStyle
.mpFill
.get());
167 // Gradient Properties
168 CPPUNIT_ASSERT_EQUAL(model::GradientType::Linear
, pGradientFill
->meGradientType
);
169 CPPUNIT_ASSERT_EQUAL(sal_Int32(5400000), pGradientFill
->maLinearGradient
.mnAngle
);
170 CPPUNIT_ASSERT_EQUAL(false, pGradientFill
->maLinearGradient
.mbScaled
);
173 CPPUNIT_ASSERT_EQUAL(size_t(3), pGradientFill
->maGradientStops
.size());
175 auto const& rGradientStop
= pGradientFill
->maGradientStops
[0];
176 CPPUNIT_ASSERT_EQUAL(0.0, rGradientStop
.mfPosition
);
177 CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder
, rGradientStop
.maColor
.getType());
178 CPPUNIT_ASSERT_EQUAL(size_t(3), rGradientStop
.maColor
.getTransformations().size());
180 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[0];
181 CPPUNIT_ASSERT_EQUAL(model::TransformationType::SatMod
, rTrasnsformation
.meType
);
182 CPPUNIT_ASSERT_EQUAL(sal_Int16(10300), rTrasnsformation
.mnValue
);
185 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[1];
186 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod
, rTrasnsformation
.meType
);
187 CPPUNIT_ASSERT_EQUAL(sal_Int16(10200), rTrasnsformation
.mnValue
);
190 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[2];
191 CPPUNIT_ASSERT_EQUAL(model::TransformationType::Tint
, rTrasnsformation
.meType
);
192 CPPUNIT_ASSERT_EQUAL(sal_Int16(9400), rTrasnsformation
.mnValue
);
196 auto const& rGradientStop
= pGradientFill
->maGradientStops
[1];
197 CPPUNIT_ASSERT_EQUAL(0.5, rGradientStop
.mfPosition
);
198 CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder
, rGradientStop
.maColor
.getType());
199 CPPUNIT_ASSERT_EQUAL(size_t(3), rGradientStop
.maColor
.getTransformations().size());
201 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[0];
202 CPPUNIT_ASSERT_EQUAL(model::TransformationType::SatMod
, rTrasnsformation
.meType
);
203 CPPUNIT_ASSERT_EQUAL(sal_Int16(11000), rTrasnsformation
.mnValue
);
206 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[1];
207 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod
, rTrasnsformation
.meType
);
208 CPPUNIT_ASSERT_EQUAL(sal_Int16(10000), rTrasnsformation
.mnValue
);
211 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[2];
212 CPPUNIT_ASSERT_EQUAL(model::TransformationType::Shade
, rTrasnsformation
.meType
);
213 CPPUNIT_ASSERT_EQUAL(sal_Int16(10000), rTrasnsformation
.mnValue
);
217 auto const& rGradientStop
= pGradientFill
->maGradientStops
[2];
218 CPPUNIT_ASSERT_EQUAL(1.0, rGradientStop
.mfPosition
);
219 CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder
, rGradientStop
.maColor
.getType());
220 CPPUNIT_ASSERT_EQUAL(size_t(3), rGradientStop
.maColor
.getTransformations().size());
222 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[0];
223 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod
, rTrasnsformation
.meType
);
224 CPPUNIT_ASSERT_EQUAL(sal_Int16(9900), rTrasnsformation
.mnValue
);
227 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[1];
228 CPPUNIT_ASSERT_EQUAL(model::TransformationType::SatMod
, rTrasnsformation
.meType
);
229 CPPUNIT_ASSERT_EQUAL(sal_Int16(12000), rTrasnsformation
.mnValue
);
232 auto const& rTrasnsformation
= rGradientStop
.maColor
.getTransformations()[2];
233 CPPUNIT_ASSERT_EQUAL(model::TransformationType::Shade
, rTrasnsformation
.meType
);
234 CPPUNIT_ASSERT_EQUAL(sal_Int16(7800), rTrasnsformation
.mnValue
);
240 void checkLineStyles(std::vector
<model::LineStyle
> const& rStyleList
)
242 CPPUNIT_ASSERT_EQUAL(size_t(3), rStyleList
.size());
245 model::LineStyle
const& rLineStyle
= rStyleList
.at(0);
246 CPPUNIT_ASSERT_EQUAL(sal_Int32(6350), rLineStyle
.mnWidth
);
247 CPPUNIT_ASSERT_EQUAL(model::CapType::Flat
, rLineStyle
.meCapType
);
248 CPPUNIT_ASSERT_EQUAL(model::PenAlignmentType::Center
, rLineStyle
.mePenAlignment
);
249 CPPUNIT_ASSERT_EQUAL(model::CompoundLineType::Single
, rLineStyle
.meCompoundLineType
);
250 CPPUNIT_ASSERT_EQUAL(model::PresetDashType::Solid
, rLineStyle
.maLineDash
.mePresetType
);
251 CPPUNIT_ASSERT_EQUAL(model::LineJoinType::Miter
, rLineStyle
.maLineJoin
.meType
);
252 CPPUNIT_ASSERT_EQUAL(sal_Int32(800000), rLineStyle
.maLineJoin
.mnMiterLimit
);
254 model::FillStyle
const& rFillStyle
= rLineStyle
.maLineFillStyle
;
255 CPPUNIT_ASSERT(rFillStyle
.mpFill
);
256 CPPUNIT_ASSERT_EQUAL(model::FillType::Solid
, rFillStyle
.mpFill
->meType
);
257 auto* pSolidFill
= static_cast<model::SolidFill
*>(rFillStyle
.mpFill
.get());
258 CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder
, pSolidFill
->maColor
.getType());
259 CPPUNIT_ASSERT_EQUAL(size_t(0), pSolidFill
->maColor
.getTransformations().size());
264 model::LineStyle
const& rLineStyle
= rStyleList
.at(1);
265 CPPUNIT_ASSERT_EQUAL(sal_Int32(12700), rLineStyle
.mnWidth
);
266 CPPUNIT_ASSERT_EQUAL(model::CapType::Flat
, rLineStyle
.meCapType
);
267 CPPUNIT_ASSERT_EQUAL(model::PenAlignmentType::Center
, rLineStyle
.mePenAlignment
);
268 CPPUNIT_ASSERT_EQUAL(model::CompoundLineType::Single
, rLineStyle
.meCompoundLineType
);
269 CPPUNIT_ASSERT_EQUAL(model::PresetDashType::Solid
, rLineStyle
.maLineDash
.mePresetType
);
270 CPPUNIT_ASSERT_EQUAL(model::LineJoinType::Miter
, rLineStyle
.maLineJoin
.meType
);
271 CPPUNIT_ASSERT_EQUAL(sal_Int32(800000), rLineStyle
.maLineJoin
.mnMiterLimit
);
273 model::FillStyle
const& rFillStyle
= rLineStyle
.maLineFillStyle
;
274 CPPUNIT_ASSERT(rFillStyle
.mpFill
);
275 CPPUNIT_ASSERT_EQUAL(model::FillType::Solid
, rFillStyle
.mpFill
->meType
);
276 auto* pSolidFill
= static_cast<model::SolidFill
*>(rFillStyle
.mpFill
.get());
277 CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder
, pSolidFill
->maColor
.getType());
278 CPPUNIT_ASSERT_EQUAL(size_t(0), pSolidFill
->maColor
.getTransformations().size());
283 model::LineStyle
const& rLineStyle
= rStyleList
.at(2);
284 CPPUNIT_ASSERT_EQUAL(sal_Int32(19050), rLineStyle
.mnWidth
);
285 CPPUNIT_ASSERT_EQUAL(model::CapType::Flat
, rLineStyle
.meCapType
);
286 CPPUNIT_ASSERT_EQUAL(model::PenAlignmentType::Center
, rLineStyle
.mePenAlignment
);
287 CPPUNIT_ASSERT_EQUAL(model::CompoundLineType::Single
, rLineStyle
.meCompoundLineType
);
288 CPPUNIT_ASSERT_EQUAL(model::PresetDashType::Solid
, rLineStyle
.maLineDash
.mePresetType
);
289 CPPUNIT_ASSERT_EQUAL(model::LineJoinType::Miter
, rLineStyle
.maLineJoin
.meType
);
290 CPPUNIT_ASSERT_EQUAL(sal_Int32(800000), rLineStyle
.maLineJoin
.mnMiterLimit
);
292 model::FillStyle
const& rFillStyle
= rLineStyle
.maLineFillStyle
;
293 CPPUNIT_ASSERT(rFillStyle
.mpFill
);
294 CPPUNIT_ASSERT_EQUAL(model::FillType::Solid
, rFillStyle
.mpFill
->meType
);
295 auto* pSolidFill
= static_cast<model::SolidFill
*>(rFillStyle
.mpFill
.get());
296 CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder
, pSolidFill
->maColor
.getType());
297 CPPUNIT_ASSERT_EQUAL(size_t(0), pSolidFill
->maColor
.getTransformations().size());
301 void checkEffects(std::vector
<model::EffectStyle
> const& rEffectStyleList
)
303 CPPUNIT_ASSERT_EQUAL(size_t(3), rEffectStyleList
.size());
305 model::EffectStyle rEffectStyle
= rEffectStyleList
[0];
306 CPPUNIT_ASSERT_EQUAL(size_t(0), rEffectStyle
.maEffectList
.size());
310 model::EffectStyle rEffectStyle
= rEffectStyleList
[1];
311 CPPUNIT_ASSERT_EQUAL(size_t(0), rEffectStyle
.maEffectList
.size());
315 model::EffectStyle rEffectStyle
= rEffectStyleList
[2];
316 CPPUNIT_ASSERT_EQUAL(size_t(1), rEffectStyle
.maEffectList
.size());
317 model::Effect
const& rEffect
= rEffectStyle
.maEffectList
[0];
319 CPPUNIT_ASSERT_EQUAL(model::EffectType::OuterShadow
, rEffect
.meType
);
320 CPPUNIT_ASSERT_EQUAL(sal_Int32(57150), rEffect
.mnBlurRadius
);
321 CPPUNIT_ASSERT_EQUAL(sal_Int32(19050), rEffect
.mnDistance
);
322 CPPUNIT_ASSERT_EQUAL(sal_Int32(5400000), rEffect
.mnDirection
);
323 CPPUNIT_ASSERT_EQUAL(model::RectangleAlignment::Center
, rEffect
.meAlignment
);
324 CPPUNIT_ASSERT_EQUAL(false, rEffect
.mbRotateWithShape
);
326 CPPUNIT_ASSERT_EQUAL(model::ColorType::RGB
, rEffect
.maColor
.getType());
327 CPPUNIT_ASSERT_EQUAL(COL_BLACK
, rEffect
.maColor
.getRGB());
329 CPPUNIT_ASSERT_EQUAL(size_t(1), rEffect
.maColor
.getTransformations().size());
330 CPPUNIT_ASSERT_EQUAL(model::TransformationType::Alpha
,
331 rEffect
.maColor
.getTransformations()[0].meType
);
332 CPPUNIT_ASSERT_EQUAL(sal_Int16(6300), rEffect
.maColor
.getTransformations()[0].mnValue
);
336 CPPUNIT_TEST_FIXTURE(SwCoreThemeTest
, testDrawPageThemeExistsDOCX
)
338 createSwDoc("ThemeColorInHeading.docx");
339 SwDoc
* pDoc
= getSwDoc();
341 SdrModel
* pModel
= pDoc
->getIDocumentDrawModelAccess().GetDrawModel();
342 CPPUNIT_ASSERT(pModel
);
343 auto const& pTheme
= pModel
->getTheme();
344 CPPUNIT_ASSERT(pTheme
);
345 CPPUNIT_ASSERT_EQUAL(u
"Office Theme"_ustr
, pTheme
->GetName());
347 auto pColorSet
= pTheme
->getColorSet();
348 CPPUNIT_ASSERT(pColorSet
);
349 CPPUNIT_ASSERT_EQUAL(u
"Orange"_ustr
, pColorSet
->getName());
351 CPPUNIT_ASSERT_EQUAL(Color(0xE48312), pTheme
->GetColor(model::ThemeColorType::Accent1
));
352 CPPUNIT_ASSERT_EQUAL(Color(0xBD582C), pTheme
->GetColor(model::ThemeColorType::Accent2
));
353 CPPUNIT_ASSERT_EQUAL(Color(0x865640), pTheme
->GetColor(model::ThemeColorType::Accent3
));
354 CPPUNIT_ASSERT_EQUAL(Color(0x9B8357), pTheme
->GetColor(model::ThemeColorType::Accent4
));
355 CPPUNIT_ASSERT_EQUAL(Color(0xC2BC80), pTheme
->GetColor(model::ThemeColorType::Accent5
));
356 CPPUNIT_ASSERT_EQUAL(Color(0x94A088), pTheme
->GetColor(model::ThemeColorType::Accent6
));
357 CPPUNIT_ASSERT_EQUAL(COL_BLACK
, pTheme
->GetColor(model::ThemeColorType::Dark1
));
358 CPPUNIT_ASSERT_EQUAL(Color(0x637052), pTheme
->GetColor(model::ThemeColorType::Dark2
));
359 CPPUNIT_ASSERT_EQUAL(COL_WHITE
, pTheme
->GetColor(model::ThemeColorType::Light1
));
360 CPPUNIT_ASSERT_EQUAL(Color(0xCCDDEA), pTheme
->GetColor(model::ThemeColorType::Light2
));
362 model::FontScheme
const& rFontScheme
= pTheme
->getFontScheme();
363 CPPUNIT_ASSERT_EQUAL(u
"Calibri Light"_ustr
, rFontScheme
.getMajorLatin().maTypeface
);
364 CPPUNIT_ASSERT_EQUAL(u
"Calibri"_ustr
, rFontScheme
.getMinorLatin().maTypeface
);
365 CPPUNIT_ASSERT_EQUAL(true, rFontScheme
.getMajorAsian().maTypeface
.isEmpty());
366 CPPUNIT_ASSERT_EQUAL(true, rFontScheme
.getMinorAsian().maTypeface
.isEmpty());
367 CPPUNIT_ASSERT_EQUAL(true, rFontScheme
.getMajorComplex().maTypeface
.isEmpty());
368 CPPUNIT_ASSERT_EQUAL(true, rFontScheme
.getMinorComplex().maTypeface
.isEmpty());
369 CPPUNIT_ASSERT_EQUAL(size_t(47), rFontScheme
.getMajorSupplementalFontList().size());
370 CPPUNIT_ASSERT_EQUAL(size_t(47), rFontScheme
.getMinorSupplementalFontList().size());
371 CPPUNIT_ASSERT_EQUAL(u
"Angsana New"_ustr
, rFontScheme
.findMajorSupplementalTypeface(u
"Thai"));
372 CPPUNIT_ASSERT_EQUAL(u
"Cordia New"_ustr
, rFontScheme
.findMinorSupplementalTypeface(u
"Thai"));
374 model::FormatScheme
const& rFormatScheme
= pTheme
->getFormatScheme();
375 checkFillStyles(rFormatScheme
.getFillStyleList());
376 checkLineStyles(rFormatScheme
.getLineStyleList());
377 checkEffects(rFormatScheme
.getEffectStyleList());
378 CPPUNIT_ASSERT_EQUAL(size_t(3), rFormatScheme
.getBackgroundFillStyleList().size());
381 CPPUNIT_TEST_FIXTURE(SwCoreThemeTest
, testDrawPageThemeExistsODT
)
383 createSwDoc("ThemeColorInHeading.fodt");
384 SwDoc
* pDoc
= getSwDoc();
386 SdrModel
* pModel
= pDoc
->getIDocumentDrawModelAccess().GetDrawModel();
387 CPPUNIT_ASSERT(pModel
);
388 auto const& pTheme
= pModel
->getTheme();
389 CPPUNIT_ASSERT(pTheme
);
390 CPPUNIT_ASSERT_EQUAL(u
"Office Theme"_ustr
, pTheme
->GetName());
392 auto pColorSet
= pTheme
->getColorSet();
393 CPPUNIT_ASSERT(pColorSet
);
394 CPPUNIT_ASSERT_EQUAL(u
"Orange"_ustr
, pColorSet
->getName());
396 CPPUNIT_ASSERT_EQUAL(Color(0xE48312), pTheme
->GetColor(model::ThemeColorType::Accent1
));
397 CPPUNIT_ASSERT_EQUAL(Color(0xBD582C), pTheme
->GetColor(model::ThemeColorType::Accent2
));
398 CPPUNIT_ASSERT_EQUAL(Color(0x865640), pTheme
->GetColor(model::ThemeColorType::Accent3
));
399 CPPUNIT_ASSERT_EQUAL(Color(0x9B8357), pTheme
->GetColor(model::ThemeColorType::Accent4
));
400 CPPUNIT_ASSERT_EQUAL(Color(0xC2BC80), pTheme
->GetColor(model::ThemeColorType::Accent5
));
401 CPPUNIT_ASSERT_EQUAL(Color(0x94A088), pTheme
->GetColor(model::ThemeColorType::Accent6
));
402 CPPUNIT_ASSERT_EQUAL(COL_BLACK
, pTheme
->GetColor(model::ThemeColorType::Dark1
));
403 CPPUNIT_ASSERT_EQUAL(Color(0x637052), pTheme
->GetColor(model::ThemeColorType::Dark2
));
404 CPPUNIT_ASSERT_EQUAL(COL_WHITE
, pTheme
->GetColor(model::ThemeColorType::Light1
));
405 CPPUNIT_ASSERT_EQUAL(Color(0xCCDDEA), pTheme
->GetColor(model::ThemeColorType::Light2
));
408 CPPUNIT_TEST_FIXTURE(SwCoreThemeTest
, testThemeChanging
)
410 createSwDoc("ThemeColorInHeading.docx");
411 SwDoc
* pDoc
= getSwDoc();
412 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
413 CPPUNIT_ASSERT(pWrtShell
);
414 SdrModel
* pModel
= pDoc
->getIDocumentDrawModelAccess().GetDrawModel();
415 CPPUNIT_ASSERT(pModel
);
417 // Check current theme colors
419 auto const& pTheme
= pModel
->getTheme();
420 CPPUNIT_ASSERT(pTheme
);
421 CPPUNIT_ASSERT_EQUAL(u
"Office Theme"_ustr
, pTheme
->GetName());
423 auto pColorSet
= pTheme
->getColorSet();
424 CPPUNIT_ASSERT(pColorSet
);
425 CPPUNIT_ASSERT_EQUAL(u
"Orange"_ustr
, pColorSet
->getName());
426 CPPUNIT_ASSERT_EQUAL(Color(0xE48312), pTheme
->GetColor(model::ThemeColorType::Accent1
));
429 // Change theme colors
431 auto const& rColorSets
= svx::ColorSets::get();
433 = std::make_shared
<model::ColorSet
>(*rColorSets
.getColorSet(u
"LibreOffice"));
434 // check that the theme colors are as expected
435 CPPUNIT_ASSERT_EQUAL(u
"LibreOffice"_ustr
, pNewColorSet
->getName());
437 sw::ThemeColorChanger
aChanger(getSwDocShell());
438 aChanger
.apply(pNewColorSet
);
441 // Check new theme colors
443 auto const& pTheme
= pModel
->getTheme();
444 CPPUNIT_ASSERT(pTheme
);
445 CPPUNIT_ASSERT_EQUAL(u
"Office Theme"_ustr
, pTheme
->GetName());
447 auto pColorSet
= pTheme
->getColorSet();
448 CPPUNIT_ASSERT(pColorSet
);
449 CPPUNIT_ASSERT_EQUAL(u
"LibreOffice"_ustr
, pColorSet
->getName());
450 CPPUNIT_ASSERT_EQUAL(Color(0x18A303), pTheme
->GetColor(model::ThemeColorType::Accent1
));
456 // Check theme colors have been reverted
458 auto const& pTheme
= pModel
->getTheme();
459 CPPUNIT_ASSERT(pTheme
);
460 CPPUNIT_ASSERT_EQUAL(u
"Office Theme"_ustr
, pTheme
->GetName());
462 auto pColorSet
= pTheme
->getColorSet();
463 CPPUNIT_ASSERT(pColorSet
);
464 CPPUNIT_ASSERT_EQUAL(u
"Orange"_ustr
, pColorSet
->getName());
465 CPPUNIT_ASSERT_EQUAL(Color(0xE48312), pTheme
->GetColor(model::ThemeColorType::Accent1
));
471 // Check theme colors have been applied again
473 auto const& pTheme
= pModel
->getTheme();
474 CPPUNIT_ASSERT(pTheme
);
475 CPPUNIT_ASSERT_EQUAL(u
"Office Theme"_ustr
, pTheme
->GetName());
477 auto pColorSet
= pTheme
->getColorSet();
478 CPPUNIT_ASSERT(pColorSet
);
479 CPPUNIT_ASSERT_EQUAL(u
"LibreOffice"_ustr
, pColorSet
->getName());
480 CPPUNIT_ASSERT_EQUAL(Color(0x18A303), pTheme
->GetColor(model::ThemeColorType::Accent1
));
484 // A simple transferable, that provides only EMBED_SOURCE and OBJECTDESCRIPTOR flavors, taking
485 // data from an ODT file. This makes the transferable behave just like clipboard content created
486 // by Writer in a different instance, taking SwTransferable::PasteOLE path.
487 class TestSimpleFileTransferable
: public cppu::WeakImplHelper
<css::datatransfer::XTransferable
>
490 TestSimpleFileTransferable(const OUString
& fileURL
);
491 css::uno::Any SAL_CALL
getTransferData(const css::datatransfer::DataFlavor
& flavor
) override
;
492 css::uno::Sequence
<css::datatransfer::DataFlavor
> SAL_CALL
getTransferDataFlavors() override
;
493 sal_Bool SAL_CALL
isDataFlavorSupported(const css::datatransfer::DataFlavor
& flavor
) override
;
499 TestSimpleFileTransferable::TestSimpleFileTransferable(const OUString
& fileURL
)
505 TestSimpleFileTransferable::getTransferData(const css::datatransfer::DataFlavor
& flavor
)
507 if (flavor
.MimeType
== SotExchange::GetFormatMimeType(SotClipboardFormatId::EMBED_SOURCE
))
509 auto xSFA(ucb::SimpleFileAccess::create(comphelper::getProcessComponentContext()));
510 auto xInputStream
= xSFA
->openFileRead(m_fileURL
);
511 sal_Int32 bytes
= xInputStream
->available();
512 css::uno::Sequence
<sal_Int8
> data
;
513 CPPUNIT_ASSERT_EQUAL(bytes
, xInputStream
->readBytes(data
, bytes
));
514 return css::uno::Any(data
);
516 if (flavor
.MimeType
== SotExchange::GetFormatMimeType(SotClipboardFormatId::OBJECTDESCRIPTOR
))
518 TransferableObjectDescriptor aDesc
;
519 aDesc
.maClassName
= SvGlobalName(SO3_SW_CLASSID
);
520 SvMemoryStream
aMemStm(1024, 1024);
521 WriteTransferableObjectDescriptor(aMemStm
, aDesc
);
522 css::uno::Sequence
<sal_Int8
> data(static_cast<const sal_Int8
*>(aMemStm
.GetData()),
524 return css::uno::Any(data
);
529 css::uno::Sequence
<css::datatransfer::DataFlavor
>
530 TestSimpleFileTransferable::getTransferDataFlavors()
532 css::datatransfer::DataFlavor embed_source
;
533 SotExchange::GetFormatDataFlavor(SotClipboardFormatId::EMBED_SOURCE
, embed_source
);
534 css::datatransfer::DataFlavor objectdescriptor
;
535 SotExchange::GetFormatDataFlavor(SotClipboardFormatId::OBJECTDESCRIPTOR
, objectdescriptor
);
536 return { embed_source
, objectdescriptor
};
540 TestSimpleFileTransferable::isDataFlavorSupported(const css::datatransfer::DataFlavor
& flavor
)
542 if (flavor
.MimeType
== SotExchange::GetFormatMimeType(SotClipboardFormatId::EMBED_SOURCE
))
544 if (flavor
.MimeType
== SotExchange::GetFormatMimeType(SotClipboardFormatId::OBJECTDESCRIPTOR
))
549 CPPUNIT_TEST_FIXTURE(SwCoreThemeTest
, testTdf162715_customTransferable
)
551 // Given a document with a custom theme:
552 createSwDoc("theme_foo.fodt");
554 auto pDoc
= getSwDoc();
556 auto pModel
= pDoc
->getIDocumentDrawModelAccess().GetDrawModel();
557 CPPUNIT_ASSERT(pModel
);
558 auto pTheme
= pModel
->getTheme().get();
559 CPPUNIT_ASSERT(pTheme
);
560 CPPUNIT_ASSERT_EQUAL(u
"foo"_ustr
, pTheme
->GetName());
561 CPPUNIT_ASSERT_EQUAL(u
"colors_foo"_ustr
, pTheme
->getColorSet()->getName());
562 CPPUNIT_ASSERT_EQUAL(Color(0x000080), pTheme
->GetColor(model::ThemeColorType::Dark1
));
563 CPPUNIT_ASSERT_EQUAL(Color(0x008000), pTheme
->GetColor(model::ThemeColorType::Dark2
));
565 // Select all and check the original text in the document:
566 auto pWrtShell
= getSwDocShell()->GetWrtShell();
568 CPPUNIT_ASSERT_EQUAL(u
"Theme foo"_ustr
, pWrtShell
->GetSelText());
570 // Create a transferable from another document with another custom theme,
571 // and insert (paste) its content over the selection:
572 css::uno::Reference
<css::datatransfer::XTransferable
> xTransferable(
573 new TestSimpleFileTransferable(createFileURL(u
"theme_bar.odt")));
574 css::uno::Reference
<css::frame::XModel
> xModel(mxComponent
, css::uno::UNO_QUERY_THROW
);
575 css::uno::Reference
<css::datatransfer::XTransferableSupplier
> xTS(
576 xModel
->getCurrentController(), css::uno::UNO_QUERY_THROW
);
577 xTS
->insertTransferable(xTransferable
);
579 // Check that the paste is successful (the text has been replaced):
581 CPPUNIT_ASSERT_EQUAL(u
"Theme bar"_ustr
, pWrtShell
->GetSelText());
583 // The original theme must not be replaced.
584 pTheme
= pModel
->getTheme().get();
585 CPPUNIT_ASSERT(pTheme
);
586 // Without the fix, this would fail, because the name was "bar":
587 CPPUNIT_ASSERT_EQUAL(u
"foo"_ustr
, pTheme
->GetName());
588 CPPUNIT_ASSERT_EQUAL(u
"colors_foo"_ustr
, pTheme
->getColorSet()->getName());
589 CPPUNIT_ASSERT_EQUAL(Color(0x000080), pTheme
->GetColor(model::ThemeColorType::Dark1
));
590 CPPUNIT_ASSERT_EQUAL(Color(0x008000), pTheme
->GetColor(model::ThemeColorType::Dark2
));
593 CPPUNIT_TEST_FIXTURE(SwCoreThemeTest
, testTdf162715_ownTransferable
)
595 css::uno::Reference
<css::datatransfer::XTransferable
> xTransferable
;
597 // Given a document with a custom theme:
598 createSwDoc("theme_bar.odt");
600 auto pDoc
= getSwDoc();
602 auto pModel
= pDoc
->getIDocumentDrawModelAccess().GetDrawModel();
603 CPPUNIT_ASSERT(pModel
);
604 auto pTheme
= pModel
->getTheme().get();
605 CPPUNIT_ASSERT(pTheme
);
606 CPPUNIT_ASSERT_EQUAL(u
"bar"_ustr
, pTheme
->GetName());
607 CPPUNIT_ASSERT_EQUAL(u
"colors_bar"_ustr
, pTheme
->getColorSet()->getName());
608 CPPUNIT_ASSERT_EQUAL(Color(0x606000), pTheme
->GetColor(model::ThemeColorType::Dark1
));
609 CPPUNIT_ASSERT_EQUAL(Color(0x800000), pTheme
->GetColor(model::ThemeColorType::Dark2
));
611 // Select all and check the original text in the document:
612 auto pWrtShell
= getSwDocShell()->GetWrtShell();
614 CPPUNIT_ASSERT_EQUAL(u
"Theme bar"_ustr
, pWrtShell
->GetSelText());
616 // Create a normal Writer's transferable out of the selection:
617 css::uno::Reference
<css::frame::XModel
> xModel(mxComponent
, css::uno::UNO_QUERY_THROW
);
618 css::uno::Reference
<css::datatransfer::XTransferableSupplier
> xTS(
619 xModel
->getCurrentController(), css::uno::UNO_QUERY_THROW
);
620 xTransferable
= xTS
->getTransferable();
623 // Open another document with another custom theme:
624 createSwDoc("theme_foo.fodt");
626 auto pDoc
= getSwDoc();
628 auto pModel
= pDoc
->getIDocumentDrawModelAccess().GetDrawModel();
629 CPPUNIT_ASSERT(pModel
);
630 auto pTheme
= pModel
->getTheme().get();
631 CPPUNIT_ASSERT(pTheme
);
632 CPPUNIT_ASSERT_EQUAL(u
"foo"_ustr
, pTheme
->GetName());
633 CPPUNIT_ASSERT_EQUAL(u
"colors_foo"_ustr
, pTheme
->getColorSet()->getName());
634 CPPUNIT_ASSERT_EQUAL(Color(0x000080), pTheme
->GetColor(model::ThemeColorType::Dark1
));
635 CPPUNIT_ASSERT_EQUAL(Color(0x008000), pTheme
->GetColor(model::ThemeColorType::Dark2
));
637 // Select all and check the original text in the second document:
638 auto pWrtShell
= getSwDocShell()->GetWrtShell();
640 CPPUNIT_ASSERT_EQUAL(u
"Theme foo"_ustr
, pWrtShell
->GetSelText());
642 // Insert (paste) the previously created transferable's content over the selection:
643 css::uno::Reference
<css::frame::XModel
> xModel(mxComponent
, css::uno::UNO_QUERY_THROW
);
644 css::uno::Reference
<css::datatransfer::XTransferableSupplier
> xTS(
645 xModel
->getCurrentController(), css::uno::UNO_QUERY_THROW
);
646 xTS
->insertTransferable(xTransferable
);
648 // Check that the paste is successful (the text has been replaced):
650 CPPUNIT_ASSERT_EQUAL(u
"Theme bar"_ustr
, pWrtShell
->GetSelText());
652 // The original theme must not be replaced.
653 pTheme
= pModel
->getTheme().get();
654 CPPUNIT_ASSERT(pTheme
);
655 CPPUNIT_ASSERT_EQUAL(u
"foo"_ustr
, pTheme
->GetName());
656 CPPUNIT_ASSERT_EQUAL(u
"colors_foo"_ustr
, pTheme
->getColorSet()->getName());
657 CPPUNIT_ASSERT_EQUAL(Color(0x000080), pTheme
->GetColor(model::ThemeColorType::Dark1
));
658 CPPUNIT_ASSERT_EQUAL(Color(0x008000), pTheme
->GetColor(model::ThemeColorType::Dark2
));
662 } // end anonymous namespace
664 CPPUNIT_PLUGIN_IMPLEMENT();
666 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */