Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!oliveb!sun!swap!page From: page%swap@Sun.COM (Bob Page) Newsgroups: comp.sources.amiga Subject: v89i121: fonz - set font on custom screen Message-ID: <104013@sun.Eng.Sun.COM> Date: 10 May 89 03:45:48 GMT Sender: news@sun.Eng.Sun.COM Lines: 502 Approved: page@sun.com Submitted-by: mott@ucscb.ucsc.edu (Hung H. Le) Posting-number: Volume 89, Issue 121 Archive-name: fonts/fonz.1 "fonz" can be used to set the font for program that opens its own screen. I use it mainly to set the font of "Handshake" to something other than topaz. A doc page is enclosed. [uuencoded executable included. ..bob] # This is a shell archive. # Remove anything above and including the cut line. # Then run the rest of the file through 'sh'. # Unpacked files will be owned by you and have default permissions. #----cut here-----cut here-----cut here-----cut here----# #!/bin/sh # shar: SHell ARchive # Run the following text through 'sh' to create: # fonz.c # fonz.doc # fonz.uu # This is archive 1 of a 1-part kit. # This archive created: Tue May 9 20:40:07 1989 echo "extracting fonz.c" sed 's/^X//' << \SHAR_EOF > fonz.c X/* X * fonz - setfont for program that opens its own screen X * X * April 18, 1989 X * A hack to subtitute my own font for Handshake. X * With a little more work, could be turn into a general purpose X * setfont for program openning its own screen. I am too lazy to do it. X * X * April 19, 1989 X * Let's rename it "fonz". X * Make necessary changes so that "fonz" can be used in general. X * Usage: %s [-s font_size] [-w wait_max] font_name screen [window] X * -s font_size: default to 8 X * -w wait_max: number of times to go around the wait loop X * font_name: name of font X * screen: screen name X * window: name X * With no argument: X * "fonz" printed out all the screens each followed by its windows X * X * If no window is specified, "fonz" will pick out the first NULL window X * X * April 20, 1989 X * Let's call thist Version 1.0 X * Bug found: X * Use the [-w] flag, "run" the application. For example, X * runback c:fonz -w 12 clean Handshake; run df2:c/handshake X * Now, do something in your CLI while the application is loaded. X * Do a "status", for example, "fonz" will pretend that it does its job X * and exist but no font is changed to the application's window. X * X * Fix: X * I don't know the reason for the bug. Attempt to fix by "delaying" X * 10 secs before do SetFont(). Seems to work OK now. X * If you know why please let me know. X * X * Hung Le (mott@ucscb.ucsc.edu) X * X * compiled under Manx v3.4a (someday I will upgrade ... ) X * 1> cc fonz.c X * 1> ln fonz.o -lc X */ X X#include X#include X#include X#include X#include X#include X X#define INTUI_REV 0L X#define usage(n) fprintf(stderr,"Usage: %s [-s font_size] [-w wait_max] font_name screen [window]\n", n) X/* 500 ticks */ X#define TEN_SECS 500L X Xstruct IntuitionBase *IntuitionBase = 0L; Xstruct Window *Window = 0L; Xstruct TextFont *Font = 0L; Xlong DiskfontBase = 0L; Xlong GfxBase = 0L; X Xint Font_Size = 0; Xint Wait_Max = 0; X X/* not parsing workbench */ X_wb_parse() {} X Xmain(ac,av) Xint ac; Xchar *av[]; X{ X char my_name[20]; X X strcpy(my_name, av[0]); X X /* Open the necessary libraries */ X Open_Libs(); X X if (ac == 1) X print_windows(); X else X { X /* two global variables: Font_Size and Wait_Max are set */ X while (av[1][0] == '-') X { X if (strcmp(av[1], "-s") == 0) X { X Font_Size = atoi(av[2]); X ac -= 2; av += 2; X } X else if (strcmp(av[1], "-w") == 0) X { X Wait_Max = atoi(av[2]); X ac -= 2; av += 2; X } X else X { X /* ignore bad flag */ X ac--; av++; X } X } X X /* X * Make sure that at least the following two X * variables are set to default values X */ X if (Font_Size <= 0) X Font_Size = 8; X if (Wait_Max < 0) X Wait_Max = 0; X X if ((ac == 3) || (ac == 4)) X do_it(ac, av); X else X { X usage(my_name); X clean_up(1); X } X } X X /* Returns resouces to the Amiga */ X clean_up(0); X} X Xdo_it(ac, av) Xint ac; Xchar *av[]; X{ X char font_name[20], screen_name[81], window_name[81]; X struct TextAttr ta; X struct TextFont *old_font; X struct RastPort *rast_port; X X /* set up the parameters */ X sprintf(font_name,"%s.font", av[1]); X strcpy(screen_name, av[2]); X if (ac == 4) X strcpy(window_name, av[3]); X else X window_name[0] = '\0'; X X /* my text attributes */ X ta.ta_Name = (UBYTE *) font_name; X ta.ta_YSize = (long) Font_Size; X ta.ta_Style = 0L; X ta.ta_Flags = FPF_DISKFONT; X X Font = (struct TextFont *) OpenDiskFont(&ta); X if (Font == (struct TextFont *) NULL) X { X fprintf(stderr,"Cannot find font \"%s %d\"\n", font_name, Font_Size); X clean_up(2); X } X X while (Wait_Max-- >= 0) X { X if (get_window(screen_name, window_name)) X /* Window is a global variable and it is set in get_window() */ X { X rast_port = Window->RPort; X old_font = rast_port->Font; X /* see heading comment box 04/20/89 */ X if (Wait_Max >= 0) Delay(TEN_SECS); X if ( SetFont(rast_port, Font)) X Font = old_font; X break; X } X else if (Wait_Max >= 0) Delay(TEN_SECS); X } X X if (Window == (struct Window *) NULL) X { X fprintf(stderr,"Cannot find window \"%s\" in screen \"%s\"\n", window_name, screen_name); X clean_up(2); X } X} X Xget_window(sn, wn) Xchar *sn; Xchar *wn; X{ X X struct Screen *screen; X X LockIBase(NULL); X X for (screen = IntuitionBase->FirstScreen; screen != (struct Screen *) NULL; screen = screen->NextScreen) X { X if (strncmp(screen->Title, sn, strlen(sn)) == 0) X { X for (Window = screen->FirstWindow; Window != (struct Window *) NULL; Window = Window->NextWindow) X { X if (wn[0] == '\0') X { X if (Window->Title == (UBYTE *) NULL) X { X UnlockIBase(NULL); X return(TRUE); X } X } X else if (strncmp(Window->Title, wn, strlen(wn)) == 0) X { X UnlockIBase(NULL); X return(TRUE); X } X } X } X } X Window = (struct Window *) NULL; X UnlockIBase(NULL); X return(FALSE); X} X Xclean_up(code) Xint code; X{ X if (Font) CloseFont(Font); X if (DiskfontBase) CloseLibrary(DiskfontBase); X if (IntuitionBase) CloseLibrary(IntuitionBase); X if (GfxBase) CloseLibrary(GfxBase); X exit(code); X} X XOpen_Libs() X{ X GfxBase = (long ) OpenLibrary("graphics.library", INTUI_REV); X if (GfxBase == NULL) X { X fprintf(stderr,"Cannot open graphics.library\n"); X clean_up(1); X } X X IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", INTUI_REV); X if (IntuitionBase == (struct IntuitionBase *) NULL) X { X fprintf(stderr,"Cannot open intuition.library\n"); X clean_up(1); X } X X DiskfontBase = (long ) OpenLibrary("diskfont.library", INTUI_REV); X if (DiskfontBase == NULL) X { X fprintf(stderr,"Cannot open diskfont.library\n"); X clean_up(1); X } X} X Xprint_windows() X{ X struct Window *window; X struct Screen *screen; X X /* Should I lock the IntuitionBase? ... Nah ... */ X for (screen = IntuitionBase->FirstScreen; screen != (struct Screen *) NULL; screen = screen->NextScreen) X { X printf("Screen: \"%s\"\n", screen->Title); X for (window = screen->FirstWindow; window != (struct Window *) NULL; window = window->NextWindow) X printf("Window: \"%s\"\n", window->Title); X } X} X SHAR_EOF echo "extracting fonz.doc" sed 's/^X//' << \SHAR_EOF > fonz.doc XFonz -- SetFont for program which opens its own screen. XVersion: 1.0 X XWhy: X Because I cannot stand topaz font on my communication X program's screen. X XUsage: X fonz [-s font_size] [-w wait_max] font_name screen [window] X X With no argument, "fonz" lists all screens each follows by its own X windows. X X -s font_size: X Specify the font_size; default value == 8; X /* I have not try anything other than 8 */ X -w wait_max: X (just for you Jon ;-) ...) X how long to wait around. One unit of wait_max == 10 secs. X Often used to start "fonz" in advance and force "fonz" to X wait until wait_max is expired or until the target window X is opened. X I use this alias Xalias c "runback df0:c/fonz -w 12 clean Handshake; run df2:c/handshake" X to set up the "clean" font for my "Handshake" program. X font_name: X is the font name available in fonts: X screen: X screen name. A list of screen names can be obtained by X using "fonz" with no argument. X window: X window name. A list of window names can also be obtained X using "fonz" with no argument. X If "window" is omitted, the first window with the NULL title is X the target window. X X X If you are not using the [-w] flag, the target window must X already be opened. X X If there are more than one NULL title window on a screen, only the X first one is reachable. X NULL Title Screen? Fix the source code if you want to deal with it. X X Sometimes, old font came back. Chances are the program that owns X the target window had decided that it was time to refresh its font. X All you can do is to flip back to the "CLI" and use "fonz" again. X X use "SetFont" to set the font for the console window. X X I would like very much to hear your bug report, comments ... X XAuthor: X Hung Le (mott@ucscb.ucsc.edu ...!ucbvax!ucscc!ucscb!edu) X X Feel free to use the source codes if they are useful to you. X SHAR_EOF echo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@`8`H_!$ZZ`-!4G XM3U)$N&R"9FWP,"R"9L'\``8O`"\L@H).N@&\4$]*K(*@9P8@;(*@3I!*K(*FV XM9PHO+(*F3KH!``$""X`!`$I9Q0O#4OZ``I.KO_B*E]@!D*G\U].R"@DI$;0JX;()F;`1*DF80.7P``H*DDZN_Y1,WR"`3G5.^@`"(F\`!"QL@GI.[OYB3.\``P`$+&R">D[N_SHBM XM;P`$+&R">D[N_MHL;()Z3N[_?")O``0@+P`(+&R">D[N_RX@;P`$+&R">D[NR XM_HQ.^@`"+&R">B)O``0@+P`(3N[]V")O``0L;()Z3N[^ADSO``,`!"QL@GI.R XM[O[.(&\`!"QL@GI.[OZ`(F\`!"QL@!).[O^R(F\`!"!O``@L;(`23N[_OBQLN XM@`(@+P`$3N[^8BQL@`(@;P`$3N[^7"!O``0L;(`.3N[_X@`````#[`````$`Z XM```!```&L`````````/R```#Z@```)H`````````````````````````````S XM```P,3(S-#4V-S@Y86)C9&5F````("`@("`@("`@,#`P,#`@("`@("`@("`@R XM("`@("`@(""00$!`0$!`0$!`0$!`0$!`#`P,#`P,#`P,#$!`0$!`0$`)"0D)L XM"0D!`0$!`0$!`0$!`0$!`0$!`0$!`4!`0$!`0`H*"@H*"@("`@("`@("`@("X XM`@("`@("`@("0$!`0"```````````````````0`````!````````````````T XM``````$!`````0`````````````````````!`@````$`````````````````' XM````````````````````````````````````````````````````````````` XM````````````````````````````````````````````````````````````` XM````````````````````````````````````````````````````````````` XM````````````````````````````````````````````````````````````` XM````````````````````````````````````````````````````````````` XM````````````````````````````````````````````````````````````` XM````````````````````````````````````````````````````````````` XM````````````````````````````````````````````````````````````` X9````````%``````#\@```^L````!```#\@``M X`` Xend Xsize 6460 SHAR_EOF echo "End of archive 1 (of 1)" # if you want to concatenate archives, remove anything after this line exit