~ubuntu-branches/ubuntu/oneiric/pdfmod/oneiric

« back to all changes in this revision

Viewing changes to lib/PdfSharp/PdfSharp.Pdf/PdfObject.cs

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-09-29 17:34:49 UTC
  • mfrom: (2.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100929173449-4ezagrzettatjk36
Tags: 0.9.0-1
* New upstream release
* debian/copyright: Document PdfSharp.SharpZipLib/*
* Drop all patches: committed upstream
* No change bump of Standards-Version from 3.8.4 to 3.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
// Authors:
4
4
//   Stefan Lange (mailto:Stefan.Lange@pdfsharp.com)
5
5
//
6
 
// Copyright (c) 2005-2008 empira Software GmbH, Cologne (Germany)
 
6
// Copyright (c) 2005-2009 empira Software GmbH, Cologne (Germany)
7
7
//
8
8
// http://www.pdfsharp.com
9
9
// http://sourceforge.net/projects/pdfsharp
56
56
    /// </summary>
57
57
    protected PdfObject(PdfDocument document)
58
58
    {
59
 
      this.Document = document;
 
59
      Document = document;
60
60
    }
61
61
 
62
62
    /// <summary>
64
64
    /// </summary>
65
65
    protected PdfObject(PdfObject obj)
66
66
    {
67
 
      this.Document = obj.Owner;
 
67
      Document = obj.Owner;
68
68
      // If the object that was transformed to an instance of a derived class was an indirect object
69
69
      // set the value of the reference to this.
70
70
      if (obj.iref != null)
71
71
        obj.iref.Value = this;
 
72
#if DEBUG
 
73
      else
 
74
      {
 
75
        // If this occurs it is an internal error
 
76
        Debug.Assert(false, "Object type transformation must not be done with direct objects");
 
77
      }
 
78
#endif
72
79
    }
73
80
 
74
81
    /// <summary>
90
97
      return obj;
91
98
    }
92
99
 
 
100
#if true_  // works, but may lead to other problems that I cannot assess
 
101
    /// <summary>
 
102
    /// Determines whether the specified object is equal to the current PdfObject.
 
103
    /// </summary>
 
104
    public override bool Equals(object obj)
 
105
    {
 
106
      if (obj is PdfObject)
 
107
      {
 
108
        PdfObject other = (PdfObject)obj;
 
109
        // Take object type transformation into account
 
110
        if (this.iref != null && other.iref != null)
 
111
        {
 
112
          Debug.Assert(this.iref.Value != null, "iref without value.");
 
113
          Debug.Assert(other.iref.Value != null, "iref without value.");
 
114
          return Object.ReferenceEquals(this.iref.Value, other.iref.Value);
 
115
        }
 
116
      }
 
117
      return base.Equals(obj);
 
118
    }
 
119
 
 
120
    public override int GetHashCode()
 
121
    {
 
122
      if (this.iref != null)
 
123
      {
 
124
        Debug.Assert(this.iref.Value != null, "iref without value.");
 
125
        return this.iref.GetHashCode();
 
126
      }
 
127
      return base.GetHashCode();
 
128
    }
 
129
#endif
 
130
 
93
131
    /// <summary>
94
132
    /// Sets the object and generation number
95
133
    /// Setting the object identifier makes this object an indirect object, i.e. the object gets
135
173
    {
136
174
      set
137
175
      {
138
 
        if (!Object.ReferenceEquals(this.document, value))
 
176
        if (!ReferenceEquals(this.document, value))
139
177
        {
140
178
          if (this.document != null)
141
179
            throw new InvalidOperationException("Cannot change document.");
150
188
    /// <summary>
151
189
    /// Indicates whether the object is an indirect object.
152
190
    /// </summary>
153
 
    internal bool IsIndirect
 
191
    public bool IsIndirect
154
192
    {
155
 
      // An object is an indirect object if and only if is has an indirect refernece value.
 
193
      // An object is an indirect object if and only if is has an indirect reference value.
156
194
      get { return this.iref != null; }
157
195
    }
158
196
 
159
197
    /// <summary>
 
198
    /// Gets the PdfInternals object of this document, that grants access to some internal structures
 
199
    /// which are not part of the public interface of PdfDocument.
 
200
    /// </summary>
 
201
    public PdfObjectInternals Internals
 
202
    {
 
203
      get
 
204
      {
 
205
        if (this.internals == null)
 
206
          this.internals = new PdfObjectInternals(this);
 
207
        return this.internals;
 
208
      }
 
209
    }
 
210
    PdfObjectInternals internals;
 
211
 
 
212
    /// <summary>
160
213
    /// When overridden in a derived class, prepares the object to get saved.
161
214
    /// </summary>
162
215
    internal virtual void PrepareForSave()
197
250
    /// </summary>
198
251
    internal int ObjectNumber
199
252
    {
200
 
      get { return this.ObjectID.ObjectNumber; }
 
253
      get { return ObjectID.ObjectNumber; }
201
254
    }
202
255
 
203
256
    /// <summary>
205
258
    /// </summary>
206
259
    internal int GenerationNumber
207
260
    {
208
 
      get { return this.ObjectID.GenerationNumber; }
 
261
      get { return ObjectID.GenerationNumber; }
209
262
    }
210
263
 
211
264
    ///// <summary>
212
265
    ///// Creates a deep copy of the specified value and its transitive closure and adds the
213
266
    ///// new objects to the specified owner document.
214
267
    ///// </summary>
215
 
    /// <param name="owner">The document that ownes the cloned objects.</param>
 
268
    /// <param name="owner">The document that owns the cloned objects.</param>
216
269
    /// <param name="externalObject">The root object to be cloned.</param>
217
270
    /// <returns>The clone of the root object</returns>
218
271
    internal static PdfObject DeepCopyClosure(PdfDocument owner, PdfObject externalObject)
284
337
    ///// Imports an object and its transitive closure to the specified document.
285
338
    ///// </summary>
286
339
    /// <param name="importedObjectTable">The imported object table of the owner for the external document.</param>
287
 
    /// <param name="owner">The document that ownes the cloned objects.</param>
 
340
    /// <param name="owner">The document that owns the cloned objects.</param>
288
341
    /// <param name="externalObject">The root object to be cloned.</param>
289
342
    /// <returns>The clone of the root object</returns>
290
343
    internal static PdfObject ImportClosure(PdfImportedObjectTable importedObjectTable, PdfDocument owner, PdfObject externalObject)
291
344
    {
292
 
      Debug.Assert(Object.ReferenceEquals(importedObjectTable.Owner, owner), "importedObjectTable does not belong to the owner.");
293
 
      Debug.Assert(Object.ReferenceEquals(importedObjectTable.ExternalDocument, externalObject.Owner),
 
345
      Debug.Assert(ReferenceEquals(importedObjectTable.Owner, owner), "importedObjectTable does not belong to the owner.");
 
346
      Debug.Assert(ReferenceEquals(importedObjectTable.ExternalDocument, externalObject.Owner),
294
347
        "The ExternalDocument of the importedObjectTable does not belong to the owner of object to be imported.");
295
348
 
296
349
      // Get transitive closure of external object
310
363
      for (int idx = 0; idx < count; idx++)
311
364
      {
312
365
        PdfObject obj = elements[idx];
313
 
        Debug.Assert(!Object.ReferenceEquals(obj.Owner, owner));
 
366
        Debug.Assert(!ReferenceEquals(obj.Owner, owner));
314
367
 
315
368
        if (importedObjectTable.Contains(obj.ObjectID))
316
369
        {
379
432
    /// </summary>
380
433
    internal static void FixUpObject(PdfImportedObjectTable iot, PdfDocument owner, PdfObject value)
381
434
    {
382
 
      Debug.Assert(Object.ReferenceEquals(iot.Owner, owner));
 
435
      Debug.Assert(ReferenceEquals(iot.Owner, owner));
383
436
 
384
437
      PdfDictionary dict;
385
438
      PdfArray array;