Qt 4.8
Functions | Variables
qfontengine_x11.cpp File Reference
#include "qbitmap.h"
#include <qapplication.h>
#include <qbytearray.h>
#include <qdebug.h>
#include <qtextcodec.h>
#include <qthread.h>
#include "qfontdatabase.h"
#include "qpaintdevice.h"
#include "qpainter.h"
#include "qvarlengtharray.h"
#include "qwidget.h"
#include "qsettings.h"
#include "qfile.h"
#include <private/qpaintengine_x11_p.h>
#include "qfont.h"
#include "qfont_p.h"
#include "qfontengine_p.h"
#include <qhash.h>
#include <private/qpainter_p.h>
#include <private/qunicodetables_p.h>
#include <private/qt_x11_p.h>
#include <private/qpixmap_x11_p.h>
#include "qx11info_x11.h"
#include "qfontengine_x11_p.h"
#include <limits.h>
#include <ft2build.h>

Go to the source code of this file.

Functions

static XCharStruct * charStruct (XFontStruct *xfs, uint ch)
 
static QFontEngineengineForPattern (FcPattern *match, const QFontDef &request, int screen)
 
static QFontEngine::FaceId fontFile (const QByteArray &_xname, QFreetypeFace **freetype, int *synth)
 
static QStringList fontPath ()
 
static int maxIndex (XFontStruct *f)
 
int qt_mib_for_xlfd_encoding (const char *encoding)
 
Q_GUI_EXPORT void qt_x11ft_convert_pattern (FcPattern *pattern, QByteArray *file_name, int *index, bool *antialias)
 
int qt_xlfd_encoding_id (const char *encoding)
 

Variables

static QStringListqt_fontpath = 0
 

Function Documentation

◆ charStruct()

static XCharStruct* charStruct ( XFontStruct *  xfs,
uint  ch 
)
inlinestatic

Definition at line 303 of file qfontengine_x11.cpp.

Referenced by QFontEngineXLFD::boundingBox(), QFontEngineXLFD::canRender(), and QFontEngineXLFD::recalcAdvances().

304 {
305  XCharStruct *xcs = 0;
306  unsigned char r = ch>>8;
307  unsigned char c = ch&0xff;
308  if (xfs->per_char &&
309  r >= xfs->min_byte1 &&
310  r <= xfs->max_byte1 &&
311  c >= xfs->min_char_or_byte2 &&
312  c <= xfs->max_char_or_byte2) {
313  xcs = xfs->per_char + ((r - xfs->min_byte1) *
314  (xfs->max_char_or_byte2 -
315  xfs->min_char_or_byte2 + 1)) +
316  (c - xfs->min_char_or_byte2);
317  if (xcs->width == 0 && xcs->ascent == 0 && xcs->descent == 0)
318  xcs = 0;
319  }
320  return xcs;
321 }
unsigned char c[8]
Definition: qnumeric_p.h:62

◆ engineForPattern()

static QFontEngine* engineForPattern ( FcPattern *  match,
const QFontDef request,
int  screen 
)
static

Definition at line 864 of file qfontengine_x11.cpp.

Referenced by QFontEngineMultiFT::loadEngine().

865 {
866  QFontEngineX11FT *engine = new QFontEngineX11FT(match, request, screen);
867  if (!engine->invalid())
868  return engine;
869 
870  delete engine;
871  QFontEngine *fe = new QFontEngineBox(request.pixelSize);
872  fe->fontDef = request;
873  return fe;
874 }
static bool match(const uchar *found, const char *target, uint len)
qreal pixelSize
Definition: qfont_p.h:90
bool invalid() const
QFontDef fontDef

◆ fontFile()

static QFontEngine::FaceId fontFile ( const QByteArray _xname,
QFreetypeFace **  freetype,
int *  synth 
)
static

Definition at line 207 of file qfontengine_x11.cpp.

Referenced by QBasicUnixFontDatabase::addTTFile(), QFontEngineXLFD::faceId(), QFontconfigDatabase::populateFontDatabase(), and resolveGdi32().

208 {
209  *freetype = 0;
210  *synth = 0;
211 
212  QByteArray xname = _xname.toLower();
213 
214  int pos = 0;
215  int minus = 0;
216  while (minus < 5 && (pos = xname.indexOf('-', pos + 1)))
217  ++minus;
218  QByteArray searchname = xname.left(pos);
219  while (minus < 12 && (pos = xname.indexOf('-', pos + 1)))
220  ++minus;
221  QByteArray encoding = xname.mid(pos + 1);
222  //qDebug("xname='%s', searchname='%s', encoding='%s'", xname.data(), searchname.data(), encoding.data());
223  QStringList fontpath = fontPath();
224  QFontEngine::FaceId face_id;
225  face_id.index = 0;
226 
227  QByteArray best_mapping;
228 
229  for (QStringList::ConstIterator it = fontpath.constBegin(); it != fontpath.constEnd(); ++it) {
230  if (!(*it).startsWith(QLatin1Char('/')))
231  continue; // not a path name, a font server
232  QString fontmapname;
233  int num = 0;
234  // search font.dir and font.scale for the right file
235  while (num < 2) {
236  if (num == 0)
237  fontmapname = (*it) + QLatin1String("/fonts.scale");
238  else
239  fontmapname = (*it) + QLatin1String("/fonts.dir");
240  ++num;
241  //qWarning(fontmapname);
242  QFile fontmap(fontmapname);
243  if (!fontmap.open(QIODevice::ReadOnly))
244  continue;
245  while (!fontmap.atEnd()) {
246  QByteArray mapping = fontmap.readLine();
247  QByteArray lmapping = mapping.toLower();
248 
249  //qWarning(xfontname);
250  //qWarning(mapping);
251  if (!lmapping.contains(searchname))
252  continue;
253  int index = mapping.indexOf(' ');
254  QByteArray ffn = mapping.mid(0,index);
255  // remove bitmap formats freetype can't handle
256  if (ffn.contains(".spd") || ffn.contains(".phont"))
257  continue;
258  bool best_match = false;
259  if (!best_mapping.isEmpty()) {
260  if (lmapping.contains("-0-0-0-0-")) { // scalable font
261  best_match = true;
262  goto found;
263  }
264  if (lmapping.contains(encoding) && !best_mapping.toLower().contains(encoding))
265  goto found;
266  continue;
267  }
268 
269  found:
270  int colon = ffn.lastIndexOf(':');
271  if (colon != -1) {
272  QByteArray s = ffn.left(colon);
273  ffn = ffn.mid(colon + 1);
274  if (s.contains("ds="))
276  if (s.contains("ai="))
278  }
279  face_id.filename = (*it).toLocal8Bit() + '/' + ffn;
280  best_mapping = mapping;
281  if (best_match)
282  goto end;
283  }
284  }
285  }
286 end:
287 // qDebug("fontfile for %s is from '%s'\n got %s synth=%d", xname.data(),
288 // best_mapping.data(), face_id.filename.data(), *synth);
289  *freetype = QFreetypeFace::getFace(face_id);
290  if (!*freetype) {
291  face_id.index = 0;
292  face_id.filename = QByteArray();
293  }
294  return face_id;
295 }
static QFreetypeFace * getFace(const QFontEngine::FaceId &face_id, const QByteArray &fontData=QByteArray())
#define it(className, varName)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QStringList fontPath()
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
QByteArray toLower() const
Returns a lowercase copy of the byte array.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
int lastIndexOf(char c, int from=-1) const
Returns the index position of the last occurrence of character ch in the byte array, searching backward from index position from.
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
static QMap< QByteArray, int > mapping
Definition: qaxserver.cpp:577
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
quint16 index
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
static const KeyPair *const end
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QBool contains(char c) const
Returns true if the byte array contains the character ch; otherwise returns false.
Definition: qbytearray.h:525
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ fontPath()

static QStringList fontPath ( )
static

Definition at line 137 of file qfontengine_x11.cpp.

Referenced by fontFile().

138 {
139  if (qt_fontpath)
140  return *qt_fontpath;
141 
142  // append qsettings fontpath
143  QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
144  settings.beginGroup(QLatin1String("Qt"));
145 
146  QStringList fontpath;
147 
148  int npaths;
149  char** font_path;
150  font_path = XGetFontPath(X11->display, &npaths);
151  bool xfsconfig_read = false;
152  for (int i=0; i<npaths; i++) {
153  // If we're using xfs, append font paths from /etc/X11/fs/config
154  // can't hurt, and chances are we'll get all fonts that way.
155  if (((font_path[i])[0] != '/') && !xfsconfig_read) {
156  // We're using xfs -> read its config
157  bool finished = false;
158  QFile f(QLatin1String("/etc/X11/fs/config"));
159  if (!f.exists())
160  f.setFileName(QLatin1String("/usr/X11R6/lib/X11/fs/config"));
161  if (!f.exists())
162  f.setFileName(QLatin1String("/usr/X11/lib/X11/fs/config"));
163  if (f.exists()) {
164  f.open(QIODevice::ReadOnly);
165  while (f.error()==QFile::NoError && !finished) {
166  QString fs = QString::fromLocal8Bit(f.readLine(1024));
167  fs=fs.trimmed();
168  if (fs.left(9)==QLatin1String("catalogue") && fs.contains(QLatin1Char('='))) {
169  fs = fs.mid(fs.indexOf(QLatin1Char('=')) + 1).trimmed();
170  bool end = false;
171  while (f.error()==QFile::NoError && !end) {
172  if (fs[int(fs.length())-1] == QLatin1Char(','))
173  fs = fs.left(fs.length()-1);
174  else
175  end = true;
176 
177  fs = fs.left(fs.indexOf(QLatin1String(":unscaled")));
178  if (fs[0] != QLatin1Char('#'))
179  fontpath += fs;
180  fs = QLatin1String(f.readLine(1024));
181  fs = fs.trimmed();
182  if (fs.isEmpty())
183  end = true;
184  }
185  finished = true;
186  }
187  }
188  f.close();
189  }
190  xfsconfig_read = true;
191  } else {
192  QString fs = QString::fromLocal8Bit(font_path[i]);
193  fontpath += fs.left(fs.indexOf(QLatin1String(":unscaled")));
194  }
195  }
196  XFreeFontPath(font_path);
197 
198  // append qsettings fontpath
199  QStringList fp = settings.value(QLatin1String("fontPath")).toStringList();
200  if (!fp.isEmpty())
201  fontpath += fp;
202 
203  qt_fontpath = new QStringList(fontpath);
204  return fontpath;
205 }
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define X11
Definition: qt_x11_p.h:724
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
static QStringList * qt_fontpath
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
QString trimmed(QString source)
Definition: generator.cpp:233
static const KeyPair *const end
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ maxIndex()

static int maxIndex ( XFontStruct *  f)
inlinestatic

Definition at line 548 of file qfontengine_x11.cpp.

Referenced by QFontEngineXLFD::minLeftBearing(), and QFontEngineXLFD::minRightBearing().

548  {
549  return (((f->max_byte1 - f->min_byte1) *
550  (f->max_char_or_byte2 - f->min_char_or_byte2 + 1)) +
551  f->max_char_or_byte2 - f->min_char_or_byte2);
552 }

◆ qt_mib_for_xlfd_encoding()

int qt_mib_for_xlfd_encoding ( const char *  encoding)

Definition at line 394 of file qfontdatabase_x11.cpp.

Referenced by fontFile().

395 {
396  int id = qt_xlfd_encoding_id(encoding);
397  if (id != -1) return xlfd_encoding[id].mib;
398  return 0;
399 }
int qt_xlfd_encoding_id(const char *encoding)
static const XlfdEncoding xlfd_encoding[]

◆ qt_x11ft_convert_pattern()

Q_GUI_EXPORT void qt_x11ft_convert_pattern ( FcPattern *  pattern,
QByteArray file_name,
int *  index,
bool *  antialias 
)

Definition at line 958 of file qfontengine_x11.cpp.

Referenced by QFontEngineX11FT::QFontEngineX11FT().

959 {
960  FcChar8 *fileName;
961  FcPatternGetString(pattern, FC_FILE, 0, &fileName);
962  *file_name = (const char *)fileName;
963  if (!FcPatternGetInteger(pattern, FC_INDEX, 0, index))
964  index = 0;
965  FcBool b;
966  if (FcPatternGetBool(pattern, FC_ANTIALIAS, 0, &b) == FcResultMatch)
967  *antialias = b;
968 }
quint16 index
static QString fileName(const QString &fileUrl)

◆ qt_xlfd_encoding_id()

int qt_xlfd_encoding_id ( const char *  encoding)

Definition at line 350 of file qfontdatabase_x11.cpp.

Referenced by fontFile(), loadXlfds(), and qt_mib_for_xlfd_encoding().

351 {
352  // qDebug("looking for encoding id for '%s'", encoding);
353  int len = strlen(encoding);
354  if (len < 4)
355  return -1;
356  unsigned int hash1 = make_tag(encoding[0], encoding[1], encoding[2], encoding[3]);
357  const char *ch = encoding + len - 4;
358  unsigned int hash2 = make_tag(ch[0], ch[1], ch[2], ch[3]);
359 
360  const XlfdEncoding *enc = xlfd_encoding;
361  for (; enc->name; ++enc) {
362  if ((enc->hash1 && enc->hash1 != hash1) ||
363  (enc->hash2 && enc->hash2 != hash2))
364  continue;
365  // hashes match, do a compare if strings match
366  // the enc->name can contain '*'s we have to interpret correctly
367  const char *n = enc->name;
368  const char *e = encoding;
369  while (1) {
370  // qDebug("bol: *e='%c', *n='%c'", *e, *n);
371  if (*e == '\0') {
372  if (*n)
373  break;
374  // qDebug("found encoding id %d", enc->id);
375  return enc->id;
376  }
377  if (*e == *n) {
378  ++e;
379  ++n;
380  continue;
381  }
382  if (*n != '*')
383  break;
384  ++n;
385  // qDebug("skip: *e='%c', *n='%c'", *e, *n);
386  while (*e && *e != *n)
387  ++e;
388  }
389  }
390  // qDebug("couldn't find encoding %s", encoding);
391  return -1;
392 }
unsigned int hash1
const char * name
#define make_tag(c1, c2, c3, c4)
static const XlfdEncoding xlfd_encoding[]
unsigned int hash2

Variable Documentation

◆ qt_fontpath

QStringList* qt_fontpath = 0
static

Definition at line 135 of file qfontengine_x11.cpp.

Referenced by fontPath().