katefont.cpp
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2002 Christian Couder <christian@kdevelop.org> 00003 Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> 00004 Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> 00005 Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License version 2 as published by the Free Software Foundation. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include "katefont.h" 00023 00024 #include <tdeglobalsettings.h> 00025 00026 #include <tqfontinfo.h> 00027 00028 // 00029 // KateFontMetrics implementation 00030 // 00031 00032 KateFontMetrics::KateFontMetrics(const TQFont& f) : TQFontMetrics(f) 00033 { 00034 for (int i=0; i<256; i++) warray[i]=0; 00035 } 00036 00037 KateFontMetrics::~KateFontMetrics() 00038 { 00039 for (int i=0; i<256; i++) 00040 delete[] warray[i]; 00041 } 00042 00043 short * KateFontMetrics::createRow (short *wa, uchar row) 00044 { 00045 wa=warray[row]=new short[256]; 00046 00047 for (int i=0; i<256; i++) wa[i]=-1; 00048 00049 return wa; 00050 } 00051 00052 int KateFontMetrics::width(TQChar c) 00053 { 00054 uchar cell=c.cell(); 00055 uchar row=c.row(); 00056 short *wa=warray[row]; 00057 00058 if (!wa) 00059 wa = createRow (wa, row); 00060 00061 if (wa[cell]<0) wa[cell]=(short) TQFontMetrics::width(c); 00062 00063 return (int)wa[cell]; 00064 } 00065 00066 // 00067 // KateFontStruct implementation 00068 // 00069 00070 KateFontStruct::KateFontStruct() 00071 : myFont(TDEGlobalSettings::fixedFont()), 00072 myFontBold(TDEGlobalSettings::fixedFont()), 00073 myFontItalic(TDEGlobalSettings::fixedFont()), 00074 myFontBI(TDEGlobalSettings::fixedFont()), 00075 myFontMetrics(myFont), 00076 myFontMetricsBold(myFontBold), 00077 myFontMetricsItalic(myFontItalic), 00078 myFontMetricsBI(myFontBI), 00079 m_fixedPitch (false) 00080 { 00081 updateFontData (); 00082 } 00083 00084 KateFontStruct::~KateFontStruct() 00085 { 00086 } 00087 00088 void KateFontStruct::updateFontData () 00089 { 00090 int maxAscent = myFontMetrics.ascent(); 00091 int maxDescent = myFontMetrics.descent(); 00092 00093 fontHeight = maxAscent + maxDescent + 1; 00094 fontAscent = maxAscent; 00095 00096 m_fixedPitch = TQFontInfo( myFont ).fixedPitch(); 00097 } 00098 00099 void KateFontStruct::setFont (const TQFont & font) 00100 { 00101 TQFontMetrics testFM (font); 00102 00103 // no valid font tried 00104 if ((testFM.ascent() + testFM.descent() + 1) < 1) 00105 return; 00106 00107 myFont = font; 00108 00109 myFontBold = TQFont (font); 00110 myFontBold.setBold (true); 00111 00112 myFontItalic = TQFont (font); 00113 myFontItalic.setItalic (true); 00114 00115 myFontBI = TQFont (font); 00116 myFontBI.setBold (true); 00117 myFontBI.setItalic (true); 00118 00119 myFontMetrics = KateFontMetrics (myFont); 00120 myFontMetricsBold = KateFontMetrics (myFontBold); 00121 myFontMetricsItalic = KateFontMetrics (myFontItalic); 00122 myFontMetricsBI = KateFontMetrics (myFontBI); 00123 00124 updateFontData (); 00125 } 00126 00127 // kate: space-indent on; indent-width 2; replace-tabs on;