home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
500.lha
/
NewPop_v3.0
/
CalcTextLength.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-04-08
|
6KB
|
198 lines
/*
* calctextlength.c -
* Quick hack to calculate the MAXTEXTLENGTH parameter needed in NewPop.c
* Copyright (c) 1990, 1991 Loren J. Rittle
*
* This program is in no way efficient or nice, but it is run only once
* when NewPop is installed with a new font, so who cares.
*
* Use: lc -L calctextlength.c to compile under SAS/C v5.10.
*/
/* * * * * * * * * * * INCLUDES * * * * * * * * * * * * */
#include <exec/types.h>
#include <exec/exec.h>
#include <exec/execbase.h>
#include <exec/tasks.h>
#include <devices/timer.h>
#include <devices/input.h>
#include <devices/inputevent.h>
#include <intuition/intuition.h>
#include <libraries/dos.h>
#include <graphics/gfxmacros.h>
#include <graphics/layers.h>
#include <hardware/custom.h>
#include <hardware/dmabits.h>
#include <graphics/text.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/diskfont.h>
#include <string.h>
#include <time.h>
#include <stdio.h>
struct NewWindow NewWindow =
{
100,100, /* window XY origin relative to TopLeft of screen */
200,100, /* window width and height */
2,1, /* detail and block pens */
0, /* IDCMP flags */
NOCAREREFRESH,/* other window flags */
NULL, /* first gadget in gadget list */
NULL, /* custom CHECKMARK imagery */
"CalcTextLength Test Window", /* window title */
NULL, /* custom screen pointer */
NULL, /* custom bitmap */
0,0, /* minimum width and height */
0,0, /* maximum width and height */
WBENCHSCREEN /* destination screen type */
};
char *PossibleDatePieces[] =
{
"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",NULL,
"Sun","Mon","Tue","Wed","Thu","Fri","Sat",NULL,
" ::",NULL,
"01","02","03","04","05","06","07","08","09","10",
"11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30","31",NULL,
"00","01","02","03","04","05","06","07","08","09",
"10","11","12","13","14","15","16","17","18","19",
"20","21","22","23",NULL,
"0","1","2","3","4","5",NULL,
"0","1","2","3","4","5","6","7","8","9",NULL,
"0","1","2","3","4","5",NULL,
"0","1","2","3","4","5","6","7","8","9",NULL,
"1","2",NULL,
"0","1","2","3","4","5","6","7","8","9",NULL,
"0","1","2","3","4","5","6","7","8","9",NULL,
"0","1","2","3","4","5","6","7","8","9",NULL,NULL
};
char *NumberTest[] =
{
"0","1","2","3","4","5","6","7","8","9",NULL
};
/* * * * GLOBALS * * * */
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct LayersBase *LayersBase;
struct DiskfontBase *DiskfontBase;
struct DosLibrary *DosBase;
struct ExecBase *ExecBase;
/* * * * * * * * * * * PROTOTYPES * * * * * * * * * * * * */
void main (void);
void MemCleanup (void);
/* * * * * * * * * * * OUR ROUTINES * * * * * * * * * * * */
void MemCleanup (void)
{
}
void main (void)
{
struct TextFont *textFont = NULL;
char fontname[256];
int fontsize;
struct TextAttr textAttr = {NULL, 0, 0, 0};
struct Window *titlewindow;
int max = 0, total = 0;
int size;
char **PDP = PossibleDatePieces;
char **NT = NumberTest;
printf("What is the font name: ");
scanf("%s", fontname);
if (!strstr(fontname, ".font"))
strcat(fontname, ".font");
textAttr.ta_Name = fontname;
printf("Font name entered: %s\n", fontname);
printf("What is the font size: ");
scanf("%d", &fontsize);
textAttr.ta_YSize = fontsize;
printf("Font size entered: %d\n", fontsize);
if (!(GfxBase = (struct GfxBase *) OpenLibrary ("graphics.library", 0)))
goto abort;
if (!(LayersBase = (struct LayersBase *) OpenLibrary ("layers.library", 0)))
goto abort;
if (!(IntuitionBase = (struct IntuitionBase *) OpenLibrary ("intuition.library", 0)))
goto abort;
if (!(DiskfontBase = (struct DiskfontBase *) OpenLibrary ("diskfont.library", 0)))
goto abort;
if (!(ExecBase = (struct ExecBase *) OpenLibrary ("exec.library", 0)))
goto abort;
if (!(titlewindow = OpenWindow (&NewWindow)))
goto abort;
if (!(textFont = OpenDiskFont (&textAttr)))
{
printf("Font not found!\n");
goto abort;
}
SetFont (titlewindow->RPort, textFont);
/* Calc Max. size in pixels needed to display any date in this font */
while (*PDP)
{
max = 0;
while (*PDP)
{
size = TextLength(titlewindow->RPort, *PDP, strlen(*PDP));
#ifdef DEBUG
printf("For ``%s'', TextLength is %d\n", *PDP, size);
#endif
if (size > max)
max = size;
PDP++;
}
total += max;
PDP++;
}
printf("MAXTEXTLENGTH for font (%s) at size (%d) should be %d.\n", fontname, fontsize, total);
/* Now do a quick check to see if all the numbers are the same width */
for (size = 0; *NT; NT++)
{
if (size == 0)
size = TextLength(titlewindow->RPort, *NT, strlen(*NT));
else
if (TextLength(titlewindow->RPort, *NT, strlen(*NT)) != size)
break;
}
if (*NT)
printf("Warning: Not all numeral in this font are the same width!\n\
This will look quite strange in NewPop's titlebar Window, as\n\
it is updated every second! NewPop handles proportional fonts,\n\
but some look better than others. Proportional fonts with a standard\n\
numeral width look much nicer in NewPop.\n\
This wouldn't happen to be one of Gold Disk's fonts, would it? Haha\n\
Case in point: Commodore's Helvetica uses fixed width numerals,\n\
Gold Disk's does not!\n");
abort:
if (titlewindow)
CloseWindow(titlewindow);
if (textFont)
CloseFont (textFont);
if (LayersBase)
CloseLibrary ((struct Library *) LayersBase);
if (IntuitionBase)
CloseLibrary ((struct Library *) IntuitionBase);
if (GfxBase)
CloseLibrary ((struct Library *) GfxBase);
if (DiskfontBase)
CloseLibrary ((struct Library *) DiskfontBase);
if (ExecBase)
CloseLibrary ((struct Library *) ExecBase);
}