Update ooo320-m1
[ooovba.git] / sd / source / ui / slidesorter / view / SlsFontProvider.cxx
blob23c87186648c62a62dde83ff18a3e8498a9e0d63
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlsFontProvider.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "view/SlsFontProvider.hxx"
36 #include "controller/SlideSorterController.hxx"
38 #include <sfx2/app.hxx>
39 #include <com/sun/star/uno/RuntimeException.hpp>
42 using namespace ::sd::slidesorter;
44 namespace sd { namespace slidesorter { namespace view {
46 FontProvider* FontProvider::mpInstance = NULL;
48 FontProvider& FontProvider::Instance (void)
50 if (mpInstance == NULL)
52 ::osl::GetGlobalMutex aMutexFunctor;
53 ::osl::MutexGuard aGuard (aMutexFunctor());
54 if (mpInstance == NULL)
56 // Create an instance of the class and register it at the
57 // SdGlobalResourceContainer so that it is eventually released.
58 FontProvider* pInstance = new FontProvider();
59 SdGlobalResourceContainer::Instance().AddResource (
60 ::std::auto_ptr<SdGlobalResource>(pInstance));
61 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
62 mpInstance = pInstance;
65 else
67 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
70 // We throw an exception when for some strange reason no instance of
71 // this class exists.
72 if (mpInstance == NULL)
73 throw ::com::sun::star::uno::RuntimeException(::rtl::OUString(
74 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.IndexedPropertyValues")),
75 NULL);
77 return *mpInstance;
83 FontProvider::FontProvider (void)
84 : maFont(),
85 maMapMode()
92 FontProvider::~FontProvider (void)
99 void FontProvider::Invalidate (void)
101 maFont.reset();
107 FontProvider::SharedFontPointer FontProvider::GetFont (const OutputDevice& rDevice)
109 // Reset the font when the map mode has changed since its creation.
110 if (maMapMode != rDevice.GetMapMode())
111 maFont.reset();
113 if (maFont.get() == NULL)
115 // Initialize the font from the application style settings.
116 maFont.reset(new Font (Application::GetSettings().GetStyleSettings().GetAppFont()));
117 maFont->SetTransparent(TRUE);
118 maFont->SetWeight(WEIGHT_NORMAL);
120 // Transform the point size to pixel size.
121 MapMode aFontMapMode (MAP_POINT);
122 Size aFontSize (rDevice.LogicToPixel(maFont->GetSize(), aFontMapMode));
124 // Transform the font size to the logical coordinates of the device.
125 maFont->SetSize (rDevice.PixelToLogic(aFontSize));
127 // Remember the map mode of the given device to detect different
128 // devices or modified zoom scales on future calls.
129 maMapMode = rDevice.GetMapMode();
132 return maFont;
135 } } } // end of namespace ::sd::slidesorter::view