⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qfontmetrics.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    Returns the distance from the base line to where an overline    should be drawn.    \sa underlinePos(), strikeOutPos(), lineWidth()*/int QFontMetrics::overlinePos() const{    return ascent() + 1;}/*!    Returns the distance from the base line to where the strikeout    line should be drawn.    \sa underlinePos(), overlinePos(), lineWidth()*/int QFontMetrics::strikeOutPos() const{    int pos = ascent() / 3;    return pos > 0 ? pos : 1;}/*!    Returns the width of the underline and strikeout lines, adjusted    for the point size of the font.    \sa underlinePos(), overlinePos(), strikeOutPos()*/int QFontMetrics::lineWidth() const{    QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);    Q_ASSERT(engine != 0);    return qRound(engine->lineThickness());}/*****************************************************************************  QFontMetricsF member functions *****************************************************************************//*!    \class QFontMetricsF qfontmetrics.h    \brief The QFontMetricsF class provides font metrics information.    \ingroup multimedia    \ingroup shared    \ingroup text    QFontMetricsF functions calculate the size of characters and    strings for a given font. You can construct a QFontMetricsF object    with an existing QFont to obtain metrics for that font. If the    font is changed later, the font metrics object is \e not updated.    Once created, the object provides functions to access the    individual metrics of the font, its characters, and for strings    rendered in the font.    There are several functions that operate on the font: ascent(),    descent(), height(), leading() and lineSpacing() return the basic    size properties of the font. The underlinePos(), overlinePos(),    strikeOutPos() and lineWidth() functions, return the properties of    the line that underlines, overlines or strikes out the    characters. These functions are all fast.    There are also some functions that operate on the set of glyphs in    the font: minLeftBearing(), minRightBearing() and maxWidth().    These are by necessity slow, and we recommend avoiding them if    possible.    For each character, you can get its width(), leftBearing() and    rightBearing() and find out whether it is in the font using    inFont(). You can also treat the character as a string, and use    the string functions on it.    The string functions include width(), to return the width of a    string in pixels (or points, for a printer), boundingRect(), to    return a rectangle large enough to contain the rendered string,    and size(), to return the size of that rectangle.    Example:    \code    QFont font("times", 24);    QFontMetricsF fm(font);    qreal pixelsWide = fm.width("What's the width of this text?");    qreal pixelsHigh = fm.height();    \endcode    \sa QFont QFontInfo QFontDatabase*//*!    \since 4.2    Constructs a font metrics object with floating point precision    from the given \a fontMetrics object.*/QFontMetricsF::QFontMetricsF(const QFontMetrics &fontMetrics)    : d(fontMetrics.d){    d->ref.ref();}/*!    \since 4.2    Assigns \a other to this object.*/QFontMetricsF &QFontMetricsF::operator=(const QFontMetrics &other){    qAtomicAssign(d, other.d);    return *this;}/*!    Constructs a font metrics object for \a font.    The font metrics will be compatible with the paintdevice used to    create \a font.    The font metrics 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 QFontMetricsF(const QFont &, QPaintDevice *) to get the font    metrics that are compatible with a certain paint device.*/QFontMetricsF::QFontMetricsF(const QFont &font)    : d(font.d){    d->ref.ref();}/*!    Constructs a font metrics object for \a font and \a paintdevice.    The font metrics will be compatible with the paintdevice passed.    If the \a paintdevice is 0, the metrics will be screen-compatible,    ie. the metrics you get if you use the font for drawing text on a    \link QWidget widgets\endlink or \link QPixmap pixmaps\endlink,    not on a QPicture or QPrinter.    The font metrics 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.*/QFontMetricsF::QFontMetricsF(const QFont &font, QPaintDevice *paintdevice){    int dpi = paintdevice ? paintdevice->logicalDpiY() : qt_defaultDpi();#ifdef Q_WS_X11    const QX11Info *info = qt_x11Info(paintdevice);    int screen = info ? info->screen() : 0;#else    const int screen = 0;#endif    if (font.d->dpi != dpi || font.d->screen != screen ) {        d = new QFontPrivate(*font.d);        d->dpi = dpi;        d->screen = screen;    } else {        d = font.d;        d->ref.ref();    }}/*!    Constructs a copy of \a fm.*/QFontMetricsF::QFontMetricsF(const QFontMetricsF &fm)    : d(fm.d){ d->ref.ref(); }/*!    Destroys the font metrics object and frees all allocated    resources.*/QFontMetricsF::~QFontMetricsF(){    if (!d->ref.deref())        delete d;}/*!    Assigns the font metrics \a fm to this font metrics object.*/QFontMetricsF &QFontMetricsF::operator=(const QFontMetricsF &fm){    qAtomicAssign(d, fm.d);    return *this;}/*!  \overload  Returns true if the font metrics are equal to the \a other font  metrics; otherwise returns false.  Two font metrics are considered equal if they were constructed from the  same QFont and the paint devices they were constructed for are  considered to be compatible.*/bool QFontMetricsF::operator ==(const QFontMetricsF &other) const{    return d == other.d;}/*!  Returns true if the font metrics are equal to the \a other font  metrics; otherwise returns false.  Two font metrics are considered equal if they were constructed from the  same QFont and the paint devices they were constructed for are  considered to be compatible.*/bool QFontMetricsF::operator ==(const QFontMetricsF &other){    return d == other.d;}/*!    \fn bool QFontMetricsF::operator!=(const QFontMetricsF &other)    Returns true if the font metrics are not equal to the \a other font    metrics; otherwise returns false.    \sa operator==()*//*!    \fn bool QFontMetricsF::operator !=(const QFontMetricsF &other) const    \overload    Returns true if the font metrics are not equal to the \a other font    metrics; otherwise returns false.    \sa operator==()*//*!    Returns the ascent of the font.    The ascent of a font is the distance from the baseline to the    highest position characters extend to. In practice, some font    designers break this rule, e.g. when they put more than one accent    on top of a character, or to accommodate an unusual character in    an exotic language, so it is possible (though rare) that this    value will be too small.    \sa descent()*/qreal QFontMetricsF::ascent() const{    QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);    Q_ASSERT(engine != 0);    return engine->ascent().toReal();}/*!    Returns the descent of the font.    The descent is the distance from the base line to the lowest point    characters extend to. (Note that this is different from X, which    adds 1 pixel.) In practice, some font designers break this rule,    e.g. to accommodate an unusual character in an exotic language, so    it is possible (though rare) that this value will be too small.    \sa ascent()*/qreal QFontMetricsF::descent() const{    QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);    Q_ASSERT(engine != 0);    return engine->descent().toReal();}/*!    Returns the height of the font.    This is always equal to ascent()+descent()+1 (the 1 is for the    base line).    \sa leading(), lineSpacing()*/qreal QFontMetricsF::height() const{    QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);    Q_ASSERT(engine != 0);    return (engine->ascent() + engine->descent() + 1).toReal();}/*!    Returns the leading of the font.    This is the natural inter-line spacing.    \sa height(), lineSpacing()*/qreal QFontMetricsF::leading() const{    QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);    Q_ASSERT(engine != 0);    return engine->leading().toReal();}/*!    Returns the distance from one base line to the next.    This value is always equal to leading()+height().    \sa height(), leading()*/qreal QFontMetricsF::lineSpacing() const{    QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);    Q_ASSERT(engine != 0);    return (engine->leading() + engine->ascent() + engine->descent() + 1).toReal();}/*!    Returns the minimum left bearing of the font.    This is the smallest leftBearing(char) of all characters in the    font.    Note that this function can be very slow if the font is large.    \sa minRightBearing(), leftBearing()*/qreal QFontMetricsF::minLeftBearing() const{    QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);    Q_ASSERT(engine != 0);    return engine->minLeftBearing();}/*!    Returns the minimum right bearing of the font.    This is the smallest rightBearing(char) of all characters in the    font.    Note that this function can be very slow if the font is large.    \sa minLeftBearing(), rightBearing()*/qreal QFontMetricsF::minRightBearing() const{    QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);    Q_ASSERT(engine != 0);    return engine->minRightBearing();}/*!    Returns the width of the widest character in the font.*/qreal QFontMetricsF::maxWidth() const{    QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);    Q_ASSERT(engine != 0);    return engine->maxCharWidth();}/*!    Returns the 'x' height of the font. This is often but not always    the same as the height of the character 'x'.*/qreal QFontMetricsF::xHeight() const{    QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);    Q_ASSERT(engine != 0);    return engine->xHeight().toReal();}/*!    \since 4.2    Returns the average width of glyphs in the font.*/qreal QFontMetricsF::averageCharWidth() const{    QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);    Q_ASSERT(engine != 0);    return engine->averageCharWidth().toReal();}/*!    Returns true if character \a ch is a valid character in the font;    otherwise returns false.*/bool QFontMetricsF::inFont(QChar ch) const{    const int script = QUnicodeTables::script(ch);    QFontEngine *engine = d->engineForScript(script);    Q_ASSERT(engine != 0);    if (engine->type() == QFontEngine::Box)        return false;    return engine->canRender(&ch, 1);}/*!    Returns the left bearing of character \a ch in the font.    The left bearing is the right-ward distance of the left-most pixel    of the character from the logical origin of the character. This    value is negative if the pixels of the character extend to the    left of the logical origin.    See width(QChar) for a graphical description of this metric.    \sa rightBearing(), minLeftBearing(), width()*/qreal QFontMetricsF::leftBearing(QChar ch) const{    const int script = QUnicodeTables::script(ch);    QFontEngine *engine = d->engineForScript(script);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -