1 /** 2 * Copyright (c) 2005 PCMan <pcman.tw@gmail.com> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 19 #ifndef FONT_H 20 #define FONT_H 21 22 #ifdef __GNUG__ 23 #pragma interface "font.h" 24 #endif 25 26 #include "pcmanx_utils.h" 27 28 #include <string> 29 #include <X11/Xft/Xft.h> 30 31 using namespace std; 32 33 /** 34 @author PCMan 35 */ 36 class CFont{ 37 public: 38 CFont(); 39 ~CFont(); 40 CFont( string name, int pt_size, bool compact = false, bool anti_alias = true ); 41 CFont( string name, int width, int height, bool compact = false, bool anti_alias = true ); 42 void SetFont( string name, int pt_size, bool compact = false, bool anti_alias = true ); 43 void SetFont( string name, int width, int height, bool compact = false, bool anti_alias = true ); 44 void SetFontFamily( string name ); GetHeight()45 int GetHeight(){ return m_XftFont->ascent + m_XftFont->descent; }; GetWidth()46 int GetWidth(){ return m_XftFont->max_advance_width / 2; }; GetXftFont()47 XftFont* GetXftFont(){ return m_XftFont; } GetName()48 string GetName(){ return m_Name; } GetAntiAlias()49 bool GetAntiAlias(){ return m_AntiAlias; } GetCompact()50 bool GetCompact(){ return m_Compact; } 51 protected: 52 XftFont* m_XftFont; 53 string m_Name; 54 int m_PointSize; 55 int m_MaxWidth; 56 int m_MaxHeight; 57 bool m_Compact; 58 bool m_AntiAlias; 59 private: 60 XftFont* CreateXftFont( string name, int size, bool anti_alias ); 61 XftFont* CreateXftFont( string name, int width, int heigh, bool anti_alias ); 62 void CloseXftFont( XftFont* font ); 63 void RecalculateMetrics( XftFont* font ); 64 }; 65 66 #endif 67