You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by je...@apache.org on 2008/02/13 11:43:24 UTC
svn commit: r627348 - in /xmlgraphics/commons/trunk:
src/java/org/apache/xmlgraphics/fonts/Glyphs.java
test/java/org/apache/xmlgraphics/fonts/
test/java/org/apache/xmlgraphics/fonts/GlyphsTest.java
Author: jeremias
Date: Wed Feb 13 02:43:24 2008
New Revision: 627348
URL: http://svn.apache.org/viewvc?rev=627348&view=rev
Log:
Deprecated glyphToString() as it only returns the first Unicode code point for a given glyph name.
Added a new method with returns all Unicode code points for a glyph name. It does so using a log(n) lookup in a TreeMap instead of a sequential scan in a table.
Added:
xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/fonts/
xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/fonts/GlyphsTest.java (with props)
Modified:
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/fonts/Glyphs.java
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/fonts/Glyphs.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/fonts/Glyphs.java?rev=627348&r1=627347&r2=627348&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/fonts/Glyphs.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/fonts/Glyphs.java Wed Feb 13 02:43:24 2008
@@ -19,6 +19,9 @@
package org.apache.xmlgraphics.fonts;
+import java.util.Collections;
+import java.util.Map;
+
/**
* This class provides a number of constants for glyph management.
*/
@@ -1265,6 +1268,23 @@
"\u03B6", "zeta"
};
+ private static final Map CHARNAMES_TO_UNICODE;
+
+ static {
+ Map map = new java.util.TreeMap();
+ for (int i = 0; i < UNICODE_GLYPHS.length; i += 2) {
+ String charName = UNICODE_GLYPHS[i + 1];
+ String unicode = UNICODE_GLYPHS[i];
+ String existing = (String)map.get(charName);
+ if (existing == null) {
+ map.put(charName, unicode);
+ } else {
+ map.put(charName, existing + unicode);
+ }
+ }
+ CHARNAMES_TO_UNICODE = Collections.unmodifiableMap(map);
+ }
+
/**
* Return the glyphname from a character,
* eg, charToGlyphName('\\') returns "backslash"
@@ -1277,13 +1297,24 @@
}
/**
+ * Returns a String containing all Unicode code points the given glyph names can be mapped to.
+ * @param glyphName the glyph name
+ * @return a String with a character per applicable Unicode code point or null if no such glyph
+ * name is known
+ */
+ public static final String getUnicodeCodePointsForGlyphName(String glyphName) {
+ return (String)CHARNAMES_TO_UNICODE.get(glyphName);
+ }
+
+ /**
* Return the glyphname from a string,
* eg, glyphToString("\\") returns "backslash"
*
* @param name glyph to evaluate
* @return the name of the glyph
* TODO: javadocs for glyphToString and stringToGlyph are confused
- * TODO: Improve method names
+ * @deprecated User getUnicodeCodePointsForGlyphName instead. This method only returns the
+ * first Unicode code point it finds.
*/
public static final String glyphToString(String name) {
for (int i = 0; i < UNICODE_GLYPHS.length; i += 2) {
Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/fonts/GlyphsTest.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/fonts/GlyphsTest.java?rev=627348&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/fonts/GlyphsTest.java (added)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/fonts/GlyphsTest.java Wed Feb 13 02:43:24 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.xmlgraphics.fonts;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for the Glyphs class.
+ */
+public class GlyphsTest extends TestCase {
+
+ public void testGetUnicodeCodePointsForGlyphName() throws Exception {
+ String glyph;
+ String unicodes;
+
+ glyph = "Omega";
+ unicodes = Glyphs.getUnicodeCodePointsForGlyphName(glyph);
+ assertEquals(2, unicodes.length());
+ assertTrue("Must contain 03A9 - GREEK CAPITAL LETTER OMEGA",
+ unicodes.indexOf("\u03A9") >= 0);
+ assertTrue("Must contain 2126 - OHM SIGN",
+ unicodes.indexOf("\u03A9") >= 0);
+
+ glyph = "A";
+ unicodes = Glyphs.getUnicodeCodePointsForGlyphName(glyph);
+ assertEquals(1, unicodes.length());
+ assertTrue("Must contain 0041 - LATIN CAPITAL LETTER A",
+ unicodes.indexOf("\u0041") >= 0);
+ }
+
+}
Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/fonts/GlyphsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/fonts/GlyphsTest.java
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
Apache XML Graphics Project URL: http://xmlgraphics.apache.org/
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org