//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();
CMAPEncodingEntry uniMap = null;
for( int i=0; i<cmaps.length; i++ )
{
if( cmaps[i].getPlatformId() == CMAPTable.PLATFORM_WINDOWS)
{
int platformEncoding = cmaps[i].getPlatformEncodingId();
if ( CMAPTable.ENCODING_UNICODE == platformEncoding )
{
uniMap = cmaps[i];
break;
}
}
}
Map<Integer, String> codeToName = this.getFontEncoding().getCodeToNameMap();
int firstChar = Collections.min(codeToName.keySet());
int lastChar = Collections.max(codeToName.keySet());
HorizontalMetricsTable hMet = ttf.getHorizontalMetrics();
int[] widthValues = hMet.getAdvanceWidth();
// some monospaced fonts provide only one value for the width
// instead of an array containing the same value for every glyphid
boolean isMonospaced = fd.isFixedPitch() || widthValues.length == 1;
int nWidths=lastChar-firstChar+1;
List<Float> widths = new ArrayList<Float>(nWidths);
// use the first width as default
// proportional fonts -> width of the .notdef character
// monospaced-fonts -> the first width
int defaultWidth = Math.round(widthValues[0] * scaling);
for (int i = 0; i < nWidths; i++)
{
widths.add((float)defaultWidth);
}
// Encoding singleton to have acces to the chglyph name to
// unicode cpoint point mapping of Adobe's glyphlist.txt
Encoding glyphlist = WinAnsiEncoding.INSTANCE;
// A character code is mapped to a glyph name via the provided
// font encoding. Afterwards, the glyph name is translated to a
// glyph ID.
// For details, see PDFReference16.pdf, Section 5.5.5, p.401
//
for (Entry<Integer, String> e : codeToName.entrySet())
{
String name = e.getValue();
// pdf code to unicode by glyph list.
String c = glyphlist.getCharacter(name);
int charCode = c.codePointAt(0);
int gid = uniMap.getGlyphId(charCode);
if (gid != 0)
{
if (isMonospaced)
{
widths.set(e.getKey().intValue() - firstChar, (float)defaultWidth);