Ejemplo n.º 1
0
    /// <summary>
    /// Writes the specified value to the PDF stream.
    /// </summary>
    public void Write(PdfName value)
    {
      WriteSeparator(CharCat.Delimiter, '/');
      string name = value.Value;

      StringBuilder pdf = new StringBuilder("/");
      for (int idx = 1; idx < name.Length; idx++)
      {
        char ch = name[idx];
        Debug.Assert(ch < 256);
        if (ch > ' ')
          switch (ch)
          {
            // TODO: is this all?
            case '%':
            case '/':
            case '<':
            case '>':
            case '(':
            case ')':
            case '#':
              break;

            default:
              pdf.Append(name[idx]);
              continue;
          }
        pdf.AppendFormat("#{0:X2}", (int)name[idx]);
      }
      WriteRaw(pdf.ToString());
      this.lastCat = CharCat.Character;
    }
Ejemplo n.º 2
0
      internal int GetEnumFromName(string key, object defaultValue, bool create)
      {
        if (!(defaultValue is Enum))
          throw new ArgumentException("defaultValue");

        object obj = this[key];
        if (obj == null)
        {
          if (create)
            this[key] = new PdfName(defaultValue.ToString());
          return (int)defaultValue;
        }
        Debug.Assert(obj is Enum);
        return (int)Enum.Parse(defaultValue.GetType(), obj.ToString().Substring(1));
      }
Ejemplo n.º 3
0
    internal override void WriteObject(PdfWriter writer)
    {
      if (this.pdfRenderer != null)
      {
        // GetContent also disposes the underlying XGraphics object, if one exists
        //Stream = new PdfStream(PdfEncoders.RawEncoding.GetBytes(this.pdfRenderer.GetContent()), this);
        this.pdfRenderer.Close();
        Debug.Assert(this.pdfRenderer == null);
      }

      if (Stream != null)
      {
        if (this.Owner.Options.CompressContentStreams)
        {
          Stream.Value = Filtering.FlateDecode.Encode(Stream.Value);
          Elements["/Filter"] = new PdfName("/FlateDecode");
        }
        Elements.SetInteger("/Length", Stream.Length);
      }

      base.WriteObject(writer);
    }
Ejemplo n.º 4
0
      /// <summary>
      /// Sets the specified name value.
      /// If the value doesn't start with a slash, it is added automatically.
      /// </summary>
      public void SetName(string key, string value)
      {
        if (value == null)
          throw new ArgumentNullException("value");

        if (value.Length == 0 || value[0] != '/')
          value = "/" + value;

        this[key] = new PdfName(value);
      }
Ejemplo n.º 5
0
    /// <summary>
    /// Writes a key/value pair of this dictionary. This function is intended to be overridden
    /// in derived classes.
    /// </summary>
    internal virtual void WriteDictionaryElement(PdfWriter writer, PdfName key)
    {
      if (key == null)
        throw new ArgumentNullException("key");
      PdfItem item = Elements[key];
#if DEBUG
      // TODO: simplify PDFsharp
      if (item is PdfObject && ((PdfObject)item).IsIndirect)
      {
        // Replace an indirect object by its Reference
        item = ((PdfObject)item).Reference;
        Debug.Assert(false, "Check when we come here.");
      }
#endif
      key.WriteObject(writer);
      item.WriteObject(writer);
      writer.NewLine();
    }
Ejemplo n.º 6
0
      /// <summary>
      /// Gets or sets an entry in the dictionary identified by a PdfName object.
      /// </summary>
      public PdfItem this[PdfName key]
      {
        get { return (PdfItem)((IDictionary)this)[key.Value]; }
        set 
        {
          if (value == null)
            throw new ArgumentNullException("value");

#if DEBUG
          if (value is PdfDictionary)
          {
            PdfDictionary dict = (PdfDictionary)value;
            if (dict.stream != null)
              throw new ArgumentException("A dictionary with stream cannot be a direct value.");
          }
#endif

          PdfObject obj = value as PdfObject;
          if (obj != null && obj.IsIndirect)
          {
            ((IDictionary)this)[key] = obj.Reference;
            return;
          }
          ((IDictionary)this)[key.Value] = value; 
        }
      }
Ejemplo n.º 7
0
 /// <summary>
 /// Gets or sets an entry in the dictionary identified by a PdfName object.
 /// </summary>
 public PdfItem this[PdfName key]
 {
   get { return (PdfItem)((IDictionary)this)[key.Value]; }
   set { ((IDictionary)this)[key.Value] = value; }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Writes a key/value pair of this dictionary. This function is intended to be overridden
 /// in derived classes.
 /// </summary>
 internal virtual void WriteDictionaryElement(PdfWriter writer, PdfName key)
 {
   if (key == null)
     throw new ArgumentNullException("key");
   PdfItem item = Elements[key];
   key.WriteObject(writer);
   item.WriteObject(writer);
   writer.NewLine();
 }