From: erg Date: Tue, 23 Jun 2009 03:22:09 +0000 (+0000) Subject: Add front-end code to support underlines, bold and italic fonts. X-Git-Tag: LAST_LIBGRAPH~32^2~1896 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=789ca2fea04b290af0de4dca3606070607df2ee8;p=graphviz Add front-end code to support underlines, bold and italic fonts. --- diff --git a/lib/common/htmllex.c b/lib/common/htmllex.c index 08c59bb9b..9c5c43693 100644 --- a/lib/common/htmllex.c +++ b/lib/common/htmllex.c @@ -488,12 +488,15 @@ static htmlimg_t *mkImg(char **atts) return img; } -static htmlfont_t *mkFont(char **atts) +static htmlfont_t *mkFont(char **atts, int flags, int ul) { htmlfont_t *font = NEW(htmlfont_t); font->size = -1.0; /* unassigned */ - doAttrs(font, font_items, sizeof(font_items) / ISIZE, atts, ""); + font->flags = flags; + font->ul = ul; + if (atts) + doAttrs(font, font_items, sizeof(font_items) / ISIZE, atts, ""); return font; } @@ -535,8 +538,17 @@ static void startElement(void *user, const char *name, char **atts) htmllval.cell = mkCell(atts); state.tok = T_cell; } else if (strcasecmp(name, "FONT") == 0) { - htmllval.font = mkFont(atts); + htmllval.font = mkFont(atts, 0, 0); state.tok = T_font; + } else if (strcasecmp(name, "B") == 0) { + htmllval.font = mkFont(0, HTML_BF, 0); + state.tok = T_bold; + } else if (strcasecmp(name, "U") == 0) { + htmllval.font = mkFont(0, 0, 1); + state.tok = T_underline; + } else if (strcasecmp(name, "I") == 0) { + htmllval.font = mkFont(0, HTML_IF, 0); + state.tok = T_italic; } else if (strcasecmp(name, "BR") == 0) { mkBR(atts); state.tok = T_br; @@ -565,6 +577,12 @@ static void endElement(void *user, const char *name) state.tok = T_end_html; } else if (strcasecmp(name, "FONT") == 0) { state.tok = T_end_font; + } else if (strcasecmp(name, "B") == 0) { + state.tok = T_n_bold; + } else if (strcasecmp(name, "U") == 0) { + state.tok = T_n_underline; + } else if (strcasecmp(name, "I") == 0) { + state.tok = T_n_italic; } else if (strcasecmp(name, "BR") == 0) { if (state.tok == T_br) state.tok = T_BR; @@ -776,6 +794,24 @@ static void printTok(int tok) case T_IMG: s = "T_IMG"; break; + case T_underline: + s = "T_underline"; + break; + case T_n_underline: + s = "T_underline"; + break; + case T_italic: + s = "T_italic"; + break; + case T_n_italic: + s = "T_italic"; + break; + case T_bold: + s = "T_bold"; + break; + case T_n_bold: + s = "T_bold"; + break; default: s = ""; } diff --git a/lib/common/htmlparse.y b/lib/common/htmlparse.y index e142ef2ad..9ba6a18f7 100644 --- a/lib/common/htmlparse.y +++ b/lib/common/htmlparse.y @@ -382,6 +382,10 @@ pushFont (htmlfont_t *f) f->size = curfont->size; if (!f->name && curfont->name) f->name = strdup(curfont->name); + if (!f->flags && curfont->flags) + f->flags = curfont->flags; + if (!f->ul && curfont->ul) + f->ul = curfont->ul; } ft->cfont = dupFont (f); @@ -415,11 +419,12 @@ popFont (void) %token T_end_br T_end_img T_row T_end_row T_html T_end_html %token T_end_table T_end_cell T_end_font T_string T_error +%token T_n_italic T_n_bold T_n_underline %token T_BR T_br %token T_IMG T_img %token T_table %token T_cell -%token T_font +%token T_font T_italic T_bold T_underline %type fonttext %type br @@ -444,15 +449,36 @@ text : text textitem textitem : string { appendFItemList(HTMLstate.str);} | br {appendFLineList($1);} - | sfont text nfont + | font text n_font + | italic text n_italic + | underline text n_underline + | bold text n_bold ; -sfont : T_font { pushFont ($1); } +font : T_font { pushFont ($1); } ; -nfont : T_end_font { popFont (); } +n_font : T_end_font { popFont (); } ; +italic : T_italic {pushFont($1);} + ; + +n_italic : T_n_italic {popFont();} + ; + +bold : T_bold {pushFont($1);} + ; + +n_bold : T_n_bold {popFont();} + ; + +underline : T_underline {pushFont($1);} + ; + +n_underline : T_n_underline {popFont();} + ; + br : T_br T_end_br { $$ = $1; } | T_BR { $$ = $1; } ; @@ -483,7 +509,10 @@ table : opt_space T_table { ; fonttable : table { $$ = $1; } - | sfont table nfont { $$=$2; } + | font table n_font { $$=$2; } + | italic table n_italic { $$=$2; } + | underline table n_underline { $$=$2; } + | bold table n_bold { $$=$2; } ; opt_space : string diff --git a/lib/common/htmltable.h b/lib/common/htmltable.h index 8b88ad247..a4bcdc941 100644 --- a/lib/common/htmltable.h +++ b/lib/common/htmltable.h @@ -38,6 +38,9 @@ extern "C" { #define UNSET_ALIGN 0 +#define HTML_BF 1 +#define HTML_IF 2 + /* font information * If name or color is NULL, or size < 0, that attribute * is unspecified. @@ -45,8 +48,10 @@ extern "C" { typedef struct { char* name; char* color; - double size; + int flags:3; + int ul:1; int cnt; /* reference count */ + double size; } htmlfont_t; /* paras of text within a cell