示例#1
0
        /**
         * Processes a dictionary.
         * In case of font dictionaries, the dictionary is processed.
         */
        public void UnembedTTF(PdfDictionary dict)
        {
            // we ignore all dictionaries that aren't font dictionaries
            if (!dict.IsFont())
            {
                return;
            }
            // we only remove TTF fonts
            if (dict.GetAsDict(PdfName.FONTFILE2) != null)
            {
                return;
            }
            // check if a subset was used (in which case we remove the prefix)
            PdfName baseFont = dict.GetAsName(PdfName.BASEFONT);

            if (baseFont.GetBytes()[7] == '+')
            {
                baseFont = new PdfName(baseFont.ToString().Substring(8));
                dict.Put(PdfName.BASEFONT, baseFont);
            }
            // we check if there's a font descriptor
            PdfDictionary fontDescriptor = dict.GetAsDict(PdfName.FONTDESCRIPTOR);

            if (fontDescriptor == null)
            {
                return;
            }
            // is there is, we replace the fontname and remove the font file
            fontDescriptor.Put(PdfName.FONTNAME, baseFont);
            fontDescriptor.Remove(PdfName.FONTFILE2);
        }
示例#2
0
        static void unembed_font(PdfDictionary dict)
        {
            if (!dict.IsFont())
            {
                return;
            }

            if (dict.GetAsDict(PdfName.FONTFILE2) != null)
            {
                return;
            }

            var basefont = dict.GetAsName(PdfName.BASEFONT);

            if (basefont.GetBytes().Length > 7 && basefont.GetBytes()[7] == '+')
            {
                basefont = new PdfName(basefont.ToString().Substring(8));
                dict.Put(PdfName.BASEFONT, basefont);
            }

            var fd = dict.GetAsDict(PdfName.FONTDESCRIPTOR);

            if (fd == null)
            {
                return;
            }

            fd.Put(PdfName.FONTNAME, basefont);
            fd.Remove(PdfName.FONTFILE);
        }