1a2510d6fe1a8b3bf185924d7f69288115a67f4c
[AXE.git] / src / font.h
1 /**************************************************************************
2 **  (c) Copyright 1998, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 **      FILE NAME      : font.h
7 **      SYSTEM NAME    : AXE - Andromeda X-windows Encapsulation
8 **      VERSION NUMBER : $Revision: 1.1 $
9 **
10 **  DESCRIPTION      : Definition of font class 
11 **
12 **  EXPORTED OBJECTS : class font
13 **  LOCAL    OBJECTS : 
14 **  MODULES  USED    :
15 ***************************************************************************
16 **  ADMINISTRATIVE INFORMATION *
17 ********************************
18 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 **      CREATION DATE   : Feb 13, 1998
20 **      LAST UPDATE     : Jan 22, 2002
21 **      MODIFICATIONS   : 
22 **************************************************************************/
23
24 /*****************************
25    $Log: font.h,v $
26    Revision 1.1  2002-07-25 08:01:26  arjen
27    First checkin, AXE release 0.2
28
29 *****************************/
30
31 /* static const char *RCSID = "$Id: font.h,v 1.1 2002-07-25 08:01:26 arjen Exp $"; */
32
33 #include <iostream>
34 #include <X11/Xlib.h>
35 #include "display.h"
36 #include "String.h"
37
38 /*
39 ///////////////////////////////////////////////////////////////////////////
40 //  NAME           : font
41 //  BASECLASS      :
42 //  MEMBERS        : XFontStruct *fs
43 //  OPERATORS      :
44 //  METHODS        :
45 //
46 //  DESCRIPTION    :
47 //
48 //  RELATIONS      :
49 //  SEE ALSO       :
50 //  LAST MODIFIED  : Jan 22, 2002
51 ///////////////////////////////////////////////////////////////////////////
52 */
53
54 class font
55 {
56    XFontStruct *fs;
57
58 public:
59
60    font()
61    {
62       fs = 0;
63    }
64
65    font(char *name)
66    {
67       fs = XLoadQueryFont(stddpy.Dpy(), name);
68       if (fs == NULL)
69       {
70          cerr << "Warnig: can not open font " << name << "\n";
71       }
72    }
73
74    ~font()
75    {
76       if (fs)
77          XFreeFont(stddpy.Dpy(), fs);
78    }
79
80    operator bool(void)
81    {
82       return fs != 0;
83    }
84
85    void Load(char *name)
86    {
87       if (fs)
88          XFreeFont(stddpy.Dpy(), fs);
89       fs = XLoadQueryFont(stddpy.Dpy(), name);
90       if (fs == NULL)
91       {
92          cerr << "Warnig: can not open font " << name << "\n";
93       }
94    }
95
96    operator XID ()
97    {
98       return fs ? fs->fid : 0;
99    }
100
101    int TextWidth(char *string, int length = 0);
102    int TextWidth(const String & string);
103
104    int ascent(void)
105    {
106       return fs ? fs->ascent : 0;
107    }
108
109    int descent(void)
110    {
111       return fs ? fs->descent : 0;
112    }
113 };
114