Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. char char_width[255];
  2.  
  3. void PreparePage()
  4. {
  5. int i;
  6.         list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1, Form.cheight-TOOLBAR_H, label.size.pt+1);
  7.         //get font chars width, need to increase performance
  8.         //if (strstri(io.buffer_data, "<html>")==-1) {
  9.                 debugln("no <html> found");
  10.                 label.changeSIZE();
  11.                 for (i=0; i<256; i++) char_width[i] = label.symbol_size(i);
  12.                 ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
  13.                 DrawProgress(STEP_2_COUNT_PAGE_HEIGHT);     ParceTxt(false);        //get page height to calculate buffer size
  14.                 DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceTxt(true);         //draw text in buffer
  15.                 DrawProgress(STEP_4_SMOOTH_FONT);           label.apply_smooth();
  16.                 DrawProgress(STEP_5_STOP);                  DrawPage();
  17.         /*}
  18.         else {
  19.                 debugln("<html> tag found");
  20.                 label.changeSIZE();
  21.                 for (i=0; i<256; i++) char_width[i] = label.symbol_size(i);
  22.                 ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
  23.                 DrawProgress(STEP_2_COUNT_PAGE_HEIGHT);     ParceHtml(false);        //get page height to calculate buffer size
  24.                 DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceHtml(true);         //draw text in buffer
  25.                 DrawProgress(STEP_4_SMOOTH_FONT);           label.apply_smooth();
  26.                 DrawProgress(STEP_5_STOP);                  DrawPage();
  27.         }*/
  28. }
  29.  
  30. void ParceTxt(byte draw)
  31. {
  32. byte ch, zeroch=0;
  33. dword bufoff, buflen, line_start, srch_pos;
  34. int stroka_y=5, line_length=0;
  35.  
  36.         line_start=io.buffer_data;
  37.         buflen = strlen(io.buffer_data) + io.buffer_data;
  38.         for (bufoff=io.buffer_data; bufoff<buflen; bufoff++)
  39.         {
  40.                 ch = ESBYTE[bufoff];
  41.                 line_length += char_width[ch];
  42.                 if (line_length>=list.w-30) || (ch==10) {
  43.                         srch_pos = bufoff;
  44.                         loop()
  45.                         {
  46.                                 if (__isWhite(ESBYTE[srch_pos])) { bufoff=srch_pos+1; break; } //normal word-break
  47.                                 if (srch_pos == line_start) break; //no white space found in whole line
  48.                                 srch_pos--;
  49.                         }
  50.                         if (draw==true) {
  51.                                 ESBYTE[bufoff] >< zeroch; //set line end
  52.                                 label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, line_start);
  53.                                 ESBYTE[bufoff] >< zeroch; //restore line
  54.                                 DrawProgressWhileDrawing(bufoff, buflen);
  55.                                 if (stroka_y/list.item_h-list.first==list.visible) DrawPage();
  56.                         }
  57.                         stroka_y += list.item_h;
  58.                         line_start = bufoff;
  59.                         line_length = 0;
  60.                 }
  61.         }
  62.         if (draw==false) {
  63.                 list.count = stroka_y/list.item_h+2;
  64.                 if (list.count < list.visible) list.count = list.visible;
  65.                 label.size.height = list.count+1*list.item_h;
  66.                 label.raw_size = 0;
  67.         }
  68.         if (draw==true) label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, line_start);
  69. }
  70.  
  71.  
  72. /*========================================================
  73. =                                                        =
  74. =                        HTML                            =
  75. =                                                        =
  76. ========================================================*/
  77.  
  78. /*
  79. HTML parcer tags:
  80. <title>
  81. <meta encoding>
  82. <a hrf="">
  83. <img src="" alt="">
  84. <h1> ... <h6>
  85. <b>
  86. <u>
  87. <s>
  88. <pre>
  89. */
  90.  
  91. struct _DOM {
  92.         dword start;
  93.         dword end;
  94.         dword len;
  95. };
  96.  
  97. struct _style {
  98.         bool b, u, i, s;
  99.         bool h1, h2, h3, h4, h5, h6;
  100.         bool a;
  101.         bool pre;
  102.         bool title;
  103.         bool br;
  104. } style;
  105.  
  106. struct _tag {
  107.         dword start;
  108.         dword name;
  109.         dword param[10];
  110.         dword value[10];
  111.         void parce();
  112.         void get_param_value();
  113. };
  114.  
  115. void _tag::parce()
  116. {
  117.         bool closed_status = false;
  118.         if (start) debugln(start);
  119.         /*
  120.         if (strncmp(start, "/", 1)==0) {
  121.                 start++;
  122.                 closed_status = true;
  123.         }
  124.         if (!strcmp(start, "title")) style.title = closed_status;
  125.         if (!strcmp(start, "br")) style.br = closed_status;
  126.         */
  127. }
  128.  
  129. struct _text {
  130.         dword start;
  131.         int x, y;
  132.         void draw();   
  133. };
  134.  
  135. void _text::draw()
  136. {
  137.         if (start) debugln(start);
  138.         /*
  139.         if (style.title) {
  140.                 strlcpy(#title, start, sizeof(title));
  141.                 DrawTitle(#title);
  142.                 return;
  143.         }
  144.         if (style.br) {
  145.                 y += list.item_h;
  146.                 style.br = false;
  147.         }
  148.         */
  149. }
  150.  
  151.  
  152. void ParceHtml(byte draw)
  153. {
  154. byte ch;
  155. _DOM DOM;
  156. _text text;
  157. _tag tag;
  158. dword DOM_pos;
  159.  
  160.         /* Create DOM */
  161.         debugln("starting DOM parce");
  162.         DOM.len = strlen(io.buffer_data);
  163.         DOM.start = malloc(DOM.len);
  164.         DOM.end = DOM.start + DOM.len;
  165.         strlcpy(DOM.start, io.buffer_data, DOM.len);
  166.  
  167.         /* Parce DOM */
  168.         text.start = DOM_pos;
  169.         for (DOM_pos=DOM.start; DOM_pos<DOM.end; DOM_pos++)
  170.         {
  171.                 ch = ESBYTE[DOM_pos];
  172.                 if (ch=='<') {
  173.                         ESBYTE[DOM_pos] = NULL;
  174.                         tag.start = DOM_pos + 1;
  175.                         text.draw();
  176.                 }
  177.                 if (ch=='>') {
  178.                         ESBYTE[DOM_pos] = NULL;
  179.                         text.start = DOM_pos + 1;
  180.                         tag.parce();
  181.                 }              
  182.         }
  183.         free(DOM.start);
  184.         ExitProcess();
  185. }