-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDisplayList.cs
More file actions
137 lines (118 loc) · 4.59 KB
/
DisplayList.cs
File metadata and controls
137 lines (118 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using mupdf;
using System;
namespace MuPDF.NET
{
public class DisplayList : IDisposable
{
static DisplayList()
{
Utils.InitApp();
}
private FzDisplayList _nativeDisplayList;
private FzPage _fzPage = null;
/// <summary>
/// Contains the display list's mediabox.
/// </summary>
public Rect Rect
{
get
{
return new Rect(_nativeDisplayList.fz_bound_display_list());
}
}
public bool ThisOwn { get; set; }
/// <summary>
///
/// </summary>
/// <param name="rect">The page's rectangle.</param>
public DisplayList(Rect rect)
{
_nativeDisplayList = new FzDisplayList(rect.ToFzRect());
ThisOwn = true;
}
public DisplayList(DisplayList displayList)
{
_nativeDisplayList = displayList.ToFzDisplayList();
}
public DisplayList(PdfPage pdfPage, int annots = 1)
{
_fzPage = new FzPage(pdfPage);
if (annots != 0)
_nativeDisplayList = mupdf.mupdf.fz_new_display_list_from_page(_fzPage);
else
_nativeDisplayList = mupdf.mupdf.fz_new_display_list_from_page_contents(_fzPage);
}
public void Dispose()
{
if (_nativeDisplayList != null)
{
_nativeDisplayList.Dispose();
_nativeDisplayList = null;
ThisOwn = false;
}
if (_fzPage != null)
{
_fzPage.Dispose();
_fzPage = null;
ThisOwn = false;
}
}
/// <summary>
/// Returns native object
/// </summary>
/// <returns>FzDisplayList</returns>
public FzDisplayList ToFzDisplayList()
{
return _nativeDisplayList;
}
/// <summary>
/// Run the display list through a draw device and return a pixmap.
/// </summary>
/// <param name="matrix">matrix to use. Default is the identity matrix.</param>
/// <param name="colorSpace">the desired colorspace. Default is RGB.</param>
/// <param name="alpha">determine whether or not (0, default) to include a transparency channel.</param>
/// <param name="clip">restrict rendering to the intersection of this area with Rect.</param>
/// <returns>pixmap of the display list.</returns>
public Pixmap GetPixmap(Matrix matrix = null, ColorSpace colorSpace = null, int alpha = 0, Rect clip = null)
{
FzColorspace _colorSpace;
if (colorSpace != null)
_colorSpace = colorSpace.ToFzColorspace();
else
_colorSpace = new FzColorspace(mupdf.FzColorspace.Fixed.Fixed_RGB);
if (matrix == null)
matrix = new Matrix(1.0f, 1.0f);
Pixmap val = Utils.GetPixmapFromDisplaylist(_nativeDisplayList, matrix, _colorSpace, alpha, clip, null);
ThisOwn = true;
return val;
}
/// <summary>
/// Run the display list through a text device and return a text page.
/// </summary>
/// <param name="flags"control which information is parsed into a text page.</param>
/// <returns>text page of the display list.</returns>
public TextPage GetTextPage(int flags = 3)
{
FzStextOptions opts = new FzStextOptions();
opts.flags = flags;
FzStextPage textPage = new FzStextPage(_nativeDisplayList, opts);
TextPage ret = new TextPage(textPage);
ret.ThisOwn = true;
return ret;
}
/// <summary>
/// Run the display list through a device. The device will populate the display list with its "commands" (i.e. text extraction or image creation). The display list can later be used to "read" a page many times without having to re-interpret it from the document file.
/// </summary>
/// <param name="dw">Device</param>
/// <param name="matrix">Transformation matrix to apply to the display list contents.</param>
/// <param name="area">Only the part visible within this area will be considered when the list is run through the device.</param>
public void Run(DeviceWrapper dw, Matrix matrix, Rect area)
{
_nativeDisplayList.fz_run_display_list(
dw.ToFzDevice(),
matrix.ToFzMatrix(),
area.ToFzRect(),
new FzCookie());
}
}
}