From 1939c00e198dd9c45bc5847dd58f27485372934e Mon Sep 17 00:00:00 2001 From: Simon Pepping Date: Thu, 11 Nov 2010 09:48:24 +0000 Subject: [PATCH] Applied patch 50240 by Mehdi Houshmand with changes: Java source and target changed to 1.5. EncodingMode changed from class -> enum. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1033859 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 4 +-- .../org/apache/fop/fonts/EncodingMode.java | 35 ++++++------------- .../fop/fonts/FontInfoConfigurator.java | 2 +- .../apache/fop/fonts/EncodingModeTest.java | 17 +++++++++ 4 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 test/java/org/apache/fop/fonts/EncodingModeTest.java diff --git a/build.xml b/build.xml index 15e6d0ac4..ae4f5c886 100644 --- a/build.xml +++ b/build.xml @@ -149,8 +149,8 @@ list of possible build targets. - - + + diff --git a/src/java/org/apache/fop/fonts/EncodingMode.java b/src/java/org/apache/fop/fonts/EncodingMode.java index 734292c54..8a40d6593 100644 --- a/src/java/org/apache/fop/fonts/EncodingMode.java +++ b/src/java/org/apache/fop/fonts/EncodingMode.java @@ -19,25 +19,19 @@ package org.apache.fop.fonts; -import java.io.ObjectStreamException; -import java.io.Serializable; - - /** * This class enumerates all supported encoding modes for fonts: auto, single-byte and CID. */ -public final class EncodingMode implements Serializable { - - private static final long serialVersionUID = 8311486102457779529L; +public enum EncodingMode { /** Automatic selection of encoding mode. */ - public static final EncodingMode AUTO = new EncodingMode("auto"); + AUTO("auto"), /** Single-byte encoding */ - public static final EncodingMode SINGLE_BYTE = new EncodingMode("single-byte"); + SINGLE_BYTE("single-byte"), /** CID encoding */ - public static final EncodingMode CID = new EncodingMode("cid"); + CID("cid"); private String name; @@ -58,25 +52,18 @@ public final class EncodingMode implements Serializable { * @param name the name of the encoding mode to look up * @return the encoding mode constant */ - public static EncodingMode valueOf(String name) { - if (name.equalsIgnoreCase(EncodingMode.AUTO.getName())) { - return EncodingMode.AUTO; - } else if (name.equalsIgnoreCase(EncodingMode.SINGLE_BYTE.getName())) { - return EncodingMode.SINGLE_BYTE; - } else if (name.equalsIgnoreCase(EncodingMode.CID.getName())) { - return EncodingMode.CID; - } else { - throw new IllegalArgumentException("Invalid encoding mode: " + name); + public static EncodingMode getEncodingMode(String name) { + for (EncodingMode em : EncodingMode.values()) { + if (name.equalsIgnoreCase(em.getName())) { + return em; + } } - } - - private Object readResolve() throws ObjectStreamException { - return valueOf(getName()); + throw new IllegalArgumentException("Invalid encoding mode: " + name); } /** {@inheritDoc} */ public String toString() { - return "EncodingMode:" + getName(); + return "EncodingMode: " + getName(); } } diff --git a/src/java/org/apache/fop/fonts/FontInfoConfigurator.java b/src/java/org/apache/fop/fonts/FontInfoConfigurator.java index f8399b110..9a11f84bc 100644 --- a/src/java/org/apache/fop/fonts/FontInfoConfigurator.java +++ b/src/java/org/apache/fop/fonts/FontInfoConfigurator.java @@ -254,7 +254,7 @@ public class FontInfoConfigurator { } boolean useKerning = fontCfg.getAttributeAsBoolean("kerning", true); - EncodingMode encodingMode = EncodingMode.valueOf( + EncodingMode encodingMode = EncodingMode.getEncodingMode( fontCfg.getAttribute("encoding-mode", EncodingMode.AUTO.getName())); EmbedFontInfo embedFontInfo = new EmbedFontInfo(metricsUrl, useKerning, tripletList, embedUrl, subFont); diff --git a/test/java/org/apache/fop/fonts/EncodingModeTest.java b/test/java/org/apache/fop/fonts/EncodingModeTest.java new file mode 100644 index 000000000..d291f4c0b --- /dev/null +++ b/test/java/org/apache/fop/fonts/EncodingModeTest.java @@ -0,0 +1,17 @@ +package org.apache.fop.fonts; + +import junit.framework.TestCase; + +public class EncodingModeTest extends TestCase { + public void testGetName() { + assertEquals("auto", EncodingMode.AUTO.getName()); + assertEquals("single-byte", EncodingMode.SINGLE_BYTE.getName()); + assertEquals("cid", EncodingMode.CID.getName()); + } + + public void testGetValue() { + assertEquals(EncodingMode.AUTO, EncodingMode.getEncodingMode("auto")); + assertEquals(EncodingMode.SINGLE_BYTE, EncodingMode.getEncodingMode("single-byte")); + assertEquals(EncodingMode.CID, EncodingMode.getEncodingMode("cid")); + } +} -- 2.39.5