summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--src/html.cc3
-rw-r--r--src/plain.cc54
3 files changed, 43 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index f88144bb..af89174a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -54,6 +54,7 @@ dillo-fltk2
- FTP dpi: Fixed algorithm bugs and improved the mime-type detector.
- CCC: added reentrancy control to the OpEnd and OpAbort operations.
- CCC: enhanced the debug function and implemented OpAbort for dpi.
+ - Hooked a decoder for text/plain with charset.
Patches: Jorge Arellano Cid
+- Connected signals to <li> elements (fixes links within lists).
- Enabled text, background-color, panel_size, geometry, fullscreen,
diff --git a/src/html.cc b/src/html.cc
index a478f62f..9841e9d0 100644
--- a/src/html.cc
+++ b/src/html.cc
@@ -936,8 +936,7 @@ void DilloHtml::write(char *Buf, int BufSize, int Eof)
len = new_text->len;
}
dStr_append_l(Local_Buf, str, len);
- if (decoder)
- dStr_free(new_text, 1);
+ dStr_free(new_text, 1);
token_start = Html_write_raw(this, Local_Buf->str + Local_Ofs,
Local_Buf->len - Local_Ofs, Eof);
diff --git a/src/plain.cc b/src/plain.cc
index 0c8a528e..6ef7c889 100644
--- a/src/plain.cc
+++ b/src/plain.cc
@@ -22,6 +22,7 @@
#include "bw.h"
#include "web.hh"
#include "misc.h"
+#include "decode.h"
#include "uicmd.hh"
@@ -48,12 +49,16 @@ public:
BrowserWindow *bw;
DilloUrl *url;
+ Decode *decoder;
+ size_t Buf_Consumed;
+ char *content_type, *charset;
+
Widget *dw;
style::Style *widgetStyle;
- size_t Start_Ofs; /* Offset of where to start reading next */
int state;
- DilloPlain(BrowserWindow *bw, const DilloUrl *url);
+ DilloPlain(BrowserWindow *bw, const DilloUrl *url,
+ const char *content_type);
~DilloPlain();
void write(void *Buf, uint_t BufSize, int Eof);
@@ -83,7 +88,8 @@ void a_Plain_free(void *data);
/*
* Diplain constructor.
*/
-DilloPlain::DilloPlain(BrowserWindow *p_bw, const DilloUrl *p_url)
+DilloPlain::DilloPlain(BrowserWindow *p_bw, const DilloUrl *p_url,
+ const char *content_type)
{
style::StyleAttrs styleAttrs;
style::FontAttrs fontAttrs;
@@ -95,9 +101,16 @@ DilloPlain::DilloPlain(BrowserWindow *p_bw, const DilloUrl *p_url)
bw = p_bw;
url = a_Url_dup(p_url);
dw = new Textblock (prefs.limit_text_width);
- Start_Ofs = 0;
state = ST_SeekingEol;
+ MSG("PLAIN content type: %s\n", content_type);
+ this->content_type = dStrdup(content_type);
+ /* get charset */
+ a_Misc_parse_content_type(content_type, NULL, NULL, &charset);
+ /* Initiallize the charset decoder */
+ decoder = a_Decode_charset_init(charset);
+ Buf_Consumed = 0;
+
/* Create the font and attribute for the page. */
fontAttrs.name = prefs.fw_fontname;
fontAttrs.size = (int) rint(12.0 * prefs.font_factor);
@@ -127,6 +140,9 @@ DilloPlain::~DilloPlain()
{
MSG("::~DilloPlain()\n");
a_Url_free(url);
+ a_Decode_free(decoder);
+ dFree(content_type);
+ dFree(charset);
widgetStyle->unref();
}
@@ -153,12 +169,24 @@ void DilloPlain::write(void *Buf, uint_t BufSize, int Eof)
{
char *Start;
char *data;
+ Dstr *new_text = NULL;
uint_t i, len, MaxBytes;
- _MSG("DilloPlain::write Eof=%d\n", Eof);
+ _MSG(" DilloPlain::write Buf=%p, BufSize=%d Buf_Consumed=%d Eof=%d\n",
+ Buf, BufSize, Buf_Consumed, Eof);
+
+ char *str = (char*)Buf + Buf_Consumed;
+ int str_len = BufSize - Buf_Consumed;
- Start = (char*)Buf + Start_Ofs;
- MaxBytes = BufSize - Start_Ofs;
+ /* decode to target charset (UTF-8) */
+ if (decoder) {
+ new_text = a_Decode_process(decoder, str, str_len);
+ str = new_text->str;
+ str_len = new_text->len;
+ }
+
+ Start = str;
+ MaxBytes = str_len;
i = len = 0;
while ( i < MaxBytes ) {
switch ( state ) {
@@ -181,28 +209,28 @@ void DilloPlain::write(void *Buf, uint_t BufSize, int Eof)
break;
}
}
- Start_Ofs += i - len;
if (Eof && len) {
data = dStrndup(Start + i - len, len);
DW2TB(dw)->addText(a_Misc_expand_tabs(data), widgetStyle);
DW2TB(dw)->addParbreak(0, widgetStyle);
dFree(data);
- Start_Ofs += len;
+ len = 0;
}
+ Buf_Consumed = BufSize - len;
+ dStr_free(new_text, 1);
DW2TB(dw)->flush(Eof ? true : false);
-
if (bw)
- a_UIcmd_set_page_prog(bw, Start_Ofs, 1);
+ a_UIcmd_set_page_prog(bw, Buf_Consumed, 1);
}
/*
* Set callback function and callback data for "text/" MIME major-type.
*/
-void *a_Plain_text(const char *type, void *P, CA_Callback_t *Call, void **Data)
+void *a_Plain_text(const char *Type, void *P, CA_Callback_t *Call, void **Data)
{
DilloWeb *web = (DilloWeb*)P;
- DilloPlain *plain = new DilloPlain(web->bw, web->url);
+ DilloPlain *plain = new DilloPlain(web->bw, web->url, Type);
*Call = (CA_Callback_t)Plain_callback;
*Data = (void*)plain;