Exemple #1
0
        public virtual void TrueTypeFontAndCmapConstructorTest()
        {
            TrueTypeFont ttf       = new TrueTypeFont(sourceFolder + "NotoSerif-Regular_v1.7.ttf");
            PdfType0Font type0Font = new PdfType0Font(ttf, PdfEncodings.IDENTITY_H);
            CMapEncoding cmap      = type0Font.GetCmap();

            NUnit.Framework.Assert.IsNotNull(cmap);
            NUnit.Framework.Assert.IsTrue(cmap.IsDirect());
            NUnit.Framework.Assert.IsFalse(cmap.HasUniMap());
            NUnit.Framework.Assert.IsNull(cmap.GetUniMapName());
            NUnit.Framework.Assert.AreEqual("Adobe", cmap.GetRegistry());
            NUnit.Framework.Assert.AreEqual("Identity", cmap.GetOrdering());
            NUnit.Framework.Assert.AreEqual(0, cmap.GetSupplement());
            NUnit.Framework.Assert.AreEqual(PdfEncodings.IDENTITY_H, cmap.GetCmapName());
        }
Exemple #2
0
        public virtual void DictionaryConstructorTest()
        {
            String        filePath    = sourceFolder + "documentWithType0Noto.pdf";
            PdfDocument   pdfDocument = new PdfDocument(new PdfReader(filePath));
            PdfDictionary fontDict    = pdfDocument.GetPage(1).GetResources().GetResource(PdfName.Font).GetAsDictionary(new
                                                                                                                        PdfName("F1"));
            PdfType0Font type0Font = new PdfType0Font(fontDict);
            CMapEncoding cmap      = type0Font.GetCmap();

            NUnit.Framework.Assert.IsNotNull(cmap);
            NUnit.Framework.Assert.IsTrue(cmap.IsDirect());
            NUnit.Framework.Assert.IsFalse(cmap.HasUniMap());
            NUnit.Framework.Assert.IsNull(cmap.GetUniMapName());
            NUnit.Framework.Assert.AreEqual("Adobe", cmap.GetRegistry());
            NUnit.Framework.Assert.AreEqual("Identity", cmap.GetOrdering());
            NUnit.Framework.Assert.AreEqual(0, cmap.GetSupplement());
            NUnit.Framework.Assert.AreEqual(PdfEncodings.IDENTITY_H, cmap.GetCmapName());
        }
        /// <summary>Generates the CIDFontType2 dictionary.</summary>
        /// <param name="fontDescriptor">the font descriptor dictionary</param>
        /// <param name="fontName">a name of the font</param>
        /// <param name="isType2">
        /// true, if the font is CIDFontType2 (TrueType glyphs),
        /// otherwise false, i.e. CIDFontType0 (Type1/CFF glyphs)
        /// </param>
        /// <returns>fully initialized CIDFont</returns>
        protected internal virtual PdfDictionary GetCidFont(PdfDictionary fontDescriptor, String fontName, bool isType2
                                                            )
        {
            PdfDictionary cidFont = new PdfDictionary();

            MarkObjectAsIndirect(cidFont);
            cidFont.Put(PdfName.Type, PdfName.Font);
            // sivan; cff
            cidFont.Put(PdfName.FontDescriptor, fontDescriptor);
            if (isType2)
            {
                cidFont.Put(PdfName.Subtype, PdfName.CIDFontType2);
                cidFont.Put(PdfName.CIDToGIDMap, PdfName.Identity);
            }
            else
            {
                cidFont.Put(PdfName.Subtype, PdfName.CIDFontType0);
            }
            cidFont.Put(PdfName.BaseFont, new PdfName(fontName));
            PdfDictionary cidInfo = new PdfDictionary();

            cidInfo.Put(PdfName.Registry, new PdfString(cmapEncoding.GetRegistry()));
            cidInfo.Put(PdfName.Ordering, new PdfString(cmapEncoding.GetOrdering()));
            cidInfo.Put(PdfName.Supplement, new PdfNumber(cmapEncoding.GetSupplement()));
            cidFont.Put(PdfName.CIDSystemInfo, cidInfo);
            if (!vertical)
            {
                cidFont.Put(PdfName.DW, new PdfNumber(FontProgram.DEFAULT_WIDTH));
                PdfObject widthsArray = GenerateWidthsArray();
                if (widthsArray != null)
                {
                    cidFont.Put(PdfName.W, widthsArray);
                }
            }
            else
            {
                //The implementation should be realized in DEVSIX-2730
                ILog logger = LogManager.GetLogger(typeof(iText.Kernel.Font.PdfType0Font));
                logger.Warn("Vertical writing has not been implemented yet.");
            }
            return(cidFont);
        }