2016-01-07 17:00:59 +01:00
|
|
|
|
|
|
|
void PreparePage()
|
|
|
|
{
|
2016-01-10 23:33:10 +01:00
|
|
|
list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1, Form.cheight-TOOLBAR_H, label.size.pt+2);
|
|
|
|
strcpy(#title, history.current()+strrchr(history.current(),'/'));
|
2016-01-07 17:00:59 +01:00
|
|
|
//get font chars width, need to increase performance
|
2016-01-10 23:33:10 +01:00
|
|
|
get_label_symbols_size();
|
|
|
|
ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
|
|
|
|
if (strstri(io.buffer_data, "<html")==-1) {
|
2016-01-07 17:00:59 +01:00
|
|
|
debugln("no <html> found");
|
2016-01-10 23:33:10 +01:00
|
|
|
DrawProgress(STEP_2_COUNT_PAGE_HEIGHT); ParceTxt(false); //get page height to calculate buffer size
|
|
|
|
DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceTxt(true); //draw text in buffer
|
|
|
|
} else {
|
2016-01-07 17:00:59 +01:00
|
|
|
debugln("<html> tag found");
|
2016-01-10 23:33:10 +01:00
|
|
|
DrawProgress(STEP_2_COUNT_PAGE_HEIGHT); ParceHtml(false); //get page height to calculate buffer size
|
|
|
|
DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceHtml(true); //draw text in buffer
|
|
|
|
}
|
|
|
|
strcat(#title, " - Aelia");
|
|
|
|
DrawTitle(#title);
|
|
|
|
DrawProgress(STEP_4_SMOOTH_FONT); label.apply_smooth();
|
|
|
|
DrawProgress(STEP_5_STOP); DrawPage();
|
2016-01-07 17:00:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ParceTxt(byte draw)
|
|
|
|
{
|
|
|
|
byte ch, zeroch=0;
|
|
|
|
dword bufoff, buflen, line_start, srch_pos;
|
|
|
|
int stroka_y=5, line_length=0;
|
|
|
|
|
|
|
|
line_start=io.buffer_data;
|
|
|
|
buflen = strlen(io.buffer_data) + io.buffer_data;
|
|
|
|
for (bufoff=io.buffer_data; bufoff<buflen; bufoff++)
|
|
|
|
{
|
|
|
|
ch = ESBYTE[bufoff];
|
|
|
|
line_length += char_width[ch];
|
|
|
|
if (line_length>=list.w-30) || (ch==10) {
|
|
|
|
srch_pos = bufoff;
|
|
|
|
loop()
|
|
|
|
{
|
|
|
|
if (__isWhite(ESBYTE[srch_pos])) { bufoff=srch_pos+1; break; } //normal word-break
|
|
|
|
if (srch_pos == line_start) break; //no white space found in whole line
|
|
|
|
srch_pos--;
|
|
|
|
}
|
|
|
|
if (draw==true) {
|
|
|
|
ESBYTE[bufoff] >< zeroch; //set line end
|
2016-01-10 23:33:10 +01:00
|
|
|
WriteTextIntoBuf(8, stroka_y, 0x000000, line_start);
|
2016-01-07 17:00:59 +01:00
|
|
|
ESBYTE[bufoff] >< zeroch; //restore line
|
|
|
|
}
|
|
|
|
stroka_y += list.item_h;
|
|
|
|
line_start = bufoff;
|
|
|
|
line_length = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (draw==false) {
|
|
|
|
list.count = stroka_y/list.item_h+2;
|
|
|
|
if (list.count < list.visible) list.count = list.visible;
|
|
|
|
label.size.height = list.count+1*list.item_h;
|
|
|
|
label.raw_size = 0;
|
|
|
|
}
|
2016-01-10 23:33:10 +01:00
|
|
|
if (draw==true) WriteTextIntoBuf(8, stroka_y, 0x000000, line_start);
|
2016-01-07 17:00:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*========================================================
|
|
|
|
= =
|
|
|
|
= HTML =
|
|
|
|
= =
|
|
|
|
========================================================*/
|
|
|
|
|
2016-01-10 23:33:10 +01:00
|
|
|
/* <title> <meta encoding> <a hrf=""> <img src="" alt=""> <h1>..<h6> <b> <u> <s> <pre> */
|
2016-01-07 17:00:59 +01:00
|
|
|
|
|
|
|
struct _DOM {
|
|
|
|
dword start;
|
|
|
|
dword end;
|
|
|
|
dword len;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _style {
|
|
|
|
bool b, u, i, s;
|
|
|
|
bool h1, h2, h3, h4, h5, h6;
|
|
|
|
bool a;
|
|
|
|
bool pre;
|
2016-01-10 23:33:10 +01:00
|
|
|
bool ignore;
|
|
|
|
dword color;
|
2016-01-07 17:00:59 +01:00
|
|
|
} style;
|
|
|
|
|
2016-01-10 23:33:10 +01:00
|
|
|
struct _text {
|
|
|
|
dword start;
|
|
|
|
int x, y;
|
|
|
|
};
|
|
|
|
|
2016-01-07 17:00:59 +01:00
|
|
|
struct _tag {
|
|
|
|
dword start;
|
|
|
|
dword name;
|
|
|
|
dword param[10];
|
|
|
|
dword value[10];
|
|
|
|
void parce();
|
2016-01-10 23:33:10 +01:00
|
|
|
int nameis();
|
2016-01-07 17:00:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void _tag::parce()
|
|
|
|
{
|
2016-01-10 23:33:10 +01:00
|
|
|
dword o = name = start;
|
|
|
|
while (ESBYTE[o]!=' ') && (ESBYTE[o]) o++; //searching for a space after tag name
|
|
|
|
ESBYTE[o] = '\0';
|
|
|
|
strlwr(name);
|
2016-01-07 17:00:59 +01:00
|
|
|
}
|
|
|
|
|
2016-01-10 23:33:10 +01:00
|
|
|
int _tag::nameis(dword _in_tag_name)
|
2016-01-07 17:00:59 +01:00
|
|
|
{
|
2016-01-10 23:33:10 +01:00
|
|
|
if (strcmp(_in_tag_name, name)==0) return true;
|
|
|
|
return false;
|
2016-01-07 17:00:59 +01:00
|
|
|
}
|
|
|
|
|
2016-01-10 23:33:10 +01:00
|
|
|
#define HTML_PADDING_X 8;
|
|
|
|
#define HTML_PADDING_Y 5;
|
|
|
|
|
2016-01-07 17:00:59 +01:00
|
|
|
|
|
|
|
void ParceHtml(byte draw)
|
|
|
|
{
|
2016-01-10 23:33:10 +01:00
|
|
|
int stroka_x = HTML_PADDING_X;
|
|
|
|
int stroka_y = HTML_PADDING_Y;
|
|
|
|
dword line_break;
|
|
|
|
byte ch, zeroch;
|
2016-01-07 17:00:59 +01:00
|
|
|
_DOM DOM;
|
|
|
|
_text text;
|
|
|
|
_tag tag;
|
|
|
|
dword DOM_pos;
|
|
|
|
|
|
|
|
/* Create DOM */
|
2016-01-10 23:33:10 +01:00
|
|
|
debugln("creating DOM");
|
2016-01-07 17:00:59 +01:00
|
|
|
DOM.len = strlen(io.buffer_data);
|
|
|
|
DOM.start = malloc(DOM.len);
|
|
|
|
DOM.end = DOM.start + DOM.len;
|
|
|
|
strlcpy(DOM.start, io.buffer_data, DOM.len);
|
|
|
|
|
|
|
|
/* Parce DOM */
|
2016-01-10 23:33:10 +01:00
|
|
|
debugln("starting DOM parce...");
|
2016-01-07 17:00:59 +01:00
|
|
|
text.start = DOM_pos;
|
|
|
|
for (DOM_pos=DOM.start; DOM_pos<DOM.end; DOM_pos++)
|
|
|
|
{
|
2016-01-10 23:33:10 +01:00
|
|
|
if (ESBYTE[DOM_pos]==0x0D) || (ESBYTE[DOM_pos]==0x0A) ESBYTE[DOM_pos]=' ';
|
2016-01-07 17:00:59 +01:00
|
|
|
ch = ESBYTE[DOM_pos];
|
2016-01-10 23:33:10 +01:00
|
|
|
//debugch(ch);
|
2016-01-07 17:00:59 +01:00
|
|
|
if (ch=='<') {
|
2016-01-10 23:33:10 +01:00
|
|
|
ESBYTE[DOM_pos] = '\0';
|
2016-01-07 17:00:59 +01:00
|
|
|
tag.start = DOM_pos + 1;
|
2016-01-10 23:33:10 +01:00
|
|
|
if (style.ignore) continue;
|
|
|
|
if (tag.nameis("title")) {
|
|
|
|
strcpy(#title, text.start);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
while (get_label_len(text.start) + stroka_x + 30 > list.w)
|
|
|
|
{
|
|
|
|
//debugln("long line cut");
|
|
|
|
zeroch = 0;
|
|
|
|
for (line_break=tag.start-1; line_break>text.start; line_break--;)
|
|
|
|
{
|
|
|
|
ESBYTE[line_break] >< zeroch; //set line end
|
|
|
|
if (get_label_len(text.start) + stroka_x + 30 <= list.w) break;
|
|
|
|
ESBYTE[line_break] >< zeroch; //restore line
|
|
|
|
}
|
|
|
|
if (draw==true) {
|
|
|
|
if (style.a) label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
|
|
|
|
WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
|
|
|
|
}
|
|
|
|
ESBYTE[line_break] >< zeroch; //restore line
|
|
|
|
text.start = line_break;
|
|
|
|
stroka_x = HTML_PADDING_X;
|
|
|
|
stroka_y += list.item_h;
|
|
|
|
}
|
|
|
|
if (draw==true) {
|
|
|
|
if (style.a) label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
|
|
|
|
WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
|
|
|
|
}
|
|
|
|
stroka_x += get_label_len(text.start);
|
2016-01-07 17:00:59 +01:00
|
|
|
}
|
|
|
|
if (ch=='>') {
|
2016-01-10 23:33:10 +01:00
|
|
|
ESBYTE[DOM_pos] = '\0';
|
2016-01-07 17:00:59 +01:00
|
|
|
text.start = DOM_pos + 1;
|
|
|
|
tag.parce();
|
2016-01-10 23:33:10 +01:00
|
|
|
if (tag.nameis("br")) || (tag.nameis("p")) || (tag.nameis("div")) || (tag.nameis("h1")) || (tag.nameis("h2")) {
|
|
|
|
stroka_y+= list.item_h;
|
|
|
|
stroka_x = HTML_PADDING_X;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (tag.nameis("script")) || (tag.nameis("style")) style.ignore = true;
|
|
|
|
if (tag.nameis("/script")) || (tag.nameis("/style")) style.ignore = false;
|
|
|
|
if (tag.nameis("a")) { style.a = true; style.color=0x0000FF; }
|
|
|
|
if (tag.nameis("/a")) { style.a = false; style.color=0x000000; }
|
2016-01-07 17:00:59 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-10 23:33:10 +01:00
|
|
|
if (draw==false) {
|
|
|
|
list.count = stroka_y/list.item_h+2;
|
|
|
|
if (list.count < list.visible) list.count = list.visible;
|
|
|
|
label.size.height = list.count+1*list.item_h;
|
|
|
|
label.raw_size = 0;
|
|
|
|
}
|
2016-01-07 17:00:59 +01:00
|
|
|
free(DOM.start);
|
|
|
|
}
|