]> granicus.if.org Git - graphviz/commitdiff
Add front-end code to support underlines, bold and italic fonts.
authorerg <devnull@localhost>
Tue, 23 Jun 2009 03:22:09 +0000 (03:22 +0000)
committererg <devnull@localhost>
Tue, 23 Jun 2009 03:22:09 +0000 (03:22 +0000)
lib/common/htmllex.c
lib/common/htmlparse.y
lib/common/htmltable.h

index 08c59bb9bb208e2fa6cd55b66c1e2208c25e67cb..9c5c43693fb6b77da5034481de34d770d3e31bea 100644 (file)
@@ -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>");
+    font->flags = flags;
+    font->ul = ul;
+    if (atts)
+       doAttrs(font, font_items, sizeof(font_items) / ISIZE, atts, "<FONT>");
 
     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 = "<unknown>";
     }
index e142ef2ad8d8ce451232aaaf43f811b8c910645c..9ba6a18f70c3a5251f0259a4b8ca054d26864bc2 100644 (file)
@@ -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 <i> T_BR T_br
 %token <img> T_IMG T_img
 %token <tbl> T_table
 %token <cell> T_cell
-%token <font> T_font
+%token <font> T_font T_italic T_bold T_underline
 
 %type <txt> fonttext
 %type <i> 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 
index 8b88ad247f2d3c60546e08b254a3c0e410b6ca8d..a4bcdc94165933ff71ad21d39055140c5798c344 100644 (file)
@@ -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