shithub: neatroff

Download patch

ref: cb8e5ddf8f87b1cea61d6603847b9fa7773089f1
parent: c52407c1a81c9df91f08edf2fd237ccf0e228ba8
author: Ali Gholami Rudi <ali@rudi.ir>
date: Tue Jul 29 10:37:03 EDT 2014

font: move font struct to font.c

--- a/dev.c
+++ b/dev.c
@@ -146,7 +146,7 @@
 			if ((g = find(dev_font(dev_pos(fspecial_sp[i])), c)))
 				return g;
 	for (i = 0; i < NFONTS; i++)
-		if (fn_font[i] && fn_font[i]->special)
+		if (fn_font[i] && font_special(fn_font[i]))
 			if ((g = find(fn_font[i], c)))
 				return g;
 	return NULL;
@@ -198,28 +198,6 @@
 struct font *dev_font(int pos)
 {
 	return pos >= 0 && pos < NFONTS ? fn_font[pos] : NULL;
-}
-
-int dev_getcs(int fn)
-{
-	return dev_font(fn)->cs;
-}
-
-void dev_setcs(int fn, int cs)
-{
-	if (fn >= 0)
-		dev_font(fn)->cs = cs;
-}
-
-int dev_getbd(int fn)
-{
-	return dev_font(fn)->bd;
-}
-
-void dev_setbd(int fn, int bd)
-{
-	if (fn >= 0)
-		dev_font(fn)->bd = bd;
 }
 
 void tr_fspecial(char **args)
--- a/font.c
+++ b/font.c
@@ -4,6 +4,32 @@
 #include <string.h>
 #include "roff.h"
 
+struct font {
+	char name[FNLEN];
+	char fontname[FNLEN];
+	struct glyph glyphs[NGLYPHS];
+	int nglyphs;
+	int spacewid;
+	int special;
+	int cs, bd;			/* for .cs and .bd requests */
+	struct dict gdict;		/* mapping from glyphs[i].id to i */
+	/* charset section characters */
+	char c[NGLYPHS][GNLEN];		/* character names in charset */
+	struct glyph *g[NGLYPHS];	/* character glyphs in charset */
+	struct glyph *g_map[NGLYPHS];	/* character remapped via font_map() */
+	int n;				/* number of characters in charset */
+	struct dict cdict;		/* mapping from c[i] to i */
+	/* font ligatures (lg*) */
+	char lg[NLIGS][LIGLEN * GNLEN];	/* ligatures */
+	int lgn;			/* number of ligatures in lg[] */
+	/* kerning pair table per glyph (kn*) */
+	int knhead[NGLYPHS];		/* kerning pairs of glyphs[] */
+	int knnext[NKERNS];		/* next item in knhead[] list */
+	int knpair[NKERNS];		/* kerning pair 2nd glyphs */
+	int knval[NKERNS];		/* font pairwise kerning value */
+	int knn;			/* number of kerning pairs */
+};
+
 /* find a glyph by its name */
 struct glyph *font_find(struct font *fn, char *name)
 {
@@ -229,4 +255,34 @@
 	dict_done(&fn->gdict);
 	dict_done(&fn->cdict);
 	free(fn);
+}
+
+int font_special(struct font *fn)
+{
+	return fn->special;
+}
+
+int font_spacewid(struct font *fn)
+{
+	return fn->spacewid;
+}
+
+int font_getcs(struct font *fn)
+{
+	return fn->cs;
+}
+
+void font_setcs(struct font *fn, int cs)
+{
+	fn->cs = cs;
+}
+
+int font_getbd(struct font *fn)
+{
+	return fn->bd;
+}
+
+void font_setbd(struct font *fn, int bd)
+{
+	fn->bd = bd;
 }
--- a/out.c
+++ b/out.c
@@ -125,6 +125,7 @@
 static void outc(char *c)
 {
 	struct glyph *g = dev_glyph(c, o_f);
+	struct font *fn = dev_font(o_f);
 	int cwid, bwid;
 	if (!g)
 		return;
@@ -132,15 +133,15 @@
 	bwid = DEVWID(o_s, g->wid);
 	if (font_mapped(g->font, c))
 		c = g->name;
-	if (dev_getcs(o_f))
+	if (font_getcs(fn))
 		outnn("h%d", (cwid - bwid) / 2);
 	outg(c, dev_fontpos(g->font));
-	if (dev_getbd(o_f)) {
-		outnn("h%d", dev_getbd(o_f) - 1);
+	if (font_getbd(fn)) {
+		outnn("h%d", font_getbd(fn) - 1);
 		outg(c, dev_fontpos(g->font));
-		outnn("h%d", -dev_getbd(o_f) + 1);
+		outnn("h%d", -font_getbd(fn) + 1);
 	}
-	if (dev_getcs(o_f))
+	if (font_getcs(fn))
 		outnn("h%d", -(cwid - bwid) / 2);
 	outnn("h%d", cwid);
 }
--- a/reg.c
+++ b/reg.c
@@ -61,7 +61,7 @@
 	if (s[0] == '.' && !s[2]) {
 		switch (s[1]) {
 		case 'b':
-			sprintf(numbuf, "%d", dev_getbd(n_f));
+			sprintf(numbuf, "%d", font_getbd(dev_font(n_f)));
 			return numbuf;
 		case 'c':
 			sprintf(numbuf, "%d", in_lnum());
--- a/ren.c
+++ b/ren.c
@@ -87,9 +87,10 @@
 
 int charwid(int fn, int sz, int wid)
 {
-	if (dev_getcs(fn))
-		return dev_getcs(n_f) * SC_EM / 36;
-	return DEVWID(sz, wid) + (dev_getbd(fn) ? dev_getbd(fn) - 1 : 0);
+	struct font *f = dev_font(fn);
+	if (font_getcs(f))
+		return font_getcs(f) * SC_EM / 36;
+	return DEVWID(sz, wid) + (font_getbd(f) ? font_getbd(f) - 1 : 0);
 }
 
 int f_divreg(void)
--- a/roff.h
+++ b/roff.h
@@ -153,32 +153,6 @@
 	int llx, lly, urx, ury;	/* character bounding box */
 };
 
-struct font {
-	char name[FNLEN];
-	char fontname[FNLEN];
-	struct glyph glyphs[NGLYPHS];
-	int nglyphs;
-	int spacewid;
-	int special;
-	int cs, bd;			/* for .cs and .bd requests */
-	struct dict gdict;		/* mapping from glyphs[i].id to i */
-	/* charset section characters */
-	char c[NGLYPHS][GNLEN];		/* character names in charset */
-	struct glyph *g[NGLYPHS];	/* character glyphs in charset */
-	struct glyph *g_map[NGLYPHS];	/* character remapped via font_map() */
-	int n;				/* number of characters in charset */
-	struct dict cdict;		/* mapping from c[i] to i */
-	/* font ligatures (lg*) */
-	char lg[NLIGS][LIGLEN * GNLEN];	/* ligatures */
-	int lgn;			/* number of ligatures in lg[] */
-	/* kerning pair table per glyph (kn*) */
-	int knhead[NGLYPHS];		/* kerning pairs of glyphs[] */
-	int knnext[NKERNS];		/* next item in knhead[] list */
-	int knpair[NKERNS];		/* kerning pair 2nd glyphs */
-	int knval[NKERNS];		/* font pairwise kerning value */
-	int knn;			/* number of kerning pairs */
-};
-
 /* output device functions */
 int dev_open(char *dir, char *dev);
 void dev_close(void);
@@ -186,10 +160,6 @@
 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);
-int dev_getbd(int fn);
 
 /* font-related functions */
 struct font *font_open(char *path);
@@ -201,6 +171,12 @@
 int font_islig(struct font *fn, char *s);
 int font_map(struct font *fn, char *name, struct glyph *gl);
 int font_mapped(struct font *fn, char *name);
+int font_special(struct font *fn);
+int font_spacewid(struct font *fn);
+void font_setcs(struct font *fn, int cs);
+int font_getcs(struct font *fn);
+void font_setbd(struct font *fn, int bd);
+int font_getbd(struct font *fn);
 
 /* glyph handling functions */
 struct glyph *dev_glyph(char *c, int fn);
@@ -209,8 +185,8 @@
 /* convert wid in device unitwidth size to size sz */
 #define DEVWID(sz, wid)		(((wid) * (sz) + (dev_uwid / 2)) / dev_uwid)
 /* the amount of word and sentence space for the given font and size */
-#define N_SS(fn, sz)	(charwid((fn), (sz), (dev_font(fn)->spacewid * n_ss + 6) / 12))
-#define N_SSS(fn, sz)	(charwid((fn), (sz), (dev_font(fn)->spacewid * n_sss + 6) / 12))
+#define N_SS(fn, sz)	(charwid((fn), (sz), (font_spacewid(dev_font(fn)) * n_ss + 6) / 12))
+#define N_SSS(fn, sz)	(charwid((fn), (sz), (font_spacewid(dev_font(fn)) * n_sss + 6) / 12))
 
 /* different layers of neatroff */
 int in_next(void);		/* input layer */
--- a/tr.c
+++ b/tr.c
@@ -453,7 +453,7 @@
 {
 	if (!args[1])
 		return;
-	dev_setcs(dev_pos(args[1]), args[2] ? eval(args[2], 0) : 0);
+	font_setcs(dev_font(dev_pos(args[1])), args[2] ? eval(args[2], 0) : 0);
 }
 
 static void tr_nm(char **args)
@@ -482,7 +482,7 @@
 {
 	if (!args[1] || !strcmp("S", args[1]))
 		return;
-	dev_setbd(dev_pos(args[1]), args[2] ? eval(args[2], 'u') : 0);
+	font_setbd(dev_font(dev_pos(args[1])), args[2] ? eval(args[2], 'u') : 0);
 }
 
 static void tr_it(char **args)