[comp.sys.amiga] Changing fonts in the SCREEN

pjm@lznh.UUCP (<10000>Paul Maioriello) (04/15/88)

I am posting this in the general newsgroup because I'm sure it's
been asked before, and the answer is readily available.

What I would like to do is to change the fonts used to write
into the title bar of a screen.  I thought I could do this
by changing the TextAttr structure to use a font other than
topaz.  It seems that I get topaz in the screen title regardless
of what fonts I set in TextAttr before calling OpenScreen.
Are the new fonts only available for text that is written into a
window on the new screen but unavailable to the screen itself?
Is there a reason why wanting to use a different font in the
screen a really dumb idea?

On a related note, is it possible to put text directly on a screen
without first opening a window?

Thanks in advance for any help


Later,
Paul Maioriello
lznh!pjm

avery@puff.cs.wisc.edu (Aaron Avery) (04/16/88)

In article <428@lznh.UUCP> pjm@lznh.UUCP (<10000>Paul Maioriello) writes:
>What I would like to do is to change the fonts used to write
>into the title bar of a screen.  I thought I could do this
>by changing the TextAttr structure to use a font other than
>topaz.  It seems that I get topaz in the screen title regardless
As you found out, the TextAttr structure is to declare which font you would
like to be the standard font for anything YOU print into that screen.
The problem with doing what you want is that INTUITION does the displaying
of the screen's title bar and menus. The program called SetFont allows one
to set the default system font for various things, including subsequently
created screens' title bar rendering. I'm not sure how it's done, but I 
believe that source is available, so you might find the answer there.

>Is there a reason why wanting to use a different font in the
>screen a really dumb idea?
Of course not.
 
>On a related note, is it possible to put text directly on a screen
>without first opening a window?
Yes. You can print text in any RastPort. The system allocates one for every
screen and puts it in the screen structure's RastPort field. To get a pointer
to a screen's RastPort do this:
struct RastPort *rp;
rp = &(screen->RastPort);

Now you can use many, many of the system graphics calls to render into your
screen, including Text(). Note that the screen has no layers defined for it,
so if you have windows on your screen, you can render on top of them if you
use the screen's RastPort. If you have windows on your screen and wish to
render behind them, you should open a BORDERLESS, BACKDROP window on your
screen, and render into ITS RastPort.

Hope this helps, and let me know if you need help finding SetFont.

-- 
Aaron Avery (avery@puff.cs.wisc.edu)
	    ({seismo,caip,allegra,harvard,rutgers,ihnp4}!uwvax!puff!avery)

cmcmanis%pepper@Sun.COM (Chuck McManis) (04/17/88)

In article <428@lznh.UUCP> pjm@lznh.UUCP (<10000>Paul Maioriello) writes:
-> I am posting this in the general newsgroup because I'm sure it's
-> been asked before, and the answer is readily available.
->
-> What I would like to do is to change the fonts used to write
-> into the title bar of a screen.  I thought I could do this
-> by changing the TextAttr structure to use a font other than
-> topaz. 

[Editing, running make, vt100, and the Infominder autodocs at the same time
 here, who was it that said Multitasking was for the birds ???? :-) ]

	-- Mini Font and Rastport Tutorial --

Without going into *extreme* detail, there are some things you will need to
understand before this makes sense. 

Graphics are rendered into a 'RastPort', the RastPort defines a lot of
constants for the graphics routines and the font is one of them. Now
everything you can write into has a RastPort associated with it. This
includes screens, windows, menu bars, etc. Each RastPort has a pointer
to a BitMap structure which points to the actual data that is displayed.

Fonts come in two flavors, DISK and ROM, and are accessed with OpenFont()
or OpenDiskFont(). These routines take a TextAttr structure to describe
what the font you would like is, they return a pointer TextFont structure 
which tells you what kind of font you got. IT MAY BE DIFFERENT THAN WHAT
YOU REQUESTED. So be aware of that. Now with this TextFont you can make a
RastPort use this font, using the call SetFont(rp,font). From then on
calls to Text() will render in this font. The color of the letters will be
the same as the APen, with the background being the color of the BPen if 
the Draw mode is JAM2. 

Now to change the font of the Screen, you have to go through three steps :
	Initialize a TextAttr structure.
	TextFont = OpenFont(TextAttr).
	SetFont(Screen->RastPort,TextFont).

Now re-render the screen title and poof, new font. Remember to close the
font when you exit. That way it can be expunged from memory.

Now if you don't know what the font is for a particular RastPort, you can
still do things safely. Critical aspects of the font are kept in the 
RastPort structure. Look at <graphics/rastport.h> where it describes the
fields TxHeight, TxWidth. Similarly if you want to know how much space 
some text is going to take on the screen but don't want to render it first
you can call TextLength(RastPort,"string",strlen("string")); (why it needs
the string length I don't know). This will return the width in pixels, the
height is in RastPort->TxHeight, and now you have a bounding box for your
text. Feed these numbers into a Border structure and you are well on your
way to having a labeled button gadget. 


--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.

chas@gtss.UUCP (Charles Cleveland) (04/18/88)

In article <428@lznh.UUCP> pjm@lznh.UUCP (<10000>Paul Maioriello) writes:
)What I would like to do is to change the fonts used to write
)into the title bar of a screen.  I thought I could do this
)by changing the TextAttr structure to use a font other than
)topaz.  It seems that I get topaz in the screen title regardless
)of what fonts I set in TextAttr before calling OpenScreen.

Well, you should be able to do exactly what to say, set the TextAttr
in NewScreen and then call OpenScreen, but the font MUST be in memory
so if its a Diskfont either another program must have opened it or
you must do so yourself before calling OpenScreen.  At the end of
this listing is a program which opens a Screen for 5 seconds.  If the
first line is uncommented, it works like you want -- but if it isn't,
the way it works depends on whether the font has already been loaded by
another program (in which case it may be expunged if memory gets low).

And you can always write directly into any RastPort.

On reading the responses to this question that have arrived at this site
to date, there seems to be some confusion about fonts and the various
intuition structures, and who depends on what.  In the following, 'font'
may mean either a TextAttr or a TextFont, depending on context.

1) The Screen's RastPort's font does not determine the Screen's Title's
font.  Neither does the Screen's TextAttr.  On the other hand, the
Screen's TextAttr determines the font which new windows on the Screen
would use INTERNALLY, while the Screen's RastPort's font determines the
font that will be used for WINDOW Titles.  Both of these fonts may be
affected by Dave Haynie's SetFont program.

2) The Screen's Title's Font is determined by the Screen's BarLayer's
Rastport's font.  This is not affected by Dave Haynie's SetFont program,
although he tells me a later version may do so.  This BarLayer's Rastport's
font also determines the font that String Gadgets use when they are first
rendered:  this is a Little Known Fact.

So here's the little program:

----------------------------cut here--------------------------------

/* #define OPENFONT */
#define INTUITION_REV 33L
#include <libraries/dos.h>
#include <exec/types.h>
#include <exec/exec.h>
#include <intuition/intuitionbase.h>
#include <libraries/dosextens.h>
#include <graphics/gfxbase.h>
#include <graphics/gfx.h>
#include <graphics/display.h>
#include <graphics/text.h>
#include <libraries/dos.h>
#include <stdio.h>

struct TextFont *OpenFont(), *OpenDiskFont();
struct Library *OpenLibrary();
struct Screen *OpenScreen();


struct TextFont *font=NULL;
struct TextAttr TAttr={"pearl.font",8,0,0};

struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct Library *DiskfontBase;

struct NewScreen NewScreen = {0,0,640,200,2,0,1,HIRES,CUSTOMSCREEN,
 &TAttr,"DefaultTitle",NULL,NULL};

void main()
{
void cleanup();

struct Screen *TempScreen;

 if(!(IntuitionBase=(struct IntuitionBase *)
		OpenLibrary("intuition.library",INTUITION_REV)))cleanup(1);

 if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0L)))
	cleanup(2);

 #ifdef OPENFONT
 if(!(font=(struct TextFont *)OpenFont(&TAttr))){
  if((DiskfontBase=(struct Library *)OpenLibrary("diskfont.library",0L))){
   font=(struct TextFont *)OpenDiskFont(&TAttr);
   CloseLibrary(DiskfontBase);
  }
 }
  if(!font){
  puts("couldn't open font!");
  cleanup(3);
 }
#endif OPENFONT

 if(!(TempScreen=(struct Screen *)OpenScreen(&NewScreen)))cleanup(4);

 Delay(250L);
 CloseScreen(TempScreen);
 cleanup(0);
 return;
}

void cleanup(errnum)
int errnum;
{
 if(IntuitionBase)CloseLibrary(IntuitionBase);
 if(font)CloseFont(font);
 if(GfxBase)CloseLibrary(GfxBase);
 exit(errnum);
}
-- 
-Life would be so much easier if we could just look at the source code.-

Charles Cleveland    Georgia Tech School of Physics    Atlanta, GA 30332
UUCP: ...!gatech!gtss!chas         INTERNET:  chas@ss.physics.gatech.edu