protected override void OnLoad(
            )
        {
            LoadEncoding();

            // Glyph widths.
            {
                glyphWidths = new Dictionary <int, int>();
                PdfArray glyphWidthObjects = (PdfArray)CIDFontDictionary.Resolve(PdfName.W);
                if (glyphWidthObjects != null)
                {
                    for (IEnumerator <PdfDirectObject> iterator = glyphWidthObjects.GetEnumerator(); iterator.MoveNext();)
                    {
                        //TODO: this algorithm is valid only in case cid-to-gid mapping is identity (see cidtogid map)!!

                        /*
                         * NOTE: Font widths are grouped in one of the following formats [PDF:1.6:5.6.3]:
                         *  1. startCID [glyphWidth1 glyphWidth2 ... glyphWidthn]
                         *  2. startCID endCID glyphWidth
                         */
                        int startCID = ((PdfInteger)iterator.Current).RawValue;
                        iterator.MoveNext();
                        PdfDirectObject glyphWidthObject2 = iterator.Current;
                        if (glyphWidthObject2 is PdfArray) // Format 1: startCID [glyphWidth1 glyphWidth2 ... glyphWidthn].
                        {
                            int cID = startCID;
                            foreach (PdfDirectObject glyphWidthObject in (PdfArray)glyphWidthObject2)
                            {
                                glyphWidths[cID++] = ((PdfInteger)glyphWidthObject).RawValue;
                            }
                        }
                        else // Format 2: startCID endCID glyphWidth.
                        {
                            int endCID = ((PdfInteger)glyphWidthObject2).RawValue;
                            iterator.MoveNext();
                            int glyphWidth = ((PdfInteger)iterator.Current).RawValue;
                            for (int cID = startCID; cID <= endCID; cID++)
                            {
                                glyphWidths[cID] = glyphWidth;
                            }
                        }
                    }
                }
            }
            // Default glyph width.
            {
                PdfInteger defaultGlyphWidthObject = (PdfInteger)BaseDataObject[PdfName.W];
                defaultGlyphWidth = (defaultGlyphWidthObject == null ? 0 : defaultGlyphWidthObject.RawValue);
            }
        }
        protected void LoadEncoding(
            )
        {
            PdfDataObject encodingObject = BaseDataObject.Resolve(PdfName.Encoding);

            // CMap [PDF:1.6:5.6.4].
            IDictionary <ByteArray, int> cmap = CMap.Get(encodingObject);

            // 1. Unicode.
            if (codes == null)
            {
                codes = new BiDictionary <ByteArray, int>();
                if (encodingObject is PdfName &&
                    !(encodingObject.Equals(PdfName.IdentityH) ||
                      encodingObject.Equals(PdfName.IdentityV)))
                {
                    /*
                     * NOTE: According to [PDF:1.6:5.9.1], the fallback method to retrieve
                     * the character-code-to-Unicode mapping implies getting the UCS2 CMap
                     * (Unicode value to CID) corresponding to the font's one (character code to CID);
                     * CIDs are the bridge from character codes to Unicode values.
                     */
                    BiDictionary <ByteArray, int> ucs2CMap;
                    {
                        PdfDictionary cidSystemInfo = (PdfDictionary)CIDFontDictionary.Resolve(PdfName.CIDSystemInfo);
                        String        registry      = (String)((PdfTextString)cidSystemInfo[PdfName.Registry]).Value;
                        String        ordering      = (String)((PdfTextString)cidSystemInfo[PdfName.Ordering]).Value;
                        String        ucs2CMapName  = registry + "-" + ordering + "-" + "UCS2";
                        ucs2CMap = new BiDictionary <ByteArray, int>(CMap.Get(ucs2CMapName));
                    }
                    if (ucs2CMap.Count > 0)
                    {
                        foreach (KeyValuePair <ByteArray, int> cmapEntry in cmap)
                        {
                            codes[cmapEntry.Key] = ConvertUtils.ByteArrayToInt(ucs2CMap.GetKey(cmapEntry.Value).Data);
                        }
                    }
                }
                if (codes.Count == 0)
                {
                    /*
                     * NOTE: In case no clue is available to determine the Unicode resolution map,
                     * the font is considered symbolic and an identity map is synthesized instead.
                     */
                    symbolic = true;
                    foreach (KeyValuePair <ByteArray, int> cmapEntry in cmap)
                    {
                        codes[cmapEntry.Key] = ConvertUtils.ByteArrayToInt(cmapEntry.Key.Data);
                    }
                }
            }

            // 2. Glyph indexes.

            /*
             * TODO: gids map for glyph indexes as glyphIndexes is used to map cids!!!
             */
            // Character-code-to-CID mapping [PDF:1.6:5.6.4,5].
            glyphIndexes = new Dictionary <int, int>();
            foreach (KeyValuePair <ByteArray, int> cmapEntry in cmap)
            {
                if (!codes.ContainsKey(cmapEntry.Key))
                {
                    continue;
                }

                glyphIndexes[codes[cmapEntry.Key]] = cmapEntry.Value;
            }
        }