summaryrefslogtreecommitdiff
path: root/dviware/dvi2pcl/sortfonts.c
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /dviware/dvi2pcl/sortfonts.c
Initial commit
Diffstat (limited to 'dviware/dvi2pcl/sortfonts.c')
-rw-r--r--dviware/dvi2pcl/sortfonts.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/dviware/dvi2pcl/sortfonts.c b/dviware/dvi2pcl/sortfonts.c
new file mode 100644
index 0000000000..5843842f26
--- /dev/null
+++ b/dviware/dvi2pcl/sortfonts.c
@@ -0,0 +1,79 @@
+/*
+ * Sorts order of fonts used in the dvi-file and not stored permanently in
+ * the printers memory in respect to font usage. Therefore a rating value
+ * is calculated for each font from their character usage in the document.
+ * The fonts are ordered in `fontlist' in order of their rating value
+ * `usage'. The function returns the number of different fonts used, but
+ * not stored permanently. As a side effect, for each font the first and
+ * last character, used in the document ist stored in font->bc and font->ec
+ * resp., to avoid unnecessary searching later on.
+ */
+
+#include "globals.h"
+
+int sortfonts(fontlist)
+int fontlist[];
+{
+ int f;
+ int i;
+ int t;
+ int store_all;
+ int fontnum = 0;
+ long total;
+ long different;
+ long tt;
+ long usage[MAXFONTS];
+ charfmt *u;
+ charfmt *cbase;
+
+ /* Determine rating value for each font used but not perm loaded */
+ for (f = 0 ; f < MAXFONTS ; f++)
+ if ((font = fontptr[f]) && (font->down < 0)) {
+ cbase = font->chr;
+ total = different = 0;
+ font->bc = 256;
+ font->ec = -1;
+ for(i = 0 ; i < 256 ; i++)
+ if((cbase + i)->use_count)
+ {
+ font->bc = i;
+ break;
+ } /* First char used */
+ for(i = 255 ; i >= font->bc ; i--)
+ if((cbase + i)->use_count) {
+ font->ec = i;
+ break;
+ } /* Last char used */
+ for(i = font->bc ; i <= font->ec ; i++) {
+ u = cbase + i;
+ if(u->use_count) {
+ different++;
+ total += u->use_count;
+ } /* Different used chars */
+ } /* and total usage */
+
+ fontlist[fontnum] = f;
+
+ /* Calculate rating */
+ if(different)
+ usage[fontnum++] =
+ (256*(total - different))/different;
+ else
+ usage[fontnum++] = 0;
+ }
+
+ /* Now sort used fonts in order of the usage rating values */
+ for(f = fontnum - 1 ; f > 0 ; f--)
+ for(i = 0 ; i < f ; i++)
+ if(usage[i] < usage[f]) {
+ tt = usage[i];
+ usage[i] = usage[f];
+ usage[f] = tt;
+ t = fontlist[i];
+ fontlist[i] = fontlist[f];
+ fontlist[f] = t;
+ }
+
+ /* Return the number of different fonts not permanently loaded */
+ return(fontnum);
+}