}
}
+ public boolean hasChar(char c) {
+ return (mapping.mapChar(c) > 0);
+ }
+
}
</xsl:template>
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()
* 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) {
/**
* 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];
}
/**
- * @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()
*/
* @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);
}
/**
}
*/
- /**
- * @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
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
}
/**
- * @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);
return '#';
}
}
+
+ /**
+ * @see org.apache.fop.fonts.Typeface#hasChar(char)
+ */
+ public boolean hasChar(char c) {
+ return (mapping.mapChar(c) > 0);
+ }
/* ---- single byte font specific setters --- */
*/
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