ref: b9eb7258bdb1b244af91dbe75595d55d3de810d4
parent: 72a5fbd8ea41d44c5b8d6ab3483c7701e0126726
author: cinap_lenrek <[email protected]>
date: Thu Sep 3 17:24:00 EDT 2015
html2ms: handle subscripts and superscripts
--- a/sys/src/cmd/html2ms.c
+++ b/sys/src/cmd/html2ms.c
@@ -217,7 +217,72 @@
fontstyle(text, "B");
}
+void onsmall(Text *text, Tag *tag);
+void onsup(Text *text, Tag *tag);
+
void
+onsub(Text *text, Tag *tag)
+{
+ emit(text, "\\v\'0.5\'");
+ if(cistrcmp(tag->tag, "sub") == 0){
+ emit(text, "\\x\'0.5\'");
+ onsmall(text, tag);
+ } else
+ restorefontsize(text, tag);
+ tag->close = onsup;
+}
+
+void
+onsup(Text *text, Tag *tag)
+{
+ emit(text, "\\v\'-0.5\'");
+ if(cistrcmp(tag->tag, "sup") == 0){
+ emit(text, "\\x\'-0.5\'");
+ onsmall(text, tag);
+ }else
+ restorefontsize(text, tag);
+ tag->close = onsub;
+}
+
+/*
+ * this is poor mans CSS handler.
+ */
+void
+onspan(Text *text, Tag *tag)
+{
+ Attr *a;
+
+ if(!tag->opening)
+ return;
+
+ for(a=tag->attr; a < tag->attr+tag->nattr; a++){
+ if(cistrcmp(a->attr, "class") != 0)
+ continue;
+
+ if(cistrcmp(a->val, "bold") == 0){
+ onb(text, tag);
+ return;
+ }
+ if(cistrcmp(a->val, "italic") == 0){
+ oni(text, tag);
+ return;
+ }
+ if(cistrcmp(a->val, "subscript") == 0){
+ strcpy(tag->tag, "sub");
+ onsub(text, tag);
+ strcpy(tag->tag, "span");
+ return;
+ }
+ if(cistrcmp(a->val, "superscript") == 0){
+ strcpy(tag->tag, "sup");
+ onsup(text, tag);
+ strcpy(tag->tag, "span");
+ return;
+ }
+ }
+}
+
+void
ontt(Text *text, Tag *tag)
{
tag->aux = text->fontstyle;
@@ -510,6 +575,9 @@
"td", oncell,
"th", oncell,
"tr", oncell,
+ "sub", onsub,
+ "sup", onsup,
+ "span", onspan,
"tt", ontt,
"var", oni,
};