public GsubWorkerForBengali(ICmapLookup cmapLookup, GsubData gsubData)
 {
     this.cmapLookup            = cmapLookup;
     this.gsubData              = gsubData;
     beforeHalfGlyphIds         = GetBeforeHalfGlyphIds();
     beforeAndAfterSpanGlyphIds = GetBeforeAndAfterSpanGlyphIds();
 }
Пример #2
0
        /**
         * Creates a new TrueType font for embedding.
         */
        public TrueTypeEmbedder(Document document, PdfDictionary dict, TrueTypeFont ttf, bool embedSubset)
        {
            this.document    = document;
            this.embedSubset = embedSubset;
            this.ttf         = ttf;
            fontDescriptor   = CreateFontDescriptor(ttf);

            if (!IsEmbeddingPermitted(ttf))
            {
                throw new IOException("This font does not permit embedding");
            }

            if (!embedSubset)
            {
                // full embedding
                PdfStream stream = new PdfStream(ttf.OriginalData);
                stream.Header[PdfName.Length]      =
                    stream.Header[PdfName.Length1] = PdfInteger.Get(ttf.OriginalDataSize);
                fontDescriptor.FontFile2           = new FontFile(document, stream);
            }
            dict[PdfName.Type]     = PdfName.Font;
            dict[PdfName.BaseFont] = new PdfName(ttf.Name);

            // choose a Unicode "cmap"
            cmapLookup = ttf.GetUnicodeCmapLookup();
        }
Пример #3
0
        internal PdfType0Font(PdfDirectObject baseObject) : base(baseObject)
        {
            gsubData   = DefaultGsubData.NO_DATA_FOUND;
            cmapLookup = null;

            var fonts = Dictionary.Resolve(PdfName.DescendantFonts);

            if (!(fonts is PdfArray))
            {
                throw new IOException("Missing descendant font array");
            }
            var descendantFonts = (PdfArray)fonts;

            if (descendantFonts.Count == 0)
            {
                throw new IOException("Descendant font array is empty");
            }
            var descendantFontDictBase = descendantFonts.Resolve(0);

            if (!(descendantFontDictBase is PdfDictionary))
            {
                throw new IOException("Missing descendant font dictionary");
            }
            ReadEncoding();
        }
Пример #4
0
        internal PdfType0Font(Document document, TrueTypeFont ttf, bool embedSubset, bool closeTTF, bool vertical)
            : base(document, new PdfDictionary())
        {
            if (vertical)
            {
                ttf.EnableVerticalSubstitutions();
            }

            gsubData   = ttf.GsubData;
            cmapLookup = ttf.GetUnicodeCmapLookup();

            embedder = new PdfCIDFontType2Embedder(document, Dictionary, ttf, embedSubset, this, vertical);
            CIDFont  = embedder.GetCIDFont();
            ReadEncoding();
            if (closeTTF)
            {
                if (embedSubset)
                {
                    this.ttf = ttf;
                    //TODO document.registerTrueTypeFontForClosing(ttf);
                }
                else
                {
                    // the TTF is fully loaded and it is safe to close the underlying data source
                    ttf.Dispose();
                }
            }
        }
Пример #5
0
        /**
         * Constructor.
         *
         * @param fontDictionary The font dictionary according to the PDF specification.
         * @param parent The parent font.
         * @param trueTypeFont The true type font used to create the parent font
         * @throws IOException
         */
        public CIDFontType2(PdfDirectObject fontDictionary, PdfType0Font parent, TrueTypeFont trueTypeFont)
            : base(fontDictionary, parent)
        {
            FontDescriptor fd = FontDescriptor;

            if (trueTypeFont != null)
            {
                ttf        = trueTypeFont;
                isEmbedded = true;
                isDamaged  = false;
            }
            else
            {
                bool         fontIsDamaged = false;
                TrueTypeFont ttfFont       = null;

                FontFile stream = null;
                if (fd != null)
                {
                    // Acrobat looks in FontFile too, even though it is not in the spec, see PDFBOX-2599
                    stream = fd.FontFile2 ?? fd.FontFile3 ?? fd.FontFile;
                }
                if (stream != null)
                {
                    try
                    {
                        // embedded OTF or TTF
                        OTFParser otfParser = new OTFParser(true);
                        ttfFont = otfParser.Parse((Bytes.Buffer)stream.BaseDataObject.ExtractBody(true), fd.FontName);

                        if (ttfFont is OpenTypeFont otf && otf.IsPostScript)
                        {
                            // PDFBOX-3344 contains PostScript outlines instead of TrueType
                            fontIsDamaged = true;
                            Debug.WriteLine($"warning: Found CFF/OTF but expected embedded TTF font {fd.FontName}");
                        }
                    }
                    catch (IOException e)
                    {
                        fontIsDamaged = true;
                        Debug.WriteLine($"warning: Could not read embedded OTF for font {BaseFont} {e}");
                    }
                }
                isEmbedded = ttfFont != null;
                isDamaged  = fontIsDamaged;

                if (ttfFont == null)
                {
                    ttfFont = FindFontOrSubstitute();
                }
                ttf = ttfFont;
            }
            cmapLookup = ttf.GetUnicodeCmapLookup(false);
            cid2gid    = ReadCIDToGIDMap();
        }
Пример #6
0
        public GsubWorker GetGsubWorker(ICmapLookup cmapLookup, GsubData gsubData)
        {
            switch (gsubData.Language)
            {
            case Language.beng:
            case Language.bng2:
                return(new GsubWorkerForBengali(cmapLookup, gsubData));

            default:
                throw new NotSupportedException(
                          "The language " + gsubData.Language + " is not yet supported");
            }
        }
Пример #7
0
        /**
         * Creates a subsetter for the given font.
         *
         * @param ttf the font to be subset
         * @param tables optional tables to keep if present
         */
        public TTFSubsetter(TrueTypeFont ttf, List <string> tables)
        {
            this.ttf        = ttf;
            this.keepTables = tables;

            uniToGID = new SortedDictionary <int, int>();
            glyphIds = new SortedSet <int>();

            // find the best Unicode cmap
            this.unicodeCmap = ttf.GetUnicodeCmapLookup();

            // always copy GID 0
            glyphIds.Add(0);
        }