Exemplo n.º 1
0
        /// <summary>
        /// Prepares the object to get saved.
        /// </summary>
        internal override void PrepareForSave()
        {
            base.PrepareForSave();

            if (FontEmbedding == PdfFontEmbedding.Always || FontEmbedding == PdfFontEmbedding.Automatic)
            {
                FontData subSet   = this.fontDescriptor.descriptor.fontData.CreateFontSubSet(this.cmapInfo.GlyphIndices, false);
                byte[]   fontData = subSet.Data;

#if DEBUG_
                TrueTypeFontSubSet fss        = new TrueTypeFontSubSet("", this.cmapInfo.descriptor.fontData, this.cmapInfo.GlyphIndices, 0, true, false);
                byte[]             fontSubSet = fss.Process();
                fss.CompareBytes(fontSubSet, fontProgram);
#endif
                PdfDictionary fontStream = new PdfDictionary(this.Owner);
                this.Owner.Internals.AddObject(fontStream);
                this.fontDescriptor.Elements[PdfFontDescriptor.Keys.FontFile2] = fontStream.Reference;

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

            //if (this.cmapInfo == null)
            //{
            FirstChar = 0;
            LastChar  = 255;
            PdfArray width = Widths;
            //width.Elements.Clear();
            for (int idx = 0; idx < 256; idx++)
            {
                width.Elements.Add(new PdfInteger(this.fontDescriptor.descriptor.widths[idx]));
            }
            //}
            //else
            //{
            //  FirstChar = (char)Math.Min(this.cmapInfo.MinChar, 255u);
            //  LastChar = (char)Math.Min(this.cmapInfo.MaxChar, 255u);

            //  PdfArray width = Widths;
            //  Debug.Assert(width.Elements.Count == 0);
            //  //width.Elements.Clear();
            //  for (int idx = FirstChar; idx <= LastChar; idx++)
            //  {
            //    int charWidth = 0;
            //    if (this.cmapInfo.Contains((char)idx))
            //      charWidth = this.fontDescriptor.descriptor.widths[idx];
            //    width.Elements.Add(new PdfInteger(charWidth));
            //  }
            //}
        }
Exemplo n.º 2
0
        /// <summary>
        /// Prepares the object to get saved.
        /// </summary>
        internal override void PrepareForSave()
        {
            base.PrepareForSave();

#if DEBUG
            if (this.fontDescriptor.descriptor.fontData.loca == null)
            {
                GetType();
            }
#endif
            // CID fonts must be always embedded. PDFsharp embedds automatically a subset.
            FontData subSet = null;
            if (this.fontDescriptor.descriptor.fontData.loca == null)
            {
                subSet = this.fontDescriptor.descriptor.fontData;
            }
            else
            {
                subSet = this.fontDescriptor.descriptor.fontData.CreateFontSubSet(this.cmapInfo.GlyphIndices, true);
            }
            byte[] fontData = subSet.Data;
#if DEBUG_
            TrueTypeFontSubSet fss        = new TrueTypeFontSubSet("", this.cmapInfo.descriptor.fontData, this.cmapInfo.GlyphIndices, 0, false, false);
            byte[]             fontSubSet = fss.Process();
            fss.CompareBytes(fontSubSet, fontProgram);
#endif
            PdfDictionary fontStream = new PdfDictionary(this.Owner);
            this.Owner.Internals.AddObject(fontStream);
            this.fontDescriptor.Elements[PdfFontDescriptor.Keys.FontFile2] = fontStream.Reference;

            fontStream.Elements["/Length1"] = new PdfInteger(fontData.Length);
            if (!this.Owner.Options.NoCompression)
            {
                fontData = Filtering.FlateDecode.Encode(fontData);
                fontStream.Elements["/Filter"] = new PdfName("/FlateDecode");
            }
            fontStream.Elements["/Length"] = new PdfInteger(fontData.Length);
            fontStream.CreateStream(fontData);
        }
Exemplo n.º 3
0
    /// <summary>
    /// Prepares the object to get saved.
    /// </summary>
    internal override void PrepareForSave()
    {
      base.PrepareForSave();

      if (FontEmbedding == PdfFontEmbedding.Always || FontEmbedding == PdfFontEmbedding.Automatic)
      {
        FontData subSet = this.fontDescriptor.descriptor.fontData.CreateFontSubSet(this.cmapInfo.GlyphIndices, false);
        byte[] fontData = subSet.Data;

#if DEBUG_
        TrueTypeFontSubSet fss = new TrueTypeFontSubSet("", this.cmapInfo.descriptor.fontData, this.cmapInfo.GlyphIndices, 0, true, false);
        byte[] fontSubSet = fss.Process();
        fss.CompareBytes(fontSubSet, fontProgram);
#endif
        PdfDictionary fontStream = new PdfDictionary(this.Owner);
        this.Owner.Internals.AddObject(fontStream);
        this.fontDescriptor.Elements[PdfFontDescriptor.Keys.FontFile2] = fontStream.Reference;

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

      //if (this.cmapInfo == null)
      //{
        FirstChar = 0;
        LastChar = 255;
        PdfArray width = Widths;
        //width.Elements.Clear();
        for (int idx = 0; idx < 256; idx++)
          width.Elements.Add(new PdfInteger(this.fontDescriptor.descriptor.widths[idx]));
      //}
      //else
      //{
      //  FirstChar = (char)Math.Min(this.cmapInfo.MinChar, 255u);
      //  LastChar = (char)Math.Min(this.cmapInfo.MaxChar, 255u);

      //  PdfArray width = Widths;
      //  Debug.Assert(width.Elements.Count == 0);
      //  //width.Elements.Clear();
      //  for (int idx = FirstChar; idx <= LastChar; idx++)
      //  {
      //    int charWidth = 0;
      //    if (this.cmapInfo.Contains((char)idx))
      //      charWidth = this.fontDescriptor.descriptor.widths[idx];
      //    width.Elements.Add(new PdfInteger(charWidth));
      //  }
      //}
    }
Exemplo n.º 4
0
    /// <summary>
    /// Prepares the object to get saved.
    /// </summary>
    internal override void PrepareForSave()
    {
      base.PrepareForSave();

#if DEBUG
      if (this.fontDescriptor.descriptor.fontData.loca == null)
      {
        GetType();
      }
#endif
      // CID fonts must be always embedded. PDFsharp embedds automatically a subset.
      FontData subSet = null;
      if (this.fontDescriptor.descriptor.fontData.loca == null)
        subSet = this.fontDescriptor.descriptor.fontData;
      else
        subSet = this.fontDescriptor.descriptor.fontData.CreateFontSubSet(this.cmapInfo.GlyphIndices, true);
      byte[] fontData = subSet.Data;
#if DEBUG_
      TrueTypeFontSubSet fss = new TrueTypeFontSubSet("", this.cmapInfo.descriptor.fontData, this.cmapInfo.GlyphIndices, 0, false, false);
      byte[] fontSubSet = fss.Process();
      fss.CompareBytes(fontSubSet, fontProgram);
#endif
      PdfDictionary fontStream = new PdfDictionary(this.Owner);
      this.Owner.Internals.AddObject(fontStream);
      this.fontDescriptor.Elements[PdfFontDescriptor.Keys.FontFile2] = fontStream.Reference;

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