Qt 4.8
Macros | Typedefs | Functions | Variables
qfont.cpp File Reference
#include "qfont.h"
#include "qdebug.h"
#include "qpaintdevice.h"
#include "qfontdatabase.h"
#include "qfontmetrics.h"
#include "qfontinfo.h"
#include "qpainter.h"
#include "qhash.h"
#include "qdatastream.h"
#include "qapplication.h"
#include "qstringlist.h"
#include "qthread.h"
#include "qthreadstorage.h"
#include <private/qunicodetables_p.h>
#include "qfont_p.h"
#include <private/qfontengine_p.h>
#include <private/qpainter_p.h>
#include <private/qtextengine_p.h>
#include <limits.h>
#include "qx11info_x11.h"
#include <private/qt_x11_p.h>
#include "qscreen_qws.h"
#include <qfile.h>
#include "qfontengine_qpf_p.h"
#include <QMutexLocker>

Go to the source code of this file.

Macros

#define FC_DEBUG   if (false) qDebug
 
#define QT_FONT_ENGINE_FROM_DATA(data, script)   data->engine
 

Typedefs

typedef QHash< QString, QStringListQFontSubst
 

Functions

static quint8 get_extended_font_bits (const QFontPrivate *f)
 
static quint8 get_font_bits (int version, const QFontPrivate *f)
 
static void initFontSubst ()
 
QDebug operator<< (QDebug stream, const QFont &font)
 
Q_GUI_EXPORT int qt_defaultDpi ()
 
Q_GUI_EXPORT int qt_defaultDpiX ()
 
Q_GUI_EXPORT int qt_defaultDpiY ()
 
QMutexqt_fontdatabase_mutex ()
 
const QX11Infoqt_x11Info (const QPaintDevice *pd)
 
static void set_extended_font_bits (quint8 bits, QFontPrivate *f)
 
static void set_font_bits (int version, quint8 bits, QFontPrivate *f)
 
HDC shared_dc ()
 

Variables

static const int fast_timeout = 10000
 
bool qt_is_gui_used
 
static const int slow_timeout = 300000
 

Macro Definition Documentation

◆ FC_DEBUG

#define FC_DEBUG   if (false) qDebug

◆ QT_FONT_ENGINE_FROM_DATA

#define QT_FONT_ENGINE_FROM_DATA (   data,
  script 
)    data->engine

Definition at line 291 of file qfont.cpp.

Referenced by QFontPrivate::engineForScript().

Typedef Documentation

◆ QFontSubst

Definition at line 2064 of file qfont.cpp.

Function Documentation

◆ get_extended_font_bits()

static quint8 get_extended_font_bits ( const QFontPrivate f)
static

Definition at line 2284 of file qfont.cpp.

2285 {
2286  Q_ASSERT(f != 0);
2287  quint8 bits = 0;
2288  if (f->request.ignorePitch)
2289  bits |= 0x01;
2290  if (f->letterSpacingIsAbsolute)
2291  bits |= 0x02;
2292  return bits;
2293 }
bool letterSpacingIsAbsolute
Definition: qfont_p.h:193
unsigned char quint8
Definition: qglobal.h:934
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QFontDef request
Definition: qfont_p.h:178
uint ignorePitch
Definition: qfont_p.h:100

◆ get_font_bits()

static quint8 get_font_bits ( int  version,
const QFontPrivate f 
)
static

Definition at line 2257 of file qfont.cpp.

2258 {
2259  Q_ASSERT(f != 0);
2260  quint8 bits = 0;
2261  if (f->request.style)
2262  bits |= 0x01;
2263  if (f->underline)
2264  bits |= 0x02;
2265  if (f->overline)
2266  bits |= 0x40;
2267  if (f->strikeOut)
2268  bits |= 0x04;
2269  if (f->request.fixedPitch)
2270  bits |= 0x08;
2271  // if (f.hintSetByUser)
2272  // bits |= 0x10;
2273  if (f->rawMode)
2274  bits |= 0x20;
2275  if (version >= QDataStream::Qt_4_0) {
2276  if (f->kerning)
2277  bits |= 0x10;
2278  }
2279  if (f->request.style == QFont::StyleOblique)
2280  bits |= 0x80;
2281  return bits;
2282 }
uint fixedPitch
Definition: qfont_p.h:96
unsigned char quint8
Definition: qglobal.h:934
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
uint rawMode
Definition: qfont_p.h:187
uint overline
Definition: qfont_p.h:189
uint underline
Definition: qfont_p.h:188
QFontDef request
Definition: qfont_p.h:178
uint style
Definition: qfont_p.h:97
uint kerning
Definition: qfont_p.h:191
uint strikeOut
Definition: qfont_p.h:190

◆ initFontSubst()

static void initFontSubst ( )
static

Definition at line 2068 of file qfont.cpp.

Referenced by QFont::insertSubstitution(), QFont::insertSubstitutions(), QFont::removeSubstitution(), QFont::substitute(), QFont::substitutes(), and QFont::substitutions().

2069 {
2070  // default substitutions
2071  static const char * const initTbl[] = {
2072 
2073 #if defined(Q_WS_X11)
2074  "arial", "helvetica",
2075  "times new roman", "times",
2076  "courier new", "courier",
2077  "sans serif", "helvetica",
2078 #elif defined(Q_WS_MAC)
2079  ".lucida grande ui", "lucida grande",
2080 #elif defined(Q_WS_WIN)
2081  "times", "times new roman",
2082  "courier", "courier new",
2083  "helvetica", "arial",
2084  "sans serif", "arial",
2085 #endif
2086 
2087  0, 0
2088  };
2089 
2090  QFontSubst *fontSubst = globalFontSubst();
2091  Q_ASSERT(fontSubst != 0);
2092  if (!fontSubst->isEmpty())
2093  return;
2094 #if defined(Q_WS_X11) && !defined(QT_NO_FONTCONFIG)
2095  if (X11->has_fontconfig)
2096  return;
2097 #endif
2098 
2099  for (int i=0; initTbl[i] != 0; i += 2) {
2100  QStringList &list = (*fontSubst)[QString::fromLatin1(initTbl[i])];
2101  list.append(QString::fromLatin1(initTbl[i+1]));
2102  }
2103 }
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define X11
Definition: qt_x11_p.h:724
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ operator<<()

QDebug operator<< ( QDebug  stream,
const QFont font 
)

Definition at line 3367 of file qfont.cpp.

3368 {
3369  return stream << "QFont(" << font.toString() << ')';
3370 }
QString toString() const
Returns a description of the font.
Definition: qfont.cpp:2344

◆ qt_defaultDpi()

Q_GUI_EXPORT int qt_defaultDpi ( )

◆ qt_defaultDpiX()

Q_GUI_EXPORT int qt_defaultDpiX ( )

Definition at line 162 of file qfont.cpp.

Referenced by QPicture::exec(), QAlphaPaintEngine::flushAndInit(), QStaticTextPrivate::get(), QBlittablePixmapData::metric(), QRasterPixmapData::metric(), QPaintBuffer::metric(), QGLPixelBuffer::metric(), QPicture::metric(), QGLFramebufferObject::metric(), QGLPixmapData::metric(), QVGPixmapData::metric(), QMacQuartzPaintDevice::metric(), QPainterReplayer::process(), QFakeDevice::QFakeDevice(), and QPainterReplayer::setupTransform().

163 {
164  if (!qt_is_gui_used)
165  return 75;
166 
167  int dpi;
168 #ifdef Q_WS_X11
169  dpi = QX11Info::appDpiX();
170 #elif defined(Q_WS_WIN)
171  dpi = GetDeviceCaps(shared_dc(),LOGPIXELSX);
172 #elif defined(Q_WS_MAC)
173  extern float qt_mac_defaultDpi_x(); //qpaintdevice_mac.cpp
174  dpi = qt_mac_defaultDpi_x();
175 #elif defined(Q_WS_QWS)
176  if (!qt_screen)
177  return 72;
178  QScreen *screen = qt_screen;
179  const QList<QScreen*> subScreens = qt_screen->subScreens();
180  if (!subScreens.isEmpty())
181  screen = subScreens.at(0);
182  dpi = qRound(screen->width() / (screen->physicalWidth() / qreal(25.4)));
183 #elif defined(Q_WS_QPA)
184  QPlatformIntegration *pi = QApplicationPrivate::platformIntegration();
185  if (pi) {
186  QPlatformScreen *screen = QApplicationPrivate::platformIntegration()->screens().at(0);
187  const QSize screenSize = screen->geometry().size();
188  const QSize physicalSize = screen->physicalSize();
189  dpi = qRound(screenSize.width() / (physicalSize.width() / qreal(25.4)));
190  } else {
191  //PI has not been initialised, or it is being initialised. Give a default dpi
192  dpi = 100;
193  }
194 #elif defined(Q_OS_SYMBIAN)
195  dpi = S60->defaultDpiX;
196 #endif // Q_WS_X11
197 
198  return dpi;
199 }
Q_GUI_EXPORT QScreen * qt_screen
Definition: qscreen_qws.cpp:69
double qreal
Definition: qglobal.h:1193
The QPlatformScreen class provides an abstraction for visual displays.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
int width() const
Returns the logical width of the framebuffer in pixels.
Definition: qscreen_qws.h:227
int width() const
Returns the width.
Definition: qsize.h:126
static int appDpiX(int screen=-1)
Returns the horizontal resolution of the given screen in terms of the number of dots per inch...
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
virtual QRect geometry() const =0
Reimplement in subclass to return the pixel geometry of the screen.
virtual QSize physicalSize() const
Reimplement this function in subclass to return the physical size of the screen.
The QPlatformIntegration class is the entry for WindowSystem specific functionality.
float qt_mac_defaultDpi_x()
virtual QList< QScreen * > subScreens() const
Definition: qscreen_qws.h:283
The QScreen class is a base class for screen drivers in Qt for Embedded Linux.
Definition: qscreen_qws.h:191
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
HDC shared_dc()
bool qt_is_gui_used
int physicalWidth() const
Returns the physical width of the screen in millimeters.
Definition: qscreen_qws.h:290
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ qt_defaultDpiY()

Q_GUI_EXPORT int qt_defaultDpiY ( )

Definition at line 201 of file qfont.cpp.

Referenced by QTextEngine::calculateTabWidth(), QPaintBufferEngine::drawTextItem(), QPicture::exec(), QAlphaPaintEngine::flushAndInit(), QStaticTextPrivate::get(), QBlittablePixmapData::metric(), QRasterPixmapData::metric(), QPaintBuffer::metric(), QGLPixelBuffer::metric(), QPicture::metric(), QGLFramebufferObject::metric(), QGLPixmapData::metric(), QVGPixmapData::metric(), QMacQuartzPaintDevice::metric(), QFontDatabase::pointSizes(), QPainterReplayer::process(), QFakeDevice::QFakeDevice(), qt_defaultDpi(), qt_FcPatternToQFontDef(), QPainterReplayer::setupTransform(), QTextEngine::shapeText(), and QFontDatabase::smoothSizes().

202 {
203  if (!qt_is_gui_used)
204  return 75;
205 
206  int dpi;
207 #ifdef Q_WS_X11
208  dpi = QX11Info::appDpiY();
209 #elif defined(Q_WS_WIN)
210  dpi = GetDeviceCaps(shared_dc(),LOGPIXELSY);
211 #elif defined(Q_WS_MAC)
212  extern float qt_mac_defaultDpi_y(); //qpaintdevice_mac.cpp
213  dpi = qt_mac_defaultDpi_y();
214 #elif defined(Q_WS_QWS)
215  if (!qt_screen)
216  return 72;
217  QScreen *screen = qt_screen;
218  const QList<QScreen*> subScreens = qt_screen->subScreens();
219  if (!subScreens.isEmpty())
220  screen = subScreens.at(0);
221  dpi = qRound(screen->height() / (screen->physicalHeight() / qreal(25.4)));
222 #elif defined(Q_WS_QPA)
223  QPlatformIntegration *pi = QApplicationPrivate::platformIntegration();
224  if (pi) {
225  QPlatformScreen *screen = QApplicationPrivate::platformIntegration()->screens().at(0);
226  const QSize screenSize = screen->geometry().size();
227  const QSize physicalSize = screen->physicalSize();
228  dpi = qRound(screenSize.height() / (physicalSize.height() / qreal(25.4)));
229  } else {
230  //PI has not been initialised, or it is being initialised. Give a default dpi
231  dpi = 100;
232  }
233 #elif defined(Q_OS_SYMBIAN)
234  dpi = S60->defaultDpiY;
235 #endif // Q_WS_X11
236 
237  return dpi;
238 }
Q_GUI_EXPORT QScreen * qt_screen
Definition: qscreen_qws.cpp:69
int height() const
Returns the logical height of the framebuffer in pixels.
Definition: qscreen_qws.h:228
double qreal
Definition: qglobal.h:1193
int physicalHeight() const
Returns the physical height of the screen in millimeters.
Definition: qscreen_qws.h:291
The QPlatformScreen class provides an abstraction for visual displays.
float qt_mac_defaultDpi_y()
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
virtual QRect geometry() const =0
Reimplement in subclass to return the pixel geometry of the screen.
virtual QSize physicalSize() const
Reimplement this function in subclass to return the physical size of the screen.
The QPlatformIntegration class is the entry for WindowSystem specific functionality.
virtual QList< QScreen * > subScreens() const
Definition: qscreen_qws.h:283
int height() const
Returns the height.
Definition: qsize.h:129
The QScreen class is a base class for screen drivers in Qt for Embedded Linux.
Definition: qscreen_qws.h:191
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
HDC shared_dc()
bool qt_is_gui_used
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static int appDpiY(int screen=-1)
Returns the vertical resolution of the given screen in terms of the number of dots per inch...

◆ qt_fontdatabase_mutex()

QMutex* qt_fontdatabase_mutex ( )

◆ qt_x11Info()

const QX11Info* qt_x11Info ( const QPaintDevice pd)
related

Referenced by QFont::QFont().

◆ set_extended_font_bits()

static void set_extended_font_bits ( quint8  bits,
QFontPrivate f 
)
static

Definition at line 2317 of file qfont.cpp.

2318 {
2319  Q_ASSERT(f != 0);
2320  f->request.ignorePitch = (bits & 0x01) != 0;
2321  f->letterSpacingIsAbsolute = (bits & 0x02) != 0;
2322 }
bool letterSpacingIsAbsolute
Definition: qfont_p.h:193
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QFontDef request
Definition: qfont_p.h:178
uint ignorePitch
Definition: qfont_p.h:100

◆ set_font_bits()

static void set_font_bits ( int  version,
quint8  bits,
QFontPrivate f 
)
static

Definition at line 2301 of file qfont.cpp.

2302 {
2303  Q_ASSERT(f != 0);
2304  f->request.style = (bits & 0x01) != 0 ? QFont::StyleItalic : QFont::StyleNormal;
2305  f->underline = (bits & 0x02) != 0;
2306  f->overline = (bits & 0x40) != 0;
2307  f->strikeOut = (bits & 0x04) != 0;
2308  f->request.fixedPitch = (bits & 0x08) != 0;
2309  // f->hintSetByUser = (bits & 0x10) != 0;
2310  f->rawMode = (bits & 0x20) != 0;
2311  if (version >= QDataStream::Qt_4_0)
2312  f->kerning = (bits & 0x10) != 0;
2313  if ((bits & 0x80) != 0)
2315 }
uint fixedPitch
Definition: qfont_p.h:96
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
uint rawMode
Definition: qfont_p.h:187
uint overline
Definition: qfont_p.h:189
uint underline
Definition: qfont_p.h:188
QFontDef request
Definition: qfont_p.h:178
uint style
Definition: qfont_p.h:97
uint kerning
Definition: qfont_p.h:191
uint strikeOut
Definition: qfont_p.h:190

◆ shared_dc()

HDC shared_dc ( )

Definition at line 118 of file qfontengine_win.cpp.

Referenced by qt_defaultDpiX(), and qt_defaultDpiY().

119 {
120  QtHDC *&hdc = local_shared_dc()->localData();
121  if (!hdc)
122  hdc = new QtHDC;
123  return hdc->hdc();
124 }
HDC hdc() const

Variable Documentation

◆ fast_timeout

const int fast_timeout = 10000
static

◆ qt_is_gui_used

bool qt_is_gui_used

Definition at line 492 of file qapplication.cpp.

Referenced by QFontDef::exactMatch(), qt_defaultDpiX(), and qt_defaultDpiY().

◆ slow_timeout

const int slow_timeout = 300000
static

Definition at line 2900 of file qfont.cpp.

Referenced by QFontInfo::exactMatch(), and QFontCache::timerEvent().