Subversion Repositories Kolibri OS

Rev

Rev 4696 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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