Esempio n. 1
0
        internal PdfTrueTypeFont(TrueTypeFont ttf, String encoding, bool embedded)
            : base()
        {
            SetFontProgram(ttf);
            this.embedded = embedded;
            FontNames fontNames = ttf.GetFontNames();

            if (embedded && !fontNames.AllowEmbedding())
            {
                throw new PdfException("{0} cannot be embedded due to licensing restrictions.").SetMessageParams(fontNames
                                                                                                                 .GetFontName());
            }
            if ((encoding == null || encoding.Length == 0) && ttf.IsFontSpecific())
            {
                encoding = FontEncoding.FONT_SPECIFIC;
            }
            if (encoding != null && FontEncoding.FONT_SPECIFIC.ToLowerInvariant().Equals(encoding.ToLowerInvariant()))
            {
                fontEncoding = FontEncoding.CreateFontSpecificEncoding();
            }
            else
            {
                fontEncoding = FontEncoding.CreateFontEncoding(encoding);
            }
        }
Esempio n. 2
0
 public static FontEncoding CreateDocFontEncoding(PdfObject encoding, CMapToUnicode toUnicode)
 {
     if (encoding != null)
     {
         if (encoding.IsName())
         {
             return(FontEncoding.CreateFontEncoding(((PdfName)encoding).GetValue()));
         }
         else
         {
             if (encoding.IsDictionary())
             {
                 iText.Kernel.Font.DocFontEncoding fontEncoding = new iText.Kernel.Font.DocFontEncoding();
                 fontEncoding.differences = new String[256];
                 FillBaseEncoding(fontEncoding, ((PdfDictionary)encoding).GetAsName(PdfName.BaseEncoding));
                 FillDifferences(fontEncoding, ((PdfDictionary)encoding).GetAsArray(PdfName.Differences), toUnicode);
                 return(fontEncoding);
             }
         }
     }
     if (toUnicode != null)
     {
         iText.Kernel.Font.DocFontEncoding fontEncoding = new iText.Kernel.Font.DocFontEncoding();
         fontEncoding.differences = new String[256];
         FillDifferences(fontEncoding, toUnicode);
         return(fontEncoding);
     }
     else
     {
         return(FontEncoding.CreateFontSpecificEncoding());
     }
 }
Esempio n. 3
0
        internal PdfTrueTypeFont(TrueTypeFont ttf, String encoding, bool embedded)
            : base()
        {
            SetFontProgram(ttf);
            this.embedded = embedded;
            FontNames fontNames = ttf.GetFontNames();

            if (embedded && !fontNames.AllowEmbedding())
            {
                throw new PdfException("1.cannot.be.embedded.due.to.licensing.restrictions").SetMessageParams(fontNames.GetFontName
                                                                                                                  ());
            }
            if ((encoding == null || encoding.Length == 0) && ttf.IsFontSpecific())
            {
                encoding = FontEncoding.FONT_SPECIFIC;
            }
            if (encoding != null && FontEncoding.FONT_SPECIFIC.ToLower(System.Globalization.CultureInfo.InvariantCulture
                                                                       ).Equals(encoding.ToLower(System.Globalization.CultureInfo.InvariantCulture)))
            {
                fontEncoding = FontEncoding.CreateFontSpecificEncoding();
            }
            else
            {
                fontEncoding = FontEncoding.CreateFontEncoding(encoding);
            }
        }
Esempio n. 4
0
 internal PdfType1Font(Type1Font type1Font, String encoding, bool embedded)
     : base()
 {
     SetFontProgram(type1Font);
     this.embedded = embedded && !type1Font.IsBuiltInFont();
     if ((encoding == null || encoding.Length == 0) && type1Font.IsFontSpecific())
     {
         encoding = FontEncoding.FONT_SPECIFIC;
     }
     if (encoding != null && FontEncoding.FONT_SPECIFIC.ToLowerInvariant().Equals(encoding.ToLowerInvariant()))
     {
         fontEncoding = FontEncoding.CreateFontSpecificEncoding();
     }
     else
     {
         fontEncoding = FontEncoding.CreateFontEncoding(encoding);
     }
 }
        public virtual void AppendGlyphsWithSpecificEncodingTest()
        {
            PdfSimpleFont <FontProgram> fontToTest = new PdfSimpleFontTest.TestSimpleFont(FontEncoding.CreateFontSpecificEncoding
                                                                                              ());
            IList <Glyph> toAppend  = new List <Glyph>();
            int           processed = fontToTest.AppendGlyphs("te", 0, 1, toAppend);

            NUnit.Framework.Assert.AreEqual(2, processed);
            IList <Glyph> glyphs = new List <Glyph>();

            glyphs.Add(T_GLYPH_FONT_SPECIFIC);
            glyphs.Add(E_GLYPH_FONT_SPECIFIC);
            NUnit.Framework.Assert.AreEqual(glyphs, toAppend);
        }
        public virtual void CreateGlyphLineWithSpecificEncodingTest()
        {
            PdfSimpleFont <FontProgram> fontToTest = new PdfSimpleFontTest.TestSimpleFont(FontEncoding.CreateFontSpecificEncoding
                                                                                              ());
            GlyphLine     glyphLine = fontToTest.CreateGlyphLine("te");
            IList <Glyph> glyphs    = new List <Glyph>();

            glyphs.Add(T_GLYPH_FONT_SPECIFIC);
            glyphs.Add(E_GLYPH_FONT_SPECIFIC);
            GlyphLine expected = new GlyphLine(glyphs, 0, 2);

            NUnit.Framework.Assert.AreEqual(expected, glyphLine);
        }
        public virtual void WriteTextGlyphLineWithSpecificEncodingTest()
        {
            PdfSimpleFont <FontProgram> fontToTest = new PdfSimpleFontTest.TestSimpleFont(FontEncoding.CreateFontSpecificEncoding
                                                                                              ());
            IList <Glyph> glyphs = new List <Glyph>();

            glyphs.Add(T_GLYPH_FONT_SPECIFIC);
            glyphs.Add(E_GLYPH_FONT_SPECIFIC);
            GlyphLine    glyphLine = new GlyphLine(glyphs, 0, 2);
            MemoryStream bos       = new MemoryStream();

            using (PdfOutputStream pos = new PdfOutputStream(bos)) {
                fontToTest.WriteText(glyphLine, 0, 1, pos);
            }
            NUnit.Framework.Assert.AreEqual(new byte[] { OPEN_BRACKET_CODE, T_CODE, E_CODE, CLOSE_BRACKET_CODE }, bos.
                                            ToArray());
        }
        public virtual void ConvertGlyphToBytesWithSpecificEncodingTest()
        {
            PdfSimpleFont <FontProgram> fontToTest = new PdfSimpleFontTest.TestSimpleFont(FontEncoding.CreateFontSpecificEncoding
                                                                                              ());

            byte[] bytes = fontToTest.ConvertToBytes(E_GLYPH_FONT_SPECIFIC);
            NUnit.Framework.Assert.AreEqual(new byte[] { E_CODE }, bytes);
        }
        public virtual void ConvertGlyphLineToBytesWithSpecificEncodingTest()
        {
            PdfSimpleFont <FontProgram> fontToTest = new PdfSimpleFontTest.TestSimpleFont(FontEncoding.CreateFontSpecificEncoding
                                                                                              ());
            IList <Glyph> glyphs = new List <Glyph>();

            glyphs.Add(T_GLYPH_FONT_SPECIFIC);
            glyphs.Add(E_GLYPH_FONT_SPECIFIC);
            GlyphLine glyphLine = new GlyphLine(glyphs, 0, 2);

            byte[] bytes = fontToTest.ConvertToBytes(glyphLine);
            NUnit.Framework.Assert.AreEqual(new byte[] { T_CODE, E_CODE }, bytes);
        }