Subversion Repositories Kolibri OS

Rev

Rev 6152 | 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. dword line_break;
  81. byte ch, zeroch;
  82. _text text;
  83. _tag tag;
  84.  
  85.         tag.clear();
  86.         style.clear();
  87.         /* Create DOM */
  88.         debugln("creating DOM");
  89.         DOM_len = strlen(io.buffer_data);
  90.         DOM_start = malloc(DOM_len);
  91.         DOM_end = DOM_start + DOM_len;
  92.         strlcpy(DOM_start, io.buffer_data, DOM_len);
  93.  
  94.         /* Parce DOM */
  95.         debugln("starting DOM parce...");
  96.         text.start = DOM_start;
  97.         for (DOM_pos=DOM_start; DOM_pos<DOM_end; DOM_pos++)
  98.         {
  99.                 if (ESBYTE[DOM_pos]==0x0D) || (ESBYTE[DOM_pos]==0x0A) ESBYTE[DOM_pos]=' ';
  100.                 ch = ESBYTE[DOM_pos];
  101.                 if (ch=='<') {
  102.                         ESBYTE[DOM_pos] = '\0';
  103.                         tag.start = DOM_pos + 1;
  104.                         if (style.ignore) continue;
  105.                         if (tag.nameis("title")) {
  106.                                 strcpy(#title, text.start);
  107.                                 continue;
  108.                         }
  109.                         strtrim(text.start);
  110.                         while (get_label_len(text.start) + stroka_x + 30 > list.w)
  111.                         {
  112.                                 zeroch = 0;
  113.                                 for (line_break=tag.start-1; line_break>text.start; line_break--;)
  114.                                 {
  115.                                         ESBYTE[line_break] >< zeroch; //set line end
  116.                                         if (get_label_len(text.start) + stroka_x + 30 <= list.w) break;
  117.                                         ESBYTE[line_break] >< zeroch; //restore line
  118.                                 }
  119.                                 if (draw==true) {
  120.                                         if (style.a) {
  121.                                                 link.add(stroka_x,stroka_y,get_label_len(text.start),list.item_h,text.start," ");
  122.                                                 label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
  123.                                         }
  124.                                         WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
  125.                                 }
  126.                                 stroka_x+=char_width[' '];
  127.                                 ESBYTE[line_break] >< zeroch; //restore line
  128.                                 text.start = line_break;
  129.                                 stroka_x = HTML_PADDING_X;
  130.                                 stroka_y += list.item_h;
  131.                         }
  132.                         if (draw==true) {
  133.                                 if (style.a) {
  134.                                         link.add(stroka_x,stroka_y,get_label_len(text.start),list.item_h,text.start," ");      
  135.                                         label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
  136.                                 }
  137.                                 WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
  138.                         }
  139.                         stroka_x+=char_width[' '];
  140.                         stroka_x += get_label_len(text.start);
  141.                 }
  142.                 if (ch=='>') {
  143.                         ESBYTE[DOM_pos] = '\0';
  144.                         text.start = DOM_pos + 1;
  145.                         tag.parce();
  146.                         if (tag.nameis("br"))
  147.                                 || (tag.nameis("p"))
  148.                                 || (tag.nameis("div"))
  149.                                 || (tag.nameis("tr")) {
  150.                                 stroka_y+= list.item_h;
  151.                                 stroka_x = HTML_PADDING_X;
  152.                                 continue;
  153.                         }
  154.                         if      (tag.nameis("h1")) || (tag.nameis("/h1"))
  155.                                 || (tag.nameis("h2")) || (tag.nameis("/h2")) {
  156.                                         stroka_y+= list.item_h;
  157.                                         stroka_x = HTML_PADDING_X;
  158.                                         continue;                                      
  159.                                 }
  160.                         if (tag.nameis("script")) || (tag.nameis("style")) style.ignore = true;
  161.                         if (tag.nameis("/script")) || (tag.nameis("/style")) style.ignore = false;
  162.                         if (tag.nameis("a"))  { style.a = true;  style.color=0x0000FF; }
  163.                         if (tag.nameis("/a")) { style.a = false; style.color=0x000000; }
  164.                 }              
  165.         }
  166.         if (draw==false) {
  167.                 list.count = stroka_y/list.item_h+3;
  168.                 if (list.count < list.visible) list.count = list.visible;
  169.                 label.size.height = list.count+5*list.item_h;
  170.                 label.raw_size = 0;
  171.         }
  172.         free(DOM_start);
  173. }