1
#region PDFsharp - A .NET library for processing PDF
4
// Stefan Lange (mailto:Stefan.Lange@pdfsharp.com)
6
// Copyright (c) 2005-2008 empira Software GmbH, Cologne (Germany)
8
// http://www.pdfsharp.com
9
// http://sourceforge.net/projects/pdfsharp
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:
18
// The above copyright notice and this permission notice shall be included
19
// in all copies or substantial portions of the Software.
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.
31
using System.Diagnostics;
32
using System.Collections;
35
using PdfSharp.Pdf.Advanced;
36
using PdfSharp.Drawing;
37
using PdfSharp.Fonts.TrueType;
38
using PdfSharp.Internal;
40
namespace PdfSharp.Pdf.Advanced
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.
46
internal sealed class PdfImportedObjectTable
49
/// Initializes a new instance of this class with the document the objects are imported from.
51
public PdfImportedObjectTable(PdfDocument owner, PdfDocument externalDocument)
54
throw new ArgumentNullException("owner");
55
if (externalDocument == null)
56
throw new ArgumentNullException("externalDocument");
58
this.externalDocumentHandle = externalDocument.Handle;
59
this.xObjects = new PdfFormXObject[externalDocument.PageCount];
61
PdfFormXObject[] xObjects;
64
/// Gets the document this table belongs to.
66
public PdfDocument Owner
68
get { return this.owner; }
73
/// Gets the external document, or null, if the external document is garbage collected.
75
public PdfDocument ExternalDocument
79
if (this.externalDocumentHandle.IsAlive)
80
return this.externalDocumentHandle.Target;
84
PdfDocument.DocumentHandle externalDocumentHandle;
86
public PdfFormXObject GetXObject(int pageNumber)
88
return this.xObjects[pageNumber - 1];
91
public void SetXObject(int pageNumber, PdfFormXObject xObject)
93
this.xObjects[pageNumber - 1] = xObject;
97
/// Indicates whether the specified object is already imported.
99
public bool Contains(PdfObjectID externalID)
101
return this.externalIDs.Contains(externalID.ToString());
105
/// Adds a cloned object to this table.
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)
112
this.externalIDs[externalID.ToString()] = iref;
116
/// Gets the cloned object that corresponds to the specified external identifier.
118
public PdfReference this[PdfObjectID externalID]
120
get { return (PdfReference)this.externalIDs[externalID.ToString()]; }
124
/// Maps external object identifiers to cross reference entries of the importing document
125
/// {PdfObjectID -> PdfReference}.
127
Hashtable externalIDs = new Hashtable();