Fixed compiler warnings
[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.2 $
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.2  2002-11-04 07:24:31  arjen
27    Use proper namespace for iostream classes
28
29    Revision 1.1  2002/07/25 08:01:26  arjen
30    First checkin, AXE release 0.2
31
32 *****************************/
33
34 /* static const char *RCSID = "$Id: font.h,v 1.2 2002-11-04 07:24:31 arjen Exp $"; */
35
36 #include <iostream>
37 #include <X11/Xlib.h>
38 #include "display.h"
39 #include "String.h"
40
41 /*
42 ///////////////////////////////////////////////////////////////////////////
43 //  NAME           : font
44 //  BASECLASS      :
45 //  MEMBERS        : XFontStruct *fs
46 //  OPERATORS      :
47 //  METHODS        :
48 //
49 //  DESCRIPTION    :
50 //
51 //  RELATIONS      :
52 //  SEE ALSO       :
53 //  LAST MODIFIED  : Jan 22, 2002
54 ///////////////////////////////////////////////////////////////////////////
55 */
56
57 class font
58 {
59    XFontStruct *fs;
60
61 public:
62
63    font()
64    {
65       fs = 0;
66    }
67
68    font(const char name[])
69    {
70       fs = XLoadQueryFont(stddpy.Dpy(), name);
71       if (fs == NULL)
72       {
73          std::cerr << "Warnig: can not open font " << name << "\n";
74       }
75    }
76
77    ~font()
78    {
79       if (fs)
80          XFreeFont(stddpy.Dpy(), fs);
81    }
82
83    operator bool(void)
84    {
85       return fs != 0;
86    }
87
88    void Load(const char name[])
89    {
90       if (fs)
91          XFreeFont(stddpy.Dpy(), fs);
92       fs = XLoadQueryFont(stddpy.Dpy(), name);
93       if (fs == NULL)
94       {
95          std::cerr << "Warnig: can not open font " << name << "\n";
96       }
97    }
98
99    operator XID ()
100    {
101       return fs ? fs->fid : 0;
102    }
103
104    int TextWidth(char *string, int length = 0);
105    int TextWidth(const String & string);
106
107    int ascent(void)
108    {
109       return fs ? fs->ascent : 0;
110    }
111
112    int descent(void)
113    {
114       return fs ? fs->descent : 0;
115    }
116 };
117