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