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 >
Text File  |  1993-10-12  |  48KB  |  1,368 lines

  1. 2    FONTS
  2.  
  3. 2.1  INTRODUCTION
  4.  
  5. In the previous chapters when we have printed text with help
  6. of the low level Text() function or the high level IntuiText
  7. structure, we have always used a font called "Topaz". The
  8. reason why we always have used this font is simply because it
  9. is the Amiga's default font and exist in ROM.
  10.  
  11. Topaz is, however, not the only font available on the Amiga.
  12. There exist thousands more, but these are not placed in ROM,
  13. they are loaded from disks. Loading fonts from disks is luckily
  14. quite a simple task since all necessary functions have already
  15. been written and exist in the "Diskfont Library".
  16.  
  17. In this chapter I will show you how to open the Diskfont
  18. Library, and use its functions. This involves finding out
  19. which fonts are available, loading them into memory and
  20. how to use them. I will also explain how to create your own
  21. fonts and use them in your own programs.
  22.  
  23.  
  24.  
  25. 2.2  FONTS
  26.  
  27. A font is a collection of graphical objects that represents
  28. characters. Since the Amiga was built as a graphical work
  29. station the system has been designed to handle all different
  30. types of fonts with great efficiency. Fonts of almost any size
  31. can be used, and the Amiga can itself convert fonts to styles
  32. like italic, underlined, bold, extended, and all possible
  33.  
  34. All fonts have a "Baseline" on which the characters are placed.
  35. Characters like "abcdef" will all be on and above the baseline.
  36. On the other hand, characters like "gjpqy" will also use some
  37. space under the baseline.
  38.  
  39. Here are three letters - 'a' 'b' and 'g'. As you can see will
  40. the 'g' use same space below the baseline. (The baseline is
  41. like normal rows on a paper.)
  42.  
  43.            #
  44.            #
  45.     ####   #
  46.         #  #
  47.         #  #
  48.         #  #
  49.     #####  #####   #####
  50.    #    #  #    # #    #
  51.    #    #  #    # #    #
  52.    #    #  #    # #    #
  53.    #    #  #    # #    #
  54.     ###### #####   ##### <= Baseline
  55.                        #
  56.                        #
  57.                   #    #
  58.                    ####
  59.  
  60.  
  61.  
  62.  
  63. 2.3  ROM FONTS
  64.  
  65. As said above, there exist for the moment only one ROM based
  66. font on the Amiga. It is Topaz and exist in two sizes, 8 and
  67. 9 pixels high. (ROM is like the normal memory in a computer,
  68. but when the computer is turned off the contents will still be
  69. intact. The disadvantage is that you can not change anything
  70. which is stored in ROM. ROM - "Read Only Memory".)
  71.  
  72. Topaz two sizes:
  73.  
  74.   - 9 pixels high (32 characters/row low resolution)
  75.                   (64     - " -      high resolution)
  76.   - 8 pixels high (40     - " -      low resolution)
  77.                   (80     - " -      high resolution)
  78.  
  79. Note! The limit on how many characters/row you can print simply
  80. depends on the width of the screen. In the above example I
  81. assume that low resolution means a 320 pixels wide display,
  82. and high resolution 640 pixels wide screen. Nowadays you can
  83. not be sure what the maximum width is simply because many
  84. users are now working on displays with overscan, extra large
  85. screens, see previous chapter for more information. I my
  86. self is currently using a 736 pixels wide and 540 lines tall
  87. display.
  88.  
  89.  
  90.  
  91. 2.3.1  TEXTATTR STRUCTURE
  92.  
  93. When you want to use a font you allocate a TextAttr structure
  94. (defined in the header file "graphics/text.h"). In the
  95. structure you write your requirements, the name of the font,
  96. height, style (normal, underlined, bold, italic...) and what
  97. type it is (if the font exist in ROM or on Disk).
  98.  
  99. The TextAttr structure look like this:
  100.  
  101. struct TextAttr
  102. {
  103.   STRPTR ta_Name;
  104.   UWORD ta_YSize;
  105.   UBYTE ta_Style;
  106.   UBYTE ta_Flags;
  107. };
  108.  
  109. ta_Name:  Name of the font together with the extension ".font".
  110.           For example: To get the font Topaz you should write
  111.           "topaz.font".
  112.  
  113. ta_YSize: The Height of the font. To get a 9 pixel high font
  114.           simply write 9.
  115.  
  116. ta_Style: There exist five different styles that may be
  117.           combined. The styles are: Normal, Underlined, Bold
  118.           Italic and Extended. You specify which styles you
  119.           want to use with the following flags: FS_NORMAL,
  120.           FSF_UNDERLINED, FSF_BOLD, FSF_ITALIC and
  121.           FSF_EXTENDED.
  122.           
  123.           To get a combination (e.g. Bold and Italic) use the
  124.           binary OR operator "|" (e.g. FSF_BOLD | FSF_ITALIC). 
  125.  
  126.           Note! If you ask for an underlined font for example,
  127.           it is not sure there exist one. You should then get
  128.           the font you want in the normal style, and then
  129.           change it with help of the SetSoftStyle() function.
  130.           (Explained later in this chapter.)
  131.  
  132. ta_Flags: This field tells the Amiga what type of font you
  133.           want. If it is a ROM based font write FPF_ROMFONT.
  134.           If it is a disk based font write FPF_DISKFONT.
  135.           (See below for a complete Flag list.)
  136.  
  137.  
  138. If you want to use the ROM font Topaz, 9 pixels high, normal
  139. style, you should initialize the TextAttr structure like this:
  140.  
  141.  
  142. struct TextAttr my_font_attr=
  143. {
  144.   "topaz.font", /* Name of the font.  */
  145.   9,            /* Height (in pixels) */
  146.   FS_NORMAL,    /* Style              */
  147.   FPF_ROMFONT   /* Exist in ROM.      */
  148. };
  149.  
  150.  
  151.  
  152. 2.3.2  OPEN ROM FONTS
  153.  
  154. After you have initialized the TextAttr structure you call the
  155. OpenFont() function to get access to a ROM font. The Amiga will
  156. open the font which closes matches your requirements in the
  157. TaxtAttr structure. If OpenFont() finds the font it returns a
  158. pointer to a TextFont structure and tells the system that you
  159. are using the font.
  160.  
  161. Synopsis: font = OpenFont( attr );
  162.  
  163. font:     (struct TextFont *) Pointer to a TextFont structure
  164.           which is declared in header file "graphics/text.h".
  165.           See below for more information about this structure.
  166.           If OpenFont() could not find the font it returns
  167.           NULL.
  168.  
  169. attr:     (struct TextAttr *) Pointer to an already initialized
  170.           TextAttr structure. OpenFont() will try to open the
  171.           font which closes matches your requirements.
  172.  
  173.  
  174.  
  175. 2.3.3  CLOSE ROM FONTS
  176.  
  177. All fonts you have opened must be "closed" before your program
  178. terminates! Since the font is in ROM no memory would be wasted
  179. if you forgot to close a previously opened font, but your
  180. program code would not look very good, so be careful. Close
  181. a font by calling the CloseFont() function.
  182.  
  183. Synopsis: CloseFont( font );
  184.  
  185. font:     (struct TextFont *) Pointer to a previously opened
  186.           TextFont structure. Note that you should NOT try to
  187.           close a font which you have not opened!
  188.  
  189.  
  190.  
  191. 2.4  DISK FONTS
  192.  
  193. Most fonts does not exist in ROM but are loaded from disks.
  194. The greatest advantage of loading fonts rather than including
  195. the fonts with the program itself is that several programs
  196. running at the same time can all use the same set of fonts.
  197. A lot of memory is therefore saved.
  198.  
  199.  
  200.  
  201. 2.4.1  DISKFONT LIBRARY
  202.  
  203. Most of the special routines which are involved with loading
  204. and using disk fonts are automatically taken care of by the
  205. Diskfont Library. Whenever you want to use disk fonts you
  206. should remember to open this library.
  207.  
  208. The diskfont library is opened as all other libraries with an
  209. OpenLibrary() call, and closed by and CloseLibrary() call. If
  210. the diskfont library not have already been opened by some
  211. other program it will be loaded from the system disk. (From
  212. the logical device "LIBS:", named "diskfont.library".
  213.  
  214. Here is an example:
  215.  
  216.   struct Library *DiskfontBase;
  217.  
  218.   DiskfontBase = (struct DiskfontBase *)
  219.     OpenLibrary( "diskfont.library", 0 );
  220.  
  221.   if( !DiskfontBase )
  222.     clean_up( "Could not open Diskfont library!" );
  223.  
  224.   ...
  225.  
  226.   if( DiskfontBase )
  227.     CloseLibrary( DiskfontBase );
  228.  
  229.  
  230.  
  231. 2.4.2  FINDING OUT WHICH FONTS ARE AVAILABLE
  232.  
  233. After you have opened the diskfont library you can use the
  234. special function AvailFonts() which will scan through the
  235. font directory of the system disk, and return a complete list
  236. of available fonts.
  237.  
  238. Synopsis: missing = AvailFonts( buffer, size, type );
  239.  
  240. missing:  (long) If the buffer was not big enough to store the
  241.           complete list of fonts in the extra number of bytes
  242.           needed is returned. If 0 is returned the buffer was
  243.           big enough for a complete list of fonts.
  244.  
  245. buffer:   (char *) Pointer to some memory were the list of
  246.           fonts can be stored.
  247.           
  248. size: