Browse Source

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
pull/30/head
Jeremias Maerki 20 years ago
parent
commit
43d5504c6a

+ 4
- 0
src/codegen/font-file.xsl View 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>


+ 18
- 2
src/java/org/apache/fop/fonts/Font.java View 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];

+ 9
- 1
src/java/org/apache/fop/fonts/LazyFont.java View 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()
*/

+ 22
- 12
src/java/org/apache/fop/fonts/MultiByteFont.java View 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

+ 8
- 1
src/java/org/apache/fop/fonts/SingleByteFont.java View 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 --- */


+ 7
- 0
src/java/org/apache/fop/fonts/Typeface.java View 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

Loading…
Cancel
Save