PageRenderTime 34ms CodeModel.GetById 1ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/groff/src/utils/addftinfo/guess.cpp

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