1#! /bin/awk -f 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License, Version 1.0 only 7# (the "License"). You may not use this file except in compliance 8# with the License. 9# 10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11# or http://www.opensolaris.org/os/licensing. 12# See the License for the specific language governing permissions 13# and limitations under the License. 14# 15# When distributing Covered Code, include this CDDL HEADER in each 16# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17# If applicable, add the following below this CDDL HEADER, with the 18# fields enclosed by brackets "[]" replaced with your own identifying 19# information: Portions Copyright [yyyy] [name of copyright owner] 20# 21# CDDL HEADER END 22# 23# 24# Copyright (c) 1998-1999 by Sun Microsystems, Inc. 25# All rights reserved. 26# 27#pragma ident "%Z%%M% %I% %E% SMI" 28# 29 30BEGIN { 31 pats["0"]=" "; 32 pats["1"]=" X"; 33 pats["2"]=" X "; 34 pats["3"]=" XX"; 35 pats["4"]=" X "; 36 pats["5"]=" X X"; 37 pats["6"]=" XX "; 38 pats["7"]=" XXX"; 39 pats["8"]="X "; 40 pats["9"]="X X"; 41 pats["a"]="X X "; pats["A"] = pats["a"]; 42 pats["b"]="X XX"; pats["B"] = pats["b"]; 43 pats["c"]="XX "; pats["C"] = pats["c"]; 44 pats["d"]="XX X"; pats["D"] = pats["d"]; 45 pats["e"]="XXX "; pats["E"] = pats["e"]; 46 pats["f"]="XXXX"; pats["F"] = pats["f"]; 47} 48 49$1=="ENDCHAR" { 50 in_bitmap = 0; 51 next; 52} 53 54in_bitmap != 0 { 55 if (ignoring) next; 56 57 for (c = 0; c < byteswide; c++) 58 printf "0x%s, ", substr($0,c*2+1,2); 59 s=""; 60 for (c = 0; c < byteswide*2; c++) 61 s = s pats[substr($0,c+1,1)]; 62 s = substr(s, 1, bitswide); 63 printf "/* %s */\n", s; 64 65 offset += length($0)/2; 66 next; 67} 68 69$1=="STARTFONT" { 70 if ($2 != "2.1") { 71 printf "Unknown BDF version number %s!\n", $2; 72 exit 1; 73 } 74 in_bitmap = 0; 75 ignoring = 1; 76 first = 1; 77 offset = 0; 78 79 for (i = 0; i < 256; i++) 80 encoding[i] = -1; 81 82 next; 83} 84 85$1=="COMMENT" { 86 if (NF > 1) { 87 printf "/*"; 88 for (i = 2; i < NF; i++) 89 printf " %s",$i; 90 printf " */"; 91 } 92 printf "\n"; 93 next; 94} 95 96$1=="FONT" { 97 printf "/* %s */\n", $0; 98 next; 99} 100 101$1=="SIZE" { 102 next; 103} 104 105$1=="FONTBOUNDINGBOX" { 106 rows = $3; 107 byteswide = int(($2 + 7)/8); 108 bitswide = $2; 109 next; 110} 111 112$1=="STARTPROPERTIES" { 113 next; 114} 115 116$1=="FONTNAME_REGISTRY" { 117 next; 118} 119 120$1=="FOUNDRY" { 121 next; 122} 123 124$1=="FAMILY_NAME" { 125 next; 126} 127 128$1=="WEIGHT_NAME" { 129 next; 130} 131 132$1=="SLANT" { 133 next; 134} 135 136$1=="SETWIDTH_NAME" { 137 next; 138} 139 140$1=="ADD_STYLE_NAME" { 141 next; 142} 143 144$1=="PIXEL_SIZE" { 145 next; 146} 147 148$1=="POINT_SIZE" { 149 next; 150} 151 152$1=="RESOLUTION_X" { 153 next; 154} 155 156$1=="RESOLUTION_Y" { 157 next; 158} 159 160 161$1=="SPACING" { 162 if ($2 != "\"C\"") printf "Unsupported format %s!\n",$2; 163 next; 164} 165 166$1=="AVERAGE_WIDTH" { 167 next; 168} 169 170$1=="CHARSET_REGISTRY" { 171 next; 172} 173 174$1=="CHARSET_ENCODING" { 175 next; 176} 177 178 179$1=="DEFAULT_CHAR" { 180 default_char = $2; 181 next; 182} 183 184$1=="FONT_DESCENT" { 185 next; 186} 187 188$1=="FONT_ASCENT" { 189 next; 190} 191 192 193$1=="COPYRIGHT" { 194 printf "/* Copyright notice from .bdf file: */\n"; 195 printf "/* %s */\n", $0; 196 next; 197} 198 199$1=="ENDPROPERTIES" { 200 next; 201} 202 203$1=="CHARS" { 204 next; 205} 206 207 208$1=="STARTCHAR" { 209 if (first) { 210 printf "unsigned char FONTDATA[] = {\n"; 211 first = 0; 212 } 213 ignoring = 1; 214 row = 0; 215 next; 216} 217 218$1=="ENCODING" { 219 encoding[$2] = offset; 220 ignoring = 0; 221 got[$2] = 1; 222 printf "\n"; 223 if ($2 >= 32 && $2 < 127) printf "/* '%c' */\n", $2; 224 else printf "/* 0x%2.2x */\n", $2; 225 next; 226} 227 228$1=="SWIDTH" { 229 next; 230} 231 232$1=="DWIDTH" { 233 next; 234} 235 236$1=="BBX" { 237 next; 238} 239 240$1=="BITMAP" { 241 in_bitmap = 1; 242 next; 243} 244 245$1=="ENDFONT" { 246 printf "};\n"; 247 printf "\n"; 248 printf "unsigned char *ENCODINGS[256] = {\n"; 249 250 for (i = 0; i < 256; i++) { 251 if (encoding[i] == -1) encoding[i] = encoding[default_char]; 252 printf "\tFONTDATA+%d,\n", encoding[i]; 253 } 254 printf "};\n"; 255 next; 256} 257 258{ 259 printf "?!? %s\n", $0; 260} 261