home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377a.lha / libraries / graphics / text / ShowOpenFont.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-04  |  3.2 KB  |  91 lines

  1. /* ShowOpenFont
  2.    An example illustrating how to request a font from OpenFont().
  3.    Insert this routine into the "wrapper" code at the end of the chapter.
  4.  
  5.    Copyright (c) 1990 Commodore-Amiga, Inc.
  6.   
  7.    This example is provided in electronic form by Commodore-Amiga, Inc. for
  8.    use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  9.    The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  10.    information on the correct usage of the techniques and operating system
  11.    functions presented in this example.  The source and executable code of
  12.    this example may only be distributed in free electronic form, via bulletin
  13.    board or as part of a fully non-commercial and freely redistributable
  14.    diskette.  Both the source and executable code (including comments) must
  15.    be included, without modification, in any copy.  This example may not be
  16.    published in printed form or distributed with any commercial product.
  17.    However, the programming techniques and support routines set forth in
  18.    this example may be used in the development of original executable
  19.    software products for Commodore Amiga computers.
  20.    All other rights reserved.
  21.    This example is provided "as-is" and is subject to change; no warranties
  22.    are made.  All use is at your own risk.  No liability or responsibility
  23.    is assumed.
  24. */
  25.  
  26.  
  27. BOOL example(struct Window *window)
  28. {
  29. SHORT indentLeft = window->BorderLeft, indentTop = window->BorderTop;
  30. struct RastPort *rastPort = window->RPort;
  31. struct TextAttr textAttr;
  32. struct TextFont *textFont, *oldTextFont;
  33.  
  34. TITLE(window, "Using OpenFont() to request fonts");
  35.  
  36. SetAPen(rastPort, COLOR1);
  37.  
  38. /*  Save the address of the RastPort's current font for replacement later.
  39.     It cannot "disappear" during this time as it still has at least
  40.     one "accessor".
  41. */
  42. oldTextFont = rastPort->Font;
  43.  
  44. /*  Fill the TextAttr structure with the desired characteristics.  */
  45. /*  These just happen to be the attributes of the standard topaz 80 font.  */
  46. textAttr.ta_Name = "topaz.font";
  47. textAttr.ta_YSize = 8;
  48. textAttr.ta_Style = FS_NORMAL;
  49. textAttr.ta_Flags = FPF_DESIGNED | FPF_ROMFONT;
  50.  
  51.  
  52. /*  Request this font from the system.  */
  53. textFont = OpenFont(&textAttr);
  54. if (textFont)
  55.     {
  56.     /*  Make this font the RastPort's default font.  */
  57.     SetFont(rastPort, textFont);
  58.  
  59.     /*  Move the pen's current position such that the characters
  60.         will be rendered below the Window's top border.
  61.     */
  62.     indentTop += rastPort->TxBaseline;
  63.     Move(rastPort, indentLeft, indentTop);
  64.  
  65.     Text(rastPort, "topaz.font, 8 dots high", 23 );
  66.  
  67.     /*  Set this RastPort's font back to its original font.  */
  68.     SetFont(rastPort, oldTextFont);
  69.  
  70.     /*  Close the font when completely done with it.  */
  71.     CloseFont(textFont);
  72.     }
  73.  
  74. textAttr.ta_YSize = 9;    /*  Change the textAttr structure,  */
  75. textFont = OpenFont(&textAttr);    /*  and request this new font.  */
  76. if (textFont)
  77.     {
  78.     SetFont(rastPort,textFont);
  79.     /*  Move down to avoid overlapping with the previous line.
  80.         Use the new font's YSize plus one pixel.
  81.     */
  82.     indentTop += textFont->tf_YSize + 1;
  83.     Move(rastPort, indentLeft, indentTop);
  84.     Text(rastPort, "topaz.font, 9 dots high", 23);
  85.     SetFont(rastPort, oldTextFont);
  86.     CloseFont(textFont);
  87.     }
  88. return(WAIT_FOR_CLOSE);
  89. }
  90.  
  91.