home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / cmanual-3.0.lha / CManual / Graphics / IncludeFonts / PrintFont.c < prev    next >
C/C++ Source or Header  |  1993-10-12  |  20KB  |  588 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Graphics                Amiga C Club       */
  7. /* Chapter: Include Fonts               Tulevagen 22       */
  8. /* File:    PrintFont.c                 181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-01                                       */
  11. /* Version: 1.10                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20.  
  21.  
  22. /****************************************************************/
  23. /*                                                              */
  24. /* PrintFont loads a specified diskfont and prints the complete */
  25. /* definition of it in 'C'. This printout can be included and   */
  26. /* compiled with your own programs, and you will then be able   */
  27. /* to use the font without having to bother about loading it.   */
  28. /* Perfect for smaller utilities and games!                     */
  29. /*                                                              */
  30. /* If you wite a large program that is using a lot of different */
  31. /* fonts it is best to load these fonts as normal, and not      */
  32. /* include all of them with help of this utility. The advantage */
  33. /* with normal diskfonts is that several programs can use the   */
  34. /* same fonts, and thus a lot of memory is saved. If the font   */
  35. /* is included together with the program code, no other program */
  36. /* can use that font. However, for small utilities and games it */
  37. /* is better to include the font rather than messing around     */
  38. /* with external files that may not exist.                      */
  39. /*                                                              */
  40. /* Many thanks to Michael Loughman who told me about his        */
  41. /* excellent idea to make a program that converts fonts into    */
  42. /* normal 'C' code. (What should we include next?)              */
  43. /*                                                              */
  44. /*                                                              */
  45. /*                 I N S T R U C T I O N S                      */
  46. /*                 -----------------------                      */
  47. /*                                                              */
  48. /* PrintFont converts disk fonts to 'C' code. The font may be   */
  49. /* of any size, proportional or non-proportional, and in any    */
  50. /* style. PrintFont does not handle coloured fonts, although    */
  51. /* this will soon be changed. If the font is non-proportional   */
  52. /* (fixed size), PrintFont will write two arrays, one for the   */
  53. /* font data (graphics) and one which contains information      */
  54. /* about where each character is in the font data, and how wide */
  55. /* each bit definition of the character is. After these two     */
  56. /* arrays a complete pre-initialized TextFont structure is      */
  57. /* written.                                                     */
  58. /*                                                              */
  59. /* If the font is proportional (variable size), PrintFont will  */
  60. /* add two more arrays. The first array contains the width of   */
  61. /* the box in which each character is printed, while the second */
  62. /* array contains the kerning data for each character. (The     */
  63. /* kerning value is the number of pixels each character is      */
  64. /* moved from the left left side of the box.)                   */
  65. /*                                                              */
  66. /* You need to tell PrintFont three things. First you must of   */
  67. /* course tell it which font yu want to convert. Secondly which */
  68. /* size of the font you want. (PrintFont will try to load the   */
  69. /* font which best matches your requirements.) Finally you need */
  70. /* to tell it what name the arrays and structure should have.   */
  71. /* (The name will be added to all arrays and the structure. For */
  72. /* example, if you set the name to "Nice", the font data array  */
  73. /* will then be called "NiceData" and the structure "NiceFont"  */
  74. /* and so on...)                                                */
  75. /*                                                              */
  76. /* This is how you call PrintFont: (without quotations)         */
  77. /*                                                              */
  78. /*   PrintFont > "file.c" "font" "size" "name"                  */
  79. /*                                                              */
  80. /* "file.c": The name of the file where all 'C' code will be    */
  81. /*           stored. Note the "arrow" in front of the name, it  */
  82. /*           tells DOS that all output should be stored in the  */
  83. /*           file "file.c".                                     */
  84. /*                                                              */
  85. /* "font":   The name of the font you want to convert.          */
  86. /*                                                              */
  87. /* "size":   The size (number of points) of the font you want   */
  88. /*           to convert.                                        */
  89. /*                                                              */
  90. /* "name":   The name of the structure and arrays.              */
  91. /*                                                              */
  92. /* For example. To convert the font "Times" of the size 18      */
  93. /* points to 'C' code, do like this: (The 'C' code will be      */
  94. /* stored in file "FontFile.c", and the TextFont structure      */
  95. /* will be called "NewsletterFont".)                            */
  96. /*                                                              */
  97. /*   PrintFont > FontFile.c Times 18 Newsletter                 */
  98. /*                                                              */
  99. /*                                                              */
  100. /* Once the font has been converted you can immediately start   */
  101. /* to use it. To change the RastPort's font to your new         */
  102. /* "NewsletterFont", simply call the function SetFont().        */
  103. /*                                                              */
  104. /* Synopsis:  error = SetFont( rast_port, font );               */
  105. /*                                                              */
  106. /* error:     (long) If SetFond could not change the RastPort's */
  107. /*            font it returns a non zero value. If it could     */
  108. /*            change font successfully it returns 0.            */
  109. /*                                                              */
  110. /* rast_port: (struct RastPort *) Pointer to the RastPort which */
  111. /*            should use the new font.                          */
  112. /*                                                              */
  113. /* font:      (struct TextFont *) Pointer to the font you have  */
  114. /*            converted (or opened as usual).                   */
  115. /*                                                              */
  116. /* error = SetFont( &my_rast_port, &NewsletterFont )            */
  117. /* if( error )                                                  */
  118. /*   printf( "Could not change font!\n" );                      */
  119. /*                                                              */
  120. /****************************************************************/
  121.  
  122.  
  123. #include <intuition/intuition.h>
  124.  
  125.  
  126. struct Intuition *IntuitionBase = NULL; /* Running under Intuition. */
  127. struct GfxBase *GfxBase = NULL;         /* Move() and Text().       */
  128. struct Library *DiskfontBase = NULL;    /* OpenDiskFont() etc.      */
  129.  
  130.  
  131.  
  132. /* The new font's attributes: */
  133. struct TextAttr font_attr;
  134.  
  135. /* Pointer to our new font: */
  136. struct TextFont *font = NULL;
  137.  
  138. /* Declare a pointer to a Window structure: */ 
  139. struct Window *m