diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2013-03-07 18:37:30 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2013-03-08 13:35:26 +0100 |
commit | 5c1c0a4eef933816685364feef93dfb090ff391d (patch) | |
tree | d7e25370a5f3fc9fbc7d543be34eb51b73eb84dd /vcl/source/gdi/embeddedfontshelper.cxx | |
parent | 4596120336b575d94d305c4139054afd95d2f740 (diff) |
function for duplicated code
Change-Id: If9d6a163abb5a1cbd64838ca005b14dcd51c4588
Diffstat (limited to 'vcl/source/gdi/embeddedfontshelper.cxx')
-rw-r--r-- | vcl/source/gdi/embeddedfontshelper.cxx | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/vcl/source/gdi/embeddedfontshelper.cxx b/vcl/source/gdi/embeddedfontshelper.cxx index e53ed1847133..5df758da0f04 100644 --- a/vcl/source/gdi/embeddedfontshelper.cxx +++ b/vcl/source/gdi/embeddedfontshelper.cxx @@ -21,6 +21,7 @@ #include <outfont.hxx> #include <salgdi.hxx> +using namespace com::sun::star; using namespace vcl; static void clearDir( const OUString& path ) @@ -49,6 +50,46 @@ void EmbeddedFontsHelper::clearTemporaryFontFiles() clearDir( path + "fromsystem/" ); } +bool EmbeddedFontsHelper::addEmbeddedFont( uno::Reference< io::XInputStream > stream, const OUString& fontName, + const char* extra, std::vector< unsigned char > key ) +{ + OUString fileUrl = EmbeddedFontsHelper::fileUrlForTemporaryFont( fontName, extra ); + osl::File file( fileUrl ); + switch( file.open( osl_File_OpenFlag_Create | osl_File_OpenFlag_Write )) + { + case osl::File::E_None: + break; // ok + case osl::File::E_EXIST: + return true; // Assume it's already been added correctly. + default: + SAL_WARN( "vcl.fonts", "Cannot open file for temporary font" ); + return false; + } + size_t keyPos = 0; + for(;;) + { + uno::Sequence< sal_Int8 > buffer; + int read = stream->readBytes( buffer, 1024 ); + for( int pos = 0; + pos < read && keyPos < key.size(); + ++pos ) + buffer[ pos ] ^= key[ keyPos++ ]; + sal_uInt64 dummy; + if( read > 0 ) + file.write( buffer.getConstArray(), read, dummy ); + if( read < 1024 ) + break; + } + if( file.close() != osl::File::E_None ) + { + SAL_WARN( "vcl.fonts", "Writing temporary font file failed" ); + osl::File::remove( fileUrl ); + return false; + } + EmbeddedFontsHelper::activateFont( fontName, fileUrl ); + return true; +} + OUString EmbeddedFontsHelper::fileUrlForTemporaryFont( const OUString& fontName, const char* extra ) { OUString path = "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}"; |