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

« back to all changes in this revision

Viewing changes to lib/PdfSharp/PdfSharp.Pdf.Advanced/PdfImageTable.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.Globalization;
 
34
using System.Text;
 
35
using System.IO;
 
36
using PdfSharp.Drawing;
 
37
using PdfSharp.Internal;
 
38
 
 
39
namespace PdfSharp.Pdf.Advanced
 
40
{
 
41
  /// <summary>
 
42
  /// Contains all used images of a document.
 
43
  /// </summary>
 
44
  internal sealed class PdfImageTable : PdfResourceTable
 
45
  {
 
46
    /// <summary>
 
47
    /// Initializes a new instance of this class, which is a singleton for each document.
 
48
    /// </summary>
 
49
    public PdfImageTable(PdfDocument document)
 
50
      : base(document)
 
51
    {
 
52
    }
 
53
 
 
54
    /// <summary>
 
55
    /// Gets a PdfImage from an XImage. If no PdfImage already exists, a new one is created.
 
56
    /// </summary>
 
57
    public PdfImage GetImage(XImage image)
 
58
    {
 
59
      PdfImageTable.ImageSelector selector = image.selector;
 
60
      if (selector == null)
 
61
      {
 
62
        selector = new ImageSelector(image);
 
63
        image.selector = selector;
 
64
      }
 
65
      PdfImage pdfImage = this.images[selector] as PdfImage;
 
66
      if (pdfImage == null)
 
67
      {
 
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)
 
73
        //{
 
74
        //  //pdfFont.Close(); delete 
 
75
        //  //pdfFont.AssignObjID(ref this.document.ObjectID); // BUG just test code!!!!
 
76
        //  //pdfFont.WriteObject(null);
 
77
        //}
 
78
      }
 
79
      return pdfImage;
 
80
    }
 
81
 
 
82
    /// <summary>
 
83
    /// Map from ImageSelector to PdfImage.
 
84
    /// </summary>
 
85
    Hashtable images = new Hashtable();
 
86
 
 
87
    /// <summary>
 
88
    /// A collection of information that uniquely idendifies a particular PdfImage.
 
89
    /// </summary>
 
90
    public class ImageSelector
 
91
    {
 
92
      /// <summary>
 
93
      /// Initializes a new instance of ImageSelector from an XImage.
 
94
      /// </summary>
 
95
      public ImageSelector(XImage image)
 
96
      {
 
97
        // HACK: implement a way to identify images when they are reused
 
98
        if (image.path == null)
 
99
          image.path = Guid.NewGuid().ToString();
 
100
 
 
101
        // HACK: just use full path to identify
 
102
        this.path = image.path.ToLower(CultureInfo.InvariantCulture);
 
103
      }
 
104
 
 
105
      public string Path
 
106
      {
 
107
        get { return this.path; }
 
108
        set { this.path = value; }
 
109
      }
 
110
      string path;
 
111
 
 
112
      public override bool Equals(object obj)
 
113
      {
 
114
        ImageSelector selector = obj as ImageSelector;
 
115
        if (obj == null)
 
116
          return false;
 
117
        return this.path == selector.path; ;
 
118
      }
 
119
 
 
120
      public override int GetHashCode()
 
121
      {
 
122
        return this.path.GetHashCode();
 
123
      }
 
124
    }
 
125
  }
 
126
}
 
 
b'\\ No newline at end of file'