diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2013-03-05 18:37:14 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2013-03-06 12:00:11 +0100 |
commit | 595f954424a5b99f0a9d396b77d2d5b89b5ae664 (patch) | |
tree | 36c4ecc844448f9da7987cb6f1fec8eeafce53fc /vcl/source/gdi | |
parent | 25a5ee2aebebe9e175ad3b1c770bba9826fe4d48 (diff) |
check whether font files allow being embedded in documents
Change-Id: I95842a35a7c795cb0a3c1957f4062a373a9c4797
Diffstat (limited to 'vcl/source/gdi')
-rw-r--r-- | vcl/source/gdi/embeddedfontshelper.cxx | 74 |
1 files changed, 52 insertions, 22 deletions
diff --git a/vcl/source/gdi/embeddedfontshelper.cxx b/vcl/source/gdi/embeddedfontshelper.cxx index dfde14a84671..ac18655a837d 100644 --- a/vcl/source/gdi/embeddedfontshelper.cxx +++ b/vcl/source/gdi/embeddedfontshelper.cxx @@ -11,6 +11,7 @@ #include <osl/file.hxx> #include <rtl/bootstrap.hxx> +#include <sft.hxx> #include <vcl/outdev.hxx> #include <vcl/svapp.hxx> @@ -20,6 +21,8 @@ #include <outfont.hxx> #include <salgdi.hxx> +using namespace vcl; + static void clearDir( const OUString& path ) { osl::Directory dir( path ); @@ -65,6 +68,30 @@ void EmbeddedFontsHelper::activateFont( const OUString& fontName, const OUString pDevice->ImplUpdateAllFontData( true ); } +// Check if it's (legally) allowed to embed the font file into a document +// (ttf has a flag allowing this). PhysicalFontFace::IsEmbeddable() appears +// to have a different meaning (guessing from code, IsSubsettable() might +// possibly mean it's ttf, while IsEmbeddable() might mean it's type1). +// So just try to open the data as ttf and see. +static bool isEmbeddingAllowed( const void* data, long size ) +{ + TrueTypeFont* font; + if( OpenTTFontBuffer( data, size, 0 /*TODO*/, &font ) == SF_OK ) + { + TTGlobalFontInfo info; + GetTTGlobalFontInfo( font, &info ); + CloseTTFont( font ); + // http://www.microsoft.com/typography/tt/ttf_spec/ttch02.doc + // font embedding is allowed if either + // no restriction at all (bit 1 clear) + // editting allowed (bit 1 set, bit 3 set) + // (preview&print is considered insufficent, as it would force the document to be read-only) + int copyright = info.typeFlags & TYPEFLAG_COPYRIGHT_MASK; + return ( copyright & 0x02 ) == 0 || ( copyright & 0x08 ); + } + return true; // no known restriction +} + OUString EmbeddedFontsHelper::fontFileUrl( const OUString& familyName, FontFamily family, FontItalic italic, FontWeight weight, FontPitch pitch, rtl_TextEncoding ) { @@ -128,33 +155,36 @@ OUString EmbeddedFontsHelper::fontFileUrl( const OUString& familyName, FontFamil 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 ) + if( isEmbeddingAllowed( data, size )) { - sal_uInt64 written = 0; - sal_uInt64 totalSize = size; - bool error = false; - while( written < totalSize && !error) + osl::File file( url ); + if( file.open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create ) == osl::File::E_None ) { - sal_uInt64 nowWritten; - switch( file.write( static_cast< const char* >( data ) + written, size - written, nowWritten )) + sal_uInt64 written = 0; + sal_uInt64 totalSize = size; + bool error = false; + while( written < totalSize && !error) { - case osl::File::E_None: - written += nowWritten; - break; - case osl::File::E_AGAIN: - case osl::File::E_INTR: - break; - default: - error = true; - break; + 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; } - file.close(); - if( error ) - osl::File::remove( url ); - else - ok = true; } graphics->FreeEmbedFontData( data, size ); } |