Subversion Repositories Kolibri OS

Rev

Rev 6376 | 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.                 // debugln("DONE STEP 2");
  18.                 DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceHtml(true);   //draw text in buffer
  19.                 // debugln("DONE STEP 3");
  20.         }
  21.         strcat(#title, " - Aelia");
  22.         DrawTitle(#title);
  23.         DrawProgress(STEP_4_SMOOTH_FONT);           label.apply_smooth();
  24.         DrawProgress(STEP_5_STOP);                  DrawPage();
  25. }
  26.  
  27. void ParceTxt(byte draw)
  28. {
  29. byte ch, zeroch=0;
  30. dword bufoff, buflen, line_start, srch_pos;
  31. int stroka_y=5, line_length=0;
  32.  
  33.         line_start=io.buffer_data;
  34.         buflen = strlen(io.buffer_data) + io.buffer_data;
  35.         for (bufoff=io.buffer_data; bufoff<buflen; bufoff++)
  36.         {
  37.                 ch = ESBYTE[bufoff];
  38.                 line_length += char_width[ch];
  39.                 if (line_length>=list.w-30) || (ch==10) {
  40.                         srch_pos = bufoff;
  41.                         loop()
  42.                         {
  43.                                 if (__isWhite(ESBYTE[srch_pos])) { bufoff=srch_pos+1; break; } //normal word-break
  44.                                 if (srch_pos == line_start) break; //no white space found in whole line
  45.                                 srch_pos--;
  46.                         }
  47.                         if (draw==true) {
  48.                                 ESBYTE[bufoff] >< zeroch; //set line end
  49.                                 WriteTextIntoBuf(8, stroka_y, 0x000000, line_start);
  50.                                 ESBYTE[bufoff] >< zeroch; //restore line
  51.                         }
  52.                         stroka_y += list.item_h;
  53.                         line_start = bufoff;
  54.                         line_length = 0;
  55.                 }
  56.         }
  57.         if (draw==false) {
  58.                 list.count = stroka_y/list.item_h+3;
  59.                 if (list.count < list.visible) list.count = list.visible;
  60.                 label.size.height = list.count+5*list.item_h;
  61.                 label.raw_size = 0;
  62.         }
  63.         if (draw==true) WriteTextIntoBuf(8, stroka_y, 0x000000, line_start);
  64. }
  65.  
  66.  
  67. /*========================================================
  68. =                                                        =
  69. =                        HTML                            =
  70. =                                                        =
  71. ========================================================*/
  72.  
  73. #define HTML_PADDING_X 8;
  74. #define HTML_PADDING_Y 5;
  75.  
  76.  
  77. void ParceHtml(byte draw)
  78. {      
  79. dword DOM_start, DOM_end, DOM_len, DOM_pos, aux2;
  80. int stroka_x = HTML_PADDING_X;
  81. int stroka_y = HTML_PADDING_Y;
  82. int size_pt_change = 0;
  83. dword line_break;
  84. byte ch, zeroch;
  85. _text text;
  86. _tag tag;
  87.         tag.clear();
  88.         style.clear();
  89.         /* Create DOM */
  90.         debugln("creating DOM");
  91.         DOM_len = strlen(io.buffer_data);
  92.         DOM_start = malloc(DOM_len);
  93.         DOM_end = DOM_start + DOM_len;
  94.         strlcpy(DOM_start, io.buffer_data, DOM_len);
  95.  
  96.         /* Parce DOM */
  97.         debugln("starting DOM parce...");
  98.         text.start = DOM_start;
  99.         for (DOM_pos=DOM_start; DOM_pos<DOM_end; DOM_pos++)
  100.         {
  101.                 if (ESBYTE[DOM_pos]==0x0D) || (ESBYTE[DOM_pos]==0x0A) ESBYTE[DOM_pos]=' ';
  102.                 ch = ESBYTE[DOM_pos];
  103.                 if (ch=='<') {
  104.                         ESBYTE[DOM_pos] = '\0';
  105.                         tag.start = DOM_pos + 1;
  106.                         if (style.ignore) continue;
  107.                         if (tag.nameis("title")) {
  108.                                 strcpy(#title, text.start);
  109.                                 continue;
  110.                         }
  111.                         strtrim(text.start);
  112.                         // try to change the special symbols that may appear
  113.                         text.fixSpecial(text.start);
  114.  
  115.                         while (get_label_len(text.start) + stroka_x + 30 > list.w)
  116.                         {
  117.                                 zeroch = 0;
  118.                                 for (line_break=tag.start-1; line_break>text.start; line_break--;)
  119.                                 {
  120.                                         ESBYTE[line_break] >< zeroch; //set line end
  121.                                         if (get_label_len(text.start) + stroka_x + 30 <= list.w) break;
  122.                                         ESBYTE[line_break] >< zeroch; //restore line
  123.                                 }
  124.                                 if (draw==true) {
  125.                                         if (style.a) {
  126.                                                 link.add(stroka_x,stroka_y + size_pt_change,get_label_len(text.start),list.item_h,text.start," ");
  127.                                                 label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
  128.                                         }
  129.                                         WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
  130.                                 }
  131.                                 stroka_x+=char_width[' '];
  132.                                 ESBYTE[line_break] >< zeroch; //restore line
  133.                                 text.start = line_break;
  134.                                 stroka_x = HTML_PADDING_X;
  135.                                 stroka_y += list.item_h;
  136.                         }
  137.                         if (draw==true) {
  138.                                 if (style.a) {
  139.                                         link.add(stroka_x,stroka_y + size_pt_change,get_label_len(text.start),list.item_h,text.start," ");     
  140.                                         label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
  141.                                 }
  142.                                 WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
  143.                         }
  144.                         stroka_x+=char_width[' '];
  145.                         stroka_x += get_label_len(text.start);
  146.                 }
  147.                 if (ch=='>') {
  148.                         ESBYTE[DOM_pos] = '\0';
  149.                         text.start = DOM_pos + 1;
  150.                         tag.parce();
  151.                         if (tag.nameis("br"))
  152.                                 || (tag.nameis("p"))
  153.                                 || (tag.nameis("div"))
  154.                                 || (tag.nameis("tr")) {
  155.                                 stroka_y+= list.item_h;
  156.                                 stroka_x = HTML_PADDING_X;
  157.                                 continue;
  158.                         }
  159.                         if      (tag.nameis("h1")) || (tag.nameis("/h1")) ||
  160.                                 (tag.nameis("h2")) || (tag.nameis("/h2")) ||
  161.                                 (tag.nameis("h3")) || (tag.nameis("/h3")) {
  162.                                 if (tag.nameis("h1")) {
  163.                                         size_pt_change = 8;
  164.                                 } else if (tag.nameis("/h1")) {
  165.                                         size_pt_change = -8;
  166.                                 } else if (tag.nameis("h2")) {
  167.                                         size_pt_change = 6;
  168.                                 } else if (tag.nameis("/h2")) {
  169.                                         size_pt_change = -6;
  170.                                 } else if (tag.nameis("h3")) {
  171.                                         size_pt_change = 4;
  172.                                 } else if (tag.nameis("/h3")) {
  173.                                         size_pt_change = -4;
  174.                                 }
  175.                                 label.size.pt += size_pt_change;
  176.                                 get_label_symbols_size();
  177.                                 if (size_pt_change > 0) {
  178.                                         stroka_y+= list.item_h;//что если будет очень длинная строка в теге?
  179.                                 } else {//коммент выше и коммент ниже связаны
  180.                                         stroka_y+= list.item_h - size_pt_change;//не очень понятна логика этого места
  181.                                         size_pt_change = 0;
  182.                                 }
  183.                                 stroka_x = HTML_PADDING_X;
  184.                                 continue;                                      
  185.                         }
  186.                         if (tag.nameis("script")) || (tag.nameis("style")) style.ignore = true;
  187.                         if (tag.nameis("/script")) || (tag.nameis("/style")) style.ignore = false;
  188.                         if (tag.nameis("a"))  { style.a = true;  style.color=0x0000FF; }
  189.                         if (tag.nameis("/a")) { style.a = false; style.color=0x000000; }
  190.                 }              
  191.         }
  192.         if (draw==false) {
  193.                 list.count = stroka_y/list.item_h+3;
  194.                 if (list.count < list.visible) list.count = list.visible;
  195.                 label.size.height = list.count+5*list.item_h;
  196.                 label.raw_size = 0;
  197.         }
  198.         free(DOM_start);
  199. }