aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAdrian Cumiskey <acumiskey@apache.org>2008-05-06 16:14:09 +0000
committerAdrian Cumiskey <acumiskey@apache.org>2008-05-06 16:14:09 +0000
commitcff8a3713fc7e069ab5bf46585131071d50fb979 (patch)
tree0135c713caba8113c6f10e2c24469af45275cdf1 /test
parente5158b410b3d257e492610b10594e670e6e1d834 (diff)
downloadxmlgraphics-fop-cff8a3713fc7e069ab5bf46585131071d50fb979.tar.gz
xmlgraphics-fop-cff8a3713fc7e069ab5bf46585131071d50fb979.zip
* Added font substitution configuration reader, model, business logic, junit test and docs.
* Added java 1.5 generics comments to many methods. * Performed some preparatory cleanup and refactoring which includes (but is not limited to..) - Creating a FontManager delegating class that is called upon when renderers are setting up fonts - A new FontCollection interface and concrete implementing classes to supercede the static FontSetup mechanism. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@653826 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r--test/config/test_fonts_substitution.xconf33
-rw-r--r--test/java/org/apache/fop/config/BaseUserConfigTestCase.java2
-rw-r--r--test/java/org/apache/fop/config/FontsSubstitutionTestCase.java63
-rw-r--r--test/java/org/apache/fop/config/UserConfigTestSuite.java1
-rw-r--r--test/java/org/apache/fop/layoutengine/LayoutEngineTester.java4
-rw-r--r--test/java/org/apache/fop/render/pdf/BasePDFTestCase.java2
-rw-r--r--test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java8
7 files changed, 105 insertions, 8 deletions
diff --git a/test/config/test_fonts_substitution.xconf b/test/config/test_fonts_substitution.xconf
new file mode 100644
index 000000000..b5638a035
--- /dev/null
+++ b/test/config/test_fonts_substitution.xconf
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<fop version="1.0">
+ <!-- Strict configuration On -->
+ <strict-configuration>true</strict-configuration>
+
+ <!-- Switch off font caching for the purposes of the unit test -->
+ <use-cache>false</use-cache>
+
+ <!-- Base URL for resolving relative URLs -->
+ <base>./</base>
+
+ <!-- Font Base URL for resolving relative font URLs -->
+ <font-base>./</font-base>
+
+ <fonts>
+ <substitutions>
+ <substitution>
+ <from font-family="Times" font-style="italic"/>
+ <to font-family="Gladiator" font-style="normal" font-weight="bold"/>
+ </substitution>
+ </substitutions>
+ </fonts>
+
+ <renderers>
+ <renderer mime="application/pdf">
+ <fonts>
+ <font metrics-url="test/resources/fonts/glb12.ttf.xml" embed-url="test/resources/fonts/glb12.ttf">
+ <font-triplet name="Gladiator" style="normal" weight="bold"/>
+ </font>
+ </fonts>
+ </renderer>
+ </renderers>
+</fop>
diff --git a/test/java/org/apache/fop/config/BaseUserConfigTestCase.java b/test/java/org/apache/fop/config/BaseUserConfigTestCase.java
index 2de7ad673..d216d583a 100644
--- a/test/java/org/apache/fop/config/BaseUserConfigTestCase.java
+++ b/test/java/org/apache/fop/config/BaseUserConfigTestCase.java
@@ -66,7 +66,7 @@ public abstract class BaseUserConfigTestCase extends BasePDFTestCase {
final File baseDir = getBaseDir();
final String fontFOFilePath = getFontFOFilePath();
File foFile = new File(baseDir, fontFOFilePath);
- final boolean dumpOutput = false;
+ final boolean dumpOutput = true;
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
convertFO(foFile, foUserAgent, dumpOutput);
}
diff --git a/test/java/org/apache/fop/config/FontsSubstitutionTestCase.java b/test/java/org/apache/fop/config/FontsSubstitutionTestCase.java
new file mode 100644
index 000000000..5202e837a
--- /dev/null
+++ b/test/java/org/apache/fop/config/FontsSubstitutionTestCase.java
@@ -0,0 +1,63 @@
+/*
+ * 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.config;
+
+import java.io.File;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.fonts.Font;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontManager;
+import org.apache.fop.fonts.FontTriplet;
+import org.apache.fop.render.PrintRenderer;
+
+public class FontsSubstitutionTestCase extends BaseConstructiveUserConfigTestCase {
+
+ public FontsSubstitutionTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected byte[] convertFO(File foFile, FOUserAgent ua, boolean dumpPdfFile) throws Exception {
+ PrintRenderer renderer = (PrintRenderer)ua.getRendererFactory().createRenderer(ua, MimeConstants.MIME_PDF);
+ FontInfo fontInfo = new FontInfo();
+ renderer.setupFontInfo(fontInfo);
+ FontManager fontManager = ua.getFactory().getFontManager();
+ fontManager.setupRenderer(renderer);
+ FontTriplet triplet = new FontTriplet("Times", "italic", Font.WEIGHT_NORMAL);
+ String internalFontKey = fontInfo.getInternalFontKey(triplet);
+ // Times italic should now be mapped to the 15th font (custom font)
+ // not the original base 14 (F6)
+ if (!"F15".equals(internalFontKey)) {
+ throw new Exception("font substitution failed :" + triplet);
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getUserConfigFilename() {
+ return "test_fonts_substitution.xconf";
+ }
+}
diff --git a/test/java/org/apache/fop/config/UserConfigTestSuite.java b/test/java/org/apache/fop/config/UserConfigTestSuite.java
index 439a2c031..c12180625 100644
--- a/test/java/org/apache/fop/config/UserConfigTestSuite.java
+++ b/test/java/org/apache/fop/config/UserConfigTestSuite.java
@@ -44,6 +44,7 @@ public class UserConfigTestSuite {
suite.addTest(new TestSuite(FontEmbedUrlMalformedTestCase.class));
suite.addTest(new TestSuite(FontsDirectoryRecursiveTestCase.class));
suite.addTest(new TestSuite(FontsAutoDetectTestCase.class));
+ suite.addTest(new TestSuite(FontsSubstitutionTestCase.class));
//$JUnit-END$
return suite;
}
diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
index bcd5f1db4..b37abdf0d 100644
--- a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
+++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
@@ -95,8 +95,8 @@ public class LayoutEngineTester {
*/
public LayoutEngineTester(File areaTreeBackupDir) {
this.areaTreeBackupDir = areaTreeBackupDir;
- fopFactory.setBase14KerningEnabled(false);
- fopFactoryWithBase14Kerning.setBase14KerningEnabled(true);
+ fopFactory.getFontManager().setBase14KerningEnabled(false);
+ fopFactoryWithBase14Kerning.getFontManager().setBase14KerningEnabled(true);
}
private Templates getTestcase2FOStylesheet() throws TransformerConfigurationException {
diff --git a/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java b/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java
index 7c66a0ceb..d4b748a8d 100644
--- a/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java
+++ b/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java
@@ -101,7 +101,7 @@ public class BasePDFTestCase extends AbstractFOPTestCase {
}
}
- private static Exception extractOriginalException(Exception e) {
+ protected static Exception extractOriginalException(Exception e) {
if (e.getCause() != null) {
return extractOriginalException((Exception)e.getCause());
} else if (e instanceof SAXException) {
diff --git a/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java b/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java
index 881a8abd2..96167ceb0 100644
--- a/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java
+++ b/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java
@@ -44,9 +44,9 @@ public class PDFAConformanceTestCase extends BasePDFTestCase {
* @return an initialized FOUserAgent
* */
protected FOUserAgent getUserAgent() {
- final FOUserAgent a = fopFactory.newFOUserAgent();
- a.getRendererOptions().put("pdf-a-mode", "PDF/A-1b");
- return a;
+ final FOUserAgent userAgent = fopFactory.newFOUserAgent();
+ userAgent.getRendererOptions().put("pdf-a-mode", "PDF/A-1b");
+ return userAgent;
}
/**
@@ -104,5 +104,5 @@ public class PDFAConformanceTestCase extends BasePDFTestCase {
//Good!
}
}
-
+
}