TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

katefont.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* This file is part of the KDE libraries
  2. Copyright (C) 2002 Christian Couder <christian@tdevelop.org>
  3. Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
  4. Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
  5. Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
  6. This library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Library General Public
  8. License version 2 as published by the Free Software Foundation.
  9. This library 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 GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public License
  14. along with this library; see the file COPYING.LIB. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. Boston, MA 02110-1301, USA.
  17. */
  18. #include "katefont.h"
  19. #include <tdeglobalsettings.h>
  20. #include <tqfontinfo.h>
  21. //
  22. // KateFontMetrics implementation
  23. //
  24. KateFontMetrics::KateFontMetrics(const TQFont& f) : TQFontMetrics(f)
  25. {
  26. for (int i=0; i<256; i++) warray[i]=0;
  27. }
  28. KateFontMetrics::~KateFontMetrics()
  29. {
  30. for (int i=0; i<256; i++)
  31. delete[] warray[i];
  32. }
  33. short * KateFontMetrics::createRow (short *wa, uchar row)
  34. {
  35. wa=warray[row]=new short[256];
  36. for (int i=0; i<256; i++) wa[i]=-1;
  37. return wa;
  38. }
  39. int KateFontMetrics::width(TQChar c)
  40. {
  41. uchar cell=c.cell();
  42. uchar row=c.row();
  43. short *wa=warray[row];
  44. if (!wa)
  45. wa = createRow (wa, row);
  46. if (wa[cell]<0) wa[cell]=(short) TQFontMetrics::width(c);
  47. return (int)wa[cell];
  48. }
  49. //
  50. // KateFontStruct implementation
  51. //
  52. KateFontStruct::KateFontStruct()
  53. : myFont(TDEGlobalSettings::fixedFont()),
  54. myFontBold(TDEGlobalSettings::fixedFont()),
  55. myFontItalic(TDEGlobalSettings::fixedFont()),
  56. myFontBI(TDEGlobalSettings::fixedFont()),
  57. myFontMetrics(myFont),
  58. myFontMetricsBold(myFontBold),
  59. myFontMetricsItalic(myFontItalic),
  60. myFontMetricsBI(myFontBI),
  61. m_fixedPitch (false)
  62. {
  63. updateFontData ();
  64. }
  65. KateFontStruct::~KateFontStruct()
  66. {
  67. }
  68. void KateFontStruct::updateFontData ()
  69. {
  70. int maxAscent = myFontMetrics.ascent();
  71. int maxDescent = myFontMetrics.descent();
  72. fontHeight = maxAscent + maxDescent + 1;
  73. fontAscent = maxAscent;
  74. m_fixedPitch = TQFontInfo( myFont ).fixedPitch();
  75. }
  76. void KateFontStruct::setFont (const TQFont & font)
  77. {
  78. TQFontMetrics testFM (font);
  79. // no valid font tried
  80. if ((testFM.ascent() + testFM.descent() + 1) < 1)
  81. return;
  82. myFont = font;
  83. myFontBold = TQFont (font);
  84. myFontBold.setBold (true);
  85. myFontItalic = TQFont (font);
  86. myFontItalic.setItalic (true);
  87. myFontBI = TQFont (font);
  88. myFontBI.setBold (true);
  89. myFontBI.setItalic (true);
  90. myFontMetrics = KateFontMetrics (myFont);
  91. myFontMetricsBold = KateFontMetrics (myFontBold);
  92. myFontMetricsItalic = KateFontMetrics (myFontItalic);
  93. myFontMetricsBI = KateFontMetrics (myFontBI);
  94. updateFontData ();
  95. }
  96. // kate: space-indent on; indent-width 2; replace-tabs on;