//todo retval.setItalic
//todo retval.setAllCap
//todo retval.setSmallCap
//todo retval.setForceBold
HeaderTable header = ttf.getHeader();
PDRectangle rect = new PDRectangle();
rect.setLowerLeftX( header.getXMin() * 1000f/header.getUnitsPerEm() );
rect.setLowerLeftY( header.getYMin() * 1000f/header.getUnitsPerEm() );
rect.setUpperRightX( header.getXMax() * 1000f/header.getUnitsPerEm() );
rect.setUpperRightY( header.getYMax() * 1000f/header.getUnitsPerEm() );
fd.setFontBoundingBox( rect );
HorizontalHeaderTable hHeader = ttf.getHorizontalHeader();
fd.setAscent( hHeader.getAscender() * 1000f/header.getUnitsPerEm() );
fd.setDescent( hHeader.getDescender() * 1000f/header.getUnitsPerEm() );
GlyphTable glyphTable = ttf.getGlyph();
GlyphData[] glyphs = glyphTable.getGlyphs();
PostScriptTable ps = ttf.getPostScript();
fd.setFixedPitch( ps.getIsFixedPitch() > 0 );
fd.setItalicAngle( ps.getItalicAngle() );
String[] names = ps.getGlyphNames();
if( names != null )
{
for( int i=0; i<names.length; i++ )
{
//if we have a capital H then use that, otherwise use the
//tallest letter
if( names[i].equals( "H" ) )
{
fd.setCapHeight( (glyphs[i].getBoundingBox().getUpperRightY()* 1000f)/
header.getUnitsPerEm() );
}
if( names[i].equals( "x" ) )
{
fd.setXHeight( (glyphs[i].getBoundingBox().getUpperRightY()* 1000f)/header.getUnitsPerEm() );
}
}
}
//hmm there does not seem to be a clear definition for StemV,
//this is close enough and I am told it doesn't usually get used.
fd.setStemV( (fd.getFontBoundingBox().getWidth() * .13f) );
CMAPTable cmapTable = ttf.getCMAP();
CMAPEncodingEntry[] cmaps = cmapTable.getCmaps();
int[] glyphToCCode = null;
for( int i=0; i<cmaps.length; i++ )
{
if( cmaps[i].getPlatformId() == CMAPTable.PLATFORM_WINDOWS &&
cmaps[i].getPlatformEncodingId() == CMAPTable.ENCODING_UNICODE )
{
glyphToCCode = cmaps[i].getGlyphIdToCharacterCode();
}
}
int firstChar = 0;
int maxWidths = glyphToCCode.length;
HorizontalMetricsTable hMet = ttf.getHorizontalMetrics();
int[] widthValues = hMet.getAdvanceWidth();
List widths = new ArrayList(maxWidths);
Integer zero = new Integer( 250 );
for( int i=0; i<maxWidths; i++ )
{
widths.add( zero );
}
for( int i=0; i<widthValues.length; i++ )
{
if(glyphToCCode[i]-firstChar < widths.size() && glyphToCCode[i]-firstChar >= 0
&& widths.get( glyphToCCode[i]-firstChar) == zero )
{
widths.set( glyphToCCode[i]-firstChar,
new Integer( (int)(widthValues[i]* 1000f)/header.getUnitsPerEm() ) );
}
}
setWidths( widths );
setFirstChar( firstChar );
setLastChar( firstChar + widths.size()-1 );