1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include "view/SlsFontProvider.hxx"
28 
29 #include "controller/SlideSorterController.hxx"
30 
31 #include <sfx2/app.hxx>
32 #include <com/sun/star/uno/RuntimeException.hpp>
33 
34 
35 using namespace ::sd::slidesorter;
36 
37 namespace sd { namespace slidesorter { namespace view {
38 
39 FontProvider* FontProvider::mpInstance = NULL;
40 
Instance(void)41 FontProvider& FontProvider::Instance (void)
42 {
43 	if (mpInstance == NULL)
44 	{
45 		::osl::GetGlobalMutex aMutexFunctor;
46 		::osl::MutexGuard aGuard (aMutexFunctor());
47 		if (mpInstance == NULL)
48 		{
49 			// Create an instance of the class and register it at the
50 			// SdGlobalResourceContainer so that it is eventually released.
51 			FontProvider* pInstance = new FontProvider();
52 			SdGlobalResourceContainer::Instance().AddResource (
53 				::std::auto_ptr<SdGlobalResource>(pInstance));
54 			OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
55 			mpInstance = pInstance;
56 		}
57 	}
58 	else
59 	{
60 		OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
61 	}
62 
63 	// We throw an exception when for some strange reason no instance of
64 	// this class exists.
65 	if (mpInstance == NULL)
66 		throw ::com::sun::star::uno::RuntimeException(::rtl::OUString(
67 			RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.IndexedPropertyValues")),
68 			NULL);
69 
70 	return *mpInstance;
71 }
72 
73 
74 
75 
FontProvider(void)76 FontProvider::FontProvider (void)
77 	: maFont(),
78 	  maMapMode()
79 {
80 }
81 
82 
83 
84 
~FontProvider(void)85 FontProvider::~FontProvider (void)
86 {
87 }
88 
89 
90 
91 
Invalidate(void)92 void FontProvider::Invalidate (void)
93 {
94 	maFont.reset();
95 }
96 
97 
98 
99 
GetFont(const OutputDevice & rDevice)100 FontProvider::SharedFontPointer FontProvider::GetFont (const OutputDevice& rDevice)
101 {
102 	// Reset the font when the map mode has changed since its creation.
103 	if (maMapMode != rDevice.GetMapMode())
104 		maFont.reset();
105 
106 	if (maFont.get() == NULL)
107 	{
108 		// Initialize the font from the application style settings.
109 		maFont.reset(new Font (Application::GetSettings().GetStyleSettings().GetAppFont()));
110 		maFont->SetTransparent(sal_True);
111 		maFont->SetWeight(WEIGHT_NORMAL);
112 
113 		// Transform the point size to pixel size.
114 		MapMode aFontMapMode (MAP_POINT);
115 		Size aFontSize (rDevice.LogicToPixel(maFont->GetSize(), aFontMapMode));
116 
117 		// Transform the font size to the logical coordinates of the device.
118 		maFont->SetSize (rDevice.PixelToLogic(aFontSize));
119 
120 		// Remember the map mode of the given device to detect different
121 		// devices or modified zoom scales on future calls.
122 		maMapMode = rDevice.GetMapMode();
123 	}
124 
125 	return maFont;
126 }
127 
128 } } } // end of namespace ::sd::slidesorter::view
129