home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
dev
/
cmanual-3.0.lha
/
CManual
/
Graphics
/
Fonts
/
Fonts.doc
< prev
next >
Wrap
Text File
|
1993-10-12
|
48KB
|
1,368 lines
2 FONTS
2.1 INTRODUCTION
In the previous chapters when we have printed text with help
of the low level Text() function or the high level IntuiText
structure, we have always used a font called "Topaz". The
reason why we always have used this font is simply because it
is the Amiga's default font and exist in ROM.
Topaz is, however, not the only font available on the Amiga.
There exist thousands more, but these are not placed in ROM,
they are loaded from disks. Loading fonts from disks is luckily
quite a simple task since all necessary functions have already
been written and exist in the "Diskfont Library".
In this chapter I will show you how to open the Diskfont
Library, and use its functions. This involves finding out
which fonts are available, loading them into memory and
how to use them. I will also explain how to create your own
fonts and use them in your own programs.
2.2 FONTS
A font is a collection of graphical objects that represents
characters. Since the Amiga was built as a graphical work
station the system has been designed to handle all different
types of fonts with great efficiency. Fonts of almost any size
can be used, and the Amiga can itself convert fonts to styles
like italic, underlined, bold, extended, and all possible
All fonts have a "Baseline" on which the characters are placed.
Characters like "abcdef" will all be on and above the baseline.
On the other hand, characters like "gjpqy" will also use some
space under the baseline.
Here are three letters - 'a' 'b' and 'g'. As you can see will
the 'g' use same space below the baseline. (The baseline is
like normal rows on a paper.)
#
#
#### #
# #
# #
# #
##### ##### #####
# # # # # #
# # # # # #
# # # # # #
# # # # # #
###### ##### ##### <= Baseline
#
#
# #
####
2.3 ROM FONTS
As said above, there exist for the moment only one ROM based
font on the Amiga. It is Topaz and exist in two sizes, 8 and
9 pixels high. (ROM is like the normal memory in a computer,
but when the computer is turned off the contents will still be
intact. The disadvantage is that you can not change anything
which is stored in ROM. ROM - "Read Only Memory".)
Topaz two sizes:
- 9 pixels high (32 characters/row low resolution)
(64 - " - high resolution)
- 8 pixels high (40 - " - low resolution)
(80 - " - high resolution)
Note! The limit on how many characters/row you can print simply
depends on the width of the screen. In the above example I
assume that low resolution means a 320 pixels wide display,
and high resolution 640 pixels wide screen. Nowadays you can
not be sure what the maximum width is simply because many
users are now working on displays with overscan, extra large
screens, see previous chapter for more information. I my
self is currently using a 736 pixels wide and 540 lines tall
display.
2.3.1 TEXTATTR STRUCTURE
When you want to use a font you allocate a TextAttr structure
(defined in the header file "graphics/text.h"). In the
structure you write your requirements, the name of the font,
height, style (normal, underlined, bold, italic...) and what
type it is (if the font exist in ROM or on Disk).
The TextAttr structure look like this:
struct TextAttr
{
STRPTR ta_Name;
UWORD ta_YSize;
UBYTE ta_Style;
UBYTE ta_Flags;
};
ta_Name: Name of the font together with the extension ".font".
For example: To get the font Topaz you should write
"topaz.font".
ta_YSize: The Height of the font. To get a 9 pixel high font
simply write 9.
ta_Style: There exist five different styles that may be
combined. The styles are: Normal, Underlined, Bold
Italic and Extended. You specify which styles you
want to use with the following flags: FS_NORMAL,
FSF_UNDERLINED, FSF_BOLD, FSF_ITALIC and
FSF_EXTENDED.
To get a combination (e.g. Bold and Italic) use the
binary OR operator "|" (e.g. FSF_BOLD | FSF_ITALIC).
Note! If you ask for an underlined font for example,
it is not sure there exist one. You should then get
the font you want in the normal style, and then
change it with help of the SetSoftStyle() function.
(Explained later in this chapter.)
ta_Flags: This field tells the Amiga what type of font you
want. If it is a ROM based font write FPF_ROMFONT.
If it is a disk based font write FPF_DISKFONT.
(See below for a complete Flag list.)
If you want to use the ROM font Topaz, 9 pixels high, normal
style, you should initialize the TextAttr structure like this:
struct TextAttr my_font_attr=
{
"topaz.font", /* Name of the font. */
9, /* Height (in pixels) */
FS_NORMAL, /* Style */
FPF_ROMFONT /* Exist in ROM. */
};
2.3.2 OPEN ROM FONTS
After you have initialized the TextAttr structure you call the
OpenFont() function to get access to a ROM font. The Amiga will
open the font which closes matches your requirements in the
TaxtAttr structure. If OpenFont() finds the font it returns a
pointer to a TextFont structure and tells the system that you
are using the font.
Synopsis: font = OpenFont( attr );
font: (struct TextFont *) Pointer to a TextFont structure
which is declared in header file "graphics/text.h".
See below for more information about this structure.
If OpenFont() could not find the font it returns
NULL.
attr: (struct TextAttr *) Pointer to an already initialized
TextAttr structure. OpenFont() will try to open the
font which closes matches your requirements.
2.3.3 CLOSE ROM FONTS
All fonts you have opened must be "closed" before your program
terminates! Since the font is in ROM no memory would be wasted
if you forgot to close a previously opened font, but your
program code would not look very good, so be careful. Close
a font by calling the CloseFont() function.
Synopsis: CloseFont( font );
font: (struct TextFont *) Pointer to a previously opened
TextFont structure. Note that you should NOT try to
close a font which you have not opened!
2.4 DISK FONTS
Most fonts does not exist in ROM but are loaded from disks.
The greatest advantage of loading fonts rather than including
the fonts with the program itself is that several programs
running at the same time can all use the same set of fonts.
A lot of memory is therefore saved.
2.4.1 DISKFONT LIBRARY
Most of the special routines which are involved with loading
and using disk fonts are automatically taken care of by the
Diskfont Library. Whenever you want to use disk fonts you
should remember to open this library.
The diskfont library is opened as all other libraries with an
OpenLibrary() call, and closed by and CloseLibrary() call. If
the diskfont library not have already been opened by some
other program it will be loaded from the system disk. (From
the logical device "LIBS:", named "diskfont.library".
Here is an example:
struct Library *DiskfontBase;
DiskfontBase = (struct DiskfontBase *)
OpenLibrary( "diskfont.library", 0 );
if( !DiskfontBase )
clean_up( "Could not open Diskfont library!" );
...
if( DiskfontBase )
CloseLibrary( DiskfontBase );
2.4.2 FINDING OUT WHICH FONTS ARE AVAILABLE
After you have opened the diskfont library you can use the
special function AvailFonts() which will scan through the
font directory of the system disk, and return a complete list
of available fonts.
Synopsis: missing = AvailFonts( buffer, size, type );
missing: (long) If the buffer was not big enough to store the
complete list of fonts in the extra number of bytes
needed is returned. If 0 is returned the buffer was
big enough for a complete list of fonts.
buffer: (char *) Pointer to some memory were the list of
fonts can be stored.
size: