summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2013-02-21 13:43:44 +0100
committerLuboš Luňák <l.lunak@suse.cz>2013-02-26 11:43:21 +0100
commit381154356c15128255e313f37641f0e50145f965 (patch)
tree6a435b01cf5f2a7b2d06da0c6632a1ad170e678f /vcl
parent0d8169955a3ccfb314605c06a790919175d30de0 (diff)
embed also system fonts when embedding fonts in a document
Without this, only fonts that had come embedded with the document were embedded when saving, which meant that it was impossible to create new documents that would have any fonts embedded. Change-Id: I3b4e87b1b3ca5ae1ccfe29d9b571b0262c568dcf
Diffstat (limited to 'vcl')
-rw-r--r--vcl/Library_vcl.mk2
-rw-r--r--vcl/Package_inc.mk2
-rw-r--r--vcl/generic/fontmanager/fontmanager.cxx2
-rw-r--r--vcl/inc/vcl/embeddedfontshelper.hxx (renamed from vcl/inc/vcl/temporaryfonts.hxx)26
-rw-r--r--vcl/source/app/svmain.cxx6
-rw-r--r--vcl/source/gdi/embeddedfontshelper.cxx104
-rw-r--r--vcl/source/gdi/temporaryfonts.cxx56
7 files changed, 125 insertions, 73 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index c71543de585b..49c1c786efae 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -207,6 +207,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/gdi/configsettings \
vcl/source/gdi/cvtgrf \
vcl/source/gdi/cvtsvm \
+ vcl/source/gdi/embeddedfontshelper \
vcl/source/gdi/extoutdevdata \
vcl/source/gdi/font \
vcl/source/gdi/gdimtf \
@@ -255,7 +256,6 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/gdi/salmisc \
vcl/source/gdi/salnativewidgets-none \
vcl/source/gdi/svgdata \
- 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 53a7326279b1..6088b66f2dd3 100644
--- a/vcl/Package_inc.mk
+++ b/vcl/Package_inc.mk
@@ -144,7 +144,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/embeddedfontshelper.hxx,vcl/embeddedfontshelper.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 175b000c8c5e..cd5e437408ab 100644
--- a/vcl/generic/fontmanager/fontmanager.cxx
+++ b/vcl/generic/fontmanager/fontmanager.cxx
@@ -33,7 +33,7 @@
#include "vcl/fontmanager.hxx"
#include "vcl/strhelper.hxx"
#include "vcl/ppdparser.hxx"
-#include <vcl/temporaryfonts.hxx>
+#include <vcl/embeddedfontshelper.hxx>
#include "tools/urlobj.hxx"
#include "tools/stream.hxx"
diff --git a/vcl/inc/vcl/temporaryfonts.hxx b/vcl/inc/vcl/embeddedfontshelper.hxx
index f8fe162c67b1..96e8226b3b00 100644
--- a/vcl/inc/vcl/temporaryfonts.hxx
+++ b/vcl/inc/vcl/embeddedfontshelper.hxx
@@ -7,31 +7,35 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#ifndef VCL_TEMPORARYFONTS_HXX
-#define VCL_TEMPORARYFONTS_HXX
+#ifndef VCL_EMBEDDEDFONTSHELPER_HXX
+#define VCL_EMBEDDEDFONTSHELPER_HXX
#include <vcl/dllapi.h>
#include <rtl/ustring.hxx>
+#include <tools/fontenum.hxx>
/**
- Management of temporary fonts (e.g. embedded in documents).
+ Helper functions for handling embedded fonts in documents.
- This class handles adding of temporary fonts.
- @since LibreOffice 4.0
*/
-class VCL_DLLPUBLIC TemporaryFonts
+class VCL_DLLPUBLIC EmbeddedFontsHelper
{
public:
/**
- Returns an URL for a file where to store contents of a temporary font
- (the file may or may not exist). The file will be cleaned up automatically as appropriate.
+ Returns URL for a font file for the given font, or empty if it does not exist.
+ */
+ static OUString fontFileUrl( const OUString& familyName, FontFamily family, FontItalic italic,
+ FontWeight weight, FontPitch pitch, rtl_TextEncoding encoding );
+ /**
+ Returns an URL for a file where to store contents of a given temporary font.
+ The file may or not may not exist yet, and 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 );
+ static 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
@@ -43,10 +47,10 @@ public:
static void activateFont( const OUString& fontName, const OUString& fileUrl );
/**
- Removes all temporary fonts.
+ Removes all temporary fonts in the path used by fileUrlForTemporaryFont().
@internal
*/
- static void clear();
+ static void clearTemporaryFontFiles();
};
#endif
diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx
index 7f22828fa1e1..c89a04e110c6 100644
--- a/vcl/source/app/svmain.cxx
+++ b/vcl/source/app/svmain.cxx
@@ -40,7 +40,7 @@
#include "vcl/unowrap.hxx"
#include "vcl/configsettings.hxx"
#include "vcl/lazydelete.hxx"
-#include "vcl/temporaryfonts.hxx"
+#include "vcl/embeddedfontshelper.hxx"
#ifdef WNT
#include <svsys.h>
@@ -248,7 +248,7 @@ sal_Bool InitVCL()
if( pExceptionHandler != NULL )
return sal_False;
- TemporaryFonts::clear();
+ EmbeddedFontsHelper::clearTemporaryFontFiles();
if( ! ImplGetSVData() )
ImplInitSVData();
@@ -575,7 +575,7 @@ void DeInitVCL()
pOwnSvApp = NULL;
}
- TemporaryFonts::clear();
+ EmbeddedFontsHelper::clearTemporaryFontFiles();
}
// only one call is allowed
diff --git a/vcl/source/gdi/embeddedfontshelper.cxx b/vcl/source/gdi/embeddedfontshelper.cxx
new file mode 100644
index 000000000000..b5d1c01d8432
--- /dev/null
+++ b/vcl/source/gdi/embeddedfontshelper.cxx
@@ -0,0 +1,104 @@
+/* -*- 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/embeddedfontshelper.hxx>
+
+#include <osl/file.hxx>
+#include <rtl/bootstrap.hxx>
+#include <vcl/fontmanager.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/outdev.hxx>
+
+using namespace std;
+
+void EmbeddedFontsHelper::clearTemporaryFontFiles()
+{
+ OUString path = "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}";
+ rtl::Bootstrap::expandMacros( path );
+ path += "/user/temp/embeddedfonts/";
+ osl::Directory dir( path );
+ if( dir.reset() == osl::Directory::E_None )
+ {
+ 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 EmbeddedFontsHelper::fileUrlForTemporaryFont( const OUString& fontName, const char* fontStyle )
+{
+ OUString path = "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}";
+ rtl::Bootstrap::expandMacros( path );
+ path += "/user/temp/embeddedfonts/";
+ 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 EmbeddedFontsHelper::activateFont( const OUString& fontName, const OUString& fileUrl )
+{
+ OutputDevice *pDevice = Application::GetDefaultDevice();
+ pDevice->AddTempDevFont( fileUrl, fontName );
+ pDevice->ImplUpdateAllFontData( true );
+}
+
+OUString EmbeddedFontsHelper::fontFileUrl( const OUString& familyName, FontFamily family, FontItalic italic,
+ FontWeight weight, FontPitch pitch, rtl_TextEncoding )
+{
+ OUString url;
+ psp::PrintFontManager& mgr = psp::PrintFontManager::get();
+ list< psp::fontID > fontIds;
+ mgr.getFontList( fontIds );
+ for( list< psp::fontID >::const_iterator it = fontIds.begin();
+ it != fontIds.end();
+ ++it )
+ {
+ psp::fontID id = *it;
+ psp::FastPrintFontInfo info;
+ if( !mgr.getFontFastInfo( id, info ))
+ continue;
+ if( info.m_aFamilyName == familyName )
+ {
+ // Ignore comparing text encodings, at least for now. They cannot be trivially compared
+ // (e.g. UCS2 and UTF8 are technically the same characters, just have different encoding,
+ // and just having a unicode font doesn't say what glyphs it actually contains).
+ // It is possible that it still may be needed to do at least some checks here
+ // for some encodings (can one font have more font files for more encodings?).
+ if(( family == FAMILY_DONTKNOW || info.m_eFamilyStyle == family )
+ && ( italic == ITALIC_DONTKNOW || info.m_eItalic == italic )
+ && ( weight == WEIGHT_DONTKNOW || info.m_eWeight == weight )
+ && ( pitch == PITCH_DONTKNOW || info.m_ePitch == pitch ))
+ { // Exact match, return it immediately.
+ OUString ret;
+ osl::File::getFileURLFromSystemPath(
+ OStringToOUString( mgr.getFontFileSysPath( id ), RTL_TEXTENCODING_UTF8 ), ret );
+ return ret;
+ }
+ if(( info.m_eFamilyStyle == FAMILY_DONTKNOW || family == FAMILY_DONTKNOW || info.m_eFamilyStyle == family )
+ && ( info.m_eItalic == ITALIC_DONTKNOW || italic == ITALIC_DONTKNOW || info.m_eItalic == italic )
+ && ( info.m_eWeight == WEIGHT_DONTKNOW || weight == WEIGHT_DONTKNOW || info.m_eWeight == weight )
+ && ( info.m_ePitch == PITCH_DONTKNOW || pitch == PITCH_DONTKNOW || info.m_ePitch == pitch ))
+ { // Some fonts specify 'DONTKNOW' for some things, still a good match, if we don't find a better one.
+ osl::File::getFileURLFromSystemPath(
+ OStringToOUString( mgr.getFontFileSysPath( id ), RTL_TEXTENCODING_UTF8 ), url );
+ }
+ }
+ }
+ return url;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/temporaryfonts.cxx b/vcl/source/gdi/temporaryfonts.cxx
deleted file mode 100644
index 292e09e25485..000000000000
--- a/vcl/source/gdi/temporaryfonts.cxx
+++ /dev/null
@@ -1,56 +0,0 @@
-/* -*- 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 );
- if( dir.reset() == osl::Directory::E_None )
- {
- 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: */