19using System.Collections;
20using System.Collections.Generic;
42 internal readonly IntPtr NativePage;
57 internal Rectangle OriginalBounds {
get; }
65 internal MuPDFPage(MuPDFContext context, MuPDFDocument document,
int number)
69 throw new DocumentLockedException(
"A password is necessary to render the document!");
72 this.OwnerContext = context;
73 this.OwnerDocument = document;
74 this.PageNumber = number;
81 ExitCodes result = (
ExitCodes)NativeMethods.LoadPage(context.NativeContext, document.NativeDocument, number, ref NativePage, ref x, ref y, ref w, ref h);
83 this.Bounds =
new Rectangle(Math.Round(x * document.ImageXRes / 72.0 * 1000) / 1000, Math.Round(y * document.ImageYRes / 72.0 * 1000) / 1000, Math.Round(w * document.ImageXRes / 72.0 * 1000) / 1000, Math.Round(h * document.ImageYRes / 72.0 * 1000) / 1000);
84 this.OriginalBounds =
new Rectangle(x, y, w, h);
91 throw new MuPDFException(
"Cannot load page", result);
93 throw new MuPDFException(
"Cannot compute bounds", result);
95 throw new MuPDFException(
"Unknown error", result);
99 private bool disposedValue;
102 protected virtual void Dispose(
bool disposing)
106 NativeMethods.DisposePage(OwnerContext.NativeContext, NativePage);
107 disposedValue =
true;
114 if (NativePage != IntPtr.Zero)
116 Dispose(disposing:
false);
121 public void Dispose()
123 Dispose(disposing:
true);
124 GC.SuppressFinalize(
this);
151 public int Length {
get {
return Pages.Length; } }
156 public int Count {
get {
return Pages.Length; } }
167 if (index < 0 || index > Pages.Length)
169 throw new IndexOutOfRangeException();
172 if (Pages[index] ==
null)
174 Pages[index] =
new MuPDFPage(OwnerContext, OwnerDocument, index);
190 OwnerContext = context;
191 OwnerDocument = document;
197 for (
int i = 0; i < Pages.Length; i++)
199 if (Pages[i] ==
null)
201 Pages[i] =
new MuPDFPage(OwnerContext, OwnerDocument, i);
205 return ((IEnumerable<MuPDFPage>)Pages).GetEnumerator();
209 IEnumerator IEnumerable.GetEnumerator()
214 private bool disposedValue;
217 protected virtual void Dispose(
bool disposing)
223 for (
int i = 0; i < Pages.Length; i++)
229 disposedValue =
true;
234 public void Dispose()
236 Dispose(disposing:
true);
237 GC.SuppressFinalize(
this);
A wrapper around a MuPDF context object, which contains the exception stack and the resource cache st...
A wrapper over a MuPDF document object, which contains possibly multiple pages.
A lazy collection of MuPDFPages. Each page is loaded from the document as it is requested for the fir...
IEnumerator< MuPDFPage > GetEnumerator()
inheritdoc/>
int Length
The number of pages in the collection.
int Count
The number of pages in the collection.
A wrapper over a MuPDF page object, which contains information about the page's boundaries.
int PageNumber
The number of this page in the original document.
Rectangle Bounds
The page's bounds at 72 DPI. Read-only.
EncryptionState
Possible document encryption states.
ExitCodes
Exit codes returned by native methods describing various errors that can occur.