/// <summary>
        /// Maps a unicode to the index of the corresponding glyph.
        /// See OpenType spec "cmap - Character To Glyph Index Mapping Table / Format 4: Segment mapping to delta values"
        /// for details about this a little bit strange looking algorithm.
        /// </summary>
        public int CharCodeToGlyphIndex(char value)
        {
            try
            {
                CMap4 cmap4    = FontFace.cmap.cmap4;
                int   segCount = cmap4.segCountX2 / 2;
                int   seg;
                for (seg = 0; seg < segCount; seg++)
                {
                    if (value <= cmap4.endCount[seg])
                    {
                        break;
                    }
                }
                Debug.Assert(seg < segCount);

                if (value < cmap4.startCount[seg])
                {
                    return(0);
                }

                if (cmap4.idRangeOffs[seg] == 0)
                {
                    return((value + cmap4.idDelta[seg]) & 0xFFFF);
                }

                int idx = cmap4.idRangeOffs[seg] / 2 + (value - cmap4.startCount[seg]) - (segCount - seg);
                Debug.Assert(idx >= 0 && idx < cmap4.glyphCount);

                if (cmap4.glyphIdArray[idx] == 0)
                {
                    return(0);
                }

                return((cmap4.glyphIdArray[idx] + cmap4.idDelta[seg]) & 0xFFFF);
            }
            catch
            {
                GetType();
                throw;
            }
        }