* For fonts that have been subsetted, only the characters that are
* included in the subset are returned.
* @see FontPdf#getWidths()
*/
public short[] getWidths() {
final FreeStandingFont fsf = this.getFreeStandingFont();
if (fsf == null) {
return null;
}
if (fsf.getFontComplexity() != Font.Complexity.SIMPLE) {
final Subset subset = this.fontUse.getSubset();
if (subset == null) {
return fsf.getWidths();
}
return getSubsetWidths();
}
final Encoding encoding = this.fontUse.getEncoding();
final CharSet charSet = fsf.getCharSet();
final int firstIndex = encoding.getFirstIndex();
final int lastIndex = encoding.getLastIndex();
final int size = lastIndex - firstIndex + 1;
final short[] widthsByFontIndex = new short[size];
for (int i = firstIndex; i <= lastIndex; i++) {
// Decode the character for this index
final int codePoint = encoding.decodeCharacter(i);
// Find the charSet index for that character.
final int charSetIndex = charSet.getIndex(codePoint);
if (charSetIndex < 0) {
continue;
}
// Find the width for that charSet index.
final short width = fsf.getWidths()[charSetIndex];
// Set the current array element to that width
widthsByFontIndex[i - firstIndex] = width;
}
return widthsByFontIndex;
}