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
This commit is contained in:
Luboš Luňák
2012-09-07 14:33:54 +02:00
parent e1276e83e0
commit fc169270ea
8 changed files with 118 additions and 70 deletions

View File

@@ -122,7 +122,7 @@
#include <rtl/strbuf.hxx>
#include <rtl/ustrbuf.hxx>
#include <rtl/ustring.hxx>
#include <vcl/fontmanager.hxx>
#include <vcl/temporaryfonts.hxx>
#include <tools/color.hxx>
@@ -2829,7 +2829,7 @@ static inline char toHexChar( int value )
void DocxAttributeOutput::EmbedFontStyle( const OUString& name, int tag, const char* style )
{
OUString fontUrl = psp::PrintFontManager::get().fileUrlForTemporaryFont( name, style );
OUString fontUrl = TemporaryFonts::fileUrlForFont( name, style );
// If a temporary font file exists for this font, assume it was embedded
// and embed it again.
// TODO IDocumentSettingAccess::EMBED_SYSTEM_FONTS

View File

@@ -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 \

View File

@@ -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))

View File

@@ -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: */

View File

@@ -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

View File

@@ -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: */

View File

@@ -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: */

View File

@@ -24,7 +24,7 @@
#include <osl/file.hxx>
#include <stdio.h>
#include <rtl/tencinfo.h>
#include <vcl/fontmanager.hxx>
#include <vcl/temporaryfonts.hxx>
#include "dmapperLoggers.hxx"
@@ -252,7 +252,7 @@ EmbeddedFontHandler::~EmbeddedFontHandler()
{
if( !inputStream.is())
return;
OUString fileUrl = psp::PrintFontManager::get().fileUrlForTemporaryFont( fontName, style );
OUString fileUrl = TemporaryFonts::fileUrlForFont( fontName, style );
osl::File file( fileUrl );
switch( file.open( osl_File_OpenFlag_Create | osl_File_OpenFlag_Write ))
{
@@ -319,7 +319,7 @@ EmbeddedFontHandler::~EmbeddedFontHandler()
osl::File::remove( fileUrl );
return;
}
psp::PrintFontManager::get().activateTemporaryFont( fontName, fileUrl );
TemporaryFonts::activateFont( fontName, fileUrl );
}
void EmbeddedFontHandler::lcl_attribute( Id name, Value& val )