summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2013-03-07 18:37:30 +0100
committerLuboš Luňák <l.lunak@suse.cz>2013-03-08 13:35:26 +0100
commit5c1c0a4eef933816685364feef93dfb090ff391d (patch)
treed7e25370a5f3fc9fbc7d543be34eb51b73eb84dd /vcl
parent4596120336b575d94d305c4139054afd95d2f740 (diff)
function for duplicated code
Change-Id: If9d6a163abb5a1cbd64838ca005b14dcd51c4588
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/vcl/embeddedfontshelper.hxx15
-rw-r--r--vcl/source/gdi/embeddedfontshelper.cxx41
2 files changed, 56 insertions, 0 deletions
diff --git a/vcl/inc/vcl/embeddedfontshelper.hxx b/vcl/inc/vcl/embeddedfontshelper.hxx
index ac4778620361..e5aead64c7bd 100644
--- a/vcl/inc/vcl/embeddedfontshelper.hxx
+++ b/vcl/inc/vcl/embeddedfontshelper.hxx
@@ -12,8 +12,11 @@
#include <vcl/dllapi.h>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/uno/Reference.hxx>
#include <rtl/ustring.hxx>
#include <tools/fontenum.hxx>
+#include <vector>
/**
Helper functions for handling embedded fonts in documents.
@@ -27,6 +30,18 @@ public:
*/
static OUString fontFileUrl( const OUString& familyName, FontFamily family, FontItalic italic,
FontWeight weight, FontPitch pitch, rtl_TextEncoding encoding );
+
+ /**
+ Reads a font from the input stream, saves it to a temporary font file and activates the font.
+ @param stream stream of font data
+ @param fontName name of the font (e.g. 'Times New Roman')
+ @param extra additional text to use for name (e.g. to distinguish regular from bold, italic,...), "?" for unique
+ @param key key to xor the data with, from the start until the key's length (not repeated)
+ */
+ static bool addEmbeddedFont( com::sun::star::uno::Reference< com::sun::star::io::XInputStream > stream,
+ const OUString& fontName, const char* extra,
+ std::vector< unsigned char > key = std::vector< unsigned char >());
+
/**
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.
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}";