class PDTrueTypeFontEmbedder extends TrueTypeEmbedder
{
    private final Encoding fontEncoding;

    /**
     * Creates a new TrueType font embedder for the given TTF as a PDTrueTypeFont.
     *
     * @param document The parent document
     * @param dict Font dictionary
     * @param ttf TrueType font
     * @param encoding The PostScript encoding vector to be used for embedding.
     * @throws IOException if the TTF could not be read
     */
    PDTrueTypeFontEmbedder(PDDocument document, COSDictionary dict, TrueTypeFont ttf,
                           Encoding encoding) throws IOException
    {
        super(document, dict, ttf, false);
        dict.setItem(COSName.SUBTYPE, COSName.TRUE_TYPE);
        
        GlyphList glyphList = GlyphList.getAdobeGlyphList();
        this.fontEncoding = encoding;
        dict.setItem(COSName.ENCODING, encoding.getCOSObject());
        fontDescriptor.setSymbolic(false);
        fontDescriptor.setNonSymbolic(true);
        
        // add the font descriptor
        dict.setItem(COSName.FONT_DESC, fontDescriptor);

        // set the glyph widths
        setWidths(dict, glyphList);
    }

    /**
     * Sets the glyph widths in the font dictionary.
     */
    private void setWidths(COSDictionary font, GlyphList glyphList) throws IOException
    {<FILL_FUNCTION_BODY>}

    /**
     * Returns the font's encoding.
     */
    public Encoding getFontEncoding()
    {
        return fontEncoding;
    }

    @Override
    protected void buildSubset(InputStream ttfSubset, String tag,
                            Map<Integer, Integer> gidToCid) throws IOException
    {
        // use PDType0Font instead
        throw new UnsupportedOperationException();
    }
}

        float scaling = 1000f / ttf.getHeader().getUnitsPerEm();
        HorizontalMetricsTable hmtx = ttf.getHorizontalMetrics();

        Map<Integer, String> codeToName = getFontEncoding().getCodeToNameMap();

        int firstChar = Collections.min(codeToName.keySet());
        int lastChar = Collections.max(codeToName.keySet());

        List<Integer> widths = new ArrayList<>(lastChar - firstChar + 1);
        for (int i = 0; i < lastChar - firstChar + 1; i++)
        {
            widths.add(0);
        }

        // 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 (Map.Entry<Integer, String> entry : codeToName.entrySet())
        {
            int code = entry.getKey();
            String name = entry.getValue();

            if (code >= firstChar && code <= lastChar)
            {
                String uni = glyphList.toUnicode(name);
                int charCode = uni.codePointAt(0);
                int gid = cmapLookup.getGlyphId(charCode);
                widths.set(entry.getKey() - firstChar,
                           Math.round(hmtx.getAdvanceWidth(gid) * scaling));
            }
        }

        font.setInt(COSName.FIRST_CHAR, firstChar);
        font.setInt(COSName.LAST_CHAR, lastChar);
        font.setItem(COSName.WIDTHS, COSArray.ofCOSIntegers(widths));
    
<methods>public void addGlyphIds(Set<java.lang.Integer>) ,public void addToSubset(int) ,public final void buildFontFile2(java.io.InputStream) throws java.io.IOException,public org.apache.pdfbox.pdmodel.font.PDFontDescriptor getFontDescriptor() ,public java.lang.String getTag(Map<java.lang.Integer,java.lang.Integer>) ,public boolean needsSubset() ,public void subset() throws java.io.IOException<variables>private static final java.lang.String BASE25,private static final int ITALIC,private static final int OBLIQUE,private final Set<java.lang.Integer> allGlyphIds,protected final non-sealed org.apache.fontbox.ttf.CmapLookup cmapLookup,private final non-sealed org.apache.pdfbox.pdmodel.PDDocument document,private final non-sealed boolean embedSubset,protected org.apache.pdfbox.pdmodel.font.PDFontDescriptor fontDescriptor,private final Set<java.lang.Integer> subsetCodePoints,protected org.apache.fontbox.ttf.TrueTypeFont ttf