00001
#ifndef _KOTEXTFORMAT_H
00002
#define _KOTEXTFORMAT_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
#undef S_NONE // Solaris defines it in sys/signal.h
00026
00027
#include <qcolor.h>
00028
#include <qfont.h>
00029
#include <qstring.h>
00030
#include <qdict.h>
00031
00032
class QFontMetrics;
00033
class KoCharStyle;
00034
class KoTextFormatCollection;
00035
class KoZoomHandler;
00036
class KoTextStringChar;
00037
class KoTextParag;
00038
00048 class KoTextFormat
00049 {
00050
friend class KoTextFormatCollection;
00051
00052
00053
00054
private:
00055
class KoTextFormatPrivate
00056 {
00057
public:
00058 KoTextFormatPrivate() : m_screenFont( 0L ), m_screenFontMetrics( 0L ),
00059 m_refFont( 0L ), m_refFontMetrics( 0L ),
00060 m_refAscent( -1 ), m_refDescent( -1 ), m_refHeight( -1 )
00061
00062 {
00063 memset( m_screenWidths, 0, 256 *
sizeof( ushort ) );
00064 m_charStyle = 0L;
00065 }
00066 ~KoTextFormatPrivate()
00067 {
00068 clearCache();
00069 }
00070
void clearCache();
00071
00072
QFont* m_screenFont;
00073
QFontMetrics* m_screenFontMetrics;
00074
QFont* m_refFont;
00075
QFontMetrics* m_refFontMetrics;
00076
int m_refAscent;
00077
int m_refDescent;
00078
int m_refHeight;
00079
int m_offsetFromBaseLine;
00080 ushort m_screenWidths[ 256 ];
00081
00082
double m_relativeTextSize;
00083
double m_underLineWidth;
00084 KoCharStyle *m_charStyle;
00085
00086
double m_shadowDistanceX;
00087
double m_shadowDistanceY;
00088
QColor m_shadowColor;
00089
bool m_bWordByWord;
00090
bool m_bHyphenation;
00091 };
00092
00093
public:
00094
enum Flags {
00095 NoFlags,
00096 Bold = 1,
00097 Italic = 2,
00098 Underline = 4,
00099 Family = 8,
00100 Size = 16,
00101 Color = 32,
00102 Misspelled = 64,
00103 VAlign = 128,
00104
00105 StrikeOut = 512,
00106 TextBackgroundColor = 1024,
00107 ExtendUnderLine = 2048,
00108 Language = 4096,
00109 ShadowText = 8192,
00110 OffsetFromBaseLine = 16384,
00111 WordByWord = 32768,
00112 Attribute = 65536,
00113 Hyphenation = 131072,
00114 UnderLineWidth = 262144,
00115
00116 Font = Bold | Italic | Underline | Family | Size,
00117
00118 Format = Font | Color | Misspelled | VAlign | StrikeOut | TextBackgroundColor |
00119 ExtendUnderLine | Language | ShadowText | OffsetFromBaseLine |
00120 WordByWord | Attribute | Hyphenation | UnderLineWidth
00121 };
00122
00123
enum VerticalAlignment { AlignNormal, AlignSubScript, AlignSuperScript };
00124
enum UnderlineType { U_NONE = 0, U_SIMPLE = 1, U_DOUBLE = 2, U_SIMPLE_BOLD = 3, U_WAVE = 4};
00125
enum StrikeOutType { S_NONE = 0, S_SIMPLE = 1, S_DOUBLE = 2, S_SIMPLE_BOLD = 3};
00126
enum UnderlineStyle { U_SOLID = 0 , U_DASH = 1, U_DOT = 2, U_DASH_DOT = 3, U_DASH_DOT_DOT = 4};
00127
enum StrikeOutStyle { S_SOLID = 0 , S_DASH = 1, S_DOT = 2, S_DASH_DOT = 3, S_DASH_DOT_DOT = 4};
00128
00129
enum AttributeStyle { ATT_NONE = 0, ATT_UPPER = 1, ATT_LOWER = 2 , ATT_SMALL_CAPS};
00130
00131
00132
KoTextFormat();
00133 ~
KoTextFormat();
00134
00136
00137
KoTextFormat(
const QFont &f,
const QColor &c,
const QString &_language,
00138
bool hyphenation,
double ulw, KoTextFormatCollection *parent = 0 );
00139
00141
KoTextFormat(
const QFont &_font,
00142 VerticalAlignment _valign,
00143
const QColor & _color,
00144
const QColor & _backGroundColor,
00145
const QColor & _underlineColor,
00146 KoTextFormat::UnderlineType _underlineType,
00147 KoTextFormat::UnderlineStyle _underlineStyle,
00148 KoTextFormat::StrikeOutType _strikeOutType,
00149 KoTextFormat::StrikeOutStyle _strikeOutStyle,
00150 KoTextFormat::AttributeStyle _fontAttribute,
00151
const QString &_language,
00152
double _relativeTextSize,
00153
int _offsetFromBaseLine,
00154
bool _wordByWord,
00155
bool _hyphenation,
00156
double _shadowDistanceX,
00157
double _shadowDistanceY,
00158
const QColor& shadowColor );
00159
00160
KoTextFormat(
const KoTextFormat &fm );
00161
00162
KoTextFormat& operator=(
const KoTextFormat &fm );
00163
void copyFormat(
const KoTextFormat &fm,
int flags );
00164
QColor color()
const;
00165
QFont font()
const;
00166
int pointSize()
const {
return font().
pointSize(); }
00167
bool isMisspelled()
const;
00168 VerticalAlignment vAlign()
const;
00169
00170
00176
int width(
const QChar &c )
const;
00177
int width(
const QString &str,
int pos )
const;
00178
int height()
const;
00179
int ascent()
const;
00180
int descent()
const;
00181
00182
int offsetX()
const;
00183
int offsetY()
const;
00184
00185
void setBold(
bool b );
00186
void setItalic(
bool b );
00187
void setUnderline(
bool b );
00188
void setFamily(
const QString &f );
00189
void setPointSize(
int s );
00190
void setFont(
const QFont &f );
00191
void setColor(
const QColor &c );
00192
void setMisspelled(
bool b );
00193
void setVAlign( VerticalAlignment a );
00194
00195
bool operator==(
const KoTextFormat &f )
const;
00196 KoTextFormatCollection *parent()
const;
00197
void setCollection( KoTextFormatCollection *parent ) { collection = parent; }
00198
QString key()
const;
00199
00200
static QString getKey(
const QFont &f,
const QColor &c,
bool misspelled, VerticalAlignment vAlign );
00201
00202
void addRef();
00203
void removeRef();
00204
00206
int compare(
const KoTextFormat & format )
const;
00207
00210
static QColor defaultTextColor(
QPainter * painter );
00211
00212
void setStrikeOutType (StrikeOutType _type);
00213 StrikeOutType strikeOutType()
const {
return m_strikeOutType;}
00214
00215
void setStrikeOutStyle( StrikeOutStyle _type );
00216 StrikeOutStyle strikeOutStyle()
const {
return m_strikeOutStyle;}
00217
00218
00219
void setTextBackgroundColor(
const QColor &);
00220
QColor textBackgroundColor()
const {
return m_textBackColor;}
00221
00222
void setTextUnderlineColor(
const QColor &);
00223
QColor textUnderlineColor()
const {
return m_textUnderlineColor;}
00224
00225
void setUnderlineType (UnderlineType _type);
00226 UnderlineType underlineType()
const {
return m_underlineType;}
00227
00228
void setUnderlineStyle (UnderlineStyle _type);
00229 UnderlineStyle underlineStyle()
const {
return m_underlineStyle;}
00230
00231
void setLanguage(
const QString & _lang);
00232
QString language()
const {
return m_language;}
00233
00234
void setHyphenation(
bool b );
00235
bool hyphenation()
const {
return d->m_bHyphenation; }
00236
00237
00238
00239
void setUnderLineWidth(
double ulw );
00240
double underLineWidth()
const {
return d->m_underLineWidth; }
00241
00242
00243
void setAttributeFont( KoTextFormat::AttributeStyle _att );
00244 KoTextFormat::AttributeStyle attributeFont()
const {
return m_attributeFont;}
00245
00246
00247
double shadowDistanceX()
const {
return d->m_shadowDistanceX; }
00248
double shadowDistanceY()
const {
return d->m_shadowDistanceY; }
00249
QColor shadowColor()
const;
00251
int shadowX(
KoZoomHandler *zh )
const;
00253
int shadowY(
KoZoomHandler *zh )
const;
00254
void setShadow(
double shadowDistanceX,
double shadowDistanceY,
const QColor& shadowColor );
00256
QString shadowAsCss()
const;
00257
static QString shadowAsCss(
double shadowDistanceX,
double shadowDistanceY,
const QColor& shadowColor );
00259
void parseShadowFromCss(
const QString& css );
00260
00261
double relativeTextSize()
const {
return d->m_relativeTextSize;}
00262
void setRelativeTextSize(
double _size );
00263
00264
00265
int offsetFromBaseLine()
const {
return d->m_offsetFromBaseLine;}
00266
void setOffsetFromBaseLine(
int _offset );
00267
00268
bool wordByWord()
const {
return d->m_bWordByWord;}
00269
void setWordByWord(
bool _b );
00270
00271
bool doubleUnderline()
const {
return (m_underlineType==U_DOUBLE ); }
00272
bool waveUnderline()
const {
return (m_underlineType==U_WAVE ); }
00273
bool underline()
const {
return (m_underlineType==U_SIMPLE ); }
00274
bool strikeOut()
const {
return (m_strikeOutType==S_SIMPLE ); }
00275
bool doubleStrikeOut()
const {
return (m_strikeOutType==S_DOUBLE ); }
00276
bool isStrikedOrUnderlined()
const {
return ((m_underlineType != U_NONE) ||(m_strikeOutType!=S_NONE));}
00277
00283
float refPointSize()
const;
00284
00289
float screenPointSize(
const KoZoomHandler* zh )
const;
00290
00296
const QFontMetrics&
refFontMetrics()
const;
00297
00303
const QFontMetrics&
screenFontMetrics(
const KoZoomHandler* zh )
const;
00304
00309
QFont refFont()
const;
00310
00316
QFont screenFont(
const KoZoomHandler* zh )
const;
00317
00318
QFont smallCapsFont(
const KoZoomHandler* zh,
bool applyZoom )
const;
00319
00325
int charWidth(
const KoZoomHandler* zh,
bool applyZoom,
const KoTextStringChar* c,
00326
const KoTextParag* parag,
int i )
const;
00327
00332
int charWidthLU(
const KoTextStringChar* c,
00333
const KoTextParag* parag,
int i )
const;
00334
00335
void applyCharStyle( KoCharStyle *_style );
00336 KoCharStyle *style()
const;
00337
static QString underlineStyleToString( UnderlineStyle _lineType );
00338
static QString strikeOutStyleToString( StrikeOutStyle _lineType );
00339
static UnderlineStyle stringToUnderlineStyle(
const QString & _str );
00340
static StrikeOutStyle stringToStrikeOutStyle(
const QString & _str );
00341
00342
static QString attributeFontToString( KoTextFormat::AttributeStyle _attr );
00343
static AttributeStyle stringToAttributeFont(
const QString & _str );
00344
00345
QString displayedString(
const QString& c )
const;
00346
static QStringList underlineTypeList();
00347
static QStringList strikeOutTypeList();
00348
static QStringList fontAttributeList();
00349
static QStringList underlineStyleList();
00350
static QStringList strikeOutStyleList();
00351
00352
#ifndef NDEBUG
00353
void printDebug();
00354
#endif
00355
00356
protected:
00357
QChar displayedChar(
QChar c )
const;
00358
void generateKey();
00359
00360
private:
00361
void update();
00362
00363
QColor m_textBackColor;
00364
QColor m_textUnderlineColor;
00365 UnderlineType m_underlineType;
00366 StrikeOutType m_strikeOutType;
00367 UnderlineStyle m_underlineStyle;
00368 StrikeOutStyle m_strikeOutStyle;
00369
QString m_language;
00370 AttributeStyle m_attributeFont;
00371
class KoTextFormatPrivate;
00372 KoTextFormatPrivate *d;
00373
00374
QFont fn;
00375
QColor col;
00376 uint missp : 1;
00377
00378 VerticalAlignment va;
00379 KoTextFormatCollection *collection;
00380
int ref;
00381
QString k;
00382 };
00383
00384
#if defined(Q_TEMPLATEDLL)
00385
00386
template class Q_EXPORT
QDict<KoTextFormat>;
00387
00388
#endif
00389
00390
class Q_EXPORT KoTextFormatCollection
00391 {
00392
friend class KoTextDocument;
00393
friend class KoTextFormat;
00394
00395
public:
00396 KoTextFormatCollection();
00397 KoTextFormatCollection(
const QFont& defaultFont,
const QColor& defaultColor,
const QString & defaultLanguage,
bool hyphen,
double ulw );
00398
virtual ~KoTextFormatCollection();
00399
00400
void setDefaultFormat(
KoTextFormat *f );
00401
KoTextFormat *defaultFormat() const;
00402 virtual
KoTextFormat *format( const
KoTextFormat *f );
00403 virtual
KoTextFormat *format( const
KoTextFormat *of, const
KoTextFormat *nf,
int flags );
00404 virtual
KoTextFormat *format( const
QFont &f, const
QColor &c , const
QString &_language,
bool hyphen,
double ulw );
00405 virtual
void remove(
KoTextFormat *f );
00406 virtual
KoTextFormat *createFormat( const
KoTextFormat &f ) {
return new KoTextFormat( f ); }
00407
virtual KoTextFormat *createFormat(
const QFont &f,
const QColor &c,
const QString & _language,
bool hyphen,
double ulw) {
return new KoTextFormat( f, c, _language, hyphen, ulw,
this ); }
00408
void debug();
00409
00410
00411
00412
00413
00414
00415
00416
00417 QDict<KoTextFormat> & dict() {
return cKey; }
00418
00419
private:
00420
KoTextFormat *defFormat, *lastFormat, *cachedFormat;
00421 QDict<KoTextFormat> cKey;
00422
KoTextFormat *cres;
00423
QFont cfont;
00424
QColor ccol;
00425
QString kof, knf;
00426
int cflags;
00427
00428 };
00429
00430
inline QColor KoTextFormat::color()
const
00431
{
00432
return col;
00433 }
00434
00435
inline QFont KoTextFormat::font()
const
00436
{
00437
return fn;
00438 }
00439
00440
inline bool KoTextFormat::isMisspelled()
const
00441
{
00442
return missp;
00443 }
00444
00445
inline KoTextFormat::VerticalAlignment KoTextFormat::vAlign()
const
00446
{
00447
return va;
00448 }
00449
00450
inline bool KoTextFormat::operator==(
const KoTextFormat &f )
const
00451
{
00452
return k == f.
k;
00453 }
00454
00455
inline KoTextFormatCollection *KoTextFormat::parent()
const
00456
{
00457
return collection;
00458 }
00459
00460
inline QString KoTextFormat::key()
const
00461
{
00462
return k;
00463 }
00464
00465
00466
00467
00468
00469
00470
inline void KoTextFormatCollection::setDefaultFormat(
KoTextFormat *f )
00471 {
00472 defFormat = f;
00473 }
00474
00475
inline KoTextFormat *KoTextFormatCollection::defaultFormat()
const
00476
{
00477
return defFormat;
00478 }
00479
00480
#endif