diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2012-09-07 14:33:54 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2012-09-07 14:37:56 +0200 |
commit | fc169270eaeb8156d40740cd088cd8ed958ea99c (patch) | |
tree | 368c844394526157226afd4a73dbebb0a9ccfc2f /vcl | |
parent | e1276e83e0e914eab8966a189948d2238c82a1b6 (diff) |
move the code for adding temporary fonts to a separate class
I'm a bit confused on how this stuff is separated between platforms,
so better do it this way.
Change-Id: I2dbd9baef587c81ee37b509bde272ef970f5b118
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/Library_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/Package_inc.mk | 1 | ||||
-rw-r--r-- | vcl/generic/fontmanager/fontmanager.cxx | 45 | ||||
-rw-r--r-- | vcl/inc/vcl/fontmanager.hxx | 23 | ||||
-rw-r--r-- | vcl/inc/vcl/temporaryfonts.hxx | 54 | ||||
-rw-r--r-- | vcl/source/gdi/temporaryfonts.cxx | 54 |
6 files changed, 113 insertions, 65 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 0a7c80750679..f8afea0440ce 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -234,6 +234,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/gdi/salmisc \ vcl/source/gdi/salnativewidgets-none \ vcl/source/gdi/svgread \ + vcl/source/gdi/temporaryfonts \ vcl/source/gdi/textlayout \ vcl/source/gdi/virdev \ vcl/source/gdi/wall \ diff --git a/vcl/Package_inc.mk b/vcl/Package_inc.mk index 3f95e97ac184..e791793dbe62 100644 --- a/vcl/Package_inc.mk +++ b/vcl/Package_inc.mk @@ -150,6 +150,7 @@ $(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/tabctrl.hxx,vcl/tabctrl.hxx)) $(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/tabdlg.hxx,vcl/tabdlg.hxx)) $(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/tabpage.hxx,vcl/tabpage.hxx)) $(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/taskpanelist.hxx,vcl/taskpanelist.hxx)) +$(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/temporaryfonts.hxx,vcl/temporaryfonts.hxx)) $(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/textdata.hxx,vcl/textdata.hxx)) $(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/texteng.hxx,vcl/texteng.hxx)) $(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/textview.hxx,vcl/textview.hxx)) diff --git a/vcl/generic/fontmanager/fontmanager.cxx b/vcl/generic/fontmanager/fontmanager.cxx index 7b9294aeecdf..209970d7cd5f 100644 --- a/vcl/generic/fontmanager/fontmanager.cxx +++ b/vcl/generic/fontmanager/fontmanager.cxx @@ -43,8 +43,7 @@ #include "vcl/fontmanager.hxx" #include "vcl/strhelper.hxx" #include "vcl/ppdparser.hxx" -#include <vcl/svapp.hxx> -#include <vcl/outdev.hxx> +#include <vcl/temporaryfonts.hxx> #include "tools/urlobj.hxx" #include "tools/stream.hxx" @@ -53,7 +52,6 @@ #include "osl/file.hxx" #include "osl/process.h" -#include <rtl/bootstrap.hxx> #include "rtl/tencinfo.h" #include "rtl/ustrbuf.hxx" #include "rtl/strbuf.hxx" @@ -1037,7 +1035,7 @@ PrintFontManager::~PrintFontManager() delete m_pAtoms; if( m_pFontCache ) delete m_pFontCache; - cleanTemporaryFonts(); + TemporaryFonts::clear(); } // ------------------------------------------------------------------------- @@ -1664,7 +1662,7 @@ void PrintFontManager::initialize() CALLGRIND_ZERO_STATS(); #endif - cleanTemporaryFonts(); + TemporaryFonts::clear(); long aDirEntBuffer[ (sizeof(struct dirent)+_PC_NAME_MAX)+1 ]; @@ -3063,41 +3061,4 @@ bool PrintFontManager::readOverrideMetrics() return true; } -void PrintFontManager::cleanTemporaryFonts() -{ - OUString path = "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}"; - rtl::Bootstrap::expandMacros( path ); - path += "/user/temp/fonts/"; - osl::Directory dir( path ); - dir.reset(); - for(;;) - { - osl::DirectoryItem item; - if( dir.getNextItem( item ) != osl::Directory::E_None ) - break; - osl::FileStatus status( osl_FileStatus_Mask_FileURL ); - if( item.getFileStatus( status ) == osl::File::E_None ) - osl::File::remove( status.getFileURL()); - } -} - -OUString PrintFontManager::fileUrlForTemporaryFont( const OUString& fontName, const char* fontStyle ) -{ - OUString path = "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}"; - rtl::Bootstrap::expandMacros( path ); - path += "/user/temp/fonts/"; - osl::Directory::createPath( path ); - OUString filename = fontName; - filename += OStringToOUString( fontStyle, RTL_TEXTENCODING_ASCII_US ); - filename += ".ttf"; // TODO is it always ttf? - return path + filename; -} - -void PrintFontManager::activateTemporaryFont( const OUString& fontName, const OUString& fileUrl ) -{ - OutputDevice *pDevice = Application::GetDefaultDevice(); - pDevice->AddTempDevFont( fileUrl, fontName ); - pDevice->ImplUpdateAllFontData( true ); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/vcl/fontmanager.hxx b/vcl/inc/vcl/fontmanager.hxx index b659435523b0..3049be0edf0c 100644 --- a/vcl/inc/vcl/fontmanager.hxx +++ b/vcl/inc/vcl/fontmanager.hxx @@ -330,8 +330,6 @@ class VCL_DLLPUBLIC PrintFontManager rtl::OString getDirectory( int nAtom ) const; int getDirectoryAtom( const rtl::OString& rDirectory, bool bCreate = false ); - void cleanTemporaryFonts(); - /* try to initialize fonts from libfontconfig called from <code>initialize()</code> @@ -595,27 +593,6 @@ public: bool Substitute( FontSelectPattern &rPattern, rtl::OUString& rMissingCodes ); int FreeTypeCharIndex( void *pFace, sal_uInt32 aChar ); - - /** - Returns an URL for a file where to store contents of a temporary font, or an empty string - if this font is already known. The file will be cleaned up automatically as appropriate. - Use activateTemporaryFont() to actually enable usage of the font. - - @param fontName name of the font (e.g. 'Times New Roman') - @param fontStyle font style, "" for regular, "bi" for bold italic, etc. - @since 3.7 - */ - OUString fileUrlForTemporaryFont( const OUString& fontName, const char* fontStyle ); - - /** - Adds the given font to the list of known fonts. The font is used only until application - exit. - - @param fontName name of the font (e.g. 'Times New Roman') - @param fileUrl URL of the font file - @since 3.7 - */ - void activateTemporaryFont( const OUString& fontName, const OUString& fileUrl ); }; } // namespace diff --git a/vcl/inc/vcl/temporaryfonts.hxx b/vcl/inc/vcl/temporaryfonts.hxx new file mode 100644 index 000000000000..6333b92ca647 --- /dev/null +++ b/vcl/inc/vcl/temporaryfonts.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef VCL_TEMPORARYFONTS_HXX +#define VCL_TEMPORARYFONTS_HXX + +#include <vcl/dllapi.h> + +#include <rtl/ustring.hxx> + +/** + Management of temporary fonts (e.g. embedded in documents). + + This class handles adding of temporary fonts. + @since LibreOffice 3.7 +*/ +class VCL_DLLPUBLIC TemporaryFonts +{ +public: + /** + Returns an URL for a file where to store contents of a temporary font, or an empty string + if this font is already known. The file will be cleaned up automatically as appropriate. + Use activateTemporaryFont() to actually enable usage of the font. + + @param fontName name of the font (e.g. 'Times New Roman') + @param fontStyle font style, "" for regular, "bi" for bold italic, etc. + */ + static OUString fileUrlForFont( const OUString& fontName, const char* fontStyle ); + + /** + Adds the given font to the list of known fonts. The font is used only until application + exit. + + @param fontName name of the font (e.g. 'Times New Roman') + @param fileUrl URL of the font file + */ + static void activateFont( const OUString& fontName, const OUString& fileUrl ); + + /** + Removes all temporary fonts. + @internal + */ + static void clear(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/gdi/temporaryfonts.cxx b/vcl/source/gdi/temporaryfonts.cxx new file mode 100644 index 000000000000..e74ea18ee64d --- /dev/null +++ b/vcl/source/gdi/temporaryfonts.cxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <vcl/temporaryfonts.hxx> + +#include <osl/file.hxx> +#include <rtl/bootstrap.hxx> +#include <vcl/svapp.hxx> +#include <vcl/outdev.hxx> + +void TemporaryFonts::clear() +{ + OUString path = "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}"; + rtl::Bootstrap::expandMacros( path ); + path += "/user/temp/fonts/"; + osl::Directory dir( path ); + dir.reset(); + for(;;) + { + osl::DirectoryItem item; + if( dir.getNextItem( item ) != osl::Directory::E_None ) + break; + osl::FileStatus status( osl_FileStatus_Mask_FileURL ); + if( item.getFileStatus( status ) == osl::File::E_None ) + osl::File::remove( status.getFileURL()); + } +} + +OUString TemporaryFonts::fileUrlForFont( const OUString& fontName, const char* fontStyle ) +{ + OUString path = "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}"; + rtl::Bootstrap::expandMacros( path ); + path += "/user/temp/fonts/"; + osl::Directory::createPath( path ); + OUString filename = fontName; + filename += OStringToOUString( fontStyle, RTL_TEXTENCODING_ASCII_US ); + filename += ".ttf"; // TODO is it always ttf? + return path + filename; +} + +void TemporaryFonts::activateFont( const OUString& fontName, const OUString& fileUrl ) +{ + OutputDevice *pDevice = Application::GetDefaultDevice(); + pDevice->AddTempDevFont( fileUrl, fontName ); + pDevice->ImplUpdateAllFontData( true ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |