HTMLv 0.99.6: reorganize structure, fix condition script, disable <right>, <center> (you can use only h1/h2/h3/h4 align="" now)

git-svn-id: svn://kolibrios.org@4475 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2014-01-18 11:46:58 +00:00
parent d8e7f62e43
commit d80753697c
4 changed files with 123 additions and 100 deletions

View File

@ -1,3 +1,4 @@
#include "..\lib\draw_buf.h"
int downloader_id;
@ -19,16 +20,17 @@ char header[2048];
char download_path[]="/rd/1/.download";
struct TWebBrowser {
llist list; //need #include "..\lib\list_box.h"
DrawBufer DrawBuf;
void GetNewUrl();
void ReadHtml(byte);
void ReadHtml();
void ShowPage();
void ParseHTML(dword);
void WhatTextStyle(int left1, top1, width1);
void ParseHTML();
void WhatTextStyle();
void DrawPage();
void DrawScroller();
void TextGoDown();
};
TWebBrowser WB1;
@ -36,6 +38,7 @@ byte rez, b_text, i_text, u_text, s_text, pre_text, blq_text, li_text, li_tab,
link, ignor_text, cur_encoding, text_align;
byte condition_text_active, condition_text_val, condition_href, condition_max;
enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT};
dword text_colors[300];
@ -61,7 +64,8 @@ char anchor[256];
#include "..\TWB\img_cache.h"
#include "..\TWB\some_code.h"
#include "..\TWB\parce_tag.h"
#include "..\TWB\draw_buf.h"
//=======================================================================
@ -85,14 +89,14 @@ void TWebBrowser::DrawPage()
start_y = stroka * 10 + list.y + magrin_left;
line_length = strlen(#line) * 6;
WriteBufText(start_x, 0, 0x88, text_colors[text_color_index], #line, drawbuf);
IF (b_text) WriteBufText(start_x+1, 0, 0x88, text_colors[text_color_index], #line, drawbuf);
IF (i_text) DrawBufSkew(start_x, 0, line_length, list.line_h);
IF (s_text) DrawBufBar(start_x, 4, line_length, 1, text_colors[text_color_index]);
IF (u_text) DrawBufBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
WriteBufText(start_x, 0, 0x88, text_colors[text_color_index], #line, buf_data);
IF (b_text) WriteBufText(start_x+1, 0, 0x88, text_colors[text_color_index], #line, buf_data);
IF (i_text) { stolbec++; DrawBuf.Skew(start_x, 0, line_length, list.line_h); }
IF (s_text) DrawBuf.DrawBar(start_x, 4, line_length, 1, text_colors[text_color_index]);
IF (u_text) DrawBuf.DrawBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
IF (link) {
UnsafeDefineButton(start_x-2, start_y, line_length + 3, 9, blink + BT_HIDE, 0xB5BFC9);
DrawBufBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
DrawBuf.DrawBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
}
stolbec += strlen(#line);
}
@ -204,11 +208,11 @@ void TWebBrowser::ParseHTML(dword bword){
b_text = i_text = u_text = s_text = blq_text =
li_text = link = ignor_text = text_color_index = text_colors[0] = li_tab =
condition_text_val = condition_text_active = 0; //îáíóëÿåì òåãè
condition_max = 10;
condition_max = 255;
text_align = ALIGN_LEFT;
link_color = 0x0000FF;
bg_color = 0xFFFFFF;
DrawBufFill();
DrawBuf.Fill(bg_color);
strcpy(#page_links,"|");
strcpy(#header, #version);
stroka = -list.first;
@ -416,13 +420,13 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (!chTag("body"))
{
do{
if (!strcmp(#parametr, "condition_max=")) { condition_max = options[0]-'0'; debugi(condition_max); }
if (!strcmp(#parametr, "condition_max=")) { condition_max = atoi(#options); debugi(condition_max); }
if (!strcmp(#parametr, "link=")) link_color = GetColor(#options);
if (!strcmp(#parametr, "text=")) text_colors[0]=GetColor(#options);
if (!strcmp(#parametr, "bgcolor="))
{
bg_color=GetColor(#options);
DrawBufFill();
DrawBuf.Fill(bg_color);
}
} while(GetNextParam());
return;
@ -496,6 +500,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
IF(rez) TextGoDown(left1, top1 + 10, width1);
return;
}
/*
if (!chTag("center"))
{
if (rez) text_align = ALIGN_CENTER;
@ -516,6 +521,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
}
return;
}
*/
if (!chTag("h1")) || (!chTag("h2")) || (!chTag("h3")) || (!chTag("h4")) {
TextGoDown(left1, top1, width1);
if (rez) && (stroka>1) TextGoDown(left1, top1 + 10, width1);
@ -563,7 +569,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (rez)
{
TextGoDown(left1, top1, width1);
if (stroka > -1) && (stroka - 2 < list.visible) DrawBufBar(li_tab * 5 * 6 + left1 - 5, list.line_h/2-3, 2, 2, 0x555555);
if (stroka > -1) && (stroka - 2 < list.visible) DrawBuf.DrawBar(li_tab * 5 * 6 + left1 - 5, list.line_h/2-3, 2, 2, 0x555555);
}
return;
}
@ -587,7 +593,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
}
if (strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); else hr_color = 0x999999;
TextGoDown(left1, top1, width1);
DrawBufBar(5, WB1.list.line_h/2, WB1.list.w-10, 1, hr_color);
DrawBuf.DrawBar(5, WB1.list.line_h/2, WB1.list.w-10, 1, hr_color);
TextGoDown(left1, top1+WB1.list.line_h, width1);
}
if (!chTag("img"))
@ -601,7 +607,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding="))
{
strcpy(#options, #options[strrchr(#options, '=')]); //ïîèñê â content=
if (!strcmp(#options,"utf-8")) || (!strcmp(#options,"utf8")) ReadHtml(_UTF);
if (!strcmp(#options, "utf-8")) || (!strcmp(#options,"utf8")) ReadHtml(_UTF);
if (!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u")) ReadHtml(_KOI);
if (!strcmp(#options, "dos")) || (!strcmp(#options, "cp-866")) ReadHtml(_DOS);
}
@ -611,7 +617,6 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
}
void TWebBrowser::DrawScroller() //íå îïòèìàëüíàÿ îòðèñîâêà, íî çàòî â îäíîì ìåñòå
{
scroll_wv.max_area = list.count;
@ -625,3 +630,18 @@ void TWebBrowser::DrawScroller() //
scrollbar_v_draw(#scroll_wv);
}
void TWebBrowser::TextGoDown(int left1, top1, width1)
{
if (!stroka) DrawBar(WB1.list.x, WB1.list.y, WB1.list.w, 5, bg_color); //çàêðàøèâàåì ôîí íàä ïåðâîé ñòðîêîé
if (top1>=WB1.list.y) && ( top1 < WB1.list.h+WB1.list.y-10) && (!anchor)
{
if (text_align == ALIGN_CENTER) DrawBuf.AlignCenter(left1,top1,WB1.list.w,WB1.list.line_h,stolbec * 6);
if (text_align == ALIGN_RIGHT) DrawBuf.AlignRight(left1,top1,WB1.list.w,WB1.list.line_h,stolbec * 6);
PutPaletteImage(buf_data+8, WB1.list.w, WB1.list.line_h, left1-5, top1, 32,0);
DrawBuf.Fill(bg_color);
}
stroka++;
if (blq_text) stolbec = 8; else stolbec = 0;
if (li_text) stolbec = li_tab * 5;
}

View File

@ -1,78 +0,0 @@
dword drawbuf;
void DrawBufInit()
{
free(drawbuf);
drawbuf = malloc(WB1.list.w * WB1.list.line_h +4 * 4 + 8); //+1 for good luck
ESDWORD[drawbuf] = WB1.list.w;
ESDWORD[drawbuf+4] = WB1.list.line_h;
}
void DrawBufFill()
{
int i;
for (i=0; i<WB1.list.w* WB1.list.line_h +4 * 4; i+=4) ESDWORD[drawbuf+i+8] = bg_color;
}
void DrawBufBar(dword x, y, w, h, color)
{
int i, j;
for (j=0; j<h; j++)
{
for (i = y+j*WB1.list.w+x*4; i<y+j*WB1.list.w+x+w*4 ; i+=4) ESDWORD[drawbuf+i+8] = color;
}
}
char shift[]={8,8,4,4};
void DrawBufSkew(dword x, y, w, h)
{
int i, j;
stolbec++;
for (j=0; j<=3; j++)
{
for (i = y+j*WB1.list.w+x+w+h*4; i>y+j*WB1.list.w+x+h-12*4 ; i-=4)
ESDWORD[drawbuf+i+8] = ESDWORD[-shift[j]+drawbuf+i+8];
}
}
void DrawBufAlignRight(dword x,y,w,h)
{
int i, j, l;
int content_width = stolbec * 6;
int content_left = w - content_width / 2;
for (j=0; j<h; j++)
{
for (i=j*w+w-x*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4)
{
ESDWORD[drawbuf+8+i] >< ESDWORD[drawbuf+8+l];
}
}
}
void DrawBufAlignCenter(dword x,y,w,h)
{
int i, j, l;
int content_width = stolbec * 6;
int content_left = w - content_width / 2;
for (j=0; j<h; j++)
{
for (i=j*w+content_width+content_left*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4)
{
ESDWORD[drawbuf+8+i] >< ESDWORD[drawbuf+8+l];
}
}
}
void TextGoDown(int left1, top1, width1)
{
if (!stroka) DrawBar(WB1.list.x, WB1.list.y, WB1.list.w, 5, bg_color); //çàêðàøèâàåì ôîí íàä ïåðâîé ñòðîêîé
if (top1>=WB1.list.y) && ( top1 < WB1.list.h+WB1.list.y-10) && (!anchor)
{
if (text_align == ALIGN_CENTER) DrawBufAlignCenter(left1,top1,WB1.list.w,WB1.list.line_h);
if (text_align == ALIGN_RIGHT) DrawBufAlignRight(left1,top1,WB1.list.w,WB1.list.line_h);
PutPaletteImage(drawbuf+8, WB1.list.w, WB1.list.line_h, left1-5, top1, 32,0);
DrawBufFill();
}
stroka++;
if (blq_text) stolbec = 8; else stolbec = 0;
if (li_text) stolbec = li_tab * 5;
}

View File

@ -26,11 +26,11 @@
#include "img\URLgoto.txt";
#ifdef LANG_RUS
char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.5";
char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.6";
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤"
#else
char version[]=" Text-based Browser 0.99.5";
char version[]=" Text-based Browser 0.99.6";
?define IMAGES_CACHE_CLEARED "Images cache cleared"
?define T_LAST_SLIDE "This slide is the last"
#endif
@ -178,7 +178,7 @@ void SetElementSizes()
WB1.list.SetSizes(0, 44, Form.width - 10 - scroll_wv.size_x, Form.cheight - 44, 0, 10);
WB1.list.column_max = WB1.list.w - 30 / 6;
WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2;
DrawBufInit();
WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h, WB1.list.line_h);
}

View File

@ -0,0 +1,81 @@
dword buf_data;
struct DrawBufer {
int bufx, bufy, bufw, bufh, buf_line_h;
void Init();
void Fill();
void Skew();
void DrawBar();
void AlignCenter();
void AlignRight();
};
void DrawBufer::Init(int i_bufx, i_bufy, i_bufw, i_bufh, i_buf_line_h)
{
bufx = i_bufx;
bufy = i_bufy;
bufw = i_bufw;
bufh = i_bufh;
buf_line_h = i_buf_line_h;
free(buf_data);
buf_data = malloc(bufw * buf_line_h +4 * 4 + 8); //+1 for good luck
ESDWORD[buf_data] = bufw;
ESDWORD[buf_data+4] = buf_line_h;
}
void DrawBufer::Fill(dword fill_color)
{
int i;
int max_i = bufw * buf_line_h + 4 * 4 + buf_data;
for (i=buf_data; i<max_i; i+=4) ESDWORD[i+8] = fill_color;
}
void DrawBufer::DrawBar(dword x, y, w, h, color)
{
int i, j;
for (j=0; j<h; j++)
{
for (i = y+j*bufw+x*4; i<y+j*bufw+x+w*4 ; i+=4) ESDWORD[buf_data+i+8] = color;
}
}
char shift[]={8,8,4,4};
void DrawBufer::Skew(dword x, y, w, h)
{
int i, j;
for (j=0; j<=3; j++)
{
for (i = y+j*bufw+x+w+h*4; i>y+j*bufw+x+h-12*4 ; i-=4)
ESDWORD[buf_data+i+8] = ESDWORD[-shift[j]+buf_data+i+8];
}
}
void DrawBufer::AlignRight(dword x,y,w,h, content_width)
{
int i, j, l;
int content_left = w - content_width / 2;
for (j=0; j<h; j++)
{
for (i=j*w+w-x*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4)
{
ESDWORD[buf_data+8+i] >< ESDWORD[buf_data+8+l];
}
}
}
void DrawBufer::AlignCenter(dword x,y,w,h, content_width)
{
int i, j, l;
int content_left = w - content_width / 2;
for (j=0; j<h; j++)
{
for (i=j*w+content_width+content_left*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4)
{
ESDWORD[buf_data+8+i] >< ESDWORD[buf_data+8+l];
}
}
}