ref: d1259f4af92f110f5025b0071872ff0e135f2513
parent: 5a3cf696ed2c10ebacf756f1d7b721a1c5ae82e3
author: Ali Gholami Rudi <[email protected]>
date: Wed Jul 24 14:33:00 EDT 2013
ren: add .ss
--- a/dev.c
+++ b/dev.c
@@ -149,11 +149,6 @@
return 0;
}
-int dev_spacewid(void)
-{
- return fn_font[n_f]->spacewid;
-}
-
/* return the mounted position of font */
int dev_pos(char *id)
{
@@ -178,10 +173,4 @@
struct font *dev_font(int pos)
{
return pos >= 0 && pos < fn_n ? fn_font[pos] : NULL;
-}
-
-int charwid(int wid, int sz)
-{
- /* the original troff rounds the widths up */
- return (wid * sz + dev_uwid / 2) / dev_uwid;
}
--- a/draw.c
+++ b/draw.c
@@ -30,7 +30,7 @@
static int cwid(char *c)
{
struct glyph *g = dev_glyph(c, n_f);
- return charwid(g ? g->wid : SC_DW, n_s);
+ return charwid(n_f, n_s, g ? g->wid : SC_DW);
}
static int hchar(char *c)
--- a/out.c
+++ b/out.c
@@ -228,7 +228,7 @@
outnn("c%s%s", c, c[1] ? "\n" : "");
else
out("C%s\n", c[0] == c_ec && c[1] == '(' ? c + 2 : c);
- outnn("h%d", charwid(g ? g->wid : SC_DW, o_s));
+ outnn("h%d", charwid(o_f, o_s, g ? g->wid : SC_DW));
continue;
}
switch (t) {
--- a/reg.c
+++ b/reg.c
@@ -43,6 +43,7 @@
REG(0, 'L'),
REG(0, 'n'),
REG(0, 'm'),
+ REG(0, 'p'),
REG(0, 's'),
REG(0, 't'),
REG(0, 'T'),
@@ -195,6 +196,7 @@
n_na = 0;
n_lt = SC_IN * 65 / 10;
n_hy = 1;
+ n_ss = 12;
strcpy(env->hc, "\\%");
adj_ll(env->adj, n_l);
adj_in(env->adj, n_i);
--- a/ren.c
+++ b/ren.c
@@ -85,6 +85,17 @@
}
}
+int charwid(int fn, int sz, int wid)
+{
+ /* the original troff rounds the widths up */
+ return (wid * sz + dev_uwid / 2) / dev_uwid;
+}
+
+int spacewid(int fn, int sz)
+{
+ return charwid(fn, sz, (dev_font(fn)->spacewid * n_ss + 6) / 12);
+}
+
int f_divreg(void)
{
return cdiv ? cdiv->reg : -1;
@@ -559,7 +570,7 @@
struct glyph *g;
switch (c) {
case ' ':
- wb_hmov(wb, charwid(dev_spacewid(), n_s));
+ wb_hmov(wb, spacewid(n_f, n_s));
break;
case 'b':
ren_bracket(wb, arg);
@@ -618,7 +629,7 @@
break;
case '0':
g = dev_glyph("0", n_f);
- wb_hmov(wb, charwid(g ? g->wid : SC_DW, n_s));
+ wb_hmov(wb, charwid(n_f, n_s, g ? g->wid : SC_DW));
break;
case '|':
wb_hmov(wb, SC_EM / 6);
@@ -851,7 +862,7 @@
fillreq = 0;
/* add wb (the current word) to cadj */
if (c == ' ' || c == '\n') {
- adj_swid(cadj, charwid(dev_spacewid(), n_s));
+ adj_swid(cadj, spacewid(n_f, n_s));
if (!wb_part(wb)) { /* not after a \c */
adj_wb(cadj, wb);
fillreq = ren_fillreq;
--- a/roff.h
+++ b/roff.h
@@ -112,7 +112,6 @@
int dev_mnt(int pos, char *id, char *name);
int dev_pos(char *id);
struct font *dev_font(int pos);
-int charwid(int wid, int sz);
/* font-related functions */
struct font *font_open(char *path);
@@ -125,7 +124,8 @@
/* glyph handling functions */
struct glyph *dev_glyph(char *c, int fn);
struct glyph *dev_glyph_byid(char *id, int fn);
-int dev_spacewid(void);
+int charwid(int fn, int sz, int wid);
+int spacewid(int fn, int sz);
/* different layers of neatroff */
int in_next(void); /* input layer */
@@ -357,6 +357,7 @@
#define n_na (*nreg(REG(0, 'n'))) /* .na mode */
#define n_ns (*nreg(REG(0, 'N'))) /* .ns mode */
#define n_o0 (*nreg(REG(0, 'o'))) /* last .o */
+#define n_ss (*nreg(REG(0, 'p'))) /* .ss value */
#define n_s0 (*nreg(REG(0, 's'))) /* last .s */
#define n_sv (*nreg(REG(0, 'S'))) /* .sv value */
#define n_lt (*nreg(REG(0, 't'))) /* .lt value */
--- a/tr.c
+++ b/tr.c
@@ -440,6 +440,12 @@
n_cp = atoi(args[1]);
}
+static void tr_ss(char **args)
+{
+ if (args[1])
+ n_ss = eval_re(args[1], n_ss, 0);
+}
+
static char *arg_regname(char *s, int len)
{
char *e = n_cp ? s + 2 : s + len;
@@ -670,6 +676,7 @@
{"rt", tr_rt},
{"so", tr_so},
{"sp", tr_sp},
+ {"ss", tr_ss},
{"sv", tr_sv},
{"sy", tr_sy, mkargs_eol},
{"ta", tr_ta},
--- a/wb.c
+++ b/wb.c
@@ -84,7 +84,7 @@
return;
}
if (c[0] == ' ') {
- wb_hmov(wb, charwid(dev_spacewid(), R_S(wb)));
+ wb_hmov(wb, spacewid(R_F(wb), R_S(wb)));
return;
}
if (c[0] == '\t' || c[0] == '' ||
@@ -110,7 +110,7 @@
strcpy(wb->prev_c, c);
wb->prev_l = sbuf_len(&wb->sbuf);
wb->prev_h = wb->h;
- wb->h += charwid(g ? g->wid : SC_DW, R_S(wb));
+ wb->h += charwid(R_F(wb), R_S(wb), g ? g->wid : SC_DW);
wb->ct |= g ? g->type : 0;
wb_stsb(wb);
}
@@ -140,7 +140,7 @@
return 1;
val = font_kern(dev_font(R_F(wb)), wb->prev_c, c);
if (val)
- wb_hmov(wb, charwid(val, R_S(wb)));
+ wb_hmov(wb, charwid(R_F(wb), R_S(wb), val));
return !val;
}
@@ -313,7 +313,7 @@
static int wb_dashwid(struct wb *wb)
{
struct glyph *g = dev_glyph("hy", R_F(wb));
- return charwid(g ? g->wid : SC_DW, R_S(wb));
+ return charwid(R_F(wb), R_S(wb), g ? g->wid : SC_DW);
}
static char *indicatorpos(char *s, int w, struct wb *w1, int flg)