sal/inc/sal/log-areas.dox | 1 sw/source/filter/ww8/docxattributeoutput.cxx | 5 + vcl/generic/fontmanager/fontmanager.cxx | 10 +-- vcl/generic/print/text_gfx.cxx | 4 - vcl/inc/vcl/embeddedfontshelper.hxx | 33 ++++++++++- vcl/inc/vcl/fontmanager.hxx | 4 - vcl/source/gdi/embeddedfontshelper.cxx | 80 ++++++++++++++++++++++++--- writerfilter/source/dmapper/FontTable.cxx | 55 +----------------- xmloff/source/style/XMLFontAutoStylePool.cxx | 5 + xmloff/source/style/XMLFontStylesContext.cxx | 30 ---------- 10 files changed, 128 insertions(+), 99 deletions(-)
New commits: commit e99d502df6561949fe34af42c7910d24455d3ba6 Author: LuboÅ¡ LuÅák <[email protected]> Date: Thu Mar 7 20:08:22 2013 +0100 fix handling of ttf embedding restrictions Font is usable for viewing if not restricted from embedding completely (since otherwise either viewing is allowed or a less restrictive setting is present). Font is usable for editing if it's installable or editable. Change-Id: I57604a54390b935bae3699dda581d1093fc245e3 diff --git a/vcl/source/gdi/embeddedfontshelper.cxx b/vcl/source/gdi/embeddedfontshelper.cxx index eedab37..a147ea3 100644 --- a/vcl/source/gdi/embeddedfontshelper.cxx +++ b/vcl/source/gdi/embeddedfontshelper.cxx @@ -146,17 +146,15 @@ bool EmbeddedFontsHelper::sufficientFontRights( const void* data, long size, Fon 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) - // viewing allowed (bit 1 set, bit 2 set) - // editting allowed (bit 1 set, bit 3 set) int copyright = info.typeFlags & TYPEFLAG_COPYRIGHT_MASK; switch( rights ) { case ViewingAllowed: - return ( copyright & 0x02 ) == 0 || ( copyright & 0x04 ) || ( copyright & 0x08 ); + // Embedding not restricted completely. + return ( copyright & 0x02 ) != 0x02; case EditingAllowed: - return ( copyright & 0x02 ) == 0 || ( copyright & 0x08 ); + // Font is installable or editable. + return copyright == 0 || ( copyright & 0x08 ); } } return true; // no known restriction commit 8da3cfcde0631a74d0446ce751c32ce8c895dc8b Author: LuboÅ¡ LuÅák <[email protected]> Date: Thu Mar 7 20:07:15 2013 +0100 editable ttf fonts are usable for print&preview too Since it's a less restrictive setting (fonts should usually have both bits set though). Change-Id: I83f740762698bd0a0f8fdee388a6e710cfd9d00a diff --git a/vcl/generic/fontmanager/fontmanager.cxx b/vcl/generic/fontmanager/fontmanager.cxx index cd5e437..59c21c3 100644 --- a/vcl/generic/fontmanager/fontmanager.cxx +++ b/vcl/generic/fontmanager/fontmanager.cxx @@ -2431,7 +2431,7 @@ const ::std::list< KernPair >& PrintFontManager::getKernPairs( fontID nFontID, b // ------------------------------------------------------------------------- -bool PrintFontManager::isFontDownloadingAllowed( fontID nFont ) const +bool PrintFontManager::isFontDownloadingAllowedForPrinting( fontID nFont ) const { static const char* pEnable = getenv( "PSPRINT_ENABLE_TTF_COPYRIGHTAWARENESS" ); bool bRet = true; @@ -2458,10 +2458,10 @@ bool PrintFontManager::isFontDownloadingAllowed( fontID nFont ) const unsigned int nCopyrightFlags = pTTFontFile->m_nTypeFlags & TYPEFLAG_COPYRIGHT_MASK; - // font embedding is allowed if either - // no restriction at all (bit 1 clear) - // printing allowed (bit 1 set, bit 2 set ) - bRet = ! ( nCopyrightFlags & 0x02 ) || ( nCopyrightFlags & 0x04 ); + // http://www.microsoft.com/typography/tt/ttf_spec/ttch02.doc + // Font embedding is allowed if not restricted completely (only bit 1 set). + // Preview&Print (bit 2), Editable (bit 3) or Installable (==0) fonts are ok. + bRet = ( nCopyrightFlags & 0x02 ) != 0x02; } } return bRet; diff --git a/vcl/generic/print/text_gfx.cxx b/vcl/generic/print/text_gfx.cxx index 48fd08e..633b742 100644 --- a/vcl/generic/print/text_gfx.cxx +++ b/vcl/generic/print/text_gfx.cxx @@ -169,7 +169,7 @@ void PrinterGfx::DrawGlyphs( if( nLen <= 0 ) return; - if ( !mrFontMgr.isFontDownloadingAllowed( mnFontID ) ) + if ( !mrFontMgr.isFontDownloadingAllowedForPrinting( mnFontID ) ) { LicenseWarning(rPoint, pUnicodes, nLen, pDeltaArray); return; @@ -569,7 +569,7 @@ PrinterGfx::drawText( PSUploadPS1Font (mnFontID); if ( eType == fonttype::TrueType - && !mrFontMgr.isFontDownloadingAllowed(mnFontID)) + && !mrFontMgr.isFontDownloadingAllowedForPrinting(mnFontID)) { LicenseWarning(rPoint, pStr, nLen, pDeltaArray); return; diff --git a/vcl/inc/vcl/fontmanager.hxx b/vcl/inc/vcl/fontmanager.hxx index 94f905d..7490f01 100644 --- a/vcl/inc/vcl/fontmanager.hxx +++ b/vcl/inc/vcl/fontmanager.hxx @@ -479,10 +479,10 @@ public: // getKernPairs method of PrinterGfx const std::list< KernPair >& getKernPairs( fontID nFontID, bool bVertical = false ) const; - // evaluates copyright flags for TrueType fonts + // evaluates copyright flags for TrueType fonts for printing/viewing // type1 fonts do not have such a feature, so return for them is true // returns true for builtin fonts (surprise!) - bool isFontDownloadingAllowed( fontID nFont ) const; + bool isFontDownloadingAllowedForPrinting( fontID nFont ) const; // helper for type 1 fonts std::list< rtl::OString > getAdobeNameFromUnicode( sal_Unicode aChar ) const; commit e2cd75f005dd5bf57336f39abd8820ecac0b048e Author: LuboÅ¡ LuÅák <[email protected]> Date: Thu Mar 7 19:45:49 2013 +0100 embed also view-only fonts, but do not use them MSO embeds even fonts which allow only embedding for viewing the document but not editing it. So embed such fonts too, but do not actually use them from the document. What MSO does when such a font is not present locally when opening the document is switching to read-only mode, warning about this and providing a button for switching to editing mode by dumping the font(s). That should be done for LO too, but right now dropping view-only fonts is better than using them for editing. Change-Id: I19c28fadb091e6b21beaf4cbf8b47e3078256d1c diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index e5366ee..1b8da73 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -3073,7 +3073,10 @@ static inline char toHexChar( int value ) void DocxAttributeOutput::EmbedFontStyle( const OUString& name, int tag, FontFamily family, FontItalic italic, FontWeight weight, FontPitch pitch, rtl_TextEncoding encoding ) { - OUString fontUrl = EmbeddedFontsHelper::fontFileUrl( name, family, italic, weight, pitch, encoding ); + // Embed font if at least viewing is allowed (in which case the opening app must check + // the font license rights too and open either read-only or not use the font for editing). + OUString fontUrl = EmbeddedFontsHelper::fontFileUrl( name, family, italic, weight, pitch, encoding, + EmbeddedFontsHelper::ViewingAllowed ); if( fontUrl.isEmpty()) return; // TODO IDocumentSettingAccess::EMBED_SYSTEM_FONTS diff --git a/vcl/inc/vcl/embeddedfontshelper.hxx b/vcl/inc/vcl/embeddedfontshelper.hxx index e5aead6..0b66e8a 100644 --- a/vcl/inc/vcl/embeddedfontshelper.hxx +++ b/vcl/inc/vcl/embeddedfontshelper.hxx @@ -25,11 +25,18 @@ class VCL_DLLPUBLIC EmbeddedFontsHelper { public: + /// Specification of what kind of operation is allowed when embedding a font + enum FontRights + { + ViewingAllowed, ///< Font may be embedded for viewing the document (but not editing) + EditingAllowed ///< Font may be embedded for editing document (implies viewing) + }; + /** 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 ); + FontWeight weight, FontPitch pitch, rtl_TextEncoding encoding, FontRights rights ); /** Reads a font from the input stream, saves it to a temporary font file and activates the font. @@ -62,6 +69,15 @@ public: static void activateFont( const OUString& fontName, const OUString& fileUrl ); /** + Returns if the restrictions specified in the font (if present) allow embedding + the font for a particular purpose. + @param data font data + @param size size of the font data + @param rights type of operation to be allowed for the font + */ + static bool sufficientFontRights( const void* data, long size, FontRights rights ); + + /** Removes all temporary fonts in the path used by fileUrlForTemporaryFont(). @internal */ diff --git a/vcl/source/gdi/embeddedfontshelper.cxx b/vcl/source/gdi/embeddedfontshelper.cxx index 691e434..eedab37 100644 --- a/vcl/source/gdi/embeddedfontshelper.cxx +++ b/vcl/source/gdi/embeddedfontshelper.cxx @@ -66,6 +66,8 @@ bool EmbeddedFontsHelper::addEmbeddedFont( uno::Reference< io::XInputStream > st return false; } size_t keyPos = 0; + std::vector< char > fontData; + fontData.reserve( 1000000 ); for(;;) { uno::Sequence< sal_Int8 > buffer; @@ -84,6 +86,7 @@ bool EmbeddedFontsHelper::addEmbeddedFont( uno::Reference< io::XInputStream > st writtenTotal += written; } } + fontData.insert( fontData.end(), buffer.getConstArray(), buffer.getConstArray() + read ); if( read <= 0 ) break; } @@ -93,6 +96,15 @@ bool EmbeddedFontsHelper::addEmbeddedFont( uno::Reference< io::XInputStream > st osl::File::remove( fileUrl ); return false; } + if( !sufficientFontRights( &fontData.front(), fontData.size(), EditingAllowed )) + { + // It would be actually better to open the document in read-only mode in this case, + // warn the user about this, and provide a button to drop the font(s) in order + // to switch to editing. + SAL_INFO( "vcl.fonts", "Ignoring embedded font that is not usable for editing" ); + osl::File::remove( fileUrl ); + return false; + } EmbeddedFontsHelper::activateFont( fontName, fileUrl ); return true; } @@ -125,7 +137,7 @@ void EmbeddedFontsHelper::activateFont( const OUString& fontName, const OUString // 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 ) +bool EmbeddedFontsHelper::sufficientFontRights( const void* data, long size, FontRights rights ) { TrueTypeFont* font; if( OpenTTFontBuffer( data, size, 0 /*TODO*/, &font ) == SF_OK ) @@ -136,16 +148,22 @@ static bool isEmbeddingAllowed( const void* data, long size ) // http://www.microsoft.com/typography/tt/ttf_spec/ttch02.doc // font embedding is allowed if either // no restriction at all (bit 1 clear) + // viewing allowed (bit 1 set, bit 2 set) // 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 ); + switch( rights ) + { + case ViewingAllowed: + return ( copyright & 0x02 ) == 0 || ( copyright & 0x04 ) || ( copyright & 0x08 ); + case EditingAllowed: + 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 ) + FontWeight weight, FontPitch pitch, rtl_TextEncoding, FontRights rights ) { OUString path = "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}"; rtl::Bootstrap::expandMacros( path ); @@ -207,7 +225,7 @@ OUString EmbeddedFontsHelper::fontFileUrl( const OUString& familyName, FontFamil long size; if( const void* data = graphics->GetEmbedFontData( selected, unicodes, widths, info, &size )) { - if( isEmbeddingAllowed( data, size )) + if( sufficientFontRights( data, size, rights )) { osl::File file( url ); if( file.open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create ) == osl::File::E_None ) diff --git a/xmloff/source/style/XMLFontAutoStylePool.cxx b/xmloff/source/style/XMLFontAutoStylePool.cxx index 561814d..8f603ab 100644 --- a/xmloff/source/style/XMLFontAutoStylePool.cxx +++ b/xmloff/source/style/XMLFontAutoStylePool.cxx @@ -282,8 +282,11 @@ void XMLFontAutoStylePool::exportXML() j < SAL_N_ELEMENTS( weight ); ++j ) { + // Embed font if at least viewing is allowed (in which case the opening app must check + // the font license rights too and open either read-only or not use the font for editing). OUString fileUrl = EmbeddedFontsHelper::fontFileUrl( pEntry->GetFamilyName(), pEntry->GetFamily(), - italic[ j ], weight[ j ], pEntry->GetPitch(), pEntry->GetEncoding()); + italic[ j ], weight[ j ], pEntry->GetPitch(), pEntry->GetEncoding(), + EmbeddedFontsHelper::ViewingAllowed ); if( fileUrl.isEmpty()) continue; if( !fontFilesMap.count( fileUrl )) commit 8fcc60bee755b812489ef652ab2fa779babddeac Author: LuboÅ¡ LuÅák <[email protected]> Date: Thu Mar 7 18:42:47 2013 +0100 protect against incomplete writes What good is an abstraction if one still has to fiddle with annoying implementation details? Change-Id: I80816bdad8c0560263306584ad001a41fc054cd2 diff --git a/vcl/source/gdi/embeddedfontshelper.cxx b/vcl/source/gdi/embeddedfontshelper.cxx index 5df758d..691e434 100644 --- a/vcl/source/gdi/embeddedfontshelper.cxx +++ b/vcl/source/gdi/embeddedfontshelper.cxx @@ -69,15 +69,22 @@ bool EmbeddedFontsHelper::addEmbeddedFont( uno::Reference< io::XInputStream > st for(;;) { uno::Sequence< sal_Int8 > buffer; - int read = stream->readBytes( buffer, 1024 ); - for( int pos = 0; + sal_uInt64 read = stream->readBytes( buffer, 1024 ); + for( sal_uInt64 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 ) + { + sal_uInt64 writtenTotal = 0; + while( writtenTotal < read ) + { + sal_uInt64 written; + file.write( buffer.getConstArray(), read, written ); + writtenTotal += written; + } + } + if( read <= 0 ) break; } if( file.close() != osl::File::E_None ) commit 5c1c0a4eef933816685364feef93dfb090ff391d Author: LuboÅ¡ LuÅák <[email protected]> Date: Thu Mar 7 18:37:30 2013 +0100 function for duplicated code Change-Id: If9d6a163abb5a1cbd64838ca005b14dcd51c4588 diff --git a/sal/inc/sal/log-areas.dox b/sal/inc/sal/log-areas.dox index 0df74eb..eca0a75 100644 --- a/sal/inc/sal/log-areas.dox +++ b/sal/inc/sal/log-areas.dox @@ -236,6 +236,7 @@ certain functionality. @li @c vcl.atsui - ATSUI (obsolete) -using code for Mac OS X @li @c vcl.control @li @c vcl.coretext - CoreText-using code for Mac OS X and iOS +@li @c vcl.fonts - font-specific code @li @c vcl.gdi - the GDI part of VCL, devices, bitmaps, etc. @li @c vcl.gtk - Gtk+ 2/3 plugin @li @c vcl.layout - Widget layout diff --git a/vcl/inc/vcl/embeddedfontshelper.hxx b/vcl/inc/vcl/embeddedfontshelper.hxx index ac47786..e5aead6 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 e53ed18..5df758d 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}"; diff --git a/writerfilter/source/dmapper/FontTable.cxx b/writerfilter/source/dmapper/FontTable.cxx index cb737f1..47fdc01 100644 --- a/writerfilter/source/dmapper/FontTable.cxx +++ b/writerfilter/source/dmapper/FontTable.cxx @@ -251,35 +251,12 @@ EmbeddedFontHandler::~EmbeddedFontHandler() { if( !inputStream.is()) return; - OUString fileUrl = EmbeddedFontsHelper::fileUrlForTemporaryFont( fontName, style ); - 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; // Assume it's already been added correctly. - default: - SAL_WARN( "writerfilter", "Cannot open file for temporary font" ); - inputStream->closeInput(); - return; - } + std::vector< unsigned char > key( 32 ); if( !fontKey.isEmpty()) - { // unobfuscate - uno::Sequence< sal_Int8 > buffer; - int read = inputStream->readBytes( buffer, 32 ); - if( read < 32 ) - { - SAL_WARN( "writerfilter", "Embedded font too small" ); - inputStream->closeInput(); - file.close(); - osl::File::remove( fileUrl ); - return; - } + { // key for unobfuscating // 1 3 5 7 10 2 5 7 20 2 5 7 9 1 3 5 // {62E79491-959F-41E9-B76B-6B32631DEA5C} static const int pos[ 16 ] = { 35, 33, 31, 29, 27, 25, 22, 20, 17, 15, 12, 10, 7, 5, 3, 1 }; - char key[ 16 ]; for( int i = 0; i < 16; ++i ) @@ -290,35 +267,11 @@ EmbeddedFontHandler::~EmbeddedFontHandler() assert(( v2 >= '0' && v2 <= '9' ) || ( v2 >= 'A' && v2 <= 'F' )); int val = ( v1 - ( v1 <= '9' ? '0' : 'A' - 10 )) * 16 + v2 - ( v2 <= '9' ? '0' : 'A' - 10 ); key[ i ] = val; + key[ i + 16 ] = val; } - for( int i = 0; - i < 16; - ++i ) - { - buffer[ i ] ^= key[ i ]; - buffer[ i + 16 ] ^= key[ i ]; - } - sal_uInt64 dummy; - file.write( buffer.getConstArray(), 32, dummy ); - } - for(;;) - { - uno::Sequence< sal_Int8 > buffer; - int read = inputStream->readBytes( buffer, 1024 ); - sal_uInt64 dummy; - if( read > 0 ) - file.write( buffer.getConstArray(), read, dummy ); - if( read < 1024 ) - break; } + EmbeddedFontsHelper::addEmbeddedFont( inputStream, fontName, style, key ); inputStream->closeInput(); - if( file.close() != osl::File::E_None ) - { - SAL_WARN( "writerfilter", "Writing temporary font file failed" ); - osl::File::remove( fileUrl ); - return; - } - EmbeddedFontsHelper::activateFont( fontName, fileUrl ); } void EmbeddedFontHandler::lcl_attribute( Id name, Value& val ) diff --git a/xmloff/source/style/XMLFontStylesContext.cxx b/xmloff/source/style/XMLFontStylesContext.cxx index 21b9cdb..37de311 100644 --- a/xmloff/source/style/XMLFontStylesContext.cxx +++ b/xmloff/source/style/XMLFontStylesContext.cxx @@ -252,38 +252,12 @@ void XMLFontStyleContextFontFaceUri::handleEmbeddedFont( const OUString& url ) if( url.indexOf( '/' ) > -1 ) // TODO what if more levels? storage.set( storage->openStorageElement( url.copy( 0, url.indexOf( '/' )), ::embed::ElementModes::READ ), uno::UNO_QUERY_THROW ); - OUString fileUrl = EmbeddedFontsHelper::fileUrlForTemporaryFont( fontName, "?" ); - osl::File file( fileUrl ); - switch( file.open( osl_File_OpenFlag_Create | osl_File_OpenFlag_Write )) - { - case osl::File::E_None: - break; // ok - default: - SAL_WARN( "xmloff", "Cannot open file for temporary font" ); - return; - } uno::Reference< io::XInputStream > inputStream; inputStream.set( storage->openStreamElement( url.copy( url.indexOf( '/' ) + 1 ), ::embed::ElementModes::READ ), UNO_QUERY_THROW ); - for(;;) - { - uno::Sequence< sal_Int8 > buffer; - int read = inputStream->readBytes( buffer, 1024 ); - sal_uInt64 dummy; - if( read > 0 ) - file.write( buffer.getConstArray(), read, dummy ); - if( read < 1024 ) - break; - } + if( EmbeddedFontsHelper::addEmbeddedFont( inputStream, fontName, "?" )) + GetImport().NotifyEmbeddedFontRead(); inputStream->closeInput(); - if( file.close() != osl::File::E_None ) - { - SAL_WARN( "xmloff", "Writing temporary font file failed" ); - osl::File::remove( fileUrl ); - return; - } - EmbeddedFontsHelper::activateFont( fontName, fileUrl ); - GetImport().NotifyEmbeddedFontRead(); } else SAL_WARN( "xmloff", "External URL for font file not handled." );
_______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
