* Finds the best encoding to use for a given Unicode code point.
* @param codePoint The Unicode code point to be tested.
* @return The best encoding to use for the code point.
*/
private Encoding getBestEncoding(final int codePoint) {
Encoding trialEncoding = null;
final Encoding internalEncoding = this.font.getInternalEncoding();
if (! (internalEncoding instanceof EncodingVector)) {
/* CMap encodings should be able to handle any character in the
* font's character set. */
return internalEncoding;
}
/* Cast checked above. */
final EncodingVector internalEncodingVector = (EncodingVector) internalEncoding;
if (internalEncodingVector.getPredefinedType() == EncodingVector.Predefined.SYMBOL
|| internalEncodingVector.getPredefinedType() == EncodingVector.Predefined.ZAPF_DINGBATS) {
/* The specialized encodings cover their entire character set. */
return internalEncoding;
}
if (internalEncodingVector.getPredefinedType() == EncodingVector.Predefined.STANDARD) {
final PsServer psServer = this.getFontConsumer().getFontServer().getPsServer();
/* Try WinAnsiEncoding. */
trialEncoding = psServer.getPredefinedEncoding(EncodingVector.Predefined.WIN_ANSI);
if (trialEncoding.canEncode(codePoint)) {
return trialEncoding;
}
/* Try the Central European encoding. */
trialEncoding = psServer.getPredefinedEncoding(EncodingVector.Predefined.CE);
if (trialEncoding.canEncode(codePoint)) {
return trialEncoding;
}
/* Try the FOray catch-all encoding. */
/* TODO: Move this encoding from the PS package to the Fonts package so that we don't have to address it
* by name. */
trialEncoding = psServer.getPredefinedEncoding("FOrayLatinExtraEncoding");
if (trialEncoding != null
&& trialEncoding.canEncode(codePoint)) {
return trialEncoding;
}
}
if (internalEncoding.canEncode(codePoint)) {
return internalEncoding;
}
return null;
}