summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2013-10-05 10:32:12 +0100
committerMichael Stahl <mstahl@redhat.com>2013-10-15 15:36:10 +0000
commitc3e4ad052f7fceda20441809e48573dc6a1589ae (patch)
tree68e9c553b9c4d9ef362a1355d7c552d3dda0fe77
parente3fdff9d00c9ef598210853f7094e8f986586e0b (diff)
CID#736943 clamp no of ttc entries to physical max
Change-Id: Ic63defe9c14c6ee2b86bd5b7730a570238ca3981 (cherry picked from commit 225539ab08043b6937fdd67d9ae308ebd4104646) Reviewed-on: https://gerrit.libreoffice.org/6149 Reviewed-by: Michael Stahl <mstahl@redhat.com> Tested-by: Michael Stahl <mstahl@redhat.com>
-rw-r--r--vcl/generic/fontmanager/fontmanager.cxx33
1 files changed, 33 insertions, 0 deletions
diff --git a/vcl/generic/fontmanager/fontmanager.cxx b/vcl/generic/fontmanager/fontmanager.cxx
index aa84fc749d34..a915d7d8d234 100644
--- a/vcl/generic/fontmanager/fontmanager.cxx
+++ b/vcl/generic/fontmanager/fontmanager.cxx
@@ -1192,6 +1192,39 @@ bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, ::
#if OSL_DEBUG_LEVEL > 1
fprintf( stderr, "ttc: %s contains %d fonts\n", aFullPath.getStr(), nLength );
#endif
+
+ sal_uInt64 fileSize;
+
+ OUString aURL;
+ if (!osl::File::getFileURLFromSystemPath(OStringToOUString(aFullPath, osl_getThreadTextEncoding()),
+ aURL))
+ {
+ fileSize = 0;
+ }
+ else
+ {
+ osl::File aFile(aURL);
+ if (aFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_NoLock) != osl::File::E_None)
+ fileSize = 0;
+ else
+ {
+ osl::DirectoryItem aItem;
+ osl::DirectoryItem::get( aURL, aItem );
+ osl::FileStatus aFileStatus( osl_FileStatus_Mask_FileSize );
+ aItem.getFileStatus( aFileStatus );
+ fileSize = aFileStatus.getFileSize();
+ }
+ }
+
+ //Feel free to calc the exact max possible number of fonts a file
+ //could contain given its physical size. But this will clamp it to
+ //a sane starting point
+ //http://processingjs.nihongoresources.com/the_smallest_font/
+ //https://github.com/grzegorzrolek/null-ttf
+ int nMaxFontsPossible = fileSize / 528;
+
+ nLength = std::min(nLength, nMaxFontsPossible);
+
for( int i = 0; i < nLength; i++ )
{
TrueTypeFontFile* pFont = new TrueTypeFontFile();