header.c revision 21c2f794
1/* $Xorg: header.c,v 1.4 2001/02/09 02:05:30 xorgcvs Exp $ */ 2/* 3 4Copyright 1990, 1998 The Open Group 5 6Permission to use, copy, modify, distribute, and sell this software and its 7documentation for any purpose is hereby granted without fee, provided that 8the above copyright notice appear in all copies and that both that 9copyright notice and this permission notice appear in supporting 10documentation. 11 12The above copyright notice and this permission notice shall be included in 13all copies or substantial portions of the Software. 14 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22Except as contained in this notice, the name of The Open Group shall not be 23used in advertising or otherwise to promote the sale, use or other dealings 24in this Software without prior written authorization from The Open Group. 25 26 * Copyright 1990 Network Computing Devices; 27 * Portions Copyright 1987 by Digital Equipment Corporation 28 * 29 * Permission to use, copy, modify, distribute, and sell this software and 30 * its documentation for any purpose is hereby granted without fee, provided 31 * that the above copyright notice appear in all copies and that both that 32 * copyright notice and this permission notice appear in supporting 33 * documentation, and that the names of Network Computing Devices, or Digital 34 * not be used in advertising or publicity pertaining to distribution 35 * of the software without specific, written prior permission. 36 * 37 * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH 38 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF 39 * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, 40 * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 41 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 42 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 43 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 44 * THIS SOFTWARE. 45 */ 46/* $XFree86: xc/programs/fstobdf/header.c,v 3.6 2001/07/25 15:05:13 dawes Exp $ */ 47 48#include <stdio.h> 49#include <X11/Xosdefs.h> 50#include <stdlib.h> 51#include <string.h> 52#include "fstobdf.h" 53 54unsigned long pointSize; 55unsigned long yResolution; 56 57static char *warning[] = 58{ 59 "COMMENT ", 60 "COMMENT WARNING: This bdf file was generated from a font server using", 61 "COMMENT fstobdf. The resulting font is subject to the same copyright,", 62 "COMMENT license, and trademark restrictions as the original font. The", 63 "COMMENT authors and distributors of fstobdf disclaim all liability for", 64 "COMMENT misuse of the program or its output.", 65 "COMMENT ", 66 NULL 67}; 68 69static char * 70FindStringProperty(char *propName, 71 int *propLength, 72 FSPropInfo *propInfo, 73 FSPropOffset *propOffsets, 74 unsigned char *propData) 75{ 76 FSPropOffset *propOffset; 77 int length; 78 int i; 79 80 propOffset = &propOffsets[0]; 81 length = strlen(propName); 82 for (i = propInfo->num_offsets; i--; propOffset++) { 83 if (propOffset->type == PropTypeString) { 84 85#ifdef DEBUG 86 char pname[256]; 87 88 memmove( pname, propData + propOffset->name.position, 89 propOffset->name.length); 90 pname[propOffset->name.length] = '\0'; 91 fprintf(stderr, "prop name: %s (len %d)\n", 92 pname, propOffset->name.length); 93#endif 94 95 if ((propOffset->name.length == length) && 96 !strncmp((char*)propData + propOffset->name.position, propName, length)) { 97 *propLength = propOffset->value.length; 98 return (char *)(propData + propOffset->value.position); 99 } 100 } 101 } 102 *propLength = 0; 103 return (NULL); 104} 105 106static int 107FindNumberProperty(char *propName, 108 unsigned long *propValue, 109 FSPropInfo *propInfo, 110 FSPropOffset *propOffsets, 111 unsigned char *propData) 112{ 113 FSPropOffset *propOffset; 114 int i; 115 int length; 116 117 propOffset = &propOffsets[0]; 118 length = strlen(propName); 119 for (i = propInfo->num_offsets; i--; propOffset++) { 120 if ((propOffset->type == PropTypeSigned) || 121 (propOffset->type == PropTypeUnsigned)) { 122 if ((propOffset->name.length == length) && 123 !strncmp((char*)propData + propOffset->name.position, propName, length)) { 124 *propValue = propOffset->value.position; 125 return (propOffset->type); 126 } 127 } 128 } 129 return (-1); 130} 131 132/* 133 * EmitHeader - print STARTFONT, COMMENT lines, FONT, SIZE, and 134 * FONTBOUNDINGBOX lines 135 */ 136Bool 137EmitHeader(FILE *outFile, 138 FSXFontInfoHeader *fontHeader, 139 FSPropInfo *propInfo, 140 FSPropOffset *propOffsets, 141 unsigned char *propData) 142{ 143 int len; 144 int type; 145 char *cp; 146 char **cpp; 147 unsigned long xResolution; 148 149 fprintf(outFile, "STARTFONT 2.1\n"); 150 151 /* 152 * find COPYRIGHT message and print it first, followed by warning 153 */ 154 cp = FindStringProperty("COPYRIGHT", &len, propInfo, propOffsets, 155 propData); 156 if (cp) { 157 fprintf(outFile, "COMMENT \nCOMMENT "); 158 fwrite(cp, 1, len, outFile); 159 fputc('\n', outFile); 160 } 161 for (cpp = warning; *cpp; cpp++) 162 fprintf(outFile, "%s\n", *cpp); 163 164 /* 165 * FONT name 166 */ 167 cp = FindStringProperty("FONT", &len, propInfo, propOffsets, propData); 168 if (cp) { 169 fprintf(outFile, "FONT "); 170 fwrite(cp, 1, len, outFile); 171 fputc('\n', outFile); 172 } else { 173 fprintf(stderr, "unable to find FONT property\n"); 174 return (False); 175 } 176 177 /* 178 * SIZE point xres yres 179 * 180 * Get XLFD values if possible, else fake it 181 */ 182 type = FindNumberProperty("RESOLUTION_X", &xResolution, propInfo, 183 propOffsets, propData); 184 if ((type != PropTypeUnsigned) && (type != PropTypeSigned)) 185 xResolution = 72; 186 187 type = FindNumberProperty("RESOLUTION_Y", &yResolution, propInfo, 188 propOffsets, propData); 189 if ((type != PropTypeUnsigned) && (type != PropTypeSigned)) 190 yResolution = 72; 191 192 type = FindNumberProperty("POINT_SIZE", &pointSize, propInfo, 193 propOffsets, propData); 194 if ((type == PropTypeUnsigned) || (type == PropTypeSigned)) 195 pointSize = (pointSize + 5) / 10; 196 else 197 pointSize = ((fontHeader->font_ascent + fontHeader->font_descent) 198 * 72) / yResolution; 199 200 fprintf(outFile, "SIZE %lu %lu %lu\n", pointSize, xResolution, 201 yResolution); 202 203 /* 204 * FONTBOUNDINGBOX width height xoff yoff 205 * 206 */ 207 fprintf(outFile, "FONTBOUNDINGBOX %d %d %d %d\n", 208 fontHeader->max_bounds.right - fontHeader->min_bounds.left, 209 fontHeader->max_bounds.ascent + fontHeader->max_bounds.descent, 210 fontHeader->min_bounds.left, 211 -fontHeader->max_bounds.descent); 212 return (True); 213} 214