svn commit: r269041 - in stable/10: tools/tools/vt/fontcvt usr.bin usr.bin/vtfontcvt

Ed Maste emaste at FreeBSD.org
Thu Jul 24 01:35:42 UTC 2014


Author: emaste
Date: Thu Jul 24 01:35:41 2014
New Revision: 269041
URL: http://svnweb.freebsd.org/changeset/base/269041

Log:
  MFC vtfontcvt improvements:
  
  r267011: Make height and width optional arguments
  
    Now defaults to a 16x8 font size.  The height and width can be specified
    using -h and -w respectively.
  
  r267012: Make the bold font optional
  
  r267035: Use a hash to speed up glyph deduplication
  
    Walking a linked list of all glyphs to look for a duplicate is very slow
    for large fonts (e.g., for CJK character sets).  In my test the runtime
    for a sample 40000 character font went from just over 80 seconds on
    average to just over 2 seconds.
  
  r267119: -w sets the width, not height
  
  r267123: Support "GNU Unifont" format font data
  
    The GNU Unifont .hex format is a text file.  Each line represents one
    glyph and consists of a four-digit hex code point, a colon, and pairs of
    hex digits representing the bitmap.  By default an 8x16 font is assumed,
    with 16x16 double-width glyphs, resulting in either 32 or 64 hex digits
    for the bitmap.
  
    Our version of the file format supports comments at the top of the file
    to set the height and width:
  
    Each row of bitmap data is rounded up to byte width - for example, a
    10-pixel wide font uses 4 characters per row.
  
    See http://czyborra.com/unifont/ for more background on the original
    format.
  
  r267126: Accept space after BITMAP in .bdf parser
  
    The Unifont BDF generator incorrectly adds a space after BITMAP, and
    and that error has been widely propagated.
  
  r267173: use -h height and -w width args
  
  r267298: Hide stats by default and improve error handling
  
    The font stats are interesting, but rather verbose.
  
  r267301: Speed up bold glyph map deduplication
  
    Perform an O(n) deduplication pass over the bold maps at the end, rather
    than walking the normal map list to look for a duplicate glyph each time
    a bold mapping entry is added.
  
  r267324: handle failure writing output font
  
  r267337: move to usr.bin/vtfontcvt
  
    vtfontcvt is useful for end users to convert arbitrary bitmap fonts
    for use by vt(4).  It can also be used as a build tool, allowing us
    to keep the source font data in the src tree rather than uuencoded
    binaries.
  
    Reviewed by:  ray, wblock (D183)
  
  r267366: Avoid leaking file pointer on error
  
    CID:          1222506, 1222505
  
  r268022: Rename the WITHOUT_VT_SUPPORT knob to WITHOUT_VT
  
    The _SUPPORT knobs have a consistent meaning which differs from the
    behaviour controlled by this knob.  As the knob is opt-out and has not
    appeared in a release the impact should be low.
  
  r268172: correct width calculation (.hex files and commandline)
  
  r268948: Use the standard way of printing the usage string
  
  r268949: Remove redundant return statement after errx
  
  Also update vtfontcvt(8), based on inclusion in FreeBSD 10.1
  
  Sponsored by:	The FreeBSD Foundation

Added:
  stable/10/usr.bin/vtfontcvt/
     - copied from r267337, head/usr.bin/vtfontcvt/
Deleted:
  stable/10/tools/tools/vt/fontcvt/Makefile
  stable/10/tools/tools/vt/fontcvt/fontcvt.c
Modified:
  stable/10/tools/tools/vt/fontcvt/terminus.sh
  stable/10/usr.bin/Makefile
  stable/10/usr.bin/vtfontcvt/vtfontcvt.8
  stable/10/usr.bin/vtfontcvt/vtfontcvt.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/tools/tools/vt/fontcvt/terminus.sh
==============================================================================
--- stable/10/tools/tools/vt/fontcvt/terminus.sh	Thu Jul 24 01:08:02 2014	(r269040)
+++ stable/10/tools/tools/vt/fontcvt/terminus.sh	Thu Jul 24 01:35:41 2014	(r269041)
@@ -1,10 +1,12 @@
 #!/bin/sh
+# $FreeBSD$
+
 for i in 6:12 8:14 8:16 10:18 10:20 11:22 12:24 14:28 16:32
 do
 	C=`echo $i | cut -f 1 -d :`
 	R=`echo $i | cut -f 2 -d :`
-	./fontcvt \
-		$C $R \
+	./vtfontcvt \
+		-w $C -h $R \
 		~/terminus-font-4.36/ter-u${R}n.bdf \
 		~/terminus-font-4.36/ter-u${R}b.bdf \
 		terminus-u${R}.vfnt

Modified: stable/10/usr.bin/Makefile
==============================================================================
--- stable/10/usr.bin/Makefile	Thu Jul 24 01:08:02 2014	(r269040)
+++ stable/10/usr.bin/Makefile	Thu Jul 24 01:35:41 2014	(r269041)
@@ -362,6 +362,10 @@ SUBDIR+=	xstr
 SUBDIR+=	yacc
 .endif
 
+.if ${MK_VT} != "no"
+SUBDIR+=	vtfontcvt
+.endif
+
 .if ${MK_USB} != "no"
 SUBDIR+=	usbhidaction
 SUBDIR+=	usbhidctl

Modified: stable/10/usr.bin/vtfontcvt/vtfontcvt.8
==============================================================================
--- head/usr.bin/vtfontcvt/vtfontcvt.8	Tue Jun 10 18:29:45 2014	(r267337)
+++ stable/10/usr.bin/vtfontcvt/vtfontcvt.8	Thu Jul 24 01:35:41 2014	(r269041)
@@ -71,4 +71,4 @@ comment before any font data.
 The
 .Nm
 utility first appeared in
-.Fx 11.0 .
+.Fx 10.1 .

Modified: stable/10/usr.bin/vtfontcvt/vtfontcvt.c
==============================================================================
--- head/usr.bin/vtfontcvt/vtfontcvt.c	Tue Jun 10 18:29:45 2014	(r267337)
+++ stable/10/usr.bin/vtfontcvt/vtfontcvt.c	Thu Jul 24 01:35:41 2014	(r269041)
@@ -91,7 +91,7 @@ static void
 usage(void)
 {
 
-	errx(1,
+	(void)fprintf(stderr,
 "usage: vtfontcvt [-w width] [-h height] [-v] normal.bdf [bold.bdf] out.fnt\n");
 	exit(1);
 }
@@ -111,10 +111,8 @@ add_mapping(struct glyph *gl, unsigned i
 
 	ml = &maps[map_idx];
 	if (TAILQ_LAST(ml, mapping_list) != NULL &&
-	    TAILQ_LAST(ml, mapping_list)->m_char >= c) {
+	    TAILQ_LAST(ml, mapping_list)->m_char >= c)
 		errx(1, "Bad ordering at character %u\n", c);
-		return (1);
-	}
 	TAILQ_INSERT_TAIL(ml, mp, m_list);
 
 	map_count[map_idx]++;
@@ -134,11 +132,9 @@ dedup_mapping(unsigned int map_idx)
 	TAILQ_FOREACH_SAFE(mp_bold, &maps[map_idx], m_list, mp_temp) {
 		while (mp_normal->m_char < mp_bold->m_char)
 			mp_normal = TAILQ_NEXT(mp_normal, m_list);
-		if (mp_bold->m_char != mp_normal->m_char) {
+		if (mp_bold->m_char != mp_normal->m_char)
 			errx(1, "Character %u not in normal font!\n",
 			    mp_bold->m_char);
-			return (1);
-		}
 		if (mp_bold->m_glyph != mp_normal->m_glyph)
 			continue;
 
@@ -211,11 +207,8 @@ parse_bitmap_line(uint8_t *left, uint8_t
 	uint8_t *p;
 	unsigned int i, subline;
 
-	if (dwidth != width && dwidth != width * 2) {
-		errx(1,
-		    "Bitmap with unsupported width %u!\n", dwidth);
-		return (1);
-	}
+	if (dwidth != width && dwidth != width * 2)
+		errx(1, "Bitmap with unsupported width %u!\n", dwidth);
 
 	/* Move pixel data right to simplify splitting double characters. */
 	line >>= (howmany(dwidth, 8) * 8) - dwidth;
@@ -232,9 +225,7 @@ parse_bitmap_line(uint8_t *left, uint8_t
 			*p++ = subline >> 8;
 			*p = subline;
 		} else {
-			errx(1,
-			    "Unsupported wbytes %u!\n", wbytes);
-			return (1);
+			errx(1, "Unsupported wbytes %u!\n", wbytes);
 		}
 
 		line >>= width;
@@ -265,10 +256,8 @@ parse_bdf(FILE *fp, unsigned int map_idx
 		if (strncmp(ln, "BITMAP", 6) == 0 &&
 		    (ln[6] == ' ' || ln[6] == '\0')) {
 			for (i = 0; i < height; i++) {
-				if ((ln = fgetln(fp, &length)) == NULL) {
+				if ((ln = fgetln(fp, &length)) == NULL)
 					errx(1, "Unexpected EOF!\n");
-					return (1);
-				}
 				ln[length - 1] = '\0';
 				sscanf(ln, "%x", &line);
 				if (parse_bitmap_line(bytes + i * wbytes,
@@ -285,6 +274,16 @@ parse_bdf(FILE *fp, unsigned int map_idx
 	return (0);
 }
 
+static void
+set_width(int w)
+{
+
+	if (w <= 0 || w > 128)
+		errx(1, "invalid width %d", w);
+	width = w;
+	wbytes = howmany(width, 8);
+}
+
 static int
 parse_hex(FILE *fp, unsigned int map_idx)
 {
@@ -300,12 +299,12 @@ parse_hex(FILE *fp, unsigned int map_idx
 		if (strncmp(ln, "# Height: ", 10) == 0) {
 			height = atoi(ln + 10);
 		} else if (strncmp(ln, "# Width: ", 9) == 0) {
-			width = atoi(ln + 9);
+			set_width(atoi(ln + 9));
 		} else if (sscanf(ln, "%4x:", &curchar)) {
 			p = ln + 5;
 			chars_per_row = strlen(p) / height;
 			dwidth = width;
-			if (chars_per_row / 2 > width / 8)
+			if (chars_per_row / 2 > (width + 7) / 8)
 				dwidth *= 2; /* Double-width character. */
 			snprintf(fmt_str, sizeof(fmt_str), "%%%ux",
 			    chars_per_row);
@@ -331,6 +330,7 @@ parse_file(const char *filename, unsigne
 {
 	FILE *fp;
 	size_t len;
+	int rv;
 
 	fp = fopen(filename, "r");
 	if (fp == NULL) {
@@ -339,8 +339,11 @@ parse_file(const char *filename, unsigne
 	}
 	len = strlen(filename);
 	if (len > 4 && strcasecmp(filename + len - 4, ".hex") == 0)
-		return parse_hex(fp, map_idx);
-	return parse_bdf(fp, map_idx);
+		rv = parse_hex(fp, map_idx);
+	else
+		rv = parse_bdf(fp, map_idx);
+	fclose(fp);
+	return (rv);
 }
 
 static void
@@ -447,6 +450,7 @@ write_fnt(const char *filename)
 	fh.map_count[3] = htobe32(map_folded_count[3]);
 	if (fwrite(&fh, sizeof fh, 1, fp) != 1) {
 		perror(filename);
+		fclose(fp);
 		return (1);
 	}
 
@@ -456,9 +460,11 @@ write_fnt(const char *filename)
 	    write_mappings(fp, VFNT_MAP_BOLD) != 0 ||
 	    write_mappings(fp, 3) != 0) {
 		perror(filename);
+		fclose(fp);
 		return (1);
 	}
 
+	fclose(fp);
 	return (0);
 }
 
@@ -511,22 +517,15 @@ main(int argc, char *argv[])
 		switch (ch) {
 		case 'h':
 			val = atoi(optarg);
-			if (val <= 0 || val > 128) {
+			if (val <= 0 || val > 128)
 				errx(1, "Invalid height %d", val);
-				return (1);
-			}
 			height = val;
 			break;
 		case 'v':
 			verbose = 1;
 			break;
 		case 'w':
-			val = atoi(optarg);
-			if (val <= 0 || val > 128) {
-				errx(1, "Invalid width %d", val);
-				return (1);
-			}
-			width = val;
+			set_width(atoi(optarg));
 			break;
 		case '?':
 		default:


More information about the svn-src-stable mailing list