예제 #1
0
        private void initFontEncoding(Type1Parser parser)
        {
            List <KeyValuePair <ushort, string> > charset = parser.GetCharset();

            if (charset != null)
            {
                for (int i = 0; i < charset.Count; ++i)
                {
                    char c = GlyfNames.GetChar(charset[i].Value);
                    if (!_charset.ContainsKey(c))
                    {
                        _charset.Add(c, (byte)charset[i].Key);
                    }
                }
            }
            else
            {
                for (byte i = 32; i < 255; ++i)
                {
                    char ch = Encoding.GetChar(i);
                    if (!_charset.ContainsKey(ch))
                    {
                        _charset.Add(ch, i);
                    }
                }
            }
        }
예제 #2
0
        private void addWidths(Type1Parser parser)
        {
            List <KeyValuePair <ushort, string> > charset = parser.GetCharset();
            Dictionary <string, int> widths = parser.GetWidths();
            PDFArray w = new PDFArray();

            if (charset != null)
            {
                int i = 0;
                if (charset[0].Key == 0)
                {
                    ++i;
                }

                int tmp = 0;
                for (; i < charset.Count; ++i)
                {
                    if (!widths.TryGetValue(charset[i].Value, out tmp))
                    {
                        w.AddItem(new PDFNumber(0));
                    }
                    else
                    {
                        w.AddItem(new PDFNumber(tmp));
                    }
                }
            }
            else
            {
                int result = 0;
                for (byte i = 32; i < 255; ++i)
                {
                    char   c        = Encoding.GetChar(i);
                    string glyfName = GlyfNames.GetName(c);
                    if (!widths.TryGetValue(glyfName, out result))
                    {
                        w.AddItem(new PDFNumber(0));
                    }
                    else
                    {
                        w.AddItem(new PDFNumber(result));
                    }
                }
            }

            GetDictionary().AddItem("Widths", w);
        }
예제 #3
0
        internal FontEncoding(IPDFObject encoding)
        {
            if (encoding is PDFDictionary)
            {
                initBaseEncoding((encoding as PDFDictionary)["BaseEncoding"] as PDFName);
                PDFArray differences = (encoding as PDFDictionary)["Differences"] as PDFArray;

                if (differences != null)
                {
                    int current = 0;
                    for (int i = 0; i < differences.Count; ++i)
                    {
                        if (differences[i] is PDFNumber)
                        {
                            current = (int)(differences[i] as PDFNumber).GetValue();
                        }
                        else
                        {
                            if (differences[i] is PDFName)
                            {
                                string glyfName = (differences[i] as PDFName).GetValue();
                                if (current < _charset.Count)
                                {
                                    _charset[current] = GlyfNames.GetChar(glyfName);
                                }
                            }

                            current++;
                        }
                    }
                }
            }
            else
            {
                initBaseEncoding(encoding as PDFName);
            }
        }