jeremias    2004/04/03 05:31:40

  Modified:    src/java/org/apache/fop/fonts Typeface.java
                        MultiByteFont.java Font.java LazyFont.java
                        SingleByteFont.java
  Log:
  New function to determine whether a particular character is available for this font.
  
  Revision  Changes    Path
  1.3       +8 -1      xml-fop/src/java/org/apache/fop/fonts/Typeface.java
  
  Index: Typeface.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fonts/Typeface.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Typeface.java     27 Feb 2004 17:47:14 -0000      1.2
  +++ Typeface.java     3 Apr 2004 13:31:40 -0000       1.3
  @@ -40,6 +40,13 @@
       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
        */
  
  
  
  1.6       +22 -12    xml-fop/src/java/org/apache/fop/fonts/MultiByteFont.java
  
  Index: MultiByteFont.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fonts/MultiByteFont.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MultiByteFont.java        27 Feb 2004 17:47:14 -0000      1.5
  +++ MultiByteFont.java        3 Apr 2004 13:31:40 -0000       1.6
  @@ -125,12 +125,7 @@
        * @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 @@
       }
   */
   
  -    /**
  -     * @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
  @@ -230,6 +232,14 @@
   
           return (char)retIdx;
       }
  +
  +    /**
  +     * @see org.apache.fop.fonts.Typeface#hasChar(char)
  +     */
  +    public boolean hasChar(char c) {
  +        return (findGlyphIndex(c) > 0);
  +    }
  +
   
       /**
        * Sets the bfentries.
  
  
  
  1.7       +18 -2     xml-fop/src/java/org/apache/fop/fonts/Font.java
  
  Index: Font.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fonts/Font.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Font.java 27 Feb 2004 17:47:14 -0000      1.6
  +++ Font.java 3 Apr 2004 13:31:40 -0000       1.7
  @@ -154,6 +154,20 @@
   
           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 @@
        * 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 @@
   
       /**
        * 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];
  
  
  
  1.7       +9 -1      xml-fop/src/java/org/apache/fop/fonts/LazyFont.java
  
  Index: LazyFont.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fonts/LazyFont.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- LazyFont.java     27 Feb 2004 17:47:14 -0000      1.6
  +++ LazyFont.java     3 Apr 2004 13:31:40 -0000       1.7
  @@ -92,11 +92,19 @@
       }
   
       /**
  -     * @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);
       }
   
       /**
  
  
  
  1.4       +8 -1      xml-fop/src/java/org/apache/fop/fonts/SingleByteFont.java
  
  Index: SingleByteFont.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fonts/SingleByteFont.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SingleByteFont.java       27 Feb 2004 17:47:14 -0000      1.3
  +++ SingleByteFont.java       3 Apr 2004 13:31:40 -0000       1.4
  @@ -67,7 +67,7 @@
       }
   
       /**
  -     * @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);
  @@ -76,6 +76,13 @@
           } else {
               return '#';
           }
  +    }
  +    
  +    /**
  +     * @see org.apache.fop.fonts.Typeface#hasChar(char)
  +     */
  +    public boolean hasChar(char c) {
  +        return (mapping.mapChar(c) > 0);
       }
   
       /* ---- single byte font specific setters --- */
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to