lookupKey.setAliased(context.isAntiAliased());
lookupKey.setFontSize(context.getFontSize());
lookupKey.setIdentifier(rawRecord);
lookupKey.setFractional(context.isFractionalMetrics());
final FontMetrics cachedMetrics = (FontMetrics) knownMetrics.get(lookupKey);
if (cachedMetrics != null)
{
return cachedMetrics;
}
final CompoundFontIdentifier compoundFontIdentifier;
final FontIdentifier record;
if (rawRecord instanceof CompoundFontIdentifier)
{
compoundFontIdentifier = (CompoundFontIdentifier) rawRecord;
record = compoundFontIdentifier.getIdentifier();
}
else
{
record = rawRecord;
compoundFontIdentifier = null;
}
final String fontName;
final boolean bold;
final boolean italic;
if (record instanceof FontRecord)
{
final FontRecord fontRecord = (FontRecord) record;
fontName = fontRecord.getFamily().getFamilyName();
if (compoundFontIdentifier != null)
{
bold = compoundFontIdentifier.isBoldSpecified();
italic = compoundFontIdentifier.isItalicsSpecified();
}
else
{
bold = fontRecord.isBold();
italic = fontRecord.isItalic();
}
}
else if (record instanceof TrueTypeFontIdentifier)
{
final TrueTypeFontIdentifier ttfFontRecord = (TrueTypeFontIdentifier) record;
fontName = ttfFontRecord.getFontName();
if (compoundFontIdentifier != null)
{
bold = compoundFontIdentifier.isBoldSpecified();
italic = compoundFontIdentifier.isItalicsSpecified();
}
else
{
bold = false;
italic = false;
}
}
else
{
throw new IllegalArgumentException("Unknown font-identifier type encountered.");
}
final BaseFont baseFont = baseFontSupport.createBaseFont
(fontName, bold, italic, context.getEncoding(), context.isEmbedded());
final FontMetrics metrics = new BaseFontFontMetrics(baseFont, (float) context.getFontSize());
final FontKey key = new FontKey(rawRecord, context.isAntiAliased(),
context.isFractionalMetrics(), context.getFontSize());
knownMetrics.put(key, metrics);
return metrics;
}