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;
33
using System.Globalization;
36
using PdfSharp.Drawing;
37
using PdfSharp.Internal;
39
namespace PdfSharp.Pdf.Advanced
42
/// Contains all used images of a document.
44
internal sealed class PdfImageTable : PdfResourceTable
47
/// Initializes a new instance of this class, which is a singleton for each document.
49
public PdfImageTable(PdfDocument document)
55
/// Gets a PdfImage from an XImage. If no PdfImage already exists, a new one is created.
57
public PdfImage GetImage(XImage image)
59
PdfImageTable.ImageSelector selector = image.selector;
62
selector = new ImageSelector(image);
63
image.selector = selector;
65
PdfImage pdfImage = this.images[selector] as PdfImage;
68
pdfImage = new PdfImage(this.owner, image);
69
//pdfImage.Document = this.document;
70
Debug.Assert(pdfImage.Owner == this.owner);
71
this.images[selector] = pdfImage;
72
//if (this.document.EarlyWrite)
74
// //pdfFont.Close(); delete
75
// //pdfFont.AssignObjID(ref this.document.ObjectID); // BUG just test code!!!!
76
// //pdfFont.WriteObject(null);
83
/// Map from ImageSelector to PdfImage.
85
Hashtable images = new Hashtable();
88
/// A collection of information that uniquely idendifies a particular PdfImage.
90
public class ImageSelector
93
/// Initializes a new instance of ImageSelector from an XImage.
95
public ImageSelector(XImage image)
97
// HACK: implement a way to identify images when they are reused
98
if (image.path == null)
99
image.path = Guid.NewGuid().ToString();
101
// HACK: just use full path to identify
102
this.path = image.path.ToLower(CultureInfo.InvariantCulture);
107
get { return this.path; }
108
set { this.path = value; }
112
public override bool Equals(object obj)
114
ImageSelector selector = obj as ImageSelector;
117
return this.path == selector.path; ;
120
public override int GetHashCode()
122
return this.path.GetHashCode();
b'\\ No newline at end of file'