home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / system / newpop-4.1 / calctextwidth.c < prev    next >
C/C++ Source or Header  |  1995-02-27  |  6KB  |  203 lines

  1. /*
  2.  *  CalcTextWidth.c -
  3.  *  Quick hack to calculate the MAXTEXTWIDTH parameter needed in
  4.  *  NewPop.c/.newpoprc.
  5.  *  Copyright (c) 1990, 1991 Loren J. Rittle
  6.  *
  7.  *  This program is in no way efficient or nice, but it is run only once
  8.  *  when NewPop is installed with a new font, so who cares.
  9.  *
  10.  *  Use: lc -L CalcTextWidth.c to compile under SAS/C v5.10.
  11.  */
  12.  
  13.  
  14. /* * * * * * * * * * * INCLUDES * * * * * * * * * * * * */
  15. #include <exec/types.h>
  16. #include <exec/exec.h>
  17. #include <exec/execbase.h>
  18. #include <exec/tasks.h>
  19. #include <devices/timer.h>
  20. #include <devices/input.h>
  21. #include <devices/inputevent.h>
  22. #include <intuition/intuition.h>
  23. #include <libraries/dos.h>
  24. #include <graphics/gfxmacros.h>
  25. #include <graphics/layers.h>
  26. #include <hardware/custom.h>
  27. #include <hardware/dmabits.h>
  28. #include <graphics/text.h>
  29. #include <proto/dos.h>
  30. #include <proto/exec.h>
  31. #include <proto/intuition.h>
  32. #include <proto/graphics.h>
  33. #include <proto/diskfont.h>
  34. #include <string.h>
  35. #include <time.h>
  36. #include <stdio.h>
  37.  
  38.  
  39. struct NewWindow NewWindow = 
  40. {
  41.   100,100,    /* window XY origin relative to TopLeft of screen */
  42.   200,100,    /* window width and height */
  43.   2,1,    /* detail and block pens */
  44.   0,    /* IDCMP flags */
  45.   NOCAREREFRESH,/* other window flags */
  46.   NULL,    /* first gadget in gadget list */
  47.   NULL,    /* custom CHECKMARK imagery */
  48.   "CalcTextWidth Test Window",    /* window title */
  49.   NULL,    /* custom screen pointer */
  50.   NULL,    /* custom bitmap */
  51.   0,0,    /* minimum width and height */
  52.   0,0,    /* maximum width and height */
  53.   WBENCHSCREEN    /* destination screen type */
  54. };
  55.  
  56. char *PossibleDatePieces[] =
  57. {
  58.   "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",NULL,
  59.   "Sun","Mon","Tue","Wed","Thu","Fri","Sat",NULL,
  60.   "    ::",NULL,
  61.   "01","02","03","04","05","06","07","08","09","10",
  62.   "11","12","13","14","15","16","17","18","19","20",
  63.   "21","22","23","24","25","26","27","28","29","30","31",NULL,
  64.   "00","01","02","03","04","05","06","07","08","09",
  65.   "10","11","12","13","14","15","16","17","18","19",
  66.   "20","21","22","23",NULL,
  67.   "0","1","2","3","4","5",NULL,
  68.   "0","1","2","3","4","5","6","7","8","9",NULL,
  69.   "0","1","2","3","4","5",NULL,
  70.   "0","1","2","3","4","5","6","7","8","9",NULL,
  71.   "1","2",NULL,
  72.   "0","1","2","3","4","5","6","7","8","9",NULL,
  73.   "0","1","2","3","4","5","6","7","8","9",NULL,
  74.   "0","1","2","3","4","5","6","7","8","9",NULL,NULL
  75. };
  76.  
  77. char *NumberTest[] =
  78. {
  79.   "0","1","2","3","4","5","6","7","8","9",NULL
  80. };
  81.  
  82.  
  83. /* * * * GLOBALS * * * */
  84. struct IntuitionBase *IntuitionBase;
  85. struct GfxBase *GfxBase;
  86. struct LayersBase *LayersBase;
  87. struct DiskfontBase *DiskfontBase;
  88. struct DosLibrary *DosBase;
  89. struct ExecBase *ExecBase;
  90.  
  91.  
  92. /* * * * * * * * * * * PROTOTYPES * * * * * * * * * * * * */
  93. void main (void);
  94. void MemCleanup (void);
  95.  
  96.  
  97. /* * * * * * * * * * * OUR ROUTINES * * * * * * * * * * * */
  98. void MemCleanup (void)
  99. {
  100. }
  101.  
  102. void main (void)
  103. {
  104.   struct TextFont *textFont = NULL;
  105.   char fontname[256];
  106.   int fontsize;
  107.   struct TextAttr textAttr = {NULL, 0, 0, 0};
  108.   struct Window *titlewindow;
  109.   int max = 0, total = 0;
  110.   int size;
  111.   char **PDP = PossibleDatePieces;
  112.   char **NT = NumberTest;
  113.  
  114.   printf("What is the font name: ");
  115.   scanf("%s", fontname);
  116.   if (!strstr(fontname, ".font"))
  117.     strcat(fontname, ".font");
  118.   textAttr.ta_Name = fontname;
  119.   printf("Font name entered: %s\n", fontname);
  120.   printf("What is the font size: ");
  121.   scanf("%d", &fontsize);
  122.   textAttr.ta_YSize = fontsize;
  123.   printf("Font size entered: %d\n", fontsize);
  124.  
  125.   if (!(GfxBase = (struct GfxBase *) OpenLibrary ("graphics.library", 0)))
  126.     goto abort;
  127.   if (!(LayersBase = (struct LayersBase *) OpenLibrary ("layers.library", 0)))
  128.     goto abort;
  129.   if (!(IntuitionBase = (struct IntuitionBase *) OpenLibrary ("intuition.library", 0)))
  130.     goto abort;
  131.   if (!(DiskfontBase = (struct DiskfontBase *) OpenLibrary ("diskfont.library", 0)))
  132.     goto abort;
  133.   if (!(ExecBase = (struct ExecBase *) OpenLibrary ("exec.library", 0)))
  134.     goto abort;
  135.   if (!(titlewindow = OpenWindow (&NewWindow)))
  136.     goto abort;
  137.   if (!(textFont = OpenDiskFont (&textAttr)))
  138.       {
  139.     printf("Font not found!\n");
  140.     goto abort;
  141.       }
  142.   SetFont (titlewindow->RPort, textFont);
  143.  
  144.   /* Calc Max. size in pixels needed to display any date in this font */
  145.   while (*PDP)
  146.     {
  147.       max = 0;
  148.       while (*PDP)
  149.     {
  150.       size = TextLength(titlewindow->RPort, *PDP, strlen(*PDP));
  151. #ifdef DEBUG
  152.       printf("For ``%s'', TextLength is %d\n", *PDP, size);
  153. #endif
  154.       if (size > max)
  155.         max = size;
  156.       PDP++;
  157.     }
  158.       total += max;
  159.       PDP++;
  160.     }
  161.  
  162.   printf("MAXTEXTLENGTH for font (%s) at size (%d) should be %d.\n", fontname, fontsize, total);
  163.  
  164.   /* Now do a quick check to see if all the numbers are the same width */
  165.   for (size = 0; *NT; NT++)
  166.     {
  167.       if (size == 0)
  168.     size = TextLength(titlewindow->RPort, *NT, strlen(*NT));
  169.       else
  170.     if (TextLength(titlewindow->RPort, *NT, strlen(*NT)) != size)
  171.       break;
  172.     }
  173.   if (*NT)
  174.     printf("Warning:  Not all numeral in this font are the same width!\n\
  175. This will look quite strange in NewPop's titlebar Window, as\n\
  176. it is updated every second!  NewPop handles proportional fonts,\n\
  177. but some look better than others.  Proportional fonts with a standard\n\
  178. numeral width look much nicer in NewPop.\n\
  179. This wouldn't happen to be one of Gold Disk's fonts, would it? Haha\n\
  180. Case in point: Commodore's Helvetica uses fixed width numerals,\n\
  181. Gold Disk's does not!\n");
  182.  
  183. abort:
  184.   if (titlewindow)
  185.     CloseWindow(titlewindow);
  186.   if (textFont)
  187.     CloseFont (textFont);
  188.   if (LayersBase)
  189.     CloseLibrary ((struct Library *) LayersBase);
  190.   if (IntuitionBase)
  191.     CloseLibrary ((struct Library *) IntuitionBase);
  192.   if (GfxBase)
  193.     CloseLibrary ((struct Library *) GfxBase);
  194.   if (DiskfontBase)
  195.     CloseLibrary ((struct Library *) DiskfontBase);
  196.   if (ExecBase)
  197.     CloseLibrary ((struct Library *) ExecBase);
  198.  
  199.   gets(fontname);
  200.   printf("Please press return: ");
  201.   gets(fontname);
  202. }
  203.