You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by "Dan Caprioara (Jira)" <ji...@apache.org> on 2019/12/16 08:36:00 UTC

[jira] [Updated] (FOP-2897) Out of memory when loading fonts on Mac - instead it should report font too large and continue

     [ https://issues.apache.org/jira/browse/FOP-2897?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dan Caprioara updated FOP-2897:
-------------------------------
    Description: 
The FontInfoFinder class collects all the fonts from the system. On Mac there are huge font files containing icons. This makes FOP break with OutOfMemoryError.

Probably it should show an warning and throw an IOException instead of OOM (IOException does not break the entire processing, just skips the current font loading, in this way next fonts can be loaded).

There are two places in the FontInfoFinder class where the OOM should be catched:
{code:java}
 try {
   TTFFile ttf = new TTFFile(false, false);                
   FontFileReader reader = new FontFileReader(in);
   ttcNames = ttf.getTTCnames(reader);
 } catch (OutOfMemoryError oom) {                  
   handleOOM(fontURI);
 }
{code}
{code:java}
try {
   OFFontLoader ttfLoader = new OFFontLoader(fontURI, fontName, true,
                				EmbeddingMode.AUTO, EncodingMode.AUTO, useKerning, useAdvanced,
                				resourceResolver, false, false);
   customFont = ttfLoader.getFont();
   if (this.eventListener != null) {
      customFont.setEventListener(this.eventListener);
   }
} catch(OutOfMemoryError e) {
   handleOOM(fontURI);
}
{code}
And the handling:
{code:java}
	private void handleOOM(URI fontURI) throws IOException {
		String sizeMsg = "";
		  if ("file".equals(fontURI.getScheme())) {
		    sizeMsg = "The font file size was: " + new File(fontURI).length() + " bytes";
		  }
		  throw new IOException(
		        "Font is too large. " + sizeMsg);
	}
{code}

  was:
The FontInfoFinder class collects all the fonts from the system. On Mac there are huge font files containing icons. This makes FOP break with OutOfMemoryError.

Probably it should show an warning and throw an IOException instead of OOM. In this way next fonts can be loaded.

There are two places in the FontInfoFinder class where the OOM should be catched:
{code:java}
 try {
   TTFFile ttf = new TTFFile(false, false);                
   FontFileReader reader = new FontFileReader(in);
   ttcNames = ttf.getTTCnames(reader);
 } catch (OutOfMemoryError oom) {                  
   handleOOM(fontURI);
 }
{code}
{code:java}
try {
   OFFontLoader ttfLoader = new OFFontLoader(fontURI, fontName, true,
                				EmbeddingMode.AUTO, EncodingMode.AUTO, useKerning, useAdvanced,
                				resourceResolver, false, false);
   customFont = ttfLoader.getFont();
   if (this.eventListener != null) {
      customFont.setEventListener(this.eventListener);
   }
} catch(OutOfMemoryError e) {
   handleOOM(fontURI);
}
{code}
And the handling:
{code:java}
	private void handleOOM(URI fontURI) throws IOException {
		String sizeMsg = "";
		  if ("file".equals(fontURI.getScheme())) {
		    sizeMsg = "The font file size was: " + new File(fontURI).length() + " bytes";
		  }
		  throw new IOException(
		        "Font is too large. " + sizeMsg);
	}
{code}


> Out of memory when loading fonts on Mac - instead it should report font too large and continue
> ----------------------------------------------------------------------------------------------
>
>                 Key: FOP-2897
>                 URL: https://issues.apache.org/jira/browse/FOP-2897
>             Project: FOP
>          Issue Type: Bug
>            Reporter: Dan Caprioara
>            Priority: Major
>             Fix For: 2.4
>
>
> The FontInfoFinder class collects all the fonts from the system. On Mac there are huge font files containing icons. This makes FOP break with OutOfMemoryError.
> Probably it should show an warning and throw an IOException instead of OOM (IOException does not break the entire processing, just skips the current font loading, in this way next fonts can be loaded).
> There are two places in the FontInfoFinder class where the OOM should be catched:
> {code:java}
>  try {
>    TTFFile ttf = new TTFFile(false, false);                
>    FontFileReader reader = new FontFileReader(in);
>    ttcNames = ttf.getTTCnames(reader);
>  } catch (OutOfMemoryError oom) {                  
>    handleOOM(fontURI);
>  }
> {code}
> {code:java}
> try {
>    OFFontLoader ttfLoader = new OFFontLoader(fontURI, fontName, true,
>                 				EmbeddingMode.AUTO, EncodingMode.AUTO, useKerning, useAdvanced,
>                 				resourceResolver, false, false);
>    customFont = ttfLoader.getFont();
>    if (this.eventListener != null) {
>       customFont.setEventListener(this.eventListener);
>    }
> } catch(OutOfMemoryError e) {
>    handleOOM(fontURI);
> }
> {code}
> And the handling:
> {code:java}
> 	private void handleOOM(URI fontURI) throws IOException {
> 		String sizeMsg = "";
> 		  if ("file".equals(fontURI.getScheme())) {
> 		    sizeMsg = "The font file size was: " + new File(fontURI).length() + " bytes";
> 		  }
> 		  throw new IOException(
> 		        "Font is too large. " + sizeMsg);
> 	}
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)