Qt 4.8
Public Functions | Static Public Functions | List of all members
QBasicUnixFontDatabase Class Reference

#include <qbasicunixfontdatabase.h>

Inheritance diagram for QBasicUnixFontDatabase:
QPlatformFontDatabase QFontconfigDatabase

Public Functions

QStringList addApplicationFont (const QByteArray &fontData, const QString &fileName)
 Adds an application font described by the font contained supplied fontData or using the font contained in the file referenced by fileName. More...
 
QStringList fallbacksForFamily (const QString family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script) const
 Returns a list of alternative fonts for the specified family and style and script using the styleHint given. More...
 
QFontEnginefontEngine (const QFontDef &fontDef, QUnicodeTables::Script script, void *handle)
 Returns the font engine that can be used to render the font described by the font definition, fontDef, in the specified script. More...
 
void populateFontDatabase ()
 This function is called once at startup by Qts internal fontdatabase. More...
 
void releaseHandle (void *handle)
 Releases the font handle and deletes any associated data loaded from a file. More...
 
- Public Functions inherited from QPlatformFontDatabase
virtual QString fontDir () const
 Returns the path to the font directory. More...
 
virtual QFontEnginefontEngine (const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference)
 

Static Public Functions

static QStringList addTTFile (const QByteArray &fontData, const QByteArray &file)
 
- Static Public Functions inherited from QPlatformFontDatabase
static void registerFont (const QString &familyname, const QString &foundryname, QFont::Weight weight, QFont::Style style, QFont::Stretch stretch, bool antialiased, bool scalable, int pixelSize, const QSupportedWritingSystems &writingSystems, void *handle)
 Registers a font with the given set of attributes describing the font's foundry, family name, style and stretch information, pixel size, and supported writing systems. More...
 
static void registerQPF2Font (const QByteArray &dataArray, void *handle)
 Registers the pre-rendered QPF2 font contained in the given dataArray. More...
 

Detailed Description

Definition at line 55 of file qbasicunixfontdatabase.h.

Functions

◆ addApplicationFont()

QStringList QBasicUnixFontDatabase::addApplicationFont ( const QByteArray fontData,
const QString fileName 
)
virtual

Adds an application font described by the font contained supplied fontData or using the font contained in the file referenced by fileName.

Returns a list of family names, or an empty list if the font could not be added.

Note
The default implementation of this function does not add an application font. Subclasses should reimplement this function to perform the necessary loading and registration of fonts.

Reimplemented from QPlatformFontDatabase.

Definition at line 249 of file qbasicunixfontdatabase.cpp.

250 {
251  return addTTFile(fontData,fileName.toLocal8Bit());
252 }
static QStringList addTTFile(const QByteArray &fontData, const QByteArray &file)
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049

◆ addTTFile()

QStringList QBasicUnixFontDatabase::addTTFile ( const QByteArray fontData,
const QByteArray file 
)
static

Definition at line 260 of file qbasicunixfontdatabase.cpp.

Referenced by addApplicationFont(), and populateFontDatabase().

261 {
262  extern FT_Library qt_getFreetype();
263  FT_Library library = qt_getFreetype();
264 
265  int index = 0;
266  int numFaces = 0;
267  QStringList families;
268  do {
269  FT_Face face;
270  FT_Error error;
271  if (!fontData.isEmpty()) {
272  error = FT_New_Memory_Face(library, (const FT_Byte *)fontData.constData(), fontData.size(), index, &face);
273  } else {
274  error = FT_New_Face(library, file.constData(), index, &face);
275  }
276  if (error != FT_Err_Ok) {
277  qDebug() << "FT_New_Face failed with index" << index << ":" << hex << error;
278  break;
279  }
280  numFaces = face->num_faces;
281 
282  QFont::Weight weight = QFont::Normal;
283 
285  if (face->style_flags & FT_STYLE_FLAG_ITALIC)
286  style = QFont::StyleItalic;
287 
288  if (face->style_flags & FT_STYLE_FLAG_BOLD)
289  weight = QFont::Bold;
290 
291  QSupportedWritingSystems writingSystems;
292  // detect symbol fonts
293  for (int i = 0; i < face->num_charmaps; ++i) {
294  FT_CharMap cm = face->charmaps[i];
295  if (cm->encoding == ft_encoding_adobe_custom
296  || cm->encoding == ft_encoding_symbol) {
297  writingSystems.setSupported(QFontDatabase::Symbol);
298  break;
299  }
300  }
301 
302  TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2);
303  if (os2) {
304  quint32 unicodeRange[4] = {
305  quint32(os2->ulUnicodeRange1), quint32(os2->ulUnicodeRange2),
306  quint32(os2->ulUnicodeRange3), quint32(os2->ulUnicodeRange4)
307  };
308  quint32 codePageRange[2] = {
309  quint32(os2->ulCodePageRange1), quint32(os2->ulCodePageRange2)
310  };
311 
312  writingSystems = determineWritingSystemsFromTrueTypeBits(unicodeRange, codePageRange);
313  }
314 
315  QString family = QString::fromAscii(face->family_name);
316  FontFile *fontFile = new FontFile;
317  fontFile->fileName = file;
318  fontFile->indexValue = index;
319 
321 
322  registerFont(family,"",weight,style,stretch,true,true,0,writingSystems,fontFile);
323 
324  families.append(family);
325 
326  FT_Done_Face(face);
327  ++index;
328  } while (index < numFaces);
329  return families;
330 }
void setSupported(QFontDatabase::WritingSystem, bool supported=true)
Sets the supported state of the writing system given by writingSystem to the value specified by suppo...
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
#define error(msg)
Weight
Qt uses a weighting scale from 0 to 99 similar to, but not the same as, the scales used in Windows or...
Definition: qfont.h:103
The QString class provides a Unicode character string.
Definition: qstring.h:83
Stretch
Predefined stretch values that follow the CSS naming convention.
Definition: qfont.h:117
Q_CORE_EXPORT QTextStream & hex(QTextStream &s)
Q_CORE_EXPORT void qDebug(const char *,...)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
struct FT_FaceRec_ * FT_Face
Definition: qfont.h:50
static QFontEngine::FaceId fontFile(const QByteArray &_xname, QFreetypeFace **freetype, int *synth)
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QSupportedWritingSystems class is used when registering fonts with the internal Qt fontdatabase...
Style
This enum describes the different styles of glyphs that are used to display text. ...
Definition: qfont.h:111
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static void registerFont(const QString &familyname, const QString &foundryname, QFont::Weight weight, QFont::Style style, QFont::Stretch stretch, bool antialiased, bool scalable, int pixelSize, const QSupportedWritingSystems &writingSystems, void *handle)
Registers a font with the given set of attributes describing the font&#39;s foundry, family name...
unsigned int quint32
Definition: qglobal.h:938
static QSupportedWritingSystems determineWritingSystemsFromTrueTypeBits(quint32 unicodeRange[4], quint32 codePageRange[2])
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
quint16 index
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
FT_Library qt_getFreetype()

◆ fallbacksForFamily()

QStringList QBasicUnixFontDatabase::fallbacksForFamily ( const QString  family,
const QFont::Style style,
const QFont::StyleHint styleHint,
const QUnicodeTables::Script script 
) const
virtual

Returns a list of alternative fonts for the specified family and style and script using the styleHint given.

Reimplemented from QPlatformFontDatabase.

Reimplemented in QFontconfigDatabase.

Definition at line 240 of file qbasicunixfontdatabase.cpp.

241 {
242  Q_UNUSED(family);
243  Q_UNUSED(style);
245  Q_UNUSED(script);
246  return QStringList();
247 }
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
const char * styleHint(const QFontDef &request)
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ fontEngine()

QFontEngine * QBasicUnixFontDatabase::fontEngine ( const QFontDef fontDef,
QUnicodeTables::Script  script,
void *  handle 
)
virtual

Returns the font engine that can be used to render the font described by the font definition, fontDef, in the specified script.

Reimplemented from QPlatformFontDatabase.

Reimplemented in QFontconfigDatabase.

Definition at line 210 of file qbasicunixfontdatabase.cpp.

211 {
212  QFontEngineFT *engine;
213  FontFile *fontfile = static_cast<FontFile *> (usrPtr);
215  fid.filename = fontfile->fileName.toLocal8Bit();
216  fid.index = fontfile->indexValue;
217  engine = new QFontEngineFT(fontDef);
218 
219  bool antialias = !(fontDef.styleStrategy & QFont::NoAntialias);
221  if (!engine->init(fid,antialias,format)) {
222  delete engine;
223  engine = 0;
224  return engine;
225  }
226  if (engine->invalid()) {
227  delete engine;
228  engine = 0;
229  } else if (scriptRequiresOpenType(script)) {
230  HB_Face hbFace = engine->harfbuzzFace();
231  if (!hbFace || !hbFace->supported_scripts[script]) {
232  delete engine;
233  engine = 0;
234  }
235  }
236 
237  return engine;
238 }
bool init(FaceId faceId, bool antiaalias, GlyphFormat defaultFormat=Format_None, const QByteArray &fontData=QByteArray())
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
bool invalid() const
static bool scriptRequiresOpenType(int script)
uint styleStrategy
Definition: qfont_p.h:92
HB_Face harfbuzzFace() const

◆ populateFontDatabase()

void QBasicUnixFontDatabase::populateFontDatabase ( )
virtual

This function is called once at startup by Qts internal fontdatabase.

Reimplement this function in a subclass for a convenient place to initialise the internal fontdatabase.

The default implementation looks in the fontDir() location and registers all qpf2 fonts.

Reimplemented from QPlatformFontDatabase.

Reimplemented in QFontconfigDatabase.

Definition at line 188 of file qbasicunixfontdatabase.cpp.

189 {
191  QString fontpath = fontDir();
192 
193  if(!QFile::exists(fontpath)) {
194  qFatal("QFontDatabase: Cannot find font directory %s - is Qt installed correctly?",
195  qPrintable(fontpath));
196  }
197 
198  QDir dir(fontpath);
199  dir.setNameFilters(QStringList() << QLatin1String("*.ttf")
200  << QLatin1String("*.ttc") << QLatin1String("*.pfa")
201  << QLatin1String("*.pfb"));
202  dir.refresh();
203  for (int i = 0; i < int(dir.count()); ++i) {
204  const QByteArray file = QFile::encodeName(dir.absoluteFilePath(dir[i]));
205 // qDebug() << "looking at" << file;
206  addTTFile(QByteArray(), file);
207  }
208 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
static QStringList addTTFile(const QByteArray &fontData, const QByteArray &file)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
Definition: qfile.cpp:626
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
virtual QString fontDir() const
Returns the path to the font directory.
Q_CORE_EXPORT void qFatal(const char *,...)
virtual void populateFontDatabase()
This function is called once at startup by Qts internal fontdatabase.
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user&#39;s loca...
Definition: qfile.cpp:528
#define qPrintable(string)
Definition: qglobal.h:1750

◆ releaseHandle()

void QBasicUnixFontDatabase::releaseHandle ( void *  handle)
virtual

Releases the font handle and deletes any associated data loaded from a file.

Reimplemented from QPlatformFontDatabase.

Definition at line 254 of file qbasicunixfontdatabase.cpp.

255 {
256  FontFile *file = static_cast<FontFile *>(handle);
257  delete file;
258 }

The documentation for this class was generated from the following files: