[comp.sys.amiga.tech] Opening a diskfont??

faheyr@silver.ucs.indiana.edu (Bob Fahey <NECR0SIS>) (01/06/91)

I am programming a utility in C (lattice), and need to open a specific font off of a disk. (the font
is already stored in the fonts: dir of my boot disk).

How do you go about opening that disk-based font? I have tried and tried, but seem to only be able
to open the rombased fonts....
What exactly needs to be opened before you can call OpenFont()? Every time I have tried doing this,
either the computer guru's, or it just simply does not open the font....

Any ideas? thanks in advance.
Bob

|      ///| a.k.a. NECR0SIS     faheyr@silver.ucs.indiana.edu  -or-          |
|  \\\///_|                     faheyr@rose.ucs.indiana.edu                  |
|   \XX/  |  M  I  G  A      "'Ere long done do does did..."  - The Smiths   |
|             "...life is seen through the eyes of a dog..."  - Skinny Puppy |

bj@cbmvax.commodore.com (Brian Jackson) (01/06/91)

In article <faheyr.663140235@silver> faheyr@silver.ucs.indiana.edu (Bob Fahey <NECR0SIS>) writes:
>I am programming a utility in C (lattice), and need to open a specific
>font off of a disk. (the font is already stored in the fonts: dir of 
>my boot disk).
>
>How do you go about opening that disk-based font? I have tried and tried,
>but seem to only be able to open the rombased fonts....
>What exactly needs to be opened before you can call OpenFont()? Every
>time I have tried doing this, either the computer guru's, or it just 
>simply does not open the font....

First you have to open the diskfont library:
 
DiskfontBase = (struct DiskfontBase *)OpenLibrary("diskfont.library",0L);

Then you have to open the font itself using an initialized TextAttr
structure:
 
struct TextFont *tf ;
tf = (struct TextFont *)OpenDiskFont((struct TextAttr *)myfontattr);
                            ^^^^
There is actually a bit more to it than this (since the font might
already be in memory) but this is the general idea :) Don't forget 
to close the font again before you exit:

CloseFont( tf ); 

bj

>Bob

 -----------------------------------------------------------------------
 | Brian Jackson  Software Engineer, Commodore-Amiga Inc.  GEnie: B.J. |
 | bj@cbmvax.cbm.commodore.com    or  ...{uunet|rutgers}!cbmvax!bj     |
 | 'Please dosconnect in your mind the concepts 'seems to work just    |
 |  fine' and 'Is allowed' - Peter Cherna                              |
 -----------------------------------------------------------------------

a447@mindlink.UUCP (Colin Fox) (01/07/91)

When you close the diskfont, or close a library, or close a device (and perhaps
more resources as well), they are marked as EXPUNGABLE but they aren't
unloaded. This improves system performance while not risking low-memory
problems.

The memory allocation routines, on failing an AllocMem() will go through and
flush all EXPUNGABLE resources and then try again. This is what the program
FLUSH does - it simply attempts to allocate an impossibly large memory hunk and
that automatically flushes all flushable resources.

######################################################################
#           | The street  finds its own   | Any opinions expressed   #
# Colin Fox | use for things. -W.Gibson   | herin reflect only those #
#Carpe Diem!+-----------------------------++ of my employer. Me. :)  #
#-----------+   Colin_Fox@MindLink.uucp    +-------------------------#
############|     Home of req.library      |##########################
######################################################################

forgeas@swinjm.UUCP (Jean-Michel Forgeas) (01/07/91)

In article <faheyr.663140235@silver>, Bob Fahey <NECR0SIS> writes:

> I am programming a utility in C (lattice), and need to open a specific font off of a disk. (the font
> is already stored in the fonts: dir of my boot disk).
>
> How do you go about opening that disk-based font? I have tried and tried, but seem to only be able
> to open the rombased fonts....

Here is the routine I'm using. It looks in ram before the disk.
It is necessary to verify tf_YSize because if a font is found
in ram with a different size, OpenFont() will success.
Before using this you have to fill the TextAttr structure.

struct TextFont *LoadThisFont( struct TextAttr *TextAttr )
{
  struct TextFont *font;

    if ((font = (struct TextFont *) OpenFont( TextAttr ))
            && Font->tf_YSize != TextAttr->ta_YSize)
        {
        CloseFont( font );
        font = 0;
        }
    if (! font)
        {
        TextAttr->ta_Flags = FPF_DISKFONT;
        font = (struct TextFont *) OpenDiskFont( TextAttr );
        }
    return( font );
}

Hope this help.
--
                                     \___/
Jean-Michel Forgeas                   \-/
cbmvax!cbmehq!cbmfra!swinjm!forgeas    |    The Software Winery
                                      -^-
                           And, where is the universe ?

Lee_Robert_Willis@cup.portal.com (01/08/91)

While talking about Opening DiskFonts, Brian Jackson wrote:

      Don't forget to close the font again before you exit:

Under 1.3, is a disk font *actually* purged from memory when all
accessors have closed it?  I have a program which opens disk fonts, 
and faithfully closes them again on exiting.  Yet if I run it again,
it doesn't go to disk, but finds them all in RAM.

Lee

Lee_Robert_Willis@cup.portal.com

bj@cbmvax.commodore.com (Brian Jackson) (01/08/91)

In article <37718@cup.portal.com> Lee_Robert_Willis@cup.portal.com asks:

>Under 1.3, is a disk font *actually* purged from memory when all
>accessors have closed it?  I have a program which opens disk fonts, 
>and faithfully closes them again on exiting.  Yet if I run it again,
>it doesn't go to disk, but finds them all in RAM.

Nope. Under both 1.3 and 2.0 the fonts (and libraries) in memory are
not flushed unless the system needs the memory and the accessor count
is zero.  Under 2.0 you can do an "avail flush" from the CLI to force
this. Under earlier OS versions, a simple little program that attempts
to allocate more memory than is in the system will do the job:
 
    AllocMem( 300000000000L, MEMF_PUBLIC ) ;

That should do it on most systems :)  But remember, this will flush 
ALL libraries and fonts from memory (those with accessor counts of zero) 
not just selected ones.

bj

>Lee

 -----------------------------------------------------------------------
 | Brian Jackson  Software Engineer, Commodore-Amiga Inc.  GEnie: B.J. |
 | bj@cbmvax.cbm.commodore.com    or  ...{uunet|rutgers}!cbmvax!bj     |
 | "Please Captain, not in front of the Klingons."                     |
 -----------------------------------------------------------------------

peterk@cbmger.UUCP (Peter Kittel GERMANY) (01/08/91)

In article <faheyr.663140235@silver> faheyr@silver.ucs.indiana.edu (Bob Fahey <NECR0SIS>) writes:
>I am programming a utility in C (lattice), and need to open a specific font off of a disk. (the font
>is already stored in the fonts: dir of my boot disk).
>
>How do you go about opening that disk-based font?

Use function OpenDiskFont() instead of OpenFont().
I'm too lazy to type an example here, but look into the program
Library in the basicdemos drawer of your Extras disk (yes, AmigaBasic).
There you can see what setup is necessary before calling that
function. Please note that you can exchange the function call in
this example easily by OpenDiskFont(). Another observation of
mine: Obviously this is the only place in the Amiga system that
is case sensitive on the filenames of the fonts! So watch out
for the real spelling of the wanted fonts. (Don't yet know if
this also applies to 2.0.)

-- 
Best regards, Dr. Peter Kittel  // E-Mail to  \\  Only my personal opinions... 
Commodore Frankfurt, Germany  \X/ {uunet|pyramid|rutgers}!cbmvax!cbmger!peterk

jap@convex.cl.msu.edu (Joe Porkka) (01/09/91)

peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:

>In article <faheyr.663140235@silver> faheyr@silver.ucs.indiana.edu (Bob Fahey <NECR0SIS>) writes:
>>I am programming a utility in C (lattice), and need to open a specific font off of a disk. (the font
>>is already stored in the fonts: dir of my boot disk).
>>
>>How do you go about opening that disk-based font?

>Use function OpenDiskFont() instead of OpenFont().
>I'm too lazy to type an example here, but look into the program

Also, in my experience, OpenDiskFont does NOT check to see
if the font is already loaded, and will load a duplicate.
So first try OpenFont, if it fails, or does not give what you want,
the OpenDiskFont.

If a duplicate gets loaded, it will get unload duriung the next
library expunge (ie - out of memory)

I WISH there was no such thing a OpenDiskFont.
Its as bad as if there was an OpenDiskLibrary.
Yucko.

peterk@cbmger.UUCP (Peter Kittel GERMANY) (01/09/91)

In article <1991Jan8.173617.12144@msuinfo.cl.msu.edu> jap@convex.cl.msu.edu (Joe Porkka) writes:
>peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:
>
>>Use function OpenDiskFont() instead of OpenFont().
>>I'm too lazy to type an example here, but look into the program
>
>Also, in my experience, OpenDiskFont does NOT check to see
>if the font is already loaded, and will load a duplicate.

Hmm, I'm told this by everyone, but it doesn't fit with my
experiences:
As I already told, I'm lazy, so I used OpenDiskFont() everytime
for loading a new font. As this was in a very memory critical
demo, I watched carefully for memory consumption or even memory
loss. Nothing harmful ever happened. (Hmm, worst case scenario:
everytime when my request came in a real tight memory situation,
then all old stuff was flushed first, so perhaps there were
delays by this? It really got slow on low memory.)

Question to those with wisdom:
Could it be that OpenDiskFont() is intelligent enough to look into
RAM first, without explicitly calling OpenFont()? Or that a
duplicate font gets loaded over an already existing one in RAM?

>I WISH there was no such thing a OpenDiskFont.

Right. If not already happened, OpenDiskFont() should get 
enhanced the mentioned way, so that it can be used safely 
as the ONLY font selecting function. Or am I missing some
special feature of the pair OpenFont()/OpenDiskFont()?

-- 
Best regards, Dr. Peter Kittel  // E-Mail to  \\  Only my personal opinions... 
Commodore Frankfurt, Germany  \X/ {uunet|pyramid|rutgers}!cbmvax!cbmger!peterk

peterk@cbmger.UUCP (Peter Kittel GERMANY) (01/09/91)

In article <1991Jan09.002927.28369@usenet@scion.CS.ORST.EDU> brindley@ECE.ORST.EDU (Mike Brindley) writes:
>AmigaBasic is not included with the A3000, not even on the 1.3 disks.
>Anyone care to comment as to the reason for this?  Is this also the
>case with any other Amiga models (2500 ...)? 

There are two issues:
1. To date there is no version of AmigaBasic that is working properly
   on the A3000 (you know, 24 bit addressing). But this may change. 

WHEN some time this is ok, THEN no. 2 may come into business:
2. As far as I know there may be also marketing issues (NOT my job).

Fact is, the A3000 is already bundled with two
languages/applications, ARexx and AmigaVision; AmigaBasic
would be third. (Don't know about other models.)

-- 
Best regards, Dr. Peter Kittel  // E-Mail to  \\  Only my personal opinions... 
Commodore Frankfurt, Germany  \X/ {uunet|pyramid|rutgers}!cbmvax!cbmger!peterk

bj@cbmvax.commodore.com (Brian Jackson) (01/10/91)

In article <706@cbmger.UUCP> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:
>Question to those with wisdom:
>Could it be that OpenDiskFont() is intelligent enough to look into
>RAM first, without explicitly calling OpenFont()? Or that a
>duplicate font gets loaded over an already existing one in RAM?

From the 1.3/2.0 autodocs:

   NAME
       OpenDiskFont - load and get a pointer to a disk font.

   FUNCTION
       This function finds the font with the specified textAttr on
       disk, loads it into memory, and returns a pointer to the font
       that can be used in subsequent SetFont and CloseFont calls.
       It is important to match this call with a corresponding
       CloseFont call for effective management of font memory.


>>>>   If the font is already in memory, the copy in memory is used. <<<<
>>>>   The disk copy is not reloaded.                                <<<<

bj

>Best regards, Dr. Peter Kittel

 -----------------------------------------------------------------------
 | Brian Jackson  Software Engineer, Commodore-Amiga Inc.  GEnie: B.J. |
 | bj@cbmvax.cbm.commodore.com    or  ...{uunet|rutgers}!cbmvax!bj     |
 | "My beer comes from farther away than your beer."                   |
 -----------------------------------------------------------------------

didierj@swindj.UUCP (Alain Didierjean) (01/10/91)

In article <1991Jan8.173617.12144@msuinfo.cl.msu.edu>, Joe Porkka writes:

-> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:
->
-> >In article <faheyr.663140235@silver> faheyr@silver.ucs.indiana.edu (Bob Fahey <NECR0SIS>) writes:
-> >>I am programming a utility in C (lattice), and need to open a specific font off of a disk. (the font
-> >>is already stored in the fonts: dir of my boot disk).
-> >>
-> >>How do you go about opening that disk-based font?
->
-> >Use function OpenDiskFont() instead of OpenFont().
-> >I'm too lazy to type an example here, but look into the program
->
-> Also, in my experience, OpenDiskFont does NOT check to see
-> if the font is already loaded, and will load a duplicate.

Quite right, you have to check by yourself. Following is an old piece of code
that :
1) Finds out wether your display is PAL or NTSC
2) Tries to OpenFont(textattr), the size of the font depending on the video, so
the display looks about the same in both modes
3) If Open Font fails, tries OpenDiskFont
4) If that fails too, sends a requester telling you should copy the proper
font in FONTS:, then uses Topaz
5) adjusts margins and the same to final font size

#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/dos.h>
#include <proto/diskfont.h>


static struct TextAttr Fbub11ta = { (STRPTR)"fbubba.font",11,0,1 };
static struct TextAttr Fbub9ta =  { (STRPTR)"fbubba.font",9,0,1 };
USHORT xpos = 100;                                  /* left margin */
USHORT linespace = 11;
USHORT strophespace = 14;
USHORT topspace = 50;


main()
{
/* deleted code here, opening a screen then a backdrop, borderless window */

    if(SysBase->VBlankFrequency == 50) pal = TRUE;  /* a PAL system */
    else                                            /* a NTSC system */
    {
        pal = FALSE;
        NewScreenStructure.Height = 200;
        PNewWindowStructure1.Height = 200;
    }

    if(pal)    Fbubbatf = OpenFont(&Fbub11ta);  /* PAL */

    else       Fbubbatf = OpenFont(&Fbub9ta);   /* NTSC */

    Topaztf = OpenFont(&TOPAZ80);

    if(! Fbubbatf)
    {
        struct Library *DiskfontBase;

        if(DiskfontBase = (struct Library *)OpenLibrary("diskfont.library", 0))
        {
            if(pal)     Fbubbatf = OpenDiskFont(&Fbub11ta);
            else        Fbubbatf = OpenDiskFont(&Fbub9ta);
        }
    }
   if(! pal)
    {
        linespace = 9;
        strophespace = 10;
        topspace = 40;
    }

    if (! Fbubbatf)
    {
        BYTE result;

        SetFont(PRastPort, Topaztf);
        result = SmartReq(PWindow, &FBubbafReq);
        xpos += 40;
        linespace = 9;
        strophespace = 10;
        topspace = 40;
    }

    /* some code here , and some cleaning */

    if (Fbubbatf)           CloseFont(Fbubbatf);
    if (DiskfontBase)       CloseLibrary((struct Library *)DiskfontBase);
}

Hope this is going to help.          Alain DIDIERJEAN
         The Software Winery        ...cbmvax!cbmehq!cbmfra!swindj!didierj

jap@convex.cl.msu.edu (Joe Porkka) (01/11/91)

bj@cbmvax.commodore.com (Brian Jackson) writes:

>In article <706@cbmger.UUCP> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:


>>>>>   If the font is already in memory, the copy in memory is used. <<<<
>>>>>   The disk copy is not reloaded.                                <<<<

Thats how it is SUPPOSED to work, but it dont.

If you want example code to demo this, emial me.