summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2012-09-03 18:07:34 +0200
committerLuboš Luňák <l.lunak@suse.cz>2012-09-06 17:35:45 +0200
commitb7e56788135c1c6179cbc5387e41a66a85a7460b (patch)
tree3ad9a41dc98f3eb9b4090f3ff7c6cf6147e9f179 /vcl
parentc1c8adca05b561afbbf3346b73225d80f2b82ee4 (diff)
basic support for temporary fonts
To be used when loading fonts embedded in documents. Change-Id: I634af1b35eba48872d045e726d1d879f455d6f2c
Diffstat (limited to 'vcl')
-rw-r--r--vcl/generic/fontmanager/fontmanager.cxx43
-rw-r--r--vcl/inc/vcl/fontmanager.hxx23
2 files changed, 66 insertions, 0 deletions
diff --git a/vcl/generic/fontmanager/fontmanager.cxx b/vcl/generic/fontmanager/fontmanager.cxx
index 2a3d29ae8293..7b9294aeecdf 100644
--- a/vcl/generic/fontmanager/fontmanager.cxx
+++ b/vcl/generic/fontmanager/fontmanager.cxx
@@ -43,6 +43,8 @@
#include "vcl/fontmanager.hxx"
#include "vcl/strhelper.hxx"
#include "vcl/ppdparser.hxx"
+#include <vcl/svapp.hxx>
+#include <vcl/outdev.hxx>
#include "tools/urlobj.hxx"
#include "tools/stream.hxx"
@@ -51,6 +53,7 @@
#include "osl/file.hxx"
#include "osl/process.h"
+#include <rtl/bootstrap.hxx>
#include "rtl/tencinfo.h"
#include "rtl/ustrbuf.hxx"
#include "rtl/strbuf.hxx"
@@ -1034,6 +1037,7 @@ PrintFontManager::~PrintFontManager()
delete m_pAtoms;
if( m_pFontCache )
delete m_pFontCache;
+ cleanTemporaryFonts();
}
// -------------------------------------------------------------------------
@@ -1660,6 +1664,8 @@ void PrintFontManager::initialize()
CALLGRIND_ZERO_STATS();
#endif
+ cleanTemporaryFonts();
+
long aDirEntBuffer[ (sizeof(struct dirent)+_PC_NAME_MAX)+1 ];
if( ! m_pFontCache )
@@ -3057,4 +3063,41 @@ 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 6666f0ffda0d..81b420031306 100644
--- a/vcl/inc/vcl/fontmanager.hxx
+++ b/vcl/inc/vcl/fontmanager.hxx
@@ -330,6 +330,8 @@ class VCL_PLUGIN_PUBLIC 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>
@@ -593,6 +595,27 @@ 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