home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / d / desklib / !DeskLib / h_doc / Font2 < prev    next >
Encoding:
Text File  |  1996-05-21  |  4.9 KB  |  163 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Font2.Font2.c
  12.     Author:  Copyright © 1994 Julian Smith
  13.     Version: 1.00 (08 Jul 1995)
  14.     Purpose: Fonts with automatic handling of mode-changing
  15. */
  16.  
  17.  
  18. /*
  19. The RISC OS font manager seems to work in terms of pixels rather than OS
  20. coordinates, and so it doesn't adjust fonts when the user changes to a
  21. screen mode with a different pixel-OS ratio. This results in fonts
  22. changing size over mode changes, unless they are re-calculated.
  23.  
  24. This causes all sorts of complexity in DeskLib's Template and Window
  25. libraries, because icons with outline fonts contain a font handle in the
  26. icon data, so Desk_Window_ModeChange (in Window.c.ModeChange) has to go
  27. through all loaded templates and windows looking for outline fonts, lose
  28. them with Desk_Font_LoseFont, recreate them with Desk_Font_FindFont and substitute
  29. the new Desk_font_handle values into the icon blocks.
  30.  
  31. For other uses of fonts, a simpler method is to make applications work
  32. with a *pointer* to a font handle rather than a straight font handle,
  33. and have a central agency take care of the actual font handles.
  34.  
  35. This is what Font2 does. The Font2 library can thus easily keep the list
  36. of font handles (which the application gets pointers into) and change
  37. the handles on mode changes without having to store the location of
  38. every font handle the application uses, and change them when the mode is
  39. changed. Hopefully this should make outline fonts much easier to use.
  40.  
  41. Note that if the application has many (Desk_font2_block *)'s, some will point
  42. to the *same* place if they are the same font. Font2 keeps a count of
  43. how many pointer there are so it knows when a Desk_font2_block is finished
  44. with.
  45.  
  46. Font2 also registers an exit-handler which calls Desk_Font_LoseFont for all
  47. fonts registered with Font2 when the application finished (the
  48. font-handling in Window/Template has always done this).
  49.  
  50. All calls to Font2 functions require the address of the (Desk_font2_block *),
  51. ie. a (Desk_font2_block **). This is because some of the functions set the
  52. pointer to NULL or a new value.
  53.  
  54.  
  55.  
  56. Use like:
  57.  
  58. Desk_font2_block    *font2;
  59.  
  60. main()
  61. {
  62. Desk_Font2_ClaimFont( &font2, "Trinity.Medium", 16*12, 16*12);
  63. }
  64.  
  65. Then in a redrawer:
  66.  
  67. Desk_Font_Paint3(
  68.     font2->handle,     |* Always correct for the current mode    *|
  69.     "Some text...", 
  70.     Desk_font_plot_OSCOORS | Desk_font_plot_CURRENTHANDLE, 
  71.     x, 
  72.     y - font2->info.miny, 
  73.     NULL, NULL, 0
  74.     );
  75.  
  76. Note the use of font2->info. I expect most programs will need to know
  77. about the Desk_font_info for all fonts they use, so Font2 provides this
  78. information automatically to a) save calls to Desk_Font_ReadInfo or b) save
  79. memory by storing each Desk_font_handle's information just once, regardless
  80. of how many times the applcation is using the font.
  81.  
  82. */
  83.  
  84.  
  85. #ifndef __Desk_Font2_h
  86. #define __Desk_Font2_h
  87.  
  88. #ifdef __cplusplus
  89.     extern "C" {
  90. #endif
  91.  
  92.  
  93. #ifndef __Desk_Font_h
  94.     #include "Desk.Font.h"
  95. #endif
  96.  
  97.  
  98.  
  99.  
  100. typedef struct Desk_font2_block    {
  101.     Desk_font_handle    handle;        /* Use for all font actions    */
  102.     Desk_font_info    info;        /* Always up-to-date info    */
  103.     }
  104.     Desk_font2_block;
  105.  
  106.  
  107. Desk_os_error    *Desk_Font2_ClaimFont(   Desk_font2_block **font2, const char *name, int sizex, int sizey);
  108. /*
  109. Makes (*font2) point to a suitable Desk_font2_block. Do not call this if
  110. font2 is already set - use Desk_Font2_ReclaimFont in this case.
  111.  
  112. sizex and sizey should be 16*pointsize.
  113.  
  114. (*font2)->info will be set with Desk_Font_ReadInfo.
  115. */
  116.  
  117. Desk_os_error    *Desk_Font2_ReclaimFont( Desk_font2_block **font2, const char *name, int xsize, int ysize);
  118. /*
  119. Releases existing font (if *font2!=NULL) and then makes *font2 point to a
  120. new Desk_font2_block for the specified font.
  121.  
  122. sizex and sizey should be 16*pointsize.
  123. */
  124.  
  125. void        Desk_Font2_ReleaseFont( Desk_font2_block **font2);
  126. /*
  127. Calls Desk_Font_LoseFont( (*font2)->handle) if *font2!=NULL, and then 
  128. sets *font2 to NULL
  129. */
  130.  
  131. void        Desk_Font2_Initialise( void);
  132. /*
  133. This is called automatically if necessary by Desk_Font2_(Re)Claim. It
  134. registers an event handler for Desk_message_MODECHANGE Desk_message_type, which
  135. re-finds all the font2 font handles.
  136. */
  137.  
  138.  
  139.  
  140.  
  141. #ifdef Desk_DeskLib_DEBUG
  142.     #ifdef Desk__making_Font2
  143.         #include "Debug.h"
  144.         #define Desk_debug_level Desk_font2_debuglevel
  145.     #endif
  146.     
  147.     extern int    Desk_font2_debuglevel;
  148. /*
  149. In the debug version of DeskLib, this is the Font2 library's own
  150. version of Desk_debug_level. It is initially 0; a program can set it to
  151. different values to turn on different debug ouputs in the Font2
  152. library.
  153.  */
  154. #endif
  155.  
  156.  
  157. #ifdef __cplusplus
  158. }
  159. #endif
  160.  
  161.  
  162. #endif
  163.