diff options
author | Jeremias Maerki <jeremias@apache.org> | 2004-04-03 13:36:08 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2004-04-03 13:36:08 +0000 |
commit | a3ae5cb800f737b9b719e5a68a9f60aff46b2ba5 (patch) | |
tree | 479c9886c9780331828debb1b2e77136af159a52 /src | |
parent | 78e4c46bdf3e66a29a605c924d1969bb2211c5b8 (diff) | |
download | xmlgraphics-fop-a3ae5cb800f737b9b719e5a68a9f60aff46b2ba5.tar.gz xmlgraphics-fop-a3ae5cb800f737b9b719e5a68a9f60aff46b2ba5.zip |
New function to determine whether a particular character is available for this font.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197488 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/codegen/font-file.xsl | 4 | ||||
-rw-r--r-- | src/java/org/apache/fop/fonts/Font.java | 20 | ||||
-rw-r--r-- | src/java/org/apache/fop/fonts/LazyFont.java | 10 | ||||
-rw-r--r-- | src/java/org/apache/fop/fonts/MultiByteFont.java | 34 | ||||
-rw-r--r-- | src/java/org/apache/fop/fonts/SingleByteFont.java | 9 | ||||
-rw-r--r-- | src/java/org/apache/fop/fonts/Typeface.java | 7 |
6 files changed, 68 insertions, 16 deletions
diff --git a/src/codegen/font-file.xsl b/src/codegen/font-file.xsl index 09fbd2225..93f70cdff 100644 --- a/src/codegen/font-file.xsl +++ b/src/codegen/font-file.xsl @@ -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> diff --git a/src/java/org/apache/fop/fonts/Font.java b/src/java/org/apache/fop/fonts/Font.java index 9cce65d74..d2e58c775 100644 --- a/src/java/org/apache/fop/fonts/Font.java +++ b/src/java/org/apache/fop/fonts/Font.java @@ -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]; diff --git a/src/java/org/apache/fop/fonts/LazyFont.java b/src/java/org/apache/fop/fonts/LazyFont.java index b16f6b027..149b15c15 100644 --- a/src/java/org/apache/fop/fonts/LazyFont.java +++ b/src/java/org/apache/fop/fonts/LazyFont.java @@ -92,7 +92,7 @@ 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(); @@ -100,6 +100,14 @@ public class LazyFont extends Typeface implements FontDescriptor { } /** + * @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() */ public boolean isMultiByte() { diff --git a/src/java/org/apache/fop/fonts/MultiByteFont.java b/src/java/org/apache/fop/fonts/MultiByteFont.java index 62f5be961..566636c37 100644 --- a/src/java/org/apache/fop/fonts/MultiByteFont.java +++ b/src/java/org/apache/fop/fonts/MultiByteFont.java @@ -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 @@ -232,6 +234,14 @@ public class MultiByteFont extends CIDFont { } /** + * @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 */ diff --git a/src/java/org/apache/fop/fonts/SingleByteFont.java b/src/java/org/apache/fop/fonts/SingleByteFont.java index e28bc653a..26bba54a6 100644 --- a/src/java/org/apache/fop/fonts/SingleByteFont.java +++ b/src/java/org/apache/fop/fonts/SingleByteFont.java @@ -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 --- */ diff --git a/src/java/org/apache/fop/fonts/Typeface.java b/src/java/org/apache/fop/fonts/Typeface.java index f3e24cf98..f39a80d40 100644 --- a/src/java/org/apache/fop/fonts/Typeface.java +++ b/src/java/org/apache/fop/fonts/Typeface.java @@ -40,6 +40,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 */ |