guess.cpp revision 1.1.1.1
1/* $NetBSD: guess.cpp,v 1.1.1.1 2016/01/13 18:41:49 christos Exp $ */ 2 3// -*- C++ -*- 4/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. 5 Written by James Clark (jjc@jclark.com) 6 7This file is part of groff. 8 9groff is free software; you can redistribute it and/or modify it under 10the terms of the GNU General Public License as published by the Free 11Software Foundation; either version 2, or (at your option) any later 12version. 13 14groff is distributed in the hope that it will be useful, but WITHOUT ANY 15WARRANTY; without even the implied warranty of MERCHANTABILITY or 16FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17for more details. 18 19You should have received a copy of the GNU General Public License along 20with groff; see the file COPYING. If not, write to the Free Software 21Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 22 23#include "guess.h" 24 25void guess(const char *s, const font_params ¶m, char_metric *metric) 26{ 27 int &height = metric->height; 28 int &depth = metric->depth; 29 30 metric->ic = 0; 31 metric->left_ic = 0; 32 metric->sk = 0; 33 height = 0; 34 depth = 0; 35 if (s[0] == '\0' || (s[1] != '\0' && s[2] != '\0')) 36 goto do_default; 37#define HASH(c1, c2) (((unsigned char)(c1) << 8) | (unsigned char)(c2)) 38 switch (HASH(s[0], s[1])) { 39 default: 40 do_default: 41 if (metric->type & 01) 42 depth = param.desc_depth; 43 if (metric->type & 02) 44 height = param.asc_height; 45 else 46 height = param.x_height; 47 break; 48 case HASH('\\', '|'): 49 case HASH('\\', '^'): 50 case HASH('\\', '&'): 51 // these have zero height and depth 52 break; 53 case HASH('f', 0): 54 height = param.asc_height; 55 if (param.italic) 56 depth = param.desc_depth; 57 break; 58 case HASH('a', 0): 59 case HASH('c', 0): 60 case HASH('e', 0): 61 case HASH('m', 0): 62 case HASH('n', 0): 63 case HASH('o', 0): 64 case HASH('r', 0): 65 case HASH('s', 0): 66 case HASH('u', 0): 67 case HASH('v', 0): 68 case HASH('w', 0): 69 case HASH('x', 0): 70 case HASH('z', 0): 71 height = param.x_height; 72 break; 73 case HASH('i', 0): 74 height = param.x_height; 75 break; 76 case HASH('b', 0): 77 case HASH('d', 0): 78 case HASH('h', 0): 79 case HASH('k', 0): 80 case HASH('l', 0): 81 case HASH('F', 'i'): 82 case HASH('F', 'l'): 83 case HASH('f', 'f'): 84 case HASH('f', 'i'): 85 case HASH('f', 'l'): 86 height = param.asc_height; 87 break; 88 case HASH('t', 0): 89 height = param.asc_height; 90 break; 91 case HASH('g', 0): 92 case HASH('p', 0): 93 case HASH('q', 0): 94 case HASH('y', 0): 95 height = param.x_height; 96 depth = param.desc_depth; 97 break; 98 case HASH('j', 0): 99 height = param.x_height; 100 depth = param.desc_depth; 101 break; 102 case HASH('A', 0): 103 case HASH('B', 0): 104 case HASH('C', 0): 105 case HASH('D', 0): 106 case HASH('E', 0): 107 case HASH('F', 0): 108 case HASH('G', 0): 109 case HASH('H', 0): 110 case HASH('I', 0): 111 case HASH('J', 0): 112 case HASH('K', 0): 113 case HASH('L', 0): 114 case HASH('M', 0): 115 case HASH('N', 0): 116 case HASH('O', 0): 117 case HASH('P', 0): 118 case HASH('Q', 0): 119 case HASH('R', 0): 120 case HASH('S', 0): 121 case HASH('T', 0): 122 case HASH('U', 0): 123 case HASH('V', 0): 124 case HASH('W', 0): 125 case HASH('X', 0): 126 case HASH('Y', 0): 127 case HASH('Z', 0): 128 height = param.cap_height; 129 break; 130 case HASH('*', 'A'): 131 case HASH('*', 'B'): 132 case HASH('*', 'C'): 133 case HASH('*', 'D'): 134 case HASH('*', 'E'): 135 case HASH('*', 'F'): 136 case HASH('*', 'G'): 137 case HASH('*', 'H'): 138 case HASH('*', 'I'): 139 case HASH('*', 'K'): 140 case HASH('*', 'L'): 141 case HASH('*', 'M'): 142 case HASH('*', 'N'): 143 case HASH('*', 'O'): 144 case HASH('*', 'P'): 145 case HASH('*', 'Q'): 146 case HASH('*', 'R'): 147 case HASH('*', 'S'): 148 case HASH('*', 'T'): 149 case HASH('*', 'U'): 150 case HASH('*', 'W'): 151 case HASH('*', 'X'): 152 case HASH('*', 'Y'): 153 case HASH('*', 'Z'): 154 height = param.cap_height; 155 break; 156 case HASH('0', 0): 157 case HASH('1', 0): 158 case HASH('2', 0): 159 case HASH('3', 0): 160 case HASH('4', 0): 161 case HASH('5', 0): 162 case HASH('6', 0): 163 case HASH('7', 0): 164 case HASH('8', 0): 165 case HASH('9', 0): 166 case HASH('1', '2'): 167 case HASH('1', '4'): 168 case HASH('3', '4'): 169 height = param.fig_height; 170 break; 171 case HASH('(', 0): 172 case HASH(')', 0): 173 case HASH('[', 0): 174 case HASH(']', 0): 175 case HASH('{', 0): 176 case HASH('}', 0): 177 height = param.body_height; 178 depth = param.body_depth; 179 break; 180 case HASH('i', 's'): 181 height = (param.em*3)/4; 182 depth = param.em/4; 183 break; 184 case HASH('*', 'a'): 185 case HASH('*', 'e'): 186 case HASH('*', 'i'): 187 case HASH('*', 'k'): 188 case HASH('*', 'n'): 189 case HASH('*', 'o'): 190 case HASH('*', 'p'): 191 case HASH('*', 's'): 192 case HASH('*', 't'): 193 case HASH('*', 'u'): 194 case HASH('*', 'w'): 195 height = param.x_height; 196 break; 197 case HASH('*', 'd'): 198 case HASH('*', 'l'): 199 height = param.asc_height; 200 break; 201 case HASH('*', 'g'): 202 case HASH('*', 'h'): 203 case HASH('*', 'm'): 204 case HASH('*', 'r'): 205 case HASH('*', 'x'): 206 case HASH('*', 'y'): 207 height = param.x_height; 208 depth = param.desc_depth; 209 break; 210 case HASH('*', 'b'): 211 case HASH('*', 'c'): 212 case HASH('*', 'f'): 213 case HASH('*', 'q'): 214 case HASH('*', 'z'): 215 height = param.asc_height; 216 depth = param.desc_depth; 217 break; 218 case HASH('t', 's'): 219 height = param.x_height; 220 depth = param.desc_depth; 221 break; 222 case HASH('!', 0): 223 case HASH('?', 0): 224 case HASH('"', 0): 225 case HASH('#', 0): 226 case HASH('$', 0): 227 case HASH('%', 0): 228 case HASH('&', 0): 229 case HASH('*', 0): 230 case HASH('+', 0): 231 height = param.asc_height; 232 break; 233 case HASH('`', 0): 234 case HASH('\'', 0): 235 height = param.asc_height; 236 break; 237 case HASH('~', 0): 238 case HASH('^', 0): 239 case HASH('a', 'a'): 240 case HASH('g', 'a'): 241 height = param.asc_height; 242 break; 243 case HASH('r', 'u'): 244 case HASH('.', 0): 245 break; 246 case HASH(',', 0): 247 depth = param.comma_depth; 248 break; 249 case HASH('m', 'i'): 250 case HASH('-', 0): 251 case HASH('h', 'y'): 252 case HASH('e', 'm'): 253 height = param.x_height; 254 break; 255 case HASH(':', 0): 256 height = param.x_height; 257 break; 258 case HASH(';', 0): 259 height = param.x_height; 260 depth = param.comma_depth; 261 break; 262 case HASH('=', 0): 263 case HASH('e', 'q'): 264 height = param.x_height; 265 break; 266 case HASH('<', 0): 267 case HASH('>', 0): 268 case HASH('>', '='): 269 case HASH('<', '='): 270 case HASH('@', 0): 271 case HASH('/', 0): 272 case HASH('|', 0): 273 case HASH('\\', 0): 274 height = param.asc_height; 275 break; 276 case HASH('_', 0): 277 case HASH('u', 'l'): 278 case HASH('\\', '_'): 279 depth = param.em/4; 280 break; 281 case HASH('r', 'n'): 282 height = (param.em*3)/4; 283 break; 284 case HASH('s', 'r'): 285 height = (param.em*3)/4; 286 depth = param.em/4; 287 break; 288 case HASH('b', 'u'): 289 case HASH('s', 'q'): 290 case HASH('d', 'e'): 291 case HASH('d', 'g'): 292 case HASH('f', 'm'): 293 case HASH('c', 't'): 294 case HASH('r', 'g'): 295 case HASH('c', 'o'): 296 case HASH('p', 'l'): 297 case HASH('*', '*'): 298 case HASH('s', 'c'): 299 case HASH('s', 'l'): 300 case HASH('=', '='): 301 case HASH('~', '='): 302 case HASH('a', 'p'): 303 case HASH('!', '='): 304 case HASH('-', '>'): 305 case HASH('<', '-'): 306 case HASH('u', 'a'): 307 case HASH('d', 'a'): 308 case HASH('m', 'u'): 309 case HASH('d', 'i'): 310 case HASH('+', '-'): 311 case HASH('c', 'u'): 312 case HASH('c', 'a'): 313 case HASH('s', 'b'): 314 case HASH('s', 'p'): 315 case HASH('i', 'b'): 316 case HASH('i', 'p'): 317 case HASH('i', 'f'): 318 case HASH('p', 'd'): 319 case HASH('g', 'r'): 320 case HASH('n', 'o'): 321 case HASH('p', 't'): 322 case HASH('e', 's'): 323 case HASH('m', 'o'): 324 case HASH('b', 'r'): 325 case HASH('d', 'd'): 326 case HASH('r', 'h'): 327 case HASH('l', 'h'): 328 case HASH('o', 'r'): 329 case HASH('c', 'i'): 330 height = param.asc_height; 331 break; 332 case HASH('l', 't'): 333 case HASH('l', 'b'): 334 case HASH('r', 't'): 335 case HASH('r', 'b'): 336 case HASH('l', 'k'): 337 case HASH('r', 'k'): 338 case HASH('b', 'v'): 339 case HASH('l', 'f'): 340 case HASH('r', 'f'): 341 case HASH('l', 'c'): 342 case HASH('r', 'c'): 343 height = (param.em*3)/4; 344 depth = param.em/4; 345 break; 346#if 0 347 case HASH('%', '0'): 348 case HASH('-', '+'): 349 case HASH('-', 'D'): 350 case HASH('-', 'd'): 351 case HASH('-', 'd'): 352 case HASH('-', 'h'): 353 case HASH('.', 'i'): 354 case HASH('.', 'j'): 355 case HASH('/', 'L'): 356 case HASH('/', 'O'): 357 case HASH('/', 'l'): 358 case HASH('/', 'o'): 359 case HASH('=', '~'): 360 case HASH('A', 'E'): 361 case HASH('A', 'h'): 362 case HASH('A', 'N'): 363 case HASH('C', 's'): 364 case HASH('D', 'o'): 365 case HASH('F', 'c'): 366 case HASH('F', 'o'): 367 case HASH('I', 'J'): 368 case HASH('I', 'm'): 369 case HASH('O', 'E'): 370 case HASH('O', 'f'): 371 case HASH('O', 'K'): 372 case HASH('O', 'm'): 373 case HASH('O', 'R'): 374 case HASH('P', 'o'): 375 case HASH('R', 'e'): 376 case HASH('S', '1'): 377 case HASH('S', '2'): 378 case HASH('S', '3'): 379 case HASH('T', 'P'): 380 case HASH('T', 'p'): 381 case HASH('Y', 'e'): 382 case HASH('\\', '-'): 383 case HASH('a', '"'): 384 case HASH('a', '-'): 385 case HASH('a', '.'): 386 case HASH('a', '^'): 387 case HASH('a', 'b'): 388 case HASH('a', 'c'): 389 case HASH('a', 'd'): 390 case HASH('a', 'e'): 391 case HASH('a', 'h'): 392 case HASH('a', 'o'): 393 case HASH('a', 't'): 394 case HASH('a', '~'): 395 case HASH('b', 'a'): 396 case HASH('b', 'b'): 397 case HASH('b', 's'): 398 case HASH('c', '*'): 399 case HASH('c', '+'): 400 case HASH('f', '/'): 401 case HASH('f', 'a'): 402 case HASH('f', 'c'): 403 case HASH('f', 'o'): 404 case HASH('h', 'a'): 405 case HASH('h', 'o'): 406 case HASH('i', 'j'): 407 case HASH('l', 'A'): 408 case HASH('l', 'B'): 409 case HASH('l', 'C'): 410 case HASH('m', 'd'): 411 case HASH('n', 'c'): 412 case HASH('n', 'e'): 413 case HASH('n', 'm'): 414 case HASH('o', 'A'): 415 case HASH('o', 'a'): 416 case HASH('o', 'e'): 417 case HASH('o', 'q'): 418 case HASH('p', 'l'): 419 case HASH('p', 'p'): 420 case HASH('p', 's'): 421 case HASH('r', '!'): 422 case HASH('r', '?'): 423 case HASH('r', 'A'): 424 case HASH('r', 'B'): 425 case HASH('r', 'C'): 426 case HASH('r', 's'): 427 case HASH('s', 'h'): 428 case HASH('s', 's'): 429 case HASH('t', 'e'): 430 case HASH('t', 'f'): 431 case HASH('t', 'i'): 432 case HASH('t', 'm'): 433 case HASH('~', '~'): 434 case HASH('v', 'S'): 435 case HASH('v', 'Z'): 436 case HASH('v', 's'): 437 case HASH('v', 'z'): 438 case HASH('^', 'A'): 439 case HASH('^', 'E'): 440 case HASH('^', 'I'): 441 case HASH('^', 'O'): 442 case HASH('^', 'U'): 443 case HASH('^', 'a'): 444 case HASH('^', 'e'): 445 case HASH('^', 'i'): 446 case HASH('^', 'o'): 447 case HASH('^', 'u'): 448 case HASH('`', 'A'): 449 case HASH('`', 'E'): 450 case HASH('`', 'I'): 451 case HASH('`', 'O'): 452 case HASH('`', 'U'): 453 case HASH('`', 'a'): 454 case HASH('`', 'e'): 455 case HASH('`', 'i'): 456 case HASH('`', 'o'): 457 case HASH('`', 'u'): 458 case HASH('~', 'A'): 459 case HASH('~', 'N'): 460 case HASH('~', 'O'): 461 case HASH('~', 'a'): 462 case HASH('~', 'n'): 463 case HASH('~', 'o'): 464 case HASH('\'', 'A'): 465 case HASH('\'', 'C'): 466 case HASH('\'', 'E'): 467 case HASH('\'', 'I'): 468 case HASH('\'', 'O'): 469 case HASH('\'', 'U'): 470 case HASH('\'', 'a'): 471 case HASH('\'', 'c'): 472 case HASH('\'', 'e'): 473 case HASH('\'', 'i'): 474 case HASH('\'', 'o'): 475 case HASH('\'', 'u') 476 case HASH(':', 'A'): 477 case HASH(':', 'E'): 478 case HASH(':', 'I'): 479 case HASH(':', 'O'): 480 case HASH(':', 'U'): 481 case HASH(':', 'Y'): 482 case HASH(':', 'a'): 483 case HASH(':', 'e'): 484 case HASH(':', 'i'): 485 case HASH(':', 'o'): 486 case HASH(':', 'u'): 487 case HASH(':', 'y'): 488 case HASH(',', 'C'): 489 case HASH(',', 'c'): 490#endif 491 } 492} 493