예제 #1
1
        /// <summary>
        /// Initializes a new instance of PdfTrueTypeFont from an XFont.
        /// </summary>
        public PdfTrueTypeFont(PdfDocument document, XFont font)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/TrueType");

            // TrueType with WinAnsiEncoding only.
            OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptorFor(font);
            FontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
            _fontOptions = font.PdfOptions;
            Debug.Assert(_fontOptions != null);

            //cmapInfo = new CMapInfo(null/*ttDescriptor*/);
            _cmapInfo = new CMapInfo(ttDescriptor);

            BaseFont = font.GlyphTypeface.GetBaseName();
     
            if (_fontOptions.FontEmbedding == PdfFontEmbedding.Always)
                BaseFont = PdfFont.CreateEmbeddedFontSubsetName(BaseFont);
            FontDescriptor.FontName = BaseFont;

            Debug.Assert(_fontOptions.FontEncoding == PdfFontEncoding.WinAnsi);
            if (!IsSymbolFont)
                Encoding = "/WinAnsiEncoding";

            Owner._irefTable.Add(FontDescriptor);
            Elements[Keys.FontDescriptor] = FontDescriptor.Reference;

            FontEncoding = font.PdfOptions.FontEncoding;
        }
예제 #2
0
        public PdfType0Font(PdfDocument document, XFont font, bool vertical)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/Type0");
            Elements.SetName(Keys.Encoding, vertical ? "/Identity-V" : "/Identity-H");

            OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptorFor(font);

            FontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
            _fontOptions   = font.PdfOptions;
            Debug.Assert(_fontOptions != null);

            _cmapInfo                = new CMapInfo(ttDescriptor);
            _descendantFont          = new PdfCIDFont(document, FontDescriptor, font);
            _descendantFont.CMapInfo = _cmapInfo;

            // Create ToUnicode map
            _toUnicode = new PdfToUnicodeMap(document, _cmapInfo);
            document.Internals.AddObject(_toUnicode);
            Elements.Add(Keys.ToUnicode, _toUnicode);

            BaseFont = font.GlyphTypeface.GetBaseName();
            // CID fonts are always embedded
            BaseFont = PdfFont.CreateEmbeddedFontSubsetName(BaseFont);

            FontDescriptor.FontName  = BaseFont;
            _descendantFont.BaseFont = BaseFont;

            PdfArray descendantFonts = new PdfArray(document);

            Owner._irefTable.Add(_descendantFont);
            descendantFonts.Elements.Add(_descendantFont.Reference);
            Elements[Keys.DescendantFonts] = descendantFonts;
        }
        /// <summary>
        /// Initializes a new instance of PdfTrueTypeFont from an XFont.
        /// </summary>
        public PdfTrueTypeFont(PdfDocument document, XFont font)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/TrueType");

            // TrueType with WinAnsiEncoding only.
            OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptorFor(font);

            FontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
            _fontOptions   = font.PdfOptions;
            Debug.Assert(_fontOptions != null);

            //cmapInfo = new CMapInfo(null/*ttDescriptor*/);
            _cmapInfo = new CMapInfo(ttDescriptor);

            BaseFont = font.GlyphTypeface.GetBaseName();

            if (_fontOptions.FontEmbedding == PdfFontEmbedding.Always)
            {
                BaseFont = PdfFont.CreateEmbeddedFontSubsetName(BaseFont);
            }
            FontDescriptor.FontName = BaseFont;

            Debug.Assert(_fontOptions.FontEncoding == PdfFontEncoding.WinAnsi);
            if (!IsSymbolFont)
            {
                Encoding = "/WinAnsiEncoding";
            }

            Owner._irefTable.Add(FontDescriptor);
            Elements[Keys.FontDescriptor] = FontDescriptor.Reference;

            FontEncoding = font.PdfOptions.FontEncoding;
        }
예제 #4
0
        public PdfType0Font(PdfDocument document, XFont font, bool vertical)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/Type0");
            Elements.SetName(Keys.Encoding, vertical ? "/Identity-V" : "/Identity-H");

            OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorStock.Global.CreateDescriptor(font);

            fontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
            fontOptions    = font.PdfOptions;
            Debug.Assert(fontOptions != null);

            cmapInfo                = new CMapInfo(ttDescriptor);
            descendantFont          = new PdfCIDFont(document, fontDescriptor, font);
            descendantFont.CMapInfo = cmapInfo;

            // Create ToUnicode map
            toUnicode = new PdfToUnicodeMap(document, cmapInfo);
            document.Internals.AddObject(toUnicode);
            Elements.Add(Keys.ToUnicode, toUnicode);

            //if (this.fontOptions.BaseFont != "")
            //{
            //  BaseFont = this.fontOptions.BaseFont;
            //}
            //else
            {
                BaseFont = font.Name.Replace(" ", "");
                switch (font.Style & (XFontStyle.Bold | XFontStyle.Italic))
                {
                case XFontStyle.Bold:
                    BaseFont += ",Bold";
                    break;

                case XFontStyle.Italic:
                    BaseFont += ",Italic";
                    break;

                case XFontStyle.Bold | XFontStyle.Italic:
                    BaseFont += ",BoldItalic";
                    break;
                }
            }
            // CID fonts are always embedded
            BaseFont = CreateEmbeddedFontSubsetName(BaseFont);

            fontDescriptor.FontName = BaseFont;
            descendantFont.BaseFont = BaseFont;

            PdfArray descendantFonts = new PdfArray(document);

            Owner.irefTable.Add(descendantFont);
            descendantFonts.Elements.Add(descendantFont.Reference);
            Elements[Keys.DescendantFonts] = descendantFonts;
        }
예제 #5
0
        public PdfType0Font(PdfDocument document, string idName, byte[] fontData, bool vertical)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/Type0");
            Elements.SetName(Keys.Encoding, vertical ? "/Identity-V" : "/Identity-H");

            OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorStock.Global.CreateDescriptor(idName, fontData);

            fontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
            fontOptions    = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
            Debug.Assert(fontOptions != null);

            cmapInfo                = new CMapInfo(ttDescriptor);
            descendantFont          = new PdfCIDFont(document, fontDescriptor, fontData);
            descendantFont.CMapInfo = cmapInfo;

            // Create ToUnicode map
            toUnicode = new PdfToUnicodeMap(document, cmapInfo);
            document.Internals.AddObject(toUnicode);
            Elements.Add(Keys.ToUnicode, toUnicode);

            BaseFont = ttDescriptor.FontName.Replace(" ", "");
            //switch (font.Style & (XFontStyle.Bold | XFontStyle.Italic))
            //{
            //  case XFontStyle.Bold:
            //    this.BaseFont += ",Bold";
            //    break;

            //  case XFontStyle.Italic:
            //    this.BaseFont += ",Italic";
            //    break;

            //  case XFontStyle.Bold | XFontStyle.Italic:
            //    this.BaseFont += ",BoldItalic";
            //    break;
            //}

            // CID fonts are always embedded
            if (!BaseFont.Contains("+")) // HACK in PdfType0Font
            {
                BaseFont = CreateEmbeddedFontSubsetName(BaseFont);
            }

            fontDescriptor.FontName = BaseFont;
            descendantFont.BaseFont = BaseFont;

            PdfArray descendantFonts = new PdfArray(document);

            Owner.irefTable.Add(descendantFont);
            descendantFonts.Elements.Add(descendantFont.Reference);
            Elements[Keys.DescendantFonts] = descendantFonts;
        }
예제 #6
0
    public PdfCIDFont(PdfDocument document, PdfFontDescriptor fontDescriptor, byte[] fontData)
      : base(document)
    {
      Elements.SetName(Keys.Type, "/Font");
      Elements.SetName(Keys.Subtype, "/CIDFontType2");
      PdfDictionary cid = new PdfDictionary();
      cid.Elements.SetString("/Ordering", "Identity");
      cid.Elements.SetString("/Registry", "Adobe");
      cid.Elements.SetInteger("/Supplement", 0);
      Elements.SetValue(Keys.CIDSystemInfo, cid);

      this.fontDescriptor = fontDescriptor;
      Owner.irefTable.Add(fontDescriptor);
      Elements[Keys.FontDescriptor] = fontDescriptor.Reference;

      FontEncoding = PdfFontEncoding.Unicode;
      FontEmbedding = PdfFontEmbedding.Always;
    }
예제 #7
0
        public PdfCIDFont(PdfDocument document, PdfFontDescriptor fontDescriptor, byte[] fontData)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/CIDFontType2");
            PdfDictionary cid = new PdfDictionary();
            cid.Elements.SetString("/Ordering", "Identity");
            cid.Elements.SetString("/Registry", "Adobe");
            cid.Elements.SetInteger("/Supplement", 0);
            Elements.SetValue(Keys.CIDSystemInfo, cid);

            FontDescriptor = fontDescriptor;
            // ReSharper disable once DoNotCallOverridableMethodsInConstructor
            Owner._irefTable.Add(fontDescriptor);
            Elements[Keys.FontDescriptor] = fontDescriptor.Reference;

            FontEncoding = PdfFontEncoding.Unicode;
        }
예제 #8
0
        public PdfCIDFont(PdfDocument document, PdfFontDescriptor fontDescriptor, byte[] fontData)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/CIDFontType2");
            PdfDictionary cid = new PdfDictionary();

            cid.Elements.SetString("/Ordering", "Identity");
            cid.Elements.SetString("/Registry", "Adobe");
            cid.Elements.SetInteger("/Supplement", 0);
            Elements.SetValue(Keys.CIDSystemInfo, cid);

            this.fontDescriptor = fontDescriptor;
            Owner.irefTable.Add(fontDescriptor);
            Elements[Keys.FontDescriptor] = fontDescriptor.Reference;

            FontEncoding  = PdfFontEncoding.Unicode;
            FontEmbedding = PdfFontEmbedding.Always;
        }
예제 #9
0
        public PdfCIDFont(PdfDocument document, PdfFontDescriptor fontDescriptor, byte[] fontData)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/CIDFontType2");
            PdfDictionary cid = new PdfDictionary();

            cid.Elements.SetString("/Ordering", "Identity");
            cid.Elements.SetString("/Registry", "Adobe");
            cid.Elements.SetInteger("/Supplement", 0);
            Elements.SetValue(Keys.CIDSystemInfo, cid);

            FontDescriptor = fontDescriptor;
            // ReSharper disable once DoNotCallOverridableMethodsInConstructor
            Owner._irefTable.Add(fontDescriptor);
            Elements[Keys.FontDescriptor] = fontDescriptor.Reference;

            FontEncoding = PdfFontEncoding.Unicode;
        }
예제 #10
0
        public PdfCIDFont(PdfDocument document, PdfFontDescriptor fontDescriptor, XFont font)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/CIDFontType2");
            PdfDictionary cid = new PdfDictionary();

            cid.Elements.SetString("/Ordering", "Identity");
            cid.Elements.SetString("/Registry", "Adobe");
            cid.Elements.SetInteger("/Supplement", 0);
            Elements.SetValue(Keys.CIDSystemInfo, cid);
            // @PDF/UA / 'Identity' or a stream must obviously be set for CIDFonts to satisfy PDF/UA requirements.
            Elements.SetName(Keys.CIDToGIDMap, "Identity");

            FontDescriptor = fontDescriptor;
            // ReSharper disable once DoNotCallOverridableMethodsInConstructor
            Owner._irefTable.Add(fontDescriptor);
            Elements[Keys.FontDescriptor] = fontDescriptor.Reference;

            FontEncoding = font.PdfOptions.FontEncoding;
        }
예제 #11
0
        public PdfType0Font(PdfDocument document, string idName, byte[] fontData, bool vertical)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/Type0");
            Elements.SetName(Keys.Encoding, vertical ? "/Identity-V" : "/Identity-H");

            OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptor(idName, fontData);

            FontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
            _fontOptions   = new XPdfFontOptions(PdfFontEncoding.Unicode);
            Debug.Assert(_fontOptions != null);

            _cmapInfo                = new CMapInfo(ttDescriptor);
            _descendantFont          = new PdfCIDFont(document, FontDescriptor, fontData);
            _descendantFont.CMapInfo = _cmapInfo;

            // Create ToUnicode map
            _toUnicode = new PdfToUnicodeMap(document, _cmapInfo);
            document.Internals.AddObject(_toUnicode);
            Elements.Add(Keys.ToUnicode, _toUnicode);

            //BaseFont = ttDescriptor.FontName.Replace(" ", "");
            BaseFont = ttDescriptor.FontName;

            // CID fonts are always embedded
            if (!BaseFont.Contains("+"))  // HACK in PdfType0Font
            {
                BaseFont = CreateEmbeddedFontSubsetName(BaseFont);
            }

            FontDescriptor.FontName  = BaseFont;
            _descendantFont.BaseFont = BaseFont;

            PdfArray descendantFonts = new PdfArray(document);

            Owner._irefTable.Add(_descendantFont);
            descendantFonts.Elements.Add(_descendantFont.Reference);
            Elements[Keys.DescendantFonts] = descendantFonts;
        }
예제 #12
0
    public PdfCIDFont(PdfDocument document, PdfFontDescriptor fontDescriptor, XFont font)
      : base(document)
    {
      Elements.SetName(Keys.Type, "/Font");
      Elements.SetName(Keys.Subtype, "/CIDFontType2");
      // This code is foobar. A PDF literal containing strings is not encrypted, but decryped when opening the PDF file. 
      //Elements.SetValue(Keys.CIDSystemInfo,
      //  new PdfLiteral("<< /Ordering (Identity) /Registry (Adobe) /Supplement 0>>"));
      // Must use real objects because PDF literals containing strings is not encrypted. That causes an error 
      // when the file is decrypted.
      PdfDictionary cid = new PdfDictionary();
      cid.Elements.SetString("/Ordering", "Identity");
      cid.Elements.SetString("/Registry", "Adobe");
      cid.Elements.SetInteger("/Supplement", 0);
      Elements.SetValue(Keys.CIDSystemInfo, cid);

      this.fontDescriptor = fontDescriptor;
      Owner.irefTable.Add(fontDescriptor);
      Elements[Keys.FontDescriptor] = fontDescriptor.Reference;

      FontEncoding = font.PdfOptions.FontEncoding;
      FontEmbedding = font.PdfOptions.FontEmbedding;
    }
예제 #13
0
        public PdfCIDFont(PdfDocument document, PdfFontDescriptor fontDescriptor, XFont font)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/CIDFontType2");
            // This code is foobar. A PDF literal containing strings is not encrypted, but decryped when opening the PDF file.
            //Elements.SetValue(Keys.CIDSystemInfo,
            //  new PdfLiteral("<< /Ordering (Identity) /Registry (Adobe) /Supplement 0>>"));
            // Must use real objects because PDF literals containing strings is not encrypted. That causes an error
            // when the file is decrypted.
            PdfDictionary cid = new PdfDictionary();

            cid.Elements.SetString("/Ordering", "Identity");
            cid.Elements.SetString("/Registry", "Adobe");
            cid.Elements.SetInteger("/Supplement", 0);
            Elements.SetValue(Keys.CIDSystemInfo, cid);

            this.fontDescriptor = fontDescriptor;
            Owner.irefTable.Add(fontDescriptor);
            Elements[Keys.FontDescriptor] = fontDescriptor.Reference;

            FontEncoding  = font.PdfOptions.FontEncoding;
            FontEmbedding = font.PdfOptions.FontEmbedding;
        }
예제 #14
0
        public PdfType0Font(PdfDocument document, string idName, byte[] fontData, bool vertical)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/Type0");
            Elements.SetName(Keys.Encoding, vertical ? "/Identity-V" : "/Identity-H");

            OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptor(idName, fontData);
            FontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
            _fontOptions = new XPdfFontOptions(PdfFontEncoding.Unicode);
            Debug.Assert(_fontOptions != null);

            _cmapInfo = new CMapInfo(ttDescriptor);
            _descendantFont = new PdfCIDFont(document, FontDescriptor, fontData);
            _descendantFont.CMapInfo = _cmapInfo;

            // Create ToUnicode map
            _toUnicode = new PdfToUnicodeMap(document, _cmapInfo);
            document.Internals.AddObject(_toUnicode);
            Elements.Add(Keys.ToUnicode, _toUnicode);

            //BaseFont = ttDescriptor.FontName.Replace(" ", "");
            BaseFont = ttDescriptor.FontName;

            // CID fonts are always embedded
            if (!BaseFont.Contains("+"))  // HACK in PdfType0Font
                BaseFont = CreateEmbeddedFontSubsetName(BaseFont);

            FontDescriptor.FontName = BaseFont;
            _descendantFont.BaseFont = BaseFont;

            PdfArray descendantFonts = new PdfArray(document);
            Owner._irefTable.Add(_descendantFont);
            descendantFonts.Elements.Add(_descendantFont.Reference);
            Elements[Keys.DescendantFonts] = descendantFonts;
        }
예제 #15
0
        /// <summary>
        /// Initializes a new instance of PdfTrueTypeFont from an XFont.
        /// </summary>
        public PdfTrueTypeFont(PdfDocument document, XFont font)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/TrueType");

            // TrueType with WinAnsiEncoding only
            OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorStock.Global.CreateDescriptor(font);

            fontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
            fontOptions    = font.PdfOptions;
            Debug.Assert(fontOptions != null);

            //this.cmapInfo = new CMapInfo(null/*ttDescriptor*/);
            cmapInfo = new CMapInfo(ttDescriptor);

            BaseFont = font.Name.Replace(" ", "");
            switch (font.Style & (XFontStyle.Bold | XFontStyle.Italic))
            {
            case XFontStyle.Bold:
                BaseFont += ",Bold";
                break;

            case XFontStyle.Italic:
                BaseFont += ",Italic";
                break;

            case XFontStyle.Bold | XFontStyle.Italic:
                BaseFont += ",BoldItalic";
                break;
            }
            if (fontOptions.FontEmbedding == PdfFontEmbedding.Always)
            {
                BaseFont = CreateEmbeddedFontSubsetName(BaseFont);
            }
            fontDescriptor.FontName = BaseFont;

            Debug.Assert(fontOptions.FontEncoding == PdfFontEncoding.WinAnsi);
            if (!IsSymbolFont)
            {
                Encoding = "/WinAnsiEncoding";
            }

            //        {
            //#if true
            //          throw new NotImplementedException("Specifying a font file is not yet supported.");
            //#else
            //          // Testcode
            //          FileStream stream = new FileStream("WAL____I.AFM", FileAccess.Read);
            //          int length = stream.Length;
            //          byte[] fontProgram = new byte[length];
            //          PdfDictionary fontStream = new PdfDictionary(this.Document);
            //          this.Document.xrefTable.Add(fontStream);
            //          this.fontDescriptor.Elements[PdfFontDescriptor.Keys.FontFile] = fontStream.XRef;

            //          fontStream.Elements["/Length1"] = new PdfInteger(fontProgram.Length);
            //          if (!this.Document.Options.NoCompression)
            //          {
            //            fontProgram = Filtering.FlateDecode.Encode(fontProgram);
            //            fontStream.Elements["/Filter"] = new PdfName("/FlateDecode");
            //          }
            //          fontStream.Elements["/Length"] = new PdfInteger(fontProgram.Length);
            //          fontStream.CreateStream(fontProgram);
            //#endif
            //        }

            Owner.irefTable.Add(fontDescriptor);
            Elements[Keys.FontDescriptor] = fontDescriptor.Reference;

            FontEncoding  = font.PdfOptions.FontEncoding;
            FontEmbedding = font.PdfOptions.FontEmbedding;
        }
예제 #16
-1
        public PdfType0Font(PdfDocument document, XFont font, bool vertical)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/Type0");
            Elements.SetName(Keys.Encoding, vertical ? "/Identity-V" : "/Identity-H");

            OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptorFor(font);
            FontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
            _fontOptions = font.PdfOptions;
            Debug.Assert(_fontOptions != null);

            _cmapInfo = new CMapInfo(ttDescriptor);
            _descendantFont = new PdfCIDFont(document, FontDescriptor, font);
            _descendantFont.CMapInfo = _cmapInfo;

            // Create ToUnicode map
            _toUnicode = new PdfToUnicodeMap(document, _cmapInfo);
            document.Internals.AddObject(_toUnicode);
            Elements.Add(Keys.ToUnicode, _toUnicode);

            BaseFont = font.GlyphTypeface.GetBaseName();
            // CID fonts are always embedded
            BaseFont = PdfFont.CreateEmbeddedFontSubsetName(BaseFont);

            FontDescriptor.FontName = BaseFont;
            _descendantFont.BaseFont = BaseFont;

            PdfArray descendantFonts = new PdfArray(document);
            Owner._irefTable.Add(_descendantFont);
            descendantFonts.Elements.Add(_descendantFont.Reference);
            Elements[Keys.DescendantFonts] = descendantFonts;
        }