home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src / lib / c / text.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-04  |  3.0 KB  |  128 lines

  1. /*
  2. ** ACE db.lib module: change text style or font.
  3. ** Copyright (C) 1998 David Benn
  4. ** 
  5. ** This program is free software; you can redistribute it and/or
  6. ** modify it under the terms of the GNU General Public License
  7. ** as published by the Free Software Foundation; either version 2
  8. ** of the License, or (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program; if not, write to the Free Software
  17. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18. **
  19. ** Author: David J Benn
  20. **   Date: 31st January 1994,
  21. **       1st,6th February 1994,
  22. **       20th March 1994,
  23. **       20th,28th August 1994,
  24. **       10th September 1994,
  25. **       17th October 1996
  26. */
  27.  
  28. #include <exec/types.h>
  29. #include <exec/memory.h>
  30. #include <intuition/intuition.h>
  31.  
  32. #define    CLEARED_ANY_MEM 7L
  33.  
  34. /* Globals */
  35. struct Library     *DiskfontBase;    
  36.  
  37. /* Externals */
  38. extern     struct     RastPort *RPort;
  39. extern    UBYTE    IntuiMode;
  40.  
  41. /* External Functions */
  42. extern     void     stringcopy();
  43. extern     ULONG     stringlength();
  44. extern    LONG    stringcompare();
  45. extern    void    *alloc();
  46.  
  47. /* Functions */
  48. void change_text_style(style)
  49. LONG style;
  50. {
  51. /*
  52. ** Change the text style for the current rastport or console window.
  53. */
  54.     
  55.     if (IntuiMode)
  56.     {
  57.         /* plain, underlined, bold, italic, extended */    
  58.         SetSoftStyle(RPort,style,(ULONG)AskSoftStyle(RPort));
  59.     }
  60.     else
  61.     /* plain, underlined, bold, italic */
  62.     if (style >= 0 && style <= 7)
  63.     {
  64.         /* 
  65.         ** Reset console text styles to plain.
  66.         ** A style of zero will do ONLY this.
  67.         */
  68.         putchar(27);
  69.         printf("[0m");
  70.  
  71.         /* underlined */
  72.         if (style & 1) { putchar(27); printf("[4m"); }
  73.  
  74.         /* bold */
  75.         if (style & 2) { putchar(27); printf("[1m"); }
  76.  
  77.         /* italic */
  78.         if (style & 4) { putchar(27); printf("[3m"); }
  79.     }
  80. }
  81.  
  82. void change_text_font(size,name)
  83. LONG size;
  84. char *name;
  85. {
  86. /*
  87. ** Change the font for the current output window's rastport 
  88. ** (intuition windows ONLY).
  89. */
  90. char    *tmp,*font;
  91. struct     TextAttr myFont;
  92. struct     TextFont *FontPtr;
  93.  
  94.     DiskfontBase = (struct Library *)
  95.             OpenLibrary("diskfont.library",0L);
  96.  
  97.     if (DiskfontBase)
  98.     {
  99.         /* append ".font" to name if not present */
  100.         font = (char *)alloc(CLEARED_ANY_MEM,stringlength(name)+6);
  101.                     
  102.         stringcopy(font,name);
  103.         tmp = font;
  104.         while (*tmp && *tmp != '.') tmp++;
  105.         if (stringcompare(tmp,".font") != 0)
  106.            stringcopy(tmp,".font");
  107.  
  108.         /* set up TextAttr structure */
  109.         myFont.ta_Name     = (STRPTR)font;
  110.         myFont.ta_YSize    = (UWORD)size;
  111.         myFont.ta_Style    = 0;
  112.         myFont.ta_Flags    = 0;
  113.  
  114.         /* attempt to open font */
  115.         FontPtr = (struct TextFont *)OpenDiskFont(&myFont);    
  116.  
  117.         /* set new font and close old one */
  118.         if (FontPtr) 
  119.         {
  120.             CloseFont(RPort->Font);
  121.             SetFont(RPort,FontPtr);
  122.         }
  123.  
  124.         /* cleanup */
  125.         CloseLibrary(DiskfontBase);
  126.     } 
  127. }
  128.