Esempio n. 1
0
        private PDFObject GetWidths(GlyphTypeface glyphTypeface, IIndirectObjectCreator creator,
                                    IDictionary <int, ushort> cmap)
        {
            PDFArray widths = creator.CreateIndirectArray();
            IDictionary <ushort, double> advWidths = glyphTypeface.AdvanceWidths;

            for (char ch = (char)firstChar; ch <= lastChar; ch++)
            {
                int width = 0;
                if (subsetCharacters.Contains(ch))
                {
                    ushort gid;
                    if (cmap.TryGetValue((int)ch, out gid))
                    {
                        double widthDouble;
                        if (advWidths.TryGetValue(gid, out widthDouble))
                        {
                            width = (int)(1000 * widthDouble);
                        }
                    }
                }
                widths.Array.Add(new PDFInt(width));
            }

            return(widths);
        }
Esempio n. 2
0
        public override void CreatePDFData(IIndirectObjectCreator creator)
        {
            if (firstChar > lastChar)
            {
                firstChar = lastChar = 0;
            }

            PDFName                   postScriptFontName = CreatePostScriptFontName(_typeface);
            GlyphTypeface             glyphTypeface      = CreateGlyphTypeface();
            IDictionary <int, ushort> cmap = glyphTypeface.CharacterToGlyphMap;

            byte[] subsetData = CreateSubsetData(glyphTypeface, cmap);

            fontDescriptor = creator.CreateIndirectDictionary();
            fontDescriptor.Put("Type", new PDFName("FontDescriptor"));
            fontDescriptor.Put("FontName", postScriptFontName);
            fontDescriptor.Put("Flags", new PDFInt(IsSymbolic ? 4 : 32));
            fontDescriptor.Put("MissingWidth", new PDFInt(250));
            AddFontMetrics(fontDescriptor, glyphTypeface, subsetData);

            fontDictionary.Put("Type", new PDFName("Font"));
            fontDictionary.Put("Subtype", new PDFName("TrueType"));
            fontDictionary.Put("BaseFont", postScriptFontName);
            if (!IsSymbolic)
            {
                fontDictionary.Put("Encoding", new PDFName("WinAnsiEncoding"));
            }
            fontDictionary.Put("FontDescriptor", fontDescriptor);
            fontDictionary.Put("Widths", GetWidths(glyphTypeface, creator, cmap));
            fontDictionary.Put("FirstChar", new PDFInt(firstChar));
            fontDictionary.Put("LastChar", new PDFInt(lastChar));
            // fontDict.Put("ToUnicode", );

            fontStream = creator.CreateStream(PDFStream.Filter.Flate);
            fontDescriptor.Put("FontFile2", fontStream);
            fontStream.Data.Write(subsetData, 0, subsetData.Length);
            fontStream.StreamDictionary.Put("Length1", new PDFInt(subsetData.Length));
        }
Esempio n. 3
0
 public abstract void CreatePDFData(IIndirectObjectCreator creator);