home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / print / ascii2ps / nenscrib / fontwidt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  2.0 KB  |  94 lines

  1. /*
  2.  *   $Id: fontwidt.c,v 1.2 1992/10/02 01:02:32 craigs Exp $
  3.  *
  4.  *   This code was written by Craig Southeren whilst under contract
  5.  *   to Computer Sciences of Australia, Systems Engineering Division.
  6.  *   It has been kindly released by CSA into the public domain.
  7.  *
  8.  *   Neither CSA or me guarantee that this source code is fit for anything,
  9.  *   so use it at your peril. I don't even work for CSA any more, so
  10.  *   don't bother them about it. If you have any suggestions or comments
  11.  *   (or money, cheques, free trips =8^) !!!!! ) please contact me
  12.  *   care of geoffw@extro.ucc.oz.au
  13.  *
  14.  */
  15.  
  16. #include "machdep.h"
  17. #include "defs.h"
  18.  
  19. #include "fontwidt.h"
  20. #include "main.h"
  21.  
  22. /********************************
  23.   globals
  24.  ********************************/
  25.  
  26. /* this table contains the width of a space character for each size of font multiplied by 100
  27.  
  28.   it was produced by the following postscript code
  29.  
  30. %!
  31. /str 10 string def
  32.  
  33. /doit { dup /Courier findfont exch scalefont setfont ( ) stringwidth pop 100 mul cvi str cvs print (, \/* ) print str cvs print ( *\/\n) print } def
  34.  
  35. 5 1 30 { doit } for
  36.  
  37. */
  38.  
  39. static int CourierFontWidths[] = {
  40.  
  41. 299, /* 5 */
  42. 359, /* 6 */
  43. 419, /* 7 */
  44. 479, /* 8 */
  45. 539, /* 9 */
  46. 599, /* 10 */
  47. 659, /* 11 */
  48. 719, /* 12 */
  49. 779, /* 13 */
  50. 839, /* 14 */
  51. 899, /* 15 */
  52. 959, /* 16 */
  53. 1019, /* 17 */
  54. 1079, /* 18 */
  55. 1139, /* 19 */
  56. 1199, /* 20 */
  57. 1259, /* 21 */
  58. 1319, /* 22 */
  59. 1379, /* 23 */
  60. 1439, /* 24 */
  61. 1499, /* 25 */
  62. 1559, /* 26 */
  63. 1619, /* 27 */
  64. 1679, /* 28 */
  65. 1739, /* 29 */
  66. 1799, /* 30 */
  67. };
  68.  
  69.  
  70. /********************************
  71.   function
  72.  ********************************/
  73.  
  74. int GetFontWidth (fontname, size)
  75.  
  76. char *fontname;
  77. long  size;
  78.  
  79. {
  80.   size /= 100;
  81.  
  82.   if (strcmp (fontname, "Courier") != 0) {
  83.     fprintf (stderr, "%s: can only use Courier - sorry!!\n", progname);
  84.     exit (1);
  85.   }
  86.  
  87.   if (size < 5 || size > 30) {
  88.     fprintf (stderr, "%s: %i not bwteen valid font sizes of 5 and 30 - sorry!!\n", progname, size);
  89.     exit (1);
  90.   }
  91.  
  92.   return CourierFontWidths [size-5];
  93. }
  94.