~ubuntu-branches/ubuntu/trusty/pdfmod/trusty

« back to all changes in this revision

Viewing changes to lib/PdfSharp/PdfSharp.Pdf.Advanced/PdfImportedObjectTable.cs

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-06-18 03:44:46 UTC
  • Revision ID: james.westby@ubuntu.com-20100618034446-bogifrsscpayp361
Tags: upstream-0.8.3
ImportĀ upstreamĀ versionĀ 0.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#region PDFsharp - A .NET library for processing PDF
 
2
//
 
3
// Authors:
 
4
//   Stefan Lange (mailto:Stefan.Lange@pdfsharp.com)
 
5
//
 
6
// Copyright (c) 2005-2008 empira Software GmbH, Cologne (Germany)
 
7
//
 
8
// http://www.pdfsharp.com
 
9
// http://sourceforge.net/projects/pdfsharp
 
10
//
 
11
// Permission is hereby granted, free of charge, to any person obtaining a
 
12
// copy of this software and associated documentation files (the "Software"),
 
13
// to deal in the Software without restriction, including without limitation
 
14
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
15
// and/or sell copies of the Software, and to permit persons to whom the
 
16
// Software is furnished to do so, subject to the following conditions:
 
17
//
 
18
// The above copyright notice and this permission notice shall be included
 
19
// in all copies or substantial portions of the Software.
 
20
//
 
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
22
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
23
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 
24
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
25
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
26
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 
27
// DEALINGS IN THE SOFTWARE.
 
28
#endregion
 
29
 
 
30
using System;
 
31
using System.Diagnostics;
 
32
using System.Collections;
 
33
using System.Text;
 
34
using System.IO;
 
35
using PdfSharp.Pdf.Advanced;
 
36
using PdfSharp.Drawing;
 
37
using PdfSharp.Fonts.TrueType;
 
38
using PdfSharp.Internal;
 
39
 
 
40
namespace PdfSharp.Pdf.Advanced
 
41
{
 
42
  /// <summary>
 
43
  /// Represents the imported objects of an external document. Used to cache objects that are
 
44
  /// already imported when a PdfFormXObject is added to a page.
 
45
  /// </summary>
 
46
  internal sealed class PdfImportedObjectTable
 
47
  {
 
48
    /// <summary>
 
49
    /// Initializes a new instance of this class with the document the objects are imported from.
 
50
    /// </summary>
 
51
    public PdfImportedObjectTable(PdfDocument owner, PdfDocument externalDocument)
 
52
    {
 
53
      if (owner == null)
 
54
        throw new ArgumentNullException("owner");
 
55
      if (externalDocument == null)
 
56
        throw new ArgumentNullException("externalDocument");
 
57
      this.owner = owner;
 
58
      this.externalDocumentHandle = externalDocument.Handle;
 
59
      this.xObjects = new PdfFormXObject[externalDocument.PageCount];
 
60
    }
 
61
    PdfFormXObject[] xObjects;
 
62
 
 
63
    /// <summary>
 
64
    /// Gets the document this table belongs to.
 
65
    /// </summary>
 
66
    public PdfDocument Owner
 
67
    {
 
68
      get { return this.owner; }
 
69
    }
 
70
    PdfDocument owner;
 
71
 
 
72
    /// <summary>
 
73
    /// Gets the external document, or null, if the external document is garbage collected.
 
74
    /// </summary>
 
75
    public PdfDocument ExternalDocument
 
76
    {
 
77
      get 
 
78
      {
 
79
        if (this.externalDocumentHandle.IsAlive)
 
80
          return this.externalDocumentHandle.Target;
 
81
        return null; 
 
82
      }
 
83
    }
 
84
    PdfDocument.DocumentHandle externalDocumentHandle;
 
85
 
 
86
    public PdfFormXObject GetXObject(int pageNumber)
 
87
    {
 
88
      return this.xObjects[pageNumber - 1];
 
89
    }
 
90
 
 
91
    public void SetXObject(int pageNumber, PdfFormXObject xObject)
 
92
    {
 
93
      this.xObjects[pageNumber - 1] = xObject;
 
94
    }
 
95
 
 
96
    /// <summary>
 
97
    /// Indicates whether the specified object is already imported.
 
98
    /// </summary>
 
99
    public bool Contains(PdfObjectID externalID)
 
100
    {
 
101
      return this.externalIDs.Contains(externalID.ToString());
 
102
    }
 
103
 
 
104
    /// <summary>
 
105
    /// Adds a cloned object to this table.
 
106
    /// </summary>
 
107
    /// <param name="externalID">The object identifier in the forein object.</param>
 
108
    /// <param name="iref">The cross reference to the clone of the forein object, which belongs to
 
109
    /// this document. In general the clone has a different object identifier.</param>
 
110
    public void Add(PdfObjectID externalID, PdfReference iref)
 
111
    {
 
112
      this.externalIDs[externalID.ToString()] = iref;
 
113
    }
 
114
 
 
115
    /// <summary>
 
116
    /// Gets the cloned object that corresponds to the specified external identifier.
 
117
    /// </summary>
 
118
    public PdfReference this[PdfObjectID externalID]
 
119
    {
 
120
      get { return (PdfReference)this.externalIDs[externalID.ToString()]; }
 
121
    }
 
122
 
 
123
    /// <summary>
 
124
    /// Maps external object identifiers to cross reference entries of the importing document
 
125
    /// {PdfObjectID -> PdfReference}.
 
126
    /// </summary>
 
127
    Hashtable externalIDs = new Hashtable();
 
128
  }
 
129
}