Пример #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 initialize(Type1Parser parser)
        {
            PDFDictionary dict = GetDictionary();

            dict.AddItem("Type", new PDFName("Font"));
            dict.AddItem("Subtype", new PDFName("Type1"));
            dict.AddItem("BaseFont", new PDFName(parser.FontName));

            addEncoding(parser);
            addWidths(parser);
            addFontDescriptor(parser);
        }
Пример #3
0
        private static FontBase loadFromBuffer(byte[] buf, uint ttcSize)
        {
            if (TrueTypeFontFile.IsTrueTypeFont(buf) || TrueTypeFontFile.IsOpenTypeFont(buf))
            {
                FontBase font = new TrueTypeFont(buf, false, false, ttcSize);
                return(font);
            }
            if (Type1Parser.IsType1Font(buf))
            {
                FontBase font = new Type1Font(buf);
                return(font);
            }

            throw new PDFUnsupportFontFormatException();
        }
Пример #4
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);
        }
Пример #5
0
        internal Type1Font(byte[] buffer)
        {
            Type1Parser parser = new Type1Parser(new Reader(buffer));

            initialize(parser);
            initFontEncoding(parser);

            PDFDictionaryStream fontFile = new PDFDictionaryStream();

            fontFile.Dictionary.AddItem("Length1", new PDFNumber(buffer.Length));
            fontFile.Dictionary.AddItem("Length2", new PDFNumber(0));
            fontFile.Dictionary.AddItem("Length3", new PDFNumber(0));
            Stream stream = fontFile.GetStream();

            stream.Position = 0;
            stream.Write(buffer, 0, buffer.Length);

            ((PDFDictionary)GetDictionary()["FontDescriptor"]).AddItem("FontFile", fontFile);

            GetDictionary().Tag = this;
        }
Пример #6
0
        private void addEncoding(Type1Parser parser)
        {
            List <KeyValuePair <ushort, string> > charset = parser.GetCharset();

            if (charset == null)
            {
                GetDictionary().AddItem("Encoding", new PDFName(parser.Encoding));
            }
            else
            {
                PDFDictionary encoding = new PDFDictionary();
                encoding.AddItem("Type", new PDFName("Encoding"));
                PDFArray differences = new PDFArray();

                for (int i = 0; i < charset.Count; ++i)
                {
                    differences.AddItem(new PDFNumber(charset[i].Key));
                    differences.AddItem(new PDFName(charset[i].Value));
                }
                encoding.AddItem("Differences", differences);
                GetDictionary().AddItem("Encoding", encoding);
            }

            if (charset == null)
            {
                GetDictionary().AddItem("FirstChar", new PDFNumber(32));
                GetDictionary().AddItem("LastChar", new PDFNumber(255));
            }
            else
            {
                int firstChar = charset[0].Key;
                if (firstChar == 0)
                {
                    firstChar = charset[1].Key;
                }
                GetDictionary().AddItem("FirstChar", new PDFNumber(firstChar));
                GetDictionary().AddItem("LastChar", new PDFNumber(charset[charset.Count - 1].Key));
            }
        }
Пример #7
0
        private void addFontDescriptor(Type1Parser parser)
        {
            PDFDictionary dict = new PDFDictionary();

            dict.AddItem("Ascent", new PDFNumber(parser.FontBBox.Height));
            dict.AddItem("Descent", new PDFNumber(parser.FontBBox.Y));
            dict.AddItem("CapHeight", new PDFNumber(0));
            dict.AddItem("Flags", new PDFNumber(32));
            dict.AddItem("FontName", new PDFName(parser.FontName));
            dict.AddItem("ItalicAngle", new PDFNumber(parser.ItalicAngle));
            dict.AddItem("StemV", new PDFNumber(0));
            dict.AddItem("Type", new PDFName("FontDescriptor"));

            PDFArray bbox = new PDFArray();

            System.Drawing.Rectangle rect = parser.FontBBox;
            bbox.AddItem(new PDFNumber(rect.X));
            bbox.AddItem(new PDFNumber(rect.Y));
            bbox.AddItem(new PDFNumber(rect.Width));
            bbox.AddItem(new PDFNumber(rect.Height));
            dict.AddItem("FontBBox", bbox);

            GetDictionary().AddItem("FontDescriptor", dict);
        }