Subversion Repositories Kolibri OS

Rev

Rev 4680 | Rev 5496 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4680 Rev 4696
1
#include
1
#include
2
#define _WIN32
2
#define _WIN32
3
#include "fitz.h"
3
#include "fitz.h"
4
#include "mupdf.h"
4
#include "mupdf.h"
5
#include "muxps.h"
5
#include "muxps.h"
6
#include "pdfapp.h"
6
#include "pdfapp.h"
-
 
7
#include "icons/allbtns.h"
7
 
8
 
8
 
9
 
9
 
10
 
10
static char Title[] = "some title";
11
static char Title[] = "some title";
11
static char * filename = "/hd0/1/yand.pdf";
12
static char * filename = "/hd0/1/yand.pdf";
12
static pdfapp_t gapp;
13
static pdfapp_t gapp;
13
 
14
 
14
void f65(unsigned x, unsigned y, unsigned w, unsigned h, char *d) //Вывод картинки
15
void f65(unsigned x, unsigned y, unsigned w, unsigned h, char *d) //Вывод картинки
15
{
16
{
16
asm ("nop"::"c"(w*65536+h), "d"(x*65536+y), "b"(d));
17
asm ("nop"::"c"(w*65536+h), "d"(x*65536+y), "b"(d));
17
asm ("xor %eax, %eax");
18
asm ("xor %eax, %eax");
18
asm ("movl %eax, %ebp");
19
asm ("movl %eax, %ebp");
19
asm ("pushl $32");
20
asm ("pushl $32");
20
asm ("popl %esi");
21
asm ("popl %esi");
21
asm ("int $0x40"::"a"(65));
22
asm ("int $0x40"::"a"(65));
22
 
23
 
23
}
24
}
24
 
25
 
25
	struct blit_call
26
	struct blit_call
26
{
27
{
27
   int dstx;       
28
   int dstx;       
28
   int dsty;
29
   int dsty;
29
   int w;
30
   int w;
30
   int h;
31
   int h;
31
 
32
 
32
   int srcx;
33
   int srcx;
33
   int srcy;
34
   int srcy;
34
   int srcw;
35
   int srcw;
35
   int srch;
36
   int srch;
36
 
37
 
37
   unsigned char *d;
38
   unsigned char *d;
38
   int   stride;
39
   int   stride;
39
};
40
};
40
 
41
 
41
void blit(int dstx, int dsty, int w, int h, int srcx, int srcy,int srcw, int srch, int stride, char *d) //Вызов сисфункции Blitter
42
void blit(int dstx, int dsty, int w, int h, int srcx, int srcy,int srcw, int srch, int stride, char *d) //Вызов сисфункции Blitter
42
{
43
{
43
 
44
 
44
struct blit_call image;
45
struct blit_call image;
45
	image.dstx=dstx;
46
	image.dstx=dstx;
46
	image.dsty=dsty;
47
	image.dsty=dsty;
47
	image.w=w;
48
	image.w=w;
48
	image.h=h;
49
	image.h=h;
49
	image.srcx=srcx;
50
	image.srcx=srcx;
50
	image.srcy=srcy;
51
	image.srcy=srcy;
51
	image.srcw=srcw;
52
	image.srcw=srcw;
52
	image.srch=srch;
53
	image.srch=srch;
53
	image.stride=stride;
54
	image.stride=stride;
54
	image.d=d;
55
	image.d=d;
55
	
56
	
56
 
57
 
57
asm ("int $0x40"::"a"(73),"b"(0),"c"(&image));
58
asm ("int $0x40"::"a"(73),"b"(0),"c"(&image));
58
 
59
 
59
}
60
}
60
 
61
 
61
void winwarn(pdfapp_t *app, char *msg)
62
void winwarn(pdfapp_t *app, char *msg)
62
{
63
{
63
	fprintf(stderr, "mupdf: %s\n", msg);
64
	fprintf(stderr, "mupdf: %s\n", msg);
64
}
65
}
65
 
66
 
66
void winerror(pdfapp_t *app, fz_error error)
67
void winerror(pdfapp_t *app, fz_error error)
67
{
68
{
68
	fz_catch(error, "aborting");
69
	fz_catch(error, "aborting");
69
	exit(1);
70
	exit(1);
70
}
71
}
71
 
72
 
72
char *winpassword(pdfapp_t *app, char *filename)
73
char *winpassword(pdfapp_t *app, char *filename)
73
{
74
{
74
	char *r = "";
75
	char *r = "";
75
	return r;
76
	return r;
76
}
77
}
77
 
78
 
78
 
79
 
79
void wincursor(pdfapp_t *app, int curs)
80
void wincursor(pdfapp_t *app, int curs)
80
{
81
{
81
	
82
	
82
}
83
}
83
 
84
 
84
void wintitle(pdfapp_t *app, char *s)
85
void wintitle(pdfapp_t *app, char *s)
85
{
86
{
86
 
87
 
87
sprintf(Title,"uPDF: %s", s);	
88
sprintf(Title,"uPDF: %s", s);	
88
}
89
}
89
 
90
 
90
void winhelp(pdfapp_t *app)
91
void winhelp(pdfapp_t *app)
91
{
92
{
92
	
93
	
93
}
94
}
94
 
95
 
95
void winresize(pdfapp_t *app, int w, int h)
96
void winresize(pdfapp_t *app, int w, int h)
96
{
97
{
97
	//here should be something!!!
98
	//here should be something!!!
98
	
99
	
99
	
100
	
100
}
101
}
101
 
102
 
102
 
103
 
103
void windocopy(pdfapp_t *app)
104
void windocopy(pdfapp_t *app)
104
{
105
{
105
}
106
}
106
 
107
 
107
void winreloadfile(pdfapp_t *app)
108
void winreloadfile(pdfapp_t *app)
108
{
109
{
109
	pdfapp_close(app);
110
	pdfapp_close(app);
110
 
111
 
111
 
112
 
112
	pdfapp_open(app, filename, 0, 1);
113
	pdfapp_open(app, filename, 0, 1);
113
}
114
}
114
 
115
 
115
void winopenuri(pdfapp_t *app, char *buf)
116
void winopenuri(pdfapp_t *app, char *buf)
116
{
117
{
117
	/* here can be browser!
118
	/* here can be browser!
118
	char *browser = getenv("BROWSER");
119
	char *browser = getenv("BROWSER");
119
	if (!browser)
120
	if (!browser)
120
		browser = "open";
121
		browser = "open";
121
	if (fork() == 0)
122
	if (fork() == 0)
122
		execlp(browser, browser, buf, (char*)0);
123
		execlp(browser, browser, buf, (char*)0);
123
		* */
124
		* */
124
		
125
		
125
}
126
}
126
 
127
 
127
 
128
 
128
 
129
 
129
void winclose(pdfapp_t *app)
130
void winclose(pdfapp_t *app)
130
{
131
{
131
	pdfapp_close(&gapp);
132
	pdfapp_close(&gapp);
132
	__menuet__sys_exit();
133
	__menuet__sys_exit();
133
}
134
}
134
 
135
 
135
void kol_paint_bar(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c)
136
void kol_paint_bar(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c)
136
{
137
{
137
asm ("int $0x40"::"a"(13), "b"(x*65536+w), "c"(y*65536+h), "d"(c));
138
asm ("int $0x40"::"a"(13), "b"(x*65536+w), "c"(y*65536+h), "d"(c));
138
}
139
}
139
 
140
 
140
 
141
 
141
static void winblit(pdfapp_t *app)
142
static void winblit(pdfapp_t *app)
142
{
143
{
143
	char yoba[32];
144
	char yoba[32];
144
	int x0 = gapp.panx;
145
	int x0 = gapp.panx;
145
	int y0 = gapp.pany;
146
	int y0 = gapp.pany;
146
	int x1 = gapp.panx + gapp.image->w;
147
	int x1 = gapp.panx + gapp.image->w;
147
	int y1 = gapp.pany + gapp.image->h;
148
	int y1 = gapp.pany + gapp.image->h;
148
__menuet__debug_out(" Window blit\n");
149
__menuet__debug_out(" Window blit\n");
-
 
150
__menuet__bar(0,0,598,370,0xababab); //background of pics
149
/*
151
/*
150
	XSetForeground(xdpy, xgc, xbgcolor.pixel);
152
	XSetForeground(xdpy, xgc, xbgcolor.pixel);
151
	fillrect(0, 0, x0, gapp.winh);
153
	fillrect(0, 0, x0, gapp.winh);
152
	fillrect(x1, 0, gapp.winw - x1, gapp.winh);
154
	fillrect(x1, 0, gapp.winw - x1, gapp.winh);
153
	fillrect(0, 0, gapp.winw, y0);
155
	fillrect(0, 0, gapp.winw, y0);
154
	fillrect(0, y1, gapp.winw, gapp.winh - y1);*/
156
	fillrect(0, y1, gapp.winw, gapp.winh - y1);*/
155
	if (gapp.image->h-y0 > 0) {
157
	if (gapp.image->h-y0 > 0) {
156
	kol_paint_bar(0, gapp.image->h-y0, 590, 368, 0xEFEFEF);
158
	kol_paint_bar(0, gapp.image->h-y0, 590, 368, 0xEFEFEF);
157
}
159
}
158
	/*kol_paint_bar(x1, 0, gapp.winw - x1, gapp.winh, 0x00FF00);
160
	/*kol_paint_bar(x1, 0, gapp.winw - x1, gapp.winh, 0x00FF00);
159
	kol_paint_bar(0, 0, gapp.winw, y0, 0xFF0000);
161
	kol_paint_bar(0, 0, gapp.winw, y0, 0xFF0000);
160
	kol_paint_bar(0, y1, gapp.winw, gapp.winh - y1, 0xFFFF);*/
162
	kol_paint_bar(0, y1, gapp.winw, gapp.winh - y1, 0xFFFF);*/
161
	
163
	
162
 
164
 
163
	/*XSetForeground(xdpy, xgc, xshcolor.pixel);
165
	/*XSetForeground(xdpy, xgc, xshcolor.pixel);
164
	fillrect(x0+2, y1, gapp.image->w, 2);
166
	fillrect(x0+2, y1, gapp.image->w, 2);
165
	fillrect(x1, y0+2, 2, gapp.image->h);*/
167
	fillrect(x1, y0+2, 2, gapp.image->h);*/
166
sprintf (yoba, "%d x %d, %d x %d \n", gapp.image->w, gapp.image->h, gapp.winw, gapp.winh);
168
sprintf (yoba, "%d x %d, %d x %d \n", gapp.image->w, gapp.image->h, gapp.winw, gapp.winh);
167
__menuet__debug_out(yoba);
169
__menuet__debug_out(yoba);
168
 
170
 
169
 
171
 
170
	if (gapp.image->n == 4)
172
	if (gapp.image->n == 4)
171
		/*ximage_blit(xwin, xgc,
173
		/*ximage_blit(xwin, xgc,
172
			x0, y0,
174
			x0, y0,
173
			gapp.image->samples,
175
			gapp.image->samples,
174
			0, 0,
176
			0, 0,
175
			gapp.image->w,
177
			gapp.image->w,
176
			gapp.image->h,
178
			gapp.image->h,
177
			gapp.image->w * gapp.image->n);*/
179
			gapp.image->w * gapp.image->n);*/
178
		//	f65(x0,y0+32,gapp.image->w,gapp.image->h,gapp.image->samples);
180
		//	f65(x0,y0+32,gapp.image->w,gapp.image->h,gapp.image->samples);
179
	 		 
181
	 		 
180
		 	blit(6, 24, 588, 368, x0, y0,gapp.image->w, gapp.image->h, gapp.image->w * gapp.image->n, gapp.image->samples);
182
		 	blit(6, 24, 588, 368, x0, y0,gapp.image->w, gapp.image->h, gapp.image->w * gapp.image->n, gapp.image->samples);
181
		 	
183
		 	
182
			
184
			
183
	else if (gapp.image->n == 2)
185
	else if (gapp.image->n == 2)
184
	{
186
	{
185
		int i = gapp.image->w*gapp.image->h;
187
		int i = gapp.image->w*gapp.image->h;
186
		unsigned char *color = malloc(i*4);
188
		unsigned char *color = malloc(i*4);
187
		if (color != NULL)
189
		if (color != NULL)
188
		{
190
		{
189
			unsigned char *s = gapp.image->samples;
191
			unsigned char *s = gapp.image->samples;
190
			unsigned char *d = color;
192
			unsigned char *d = color;
191
			for (; i > 0 ; i--)
193
			for (; i > 0 ; i--)
192
			{
194
			{
193
				d[2] = d[1] = d[0] = *s++;
195
				d[2] = d[1] = d[0] = *s++;
194
				d[3] = *s++;
196
				d[3] = *s++;
195
				d += 4;
197
				d += 4;
196
			}
198
			}
197
			/*ximage_blit(xwin, xgc,
199
			/*ximage_blit(xwin, xgc,
198
				x0, y0,
200
				x0, y0,
199
				color,
201
				color,
200
				0, 0,
202
				0, 0,
201
				gapp.image->w,
203
				gapp.image->w,
202
				gapp.image->h,
204
				gapp.image->h,
203
				gapp.image->w * 4); */
205
				gapp.image->w * 4); */
204
			//f65(x0,y0,gapp.image->w,gapp.image->h,color);
206
			//f65(x0,y0,gapp.image->w,gapp.image->h,color);
205
			blit(6, 24, 588, 368, x0, y0,gapp.image->w, gapp.image->h, gapp.image->w * 4, color);
207
			blit(6, 24, 588, 368, x0, y0,gapp.image->w, gapp.image->h, gapp.image->w * 4, color);
206
			free(color);
208
			free(color);
207
		}
209
		}
208
	}
210
	}
209
 
211
 
210
 
-
 
211
 __menuet__bar(0,0,600,20,0xFFFFFF);
212
 
212
 __menuet__make_button(0,0,40,20,7,0x404040FF); //(posirion x, position y, width, height, id, color) 
213
 __menuet__bar(0,0,598,34,0xe1e1e1); // bar on the top (buttons holder)
213
 __menuet__write_text(5,4,0xFFFFFF,"Open",4);
214
 __menuet__bar(590,0,5,400,0xe1e1e1); // sidebar for scrolling 
214
 
215
 
215
 __menuet__make_button(550,0,20,20,2,0x404040FF); //prev page
216
 __menuet__make_button(8,5,26,24,7,0xe1e1e1); //(posirion x, position y, width, height, id, color) 
216
 __menuet__write_text(555,3,0xFFFFFF,"<",1);
217
 __menuet__putimage(8,5,26,24,folder.pixel_data); 
217
 
218
   
218
 __menuet__make_button(570,0,20,20,3,0x404040FF); //nex page 
219
 __menuet__make_button(42,5,26,24,6,0xe1e1e1); //magnify -
219
 __menuet__write_text(575,3,0xFFFFFF,">",1);
-
 
220
 
-
 
221
 __menuet__make_button(40,0,20,20,4,0x404040FF); //show help
220
 __menuet__putimage(42,5,26,24,minus.pixel_data); 
222
 __menuet__write_text(45,3,0xFFFFFF,"?",1);
221
 
223
 
222
 __menuet__make_button(68,5,26,24,5,0xe1e1e1); //magnify + 
224
 __menuet__make_button(60,0,20,20,5,0x404040FF); //magnify + 
223
 __menuet__putimage(68,5,26,24,plus.pixel_data); 
225
 __menuet__write_text(65,3,0xFFFFFF,"+",1);
224
 
226
 
225
 
227
 __menuet__make_button(80,0,20,20,6,0x404040FF); //magnify -
226
/* __menuet__make_button(100,0,20,20,10,0xe1e1e1); // rotate + 15 deg
228
 __menuet__write_text(85,3,0xFFFFFF,"-",1);
227
 __menuet__write_text(105,3,0xFFFFFF,"p",1);
229
 
228
 
230
 __menuet__make_button(570,20,20,20,8,0x404040FF); // move up
229
 __menuet__make_button(120,0,20,20,11,0xe1e1e1); // rotate - 15 deg
-
 
230
 __menuet__write_text(125,3,0xFFFFFF,"q",1); */
-
 
231
 
-
 
232
 __menuet__make_button(500,5,26,24,4,0xe1e1e1); //show help
-
 
233
 __menuet__putimage(500,5,26,24,help.pixel_data); 
-
 
234
 
-
 
235
 __menuet__make_button(534,5,24,24,2,0xe1e1e1); //prev page
231
 __menuet__write_text(575,3,0xFFFFFF,"^",1);
236
 __menuet__putimage(534,5,24,24,prev.pixel_data); 
232
 
237
 
233
 __menuet__make_button(570,360,20,20,9,0x404040FF); // move down
238
 __menuet__make_button(558,5,24,24,3,0xe1e1e1); //nex page 
234
 __menuet__write_text(575,363,0xFFFFFF,"v",1);
239
 __menuet__putimage(558,5,24,24,next.pixel_data); 
235
 
240
 
236
 __menuet__make_button(100,0,20,20,10,0x404040FF); // rotate + 15 deg
241
  __menuet__make_button(573,34,17,17,8,0xe1e1e1); // move up
237
 __menuet__write_text(105,3,0xFFFFFF,"cw",1);
242
 __menuet__putimage(573,34,17,17,scrup.pixel_data); 
238
 
243
 
239
 __menuet__make_button(120,0,20,20,11,0x404040FF); // rotate - 15 deg
244
 __menuet__make_button(573,363,17,17,9,0xe1e1e1); // move down
240
 __menuet__write_text(125,3,0xFFFFFF,"ccw",1); 
245
 __menuet__putimage(573,363,17,17,scrdn.pixel_data); 
241
 
246
 
242
 
247
 
243
}
248
}
244
 
249
 
245
void paint(void)
250
void paint(void)
246
{
251
{
247
 __menuet__window_redraw(1);
252
 __menuet__window_redraw(1);
248
 //__menuet__define_window(10,10,600,400,0x64CFCFCF,0x800000FF,Title);
253
 //__menuet__define_window(10,10,600,400,0x64CFCFCF,0x800000FF,Title);
249
 __menuet__define_window(10,10,600,400,0x73CFCFCF,0x800000FF,Title);
254
 __menuet__define_window(10,10,600,400,0x73CFCFCF,0x800000FF,Title);
250
 __menuet__bar(0,0,600,400,0xFFFFFF);
255
 __menuet__bar(0,0,600,400,0xFFFFFF);
251
 winblit(&gapp);
256
 winblit(&gapp);
252
 __menuet__window_redraw(2);
257
 __menuet__window_redraw(2);
253
 }
258
 }
254
 
259
 
255
void winrepaint(pdfapp_t *app)
260
void winrepaint(pdfapp_t *app)
256
{
261
{
257
	winblit(&gapp);
262
	winblit(&gapp);
258
}
263
}
259
 
264
 
260
void winrepaintsearch(pdfapp_t *app)
265
void winrepaintsearch(pdfapp_t *app)
261
{
266
{
262
	paint();
267
	paint();
263
	//search!
268
	//search!
264
}
269
}
265
 
270
 
266
 
271
 
267
int main (void)
272
int main (void)
268
{
273
{
-
 
274
	
269
	char* original_command_line = *(char**)0x1C;
275
	char* original_command_line = *(char**)0x1C;
270
	__menuet__debug_out(original_command_line);
276
	__menuet__debug_out(original_command_line);
271
	
277
	
272
	char buf[128];
278
	char buf[128];
273
	int resolution = 72;
279
	int resolution = 72;
274
		int pageno = 1;
280
		int pageno = 1;
275
		__menuet__debug_out("\nStarted\n");
281
		__menuet__debug_out("\nStarted\n");
276
		fz_accelerate();
282
		fz_accelerate();
277
		__menuet__debug_out("PDF init\n");
283
		__menuet__debug_out("PDF init\n");
278
		pdfapp_init(&gapp);
284
		pdfapp_init(&gapp);
279
	gapp.scrw = 600;
285
	gapp.scrw = 600;
280
	gapp.scrh = 400;
286
	gapp.scrh = 400;
281
	gapp.resolution = resolution;
287
	gapp.resolution = resolution;
282
	gapp.pageno = pageno;
288
	gapp.pageno = pageno;
283
	__menuet__debug_out("PDF Open\n");
289
	__menuet__debug_out("PDF Open\n");
284
	pdfapp_open(&gapp, original_command_line, 0, 0);
290
	pdfapp_open(&gapp, original_command_line, 0, 0);
285
		__menuet__debug_out("PDF Opened\n");
291
		__menuet__debug_out("PDF Opened\n");
286
	
292
	
287
	
293
	
288
 
294
 
289
 int i;
295
 int i;
290
 int butt;
296
 int butt;
291
 
297
 
292
 __menuet__debug_out("Inital paint\n");
298
 __menuet__debug_out("Inital paint\n");
293
   pdfapp_onresize(&gapp, 600, 400);
299
   pdfapp_onresize(&gapp, 600, 400);
294
 paint();
300
 paint();
295
 for(;;)
301
 for(;;)
296
 {
302
 {
297
 
303
 
298
  i=__menuet__wait_for_event();
304
  i=__menuet__wait_for_event();
299
  butt = __menuet__get_button_id();
305
  butt = __menuet__get_button_id();
300
  if (gapp.image)
306
  if (gapp.image)
301
				{
307
				{
302
					
308
					
303
						gapp.shrinkwrap = 0;
309
						gapp.shrinkwrap = 0;
304
				}
310
				}
305
  switch(i)
311
  switch(i)
306
  {
312
  {
307
   case 1:
313
   case 1:
308
    paint();
314
    paint();
309
    
315
    
310
    continue;
316
    continue;
311
   case 2:
317
   case 2:
312
    buf[0]=__menuet__getkey(); 
318
    buf[0]=__menuet__getkey(); 
313
    pdfapp_onkey(&gapp, buf[0]);
319
    pdfapp_onkey(&gapp, buf[0]);
314
    continue;
320
    continue;
315
   case 3:
321
   case 3:
316
    if(butt==1) __menuet__sys_exit();//browse file
322
    if(butt==1) __menuet__sys_exit();//browse file
317
    if(butt==2) pdfapp_onkey(&gapp, '['); //previous page
323
    if(butt==2) pdfapp_onkey(&gapp, '['); //previous page
318
    if(butt==3) pdfapp_onkey(&gapp, ']'); __menuet__debug_out("\nStarted\n"); //next page
324
    if(butt==3) pdfapp_onkey(&gapp, ']'); __menuet__debug_out("\nStarted\n"); //next page
319
    if(butt==4) pdfapp_onkey(&gapp, '?'); //show help window
325
    if(butt==4) pdfapp_onkey(&gapp, '?'); //show help window
320
    if(butt==5) pdfapp_onkey(&gapp, '+'); //magnify +
326
    if(butt==5) pdfapp_onkey(&gapp, '+'); //magnify +
321
    if(butt==6) pdfapp_onkey(&gapp, '-'); //mag -
327
    if(butt==6) pdfapp_onkey(&gapp, '-'); //mag -
322
    if(butt==7) ;//mag open file
328
    if(butt==7) ;//mag open file
323
    if(butt==8) pdfapp_onkey(&gapp, 'j'); //move up
329
    if(butt==8) pdfapp_onkey(&gapp, 'j'); //move up
324
    if(butt==9) pdfapp_onkey(&gapp, 'k'); //move down
330
    if(butt==9) pdfapp_onkey(&gapp, 'k'); //move down
325
    if(butt==10) pdfapp_onkey(&gapp, 'a'); //rotate +15 deg
331
    if(butt==10) pdfapp_onkey(&gapp, 'a'); //rotate +15 deg
326
    if(butt==11) pdfapp_onkey(&gapp, 's'); //rotate -15deg
332
    if(butt==11) pdfapp_onkey(&gapp, 's'); //rotate -15deg
327
    continue;
333
    continue;
328
  
334
  
329
  }
335
  }
330
 }
336
 }
331
 return 0;
337
 return 0;
332
}
338
}
333
>
-