📄 qfont.cpp
字号:
return; for (int i=0; initTbl[i] != 0; i += 2) { QStringList &list = (*fontSubst)[QString::fromLatin1(initTbl[i])]; list.append(QString::fromLatin1(initTbl[i+1])); }}/*! Returns the first family name to be used whenever \a familyName is specified. The lookup is case insensitive. If there is no substitution for \a familyName, \a familyName is returned. To obtain a list of substitutions use substitutes(). \sa setFamily() insertSubstitutions() insertSubstitution() removeSubstitution()*/QString QFont::substitute(const QString &familyName){ initFontSubst(); QFontSubst *fontSubst = globalFontSubst(); Q_ASSERT(fontSubst != 0); QFontSubst::ConstIterator it = fontSubst->constFind(familyName.toLower()); if (it != fontSubst->constEnd() && !(*it).isEmpty()) return (*it).first(); return familyName;}/*! Returns a list of family names to be used whenever \a familyName is specified. The lookup is case insensitive. If there is no substitution for \a familyName, an empty list is returned. \sa substitute() insertSubstitutions() insertSubstitution() removeSubstitution() */QStringList QFont::substitutes(const QString &familyName){ initFontSubst(); QFontSubst *fontSubst = globalFontSubst(); Q_ASSERT(fontSubst != 0); return fontSubst->value(familyName.toLower(), QStringList());}/*! Inserts \a substituteName into the substitution table for the family \a familyName. \sa insertSubstitutions() removeSubstitution() substitutions() substitute() substitutes()*/void QFont::insertSubstitution(const QString &familyName, const QString &substituteName){ initFontSubst(); QFontSubst *fontSubst = globalFontSubst(); Q_ASSERT(fontSubst != 0); QStringList &list = (*fontSubst)[familyName.toLower()]; QString s = substituteName.toLower(); if (!list.contains(s)) list.append(s);}/*! Inserts the list of families \a substituteNames into the substitution list for \a familyName. \sa insertSubstitution(), removeSubstitution(), substitutions(), substitute()*/void QFont::insertSubstitutions(const QString &familyName, const QStringList &substituteNames){ initFontSubst(); QFontSubst *fontSubst = globalFontSubst(); Q_ASSERT(fontSubst != 0); QStringList &list = (*fontSubst)[familyName.toLower()]; QStringList::ConstIterator it = substituteNames.constBegin(); while (it != substituteNames.constEnd()) { QString s = (*it).toLower(); if (!list.contains(s)) list.append(s); it++; }}// ### mark: should be called removeSubstitutions()/*! Removes all the substitutions for \a familyName. \sa insertSubstitutions(), insertSubstitution(), substitutions(), substitute()*/void QFont::removeSubstitution(const QString &familyName){ // ### function name should be removeSubstitutions() or // ### removeSubstitutionList() initFontSubst(); QFontSubst *fontSubst = globalFontSubst(); Q_ASSERT(fontSubst != 0); fontSubst->remove(familyName.toLower());}/*! Returns a sorted list of substituted family names. \sa insertSubstitution(), removeSubstitution(), substitute()*/QStringList QFont::substitutions(){ initFontSubst(); QFontSubst *fontSubst = globalFontSubst(); Q_ASSERT(fontSubst != 0); QStringList ret; QFontSubst::ConstIterator it = fontSubst->constBegin(); while (it != fontSubst->constEnd()) { ret.append(it.key()); ++it; } ret.sort(); return ret;}/* \internal Internal function. Converts boolean font settings to an unsigned 8-bit number. Used for serialization etc.*/static quint8 get_font_bits(int version, const QFontPrivate *f){ Q_ASSERT(f != 0); quint8 bits = 0; if (f->request.style) bits |= 0x01; if (f->underline) bits |= 0x02; if (f->overline) bits |= 0x40; if (f->strikeOut) bits |= 0x04; if (f->request.fixedPitch) bits |= 0x08; // if (f.hintSetByUser) // bits |= 0x10; if (f->rawMode) bits |= 0x20; if (version >= QDataStream::Qt_4_0) { if (f->kerning) bits |= 0x10; } if (f->request.style == QFont::StyleOblique) bits |= 0x80; return bits;}#ifndef QT_NO_DATASTREAM/* \internal Internal function. Sets boolean font settings from an unsigned 8-bit number. Used for serialization etc.*/static void set_font_bits(int version, quint8 bits, QFontPrivate *f){ Q_ASSERT(f != 0); f->request.style = (bits & 0x01) != 0 ? QFont::StyleItalic : QFont::StyleNormal; f->underline = (bits & 0x02) != 0; f->overline = (bits & 0x40) != 0; f->strikeOut = (bits & 0x04) != 0; f->request.fixedPitch = (bits & 0x08) != 0; // f->hintSetByUser = (bits & 0x10) != 0; f->rawMode = (bits & 0x20) != 0; if (version >= QDataStream::Qt_4_0) f->kerning = (bits & 0x10) != 0; if ((bits & 0x80) != 0) f->request.style = QFont::StyleOblique;}#endif/*! Returns the font's key, a textual representation of a font. It is typically used as the key for a cache or dictionary of fonts. \sa QMap*/QString QFont::key() const{ return toString();}/*! Returns a description of the font. The description is a comma-separated list of the attributes, perfectly suited for use in QSettings. \sa fromString() */QString QFont::toString() const{ const QChar comma(QLatin1Char(',')); return family() + comma + QString::number( pointSizeF()) + comma + QString::number( pixelSize()) + comma + QString::number((int) styleHint()) + comma + QString::number( weight()) + comma + QString::number((int) style()) + comma + QString::number((int) underline()) + comma + QString::number((int) strikeOut()) + comma + QString::number((int)fixedPitch()) + comma + QString::number((int) rawMode());}/*! Sets this font to match the description \a descrip. The description is a comma-separated list of the font attributes, as returned by toString(). \sa toString() */bool QFont::fromString(const QString &descrip){ QStringList l(descrip.split(QLatin1Char(','))); int count = l.count(); if (!count || (count > 2 && count < 9) || count > 11) { qWarning("QFont::fromString: Invalid description '%s'", descrip.isEmpty() ? "(empty)" : descrip.toLatin1().data()); return false; } setFamily(l[0]); if (count > 1 && l[1].toDouble() > 0.0) setPointSizeF(l[1].toDouble()); if (count == 9) { setStyleHint((StyleHint) l[2].toInt()); setWeight(qMax(qMin(99, l[3].toInt()), 0)); setItalic(l[4].toInt()); setUnderline(l[5].toInt()); setStrikeOut(l[6].toInt()); setFixedPitch(l[7].toInt()); setRawMode(l[8].toInt()); } else if (count == 10) { if (l[2].toInt() > 0) setPixelSize(l[2].toInt()); setStyleHint((StyleHint) l[3].toInt()); setWeight(qMax(qMin(99, l[4].toInt()), 0)); setStyle((QFont::Style)l[5].toInt()); setUnderline(l[6].toInt()); setStrikeOut(l[7].toInt()); setFixedPitch(l[8].toInt()); setRawMode(l[9].toInt()); } return true;}#if !defined(Q_WS_QWS)/*! \internal Internal function that dumps font cache statistics.*/void QFont::cacheStatistics(){}#endif // !Q_WS_QWS/***************************************************************************** QFont stream functions *****************************************************************************/#ifndef QT_NO_DATASTREAM/*! \relates QFont Writes the font \a font to the data stream \a s. (toString() writes to a text stream.) \sa \link datastreamformat.html Format of the QDataStream operators \endlink*/QDataStream &operator<<(QDataStream &s, const QFont &font){ if (s.version() == 1) { s << font.d->request.family.toLatin1(); } else { s << font.d->request.family; } if (s.version() >= QDataStream::Qt_4_0) { // 4.0 double pointSize = font.d->request.pointSize; qint32 pixelSize = font.d->request.pixelSize; s << pointSize; s << pixelSize; } else if (s.version() <= 3) { qint16 pointSize = (qint16) (font.d->request.pointSize * 10); if (pointSize < 0) {#ifdef Q_WS_X11 pointSize = (qint16)(font.d->request.pixelSize*720/QX11Info::appDpiY());#else pointSize = (qint16)QFontInfo(font).pointSize() * 10;#endif } s << pointSize; } else { s << (qint16) (font.d->request.pointSize * 10); s << (qint16) font.d->request.pixelSize; } s << (quint8) font.d->request.styleHint; if (s.version() >= 5) s << (quint8) font.d->request.styleStrategy; s << (quint8) 0 << (quint8) font.d->request.weight << get_font_bits(s.version(), font.d); if (s.version() >= QDataStream::Qt_4_3) s << (quint16)font.d->request.stretch; return s;}/*! \relates QFont Reads the font \a font from the data stream \a s. (fromString() reads from a text stream.) \sa \link datastreamformat.html Format of the QDataStream operators \endlink*/QDataStream &operator>>(QDataStream &s, QFont &font){ if (!font.d->ref.deref()) delete font.d; font.d = new QFontPrivate; font.resolve_mask = QFontPrivate::Complete; quint8 styleHint, styleStrategy = QFont::PreferDefault, charSet, weight, bits; if (s.version() == 1) { QByteArray fam; s >> fam; font.d->request.family = QString::fromLatin1(fam); } else { s >> font.d->request.family; } if (s.version() >= QDataStream::Qt_4_0) { // 4.0 double pointSize; qint32 pixelSize; s >> pointSize; s >> pixelSize; font.d->request.pointSize = qreal(pointSize); font.d->request.pixelSize = pixelSize; } else { qint16 pointSize, pixelSize = -1; s >> pointSize; if (s.version() >= 4) s >> pixelSize; font.d->request.pointSize = qreal(pointSize / 10.); font.d->request.pixelSize = pixelSize; } s >> styleHint; if (s.version() >= 5) s >> styleStrategy; s >> charSet; s >> weight; s >> bits; font.d->request.styleHint = styleHint; font.d->request.styleStrategy = styleStrategy; font.d->request.weight = weight; set_font_bits(s.version(), bits, font.d); if (s.version() >= QDataStream::Qt_4_3) { quint16 stretch; s >> stretch; font.d->request.stretch = stretch; } return s;}#endif // QT_NO_DATASTREAM/***************************************************************************** QFontInfo member functions *****************************************************************************//*! \class QFontInfo \brief The QFontInfo class provides general information about fonts. \ingroup multimedia \ingroup shared \ingroup text The QFontInfo class provides the same access functions as QFont, e.g. family(), pointSize(), italic(), weight(), fixedPitch(), styleHint() etc. But whilst the QFont access functions return the values that were set, a QFontInfo object returns the values that apply to the font that will actually be used to draw the text. For example, when the program asks for a 25pt Courier font on a machine that has a non-scalable 24pt Courier font, QFont will (normally) use the 24pt Courier for rendering. In this case, QFont::pointSize() returns 25 and QFontInfo::pointSize() returns 24. There are three ways to create a QFontInfo object. \list 1 \o Calling the QFontInfo constructor with a QFont creates a font info object for a screen-compatible font, i.e. the font cannot be a printer font. If the font is changed later, the font info object is \e not updated. (Note: If you use a printer font the values returned may be inaccurate. Printer fonts are not always accessible so the nearest screen font is used if a printer font is supplied.) \o QWidget::fontInfo() returns the font info for a widget's font. This is equivalent to calling QFontInfo(widget->font()). If the widget's font is changed later, the font info object is \e not updated. \o QPainter::fontInfo() returns the font info for a painter's current font. If the painter's font is changed later, the font info object is \e not updated. \endlist \sa QFont QFontMetrics QFontDatabase*//*! Constructs a font info object for \a font. The font must be screen-compatible, i.e. a font you use when drawing text in \link QWidget widgets\endlink or \link QPixmap pixmaps\endlink, not QPicture or QPrinter. The font info object holds the information for the font that is passed in the constructor at the time it is created, and is not updated if the font's attributes are changed later. Use QPainter::fontInfo() to get the font info when painting. This will give correct results also when painting on paint device that is not screen-compatible.*/QFontInfo::QFontInfo(const QFont &font) : d(font.d){ d->ref.ref(); }/*! Constructs a copy of \a fi.*/QFontInfo::QFontInfo(const QFontInfo &fi) : d(fi.d){ d->ref.ref(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -