From 7d52dfd5874f1fbc6cd4995a1c9fe7a112641d7f Mon Sep 17 00:00:00 2001 From: "Emden R. Gansner" Date: Sun, 15 Sep 2013 17:00:30 -0400 Subject: [PATCH] Add element to html-like labels --- doc/info/shapes.html | 19 ++++++++++++++++--- doc/infosrc/html.1 | 8 +++++--- doc/infosrc/html.2 | 6 ++++++ doc/infosrc/html_grammar | 2 +- lib/common/htmllex.c | 17 ++++++++++++++--- lib/common/htmlparse.y | 11 +++++++++-- lib/common/textpara.h | 7 ++++--- plugin/core/gvrender_core_svg.c | 13 +++++++++++-- plugin/pango/gvtextlayout_pango.c | 2 ++ 9 files changed, 68 insertions(+), 17 deletions(-) diff --git a/doc/info/shapes.html b/doc/info/shapes.html index 3a19e3c37..8424d7a2b 100644 --- a/doc/info/shapes.html +++ b/doc/info/shapes.html @@ -400,10 +400,12 @@ that are newer than mid-November 2003. In particular, it is not part of release 1.10.

NOTE:The font markups for bold, italic, underlining, subscript and -superscript (<B>, <I>, <U>, <SUB>; and <SUP>) -are only available in versions after 14 October 2011, and are +superscript (<B>, <I>, <U>, <SUB> and <SUP>) +are only available in versions after 14 October 2011, and +the markup for strike-through (<S>) requires versions later than 15 September 2013. +In addition, all of these markups are currently only available via the cairo and svg renderers. -In addition, the horizontal and vertical rules (<HR> and <VR>) +The horizontal and vertical rules (<HR> and <VR>) are only available in versions later than 8 July 2011. @@ -515,6 +517,11 @@ Note that, as in HTML, element and attribute names are case-insensitive. | <SUP> text </SUP> + + + | + <S> text </S> + table : @@ -701,6 +708,12 @@ Attribute values must appear in double quotes. <!-- No attributes --> > +

+ <!-- Strike-through text --> +

<S
+  <!-- No attributes -->
+>
+

<!-- Horizontal rule -->

<HR
diff --git a/doc/infosrc/html.1 b/doc/infosrc/html.1
index c043a0dbd..568199c90 100644
--- a/doc/infosrc/html.1
+++ b/doc/infosrc/html.1
@@ -5,10 +5,12 @@ that are newer than mid-November 2003. In particular, it is not part
 of release 1.10.
 

NOTE:The font markups for bold, italic, underlining, subscript and -superscript (<B>, <I>, <U>, <SUB>; and <SUP>) -are only available in versions after 14 October 2011, and are +superscript (<B>, <I>, <U>, <SUB> and <SUP>) +are only available in versions after 14 October 2011, and +the markup for strike-through (<S>) requires versions later than 15 September 2013. +In addition, all of these markups are currently only available via the cairo and svg renderers. -In addition, the horizontal and vertical rules (<HR> and <VR>) +The horizontal and vertical rules (<HR> and <VR>) are only available in versions later than 8 July 2011. diff --git a/doc/infosrc/html.2 b/doc/infosrc/html.2 index 9d72896f8..49e6517ac 100644 --- a/doc/infosrc/html.2 +++ b/doc/infosrc/html.2 @@ -134,6 +134,12 @@ Attribute values must appear in double quotes. <!-- No attributes --> >

+

+ <!-- Strike-through text --> +

<S
+  <!-- No attributes -->
+>
+

<!-- Horizontal rule -->

<HR
diff --git a/doc/infosrc/html_grammar b/doc/infosrc/html_grammar
index f0bdee60d..d1699c8e0 100644
--- a/doc/infosrc/html_grammar
+++ b/doc/infosrc/html_grammar
@@ -1,6 +1,6 @@
 label    =  text | table
 text     = textitem | text textitem
-textitem = string | T_<BR/> | T_<FONT> text T_</FONT> | T_<I> text T_</I> | T_<B> text T_</B> | T_<U> text T_</U> | T_<SUB> text T_</SUB> |T_<SUP> text T_</SUP>
+textitem = string | T_<BR/> | T_<FONT> text T_</FONT> | T_<I> text T_</I> | T_<B> text T_</B> | T_<U> text T_</U> | T_<SUB> text T_</SUB> |T_<SUP> text T_</SUP> | T_<S> text T_</S>
 table =  [ T_<FONT> ] T_<TABLE> rows T_</TABLE> [ T_</FONT> ]
 rows = row | rows row | rows T_<HR/> row
 row = T_<TR> cells T_</TR>
diff --git a/lib/common/htmllex.c b/lib/common/htmllex.c
index d0257e0b4..d51c6223f 100644
--- a/lib/common/htmllex.c
+++ b/lib/common/htmllex.c
@@ -617,6 +617,9 @@ static void startElement(void *user, const char *name, char **atts)
     } else if (strcasecmp(name, "B") == 0) {
 	htmllval.font = mkFont(0, HTML_BF, 0);
 	state.tok = T_bold;
+    } else if (strcasecmp(name, "S") == 0) {
+	htmllval.font = mkFont(0, HTML_S, 0);
+	state.tok = T_s;
     } else if (strcasecmp(name, "U") == 0) {
 	htmllval.font = mkFont(0, HTML_UL, 1);
 	state.tok = T_underline;
@@ -671,6 +674,8 @@ static void endElement(void *user, const char *name)
 	state.tok = T_n_sup;
     } else if (strcasecmp(name, "SUB") == 0) {
 	state.tok = T_n_sub;
+    } else if (strcasecmp(name, "S") == 0) {
+	state.tok = T_n_s;
     } else if (strcasecmp(name, "BR") == 0) {
 	if (state.tok == T_br)
 	    state.tok = T_BR;
@@ -914,19 +919,25 @@ static void printTok(int tok)
 	s = "T_underline";
 	break;
     case T_n_underline:
-	s = "T_underline";
+	s = "T_n_underline";
 	break;
     case T_italic:
 	s = "T_italic";
 	break;
     case T_n_italic:
-	s = "T_italic";
+	s = "T_n_italic";
 	break;
     case T_bold:
 	s = "T_bold";
 	break;
     case T_n_bold:
-	s = "T_bold";
+	s = "T_n_bold";
+	break;
+    case T_s:
+	s = "T_s";
+	break;
+    case T_n_s:
+	s = "T_n_s";
 	break;
     default:
 	s = "";
diff --git a/lib/common/htmlparse.y b/lib/common/htmlparse.y
index 880e6fd69..2ed8d9686 100644
--- a/lib/common/htmlparse.y
+++ b/lib/common/htmlparse.y
@@ -436,14 +436,14 @@ 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 T_n_sup T_n_sub
+%token T_n_italic T_n_bold T_n_underline T_n_sup T_n_sub T_n_s
 %token T_HR T_hr T_end_hr
 %token T_VR T_vr T_end_vr
 %token  T_BR T_br
 %token  T_IMG T_img
 %token  T_table
 %token  T_cell
-%token  T_font T_italic T_bold T_underline T_sup T_sub
+%token  T_font T_italic T_bold T_underline T_sup T_sub T_s
 
 %type  fonttext
 %type  cell cells
@@ -476,6 +476,7 @@ textitem : string { appendFItemList(HTMLstate.str);}
          | bold text n_bold
          | sup text n_sup
          | sub text n_sub
+         | strike text n_strike
          ;
 
 font : T_font { pushFont ($1); }
@@ -496,6 +497,12 @@ bold : T_bold {pushFont($1);}
 n_bold : T_n_bold {popFont();}
             ;
 
+strike : T_s {pushFont($1);}
+          ;
+
+n_strike : T_n_s {popFont();}
+            ;
+
 underline : T_underline {pushFont($1);}
           ;
 
diff --git a/lib/common/textpara.h b/lib/common/textpara.h
index 08ed6f298..3d98a26fb 100644
--- a/lib/common/textpara.h
+++ b/lib/common/textpara.h
@@ -18,12 +18,13 @@
 extern "C" {
 #endif
 
-/* Bold, Italic, Underline */
+/* Bold, Italic, Underline, Sup, Sub, Strike */
 #define HTML_BF 1
 #define HTML_IF 2
 #define HTML_UL 4
 #define HTML_SUP 8
 #define HTML_SUB 16
+#define HTML_S   32
 
     /* font information
      * If name or color is NULL, or size < 0, that attribute
@@ -32,8 +33,8 @@ extern "C" {
     typedef struct {
 	char*  name;
 	char*  color;
-        int    flags:7;  /* HTML_UL, HTML_IF, HTML_BF */
-	int    cnt;   /* reference count */
+        int    flags:7;  /* HTML_UL, HTML_IF, HTML_BF, etc. */
+	int    cnt:(sizeof(int) * 8 - 7);   /* reference count */
 	double size;
     } htmlfont_t;
 
diff --git a/plugin/core/gvrender_core_svg.c b/plugin/core/gvrender_core_svg.c
index c2d06745f..aa08171a0 100644
--- a/plugin/core/gvrender_core_svg.c
+++ b/plugin/core/gvrender_core_svg.c
@@ -404,8 +404,17 @@ static void svg_textpara(GVJ_t * job, pointf p, textpara_t * para)
 	    gvprintf(job, " font-weight=\"bold\"");
 	if ((flags & HTML_IF) && !style)
 	    gvprintf(job, " font-style=\"italic\"");
-	if ((flags & HTML_UL))
-	    gvprintf(job, " text-decoration=\"underline\"");
+	if ((flags & (HTML_UL|HTML_S))) {
+	    int comma = 0;
+	    gvprintf(job, " text-decoration=\"");
+	    if ((flags & HTML_UL)) {
+		gvprintf(job, "underline");
+		comma = 1;
+	    }
+	    if ((flags & HTML_S))
+		gvprintf(job, "%sline-through", (comma?",":""));
+	    gvprintf(job, "\"");
+	}
 	if ((flags & HTML_SUP))
 	    gvprintf(job, " baseline-shift=\"super\"");
 	if ((flags & HTML_SUB))
diff --git a/plugin/pango/gvtextlayout_pango.c b/plugin/pango/gvtextlayout_pango.c
index 28a681d3e..45a2d79ef 100644
--- a/plugin/pango/gvtextlayout_pango.c
+++ b/plugin/pango/gvtextlayout_pango.c
@@ -190,6 +190,8 @@ static boolean pango_textlayout(textpara_t * para, char **fontpath)
 	    agxbput(&xb," style=\"italic\"");
 	if (flags & HTML_UL)
 	    agxbput(&xb," underline=\"single\"");
+	if (flags & HTML_S)
+	    agxbput(&xb," strikethrough=\"true\"");
 	agxbput (&xb,">");
 
 	if (flags & HTML_SUP)
-- 
2.40.0