shithub: neatpost

Download patch

ref: c9d2d3372a22edf3f50161b6a8c263ea6b078627
parent: 635ecc2c38e0b2c644bcad9e5b9252b0624d77d2
author: Ali Gholami Rudi <ali@rudi.ir>
date: Fri Aug 29 08:14:04 EDT 2014

font: move font struct to font.c

--- a/dev.c
+++ b/dev.c
@@ -122,12 +122,6 @@
 	return pos >= 0 && pos < NFONTS ? 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;
-}
-
 int dev_fontid(struct font *fn)
 {
 	int i;
--- a/font.c
+++ b/font.c
@@ -3,6 +3,24 @@
 #include <string.h>
 #include "post.h"
 
+struct font {
+	char name[FNLEN];
+	char fontname[FNLEN];
+	struct glyph glyphs[NGLYPHS];
+	int nglyphs;
+	int spacewid;
+	/* glyph list based on the first character of their id fields in glyphs[] */
+	int ghead[256];			/* glyph list head */
+	int gnext[NGLYPHS];		/* next item in glyph list */
+	/* charset section characters */
+	char c[NGLYPHS][GNLEN];		/* character names in charset */
+	struct glyph *g[NGLYPHS];	/* character glyphs in charset */
+	int n;				/* number of characters in charset */
+	/* glyph list based on the first character of glyph names in c[] */
+	int chead[256];			/* glyph list head */
+	int cnext[NGLYPHS];		/* next item in glyph list */
+};
+
 struct glyph *font_find(struct font *fn, char *name)
 {
 	int i = fn->chead[(unsigned char) name[0]];
@@ -120,8 +138,6 @@
 			font_readchar(fn, fin);
 		} else if (!strcmp("spacewidth", tok)) {
 			fscanf(fin, "%d", &fn->spacewid);
-		} else if (!strcmp("special", tok)) {
-			fn->special = 1;
 		} else if (!strcmp("name", tok)) {
 			fscanf(fin, "%s", fn->name);
 		} else if (!strcmp("fontname", tok)) {
@@ -144,4 +160,19 @@
 void font_close(struct font *fn)
 {
 	free(fn);
+}
+
+int font_wid(struct font *fn, int sz, int w)
+{
+	return (w * sz + dev_uwid / 2) / dev_uwid;
+}
+
+int font_swid(struct font *fn, int sz)
+{
+	return font_wid(fn, sz, fn->spacewid);
+}
+
+char *font_name(struct font *fn)
+{
+	return fn->fontname;
 }
--- a/out.c
+++ b/out.c
@@ -65,7 +65,7 @@
 	} else {
 		outf("/%s", g->id);
 	}
-	o_qend = o_h + charwid(g->wid, o_s);
+	o_qend = o_h + font_wid(g->font, o_s, g->wid);
 }
 
 /* calls o_flush() if necessary */
@@ -88,12 +88,12 @@
 	}
 	if (fid != p_f || o_s != p_s) {
 		fn = dev_font(fid);
-		out("%d /%s f\n", o_s, fn->fontname);
+		out("%d /%s f\n", o_s, font_name(fn));
 		p_f = fid;
 		p_s = o_s;
-		sprintf(fnname, " %s ", fn->fontname);
+		sprintf(fnname, " %s ", font_name(fn));
 		if (!strstr(o_fonts, fnname))
-			sprintf(strchr(o_fonts, '\0'), "%s ", fn->fontname);
+			sprintf(strchr(o_fonts, '\0'), "%s ", font_name(fn));
 	}
 }
 
@@ -104,7 +104,7 @@
 	g = dev_glyph(c, o_f);
 	fn = g ? g->font : dev_font(o_f);
 	if (!g) {
-		outrel(*c == ' ' && fn ? charwid(fn->spacewid, o_s) : 1, 0);
+		outrel(*c == ' ' && fn ? font_swid(fn, o_s) : 1, 0);
 		return;
 	}
 	out_fontup(dev_fontid(fn));
--- a/post.h
+++ b/post.h
@@ -26,26 +26,6 @@
 	int pos;		/* glyph code */
 };
 
-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 */
-	/* glyph list based on the first character of their id fields in glyphs[] */
-	int ghead[256];			/* glyph list head */
-	int gnext[NGLYPHS];		/* next item in glyph list */
-	/* charset section characters */
-	char c[NGLYPHS][GNLEN];		/* character names in charset */
-	struct glyph *g[NGLYPHS];	/* character glyphs in charset */
-	int n;				/* number of characters in charset */
-	/* glyph list based on the first character of glyph names in c[] */
-	int chead[256];			/* glyph list head */
-	int cnext[NGLYPHS];		/* next item in glyph list */
-};
-
 /* output device functions */
 int dev_open(char *dir, char *dev);
 void dev_close(void);
@@ -52,7 +32,6 @@
 int dev_mnt(int pos, char *id, char *name);
 struct font *dev_font(int fn);
 int dev_fontid(struct font *fn);
-int charwid(int wid, int sz);
 struct glyph *dev_glyph(char *c, int fn);
 
 /* font-related functions */
@@ -60,6 +39,9 @@
 void font_close(struct font *fn);
 struct glyph *font_glyph(struct font *fn, char *id);
 struct glyph *font_find(struct font *fn, char *name);
+int font_wid(struct font *fn, int sz, int w);
+int font_swid(struct font *fn, int sz);
+char *font_name(struct font *fn);
 
 /* output functions */
 void out(char *s, ...);