From: Simon Steiner Date: Thu, 12 Oct 2017 11:44:13 +0000 (+0000) Subject: FOP-2752: Show name of font file on error X-Git-Tag: fop-2_3~26 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d81e5851f7c083b4bd86867dee19bc4f19c5610e;p=xmlgraphics-fop.git FOP-2752: Show name of font file on error git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1811944 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/fop-core/src/main/java/org/apache/fop/fonts/LazyFont.java b/fop-core/src/main/java/org/apache/fop/fonts/LazyFont.java index d99a3675f..8963d2102 100644 --- a/fop-core/src/main/java/org/apache/fop/fonts/LazyFont.java +++ b/fop-core/src/main/java/org/apache/fop/fonts/LazyFont.java @@ -19,7 +19,6 @@ package org.apache.fop.fonts; import java.awt.Rectangle; -import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.List; @@ -31,7 +30,6 @@ import org.xml.sax.InputSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.fop.apps.FOPException; import org.apache.fop.apps.io.InternalResourceResolver; import org.apache.fop.complexscripts.fonts.Positionable; import org.apache.fop.complexscripts.fonts.Substitutable; @@ -124,15 +122,14 @@ public class LazyFont extends Typeface implements FontDescriptor, Substitutable, if (realFont instanceof FontDescriptor) { realFontDescriptor = (FontDescriptor) realFont; } - } catch (FOPException fopex) { - log.error("Failed to read font metrics file " + fontUris.getMetrics(), fopex); + } catch (RuntimeException e) { + String error = "Failed to read font file " + fontUris.getEmbed(); + throw new RuntimeException(error, e); + } catch (Exception e) { + String error = "Failed to read font file " + fontUris.getEmbed(); + log.error(error, e); if (fail) { - throw new RuntimeException(fopex); - } - } catch (IOException ioex) { - log.error("Failed to read font metrics file " + fontUris.getMetrics(), ioex); - if (fail) { - throw new RuntimeException(ioex); + throw new RuntimeException(error, e); } } realFont.setEventListener(this.eventListener); diff --git a/fop-core/src/test/java/org/apache/fop/fonts/LazyFontTestCase.java b/fop-core/src/test/java/org/apache/fop/fonts/LazyFontTestCase.java new file mode 100644 index 000000000..afea3ce9d --- /dev/null +++ b/fop-core/src/test/java/org/apache/fop/fonts/LazyFontTestCase.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ +package org.apache.fop.fonts; + +import java.net.URI; +import java.net.URISyntaxException; + +import org.junit.Assert; +import org.junit.Test; + +public class LazyFontTestCase { + @Test + public void testFontError() throws URISyntaxException { + FontUris fontUris = new FontUris(new URI("test"), null); + LazyFont lazyFont = new LazyFont(new EmbedFontInfo(fontUris, true, true, null, null), null, true); + String ex = null; + try { + lazyFont.getAscender(); + } catch (RuntimeException e) { + ex = e.getMessage(); + } + Assert.assertEquals(ex, "Failed to read font file test"); + } +}