summaryrefslogtreecommitdiff
path: root/platform/winrt/mupdfwinrt/muctx.h
blob: 16c44cd18aa551a4451578834b91022e8f045ad6 (plain)
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
#pragma once

#include <memory>
#include <functional>
#include <vector>
#include <windows.h>
#include "status.h"
#include "Cache.h"
extern "C" {
#include "mupdf/fitz.h"
#include "mupdf/pdf-tools.h"
}


#define MAX_SEARCH 500

enum { SVG_OUT, PNM_OUT, PCL_OUT, PWG_OUT };
enum { HTML = 0, XML, TEXT };

typedef struct point_s
{
	double X;
	double Y;
} point_t;

/* Links */
typedef struct document_link_s
{
	link_t type;
	point_t upper_left;
	point_t lower_right;
	std::unique_ptr<char[]> uri;
	int page_num;
} document_link_t;
#define sh_link std::shared_ptr<document_link_t>
#define sh_vector_link std::shared_ptr<std::vector<sh_link>>

/* Text Search */
typedef struct text_search_s
{
	point_t upper_left;
	point_t lower_right;
} text_search_t;
#define sh_text std::shared_ptr<text_search_t>
#define sh_vector_text std::shared_ptr<std::vector<sh_text>>

/* Content Results */
typedef struct content_s
{
	int  page;
	std::string string_orig;
	std::string string_margin;
} content_t;
#define sh_content std::shared_ptr<content_t>
#define sh_vector_content std::shared_ptr<std::vector<sh_content>>

#ifdef _WINRT_DLL
using namespace Windows::Storage::Streams;
using namespace Windows::Foundation;

typedef struct win_stream_struct_s
{
	IRandomAccessStream^ stream;
	unsigned char public_buffer[4096];
} win_stream_struct;
#else
typedef struct win_stream_struct_s
{
	char* stream;
} win_stream_struct;
#endif

class muctx
{
private:
	CRITICAL_SECTION mu_criticalsec[FZ_LOCK_MAX];
	win_stream_struct win_stream;
	fz_locks_context mu_locks;
	fz_context *mu_ctx;
	fz_document *mu_doc;
	fz_outline *mu_outline;
	fz_rect mu_hit_bbox[MAX_SEARCH];
	void FlattenOutline(fz_outline *outline, int level,
						sh_vector_content contents_vec);
	Cache *page_cache;
	Cache *annot_cache;

public:
	muctx(void);
	~muctx(void);
	void CleanUp(void);
	int GetPageCount();
	status_t InitializeContext();
	status_t RenderPage(int page_num, unsigned char *bmp_data, int bmp_width, 
						int bmp_height, float scale, bool flipy);
	status_t RenderPageMT(void *dlist, void *a_dlist, int page_width, int page_height,
							unsigned char *bmp_data, int bmp_width, int bmp_height,
							float scale, bool flipy, bool tile, point_t top_left,
							point_t bottom_right);
	fz_display_list* CreateDisplayList(int page_num, int *width, int *height);
	fz_display_list * CreateDisplayListText(int page_num, int *width,
		int *height, fz_text_page **text, int *length);
	fz_display_list * CreateAnnotationList(int page_num);
	int MeasurePage(int page_num, point_t *size);
	point_t MeasurePage(fz_page *page);
	unsigned int GetLinks(int page_num, sh_vector_link links_vec);
	void SetAA(int level);
	int GetTextSearch(int page_num, char* needle, sh_vector_text texts_vec);
	int GetContents(sh_vector_content contents_vec);
	std::string GetText(int page_num, int type);
	void ReleaseText(void *text);
	bool RequiresPassword(void);
	bool ApplyPassword(char* password);
	status_t SavePage(char *filename, int pagenum, int resolution, int type,
		bool append);

#ifdef _WINRT_DLL
	status_t InitializeStream(IRandomAccessStream^ readStream, char *ext);
#else
	status_t OpenDocument(char *filename);
#endif

};