#ifndef KHTMLFONT_H
#define KHTMLFONT_H
#include <qfont.h>
#include <qfontmetrics.h>
#include <qpainter.h>
class QPaintDeviceMetrics;
namespace khtml
{
class RenderStyle;
class CSSStyleSelector;
class FontDef
{
public:
FontDef()
: specifiedSize(0), computedSize(0),
italic( false ), smallCaps( false ), isAbsoluteSize(false), weight( 50 ),
genericFamily(0), hasNbsp( true )
#if APPLE_CHANGES
, usePrinterFont( false )
#endif
{}
bool operator == ( const FontDef &other ) const {
return ( family == other.family &&
specifiedSize == other.specifiedSize &&
computedSize == other.computedSize &&
italic == other.italic &&
smallCaps == other.smallCaps &&
weight == other.weight &&
isAbsoluteSize == other.isAbsoluteSize
#if APPLE_CHANGES
&& usePrinterFont == other.usePrinterFont
#endif
);
}
enum GenericFamilyType { eNone, eStandard, eSerif, eSansSerif, eMonospace, eCursive, eFantasy };
void setGenericFamily(unsigned int aGenericFamily) { genericFamily = aGenericFamily; }
KWQFontFamily &firstFamily() { return family; }
KWQFontFamily family;
int computedPixelSize() const { return int(computedSize+0.5); }
float specifiedSize; float computedSize;
bool italic : 1;
bool smallCaps : 1;
bool isAbsoluteSize : 1; unsigned int weight : 8;
unsigned int genericFamily : 3;
mutable bool hasNbsp : 1;
#if APPLE_CHANGES
bool usePrinterFont : 1;
#endif
};
class Font
{
friend class RenderStyle;
friend class CSSStyleSelector;
public:
#if APPLE_CHANGES
Font() : letterSpacing(0), wordSpacing(0) {}
Font(const FontDef &fd, int l, int w) : fontDef(fd), letterSpacing(l), wordSpacing(w) {}
#else
Font() : fontDef(), f(), fm( f ), scFont( 0 ), letterSpacing( 0 ), wordSpacing( 0 ) {}
Font( const FontDef &fd, int l, int w )
: fontDef( fd ), f(), fm( f ), scFont( 0 ), letterSpacing( l ), wordSpacing( w )
{}
#endif
bool operator == ( const Font &other ) const {
return (fontDef == other.fontDef &&
letterSpacing == other.letterSpacing &&
wordSpacing == other.wordSpacing );
}
const FontDef& getFontDef() const { return fontDef; }
void update( QPaintDeviceMetrics *devMetrics ) const;
#if !APPLE_CHANGES
void drawText( QPainter *p, int x, int y, QChar *str, int slen, int pos, int len, int width,
QPainter::TextDirection d, int from=-1, int to=-1, QColor bg=QColor() ) const;
#else
void drawText( QPainter *p, int x, int y, QChar *str, int slen, int pos, int len, int width,
QPainter::TextDirection d, bool visuallyOrdered = false, int from=-1, int to=-1, QColor bg=QColor() ) const;
float floatWidth( QChar *str, int slen, int pos, int len ) const;
void floatCharacterWidths( QChar *str, int slen, int pos, int len, int toAdd, float *buffer) const;
bool isFixedPitch() const;
int checkSelectionPoint (QChar *s, int slen, int pos, int len, int toAdd, int x, bool reversed, bool includePartialGlyphs) const;
void drawHighlightForText( QPainter *p, int x, int y, int h,
QChar *str, int slen, int pos, int len, int width,
QPainter::TextDirection d, bool visuallyOrdered = false, int from=-1, int to=-1, QColor bg=QColor()) const;
#endif
int width( QChar *str, int slen, int pos, int len ) const;
int width( QChar *str, int slen, int pos ) const;
bool isSmallCaps() const { return fontDef.smallCaps; }
private:
FontDef fontDef;
mutable QFont f;
mutable QFontMetrics fm;
#if !APPLE_CHANGES
QFont *scFont;
#endif
short letterSpacing;
short wordSpacing;
};
};
#endif