]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
New function to determine whether a particular character is available for this font.
authorJeremias Maerki <jeremias@apache.org>
Sat, 3 Apr 2004 13:36:08 +0000 (13:36 +0000)
committerJeremias Maerki <jeremias@apache.org>
Sat, 3 Apr 2004 13:36:08 +0000 (13:36 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197488 13f79535-47bb-0310-9956-ffa450edef68

src/codegen/font-file.xsl
src/java/org/apache/fop/fonts/Font.java
src/java/org/apache/fop/fonts/LazyFont.java
src/java/org/apache/fop/fonts/MultiByteFont.java
src/java/org/apache/fop/fonts/SingleByteFont.java
src/java/org/apache/fop/fonts/Typeface.java

index 09fbd222579a72727eff8fb8502732119f19577f..93f70cdff614cfa0e3dd67b8a8324896345abd9e 100644 (file)
@@ -121,6 +121,10 @@ public class <xsl:value-of select="class-name"/> extends Typeface {
         }
     }
 
+    public boolean hasChar(char c) {
+        return (mapping.mapChar(c) > 0);
+    }
+
 }
   </xsl:template>
 
index 9cce65d74bd95dea6843b9db0c5c7c6275a562ea..d2e58c7757b3ee7cbbfc670adce4f7a5ee3efc82 100644 (file)
@@ -154,6 +154,20 @@ public class Font {
 
         return c;
     }
+    
+    /**
+     * Determines whether this font contains a particular character/glyph.
+     * @param c character to check
+     * @return True if the character is supported, Falso otherwise
+     */
+    public boolean hasChar(char c) {
+        if (metric instanceof org.apache.fop.fonts.Typeface) {
+            return ((org.apache.fop.fonts.Typeface)metric).hasChar(c);
+        } else {
+            // Use default CodePointMapping
+            return (CodePointMapping.getMapping("WinAnsiEncoding").mapChar(c) > 0);
+        }
+    }
 
     /**
      * @see java.lang.Object#toString()
@@ -182,7 +196,6 @@ public class Font {
      * This also performs some guessing on widths on various
      * versions of space that might not exists in the font.
      * @param c character to inspect
-     * @param fs FontState to use
      * @return the width of the character
      */
     public int getCharWidth(char c) {
@@ -257,10 +270,13 @@ public class Font {
 
     /**
      * Calculates the word width.
+     * @param word text to get width for
+     * @return the width of the text
      */
     public int getWordWidth(String word) {
-        if (word == null)
+        if (word == null) {
             return 0;
+        }
         int wordLength = word.length();
         int width = 0;
         char[] characters = new char[wordLength];
index b16f6b0273ce843619f3e38c021f1e5b692a7b22..149b15c15f8d9fc1768a769f7efe492ae5770312 100644 (file)
@@ -92,13 +92,21 @@ public class LazyFont extends Typeface implements FontDescriptor {
     }
 
     /**
-     * @see org.apache.fop.fonts.Font#mapChar(char)
+     * @see org.apache.fop.fonts.Typeface#mapChar(char)
      */
     public char mapChar(char c) {
         load();
         return realFont.mapChar(c);
     }
 
+    /**
+     * @see org.apache.fop.fonts.Typeface#hasChar(char)
+     */
+    public boolean hasChar(char c) {
+        load();
+        return realFont.hasChar(c);
+    }
+
     /**
      * @see org.apache.fop.fonts.Typeface#isMultiByte()
      */
index 62f5be9610b3a0e5e0ef3504130c9cfaddb8561f..566636c3778f720c795c37de31a7062dc0e4bc68 100644 (file)
@@ -125,12 +125,7 @@ public class MultiByteFont extends CIDFont {
      * @see org.apache.fop.fonts.FontDescriptor#isEmbeddable()
      */
     public boolean isEmbeddable() {
-        if (getEmbedFileName() == null
-            && embedResourceName == null) {
-            return false;
-        } else {
-            return true;
-            }
+        return !(getEmbedFileName() == null && embedResourceName == null); 
     }
 
     /**
@@ -196,20 +191,27 @@ public class MultiByteFont extends CIDFont {
     }
 */
 
-    /**
-     * @see org.apache.fop.fonts.Font#mapChar(char)
-     */
-    public char mapChar(char c) {
+    private int findGlyphIndex(char c) {
         int idx = (int)c;
         int retIdx = 0;
 
         for (int i = 0; (i < bfentries.length) && retIdx == 0; i++) {
             if (bfentries[i].getUnicodeStart() <= idx
                     && bfentries[i].getUnicodeEnd() >= idx) {
-                retIdx = bfentries[i].getGlyphStartIndex() + idx
-                         - bfentries[i].getUnicodeStart();
+                        
+                retIdx = bfentries[i].getGlyphStartIndex() 
+                    + idx
+                    - bfentries[i].getUnicodeStart();
             }
         }
+        return retIdx;
+    }
+
+    /**
+     * @see org.apache.fop.fonts.Typeface#mapChar(char)
+     */
+    public char mapChar(char c) {
+        int retIdx = findGlyphIndex(c);
 
         if (isEmbeddable()) {
             // Reencode to a new subset font or get
@@ -231,6 +233,14 @@ public class MultiByteFont extends CIDFont {
         return (char)retIdx;
     }
 
+    /**
+     * @see org.apache.fop.fonts.Typeface#hasChar(char)
+     */
+    public boolean hasChar(char c) {
+        return (findGlyphIndex(c) > 0);
+    }
+
+
     /**
      * Sets the bfentries.
      * @param bfentries The bfentries to set
index e28bc653a3cc23bed86c2c00220e78ef42b4b3d0..26bba54a605dd4819eba72b7fa2ca7f86abafb7a 100644 (file)
@@ -67,7 +67,7 @@ public class SingleByteFont extends CustomFont {
     }
 
     /**
-     * @see org.apache.fop.fonts.Font#mapChar(char)
+     * @see org.apache.fop.fonts.Typeface#mapChar(char)
      */
     public char mapChar(char c) {
         char d = mapping.mapChar(c);
@@ -77,6 +77,13 @@ public class SingleByteFont extends CustomFont {
             return '#';
         }
     }
+    
+    /**
+     * @see org.apache.fop.fonts.Typeface#hasChar(char)
+     */
+    public boolean hasChar(char c) {
+        return (mapping.mapChar(c) > 0);
+    }
 
     /* ---- single byte font specific setters --- */
 
index f3e24cf986b366251411b3eff737fbbe90aa03bb..f39a80d40785c6f91939e61103694ea8f483ce70 100644 (file)
@@ -39,6 +39,13 @@ public abstract class Typeface implements FontMetrics {
      */
     public abstract char mapChar(char c);
 
+    /**
+     * Determines whether this font contains a particular character/glyph.
+     * @param c character to check
+     * @return True if the character is supported, Falso otherwise
+     */
+    public abstract boolean hasChar(char c);
+    
     /**
      * Determines whether the font is a multibyte font.
      * @return True if it is multibyte