diff options
author | dawes <dawes> | 1994-04-27 07:07:10 +0000 |
---|---|---|
committer | dawes <dawes> | 1994-04-27 07:07:10 +0000 |
commit | 0eb2a9ffbce458a68d60d1a1854c115cd68feaaf (patch) | |
tree | 0d20c0850671e155b34993ba0a7bf44f02551892 /programs/fstobdf |
Initial revision
Diffstat (limited to 'programs/fstobdf')
-rw-r--r-- | programs/fstobdf/Imakefile | 9 | ||||
-rw-r--r-- | programs/fstobdf/chars.c | 216 | ||||
-rw-r--r-- | programs/fstobdf/fstobdf.c | 137 | ||||
-rw-r--r-- | programs/fstobdf/fstobdf.man | 63 | ||||
-rw-r--r-- | programs/fstobdf/header.c | 212 | ||||
-rw-r--r-- | programs/fstobdf/props.c | 147 |
6 files changed, 784 insertions, 0 deletions
diff --git a/programs/fstobdf/Imakefile b/programs/fstobdf/Imakefile new file mode 100644 index 000000000..811b3fefe --- /dev/null +++ b/programs/fstobdf/Imakefile @@ -0,0 +1,9 @@ +XCOMM $XConsortium: Imakefile,v 1.9 93/09/04 17:42:06 rws Exp $ +LOCAL_LIBRARIES = $(FSLIB) $(XLIB) +DEPLIBS = $(DEPFSLIB) $(DEPXLIB) +INCLUDES = -I$(BUILDINCDIR)/fonts -I$(FONTINCSRC) + + SRCS = chars.c fstobdf.c header.c props.c + OBJS = chars.o fstobdf.o header.o props.o + +ComplexProgramTarget (fstobdf) diff --git a/programs/fstobdf/chars.c b/programs/fstobdf/chars.c new file mode 100644 index 000000000..2f9f97c38 --- /dev/null +++ b/programs/fstobdf/chars.c @@ -0,0 +1,216 @@ +/* $XConsortium: chars.c,v 1.4 94/04/17 20:24:26 gildea Exp $ */ +/* + +Copyright (c) 1990 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + + * Copyright 1990 Network Computing Devices; + * Portions Copyright 1987 by Digital Equipment Corporation + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of Network Computing Devices, or Digital + * not be used in advertising or publicity pertaining to distribution + * of the software without specific, written prior permission. + * + * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, + * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + * THIS SOFTWARE. + */ + +#include <stdio.h> +#include <X11/Xlib.h> +#include "FSlib.h" + +extern long yResolution; /* intended vertical resoultion for font */ +extern long pointSize; /* font height in points */ + +#define BIT_ORDER BitmapFormatBitOrderMSB +#define BYTE_ORDER BitmapFormatByteOrderMSB +#define SCANLINE_UNIT BitmapFormatScanlineUnit8 +#define SCANLINE_PAD BitmapFormatScanlinePad8 +#define EXTENTS BitmapFormatImageRectMin + +#define SCANLINE_PAD_BYTES 1 + +#define GLWIDTHBYTESPADDED(bits, nBytes) \ + ((nBytes) == 1 ? (((bits) + 7) >> 3) /* pad to 1 byte */\ + :(nBytes) == 2 ? ((((bits) + 15) >> 3) & ~1) /* pad to 2 bytes */\ + :(nBytes) == 4 ? ((((bits) + 31) >> 3) & ~3) /* pad to 4 bytes */\ + :(nBytes) == 8 ? ((((bits) + 63) >> 3) & ~7) /* pad to 8 bytes */\ + : 0) + + +static void +EmitBitmap(outFile, fontHeader, charInfo, encoding, bpr, data) + FILE *outFile; + FSXFontInfoHeader *fontHeader; + FSXCharInfo *charInfo; + unsigned int encoding; + int bpr; + unsigned char *data; +{ + char *glyphName; + unsigned int row; + + /*- + * format: + * STARTCHAR name + * ENCODING index + * SWIDTH scalablewidth 0 + * DWIDTH pixels 0 + * BBX width height xoff yoff + * ATTRIBUTES xxxx + * BITMAP hhhhhhhh ... + * ENDCHAR + * + * where, SWIDTH * (point / 1000) * (yres / 72) = DWIDTH or, + * SWIDTH = 72000 * + * DWIDTH / (point * yres) + */ + + fprintf(outFile, "STARTCHAR "); + glyphName = XKeysymToString((KeySym) encoding); + if (glyphName) + fputs(glyphName, outFile); + else + fprintf(outFile, (fontHeader->char_range.min_char.low > 0 ? + "C%06o" : "C%03o"), encoding); + fputc('\n', outFile); + fprintf(outFile, "ENCODING %u\n", encoding); + fprintf(outFile, "SWIDTH %ld 0\n", + (((long) charInfo->width) * 72000L) / + (pointSize * yResolution)); + fprintf(outFile, "DWIDTH %d 0\n", charInfo->width); + fprintf(outFile, "BBX %d %d %d %d\n", + charInfo->right - charInfo->left, + charInfo->ascent + charInfo->descent, + charInfo->left, + -charInfo->descent); + if (charInfo->attributes) + fprintf(outFile, "ATTRIBUTES 0x%04x\n", charInfo->attributes); + + /* + * emit the bitmap + */ + fprintf(outFile, "BITMAP\n"); + for (row = 0; row < (charInfo->ascent + charInfo->descent); row++) { + unsigned byte; + unsigned bit; + + static unsigned maskTab[] = + { + (1 << 7), (1 << 6), (1 << 5), (1 << 4), + (1 << 3), (1 << 2), (1 << 1), (1 << 0), + }; + + byte = 0; + for (bit = 0; bit < (charInfo->right - charInfo->left); bit++) { + byte |= maskTab[bit & 7] & data[bit >> 3]; + if ((bit & 7) == 7) { + fprintf(outFile, "%02x", byte); + byte = 0; + } + } + if ((bit & 7) != 0) + fprintf(outFile, "%02x", byte); + fputc('\n', outFile); + data += bpr; + } + fprintf(outFile, "ENDCHAR\n"); +} + + +Bool +EmitCharacters(outFile, fontServer, fontHeader, fontID) + FILE *outFile; + FSServer *fontServer; + FSXFontInfoHeader *fontHeader; + Font fontID; +{ + FSXCharInfo *extents; + FSXCharInfo *charInfo; + int encoding; + FSOffset *offsets; + unsigned char *glyph; + unsigned char *glyphs; + unsigned int nChars; + int firstChar; + int lastChar; + int ch; + FSBitmapFormat format; + + nChars = 0; + + format = BYTE_ORDER | BIT_ORDER | SCANLINE_UNIT | + SCANLINE_PAD | EXTENTS; + firstChar = (fontHeader->char_range.min_char.high << 8) + + fontHeader->char_range.min_char.low; + lastChar = (fontHeader->char_range.max_char.high << 8) + + fontHeader->char_range.max_char.low; + + (void) FSQueryXExtents16(fontServer, fontID, True, (FSChar2b *) 0, 0, + &extents); + (void) FSQueryXBitmaps16(fontServer, fontID, format, True, (FSChar2b *) 0, + 0, &offsets, &glyphs); + + charInfo = extents; + /* calculate the actual number of chars */ + for (ch = 0; ch <= (lastChar - firstChar); ch++) { + if ((charInfo->width != 0) || (charInfo->left != charInfo->right)) + nChars++; + charInfo++; + } + + fprintf(outFile, "CHARS %u\n", nChars); + + /* + * actually emit the characters + */ + charInfo = extents; + encoding = firstChar; + glyph = glyphs; + for (ch = 0; ch <= (lastChar - firstChar); ch++) { + int bpr; + + bpr = GLWIDTHBYTESPADDED((charInfo->right - charInfo->left), + SCANLINE_PAD_BYTES); + if ((charInfo->width != 0) || (charInfo->right != charInfo->left)) + EmitBitmap(outFile, fontHeader, charInfo, encoding, bpr, glyph); + glyph += (charInfo->descent + charInfo->ascent) * bpr; + + charInfo++; + encoding++; + } + FSFree((char *) extents); + FSFree((char *) glyphs); + FSFree((char *) offsets); + return (True); +} diff --git a/programs/fstobdf/fstobdf.c b/programs/fstobdf/fstobdf.c new file mode 100644 index 000000000..569354399 --- /dev/null +++ b/programs/fstobdf/fstobdf.c @@ -0,0 +1,137 @@ +/* $XConsortium: fstobdf.c,v 1.5 94/04/17 20:24:27 gildea Exp $ */ +/* + +Copyright (c) 1990 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + + * Copyright 1990 Network Computing Devices; + * Portions Copyright 1987 by Digital Equipment Corporation + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of Network Computing Devices, or Digital + * not be used in advertising or publicity pertaining to distribution + * of the software without specific, written prior permission. + * + * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, + * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + * THIS SOFTWARE. + */ + +#include <stdio.h> +#include "FSlib.h" + +extern Bool EmitHeader(); +extern Bool EmitProperties(); +extern Bool EmitCharacters(); +extern Bool EmitTrailer(); + +static void +usage(progName) + char *progName; +{ + fprintf(stderr, "Usage: %s [-s <font server>] -fn <font name>\n", + progName); + exit(0); +} + +main(argc, argv) + int argc; + char **argv; +{ + FSServer *fontServer; + Font fontID, + dummy; + FSBitmapFormat bitmapFormat; + FSXFontInfoHeader fontHeader; + FSPropInfo propInfo; + FSPropOffset *propOffsets; + unsigned char *propData; + + FILE *outFile; + char *fontName; + char *serverName; + int i; + + fontName = NULL; + serverName = NULL; + outFile = stdout; + + for (i = 1; i < argc; i++) { + if (!strncmp(argv[i], "-s", 2)) { + if (argv[++i]) + serverName = argv[i]; + else + usage(argv[0]); + } else if (!strncmp(argv[i], "-fn", 3)) { + if (argv[++i]) + fontName = argv[i]; + else + usage(argv[0]); + } + } + + if (fontName == NULL) + usage(argv[0]); + + fontServer = FSOpenServer(serverName); + if (!fontServer) { + fprintf(stderr, "can't open font server \"%s\"\n", + FSServerName(serverName)); + exit(0); + } + bitmapFormat = 0; + fontID = FSOpenBitmapFont(fontServer, bitmapFormat, (FSBitmapFormatMask) 0, + fontName, &dummy); + if (!fontID) { + printf("can't open font \"%s\"\n", fontName); + exit(0); + } + FSQueryXInfo(fontServer, fontID, &fontHeader, &propInfo, &propOffsets, + &propData); + + if (!EmitHeader(outFile, &fontHeader, &propInfo, propOffsets, propData)) + Fail(argv[0]); + if (!EmitProperties(outFile, &fontHeader, &propInfo, propOffsets, propData)) + Fail(argv[0]); + if (!EmitCharacters(outFile, fontServer, &fontHeader, fontID)) + Fail(argv[0]); + fprintf(outFile, "ENDFONT\n"); + + FSFree((char *) propOffsets); + FSFree((char *) propData); +} + +Fail(progName) + char *progName; +{ + fprintf(stderr, "%s: unable to dump font\n", progName); + exit(1); +} diff --git a/programs/fstobdf/fstobdf.man b/programs/fstobdf/fstobdf.man new file mode 100644 index 000000000..f63dfb4d2 --- /dev/null +++ b/programs/fstobdf/fstobdf.man @@ -0,0 +1,63 @@ +.\" $XConsortium: fstobdf.man,v 1.6 94/04/17 20:24:27 gildea Exp $ +.\" Copyright 1990, Network Computing Devices +.\" Copyright (c) 1990 X Consortium +.\" +.\" Permission is hereby granted, free of charge, to any person obtaining +.\" a copy of this software and associated documentation files (the +.\" "Software"), to deal in the Software without restriction, including +.\" without limitation the rights to use, copy, modify, merge, publish, +.\" distribute, sublicense, and/or sell copies of the Software, and to +.\" permit persons to whom the Software is furnished to do so, subject to +.\" the following conditions: +.\" +.\" The above copyright notice and this permission notice shall be included +.\" in all copies or substantial portions of the Software. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +.\" IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +.\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +.\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +.\" OTHER DEALINGS IN THE SOFTWARE. +.\" +.\" Except as contained in this notice, the name of the X Consortium shall +.\" not be used in advertising or otherwise to promote the sale, use or +.\" other dealings in this Software without prior written authorization +.\" from the X Consortium. +.TH FSTOBDF 1 "Release 6" "X Version 11" +.SH NAME +fstobdf \- generate BDF font from X font server +.SH SYNOPSIS +.B "fstobdf" +[ +.B \-server +.I server +] +.B \-fn +.I fontname +.SH DESCRIPTION +The \fIfstobdf\fP program reads a font from a font server and prints a BDF +file on the standard output that may be used to recreate the font. +This is useful in testing servers, debugging font metrics, and reproducing +lost BDF files. +.SH OPTIONS +.TP 8 +.B \-server \fIservername\fP +This option specifies the server from which the font should be read. +.TP 8 +.B \-fn \fIfontname\fP +This option specifies the font for which a BDF file should be generated. +.SH ENVIRONMENT +.TP 8 +.B FONTSERVER +default server to use +.SH "SEE ALSO" +xfs(1), bdftopcf(1), fslsfonts(1) +.SH AUTHOR +Olaf Brandt, Network Computing Devices +.br +Dave Lemke, Network Computing Devices +.br +.sp +Jim Fulton, MIT X Consortium diff --git a/programs/fstobdf/header.c b/programs/fstobdf/header.c new file mode 100644 index 000000000..2da3109e3 --- /dev/null +++ b/programs/fstobdf/header.c @@ -0,0 +1,212 @@ +/* $XConsortium: header.c,v 1.5 94/04/17 20:24:28 hersh Exp $ */ +/* + +Copyright (c) 1990 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + + * Copyright 1990 Network Computing Devices; + * Portions Copyright 1987 by Digital Equipment Corporation + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of Network Computing Devices, or Digital + * not be used in advertising or publicity pertaining to distribution + * of the software without specific, written prior permission. + * + * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, + * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + * THIS SOFTWARE. + */ + +#include <stdio.h> +#include "FSlib.h" + +long pointSize; +long yResolution; + +static char *warning[] = +{ + "COMMENT ", + "COMMENT WARNING: This bdf file was generated from a font server using", + "COMMENT fstobdf. The resulting font is subject to the same copyright,", + "COMMENT license, and trademark restrictions as the original font. The", + "COMMENT authors and distributors of fstobdf disclaim all liability for", + "COMMENT misuse of the program or its output.", + "COMMENT ", + NULL +}; + +static char * +FindStringProperty(propName, propLength, propInfo, propOffsets, propData) + char *propName; + int *propLength; + FSPropInfo *propInfo; + FSPropOffset *propOffsets; + unsigned char *propData; +{ + FSPropOffset *propOffset; + int length; + int i; + + propOffset = &propOffsets[0]; + length = strlen(propName); + for (i = propInfo->num_offsets; i--; propOffset++) { + if (propOffset->type == PropTypeString) { + +#ifdef DEBUG + char pname[256]; + + memmove( pname, propData + propOffset->name.position, + propOffset->name.length); + pname[propOffset->name.length] = '\0'; + fprintf(stderr, "prop name: %s (len %d)\n", + pname, propOffset->name.length); +#endif + + if ((propOffset->name.length == length) && + !strncmp(propData + propOffset->name.position, propName, length)) { + *propLength = propOffset->value.length; + return (char *)(propData + propOffset->value.position); + } + } + } + *propLength = 0; + return (NULL); +} + +static int +FindNumberProperty(propName, propValue, propInfo, propOffsets, propData) + char *propName; + int *propValue; + FSPropInfo *propInfo; + FSPropOffset *propOffsets; + unsigned char *propData; +{ + FSPropOffset *propOffset; + int i; + int length; + + propOffset = &propOffsets[0]; + length = strlen(propName); + for (i = propInfo->num_offsets; i--; propOffset++) { + if ((propOffset->type == PropTypeSigned) || + (propOffset->type == PropTypeUnsigned)) { + if ((propOffset->name.length == length) && + !strncmp(propData + propOffset->name.position, propName, length)) { + *propValue = propOffset->value.position; + return (propOffset->type); + } + } + } + return (-1); +} + +/* + * EmitHeader - print STARTFONT, COMMENT lines, FONT, SIZE, and + * FONTBOUNDINGBOX lines + */ +Bool +EmitHeader(outFile, fontHeader, propInfo, propOffsets, propData) + FILE *outFile; + FSXFontInfoHeader *fontHeader; + FSPropInfo *propInfo; + FSPropOffset *propOffsets; + unsigned char *propData; +{ + int len; + int type; + char *cp; + char **cpp; + unsigned long xResolution; + + fprintf(outFile, "STARTFONT 2.1\n"); + + /* + * find COPYRIGHT message and print it first, followed by warning + */ + cp = FindStringProperty("COPYRIGHT", &len, propInfo, propOffsets, + propData); + if (cp) { + fprintf(outFile, "COMMENT \nCOMMENT "); + fwrite(cp, 1, len, outFile); + fputc('\n', outFile); + } + for (cpp = warning; *cpp; cpp++) + fprintf(outFile, "%s\n", *cpp); + + /* + * FONT name + */ + cp = FindStringProperty("FONT", &len, propInfo, propOffsets, propData); + if (cp) { + fprintf(outFile, "FONT "); + fwrite(cp, 1, len, outFile); + fputc('\n', outFile); + } else { + fprintf(stderr, "unable to find FONT property\n"); + return (False); + } + + /* + * SIZE point xres yres + * + * Get XLFD values if possible, else fake it + */ + type = FindNumberProperty("RESOLUTION_X", &xResolution, propInfo, + propOffsets, propData); + if ((type != PropTypeUnsigned) && (type != PropTypeSigned)) + xResolution = 72; + + type = FindNumberProperty("RESOLUTION_Y", &yResolution, propInfo, + propOffsets, propData); + if ((type != PropTypeUnsigned) && (type != PropTypeSigned)) + yResolution = 72; + + type = FindNumberProperty("POINT_SIZE", &pointSize, propInfo, + propOffsets, propData); + if ((type == PropTypeUnsigned) || (type == PropTypeSigned)) + pointSize = (pointSize + 5) / 10; + else + pointSize = ((fontHeader->font_ascent + fontHeader->font_descent) + * 72) / yResolution; + + fprintf(outFile, "SIZE %d %d %d\n", pointSize, xResolution, yResolution); + + /* + * FONTBOUNDINGBOX width height xoff yoff + * + */ + fprintf(outFile, "FONTBOUNDINGBOX %d %d %d %d\n", + fontHeader->max_bounds.right - fontHeader->min_bounds.left, + fontHeader->max_bounds.ascent + fontHeader->max_bounds.descent, + fontHeader->min_bounds.left, + -fontHeader->max_bounds.descent); + return (True); +} diff --git a/programs/fstobdf/props.c b/programs/fstobdf/props.c new file mode 100644 index 000000000..9968dc537 --- /dev/null +++ b/programs/fstobdf/props.c @@ -0,0 +1,147 @@ +/* $XConsortium: props.c,v 1.4 94/04/17 20:24:28 gildea Exp $ */ +/* + +Copyright (c) 1990, 1991 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + + * Copyright 1990, 1991 Network Computing Devices; + * Portions Copyright 1987 by Digital Equipment Corporation + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of Network Computing Devices, or Digital + * not be used in advertising or publicity pertaining to distribution + * of the software without specific, written prior permission. + * + * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, + * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + * THIS SOFTWARE. + */ + +#include <stdio.h> +#include "FSlib.h" + +static char * +AddQuotes(string, length) + unsigned char *string; + int length; +{ + static unsigned char new[256] = "\""; + unsigned char *cp; + unsigned char *end; + + end = string + length; + for (cp = &new[1]; string < end; cp++, string++) { + *cp = *string; + if (*cp == '"') + *++cp = '"'; + } + *cp++ = '"'; + *cp = '\0'; + return (char *)(new); +} + +Bool +EmitProperties(outFile, fontHeader, propInfo, propOffsets, propData) + FILE *outFile; + FSXFontInfoHeader *fontHeader; + FSPropInfo *propInfo; + FSPropOffset *propOffsets; + unsigned char *propData; +{ + int nProperties; + FSPropOffset *property; + Bool needDefaultChar; + Bool needFontAscent; + Bool needFontDescent; + + needDefaultChar = True; + needFontAscent = True; + needFontDescent = True; + + nProperties = propInfo->num_offsets; + for (property = &propOffsets[0]; nProperties--; property++) { + unsigned char *name; + int length; + + name = propData + property->name.position; + length = property->name.length; + + if ((length == 12) && (!strncmp(name, "DEFAULT_CHAR", 12))) + needDefaultChar = False; + else if ((length == 11) && (!strncmp(name, "FONT_ASCENT", 11))) + needFontAscent = False; + else if ((length == 12) && (!strncmp(name, "FONT_DESCENT", 12))) + needFontDescent = False; + } + + nProperties = propInfo->num_offsets; + fprintf(outFile, "STARTPROPERTIES %d\n", nProperties + + (needDefaultChar ? 1 : 0) + (needFontAscent ? 1 : 0) + + (needFontDescent ? 1 : 0)); + + for (property = &propOffsets[0]; nProperties--; property++) { + unsigned long value; + + /* Don't emit properties that are computed by bdftosnf */ + + fwrite(propData + property->name.position, 1, property->name.length, + outFile); + fputc(' ', outFile); + + value = property->value.position; + switch (property->type) { + case PropTypeString: + fprintf(outFile, "%s\n", AddQuotes(propData + value, + property->value.length)); + break; + case PropTypeUnsigned: + fprintf(outFile, "%lu\n", value); + break; + case PropTypeSigned: + fprintf(outFile, "%ld\n", value); + break; + default: + fprintf(stderr, "unknown property type\n"); + return (False); + } + } + if (needDefaultChar) { + fprintf(outFile, "DEFAULT_CHAR %lu\n", + (long) (fontHeader->default_char.high << 8) + | (fontHeader->default_char.low)); + } + if (needFontAscent) + fprintf(outFile, "FONT_ASCENT %d\n", fontHeader->font_ascent); + if (needFontDescent) + fprintf(outFile, "FONT_DESCENT %d\n", fontHeader->font_descent); + fprintf(outFile, "ENDPROPERTIES\n"); + return (True); +} |