1/* 2 3Copyright 1990, 1991, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in this Software without prior written authorization from The Open Group. 24 25 * Copyright 1990, 1991 Network Computing Devices; 26 * Portions Copyright 1987 by Digital Equipment Corporation 27 * 28 * Permission to use, copy, modify, distribute, and sell this software and 29 * its documentation for any purpose is hereby granted without fee, provided 30 * that the above copyright notice appear in all copies and that both that 31 * copyright notice and this permission notice appear in supporting 32 * documentation, and that the names of Network Computing Devices, or Digital 33 * not be used in advertising or publicity pertaining to distribution 34 * of the software without specific, written prior permission. 35 * 36 * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH 37 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF 38 * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, 39 * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 40 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 41 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 42 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 43 * THIS SOFTWARE. 44 */ 45 46#include <stdio.h> 47#include <string.h> 48#include "fstobdf.h" 49 50static char * 51AddQuotes(const unsigned char *string, unsigned int length) 52{ 53 static unsigned char new[256] = "\""; 54 unsigned char *cp; 55 const unsigned char *end; 56 57 end = string + length; 58 for (cp = &new[1]; string < end; cp++, string++) { 59 *cp = *string; 60 if (*cp == '"') 61 *++cp = '"'; 62 } 63 *cp++ = '"'; 64 *cp = '\0'; 65 return (char *) (new); 66} 67 68Bool 69EmitProperties(FILE *outFile, 70 FSXFontInfoHeader *fontHeader, 71 FSPropInfo *propInfo, 72 FSPropOffset *propOffsets, 73 unsigned char *propData) 74{ 75 unsigned int nProperties; 76 FSPropOffset *property; 77 Bool needDefaultChar; 78 Bool needFontAscent; 79 Bool needFontDescent; 80 81 needDefaultChar = True; 82 needFontAscent = True; 83 needFontDescent = True; 84 85 nProperties = propInfo->num_offsets; 86 for (property = &propOffsets[0]; nProperties--; property++) { 87 char *name; 88 unsigned int length; 89 90 name = (char *) propData + property->name.position; 91 length = property->name.length; 92 93 if ((length == 12) && (!strncmp(name, "DEFAULT_CHAR", 12))) 94 needDefaultChar = False; 95 else if ((length == 11) && (!strncmp(name, "FONT_ASCENT", 11))) 96 needFontAscent = False; 97 else if ((length == 12) && (!strncmp(name, "FONT_DESCENT", 12))) 98 needFontDescent = False; 99 } 100 101 nProperties = propInfo->num_offsets; 102 fprintf(outFile, "STARTPROPERTIES %d\n", nProperties + 103 (needDefaultChar ? 1 : 0) + (needFontAscent ? 1 : 0) + 104 (needFontDescent ? 1 : 0)); 105 106 for (property = &propOffsets[0]; nProperties--; property++) { 107 unsigned long value; 108 109 /* Don't emit properties that are computed by bdftosnf */ 110 111 fwrite(propData + property->name.position, 1, property->name.length, 112 outFile); 113 fputc(' ', outFile); 114 115 value = property->value.position; 116 switch (property->type) { 117 case PropTypeString: 118 fprintf(outFile, "%s\n", AddQuotes(propData + value, 119 property->value.length)); 120 break; 121 case PropTypeUnsigned: 122 fprintf(outFile, "%lu\n", value); 123 break; 124 case PropTypeSigned: 125 fprintf(outFile, "%ld\n", (signed long) value); 126 break; 127 default: 128 fprintf(stderr, "unknown property type\n"); 129 return (False); 130 } 131 } 132 if (needDefaultChar) { 133 fprintf(outFile, "DEFAULT_CHAR %lu\n", 134 (long) (fontHeader->default_char.high << 8) 135 | (fontHeader->default_char.low)); 136 } 137 if (needFontAscent) 138 fprintf(outFile, "FONT_ASCENT %d\n", fontHeader->font_ascent); 139 if (needFontDescent) 140 fprintf(outFile, "FONT_DESCENT %d\n", fontHeader->font_descent); 141 fprintf(outFile, "ENDPROPERTIES\n"); 142 return (True); 143} 144