diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-09-03 19:07:48 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-09-03 19:07:48 +0200 |
commit | 72a5fbd8ea41d44c5b8d6ab3483c7701e0126726 (patch) | |
tree | d471e584eac426b4730117de7cf74446b1a0b785 /sys | |
parent | c8dd01d5f673d62555ac773a61798901784445de (diff) |
mothra: subscript and superscript support
Diffstat (limited to 'sys')
-rw-r--r-- | sys/src/cmd/mothra/html.h | 3 | ||||
-rw-r--r-- | sys/src/cmd/mothra/html.syntax.c | 2 | ||||
-rw-r--r-- | sys/src/cmd/mothra/libpanel/panel.h | 7 | ||||
-rw-r--r-- | sys/src/cmd/mothra/libpanel/rtext.c | 18 | ||||
-rw-r--r-- | sys/src/cmd/mothra/mothra.c | 2 | ||||
-rw-r--r-- | sys/src/cmd/mothra/rdhtml.c | 43 |
6 files changed, 51 insertions, 24 deletions
diff --git a/sys/src/cmd/mothra/html.h b/sys/src/cmd/mothra/html.h index 7393f6e6f..dfb442c08 100644 --- a/sys/src/cmd/mothra/html.h +++ b/sys/src/cmd/mothra/html.h @@ -29,6 +29,7 @@ struct Stack{ int pre; /* in preformatted text? */ int font; /* typeface */ int size; /* point size of text */ + int sub; /* < 0 superscript, > 0 subscript */ int margin; /* left margin position */ int indent; /* extra indent at paragraph start */ int number; /* paragraph number */ @@ -195,6 +196,8 @@ enum{ Tag_strike, Tag_strong, Tag_style, + Tag_sub, + Tag_sup, Tag_source, Tag_table, /* rm 3.8.00 */ Tag_td, diff --git a/sys/src/cmd/mothra/html.syntax.c b/sys/src/cmd/mothra/html.syntax.c index 28d0afffe..c9065bc55 100644 --- a/sys/src/cmd/mothra/html.syntax.c +++ b/sys/src/cmd/mothra/html.syntax.c @@ -73,6 +73,8 @@ Tag tag[]={ [Tag_strike] "strike", END, [Tag_strong] "strong", END, [Tag_style] "style", END, +[Tag_sub] "sub", END, +[Tag_sup] "sup", END, [Tag_source] "source", NOEND, [Tag_table] "table", END, [Tag_td] "td", END, diff --git a/sys/src/cmd/mothra/libpanel/panel.h b/sys/src/cmd/mothra/libpanel/panel.h index 7c06bc2fd..3d73a81bd 100644 --- a/sys/src/cmd/mothra/libpanel/panel.h +++ b/sys/src/cmd/mothra/libpanel/panel.h @@ -13,6 +13,7 @@ struct Rtext{ void *user; /* user data */ int space; /* how much space before, if no break */ int indent; /* how much space before, after a break */ + int voff; /* vertical offset (for subscripts and superscripts) */ Image *b; /* what to display, if nonzero */ Panel *p; /* what to display, if nonzero and b==0 */ Font *font; /* font in which to draw text */ @@ -173,9 +174,9 @@ void plinittextview(Panel *, int, Point, Rtext *, void (*)(Panel *, int, Rtext * /* * Rtext constructors & destructor */ -Rtext *plrtstr(Rtext **, int, int, Font *, char *, int, void *); -Rtext *plrtbitmap(Rtext **, int, int, Image *, int, void *); -Rtext *plrtpanel(Rtext **, int, int, Panel *, void *); +Rtext *plrtstr(Rtext **, int, int, int, Font *, char *, int, void *); +Rtext *plrtbitmap(Rtext **, int, int, int, Image *, int, void *); +Rtext *plrtpanel(Rtext **, int, int, int, Panel *, void *); void plrtfree(Rtext *); void plrtseltext(Rtext *, Rtext *, Rtext *); char *plrtsnarftext(Rtext *); diff --git a/sys/src/cmd/mothra/libpanel/rtext.c b/sys/src/cmd/mothra/libpanel/rtext.c index 92f195633..8f8fe4704 100644 --- a/sys/src/cmd/mothra/libpanel/rtext.c +++ b/sys/src/cmd/mothra/libpanel/rtext.c @@ -13,13 +13,14 @@ #define LEAD 4 /* extra space between lines */ #define BORD 2 /* extra border for images */ -Rtext *pl_rtnew(Rtext **t, int space, int indent, Image *b, Panel *p, Font *f, char *s, int flags, void *user){ +Rtext *pl_rtnew(Rtext **t, int space, int indent, int voff, Image *b, Panel *p, Font *f, char *s, int flags, void *user){ Rtext *new; new=pl_emalloc(sizeof(Rtext)); new->flags=flags; new->user=user; new->space=space; new->indent=indent; + new->voff=voff; new->b=b; new->p=p; new->font=f; @@ -34,14 +35,14 @@ Rtext *pl_rtnew(Rtext **t, int space, int indent, Image *b, Panel *p, Font *f, c (*t)->last=new; return new; } -Rtext *plrtpanel(Rtext **t, int space, int indent, Panel *p, void *user){ - return pl_rtnew(t, space, indent, 0, p, 0, 0, 1, user); +Rtext *plrtpanel(Rtext **t, int space, int indent, int voff, Panel *p, void *user){ + return pl_rtnew(t, space, indent, voff, 0, p, 0, 0, 1, user); } -Rtext *plrtstr(Rtext **t, int space, int indent, Font *f, char *s, int flags, void *user){ - return pl_rtnew(t, space, indent, 0, 0, f, s, flags, user); +Rtext *plrtstr(Rtext **t, int space, int indent, int voff, Font *f, char *s, int flags, void *user){ + return pl_rtnew(t, space, indent, voff, 0, 0, f, s, flags, user); } -Rtext *plrtbitmap(Rtext **t, int space, int indent, Image *b, int flags, void *user){ - return pl_rtnew(t, space, indent, b, 0, 0, 0, flags, user); +Rtext *plrtbitmap(Rtext **t, int space, int indent, int voff, Image *b, int flags, void *user){ + return pl_rtnew(t, space, indent, voff, b, 0, 0, 0, flags, user); } void plrtfree(Rtext *t){ Rtext *next; @@ -102,6 +103,7 @@ Point pl_rtfmt(Rtext *t, int wid){ d=tp->font->height-a; w=tp->wid=stringwidth(tp->font, tp->text); } + a-=tp->voff,d+=tp->voff; if(x+w+space>wid) break; if(a>ascent) ascent=a; if(d>descent) descent=d; @@ -128,6 +130,7 @@ Point pl_rtfmt(Rtext *t, int wid){ for(;;){ t->topy=topy; t->r.min.x=p.x; + p.y+=t->voff; if(t->b){ t->r.max.y=p.y+BORD; t->r.min.y=p.y-(t->b->r.max.y-t->b->r.min.y)-BORD; @@ -143,6 +146,7 @@ Point pl_rtfmt(Rtext *t, int wid){ t->r.max.y=t->r.min.y+t->font->height; p.x+=t->wid; } + p.y-=t->voff; t->r.max.x=p.x; t->nextline=eline; t=t->next; diff --git a/sys/src/cmd/mothra/mothra.c b/sys/src/cmd/mothra/mothra.c index 0a6407231..8a6967d7a 100644 --- a/sys/src/cmd/mothra/mothra.c +++ b/sys/src/cmd/mothra/mothra.c @@ -1124,7 +1124,7 @@ mothon(Www *w, int on) t->next = nil; ap=emalloc(sizeof(Action)); ap->link = strdup(a->link); - plrtstr(&t->next, 0, 0, t->font, strdup("->"), PL_HOT, ap); + plrtstr(&t->next, 0, 0, 0, t->font, strdup("->"), PL_HOT, ap); t->next->next = x; } else { if(x) { diff --git a/sys/src/cmd/mothra/rdhtml.c b/sys/src/cmd/mothra/rdhtml.c index 76a2a2bcb..d415aacbe 100644 --- a/sys/src/cmd/mothra/rdhtml.c +++ b/sys/src/cmd/mothra/rdhtml.c @@ -33,7 +33,8 @@ struct Fontdata{ "terminus/unicode.16", 0, 0, "terminus/unicode.18", 0, 0, }; -Fontdata *pl_whichfont(int f, int s){ + +Font *pl_whichfont(int f, int s, int *space){ char name[NNAME]; assert(f >= 0 && f < 4); @@ -45,14 +46,16 @@ Fontdata *pl_whichfont(int f, int s){ if(fontlist[f][s].font==0) fontlist[f][s].font=font; fontlist[f][s].space=stringwidth(fontlist[f][s].font, "0"); } - return &fontlist[f][s]; - + if(space) + *space = fontlist[f][s].space; + return fontlist[f][s].font; } + void getfonts(void){ int f, s; for(f=0;f!=4;f++) for(s=0;s!=4;s++) - pl_whichfont(f, s); + pl_whichfont(f, s, nil); } void pl_pushstate(Hglob *g, int t){ ++g->state; @@ -80,7 +83,7 @@ void pl_popstate(Stack *state){ } void pl_linespace(Hglob *g){ - plrtbitmap(&g->dst->text, 1000000, 0, linespace, 0, 0); + plrtbitmap(&g->dst->text, 1000000, 0, 0, linespace, 0, 0); g->para=0; g->linebrk=0; } @@ -93,15 +96,15 @@ int strtolength(Hglob *g, int dir, char *str){ if(cistrstr(str, "%")) return 0; if(cistrstr(str, "em")){ - p=stringsize(pl_whichfont(g->state->font, g->state->size)->font, "M"); + p=stringsize(pl_whichfont(g->state->font, g->state->size, nil), "M"); return floor(f*((dir==HORIZ) ? p.x : p.y)); } return floor(f); } void pl_htmloutput(Hglob *g, int nsp, char *s, Field *field){ - Fontdata *f; - int space, indent, flags; + Font *f; + int space, indent, flags, voff; Action *ap; if(g->state->tag==Tag_title /* || g->state->tag==Tag_textarea */ @@ -115,8 +118,13 @@ void pl_htmloutput(Hglob *g, int nsp, char *s, Field *field){ } return; } - f=pl_whichfont(g->state->font, g->state->size); - space=f->space; + voff = 0; + f=pl_whichfont(g->state->font, g->state->size, &space); + if(g->state->sub){ + voff = g->state->sub * f->ascent / 2; + g->state->size = SMALL; + f=pl_whichfont(g->state->font, g->state->size, &space); + } indent=g->state->margin; if(g->para){ space=1000000; @@ -160,7 +168,7 @@ void pl_htmloutput(Hglob *g, int nsp, char *s, Field *field){ flags |= PL_HOT; if(g->state->strike) flags |= PL_STR; - plrtstr(&g->dst->text, space, indent, f->font, strdup(s), flags, ap); + plrtstr(&g->dst->text, space, indent, voff, f, strdup(s), flags, ap); g->para=0; g->linebrk=0; g->dst->changed=1; @@ -636,6 +644,7 @@ void plaintext(Hglob *g){ int c; g->state->font=CWIDTH; g->state->size=NORMAL; + g->state->sub = 0; elp=&line[NLINE-UTFmax-1]; lp=line; for(;;){ @@ -665,6 +674,7 @@ void plrdplain(char *name, int fd, Www *dst){ g.state->tag=Tag_html; g.state->font=CWIDTH; g.state->size=NORMAL; + g.state->sub=0; g.state->pre=0; g.state->image=0; g.state->link=0; @@ -701,6 +711,7 @@ void plrdhtml(char *name, int fd, Www *dst){ g.state->tag=Tag_html; g.state->font=ROMAN; g.state->size=NORMAL; + g.state->sub=0; g.state->pre=0; g.state->image=0; g.state->link=0; @@ -914,6 +925,12 @@ void plrdhtml(char *name, int fd, Www *dst){ case Tag_del: g.state->strike=1; break; + case Tag_sub: + g.state->sub++; + break; + case Tag_sup: + g.state->sub--; + break; case Tag_blockquot: g.spacc=0; g.linebrk=1; @@ -1026,7 +1043,7 @@ void plrdhtml(char *name, int fd, Www *dst){ break; case Tag_hr: g.spacc=0; - plrtbitmap(&g.dst->text, 1000000, g.state->margin, hrule, 0, 0); + plrtbitmap(&g.dst->text, 1000000, g.state->margin, 0, hrule, 0, 0); break; case Tag_key: htmlerror(g.name, g.lineno, "<key> deprecated"); @@ -1063,7 +1080,7 @@ void plrdhtml(char *name, int fd, Www *dst){ g.linebrk=0; g.spacc=-1; plrtbitmap(&g.dst->text, 100000, - g.state->margin+g.state->indent, bullet, 0, 0); + g.state->margin+g.state->indent, 0, bullet, 0, 0); break; } break; |