vcl/inc/vcl/outdev.hxx | 2 vcl/source/gdi/embeddedfontshelper.cxx | 144 ++++++++++++++++++++++----------- vcl/source/gdi/outdev.cxx | 7 - 3 files changed, 101 insertions(+), 52 deletions(-)
New commits: commit 80475eca9fc63c15f0ba49a1e585190dee7affe2 Author: LuboÅ¡ LuÅák <[email protected]> Date: Wed Feb 27 17:41:46 2013 +0100 get installed fonts etc. using SalGraphics This avoids the use of the "generic" Unix-specific PrintFontManager class at the expense of somewhat more clumsy code. Change-Id: I4e6cdcdba4f16d5a3b9d56c3c4972b34339495cf diff --git a/vcl/source/gdi/embeddedfontshelper.cxx b/vcl/source/gdi/embeddedfontshelper.cxx index b063d7d..dfde14a 100644 --- a/vcl/source/gdi/embeddedfontshelper.cxx +++ b/vcl/source/gdi/embeddedfontshelper.cxx @@ -11,20 +11,17 @@ #include <osl/file.hxx> #include <rtl/bootstrap.hxx> -#include <vcl/svapp.hxx> #include <vcl/outdev.hxx> +#include <vcl/svapp.hxx> -#if defined(UNX) && !defined(MACOSX) -#include <vcl/fontmanager.hxx> -#endif - -using namespace std; +#include <boost/scoped_ptr.hpp> +#include <fontsubset.hxx> +#include <outdev.h> +#include <outfont.hxx> +#include <salgdi.hxx> -void EmbeddedFontsHelper::clearTemporaryFontFiles() -{ - OUString path = "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}"; - rtl::Bootstrap::expandMacros( path ); - path += "/user/temp/embeddedfonts/"; +static void clearDir( const OUString& path ) + { osl::Directory dir( path ); if( dir.reset() == osl::Directory::E_None ) { @@ -40,11 +37,20 @@ void EmbeddedFontsHelper::clearTemporaryFontFiles() } } -OUString EmbeddedFontsHelper::fileUrlForTemporaryFont( const OUString& fontName, const char* fontStyle ) +void EmbeddedFontsHelper::clearTemporaryFontFiles() { OUString path = "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}"; rtl::Bootstrap::expandMacros( path ); path += "/user/temp/embeddedfonts/"; + clearDir( path + "fromdocs/" ); + clearDir( path + "fromsystem/" ); +} + +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/fromdocs/"; osl::Directory::createPath( path ); OUString filename = fontName; filename += OStringToOUString( fontStyle, RTL_TEXTENCODING_ASCII_US ); @@ -62,54 +68,98 @@ void EmbeddedFontsHelper::activateFont( const OUString& fontName, const OUString OUString EmbeddedFontsHelper::fontFileUrl( const OUString& familyName, FontFamily family, FontItalic italic, FontWeight weight, FontPitch pitch, rtl_TextEncoding ) { - OUString url; -#if defined(UNX) && !defined(MACOSX) - 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 ) + OUString path = "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}"; + rtl::Bootstrap::expandMacros( path ); + path += "/user/temp/embeddedfonts/fromsystem/"; + osl::Directory::createPath( path ); + OUString filename = familyName + "_" + OUString::number( family ) + "_" + OUString::number( italic ) + + "_" + OUString::number( weight ) + "_" + OUString::number( pitch ); + filename += ".ttf"; // TODO is it always ttf? + OUString url = path + filename; + if( osl::File( url ).open( osl_File_OpenFlag_Read ) == osl::File::E_None ) // = exists() { - psp::fontID id = *it; - psp::FastPrintFontInfo info; - if( !mgr.getFontFastInfo( id, info )) - continue; - if( info.m_aFamilyName == familyName ) + // File with contents of the font file already exists, assume it's been created by a previous call. + return url; + } + bool ok = false; + SalGraphics* graphics = Application::GetDefaultDevice()->ImplGetGraphics(); + ImplDevFontList fonts; + graphics->GetDevFontList( &fonts ); + boost::scoped_ptr< ImplGetDevFontList > fontInfo( fonts.GetDevFontList()); + PhysicalFontFace* selected = NULL; + for( int i = 0; + i < fontInfo->Count(); + ++i ) + { + PhysicalFontFace* f = fontInfo->Get( i ); + if( f->GetFamilyName() == 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 )) + if(( family == FAMILY_DONTKNOW || f->GetFamilyType() == family ) + && ( italic == ITALIC_DONTKNOW || f->GetSlant() == italic ) + && ( weight == WEIGHT_DONTKNOW || f->GetWeight() == weight ) + && ( pitch == PITCH_DONTKNOW || f->GetPitch() == pitch )) { // Exact match, return it immediately. - OUString ret; - osl::File::getFileURLFromSystemPath( - OStringToOUString( mgr.getFontFileSysPath( id ), RTL_TEXTENCODING_UTF8 ), ret ); - return ret; + selected = f; + break; } - 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 )) + if(( f->GetFamilyType() == FAMILY_DONTKNOW || family == FAMILY_DONTKNOW || f->GetFamilyType() == family ) + && ( f->GetSlant() == ITALIC_DONTKNOW || italic == ITALIC_DONTKNOW || f->GetSlant() == italic ) + && ( f->GetWeight() == WEIGHT_DONTKNOW || weight == WEIGHT_DONTKNOW || f->GetWeight() == weight ) + && ( f->GetPitch() == PITCH_DONTKNOW || pitch == PITCH_DONTKNOW || f->GetPitch() == 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 ); + selected = f; + } + } + } + if( selected != NULL ) + { + sal_Ucs unicodes[ 256 ]; + for( int i = 0; + i < 256; + ++i ) + unicodes[ i ] = 'A'; // Just something, not needed, but GetEmbedFontData() needs it. + sal_Int32 widths[ 256 ]; + FontSubsetInfo info; + long size; + if( const void* data = graphics->GetEmbedFontData( selected, unicodes, widths, info, &size )) + { + osl::File file( url ); + if( file.open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create ) == osl::File::E_None ) + { + sal_uInt64 written = 0; + sal_uInt64 totalSize = size; + bool error = false; + while( written < totalSize && !error) + { + sal_uInt64 nowWritten; + switch( file.write( static_cast< const char* >( data ) + written, size - written, nowWritten )) + { + case osl::File::E_None: + written += nowWritten; + break; + case osl::File::E_AGAIN: + case osl::File::E_INTR: + break; + default: + error = true; + break; + } + } + file.close(); + if( error ) + osl::File::remove( url ); + else + ok = true; } + graphics->FreeEmbedFontData( data, size ); } } -#else - (void) familyName; - (void) family; - (void) italic; - (void) weight; - (void) pitch; -#endif - return url; + return ok ? url : ""; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 1bb6cd6e56ea0932868cba0ec9fe9736a5b8066e Author: LuboÅ¡ LuÅák <[email protected]> Date: Wed Feb 27 15:52:18 2013 +0100 make OutputDevice::ImplGetGraphics() return the SalGraphics* Currently it returns int, meaning to be actually a bool returning whether the call was successful. The pointer can work the same way, but moreover allows access to SalGraphics* also from outside of the class (otherwise I don't see much point in the method being public). To be used by code for embedded fonts handling for getting a list of fonts etc. Change-Id: I64f2acd61c1ce2f6c2e1e4aeac3f2af97c3198de diff --git a/vcl/inc/vcl/outdev.hxx b/vcl/inc/vcl/outdev.hxx index 1fb5f25..a4c3981 100644 --- a/vcl/inc/vcl/outdev.hxx +++ b/vcl/inc/vcl/outdev.hxx @@ -361,7 +361,7 @@ private: public: SAL_DLLPRIVATE sal_Int32 ImplGetDPIX() const { return mnDPIX; } SAL_DLLPRIVATE sal_Int32 ImplGetDPIY() const { return mnDPIY; } - SAL_DLLPRIVATE int ImplGetGraphics() const; + SAL_DLLPRIVATE SalGraphics* ImplGetGraphics() const; SAL_DLLPRIVATE void ImplReleaseGraphics( sal_Bool bRelease = sal_True ); SAL_DLLPRIVATE sal_Bool ImplHasMirroredGraphics(); SAL_DLLPRIVATE void ImplReMirror( Point &rPoint ) const; diff --git a/vcl/source/gdi/outdev.cxx b/vcl/source/gdi/outdev.cxx index 231c238..cb014ec 100644 --- a/vcl/source/gdi/outdev.cxx +++ b/vcl/source/gdi/outdev.cxx @@ -564,12 +564,12 @@ void OutputDevice::ImplReMirror( Region &rRegion ) const // ----------------------------------------------------------------------- -int OutputDevice::ImplGetGraphics() const +SalGraphics* OutputDevice::ImplGetGraphics() const { DBG_TESTSOLARMUTEX(); if ( mpGraphics ) - return sal_True; + return mpGraphics; mbInitLineColor = sal_True; mbInitFillColor = sal_True; @@ -709,10 +709,9 @@ int OutputDevice::ImplGetGraphics() const { mpGraphics->SetXORMode( (ROP_INVERT == meRasterOp) || (ROP_XOR == meRasterOp), ROP_INVERT == meRasterOp ); mpGraphics->setAntiAliasB2DDraw(mnAntialiasing & ANTIALIASING_ENABLE_B2DDRAW); - return sal_True; } - return sal_False; + return mpGraphics; } // -----------------------------------------------------------------------
_______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
