html2ms: underline links

This commit is contained in:
stanley lieber 2011-09-19 19:21:54 -05:00
parent dbaea2b342
commit 7a29aa57cb

View file

@ -28,11 +28,12 @@ struct Tag {
}; };
struct Text { struct Text {
char font; char* font;
int pre; int pre;
int pos; int pos;
int space; int space;
int output; int output;
int underline;
}; };
void eatwhite(void); void eatwhite(void);
@ -122,28 +123,35 @@ onbr(Text *text, Tag *tag)
void void
restorefont(Text *text, Tag *tag) restorefont(Text *text, Tag *tag)
{ {
text->font = tag->restore; text->font = tag->aux;
text->pos += Bprint(&out, "\\f%c", text->font); text->pos += Bprint(&out, "\\f%s", text->font);
} }
void void
onfont(Text *text, Tag *tag) onfont(Text *text, Tag *tag)
{ {
if(text->font == 0) if(text->font == 0)
text->font = 'R'; text->font = "R";
tag->restore = text->font; tag->aux = text->font;
tag->close = restorefont; tag->close = restorefont;
if(cistrcmp(tag->tag, "i") == 0) if(cistrcmp(tag->tag, "i") == 0)
text->font = 'I'; text->font = "I";
else if(cistrcmp(tag->tag, "b") == 0) else if(cistrcmp(tag->tag, "b") == 0)
text->font = 'B'; text->font = "B";
text->pos += Bprint(&out, "\\f%c", text->font); text->pos += Bprint(&out, "\\f%s", text->font);
}
void
ona(Text *text, Tag *)
{
text->underline = 1;
} }
struct { struct {
char *tag; char *tag;
void (*open)(Text *, Tag *); void (*open)(Text *, Tag *);
} ontag[] = { } ontag[] = {
"a", ona,
"br", onbr, "br", onbr,
"hr", onbr, "hr", onbr,
"b", onfont, "b", onfont,
@ -154,6 +162,7 @@ struct {
"h3", onh, "h3", onh,
"h4", onh, "h4", onh,
"h5", onh, "h5", onh,
"h6", onh,
"li", onli, "li", onli,
"pre", onpre, "pre", onpre,
"head", ongarbage, "head", ongarbage,
@ -300,7 +309,7 @@ Rune
parserune(int c) parserune(int c)
{ {
char buf[10]; char buf[10];
int i, n; int n;
Rune r; Rune r;
n = 0; n = 0;
@ -425,7 +434,10 @@ parsetext(Text *text, Tag *tag)
text->pos = 0; text->pos = 0;
if(text->space){ if(text->space){
text->space = 0; text->space = 0;
if(text->pos >= 70){ if(text->underline){
emit(text, "");
text->pos = Bprint(&out, ".UL ");
} else if(text->pos >= 70){
text->pos = 0; text->pos = 0;
Bputc(&out, '\n'); Bputc(&out, '\n');
} else if(text->pos > 0){ } else if(text->pos > 0){