]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2752: Show name of font file on error
authorSimon Steiner <ssteiner@apache.org>
Thu, 12 Oct 2017 11:44:13 +0000 (11:44 +0000)
committerSimon Steiner <ssteiner@apache.org>
Thu, 12 Oct 2017 11:44:13 +0000 (11:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1811944 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/fonts/LazyFont.java
fop-core/src/test/java/org/apache/fop/fonts/LazyFontTestCase.java [new file with mode: 0644]

index d99a3675f1ba71c9aec632baa9a6b3baa4a60532..8963d2102d47c7dd7fba363b21a22673e757929e 100644 (file)
@@ -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 (file)
index 0000000..afea3ce
--- /dev/null
@@ -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");
+    }
+}