Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. void PreparePage()
  3. {
  4.         list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1, Form.cheight-TOOLBAR_H, label.size.pt+2);
  5.         strcpy(#title, history.current()+strrchr(history.current(),'/'));
  6.         //get font chars width, need to increase performance
  7.         get_label_symbols_size();
  8.         ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
  9.         link.clear();
  10.         if (strstri(io.buffer_data, "<html")==-1) {
  11.                 debugln("no <html> found");
  12.                 DrawProgress(STEP_2_COUNT_PAGE_HEIGHT);     ParceTxt(false);   //get page height to calculate buffer size
  13.                 DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceTxt(true);    //draw text in buffer
  14.         } else {
  15.                 debugln("<html> tag found");
  16.                 DrawProgress(STEP_2_COUNT_PAGE_HEIGHT);     ParceHtml(false);  //get page height to calculate buffer size
  17.                 DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceHtml(true);   //draw text in buffer
  18.         }
  19.         strcat(#title, " - Aelia");
  20.         DrawTitle(#title);
  21.         DrawProgress(STEP_4_SMOOTH_FONT);           label.apply_smooth();
  22.         DrawProgress(STEP_5_STOP);                  DrawPage();
  23. }
  24.  
  25. void ParceTxt(byte draw)
  26. {
  27. byte ch, zeroch=0;
  28. dword bufoff, buflen, line_start, srch_pos;
  29. int stroka_y=5, line_length=0;
  30.  
  31.         line_start=io.buffer_data;
  32.         buflen = strlen(io.buffer_data) + io.buffer_data;
  33.         for (bufoff=io.buffer_data; bufoff<buflen; bufoff++)
  34.         {
  35.                 ch = ESBYTE[bufoff];
  36.                 line_length += char_width[ch];
  37.                 if (line_length>=list.w-30) || (ch==10) {
  38.                         srch_pos = bufoff;
  39.                         loop()
  40.                         {
  41.                                 if (__isWhite(ESBYTE[srch_pos])) { bufoff=srch_pos+1; break; } //normal word-break
  42.                                 if (srch_pos == line_start) break; //no white space found in whole line
  43.                                 srch_pos--;
  44.                         }
  45.                         if (draw==true) {
  46.                                 ESBYTE[bufoff] >< zeroch; //set line end
  47.                                 WriteTextIntoBuf(8, stroka_y, 0x000000, line_start);
  48.                                 ESBYTE[bufoff] >< zeroch; //restore line
  49.                         }
  50.                         stroka_y += list.item_h;
  51.                         line_start = bufoff;
  52.                         line_length = 0;
  53.                 }
  54.         }
  55.         if (draw==false) {
  56.                 list.count = stroka_y/list.item_h+3;
  57.                 if (list.count < list.visible) list.count = list.visible;
  58.                 label.size.height = list.count+5*list.item_h;
  59.                 label.raw_size = 0;
  60.         }
  61.         if (draw==true) WriteTextIntoBuf(8, stroka_y, 0x000000, line_start);
  62. }
  63.  
  64.  
  65. /*========================================================
  66. =                                                        =
  67. =                        HTML                            =
  68. =                                                        =
  69. ========================================================*/
  70.  
  71. #define HTML_PADDING_X 8;
  72. #define HTML_PADDING_Y 5;
  73.  
  74.  
  75. void ParceHtml(byte draw)
  76. {
  77. dword DOM_start, DOM_end, DOM_len, DOM_pos;
  78. int stroka_x = HTML_PADDING_X;
  79. int stroka_y = HTML_PADDING_Y;
  80. int size_pt_change;
  81. dword line_break;
  82. byte ch, zeroch;
  83. _text text;
  84. _tag tag;
  85.  
  86.         tag.clear();
  87.         style.clear();
  88.         /* Create DOM */
  89.         debugln("creating DOM");
  90.         DOM_len = strlen(io.buffer_data);
  91.         DOM_start = malloc(DOM_len);
  92.         DOM_end = DOM_start + DOM_len;
  93.         strlcpy(DOM_start, io.buffer_data, DOM_len);
  94.  
  95.         /* Parce DOM */
  96.         debugln("starting DOM parce...");
  97.         text.start = DOM_start;
  98.         for (DOM_pos=DOM_start; DOM_pos<DOM_end; DOM_pos++)
  99.         {
  100.                 if (ESBYTE[DOM_pos]==0x0D) || (ESBYTE[DOM_pos]==0x0A) ESBYTE[DOM_pos]=' ';
  101.                 ch = ESBYTE[DOM_pos];
  102.                 if (ch=='<') {
  103.                         ESBYTE[DOM_pos] = '\0';
  104.                         tag.start = DOM_pos + 1;
  105.                         if (style.ignore) continue;
  106.                         if (tag.nameis("title")) {
  107.                                 strcpy(#title, text.start);
  108.                                 continue;
  109.                         }
  110.                         strtrim(text.start);
  111.                         while (get_label_len(text.start) + stroka_x + 30 > list.w)
  112.                         {
  113.                                 zeroch = 0;
  114.                                 for (line_break=tag.start-1; line_break>text.start; line_break--;)
  115.                                 {
  116.                                         ESBYTE[line_break] >< zeroch; //set line end
  117.                                         if (get_label_len(text.start) + stroka_x + 30 <= list.w) break;
  118.                                         ESBYTE[line_break] >< zeroch; //restore line
  119.                                 }
  120.                                 if (draw==true) {
  121.                                         if (style.a) {
  122.                                                 link.add(stroka_x,stroka_y,get_label_len(text.start),list.item_h,text.start," ");
  123.                                                 label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
  124.                                         }
  125.                                         WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
  126.                                 }
  127.                                 stroka_x+=char_width[' '];
  128.                                 ESBYTE[line_break] >< zeroch; //restore line
  129.                                 text.start = line_break;
  130.                                 stroka_x = HTML_PADDING_X;
  131.                                 stroka_y += list.item_h;
  132.                         }
  133.                         if (draw==true) {
  134.                                 if (style.a) {
  135.                                         link.add(stroka_x,stroka_y,get_label_len(text.start),list.item_h,text.start," ");      
  136.                                         label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
  137.                                 }
  138.                                 WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
  139.                         }
  140.                         stroka_x+=char_width[' '];
  141.                         stroka_x += get_label_len(text.start);
  142.                 }
  143.                 if (ch=='>') {
  144.                         ESBYTE[DOM_pos] = '\0';
  145.                         text.start = DOM_pos + 1;
  146.                         tag.parce();
  147.                         if (tag.nameis("br"))
  148.                                 || (tag.nameis("p"))
  149.                                 || (tag.nameis("div"))
  150.                                 || (tag.nameis("tr")) {
  151.                                 stroka_y+= list.item_h;
  152.                                 stroka_x = HTML_PADDING_X;
  153.                                 continue;
  154.                         }
  155.                         if      (tag.nameis("h1")) || (tag.nameis("/h1")) ||
  156.                                 (tag.nameis("h2")) || (tag.nameis("/h2")) ||
  157.                                 (tag.nameis("h3")) || (tag.nameis("/h3")) {
  158.                                 if (tag.nameis("h1")) {
  159.                                         size_pt_change = 8;
  160.                                 } else if (tag.nameis("/h1")) {
  161.                                         size_pt_change = -8;
  162.                                 } else if (tag.nameis("h2")) {
  163.                                         size_pt_change = 6;
  164.                                 } else if (tag.nameis("/h2")) {
  165.                                         size_pt_change = -6;
  166.                                 } else if (tag.nameis("h3")) {
  167.                                         size_pt_change = 4;
  168.                                 } else if (tag.nameis("/h3")) {
  169.                                         size_pt_change = -4;
  170.                                 }
  171.                                 label.size.pt += size_pt_change;
  172.                                 if (size_pt_change > 0) {
  173.                                         stroka_y+= list.item_h;
  174.                                 } else {
  175.                                         stroka_y+= list.item_h - size_pt_change;
  176.                                 }
  177.                                 stroka_x = HTML_PADDING_X;
  178.                                 continue;                                      
  179.                         }
  180.                         if (tag.nameis("script")) || (tag.nameis("style")) style.ignore = true;
  181.                         if (tag.nameis("/script")) || (tag.nameis("/style")) style.ignore = false;
  182.                         if (tag.nameis("a"))  { style.a = true;  style.color=0x0000FF; }
  183.                         if (tag.nameis("/a")) { style.a = false; style.color=0x000000; }
  184.                 }              
  185.         }
  186.         if (draw==false) {
  187.                 list.count = stroka_y/list.item_h+3;
  188.                 if (list.count < list.visible) list.count = list.visible;
  189.                 label.size.height = list.count+5*list.item_h;
  190.                 label.raw_size = 0;
  191.         }
  192.         free(DOM_start);
  193. }