ref: 888606f23b59720a5e76500b8681caf34c2c60c8
parent: c562fdffeebe2eceafdf4deb51ad96bc993fbf35
author: Ali Gholami Rudi <[email protected]>
date: Thu Oct 24 07:34:51 EDT 2013
dev: add .fspecial
--- a/dev.c
+++ b/dev.c
@@ -16,6 +16,11 @@
static struct font *fn_font[NFONTS]; /* font structs */
static int fn_n; /* number of mounted fonts */
+/* .fspecial request */
+static char fspecial_fn[NFONTS][FNLEN]; /* .fspecial first arguments */
+static char fspecial_sp[NFONTS][FNLEN]; /* .fspecial special fonts */
+static int fspecial_n; /* number of fonts in fspecial_sp[] */
+
static void skipline(FILE* filp)
{
int c;
@@ -137,6 +142,10 @@
g = font_find(fn_font[fn], c);
if (g)
return g;
+ for (i = 0; i < fspecial_n; i++)
+ if (dev_pos(fspecial_fn[i]) == fn && dev_pos(fspecial_sp[i]) >= 0)
+ if ((g = font_find(dev_font(dev_pos(fspecial_sp[i])), c)))
+ return g;
for (i = 0; i < fn_n; i++)
if (fn_font[i] && fn_font[i]->special)
if ((g = font_find(fn_font[i], c)))
@@ -154,7 +163,7 @@
return 0;
}
-/* return the mounted position of font */
+/* return the mounted position of a font */
int dev_pos(char *id)
{
int i;
@@ -174,6 +183,16 @@
return dev_mnt(0, id, id);
}
+/* return the mounted position of a font struct */
+int dev_fontpos(struct font *fn)
+{
+ int i;
+ for (i = 0; i < fn_n; i++)
+ if (fn_font[i] == fn)
+ return i;
+ return 0;
+}
+
/* return the font struct at pos */
struct font *dev_font(int pos)
{
@@ -200,4 +219,21 @@
{
if (fn >= 0)
dev_font(fn)->bd = bd;
+}
+
+void tr_fspecial(char **args)
+{
+ char *fn = args[1];
+ int i;
+ if (!fn) {
+ fspecial_n = 0;
+ return;
+ }
+ for (i = 2; i < NARGS; i++) {
+ if (args[i] && fspecial_n < LEN(fspecial_fn)) {
+ strcpy(fspecial_fn[fspecial_n], fn);
+ strcpy(fspecial_sp[fspecial_n], args[i]);
+ fspecial_n++;
+ }
+ }
}
--- a/out.c
+++ b/out.c
@@ -110,12 +110,15 @@
outnn("\n");
}
-static void outg(char *c)
+static void outg(char *c, int fn)
{
+ int ofn = o_f;
+ out_ft(fn);
if (utf8one(c))
outnn("c%s%s", c, c[1] ? "\n" : "");
else
out("C%s\n", c[0] == c_ec && c[1] == '(' ? c + 2 : c);
+ out_ft(ofn);
}
static void outc(char *c)
@@ -125,10 +128,10 @@
int bwid = charwid_base(o_f, o_s, g ? g->wid : SC_DW);
if (dev_getcs(o_f))
outnn("h%d", (cwid - bwid) / 2);
- outg(c);
+ outg(c, g ? dev_fontpos(g->font) : o_f);
if (dev_getbd(o_f)) {
outnn("h%d", dev_getbd(o_f) - 1);
- outg(c);
+ outg(c, g ? dev_fontpos(g->font) : o_f);
outnn("h%d", -dev_getbd(o_f) + 1);
}
if (dev_getcs(o_f))
--- a/roff.h
+++ b/roff.h
@@ -130,6 +130,7 @@
int dev_mnt(int pos, char *id, char *name);
int dev_pos(char *id);
struct font *dev_font(int pos);
+int dev_fontpos(struct font *fn);
void dev_setcs(int fn, int cs);
int dev_getcs(int fn);
void dev_setbd(int fn, int bd);
@@ -307,6 +308,7 @@
void tr_fc(char **args);
void tr_fi(char **args);
void tr_fp(char **args);
+void tr_fspecial(char **args);
void tr_ft(char **args);
void tr_hw(char **args);
void tr_in(char **args);
--- a/tr.c
+++ b/tr.c
@@ -820,6 +820,7 @@
{"fc", tr_fc},
{"fi", tr_fi},
{"fp", tr_fp},
+ {"fspecial", tr_fspecial},
{"ft", tr_ft},
{"hc", tr_hc},
{"hy", tr_hy},