summaryrefslogtreecommitdiff
path: root/vcl/generic
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2013-10-05 10:32:12 +0100
committerCaolán McNamara <caolanm@redhat.com>2013-10-07 09:16:21 +0100
commit225539ab08043b6937fdd67d9ae308ebd4104646 (patch)
treeeb695a2016a2aa5b6886a94950a4c27794642aaf /vcl/generic
parent54250655897009914936f02e04d601eadfddb2c1 (diff)
CID#736943 clamp no of ttc entries to physical max
Change-Id: Ic63defe9c14c6ee2b86bd5b7730a570238ca3981
Diffstat (limited to 'vcl/generic')
-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 2ab8e6c9c4f8..6d47ed5f5c56 100644
--- a/vcl/generic/fontmanager/fontmanager.cxx
+++ b/vcl/generic/fontmanager/fontmanager.cxx
@@ -1175,6 +1175,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();