kate Library API Documentation

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., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. 00020 */ 00021 00022 #include "katefont.h" 00023 00024 #include <kglobalsettings.h> 00025 00026 // 00027 // KateFontMetrics implementation 00028 // 00029 00030 KateFontMetrics::KateFontMetrics(const QFont& f) : QFontMetrics(f) 00031 { 00032 for (int i=0; i<256; i++) warray[i]=0; 00033 } 00034 00035 KateFontMetrics::~KateFontMetrics() 00036 { 00037 for (int i=0; i<256; i++) 00038 delete[] warray[i]; 00039 } 00040 00041 short * KateFontMetrics::createRow (short *wa, uchar row) 00042 { 00043 wa=warray[row]=new short[256]; 00044 00045 for (int i=0; i<256; i++) wa[i]=-1; 00046 00047 return wa; 00048 } 00049 00050 int KateFontMetrics::width(QChar c) 00051 { 00052 uchar cell=c.cell(); 00053 uchar row=c.row(); 00054 short *wa=warray[row]; 00055 00056 if (!wa) 00057 wa = createRow (wa, row); 00058 00059 if (wa[cell]<0) wa[cell]=(short) QFontMetrics::width(c); 00060 00061 return (int)wa[cell]; 00062 } 00063 00064 // 00065 // FontStruct implementation 00066 // 00067 00068 FontStruct::FontStruct() 00069 : myFont(KGlobalSettings::fixedFont()), 00070 myFontBold(KGlobalSettings::fixedFont()), 00071 myFontItalic(KGlobalSettings::fixedFont()), 00072 myFontBI(KGlobalSettings::fixedFont()), 00073 myFontMetrics(myFont), 00074 myFontMetricsBold(myFontBold), 00075 myFontMetricsItalic(myFontItalic), 00076 myFontMetricsBI(myFontBI) 00077 { 00078 updateFontData (); 00079 } 00080 00081 FontStruct::~FontStruct() 00082 { 00083 } 00084 00085 void FontStruct::updateFontData () 00086 { 00087 int maxAscent = myFontMetrics.ascent(); 00088 int maxDescent = myFontMetrics.descent(); 00089 00090 fontHeight = maxAscent + maxDescent + 1; 00091 fontAscent = maxAscent; 00092 } 00093 00094 int FontStruct::width(const QString& text, int col, bool bold, bool italic, int tabWidth) 00095 { 00096 if (text[col] == QChar('\t')) 00097 return tabWidth * myFontMetrics.width(' '); 00098 00099 return (bold) ? 00100 ( (italic) ? 00101 myFontMetricsBI.charWidth(text, col) : 00102 myFontMetricsBold.charWidth(text, col) ) : 00103 ( (italic) ? 00104 myFontMetricsItalic.charWidth(text, col) : 00105 myFontMetrics.charWidth(text, col) ); 00106 } 00107 00108 int FontStruct::width(const QChar& c, bool bold, bool italic, int tabWidth) 00109 { 00110 if (c == QChar('\t')) 00111 return tabWidth * myFontMetrics.width(' '); 00112 00113 return (bold) ? 00114 ( (italic) ? 00115 myFontMetricsBI.width(c) : 00116 myFontMetricsBold.width(c) ) : 00117 ( (italic) ? 00118 myFontMetricsItalic.width(c) : 00119 myFontMetrics.width(c) ); 00120 } 00121 00122 void FontStruct::setFont (const QFont & font) 00123 { 00124 myFont = font; 00125 00126 myFontBold = QFont (font); 00127 myFontBold.setBold (true); 00128 00129 myFontItalic = QFont (font); 00130 myFontItalic.setItalic (true); 00131 00132 myFontBI = QFont (font); 00133 myFontBI.setBold (true); 00134 myFontBI.setItalic (true); 00135 00136 myFontMetrics = KateFontMetrics (myFont); 00137 myFontMetricsBold = KateFontMetrics (myFontBold); 00138 myFontMetricsItalic = KateFontMetrics (myFontItalic); 00139 myFontMetricsBI = KateFontMetrics (myFontBI); 00140 00141 updateFontData (); 00142 } 00143 00144 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE Logo
This file is part of the documentation for kate Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 8 11:16:26 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003