1 #ifndef __FC_ENGINE_H__
2 #define __FC_ENGINE_H__
5 * KFontInst - KDE Font Installer
7 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
27 #include <config-workspace.h>
29 #include <QtCore/QVector>
30 #include <QtCore/QRect>
31 #include <QtGui/QFont>
32 #include <QtGui/QColor>
34 #include <fontconfig/fontconfig.h>
35 #include "KfiConstants.h"
39 //Enable the following to use locale aware family name - if font supports this.
40 //#define KFI_USE_TRANSLATED_FAMILY_NAME
45 typedef struct _XftFont XftFont
;
46 typedef struct _XftDraw XftDraw
;
47 typedef struct _XftColor XftColor
;
52 class KDE_EXPORT CFcEngine
58 TRange(quint32 f
=0, quint32 t
=0) : from(f
), to(t
) { }
59 bool null() const { return 0==from
&& 0==to
; }
65 struct TChar
: public QRect
67 TChar(const QRect
&r
=QRect(), quint32 u
=0)
68 : QRect(r
), ucs4(u
) { }
73 static CFcEngine
* instance();
75 CFcEngine(bool init
=true);
78 void readConfig(KConfig
&cfg
);
79 void writeConfig(KConfig
&cfg
);
80 static void setDirty() { theirFcDirty
=true; }
81 bool drawPreview(const QString
&item
, QPixmap
&pix
, const QColor
&col
, int h
,
82 quint32 style
=KFI_NO_STYLE_INFO
, int face
=0);
83 bool draw(const KUrl
&url
, int w
, int h
, QPixmap
&pix
, int faceNo
, bool thumb
,
84 const QList
<TRange
> &range
=QList
<TRange
>(), QList
<TChar
> *chars
=NULL
,
85 const QString
&name
=QString(), quint32 style
=KFI_NO_STYLE_INFO
);
86 int getNumIndexes() { return itsIndexCount
; } // Only valid after draw has been called!
87 const QString
& getName(const KUrl
&url
, int faceNo
=0);
88 bool getInfo(const KUrl
&url
, int faceNo
, Misc::TFont
&info
);
89 static QFont
getQFont(const QString
&family
, quint32 style
, int size
);
90 const QVector
<int> & sizes() const { return itsSizes
; }
91 bool atMin() const { return 0==itsSizes
.size() || 0==itsAlphaSizeIndex
; }
92 bool atMax() const { return 0==itsSizes
.size() || itsSizes
.size()-1==itsAlphaSizeIndex
; }
93 void zoomIn() { if(!atMax()) itsAlphaSizeIndex
++; }
94 void zoomOut() { if(!atMin()) itsAlphaSizeIndex
--; }
95 int alphaSize() const { return itsSizes
[itsAlphaSizeIndex
]; }
96 quint32
styleVal() { return FC::createStyleVal(itsWeight
, itsWidth
, itsSlant
); }
98 const QString
& getPreviewString() { return itsPreviewString
; }
99 static QString
getDefaultPreviewString();
100 void setPreviewString(const QString
&str
)
101 { itsPreviewString
=str
.isEmpty() ? getDefaultPreviewString() : str
; }
102 static QString
getUppercaseLetters();
103 static QString
getLowercaseLetters();
104 static QString
getPunctuation();
106 static void setTextCol(const QColor
&col
) { theirTextCol
=col
; }
107 static const QColor
& textCol() { return theirTextCol
; }
109 static const int constScalableSizes
[];
110 static const int constDefaultAlphaSize
;
114 bool parseUrl(const KUrl
&url
, int faceNo
);
115 bool parseName(const QString
&name
, quint32 style
=KFI_NO_STYLE_INFO
, const KUrl
&url
=KUrl());
116 XftFont
* queryFont();
117 XftFont
* getFont(int size
);
118 bool isCorrect(XftFont
*f
, bool checkFamily
);
120 void drawLine(QPixmap
&pix
, int x
, int y
, int w
, int h
);
121 void drawName(QPixmap
&pix
, XftDraw
*xftDraw
, XftColor
*xftCol
, int x
, int &y
, int w
, int h
);
122 void addFontFile(const QString
&file
);
137 QVector
<int> itsSizes
;
140 QStringList itsAddedFiles
;
141 QString itsPreviewString
;
142 static bool theirFcDirty
;
143 static QColor theirTextCol
;