On Tuesday 27 of August 2013, Brennan T Vincent wrote:
Hi all,
One of the most commonly-occurring problems with .pub import is the fact
that we don't respect embedded fonts. Now that LibreOffice supports
embedded fonts, it should be possible to make this work.
That depends. EOT is a Microsoft proprietary font format (which has been
submitted to W3C, but AFAICT pretty much everybody else ignores it). There
are tools to convert e.g. TTF fonts to EOT, but I couldn't find absolutely
anything that'd convert from EOT and the only thing capable of at least
reading it is MS Windows itself. As far as I understand it, the available
documentation on it is unsufficient for implementing a reader if you'd decide
it'd be worth the effort (I'm not entirely sure on this part, feel free to do
your own research).
Here are some links that I found on the topic:
http://blog.yezhucn.com/gdi/t2embed_TTLoadEmbeddedFont.htm
http://www.pptfaq.com/FAQ00076_Embedding_fonts.htm
http://graphicdesign.stackexchange.com/questions/16234/are-there-any-free-tools-to-convert-eot-files-to-ttf-otf-or-any-other-font-f
http://www.w3.org/Submission/2008/SUBM-EOT-20080305/
http://www.w3.org/Submission/2008/SUBM-MTX-20080305/
http://lists.w3.org/Archives/Public/www-style/2008Apr/0227.html
http://securitylabs.websense.com/content/Blogs/3114.aspx
A few questions:
(1) Do we support Embedded OpenType fonts currently? (.eot)
No.
(2) If not (which I suspect), I can contribute some code to do this.
Microsoft and Monotype recently granted a perpetual, irrevocable free
patent and copyright license to implement the .eot format, so there should
be no legal issues. I have written a C library to convert from .eot to .ttf
and would like to know who to talk to in order to get this included in
LibreOffice.
Yes, adding support for export should be fairly easy, given that TTF->EOT
conversion is possible, but that's the easier part and it doesn't really help
LO much.
A kind of limited import support should be also doable, as the Windows
TTLoadEmbeddedFont() function can load such a font for use (unlike the normal
Windows function for opening fonts). See the attached hackish proof of
concept patch. That'd make import of it Windows-only, unless you find a way
to use EOT on other platforms. It'd also most probably require some changes
in VCL's font handling, as I couldn't get the activated font listed among
available fonts (which is what otherwise the current reading of embedded
fonts does, it adds the new font temporarily in whichever way the underlying
font system supports and then just uses it normally as if it was a system
font).
There's a class EmbeddedFontsHelper in VCL that I created for handling
embedded fonts, that should be the place to start if you want to give
implementing this a try.
--
Lubos Lunak
l.lunak@suse.cz
diff --git a/oox/Library_oox.mk b/oox/Library_oox.mk
index 8d07153..a4aeb7c 100644
--- a/oox/Library_oox.mk
+++ b/oox/Library_oox.mk
@@ -312,4 +312,10 @@ $(eval $(call gb_Library_add_generated_exception_objects,oox,\
CustomTarget/oox/generated/misc/vmlexport-shape-types \
))
+$(eval $(call gb_Library_use_system_win32_libs,oox,\
+ $(if $(filter $(COM),MSC), \
+ t2embed \
+ ) \
+))
+
# vim: set noet sw=4 ts=4:
diff --git a/oox/source/ppt/pptimport.cxx b/oox/source/ppt/pptimport.cxx
index a7e9922..d468d41 100644
--- a/oox/source/ppt/pptimport.cxx
+++ b/oox/source/ppt/pptimport.cxx
@@ -32,6 +32,13 @@ using namespace oox::core;
using ::com::sun::star::beans::PropertyValue;
using ::com::sun::star::lang::XComponent;
+#include <vcl/embeddedfontshelper.hxx>
+
+#undef WB_LEFT
+#undef WB_RIGHT
+#include <windows.h>
+#include <t2embapi.h>
+
namespace oox { namespace ppt {
OUString SAL_CALL PowerPointImport_getImplementationName() throw()
@@ -70,8 +77,51 @@ PowerPointImport::~PowerPointImport()
{
}
+
+FILE* ff;
+unsigned long readfunc( void*, void* out, unsigned long len )
+{
+ int r = fread( out, 1, len, ff );
+ SAL_DEBUG("RF:" << len << ":" << r );
+ return r;
+}
+
+
+void hack()
+{
+ EmbeddedFontsHelper::activateFont( "Bauhaus 93",
"file://c:/cygwin/home/tinderbox/tmp/font.eof" );
+ return;
+
+
+ ff = fopen( "c:\\cygwin\\home\\tinderbox\\tmp\\font.eot", "rb" );
+ SAL_DEBUG( "F:" << (void*)ff );
+ HANDLE ft;
+ ULONG status1;
+ ULONG status2;
+ LONG ret = TTLoadEmbeddedFont(
+ &ft,
+ 0, //TTLOAD_PRIVATE,
+ &status1,
+ LICENSE_DEFAULT,
+ &status2,
+ readfunc,
+ NULL,
+ NULL,
+ NULL,
+ NULL );
+ SAL_DEBUG( "F2:" << ret << ":" << status1 << ":" << status2 );
+ fclose( ff );
+ wchar_t nm[ LF_FACESIZE + 1 ];
+ char nm2[ LF_FACESIZE + 1 ];
+ ret = TTGetNewFontName( &ft, nm, sizeof( nm ), nm2, sizeof(nm2));
+ SAL_DEBUG("F3:" << ret << ":" << OUString( nm ));
+}
+
+
bool PowerPointImport::importDocument() throw()
{
+ SAL_DEBUG("HACK");
+ hack();
/* to activate the PPTX dumper, define the environment variable
OOO_PPTXDUMPER and insert the full path to the file
file:///<path-to-oox-module>/source/dump/pptxdumper.ini. */
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 17d1ef6..30b90a7 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -691,4 +691,10 @@ endif
$(call gb_LinkTarget_get_target,$(call gb_Library_get_linktargetname,vcl)) :| \
$(call gb_AllLangResTarget_get_target,vcl)
+$(eval $(call gb_Library_use_system_win32_libs,vcl,\
+ $(if $(filter $(COM),MSC), \
+ t2embed \
+ ) \
+))
+
# vim: set noet sw=4 ts=4:
diff --git a/vcl/source/gdi/embeddedfontshelper.cxx b/vcl/source/gdi/embeddedfontshelper.cxx
index a147ea3..c41c1b7 100644
--- a/vcl/source/gdi/embeddedfontshelper.cxx
+++ b/vcl/source/gdi/embeddedfontshelper.cxx
@@ -127,9 +127,10 @@ OUString EmbeddedFontsHelper::fileUrlForTemporaryFont( const OUString&
fontName,
void EmbeddedFontsHelper::activateFont( const OUString& fontName, const OUString& fileUrl )
{
+ SAL_DEBUG("ACT:" << fontName << ":" << fileUrl );
OutputDevice *pDevice = Application::GetDefaultDevice();
pDevice->AddTempDevFont( fileUrl, fontName );
- pDevice->ImplUpdateAllFontData( true );
+// pDevice->ImplUpdateAllFontData( true );
}
// Check if it's (legally) allowed to embed the font file into a document
diff --git a/vcl/win/source/gdi/salgdi3.cxx b/vcl/win/source/gdi/salgdi3.cxx
index 1d08d50..a30522a 100644
--- a/vcl/win/source/gdi/salgdi3.cxx
+++ b/vcl/win/source/gdi/salgdi3.cxx
@@ -53,6 +53,9 @@
#include <set>
#include <map>
+#include <windows.h>
+#include <t2embapi.h>
+
using namespace vcl;
static const int MAXFONTHEIGHT = 2048;
@@ -136,6 +139,7 @@ ImplFontAttrCache::ImplFontAttrCache( const String& rFileNameURL, const String&
if( !aFontFileURL.Len() )
break;
aDFA.SetFamilyName(read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(aCacheFile,
RTL_TEXTENCODING_UTF8));
+// aDFA.SetFamilyName("Bauhaus 93");
short n;
aCacheFile >> n; aDFA.SetWeight(static_cast<FontWeight>(n));
@@ -817,6 +821,7 @@ static ImplDevFontAttributes WinFont2DevFontAttributes( const ENUMLOGFONTEXA& rE
// get the font face name
aDFA.SetFamilyName(ImplSalGetUniString( rLogFont.lfFaceName ));
+// aDFA.SetFamilyName("Bauhaus 93");
// use the face's style name only if it looks reasonable
const char* pStyleName = (const char*)rEnumFont.elfStyle;
@@ -892,6 +897,7 @@ static ImplDevFontAttributes WinFont2DevFontAttributes( const ENUMLOGFONTEXW& rE
// get the font face name
aDFA.SetFamilyName( String().Assign(reinterpret_cast<const
sal_Unicode*>(rLogFont.lfFaceName)));
+// aDFA.SetFamilyName("Bauhaus 93");
// use the face's style name only if it looks reasonable
const wchar_t* pStyleName = rEnumFont.elfStyle;
@@ -1872,6 +1878,7 @@ int CALLBACK SalEnumFontsProcExW( const ENUMLOGFONTEXW* pLogFont,
pInfo->mbCourier = FALSE;
String aName = OUString(reinterpret_cast<const
sal_Unicode*>(pLogFont->elfLogFont.lfFaceName));
pInfo->mpName = &aName;
+// SAL_DEBUG("FN1:" << aName);
memcpy( pInfo->mpLogFontW->lfFaceName, pLogFont->elfLogFont.lfFaceName,
(aName.Len()+1)*sizeof( wchar_t ) );
pInfo->mpLogFontW->lfCharSet = pLogFont->elfLogFont.lfCharSet;
EnumFontFamiliesExW( pInfo->mhDC, pInfo->mpLogFontW,
(FONTENUMPROCW)SalEnumFontsProcExW,
@@ -1936,16 +1943,55 @@ static int WINAPI __AddFontResourceExW( LPCWSTR lpszfileName, DWORD fl,
PVOID pd
}
#endif
+FILE* ff;
+unsigned long readfunc( void*, void* out, unsigned long len )
+{
+ int r = fread( out, 1, len, ff );
+ SAL_DEBUG("RF:" << len << ":" << r );
+ return r;
+}
+
+
+void hack()
+{
+ ff = fopen( "c:\\cygwin\\home\\tinderbox\\tmp\\font.eot", "rb" );
+ SAL_DEBUG( "F:" << (void*)ff );
+ HANDLE ft;
+ ULONG status1;
+ ULONG status2;
+ LONG ret = TTLoadEmbeddedFont(
+ &ft,
+ 0, //TTLOAD_PRIVATE,
+ &status1,
+ LICENSE_DEFAULT,
+ &status2,
+ readfunc,
+ NULL,
+ NULL,
+ NULL,
+ NULL );
+ SAL_DEBUG( "F2:" << ret << ":" << status1 << ":" << status2 );
+ fclose( ff );
+ wchar_t nm[ LF_FACESIZE + 1 ];
+ char nm2[ LF_FACESIZE + 1 ];
+ ret = TTGetNewFontName( &ft, nm, sizeof( nm ), nm2, sizeof(nm2));
+ SAL_DEBUG("F3:" << ret << ":" << OUString( nm ));
+}
+
bool ImplAddTempFont( SalData& rSalData, const OUString& rFontFileURL )
{
+ hack();
+ return true;
+
int nRet = 0;
OUString aUSytemPath;
OSL_VERIFY( !osl::FileBase::getSystemPathFromFileURL( rFontFileURL, aUSytemPath ) );
#ifdef FR_PRIVATE
nRet = __AddFontResourceExW( reinterpret_cast<LPCWSTR>(aUSytemPath.getStr()), FR_PRIVATE, NULL
);
+ SAL_DEBUG("I1");
#endif
-
+ SAL_DEBUG("I2");
if ( !nRet )
{
static int nCounter = 0;
@@ -1962,12 +2008,15 @@ bool ImplAddTempFont( SalData& rSalData, const OUString& rFontFileURL )
rtl_TextEncoding theEncoding = osl_getThreadTextEncoding();
OString aCFileName = OUStringToOString( aUSytemPath, theEncoding );
+ SAL_DEBUG("I3");
// TODO: font should be private => need to investigate why it doesn't work then
if( !::CreateScalableFontResourceA( 0, aResourceName, aCFileName.getStr(), NULL ) )
return false;
++nCounter;
+ SAL_DEBUG("I4");
nRet = ::AddFontResourceA( aResourceName );
+ SAL_DEBUG("I5:" << nRet);
if( nRet > 0 )
{
TempFontItem* pNewItem = new TempFontItem;
@@ -1977,7 +2026,7 @@ bool ImplAddTempFont( SalData& rSalData, const OUString& rFontFileURL )
rSalData.mpTempFontItem = pNewItem;
}
}
-
+ SAL_DEBUG("IX:" << nRet);
return (nRet > 0);
}
@@ -2074,6 +2123,7 @@ static bool ImplGetFontAttrFromFile( const String& rFontFileURL,
// convert byte strings to unicode
rDFA.SetFamilyName(String( aBuffer + nNameOfs, osl_getThreadTextEncoding() ));
+// rDFA.SetFamilyName("Bauhaus 93");
rDFA.SetStyleName(String( aBuffer + nStyleOfs, osl_getThreadTextEncoding() ));
// byte offset 0x4C7: OS2_fsSelection
@@ -2113,7 +2163,7 @@ bool WinSalGraphics::AddTempDevFont( ImplDevFontList* pFontList,
const OUString& rFontFileURL, const OUString& rFontName )
{
RTL_LOGFILE_TRACE1( "WinSalGraphics::AddTempDevFont(): %s", OUStringToOString( rFontFileURL,
RTL_TEXTENCODING_UTF8 ).getStr() );
-
+ SAL_DEBUG("A1:" << rFontFileURL << ":" << rFontName);
ImplDevFontAttributes aDFA;
aDFA.SetFamilyName(rFontName);
aDFA.mnQuality = 1000;
@@ -2131,6 +2181,7 @@ bool WinSalGraphics::AddTempDevFont( ImplDevFontList* pFontList,
mpFontAttrCache->AddFontAttr( rFontFileURL, aDFA );
}
+ SAL_DEBUG("A2");
if ( aDFA.GetFamilyName().isEmpty() )
return false;
@@ -2138,6 +2189,7 @@ bool WinSalGraphics::AddTempDevFont( ImplDevFontList* pFontList,
if( !ImplAddTempFont( *GetSalData(), rFontFileURL ) )
return false;
+ SAL_DEBUG("A3");
UINT nPreferedCharSet = DEFAULT_CHARSET;
// create matching FontData struct
Context
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.