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:34:42 +0000
commit22e58528fed41b15d242eb9e85dc25c51ec01e4d (patch)
tree5048a4097cd82a485cddb5a6df2bd84a4bc6d376
parenta6e066e3aa1fdf0e9001e4721171b523ac39d8d8 (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/6150 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 d3adb503074d..418f480a9593 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();