示例#1
0
        /**
         * <summary>Loads the font data.</summary>
         */
        private void Load(
            )
        {
            try
            {
                ParseHeader();
                Index nameIndex    = Index.Parse(fontData);
                Index topDictIndex = Index.Parse(fontData);
                stringIndex = Index.Parse(fontData);
        #pragma warning disable 0219
                Index globalSubrIndex = Index.Parse(fontData);

                string fontName = ToString(nameIndex[0]);
        #pragma warning restore 0219
                Dict topDict = Dict.Parse(topDictIndex[0]);

                //      int encodingOffset = topDict.get(Dict.OperatorEnum.Encoding, 0, 0).intValue();
                //TODO: encoding

                int charsetOffset           = (int)topDict.Get(Dict.OperatorEnum.Charset, 0, 0);
                StandardCharsetEnum?charset = GetStandardCharset(charsetOffset);
                if (charset.HasValue)
                {
                    glyphIndexes = new Dictionary <int, int>(StandardCharsets[charset.Value]);
                }
                else
                {
                    glyphIndexes = new Dictionary <int, int>();

                    int   charStringsOffset = (int)topDict.Get(Dict.OperatorEnum.CharStrings, 0);
                    Index charStringsIndex  = Index.Parse(fontData, charStringsOffset);

                    fontData.Seek(charsetOffset);
                    int charsetFormat = fontData.ReadByte();
                    for (int index = 1, count = charStringsIndex.Count; index <= count;)
                    {
                        switch (charsetFormat)
                        {
                        case 0:
                            glyphIndexes[index++] = ToUnicode(fontData.ReadUnsignedShort());
                            break;

                        case 1:
                        case 2:
                        {
                            int first = fontData.ReadUnsignedShort();
                            int nLeft = (charsetFormat == 1 ? fontData.ReadByte() : fontData.ReadUnsignedShort());
                            for (int rangeItemIndex = first, rangeItemEndIndex = first + nLeft; rangeItemIndex <= rangeItemEndIndex; rangeItemIndex++)
                            {
                                glyphIndexes[index++] = ToUnicode(rangeItemIndex);
                            }
                        }
                        break;
                        }
                    }
                }
            }
            catch (Exception e)
            { throw e; }
        }
示例#2
0
 public static Index Parse(IInputStream stream)
 {
     byte[][] data = new byte[stream.ReadUnsignedShort()][];
     {
         int[] offsets = new int[data.Length + 1];
         int   offSize = stream.ReadByte();
         for (int index = 0, count = offsets.Length; index < count; index++)
         {
             offsets[index] = stream.ReadInt(offSize);
         }
         for (int index = 0, count = data.Length; index < count; index++)
         {
             stream.Read(data[index] = new byte[offsets[index + 1] - offsets[index]]);
         }
     }
     return(new Index(data));
 }