LibreOffice Module sdext (master) 1
PresenterTheme.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "PresenterTheme.hxx"
24#include <com/sun/star/drawing/XPresenterHelper.hpp>
25#include <com/sun/star/rendering/PanoseWeight.hpp>
26#include <osl/diagnose.h>
27#include <map>
28#include <numeric>
29#include <utility>
30
31using namespace ::com::sun::star;
32using namespace ::com::sun::star::uno;
33using namespace ::std;
34
35namespace sdext::presenter {
36
37namespace {
38
39class BorderSize
40{
41public:
42 const static sal_Int32 mnInvalidValue = -10000;
43
44 BorderSize() : mnLeft(mnInvalidValue),
48
49 sal_Int32 mnLeft;
50 sal_Int32 mnTop;
51 sal_Int32 mnRight;
52 sal_Int32 mnBottom;
53
54 vector<sal_Int32> ToVector()
55 {
56 return
57 {
59 mnTop == mnInvalidValue ? 0 : mnTop,
62 };
63 };
64
65 void Merge (const BorderSize& rBorderSize)
66 {
68 mnLeft = rBorderSize.mnLeft;
69 if (mnTop == mnInvalidValue)
70 mnTop = rBorderSize.mnTop;
72 mnRight = rBorderSize.mnRight;
74 mnBottom = rBorderSize.mnBottom;
75 }
76};
77
82class ReadContext
83{
84public:
85 Reference<XComponentContext> mxComponentContext;
86 Reference<rendering::XCanvas> mxCanvas;
87 Reference<drawing::XPresenterHelper> mxPresenterHelper;
88
89 ReadContext (
90 const Reference<XComponentContext>& rxContext,
91 const Reference<rendering::XCanvas>& rxCanvas);
92
99 const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxTheme,
100 const PresenterTheme::SharedFontDescriptor& rpDefault);
102 const Reference<beans::XPropertySet>& rxFontProperties,
103 const PresenterTheme::SharedFontDescriptor& rpDefault);
104
105 std::shared_ptr<PresenterTheme::Theme> ReadTheme (
106 PresenterConfigurationAccess& rConfiguration,
107 const OUString& rsThemeName);
108
109 static BorderSize ReadBorderSize (const Reference<container::XNameAccess>& rxNode);
110
111private:
112 static Any GetByName (
113 const Reference<container::XNameAccess>& rxNode,
114 const OUString& rsName);
115};
116
119class PaneStyle
120{
121public:
122 PaneStyle();
123
124 SharedBitmapDescriptor GetBitmap (const OUString& sBitmapName) const;
125
126 OUString msStyleName;
127 std::shared_ptr<PaneStyle> mpParentStyle;
131 std::shared_ptr<PresenterBitmapContainer> mpBitmaps;
132
134};
135
136typedef std::shared_ptr<PaneStyle> SharedPaneStyle;
137
138class PaneStyleContainer
139{
140private:
141 ::std::vector<SharedPaneStyle> mStyles;
142
143public:
144 void Read (
145 const ReadContext& rReadContext,
146 const Reference<container::XHierarchicalNameAccess>& rThemeRoot);
147
148 SharedPaneStyle GetPaneStyle (const OUString& rsStyleName) const;
149
150private:
151 void ProcessPaneStyle (
152 ReadContext const & rReadContext,
153 const ::std::vector<css::uno::Any>& rValues);
154};
155
158class ViewStyle
159{
160public:
161 ViewStyle();
162
163 SharedBitmapDescriptor GetBitmap (std::u16string_view sBitmapName) const;
164
166
167 OUString msStyleName;
168 std::shared_ptr<ViewStyle> mpParentStyle;
171};
172
173typedef std::shared_ptr<ViewStyle> SharedViewStyle;
174
175class ViewStyleContainer
176{
177private:
178 ::std::vector<SharedViewStyle> mStyles;
179
180public:
181 void Read (
182 const ReadContext& rReadContext,
183 const Reference<container::XHierarchicalNameAccess>& rThemeRoot);
184
185 SharedViewStyle GetViewStyle (const OUString& rsStyleName) const;
186
187private:
188 void ProcessViewStyle(
189 ReadContext const & rReadContext,
190 const Reference<beans::XPropertySet>& rxProperties);
191};
192
193class StyleAssociationContainer
194{
195public:
196 void Read (
197 const Reference<container::XHierarchicalNameAccess>& rThemeRoot);
198
199 OUString GetStyleName (const OUString& rsResourceName) const;
200
201private:
202 typedef map<OUString, OUString> StyleAssociations;
203 StyleAssociations maStyleAssociations;
204
205 void ProcessStyleAssociation(
206 const ::std::vector<css::uno::Any>& rValues);
207};
208
209} // end of anonymous namespace
210
212{
213public:
214 Theme (
215 const Reference<container::XHierarchicalNameAccess>& rThemeRoot,
216 OUString sNodeName);
217
218 void Read (
219 PresenterConfigurationAccess& rConfiguration,
220 ReadContext& rReadContext);
221
223 std::shared_ptr<Theme> mpParentTheme;
225 PaneStyleContainer maPaneStyles;
226 ViewStyleContainer maViewStyles;
227 StyleAssociationContainer maStyleAssociations;
228 Reference<container::XHierarchicalNameAccess> mxThemeRoot;
229 std::shared_ptr<PresenterBitmapContainer> mpIconContainer;
230 typedef map<OUString,SharedFontDescriptor> FontContainer;
232
233 SharedPaneStyle GetPaneStyle (const OUString& rsStyleName) const;
234 SharedViewStyle GetViewStyle (const OUString& rsStyleName) const;
235
236private:
237 void ProcessFont(
238 const OUString& rsKey,
239 const Reference<beans::XPropertySet>& rxProperties);
240};
241
242//===== PresenterTheme ========================================================
243
245 css::uno::Reference<css::uno::XComponentContext> xContext,
246 css::uno::Reference<css::rendering::XCanvas> xCanvas)
247 : mxContext(std::move(xContext)),
248 mxCanvas(std::move(xCanvas))
249{
250 mpTheme = ReadTheme();
251}
252
254{
255}
256
257std::shared_ptr<PresenterTheme::Theme> PresenterTheme::ReadTheme()
258{
259 ReadContext aReadContext(mxContext, mxCanvas);
260
261 PresenterConfigurationAccess aConfiguration (
262 mxContext,
263 "/org.openoffice.Office.PresenterScreen/",
265
266 return aReadContext.ReadTheme(aConfiguration, OUString());
267}
268
270{
271 return mxCanvas.is();
272}
273
274void PresenterTheme::ProvideCanvas (const Reference<rendering::XCanvas>& rxCanvas)
275{
276 if ( ! mxCanvas.is() && rxCanvas.is())
277 {
278 mxCanvas = rxCanvas;
279 ReadTheme();
280 }
281}
282
283OUString PresenterTheme::GetStyleName (const OUString& rsResourceURL) const
284{
285 OUString sStyleName;
286 std::shared_ptr<Theme> pTheme (mpTheme);
287 while (sStyleName.isEmpty() && pTheme != nullptr)
288 {
289 sStyleName = pTheme->maStyleAssociations.GetStyleName(rsResourceURL);
290 pTheme = pTheme->mpParentTheme;
291 }
292 return sStyleName;
293}
294
295::std::vector<sal_Int32> PresenterTheme::GetBorderSize (
296 const OUString& rsStyleName,
297 const bool bOuter) const
298{
299 OSL_ASSERT(mpTheme != nullptr);
300
301 SharedPaneStyle pPaneStyle (mpTheme->GetPaneStyle(rsStyleName));
302 if (pPaneStyle)
303 if (bOuter)
304 return pPaneStyle->maOuterBorderSize.ToVector();
305 else
306 return pPaneStyle->maInnerBorderSize.ToVector();
307 else
308 {
309 return ::std::vector<sal_Int32>(4,0);
310 }
311}
312
314 const Reference<container::XHierarchicalNameAccess>& rxNode,
316{
317 return ReadContext::ReadFont(rxNode, rpDefault);
318}
319
321 const Any& rColorSequence,
322 sal_uInt32& rColor)
323{
324 Sequence<sal_Int8> aByteSequence;
325 if (rColorSequence >>= aByteSequence)
326 {
327 rColor = std::accumulate(std::cbegin(aByteSequence), std::cend(aByteSequence), sal_uInt32(0),
328 [](const sal_uInt32 nRes, const sal_uInt8 nByte) { return (nRes << 8) | nByte; });
329 return true;
330 }
331 else
332 return false;
333}
334
335std::shared_ptr<PresenterConfigurationAccess> PresenterTheme::GetNodeForViewStyle (
336 const OUString& rsStyleName) const
337{
338 if (mpTheme == nullptr)
339 return std::shared_ptr<PresenterConfigurationAccess>();
340
341 // Open configuration for writing.
342 auto pConfiguration = std::make_shared<PresenterConfigurationAccess>(
343 mxContext,
344 "/org.openoffice.Office.PresenterScreen/",
346
347 // Get configuration node for the view style container of the current
348 // theme.
349 if (pConfiguration->GoToChild( OUString(
350 "Presenter/Themes/" + mpTheme->msConfigurationNodeName + "/ViewStyles")))
351 {
352 pConfiguration->GoToChild(
353 [&rsStyleName] (OUString const&, uno::Reference<beans::XPropertySet> const& xProps)
354 {
356 rsStyleName, "StyleName", xProps);
357 });
358 }
359 return pConfiguration;
360}
361
363 const OUString& rsStyleName,
364 const OUString& rsBitmapName) const
365{
366 if (mpTheme != nullptr)
367 {
368 if (rsStyleName.isEmpty())
369 {
370 if (rsBitmapName == "Background")
371 {
372 std::shared_ptr<Theme> pTheme (mpTheme);
373 while (pTheme != nullptr && !pTheme->mpBackground)
374 pTheme = pTheme->mpParentTheme;
375 if (pTheme != nullptr)
376 return pTheme->mpBackground;
377 else
378 return SharedBitmapDescriptor();
379 }
380 }
381 else
382 {
383 SharedPaneStyle pPaneStyle (mpTheme->GetPaneStyle(rsStyleName));
384 if (pPaneStyle)
385 {
386 SharedBitmapDescriptor pBitmap (pPaneStyle->GetBitmap(rsBitmapName));
387 if (pBitmap)
388 return pBitmap;
389 }
390
391 SharedViewStyle pViewStyle (mpTheme->GetViewStyle(rsStyleName));
392 if (pViewStyle)
393 {
394 SharedBitmapDescriptor pBitmap (pViewStyle->GetBitmap(rsBitmapName));
395 if (pBitmap)
396 return pBitmap;
397 }
398 }
399 }
400
401 return SharedBitmapDescriptor();
402}
403
405 const OUString& rsBitmapName) const
406{
407 if (mpTheme != nullptr)
408 {
409 if (rsBitmapName == "Background")
410 {
411 std::shared_ptr<Theme> pTheme (mpTheme);
412 while (pTheme != nullptr && !pTheme->mpBackground)
413 pTheme = pTheme->mpParentTheme;
414 if (pTheme != nullptr)
415 return pTheme->mpBackground;
416 else
417 return SharedBitmapDescriptor();
418 }
419 else
420 {
421 if (mpTheme->mpIconContainer != nullptr)
422 return mpTheme->mpIconContainer->GetBitmap(rsBitmapName);
423 }
424 }
425
426 return SharedBitmapDescriptor();
427}
428
429std::shared_ptr<PresenterBitmapContainer> PresenterTheme::GetBitmapContainer() const
430{
431 if (mpTheme != nullptr)
432 return mpTheme->mpIconContainer;
433 else
434 return std::shared_ptr<PresenterBitmapContainer>();
435}
436
438 const OUString& rsStyleName) const
439{
440 if (mpTheme != nullptr)
441 {
442 SharedPaneStyle pPaneStyle (mpTheme->GetPaneStyle(rsStyleName));
443 if (pPaneStyle)
444 return pPaneStyle->GetFont();
445
446 SharedViewStyle pViewStyle (mpTheme->GetViewStyle(rsStyleName));
447 if (pViewStyle)
448 return pViewStyle->GetFont();
449
450 std::shared_ptr<Theme> pTheme (mpTheme);
451 while (pTheme != nullptr)
452 {
453 Theme::FontContainer::const_iterator iFont (pTheme->maFontContainer.find(rsStyleName));
454 if (iFont != pTheme->maFontContainer.end())
455 return iFont->second;
456
457 pTheme = pTheme->mpParentTheme;
458 }
459 }
460
461 return SharedFontDescriptor();
462}
463
464//===== FontDescriptor ========================================================
465
467 const std::shared_ptr<FontDescriptor>& rpDescriptor)
468 : mnSize(12),
469 mnColor(0x00000000),
470 msAnchor(OUString("Left")),
471 mnXOffset(0),
472 mnYOffset(0)
473{
474 if (rpDescriptor != nullptr)
475 {
476 msFamilyName = rpDescriptor->msFamilyName;
477 msStyleName = rpDescriptor->msStyleName;
478 mnSize = rpDescriptor->mnSize;
479 mnColor = rpDescriptor->mnColor;
480 msAnchor = rpDescriptor->msAnchor;
481 mnXOffset = rpDescriptor->mnXOffset;
482 mnYOffset = rpDescriptor->mnYOffset;
483 }
484}
485
487 const Reference<rendering::XCanvas>& rxCanvas)
488{
489 if (mxFont.is())
490 return true;
491
492 if ( ! rxCanvas.is())
493 return false;
494
495 const double nCellSize (GetCellSizeForDesignSize(rxCanvas, mnSize));
496 mxFont = CreateFont(rxCanvas, nCellSize);
497
498 return mxFont.is();
499}
500
501Reference<rendering::XCanvasFont> PresenterTheme::FontDescriptor::CreateFont (
502 const Reference<rendering::XCanvas>& rxCanvas,
503 const double nCellSize) const
504{
505 rendering::FontRequest aFontRequest;
506 aFontRequest.FontDescription.FamilyName = msFamilyName;
507 if (msFamilyName.isEmpty())
508 aFontRequest.FontDescription.FamilyName = "Tahoma";
509 aFontRequest.FontDescription.StyleName = msStyleName;
510 aFontRequest.CellSize = nCellSize;
511
512 // Make an attempt at translating the style name(s)into a corresponding
513 // font description.
514 if (msStyleName == "Bold")
515 aFontRequest.FontDescription.FontDescription.Weight = rendering::PanoseWeight::HEAVY;
516
517 return rxCanvas->createFont(
518 aFontRequest,
519 Sequence<beans::PropertyValue>(),
520 geometry::Matrix2D(1,0,0,1));
521}
522
524 const Reference<rendering::XCanvas>& rxCanvas,
525 const double nDesignSize) const
526{
527 // Use the given design size as initial value in calculating the cell
528 // size.
529 double nCellSize (nDesignSize);
530
531 if ( ! rxCanvas.is())
532 {
533 // We need the canvas to do the conversion. Return the design size,
534 // it is the our best guess in this circumstance.
535 return nDesignSize;
536 }
537
538 Reference<rendering::XCanvasFont> xFont (CreateFont(rxCanvas, nCellSize));
539 if ( ! xFont.is())
540 return nDesignSize;
541
542 geometry::RealRectangle2D aBox (PresenterCanvasHelper::GetTextBoundingBox (xFont, "X"));
543
544 const double nAscent (-aBox.Y1);
545 //tdf#112408
546 if (nAscent == 0)
547 return nDesignSize;
548 const double nDescent (aBox.Y2);
549 const double nScale = (nAscent+nDescent) / nAscent;
550 return nDesignSize * nScale;
551}
552
553//===== Theme =================================================================
554
556 const Reference<container::XHierarchicalNameAccess>& rxThemeRoot,
557 OUString sNodeName)
558 : msConfigurationNodeName(std::move(sNodeName)),
559 maPaneStyles(),
560 maViewStyles(),
562 mxThemeRoot(rxThemeRoot)
563{
564}
565
567 PresenterConfigurationAccess& rConfiguration,
568 ReadContext& rReadContext)
569{
570 // Parent theme name.
571 OUString sParentThemeName;
572 if ((PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot, "ParentTheme")
573 >>= sParentThemeName)
574 && !sParentThemeName.isEmpty())
575 {
576 mpParentTheme = rReadContext.ReadTheme(rConfiguration, sParentThemeName);
577 }
578
579 // Background.
581 mxThemeRoot,
582 "Background",
583 rReadContext.mxPresenterHelper,
584 rReadContext.mxCanvas,
586
587 // Style associations.
588 maStyleAssociations.Read(mxThemeRoot);
589
590 // Pane styles.
591 maPaneStyles.Read(rReadContext, mxThemeRoot);
592
593 // View styles.
594 maViewStyles.Read(rReadContext, mxThemeRoot);
595
596 // Read bitmaps.
597 mpIconContainer = std::make_shared<PresenterBitmapContainer>(
598 Reference<container::XNameAccess>(
599 PresenterConfigurationAccess::GetConfigurationNode(mxThemeRoot, "Bitmaps"), UNO_QUERY),
600 mpParentTheme != nullptr ? mpParentTheme->mpIconContainer
601 : std::shared_ptr<PresenterBitmapContainer>(),
602 rReadContext.mxComponentContext, rReadContext.mxCanvas);
603
604 // Read fonts.
605 Reference<container::XNameAccess> xFontNode(
607 UNO_QUERY);
609 xFontNode,
610 [this] (OUString const& rKey, uno::Reference<beans::XPropertySet> const& xProps)
611 {
612 return this->ProcessFont(rKey, xProps);
613 });
614}
615
616SharedPaneStyle PresenterTheme::Theme::GetPaneStyle (const OUString& rsStyleName) const
617{
618 SharedPaneStyle pPaneStyle (maPaneStyles.GetPaneStyle(rsStyleName));
619 if (pPaneStyle)
620 return pPaneStyle;
621 else if (mpParentTheme != nullptr)
622 return mpParentTheme->GetPaneStyle(rsStyleName);
623 else
624 return SharedPaneStyle();
625}
626
627SharedViewStyle PresenterTheme::Theme::GetViewStyle (const OUString& rsStyleName) const
628{
629 SharedViewStyle pViewStyle (maViewStyles.GetViewStyle(rsStyleName));
630 if (pViewStyle)
631 return pViewStyle;
632 else if (mpParentTheme != nullptr)
633 return mpParentTheme->GetViewStyle(rsStyleName);
634 else
635 return SharedViewStyle();
636}
637
639 const OUString& rsKey,
640 const Reference<beans::XPropertySet>& rxProperties)
641{
642 maFontContainer[rsKey] = ReadContext::ReadFont(rxProperties, SharedFontDescriptor());
643}
644
645namespace {
646
647//===== ReadContext ===========================================================
648
649ReadContext::ReadContext (
650 const css::uno::Reference<css::uno::XComponentContext>& rxContext,
651 const Reference<rendering::XCanvas>& rxCanvas)
652 : mxComponentContext(rxContext),
653 mxCanvas(rxCanvas)
654{
655 Reference<lang::XMultiComponentFactory> xFactory (rxContext->getServiceManager());
656 if (xFactory.is())
657 {
659 xFactory->createInstanceWithContext(
660 "com.sun.star.comp.Draw.PresenterHelper",
661 rxContext),
662 UNO_QUERY_THROW);
663 }
664}
665
666PresenterTheme::SharedFontDescriptor ReadContext::ReadFont (
667 const Reference<container::XHierarchicalNameAccess>& rxNode,
669{
670 if ( ! rxNode.is())
672
673 try
674 {
675 Reference<container::XHierarchicalNameAccess> xFont (
677 rxNode,
678 /*rsFontPath*/""),
679 UNO_QUERY_THROW);
680
681 Reference<beans::XPropertySet> xProperties (xFont, UNO_QUERY_THROW);
682 return ReadFont(xProperties, rpDefault);
683 }
684 catch (Exception&)
685 {
686 OSL_ASSERT(false);
687 }
688
690}
691
692PresenterTheme::SharedFontDescriptor ReadContext::ReadFont (
693 const Reference<beans::XPropertySet>& rxProperties,
695{
696 auto pDescriptor = std::make_shared<PresenterTheme::FontDescriptor>(rpDefault);
697
698 PresenterConfigurationAccess::GetProperty(rxProperties, "FamilyName") >>= pDescriptor->msFamilyName;
699 PresenterConfigurationAccess::GetProperty(rxProperties, "Style") >>= pDescriptor->msStyleName;
700 PresenterConfigurationAccess::GetProperty(rxProperties, "Size") >>= pDescriptor->mnSize;
702 PresenterConfigurationAccess::GetProperty(rxProperties, "Color"),
703 pDescriptor->mnColor);
704 PresenterConfigurationAccess::GetProperty(rxProperties, "Anchor") >>= pDescriptor->msAnchor;
705 PresenterConfigurationAccess::GetProperty(rxProperties, "XOffset") >>= pDescriptor->mnXOffset;
706 PresenterConfigurationAccess::GetProperty(rxProperties, "YOffset") >>= pDescriptor->mnYOffset;
707
708 return pDescriptor;
709}
710
711Any ReadContext::GetByName (
712 const Reference<container::XNameAccess>& rxNode,
713 const OUString& rsName)
714{
715 OSL_ASSERT(rxNode.is());
716 if (rxNode->hasByName(rsName))
717 return rxNode->getByName(rsName);
718 else
719 return Any();
720}
721
722std::shared_ptr<PresenterTheme::Theme> ReadContext::ReadTheme (
723 PresenterConfigurationAccess& rConfiguration,
724 const OUString& rsThemeName)
725{
726 std::shared_ptr<PresenterTheme::Theme> pTheme;
727
728 OUString sCurrentThemeName (rsThemeName);
729 if (sCurrentThemeName.isEmpty())
730 {
731 // No theme name given. Look up the CurrentTheme property.
732 rConfiguration.GetConfigurationNode("Presenter/CurrentTheme") >>= sCurrentThemeName;
733 if (sCurrentThemeName.isEmpty())
734 {
735 // Still no name. Use "DefaultTheme".
736 sCurrentThemeName = "DefaultTheme";
737 }
738 }
739
740 Reference<container::XNameAccess> xThemes (
741 rConfiguration.GetConfigurationNode("Presenter/Themes"),
742 UNO_QUERY);
743 if (xThemes.is())
744 {
745 // Iterate over all themes and search the one with the given name.
746 const Sequence<OUString> aKeys (xThemes->getElementNames());
747 for (const OUString& rsKey : aKeys)
748 {
749 Reference<container::XHierarchicalNameAccess> xTheme (
750 xThemes->getByName(rsKey), UNO_QUERY);
751 if (xTheme.is())
752 {
753 OUString sThemeName;
755 >>= sThemeName;
756 if (sThemeName == sCurrentThemeName)
757 {
758 pTheme = std::make_shared<PresenterTheme::Theme>(xTheme,rsKey);
759 break;
760 }
761 }
762 }
763 }
764
765 if (pTheme != nullptr)
766 {
767 pTheme->Read(rConfiguration, *this);
768 }
769
770 return pTheme;
771}
772
773BorderSize ReadContext::ReadBorderSize (const Reference<container::XNameAccess>& rxNode)
774{
775 BorderSize aBorderSize;
776
777 if (rxNode.is())
778 {
779 GetByName(rxNode, "Left") >>= aBorderSize.mnLeft;
780 GetByName(rxNode, "Top") >>= aBorderSize.mnTop;
781 GetByName(rxNode, "Right") >>= aBorderSize.mnRight;
782 GetByName(rxNode, "Bottom") >>= aBorderSize.mnBottom;
783 }
784
785 return aBorderSize;
786}
787
788//===== PaneStyleContainer ====================================================
789
790void PaneStyleContainer::Read (
791 const ReadContext& rReadContext,
792 const Reference<container::XHierarchicalNameAccess>& rxThemeRoot)
793{
794 Reference<container::XNameAccess> xPaneStyleList (
796 rxThemeRoot,
797 "PaneStyles"),
798 UNO_QUERY);
799 if (!xPaneStyleList.is())
800 return;
801
802 ::std::vector<OUString> aProperties;
803 aProperties.reserve(6);
804 aProperties.emplace_back("StyleName");
805 aProperties.emplace_back("ParentStyle");
806 aProperties.emplace_back("TitleFont");
807 aProperties.emplace_back("InnerBorderSize");
808 aProperties.emplace_back("OuterBorderSize");
809 aProperties.emplace_back("BorderBitmapList");
811 xPaneStyleList,
812 aProperties,
813 [this, &rReadContext] (std::vector<uno::Any> const& rValues)
814 {
815 return this->ProcessPaneStyle(rReadContext, rValues);
816 });
817}
818
819void PaneStyleContainer::ProcessPaneStyle(
820 ReadContext const & rReadContext,
821 const ::std::vector<Any>& rValues)
822{
823 if (rValues.size() != 6)
824 return;
825
826 auto pStyle = std::make_shared<PaneStyle>();
827
828 rValues[0] >>= pStyle->msStyleName;
829
830 OUString sParentStyleName;
831 if (rValues[1] >>= sParentStyleName)
832 {
833 // Find parent style.
834 auto iStyle = std::find_if(mStyles.begin(), mStyles.end(),
835 [&sParentStyleName](const SharedPaneStyle& rxStyle) { return rxStyle->msStyleName == sParentStyleName; });
836 if (iStyle != mStyles.end())
837 pStyle->mpParentStyle = *iStyle;
838 }
839
840 Reference<container::XHierarchicalNameAccess> xFontNode (rValues[2], UNO_QUERY);
841 pStyle->mpFont = ReadContext::ReadFont(
843
844 Reference<container::XNameAccess> xInnerBorderSizeNode (rValues[3], UNO_QUERY);
845 pStyle->maInnerBorderSize = ReadContext::ReadBorderSize(xInnerBorderSizeNode);
846 Reference<container::XNameAccess> xOuterBorderSizeNode (rValues[4], UNO_QUERY);
847 pStyle->maOuterBorderSize = ReadContext::ReadBorderSize(xOuterBorderSizeNode);
848
849 if (pStyle->mpParentStyle != nullptr)
850 {
851 pStyle->maInnerBorderSize.Merge(pStyle->mpParentStyle->maInnerBorderSize);
852 pStyle->maOuterBorderSize.Merge(pStyle->mpParentStyle->maOuterBorderSize);
853 }
854
855 if (rReadContext.mxCanvas.is())
856 {
857 Reference<container::XNameAccess> xBitmapsNode (rValues[5], UNO_QUERY);
858 pStyle->mpBitmaps = std::make_shared<PresenterBitmapContainer>(
859 xBitmapsNode,
860 pStyle->mpParentStyle != nullptr ? pStyle->mpParentStyle->mpBitmaps
861 : std::shared_ptr<PresenterBitmapContainer>(),
862 rReadContext.mxComponentContext, rReadContext.mxCanvas,
863 rReadContext.mxPresenterHelper);
864 }
865
866 mStyles.push_back(pStyle);
867}
868
869SharedPaneStyle PaneStyleContainer::GetPaneStyle (const OUString& rsStyleName) const
870{
871 auto iStyle = std::find_if(mStyles.begin(), mStyles.end(),
872 [&rsStyleName](const SharedPaneStyle& rxStyle) { return rxStyle->msStyleName == rsStyleName; });
873 if (iStyle != mStyles.end())
874 return *iStyle;
875 return SharedPaneStyle();
876}
877
878//===== PaneStyle =============================================================
879
880PaneStyle::PaneStyle()
881{
882}
883
884SharedBitmapDescriptor PaneStyle::GetBitmap (const OUString& rsBitmapName) const
885{
886 if (mpBitmaps != nullptr)
887 {
888 SharedBitmapDescriptor pBitmap = mpBitmaps->GetBitmap(rsBitmapName);
889 if (pBitmap)
890 return pBitmap;
891 }
892
893 if (mpParentStyle != nullptr)
894 return mpParentStyle->GetBitmap(rsBitmapName);
895 else
896 return SharedBitmapDescriptor();
897}
898
899PresenterTheme::SharedFontDescriptor PaneStyle::GetFont() const
900{
901 if (mpFont)
902 return mpFont;
903 else if (mpParentStyle != nullptr)
904 return mpParentStyle->GetFont();
905 else
907}
908
909//===== ViewStyleContainer ====================================================
910
911void ViewStyleContainer::Read (
912 const ReadContext& rReadContext,
913 const Reference<container::XHierarchicalNameAccess>& rxThemeRoot)
914{
915 Reference<container::XNameAccess> xViewStyleList (
917 rxThemeRoot,
918 "ViewStyles"),
919 UNO_QUERY);
920 if (xViewStyleList.is())
921 {
923 xViewStyleList,
924 [this, &rReadContext] (OUString const&, uno::Reference<beans::XPropertySet> const& xProps)
925 {
926 return this->ProcessViewStyle(rReadContext, xProps);
927 });
928 }
929}
930
931void ViewStyleContainer::ProcessViewStyle(
932 ReadContext const & rReadContext,
933 const Reference<beans::XPropertySet>& rxProperties)
934{
935 auto pStyle = std::make_shared<ViewStyle>();
936
937 PresenterConfigurationAccess::GetProperty(rxProperties, "StyleName")
938 >>= pStyle->msStyleName;
939
940 OUString sParentStyleName;
941 if (PresenterConfigurationAccess::GetProperty(rxProperties, "ParentStyle")
942 >>= sParentStyleName)
943 {
944 // Find parent style.
945 auto iStyle = std::find_if(mStyles.begin(), mStyles.end(),
946 [&sParentStyleName](const SharedViewStyle& rxStyle) { return rxStyle->msStyleName == sParentStyleName; });
947 if (iStyle != mStyles.end())
948 {
949 pStyle->mpParentStyle = *iStyle;
950 pStyle->mpFont = (*iStyle)->mpFont;
951 pStyle->mpBackground = (*iStyle)->mpBackground;
952 }
953 }
954
955 Reference<container::XHierarchicalNameAccess> xFontNode (
956 PresenterConfigurationAccess::GetProperty(rxProperties, "Font"), UNO_QUERY);
958 ReadContext::ReadFont(xFontNode, PresenterTheme::SharedFontDescriptor()));
959 if (pFont)
960 pStyle->mpFont = pFont;
961
962 Reference<container::XHierarchicalNameAccess> xBackgroundNode (
963 PresenterConfigurationAccess::GetProperty(rxProperties, "Background"),
964 UNO_QUERY);
966 xBackgroundNode,
967 OUString(),
968 rReadContext.mxPresenterHelper,
969 rReadContext.mxCanvas,
971 if (pBackground && pBackground->GetNormalBitmap().is())
972 pStyle->mpBackground = pBackground;
973
974 mStyles.push_back(pStyle);
975}
976
977SharedViewStyle ViewStyleContainer::GetViewStyle (const OUString& rsStyleName) const
978{
979 auto iStyle = std::find_if(mStyles.begin(), mStyles.end(),
980 [&rsStyleName](const SharedViewStyle& rxStyle) { return rxStyle->msStyleName == rsStyleName; });
981 if (iStyle != mStyles.end())
982 return *iStyle;
983 return SharedViewStyle();
984}
985
986//===== ViewStyle =============================================================
987
988ViewStyle::ViewStyle()
989{
990}
991
992SharedBitmapDescriptor ViewStyle::GetBitmap (std::u16string_view rsBitmapName) const
993{
994 if (rsBitmapName == u"Background")
995 return mpBackground;
996 else
997 return SharedBitmapDescriptor();
998}
999
1000PresenterTheme::SharedFontDescriptor ViewStyle::GetFont() const
1001{
1002 if (mpFont)
1003 return mpFont;
1004 else if (mpParentStyle != nullptr)
1005 return mpParentStyle->GetFont();
1006 else
1008}
1009
1010//===== StyleAssociationContainer =============================================
1011
1012void StyleAssociationContainer::Read (
1013 const Reference<container::XHierarchicalNameAccess>& rxThemeRoot)
1014{
1015 Reference<container::XNameAccess> xStyleAssociationList (
1017 rxThemeRoot,
1018 "StyleAssociations"),
1019 UNO_QUERY);
1020 if (!xStyleAssociationList.is())
1021 return;
1022
1023 ::std::vector<OUString> aProperties { "ResourceURL", "StyleName" };
1025 xStyleAssociationList,
1026 aProperties,
1027 [this] (std::vector<uno::Any> const& rValues)
1028 {
1029 return this->ProcessStyleAssociation(rValues);
1030 });
1031}
1032
1033OUString StyleAssociationContainer::GetStyleName (const OUString& rsResourceName) const
1034{
1035 StyleAssociations::const_iterator iAssociation (maStyleAssociations.find(rsResourceName));
1036 if (iAssociation != maStyleAssociations.end())
1037 return iAssociation->second;
1038 else
1039 return OUString();
1040}
1041
1042void StyleAssociationContainer::ProcessStyleAssociation(
1043 const ::std::vector<Any>& rValues)
1044{
1045 if (rValues.size() != 2)
1046 return;
1047
1048 OUString sResourceURL;
1049 OUString sStyleName;
1050 if ((rValues[0] >>= sResourceURL)
1051 && (rValues[1] >>= sStyleName))
1052 {
1053 maStyleAssociations[sResourceURL] = sStyleName;
1054 }
1055}
1056
1057} // end of anonymous namespace
1058
1059} // end of namespace ::sdext::presenter
1060
1061/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > mxComponentContext
sal_Int32 mnTop
std::shared_ptr< PaneStyle > mpParentStyle
::std::vector< SharedPaneStyle > mStyles
StyleAssociations maStyleAssociations
sal_Int32 mnRight
PresenterTheme::SharedFontDescriptor mpFont
Reference< rendering::XCanvas > mxCanvas
static const sal_Int32 mnInvalidValue
sal_Int32 mnBottom
SharedBitmapDescriptor mpBackground
BorderSize maInnerBorderSize
Reference< drawing::XPresenterHelper > mxPresenterHelper
sal_Int32 mnLeft
OUString msStyleName
BorderSize maOuterBorderSize
std::shared_ptr< PresenterBitmapContainer > mpBitmaps
PropertiesInfo aProperties
static std::shared_ptr< BitmapDescriptor > LoadBitmap(const css::uno::Reference< css::container::XHierarchicalNameAccess > &rxNode, const OUString &rsPathToBitmapNode, const css::uno::Reference< css::drawing::XPresenterHelper > &rxPresenterHelper, const css::uno::Reference< css::rendering::XCanvas > &rxCanvas, const std::shared_ptr< BitmapDescriptor > &rpDefaultBitmap)
static css::geometry::RealRectangle2D GetTextBoundingBox(const css::uno::Reference< css::rendering::XCanvasFont > &rxFont, const OUString &rsText, const sal_Int8=css::rendering::TextDirection::WEAK_LEFT_TO_RIGHT)
This class gives access to the configuration.
css::uno::Any GetConfigurationNode(const OUString &rsPathToNode)
Return a configuration node below the root of the called object.
static css::uno::Any GetProperty(const css::uno::Reference< css::beans::XPropertySet > &rxProperties, const OUString &rsKey)
This method wraps a call to getPropertyValue() and returns an empty Any instead of throwing an except...
static void ForAll(const css::uno::Reference< css::container::XNameAccess > &rxContainer, const ::std::vector< OUString > &rArguments, const ItemProcessor &rProcessor)
Execute a functor for all elements of the given container.
static bool IsStringPropertyEqual(std::u16string_view rsValue, const OUString &rsPropertyName, const css::uno::Reference< css::beans::XPropertySet > &rxNode)
css::uno::Reference< css::rendering::XCanvasFont > CreateFont(const css::uno::Reference< css::rendering::XCanvas > &rxCanvas, const double nCellSize) const
double GetCellSizeForDesignSize(const css::uno::Reference< css::rendering::XCanvas > &rxCanvas, const double nDesignSize) const
FontDescriptor(const std::shared_ptr< FontDescriptor > &rpDescriptor)
bool PrepareFont(const css::uno::Reference< css::rendering::XCanvas > &rxCanvas)
SharedPaneStyle GetPaneStyle(const OUString &rsStyleName) const
void ProcessFont(const OUString &rsKey, const Reference< beans::XPropertySet > &rxProperties)
StyleAssociationContainer maStyleAssociations
SharedViewStyle GetViewStyle(const OUString &rsStyleName) const
std::shared_ptr< PresenterBitmapContainer > mpIconContainer
map< OUString, SharedFontDescriptor > FontContainer
Reference< container::XHierarchicalNameAccess > mxThemeRoot
Theme(const Reference< container::XHierarchicalNameAccess > &rThemeRoot, OUString sNodeName)
void Read(PresenterConfigurationAccess &rConfiguration, ReadContext &rReadContext)
void ProvideCanvas(const css::uno::Reference< css::rendering::XCanvas > &rxCanvas)
SharedBitmapDescriptor GetBitmap(const OUString &rsStyleName, const OUString &rsBitmapName) const
std::shared_ptr< FontDescriptor > SharedFontDescriptor
css::uno::Reference< css::rendering::XCanvas > mxCanvas
css::uno::Reference< css::uno::XComponentContext > mxContext
PresenterTheme(css::uno::Reference< css::uno::XComponentContext > xContext, css::uno::Reference< css::rendering::XCanvas > xCanvas)
static SharedFontDescriptor ReadFont(const css::uno::Reference< css::container::XHierarchicalNameAccess > &rxNode, const SharedFontDescriptor &rDefaultFount)
::std::vector< sal_Int32 > GetBorderSize(const OUString &rsStyleName, const bool bOuter) const
std::shared_ptr< Theme > mpTheme
std::shared_ptr< Theme > ReadTheme()
static bool ConvertToColor(const css::uno::Any &rColorSequence, sal_uInt32 &rColor)
SharedFontDescriptor GetFont(const OUString &rsStyleName) const
OUString GetStyleName(const OUString &rsResourceURL) const
std::shared_ptr< PresenterConfigurationAccess > GetNodeForViewStyle(const OUString &rsStyleName) const
std::shared_ptr< PresenterBitmapContainer > GetBitmapContainer() const
Color mnColor
sal_uInt32 mnSize
uno::Reference< uno::XComponentContext > mxContext
void CreateFont(SvxFont &rFont, const SfxItemSet &rSet, bool bSearchInParent=true, SvtScriptType nScriptType=SvtScriptType::NONE)
Reference< XSingleServiceFactory > xFactory
VCL_DLLPUBLIC SvStream & ReadFont(SvStream &rIStm, vcl::Font &)
std::shared_ptr< PresenterBitmapContainer::BitmapDescriptor > SharedBitmapDescriptor
vcl::Font GetFont(vcl::Font const &rFont, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
uno::Reference< rendering::XCanvasFont > mxFont
unsigned char sal_uInt8