From 0f05b729fa8590f7473af78b1532cd9a3d589f1b Mon Sep 17 00:00:00 2001 From: Kaleb Keithley Date: Fri, 14 Nov 2003 15:54:52 +0000 Subject: R6.6 is the Xorg base-line --- chars.c | 215 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fstobdf.c | 136 ++++++++++++++++++++++++++++++++++++++ fstobdf.man | 61 +++++++++++++++++ header.c | 211 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ props.c | 146 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 769 insertions(+) create mode 100644 chars.c create mode 100644 fstobdf.c create mode 100644 fstobdf.man create mode 100644 header.c create mode 100644 props.c diff --git a/chars.c b/chars.c new file mode 100644 index 0000000..a0b0d26 --- /dev/null +++ b/chars.c @@ -0,0 +1,215 @@ +/* $Xorg: chars.c,v 1.4 2001/02/09 02:05:30 xorgcvs Exp $ */ +/* + +Copyright 1990, 1998 The Open Group + +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. + +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 +OPEN GROUP 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 Open Group 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 Open Group. + + * 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 +#include +#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/fstobdf.c b/fstobdf.c new file mode 100644 index 0000000..48d560a --- /dev/null +++ b/fstobdf.c @@ -0,0 +1,136 @@ +/* $Xorg: fstobdf.c,v 1.4 2001/02/09 02:05:30 xorgcvs Exp $ */ +/* + +Copyright 1990, 1998 The Open Group + +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. + +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 +OPEN GROUP 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 Open Group 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 Open Group. + + * 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 +#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 ] -fn \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/fstobdf.man b/fstobdf.man new file mode 100644 index 0000000..06129fb --- /dev/null +++ b/fstobdf.man @@ -0,0 +1,61 @@ +.\" $Xorg: fstobdf.man,v 1.4 2001/02/09 02:05:30 xorgcvs Exp $ +.\" Copyright 1990, Network Computing Devices +.\" Copyright 1990, 1998 The Open Group +.\" +.\" 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. +.\" +.\" 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 OPEN GROUP 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 Open Group 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 Open Group. +.TH FSTOBDF 1 "Release 6.4" "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/header.c b/header.c new file mode 100644 index 0000000..2d99839 --- /dev/null +++ b/header.c @@ -0,0 +1,211 @@ +/* $Xorg: header.c,v 1.4 2001/02/09 02:05:30 xorgcvs Exp $ */ +/* + +Copyright 1990, 1998 The Open Group + +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. + +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 +OPEN GROUP 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 Open Group 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 Open Group. + + * 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 +#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/props.c b/props.c new file mode 100644 index 0000000..eaeb47f --- /dev/null +++ b/props.c @@ -0,0 +1,146 @@ +/* $Xorg: props.c,v 1.4 2001/02/09 02:05:30 xorgcvs Exp $ */ +/* + +Copyright 1990, 1991, 1998 The Open Group + +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. + +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 +OPEN GROUP 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 Open Group 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 Open Group. + + * 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 +#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); +} -- cgit v1.2.3