diff options
author | Brennan Vincent <brennanv@email.arizona.edu> | 2013-10-05 16:50:24 -0700 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-11-13 14:37:53 +0000 |
commit | 5ce50b8d171c9d86d2175dd35b1e7ef23255e895 (patch) | |
tree | de6bd12da7446ec1efe1f377f5f0e031cc59e83d /vcl | |
parent | 4f1e4c05a9b67fbc67ea4279793a61af46444dad (diff) |
Respect svg:font-face-format element.
Call libeot to parse font if value "embedded-opentype" is found.
Change-Id: I03a072fd4db47d151a3934e959ad17c1e24fcf09
Reviewed-on: https://gerrit.libreoffice.org/6144
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/Library_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/source/gdi/embeddedfontshelper.cxx | 63 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 6 |
3 files changed, 64 insertions, 6 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index fd245893b6b9..38cf55acd605 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -58,6 +58,7 @@ $(eval $(call gb_Library_use_custom_headers,vcl,\ $(eval $(call gb_Library_use_externals,vcl,\ jpeg \ nss3 \ + libeot \ )) $(eval $(call gb_Library_use_libraries,vcl,\ diff --git a/vcl/source/gdi/embeddedfontshelper.cxx b/vcl/source/gdi/embeddedfontshelper.cxx index 3460f7835f88..c3101df0641b 100644 --- a/vcl/source/gdi/embeddedfontshelper.cxx +++ b/vcl/source/gdi/embeddedfontshelper.cxx @@ -18,16 +18,29 @@ #include <vcl/svapp.hxx> #include <boost/scoped_ptr.hpp> +#include <boost/shared_ptr.hpp> #include <fontsubset.hxx> #include <outdev.h> #include <outfont.hxx> #include <salgdi.hxx> +#include <config_eot.h> + +#if ENABLE_EOT +extern "C" +{ +namespace libeot +{ +#include <libeot.h> +} // namespace libeot +} // extern "C" +#endif + using namespace com::sun::star; using namespace vcl; static void clearDir( const OUString& path ) - { +{ osl::Directory dir( path ); if( dir.reset() == osl::Directory::E_None ) { @@ -53,7 +66,7 @@ void EmbeddedFontsHelper::clearTemporaryFontFiles() } bool EmbeddedFontsHelper::addEmbeddedFont( uno::Reference< io::XInputStream > stream, const OUString& fontName, - const char* extra, std::vector< unsigned char > key ) + const char* extra, std::vector< unsigned char > key, bool eot ) { OUString fileUrl = EmbeddedFontsHelper::fileUrlForTemporaryFont( fontName, extra ); osl::File file( fileUrl ); @@ -78,7 +91,8 @@ bool EmbeddedFontsHelper::addEmbeddedFont( uno::Reference< io::XInputStream > st pos < read && keyPos < key.size(); ++pos ) buffer[ pos ] ^= key[ keyPos++ ]; - if( read > 0 ) + // if eot, don't write the file out yet, since we need to unpack it first. + if( !eot && read > 0 ) { sal_uInt64 writtenTotal = 0; while( writtenTotal < read ) @@ -92,13 +106,50 @@ bool EmbeddedFontsHelper::addEmbeddedFont( uno::Reference< io::XInputStream > st if( read <= 0 ) break; } + bool sufficientFontRights; +#if ENABLE_EOT + if( eot ) + { + unsigned uncompressedFontSize = 0; + unsigned char *nakedPointerToUncompressedFont = NULL; + libeot::EOTMetadata eotMetadata; + libeot::EOTError uncompressError = + libeot::eot2ttf_buffer( (const unsigned char *)&fontData[0], fontData.size(), &eotMetadata, &nakedPointerToUncompressedFont, &uncompressedFontSize ): + boost::shared_ptr<unsigned char> uncompressedFont( nakedPointerToUncompressedFont, libeot::freeEOTBuffer ); + if( uncompressError != libeot::EOT_SUCCESS ) + { + SAL_WARN( "vcl.fonts", "Failed to uncompress font" ); + osl::File::remove( fileUrl ); + return false; + } + sal_uInt64 writtenTotal = 0; + while( writtenTotal < uncompressedFontSize ) + { + sal_uInt64 written; + if( file.write( uncompressedFont.get() + writtenTotal, uncompressedFontSize - writtenTotal, written ) != osl::File::E_None ) + { + SAL_WARN( "vcl.fonts", "Error writing temporary font file" ); + osl::File::remove( fileUrl ); + return false; + } + writtenTotal += written; + } + sufficientFontRights = libeot::canLegallyEdit( eotMetadata ); + libeot::EOTfreeMetadata( &eotMetadata ); + } +#endif + if( file.close() != osl::File::E_None ) { SAL_WARN( "vcl.fonts", "Writing temporary font file failed" ); osl::File::remove( fileUrl ); return false; } - if( !sufficientFontRights( &fontData.front(), fontData.size(), EditingAllowed )) + if( !eot ) + { + sufficientFontRights = sufficientTTFRights( &fontData.front(), fontData.size(), EditingAllowed ); + } + if( sufficientFontRights ) { // 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 @@ -139,7 +190,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. -bool EmbeddedFontsHelper::sufficientFontRights( const void* data, long size, FontRights rights ) +bool EmbeddedFontsHelper::sufficientTTFRights( const void* data, long size, FontRights rights ) { TrueTypeFont* font; if( OpenTTFontBuffer( data, size, 0 /*TODO*/, &font ) == SF_OK ) @@ -225,7 +276,7 @@ OUString EmbeddedFontsHelper::fontFileUrl( const OUString& familyName, FontFamil long size; if( const void* data = graphics->GetEmbedFontData( selected, unicodes, widths, info, &size )) { - if( sufficientFontRights( data, size, rights )) + if( sufficientTTFRights( 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/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index f6e823a26f0f..b6001cb38fba 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -85,6 +85,12 @@ #include "cmst.h" #endif +#include <config_eot.h> + +#if ENABLE_EOT +#include "libeot.h" +#endif + using namespace vcl; #if (OSL_DEBUG_LEVEL < 3) |