HTMLv 0.70b: universal function for detecting colors

git-svn-id: svn://kolibrios.org@2238 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2011-09-26 11:41:07 +00:00
parent 8908070ea6
commit aec194c6f0
5 changed files with 141 additions and 77 deletions

View File

@ -15,17 +15,17 @@
#include "../lib/dll.h--" #include "../lib/dll.h--"
//ïåğåìåííûå //ïåğåìåííûå
byte URL[4096]="/sys/index.htm", char URL[4096]="/sys/index.htm",
editURL[4096], editURL[4096],
page_links[12000], page_links[12000],
header[512]; header[512];
dword max_kolvo_strok, int max_kolvo_strok,
max_kolvo_stolbcov, max_kolvo_stolbcov,
kolichestvo; count;
int za_kadrom, int za_kadrom,
razm_scrl, scroll_size,
mouse_dd; mouse_dd;
edit_box edit1= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,248,#editURL,#mouse_dd,2,19,19}; edit_box edit1= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,248,#editURL,#mouse_dd,2,19,19};
@ -71,22 +71,22 @@ void main()
} }
IF (m.vert==1) IF (m.vert==1)
{ {
IF(max_kolvo_strok+za_kadrom+3>=kolichestvo) WB1.Scan(181); IF(max_kolvo_strok+za_kadrom+3>=count) WB1.Scan(181);
ELSE { ELSE {
za_kadrom+=2; za_kadrom+=2;
WB1.Scan(ID2); WB1.Scan(ID2);
} }
} }
//IF (kolichestvo<max_kolvo_strok) break; //IF (count<max_kolvo_strok) break;
if (m.x>=WB1.width-14) && (m.x<=WB1.width+6) if (m.x>=WB1.width-14) && (m.x<=WB1.width+6)
&& (m.y>WB1.top+16) && (m.y<WB1.top+WB1.height-16) && (m.y>WB1.top+16) && (m.y<WB1.top+WB1.height-16)
&& (kolichestvo>max_kolvo_strok) while (m.lkm) && (count>max_kolvo_strok) while (m.lkm)
{ {
IF (razm_scrl/2+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=razm_scrl/2+WB1.top; //åñëè êóðñîð íàä îêíîì IF (scroll_size/2+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=scroll_size/2+WB1.top; //åñëè êóðñîð íàä îêíîì
btn=za_kadrom; //ñîõğàíÿåì ñòàğîå êîëè÷åñòâî btn=za_kadrom; //ñîõğàíÿåì ñòàğîå êîëè÷åñòâî
j= razm_scrl/2; j= scroll_size/2;
za_kadrom = m.y -j -WB1.top * kolichestvo / WB1.height; za_kadrom = m.y -j -WB1.top * count / WB1.height;
IF (max_kolvo_strok+za_kadrom>kolichestvo) za_kadrom=kolichestvo-max_kolvo_strok; IF (max_kolvo_strok+za_kadrom>count) za_kadrom=count-max_kolvo_strok;
IF (btn<>za_kadrom) WB1.ParseHTML(buf, filesize); //÷òîá ëèøíèé ğàç íå ïåğåğèñîâûâàòü IF (btn<>za_kadrom) WB1.ParseHTML(buf, filesize); //÷òîá ëèøíèé ğàç íå ïåğåğèñîâûâàòü
m.get(); m.get();
} }
@ -147,8 +147,8 @@ void Draw_Window()
WindowRedrawStatus(2); WindowRedrawStatus(2);
} }
int onLeft(dword right,left) {EAX=Form.width-right-left;} int onLeft(dword right,left) {return Form.width-right-left;}
int onTop(dword down,up) {EAX=Form.height-GetSkinWidth()-down-up;} int onTop(dword down,up) {return Form.height-GetSkinWidth()-down-up;}
stop: stop:

View File

@ -1,3 +1,6 @@
26.09.11 -- v0.70b -- 11.4 Кб
- универсальная обработка цветов.
22.09.11 -- v0.70 -- 11.3 Кб 22.09.11 -- v0.70 -- 11.3 Кб
- улучшен и оптимизирован код обработки юникодовских тегов (&amp;), исправлен - улучшен и оптимизирован код обработки юникодовских тегов (&amp;), исправлен
и дополнен их список; и дополнен их список;

View File

@ -35,6 +35,24 @@ struct TWebBrowser {
TWebBrowser WB1; TWebBrowser WB1;
byte rez, b_text, i_text, u_text, s_text, w_title, pre_text, blq_text, li_text, link, ignor_text, li_tab;
dword text_colors[10],
text_color_index = 0,
link_color;
int stroka,
stolbec,
tab_len;
char line[330],
tag[100],
tagparam[10000],
parametr[1200],
options[1000];
#include "include\history.h--" #include "include\history.h--"
#include "include\colors.h--" #include "include\colors.h--"
#include "include\unicode_tags.h--" #include "include\unicode_tags.h--"
@ -53,7 +71,7 @@ void TWebBrowser::Scan(dword id) {
return; return;
} }
//edit1.flags=64; //edit1.flags=64;
IF(kolichestvo < max_kolvo_strok) SWITCH(id) { IF(count < max_kolvo_strok) SWITCH(id) {
CASE 183: CASE 184: CASE 180: CASE 181: return; CASE 183: CASE 184: CASE 180: CASE 181: return;
} //åñëè ìàëî ñòðîê èãíîðèðóåì íåêîòîðûå êíîïêè } //åñëè ìàëî ñòðîê èãíîðèðóåì íåêîòîðûå êíîïêè
switch (id) { switch (id) {
@ -100,13 +118,13 @@ void TWebBrowser::Scan(dword id) {
ELSE return; ELSE return;
break; break;
case ID2: //ìîòàåì âíèç case ID2: //ìîòàåì âíèç
IF(max_kolvo_strok + za_kadrom >= kolichestvo) return; IF(max_kolvo_strok + za_kadrom >= count) return;
za_kadrom++; za_kadrom++;
break; break;
case 183: //PgDown case 183: //PgDown
IF(za_kadrom == kolichestvo - max_kolvo_strok) return; IF(za_kadrom == count - max_kolvo_strok) return;
za_kadrom = za_kadrom + max_kolvo_strok + 2; za_kadrom = za_kadrom + max_kolvo_strok + 2;
IF(max_kolvo_strok + za_kadrom > kolichestvo) za_kadrom = kolichestvo - max_kolvo_strok; IF(max_kolvo_strok + za_kadrom > count) za_kadrom = count - max_kolvo_strok;
BREAK; BREAK;
case 184: //PgUp case 184: //PgUp
IF(za_kadrom == 0) RETURN; IF(za_kadrom == 0) RETURN;
@ -118,7 +136,7 @@ void TWebBrowser::Scan(dword id) {
ELSE RETURN; ELSE RETURN;
BREAK; BREAK;
case 181: //end case 181: //end
za_kadrom = kolichestvo - max_kolvo_strok; za_kadrom = count - max_kolvo_strok;
BREAK; BREAK;
default: default:
RETURN; RETURN;
@ -134,19 +152,19 @@ void TWebBrowser::DrawScroller() {
DrawFlatButton(left + width - 15, top + height - 17, 16, 16, ID2, 0xE4DFE1, "\x19"); DrawFlatButton(left + width - 15, top + height - 17, 16, 16, ID2, 0xE4DFE1, "\x19");
DrawFlatButton(left + width - 15, top, 16, 16, ID1, 0xE4DFE1, "\x18"); DrawFlatButton(left + width - 15, top, 16, 16, ID1, 0xE4DFE1, "\x18");
IF(kolichestvo <= max_kolvo_strok) { IF(count <= max_kolvo_strok) {
DrawBar(left + width - 14, top + 17, 16, height - 34, 0xCED0D0); DrawBar(left + width - 14, top + 17, 16, height - 34, 0xCED0D0);
return; return;
} }
razm_scrl = height - 16 * max_kolvo_strok / kolichestvo - 3; scroll_size = height - 16 * max_kolvo_strok / count - 3;
IF(razm_scrl < 10) razm_scrl = 10; IF(scroll_size < 10) scroll_size = 10;
IF(za_kadrom + max_kolvo_strok >= kolichestvo) on_y = height - razm_scrl + top - 17; IF(za_kadrom + max_kolvo_strok >= count) on_y = height - scroll_size + top - 17;
ELSE on_y = height - 32 * za_kadrom / kolichestvo + top + 16; ELSE on_y = height - 32 * za_kadrom / count + top + 16;
DrawFlatButton(left + width - 15, on_y, 16, razm_scrl, 0, 0xE4DFE1, ""); //ïîëçóíîê DrawFlatButton(left + width - 15, on_y, 16, scroll_size, 0, 0xE4DFE1, ""); //ïîëçóíîê
IF(on_y > top + 17) DrawBar(left + width - 14, top + 17, 16, on_y - top - 17, 0xCED0D0); //ïîëå äî ïîëçóíêà IF(on_y > top + 17) DrawBar(left + width - 14, top + 17, 16, on_y - top - 17, 0xCED0D0); //ïîëå äî ïîëçóíêà
IF(height - razm_scrl + top - 17 > on_y) IF(height - scroll_size + top - 17 > on_y)
DrawBar(left + width - 14, on_y + razm_scrl + 1, 16, height - razm_scrl - on_y + top - 18, 0xCED0D0); //ïîëå ïîñëå ïîëçóíêà DrawBar(left + width - 14, on_y + scroll_size + 1, 16, height - scroll_size - on_y + top - 18, 0xCED0D0); //ïîëå ïîñëå ïîëçóíêà
} }
@ -162,7 +180,7 @@ void GetNewUrl(){
{ {
copystr(BrowserHistory.CurrentUrl(), #editURL); //äîñòà¸ì àäðåñ òåêóùåé ñòðàíèöû copystr(BrowserHistory.CurrentUrl(), #editURL); //äîñòà¸ì àäðåñ òåêóùåé ñòðàíèöû
IF (editURL[find_symbol(#editURL, '/')-2]<>'/') // åñëè íå http://test.ua IF (editURL[find_symbol(#editURL, '/')-2]<>'/') // åñëè íå http://pagename.ua
{ {
editURL[find_symbol(#editURL, '/')] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî / editURL[find_symbol(#editURL, '/')] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
IF (URL[0]=='/') copystr(#URL+1,#URL); IF (URL[0]=='/') copystr(#URL+1,#URL);
@ -192,6 +210,7 @@ void ReadHtml(byte DO_LOAD)
} }
ELSE file_size stdcall (#URL); ELSE file_size stdcall (#URL);
filesize = EBX; filesize = EBX;
IF (!filesize) return; //Lee 22.09 IF (!filesize) return; //Lee 22.09
mem_Free(buf); mem_Free(buf);
@ -243,23 +262,9 @@ void TWebBrowser::Load(dword adress) {
byte rez, b_text, i_text, u_text, s_text, w_title, pre_text, blq_text, li_text, link, ignor_text, li_tab;
dword text_colors[10],
text_color_index = 0,
link_color;
int stroka,
stolbec,
tab_len;
byte line[330],
tag[100],
tagparam[10000],
parametr[1200],
options[1000];
byte ignor_param = 0;
void TWebBrowser::ParseHTML(dword bword, fsize){ void TWebBrowser::ParseHTML(dword bword, fsize){
word bukva[1]; word bukva[1];
byte ignor_param = 0;
char temp[768]; char temp[768];
stroka = -za_kadrom; stroka = -za_kadrom;
stolbec = 0; stolbec = 0;
@ -428,7 +433,7 @@ void TWebBrowser::ParseHTML(dword bword, fsize){
DrawBar(left, max_kolvo_strok * 10 + top + 25, width - 15, -max_kolvo_strok * 10 + height - 25, 0xFFFFFF); DrawBar(left, max_kolvo_strok * 10 + top + 25, width - 15, -max_kolvo_strok * 10 + height - 25, 0xFFFFFF);
IF(stroka * 10 + 15 <= height) IF(stroka * 10 + 15 <= height)
DrawBar(left, stroka * 10 + top + 15, width - 15, -stroka * 10 + height - 15, 0xFFFFFF); //çàêðàøèâàåì âñ¸ äî êîíöà DrawBar(left, stroka * 10 + top + 15, width - 15, -stroka * 10 + height - 15, 0xFFFFFF); //çàêðàøèâàåì âñ¸ äî êîíöà
IF(za_kadrom == 0) kolichestvo = stroka; IF(za_kadrom == 0) count = stroka;
DrawScroller(); //ðèñóåì ñêðîëë DrawScroller(); //ðèñóåì ñêðîëë
} }
@ -483,10 +488,15 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
char temp[4096]; char temp[4096];
int w, h, img_za_kadrom=0; int w, h, img_za_kadrom=0;
IF(tag[0] == '/') { //ïðîâåðÿåì òåã îòêðûâàåòñÿ èëè çàêðûâàåòñÿ
IF(tag[0] == '/')
{
rez = 0; rez = 0;
copystr(#tag + 1, #tag); copystr(#tag + 1, #tag);
} ELSE rez = 1; }
ELSE
rez = 1;
// //
IF(!chTag("html")) { IF(!chTag("html")) {
IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (rez==0) ignor_text = 1; ELSE ignor_text = 0; IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (rez==0) ignor_text = 1; ELSE ignor_text = 0;
@ -496,7 +506,8 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
IF (ignor_text == 1) return; IF (ignor_text == 1) return;
// //
if(!chTag("title")) IF(w_title == 0) { if(!chTag("title")) IF(w_title == 0)
{
copystr(" ", #line); copystr(" ", #line);
w_title = 1; w_title = 1;
} }
@ -510,12 +521,16 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
//äà, çíàþ, 2 ðàçà âûõîäèò, íî, åñëè áîëüøàÿ ñòðàíèöà, òî òðóú //äà, çíàþ, 2 ðàçà âûõîäèò, íî, åñëè áîëüøàÿ ñòðàíèöà, òî òðóú
return; return;
} }
// //
IF(!chTag("q")) copystr("\"", #line + strlen(#line)); IF(!chTag("q")) copystr("\"", #line + strlen(#line));
if (stroka > -1) && (stroka - 2 < max_kolvo_strok) && (line) {
//âûâîä íà ýêðàí
if (stroka >= 0) && (stroka - 2 < max_kolvo_strok) && (line)
{
WriteText(stolbec * 6 + left1, top1, 0x80, text_colors[text_color_index], #line, 0); WriteText(stolbec * 6 + left1, top1, 0x80, text_colors[text_color_index], #line, 0);
IF (b_text) WriteText(stolbec * 6 + left1 + 1, top1, 0x80, text_colors[text_color_index], #line, 0); IF (b_text) WriteText(stolbec * 6 + left1 + 1, top1, 0x80, text_colors[text_color_index], #line, 0);
IF(i_text) Skew(stolbec * 6 + left1, top1, strlen(#line)+1*6, 10); IF (i_text) Skew(stolbec * 6 + left1, top1, strlen(#line)+1*6, 10); //íàêëîííûé òåêñò
IF (s_text) DrawBar(stolbec * 6 + left1, top1 + 4, strlen(#line) * 6, 1, text_colors[text_color_index]); //çà÷¸ðêíóòûé IF (s_text) DrawBar(stolbec * 6 + left1, top1 + 4, strlen(#line) * 6, 1, text_colors[text_color_index]); //çà÷¸ðêíóòûé
IF (u_text) DrawBar(stolbec * 6 + left1, top1 + 8, strlen(#line) * 6, 1, text_colors[text_color_index]); //ïîä÷¸ðêíóòûé IF (u_text) DrawBar(stolbec * 6 + left1, top1 + 8, strlen(#line) * 6, 1, text_colors[text_color_index]); //ïîä÷¸ðêíóòûé
IF (link) { IF (link) {
@ -526,6 +541,31 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
// //
IF(!tag) return; IF(!tag) return;
stolbec += strlen(#line); stolbec += strlen(#line);
////////////////////////// <body bgcolor="#000000" text="#FFFFFF">
if (!chTag("body"))
{
BODY_MARK:
if (strcmp(#parametr, "link=") == 0)
link_color = GetColor(#options);
/*if (strcmp(#parametr, "text=") == 0)
{
text_colors[0]=GetColor(#options);
}
if (strcmp(#parametr, "bgcolor=") == 0)
{
//text_colors[0]=GetColor(#options);
WriteDebug("bgcolor=");
WriteDebug(#options);
}*/
IF(tagparam) {
GetNextParam();
GOTO BODY_MARK;
}
}
////////////////////////// //////////////////////////
if (!chTag("a")) { if (!chTag("a")) {
IF (stroka - 1 > max_kolvo_strok) || (stroka < -2) return; IF (stroka - 1 > max_kolvo_strok) || (stroka < -2) return;
@ -558,25 +598,9 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#') if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#')
{ {
text_color_index++; text_color_index++;
IF (options[0] == '#') text_colors[text_color_index] = GetColor(#options);
{
text_colors[text_color_index] = StrToCol(#options);
} }
ELSE IF(tagparam) {
{
FOR (i=0; color_names[i]!=0; i++)
{
IF(!strcmp(#options, color_names[i]))
{
text_colors[text_color_index] = colors[i];
BREAK;
}
text_colors[text_color_index] = text_colors[0];
}
}
}
IF(tagparam[0] <>'') {
GetNextParam(); GetNextParam();
GOTO COL_MARK; GOTO COL_MARK;
} }
@ -634,12 +658,11 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
} ELSE li_tab++; } ELSE li_tab++;
IF(!chTag("dd")) stolbec += 5; IF(!chTag("dd")) stolbec += 5;
IF(!chTag("blockquote")) blq_text = rez; IF(!chTag("blockquote")) blq_text = rez;
IF(!chTag("body")) IF(strcmp(#parametr, "link=") == 0) link_color = StrToCol(#options);
IF(!chTag("pre")) pre_text = rez; IF(!chTag("pre")) pre_text = rez;
IF(!chTag("hr")) { IF(!chTag("hr")) {
TextGoDown(left1, top1, width1); TextGoDown(left1, top1, width1);
TextGoDown(left1, top1 + 10, width1); TextGoDown(left1, top1 + 10, width1);
IF(strcmp(#parametr, "color=") == 0) hr_color = StrToCol(#options); IF(strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options);
ELSE hr_color = 0x999999; ELSE hr_color = 0x999999;
IF(stroka > 0) DrawBar(left1, top1 + 14, width1 - 8, 1, hr_color); IF(stroka > 0) DrawBar(left1, top1 + 14, width1 - 8, 1, hr_color);
} }
@ -714,7 +737,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
ReadHtml(DONT_LOAD); ReadHtml(DONT_LOAD);
} }
} }
IF(tagparam[0] <>'') IF(tagparam)
{ {
GetNextParam(); GetNextParam();
goto META; goto META;

View File

@ -5,7 +5,7 @@
<title>Çàãîëîâîê ýòîãî äîêóìåíòà</title> <title>Çàãîëîâîê ýòîãî äîêóìåíòà</title>
</head> </head>
<body bgcolor="#000000" text="#FFFFFF"> <body bgcolor="#000000" link="#0066FF" text="#FFFFFF">
<b>Ýòî òåñòîâàÿ ñòðàíèöà äëÿ ïðîâåðêè HTML Viewer</b><br /> <b>Ýòî òåñòîâàÿ ñòðàíèöà äëÿ ïðîâåðêè HTML Viewer</b><br />
<br /> <br />
@ -19,7 +19,7 @@
<font color="#9EFC36">a</font> <font color="#9EFC36">a</font>
<font color="#29FDFD">t</font> <font color="#29FDFD">t</font>
<font color="#36A8FC">e</font> <font color="#36A8FC">e</font>
<font color="#C911FF">d </font> <font color="blueviolet">d </font>
<font color="#C911FF">b</font> <font color="#C911FF">b</font>
<font color= #C911FF >y </font> <font color= #C911FF >y </font>
<font color="#C911FF">L</font> <font color="#C911FF">L</font>
@ -27,9 +27,9 @@
<font color="#29FDFD">e</font> <font color="#29FDFD">e</font>
<font color="#9EFC36">n</font> <font color="#9EFC36">n</font>
<font color="#FFC005">c</font> <font color="#FFC005">c</font>
<font color="#FF0000">y</font><br> <font color="red">y</font><br>
</b> </b>
Æèòîìèð 2008 Æèòîìèð 2008-2011
<p> <p>
Íåáîëüøîé ñïèñîê:<ol> Íåáîëüøîé ñïèñîê:<ol>
@ -55,6 +55,7 @@
 ýòîì òåêñòå åñòü ïåðåõîä íà ñëåäóþùóþ ñòðîêó, íî áðàóçåð  ýòîì òåêñòå åñòü ïåðåõîä íà ñëåäóþùóþ ñòðîêó, íî áðàóçåð
åãî äîëæåí ïðîèãíîðèðîâàòü. Åùå ìíîãî ïðîáåëîâ. À òóò åñòü åãî äîëæåí ïðîèãíîðèðîâàòü. Åùå ìíîãî ïðîáåëîâ. À òóò åñòü
òàáû. Êîå-êàêèå ñèìâîëû: &quot; &amp; &lt; &gt; &#149; &nbsp; &copy; &reg; &bdquo; &ldquo; &#151; ¯æà÷îê ³íøîãî áîêó ð. ªâôðàò ç'¿â ´ðóíò òà ºâðåéñüêèé ´åðáàëàéô. òàáû. Êîå-êàêèå ñèìâîëû: &quot; &amp; &lt; &gt; &#149; &nbsp; &copy; &reg; &bdquo; &ldquo; &#151; ¯æà÷îê ³íøîãî áîêó ð. ªâôðàò ç'¿â ´ðóíò òà ºâðåéñüêèé ´åðáàëàéô.
<hr color="grey">
<p><a href='index.htm'>Íà ãëàâíóþ ñòðàíèöó</a></p> <p><a href='index.htm'>Íà ãëàâíóþ ñòðàíèöó</a></p>
<p><a href="index.htm" id="#end">×òåíèå íå ïîñëåäíåãî òåãà</a></p> <p><a href="index.htm" id="#end">×òåíèå íå ïîñëåäíåãî òåãà</a></p>

View File

@ -287,3 +287,40 @@ dword *colors[]={
0xf5f5f5, 0xf5f5f5,
0xffff00, 0xffff00,
0x9acd32}; 0x9acd32};
dword StrToCol(char* htmlcolor)
{
dword j=1, color=0;
char ch=0x00;
IF (ESBYTE[htmlcolor]<>'#') RETURN;
FOR (;j<7;j++)
{
ch=ESBYTE[htmlcolor+j];
IF ((ch>='0') && (ch<='9')) ch -= '0';
IF ((ch>='A') && (ch<='F')) ch -= 'A'-10;
IF ((ch>='a') && (ch<='f')) ch -= 'a'-10;
color = color*0x10 + ch;
}
return color;
}
dword GetColor(char* color_str)
{
int ii;
IF (ESBYTE[color_str] == '#')
return StrToCol(color_str);
ELSE
FOR (ii=0; color_names[ii]!=0; ii++)
{
IF(!strcmp(color_str, color_names[ii]))
{
return colors[ii];
}
}
return text_colors[0];
}