font.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef KHTMLFONT_H
00027 #define KHTMLFONT_H
00028
00029 #include <qfont.h>
00030 #include <qfontmetrics.h>
00031 #include <qpainter.h>
00032
00033 class QPaintDeviceMetrics;
00034
00035
00036 namespace khtml
00037 {
00038 class RenderStyle;
00039 class CSSStyleSelector;
00040
00041 class FontDef
00042 {
00043 public:
00044 FontDef()
00045 : size( 0 ), italic( false ), smallCaps( false ), weight( 50 ), hasNbsp( true ) {}
00046 bool operator == ( const FontDef &other ) const {
00047 return ( family == other.family &&
00048 size == other.size &&
00049 italic == other.italic &&
00050 smallCaps == other.smallCaps &&
00051 weight == other.weight );
00052 }
00053
00054 QString family;
00055 short int size;
00056 bool italic : 1;
00057 bool smallCaps : 1;
00058 unsigned int weight : 8;
00059 mutable bool hasNbsp : 1;
00060 };
00061
00062
00063 class Font
00064 {
00065 friend class RenderStyle;
00066 friend class CSSStyleSelector;
00067
00068 public:
00069 Font() : fontDef(), f(), fm( f ), scFont( 0 ), letterSpacing( 0 ), wordSpacing( 0 ) {}
00070 Font( const FontDef &fd )
00071 : fontDef( fd ), f(), fm( f ), scFont( 0 ), letterSpacing( 0 ), wordSpacing( 0 )
00072 {}
00073
00074 bool operator == ( const Font &other ) const {
00075 return (fontDef == other.fontDef &&
00076 letterSpacing == other.letterSpacing &&
00077 wordSpacing == other.wordSpacing );
00078 }
00079
00080 void update( QPaintDeviceMetrics *devMetrics ) const;
00081
00082 void drawText( QPainter *p, int x, int y, QChar *str, int slen, int pos, int len, int width,
00083 QPainter::TextDirection d, int from=-1, int to=-1, QColor bg=QColor() ) const;
00084
00085 int width( QChar *str, int slen, int pos, int len ) const;
00086 int width( QChar *str, int slen, int pos ) const;
00087
00088 private:
00089 FontDef fontDef;
00090 mutable QFont f;
00091 mutable QFontMetrics fm;
00092 QFont *scFont;
00093 short letterSpacing;
00094 short wordSpacing;
00095 };
00096
00097 };
00098
00099
00100 #endif
This file is part of the documentation for kdelibs Version 3.1.0.