📄 html.c
字号:
/* todo: Connect it to the form */}static void Html_tag_open_font(DilloHtml *html, char *tag, gint tagsize){#if 1 DwStyle style_attrs, *old_style; /*DwStyleFont font;*/ const char *attrbuf; gint32 color; Html_push_tag(html, tag, tagsize); if (!prefs.force_my_colors) { old_style = html->stack[html->stack_top].style; style_attrs = *old_style; if ((attrbuf = Html_get_attr(html, tag, tagsize, "color"))) { if (!(prefs.force_visited_color && html->InVisitedLink)) { /* use current text color as default */ color = a_Color_parse(attrbuf, style_attrs.color->color_val); style_attrs.color = a_Dw_style_color_new (color, html->bw->main_window->window); } }#if 0 if ((attrbuf = Html_get_attr(html, tag, tagsize, "face"))) { font = *( style_attrs.font ); font.name = attrbuf; style_attrs.font = a_Dw_style_font_new_from_list (&font); }#endif html->stack[html->stack_top].style = a_Dw_style_new (&style_attrs, html->bw->main_window->window); a_Dw_style_unref (old_style); }#else Html_push_tag(html, tag, tagsize);#endif}/* * <B> */static void Html_tag_open_b(DilloHtml *html, char *tag, gint tagsize){ Html_push_tag(html, tag, tagsize); Html_set_top_font(html, NULL, 0, 1, 1);}/* * <STRONG> */static void Html_tag_open_strong(DilloHtml *html, char *tag, gint tagsize){ Html_push_tag(html, tag, tagsize); Html_set_top_font(html, NULL, 0, 1, 1);}/* * <I> */static void Html_tag_open_i(DilloHtml *html, char *tag, gint tagsize){ Html_push_tag(html, tag, tagsize); Html_set_top_font(html, NULL, 0, 2, 2);}/* * <EM> */static void Html_tag_open_em(DilloHtml *html, char *tag, gint tagsize){ Html_push_tag(html, tag, tagsize); Html_set_top_font(html, NULL, 0, 2, 2);}/* * <CITE> */static void Html_tag_open_cite(DilloHtml *html, char *tag, gint tagsize){ Html_push_tag(html, tag, tagsize); Html_set_top_font(html, NULL, 0, 2, 2);}/* * <CENTER> */static void Html_tag_open_center(DilloHtml *html, char *tag, gint tagsize){ a_Dw_page_add_parbreak(DW_PAGE (html->dw), 0, html->stack[(html)->stack_top].style); Html_push_tag(html, tag, tagsize); HTML_SET_TOP_ATTR(html, text_align, DW_STYLE_TEXT_ALIGN_CENTER);}/* * <TT> */static void Html_tag_open_tt(DilloHtml *html, char *tag, gint tagsize){ Html_push_tag(html, tag, tagsize); Html_set_top_font(html, prefs.fw_fontname, 0, 0, 0);}/* * Create a new Image struct and request the image-url to the cache * (If it either hits or misses, is not relevant here; that's up to the * cache functions) */static void Html_tag_open_img(DilloHtml *html, char *tag, gint tagsize){ DilloImage *Image; DilloWeb *Web; DilloUrl *url, *usemap_url; DwPage *page; DwStyle style_attrs; char *width_ptr, *height_ptr, *alt_ptr; const char *attrbuf; gint ClientKey, border; if ( !(attrbuf = Html_get_attr(html, tag, tagsize, "src")) ) return; if (!(url = a_Url_new(attrbuf, URL_STR_(html->linkblock->base_url), 0, 0))) return; page = DW_PAGE (html->dw); width_ptr = NULL; if ((attrbuf = Html_get_attr(html, tag, tagsize, "width"))) width_ptr = g_strdup(attrbuf); height_ptr = NULL; if ((attrbuf = Html_get_attr(html, tag, tagsize, "height"))) height_ptr = g_strdup(attrbuf); alt_ptr = NULL; if ((attrbuf = Html_get_attr(html, tag, tagsize, "alt"))) alt_ptr = g_strdup(attrbuf); usemap_url = NULL; if ((attrbuf = Html_get_attr(html, tag, tagsize, "usemap"))) /* todo: usemap URLs outside of the document are not used. */ usemap_url = a_Url_new(attrbuf, URL_STR_(html->linkblock->base_url),0,0); if ((width_ptr && !height_ptr) || (height_ptr && !width_ptr)) DEBUG_HTML_MSG("Image tag only sepecifies <%s>\n", (width_ptr) ? "width" : "height"); style_attrs = *html->stack[html->stack_top].style; if (html->stack[html->stack_top].style->link != -1 || usemap_url != NULL) { /* Images within links */ border = 1; if ((attrbuf = Html_get_attr(html, tag, tagsize, "border"))) border = strtol (attrbuf, NULL, 10); if (html->stack[html->stack_top].style->link != -1) /* In this case we can use the text color */ a_Dw_style_box_set_border_color (&style_attrs, a_Dw_style_shaded_color_new (style_attrs.color->color_val, html->bw->main_window->window)); else a_Dw_style_box_set_border_color (&style_attrs, a_Dw_style_shaded_color_new (html->linkblock->link_color, html->bw->main_window->window)); a_Dw_style_box_set_border_style (&style_attrs, DW_STYLE_BORDER_SOLID); a_Dw_style_box_set_val (&style_attrs.border_width, border); } /* Add a new image widget to this page */ Image = a_Image_new(0, 0, alt_ptr, html->stack[html->stack_top].current_bg_color); Html_add_widget(html, DW_WIDGET(Image->dw), width_ptr, height_ptr, &style_attrs); Html_connect_signals(html, GTK_OBJECT(Image->dw)); /* Image maps */ if (Html_get_attr(html, tag, tagsize, "ismap")) { /* BUG: if several ISMAP images follow each other without * being separated with a word, only the first one is ISMAPed */ a_Dw_image_set_ismap (Image->dw); //g_print(" Html_tag_open_img: server-side map (ISMAP)\n"); } if (usemap_url) { a_Dw_image_set_usemap (Image->dw, &html->linkblock->maps, usemap_url); a_Url_free (usemap_url); } /* Fill a Web structure for the cache query */ Web = a_Web_new(url); Web->bw = html->bw; Web->Image = Image; Web->flags |= WEB_Image; /* Request image data from the cache */ if ((ClientKey = a_Cache_open_url(Web, NULL, NULL)) != 0) { a_Interface_add_client(html->bw, ClientKey, 0); a_Interface_add_url(html->bw, url, WEB_Image); } a_Url_free(url); g_free(width_ptr); g_free(height_ptr); g_free(alt_ptr);}/* * <map> */static void Html_tag_open_map(DilloHtml *html, char *tag, gint tagsize){ char *hash_name; const char *attrbuf; DilloUrl *url; Html_push_tag(html, tag, tagsize); if (html->InFlags & IN_MAP) { DEBUG_HTML_MSG("nested <map>\n"); } else { if ((attrbuf = Html_get_attr(html, tag, tagsize, "name"))) { hash_name = g_strdup_printf("#%s", attrbuf); url = a_Url_new (hash_name, URL_STR_(html->linkblock->base_url), 0,0); a_Dw_image_map_list_add_map (&html->linkblock->maps, url); a_Url_free (url); g_free(hash_name); } html->InFlags |= IN_MAP; }}/* * ? */static void Html_tag_close_map(DilloHtml *html, char *tag, gint tagsize){ if (!(html->InFlags & IN_MAP)) { DEBUG_HTML_MSG("</map> without <map>\n"); return; } html->InFlags &= ~IN_MAP; Html_pop_tag(html, tag, tagsize);}/* * Read coords in a string and fill a GdkPoint array */static int Html_read_coords(const char *str, GdkPoint *array){ gint i, toggle, pending, coord; const char *tail = str; char *newtail = NULL; i = 0; toggle = 0; pending = 1; while( pending ) { coord = strtol(tail, &newtail, 10); if (toggle) { array[i].y = coord; array[++i].x = 0; toggle = 0; } else { array[i].x = coord; array[i].y = -1; toggle = 1; } if (!*newtail || (coord == 0 && newtail == tail)) { pending = 0; } else { if (*newtail != ',') { DEBUG_HTML_MSG("usemap coords MUST be separated with ','\n"); } tail = newtail + 1; } } return i;}/* * <AREA> */static void Html_tag_open_area(DilloHtml *html, char *tag, gint tagsize){ GdkPoint point[1024]; DilloUrl* url; const char *attrbuf; gint type = DW_IMAGE_MAP_SHAPE_RECT; gint nbpoints, link = -1; if ( (attrbuf = Html_get_attr(html, tag, tagsize, "shape")) ) { if ( g_strcasecmp(attrbuf, "rect") == 0 ) type = DW_IMAGE_MAP_SHAPE_RECT; else if ( g_strcasecmp(attrbuf, "circle") == 0 ) type = DW_IMAGE_MAP_SHAPE_CIRCLE; else if ( g_strncasecmp(attrbuf, "poly", 4) == 0 ) type = DW_IMAGE_MAP_SHAPE_POLY; else type = DW_IMAGE_MAP_SHAPE_RECT; } /* todo: add support for coords in % */ if ( (attrbuf = Html_get_attr(html, tag, tagsize, "coords")) ) { /* Is this a valid poly ? * rect = x0,y0,x1,y1 => 2 * circle = x,y,r => 2 * poly = x0,y0,x1,y1,x2,y2 minimum => 3 */ nbpoints = Html_read_coords(attrbuf, point); } else return; if ( Html_get_attr(html, tag, tagsize, "nohref") ) { link = -1; //g_print("nohref"); } if ((attrbuf = Html_get_attr(html, tag, tagsize, "href"))) { url = a_Url_new(attrbuf, URL_STR_(html->linkblock->base_url), 0, 0); g_return_if_fail ( url != NULL ); if ((attrbuf = Html_get_attr(html, tag, tagsize, "alt"))) a_Url_set_alt(url, attrbuf); link = Html_set_new_link(html, &url); } a_Dw_image_map_list_add_shape(&html->linkblock->maps, type, link, point, nbpoints);}/* * <A> */static void Html_tag_open_a(DilloHtml *html, char *tag, gint tagsize){ DwPage *page; DwStyle style_attrs, *old_style; DilloUrl *url; const char *attrbuf; gint dummy; Html_push_tag(html, tag, tagsize); page = DW_PAGE (html->dw); /* todo: add support for MAP with A HREF */ Html_tag_open_area(html, tag, tagsize); if ( (attrbuf = Html_get_attr(html, tag, tagsize, "href"))) { url = a_Url_new(attrbuf, URL_STR_(html->linkblock->base_url), 0, 0); g_return_if_fail ( url != NULL ); old_style = html->stack[html->stack_top].style; style_attrs = *old_style; if (a_Cache_url_read(url, &dummy)) { html->InVisitedLink = TRUE; style_attrs.color = a_Dw_style_color_new (html->linkblock->visited_color, html->bw->main_window->window); } else { style_attrs.color = a_Dw_style_color_new (html->linkblock->link_color, html->bw->main_window->window); } style_attrs.uline = TRUE; style_attrs.link = Html_set_new_link(html, &url); html->stack[html->stack_top].style = a_Dw_style_new (&style_attrs, html->bw->main_window->window); a_Dw_style_unref (old_style); } if ( (attrbuf = Html_get_attr(html, tag, tagsize, "name"))) { a_Dw_page_add_anchor(page, attrbuf, html->stack[html->stack_top].style); // g_print("Registering ANCHOR: %s\n", attrbuf); }}/* * <A> close function */static void Html_tag_close_a(DilloHtml *html, char *tag, gint tagsize){ html->InVisitedLink = FALSE; Html_pop_tag(html, tag, tagsize);}/* * Insert underlined text in the page. */static void Html_tag_open_u(DilloHtml *html, char *tag, gint tagsize){ Html_push_tag(html, tag, tagsize); HTML_SET_TOP_ATTR (html, uline, TRUE);}/* * Insert strike-through text. Used by <S>, <STRIKE> and <DEL>. */static void Html_tag_open_strike(DilloHtml *html, char *tag, gint tagsize){ Html_push_tag(html, tag, tagsize); HTML_SET_TOP_ATTR (html, strike, TRUE);}/* * <BLOCKQUOTE> */static void Html_tag_open_blockquote(DilloHtml *html, char *tag, gint tagsize){ Html_par_push_tag(html, tag, tagsize); Html_add_indented(ht
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -