Subversion Repositories Kolibri OS

Rev

Rev 6372 | 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.                 // 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.         debugln("-------START PARCING-------");
  88.         tag.clear();
  89.         style.clear();
  90.         /* Create DOM */
  91.         debugln("creating DOM");
  92.         DOM_len = strlen(io.buffer_data);
  93.         DOM_start = malloc(DOM_len);
  94.         DOM_end = DOM_start + DOM_len;
  95.         strlcpy(DOM_start, io.buffer_data, DOM_len);
  96.  
  97.         /* Parce DOM */
  98.         debugln("starting DOM parce...");
  99.         text.start = DOM_start;
  100.         for (DOM_pos=DOM_start; DOM_pos<DOM_end; DOM_pos++)
  101.         {
  102.                 if (ESBYTE[DOM_pos]==0x0D) || (ESBYTE[DOM_pos]==0x0A) ESBYTE[DOM_pos]=' ';
  103.                 ch = ESBYTE[DOM_pos];
  104.                 if (ch=='<') {
  105.                         ESBYTE[DOM_pos] = '\0';
  106.                         tag.start = DOM_pos + 1;
  107.                         if (style.ignore) continue;
  108.                         if (tag.nameis("title")) {
  109.                                 strcpy(#title, text.start);
  110.                                 continue;
  111.                         }
  112.                         strtrim(text.start);
  113.                         // try to change the special symbols that may appear
  114.                         text.fixSpecial();
  115.  
  116.                         while (get_label_len(text.start) + stroka_x + 30 > list.w)
  117.                         {
  118.                                 zeroch = 0;
  119.                                 for (line_break=tag.start-1; line_break>text.start; line_break--;)
  120.                                 {
  121.                                         ESBYTE[line_break] >< zeroch; //set line end
  122.                                         if (get_label_len(text.start) + stroka_x + 30 <= list.w) break;
  123.                                         ESBYTE[line_break] >< zeroch; //restore line
  124.                                 }
  125.                                 if (draw==true) {
  126.                                         if (style.a) {
  127.                                                 link.add(stroka_x,stroka_y + size_pt_change,get_label_len(text.start),list.item_h,text.start," ");
  128.                                                 label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
  129.                                         }
  130.                                         WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
  131.                                 }
  132.                                 stroka_x+=char_width[' '];
  133.                                 ESBYTE[line_break] >< zeroch; //restore line
  134.                                 text.start = line_break;
  135.                                 stroka_x = HTML_PADDING_X;
  136.                                 stroka_y += list.item_h;
  137.                         }
  138.                         if (draw==true) {
  139.                                 if (style.a) {
  140.                                         link.add(stroka_x,stroka_y + size_pt_change,get_label_len(text.start),list.item_h,text.start," ");     
  141.                                         label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
  142.                                 }
  143.                                 WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
  144.                         }
  145.                         stroka_x+=char_width[' '];
  146.                         stroka_x += get_label_len(text.start);
  147.                 }
  148.                 if (ch=='>') {
  149.                         ESBYTE[DOM_pos] = '\0';
  150.                         text.start = DOM_pos + 1;
  151.                         tag.parce();
  152.                         if (tag.nameis("br"))
  153.                                 || (tag.nameis("p"))
  154.                                 || (tag.nameis("div"))
  155.                                 || (tag.nameis("tr")) {
  156.                                 stroka_y+= list.item_h;
  157.                                 stroka_x = HTML_PADDING_X;
  158.                                 continue;
  159.                         }
  160.                         if      (tag.nameis("h1")) || (tag.nameis("/h1")) ||
  161.                                 (tag.nameis("h2")) || (tag.nameis("/h2")) ||
  162.                                 (tag.nameis("h3")) || (tag.nameis("/h3")) {
  163.                                 if (tag.nameis("h1")) {
  164.                                         size_pt_change = 8;
  165.                                 } else if (tag.nameis("/h1")) {
  166.                                         size_pt_change = -8;
  167.                                 } else if (tag.nameis("h2")) {
  168.                                         size_pt_change = 6;
  169.                                 } else if (tag.nameis("/h2")) {
  170.                                         size_pt_change = -6;
  171.                                 } else if (tag.nameis("h3")) {
  172.                                         size_pt_change = 4;
  173.                                 } else if (tag.nameis("/h3")) {
  174.                                         size_pt_change = -4;
  175.                                 }
  176.                                 label.size.pt += size_pt_change;
  177.                                 get_label_symbols_size();
  178.                                 if (size_pt_change > 0) {
  179.                                         stroka_y+= list.item_h;//что если будет очень длинная строка в теге?
  180.                                 } else {//коммент выше и коммент ниже связаны
  181.                                         stroka_y+= list.item_h - size_pt_change;//не очень понятна логика этого места
  182.                                         size_pt_change = 0;
  183.                                 }
  184.                                 stroka_x = HTML_PADDING_X;
  185.                                 continue;                                      
  186.                         }
  187.                         if (tag.nameis("script")) || (tag.nameis("style")) style.ignore = true;
  188.                         if (tag.nameis("/script")) || (tag.nameis("/style")) style.ignore = false;
  189.                         if (tag.nameis("a"))  { style.a = true;  style.color=0x0000FF; }
  190.                         if (tag.nameis("/a")) { style.a = false; style.color=0x000000; }
  191.                 }              
  192.         }
  193.         if (draw==false) {
  194.                 list.count = stroka_y/list.item_h+3;
  195.                 if (list.count < list.visible) list.count = list.visible;
  196.                 label.size.height = list.count+5*list.item_h;
  197.                 label.raw_size = 0;
  198.         }
  199.         free(DOM_start);
  200.         debugln("-------STOP PARCING--------");
  201. }