xref: /AOO41X/main/sd/source/ui/slidesorter/view/SlsFontProvider.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "view/SlsFontProvider.hxx"
32 
33 #include "controller/SlideSorterController.hxx"
34 
35 #include <sfx2/app.hxx>
36 #include <com/sun/star/uno/RuntimeException.hpp>
37 
38 
39 using namespace ::sd::slidesorter;
40 
41 namespace sd { namespace slidesorter { namespace view {
42 
43 FontProvider* FontProvider::mpInstance = NULL;
44 
45 FontProvider& FontProvider::Instance (void)
46 {
47     if (mpInstance == NULL)
48     {
49         ::osl::GetGlobalMutex aMutexFunctor;
50         ::osl::MutexGuard aGuard (aMutexFunctor());
51         if (mpInstance == NULL)
52         {
53             // Create an instance of the class and register it at the
54             // SdGlobalResourceContainer so that it is eventually released.
55             FontProvider* pInstance = new FontProvider();
56             SdGlobalResourceContainer::Instance().AddResource (
57                 ::std::auto_ptr<SdGlobalResource>(pInstance));
58             OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
59             mpInstance = pInstance;
60         }
61     }
62     else
63     {
64         OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
65     }
66 
67     // We throw an exception when for some strange reason no instance of
68     // this class exists.
69     if (mpInstance == NULL)
70         throw ::com::sun::star::uno::RuntimeException(::rtl::OUString(
71             RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.IndexedPropertyValues")),
72             NULL);
73 
74     return *mpInstance;
75 }
76 
77 
78 
79 
80 FontProvider::FontProvider (void)
81     : maFont(),
82       maMapMode()
83 {
84 }
85 
86 
87 
88 
89 FontProvider::~FontProvider (void)
90 {
91 }
92 
93 
94 
95 
96 void FontProvider::Invalidate (void)
97 {
98     maFont.reset();
99 }
100 
101 
102 
103 
104 FontProvider::SharedFontPointer FontProvider::GetFont (const OutputDevice& rDevice)
105 {
106     // Reset the font when the map mode has changed since its creation.
107     if (maMapMode != rDevice.GetMapMode())
108         maFont.reset();
109 
110     if (maFont.get() == NULL)
111     {
112         // Initialize the font from the application style settings.
113         maFont.reset(new Font (Application::GetSettings().GetStyleSettings().GetAppFont()));
114         maFont->SetTransparent(sal_True);
115         maFont->SetWeight(WEIGHT_NORMAL);
116 
117         // Transform the point size to pixel size.
118         MapMode aFontMapMode (MAP_POINT);
119         Size aFontSize (rDevice.LogicToPixel(maFont->GetSize(), aFontMapMode));
120 
121         // Transform the font size to the logical coordinates of the device.
122         maFont->SetSize (rDevice.PixelToLogic(aFontSize));
123 
124         // Remember the map mode of the given device to detect different
125         // devices or modified zoom scales on future calls.
126         maMapMode = rDevice.GetMapMode();
127     }
128 
129     return maFont;
130 }
131 
132 } } }  // end of namespace ::sd::slidesorter::view
133