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

📄 qfontmetrics.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    Q_ASSERT(engine != 0);    if (engine->type() == QFontEngine::Box)        return 0;    QGlyphLayout glyphs[10];    int nglyphs = 9;    engine->stringToCMap(&ch, 1, glyphs, &nglyphs, 0);    // ### can nglyphs != 1 happen at all? Not currently I think    glyph_metrics_t gi = engine->boundingBox(glyphs[0].glyph);    return gi.x.toReal();}/*!    Returns the right bearing of character \a ch in the font.    The right bearing is the left-ward distance of the right-most    pixel of the character from the logical origin of a subsequent    character. This value is negative if the pixels of the character    extend to the right of the width() of the character.    See width() for a graphical description of this metric.    \sa leftBearing(), minRightBearing(), width()*/qreal QFontMetricsF::rightBearing(QChar ch) const{    const int script = QUnicodeTables::script(ch);    QFontEngine *engine = d->engineForScript(script);    Q_ASSERT(engine != 0);    if (engine->type() == QFontEngine::Box)        return 0;    QGlyphLayout glyphs[10];    int nglyphs = 9;    engine->stringToCMap(&ch, 1, glyphs, &nglyphs, 0);    // ### can nglyphs != 1 happen at all? Not currently I think    glyph_metrics_t gi = engine->boundingBox(glyphs[0].glyph);    return (gi.xoff - gi.x - gi.width).toReal();}/*!    Returns the width in pixels of the characters in the given \a text.    Note that this value is \e not equal to the width returned by    boundingRect().width() because boundingRect() returns a rectangle    describing the pixels this string will cover whereas width()    returns the distance to where the next string should be drawn.    \sa boundingRect()*/qreal QFontMetricsF::width(const QString &text) const{    QTextEngine layout(text, d);    layout.ignoreBidi = true;    layout.itemize();    return layout.width(0, text.length()).toReal();}/*!    \overload    \img bearings.png Bearings    Returns the logical width of character \a ch in pixels. This is a    distance appropriate for drawing a subsequent character after \a    ch.    Some of the metrics are described in the image to the right. The    central dark rectangles cover the logical width() of each    character. The outer pale rectangles cover the leftBearing() and    rightBearing() of each character. Notice that the bearings of "f"    in this particular font are both negative, while the bearings of    "o" are both positive.    \warning This function will produce incorrect results for Arabic    characters or non-spacing marks in the middle of a string, as the    glyph shaping and positioning of marks that happens when    processing strings cannot be taken into account. Use charWidth()    instead if you aren't looking for the width of isolated    characters.    \sa boundingRect()*/qreal QFontMetricsF::width(QChar ch) const{    if (QChar::category(ch.unicode()) == QChar::Mark_NonSpacing)        return 0.;    const int script = QUnicodeTables::script(ch);    QFontEngine *engine = d->engineForScript(script);    Q_ASSERT(engine != 0);    QGlyphLayout glyphs[8];    int nglyphs = 7;    engine->stringToCMap(&ch, 1, glyphs, &nglyphs, 0);    return glyphs[0].advance.x.toReal();}/*!    Returns the bounding rectangle of the characters in the string    specified by \a text. The bounding rectangle always covers at least    the set of pixels the text would cover if drawn at (0, 0).    Note that the bounding rectangle may extend to the left of (0, 0),    e.g. for italicized fonts, and that the width of the returned    rectangle might be different than what the width() method returns.    If you want to know the advance width of the string (to layout    a set of strings next to each other), use width() instead.    Newline characters are processed as normal characters, \e not as    linebreaks.    The height of the bounding rectangle is at least as large as the    value returned height().    \sa width(), height(), QPainter::boundingRect()*/QRectF QFontMetricsF::boundingRect(const QString &text) const{    int len = text.length();    if (len == 0)        return QRectF();    QTextEngine layout(text, d);    layout.ignoreBidi = true;    layout.itemize();    glyph_metrics_t gm = layout.boundingBox(0, len);    return QRectF(gm.x.toReal(), gm.y.toReal(),                  gm.width.toReal(), gm.height.toReal());}/*!    Returns the bounding rectangle of the character \a ch relative to    the left-most point on the base line.    Note that the bounding rectangle may extend to the left of (0, 0),    e.g. for italicized fonts, and that the text output may cover \e    all pixels in the bounding rectangle.    Note that the rectangle usually extends both above and below the    base line.    \sa width()*/QRectF QFontMetricsF::boundingRect(QChar ch) const{    const int script = QUnicodeTables::script(ch);    QFontEngine *engine = d->engineForScript(script);    Q_ASSERT(engine != 0);    QGlyphLayout glyphs[10];    int nglyphs = 9;    engine->stringToCMap(&ch, 1, glyphs, &nglyphs, 0);    glyph_metrics_t gm = engine->boundingBox(glyphs[0].glyph);    return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal());}/*!    \overload    Returns the bounding rectangle of the characters in the given \a text.    This is the set of pixels the text would cover if drawn when constrained    to the bounding rectangle specified by \a rect.    The \a flags argument is the bitwise OR of the following flags:    \list    \o Qt::AlignLeft aligns to the left border, except for          Arabic and Hebrew where it aligns to the right.    \o Qt::AlignRight aligns to the right border, except for          Arabic and Hebrew where it aligns to the left.    \o Qt::AlignJustify produces justified text.    \o Qt::AlignHCenter aligns horizontally centered.    \o Qt::AlignTop aligns to the top border.    \o Qt::AlignBottom aligns to the bottom border.    \o Qt::AlignVCenter aligns vertically centered    \o Qt::AlignCenter (== \c{Qt::AlignHCenter | Qt::AlignVCenter})    \o Qt::TextSingleLine ignores newline characters in the text.    \o Qt::TextExpandTabs expands tabs (see below)    \o Qt::TextShowMnemonic interprets "&x" as \underline{x}, i.e. underlined.    \o Qt::TextWordWrap breaks the text to fit the rectangle.    \endlist    Qt::Horizontal alignment defaults to Qt::AlignLeft and vertical    alignment defaults to Qt::AlignTop.    If several of the horizontal or several of the vertical alignment    flags are set, the resulting alignment is undefined.    These flags are defined in \l{Qt::AlignmentFlag}.    If Qt::TextExpandTabs is set in \a flags, the following behavior is    used to interpret tab characters in the text:    \list    \o If \a tabArray is non-null, it specifies a 0-terminated sequence of       pixel-positions for tabs in the text.    \o If \a tabStops is non-zero, it is used as the tab spacing (in pixels).    \endlist    Note that the bounding rectangle may extend to the left of (0, 0),    e.g. for italicized fonts.    Newline characters are processed as line breaks.    Despite the different actual character heights, the heights of the    bounding rectangles of "Yes" and "yes" are the same.    The bounding rectangle returned by this function is somewhat larger    than that calculated by the simpler boundingRect() function. This    function uses the \link minLeftBearing() maximum left \endlink and    \link minRightBearing() right \endlink font bearings as is    necessary for multi-line text to align correctly. Also,    fontHeight() and lineSpacing() are used to calculate the height,    rather than individual character heights.    \sa width(), QPainter::boundingRect(), Qt::Alignment*/QRectF QFontMetricsF::boundingRect(const QRectF &rect, int flags, const QString& text,                                   int tabStops, int *tabArray) const{    int tabArrayLen = 0;    if (tabArray)        while (tabArray[tabArrayLen])            tabArrayLen++;    QRectF rb;    qt_format_text(QFont(d), rect, flags | Qt::TextDontPrint, text, &rb, tabStops, tabArray,                   tabArrayLen, 0);    return rb;}/*!    Returns the size in pixels of the characters in the given \a text.    The \a flags argument is the bitwise OR of the following flags:    \list    \o Qt::TextSingleLine ignores newline characters.    \o Qt::TextExpandTabs expands tabs (see below)    \o Qt::TextShowMnemonic interprets "&x" as \underline{x}, i.e. underlined.    \o Qt::TextWordBreak breaks the text to fit the rectangle.    \endlist    These flags are defined in \l{Qt::TextFlags}.    If Qt::TextExpandTabs is set in \a flags, the following behavior is    used to interpret tab characters in the text:    \list    \o If \a tabArray is non-null, it specifies a 0-terminated sequence of       pixel-positions for tabs in the text.    \o If \a tabStops is non-zero, it is used as the tab spacing (in pixels).    \endlist    Newline characters are processed as line breaks.    Note: Despite the different actual character heights, the heights of the    bounding rectangles of "Yes" and "yes" are the same.    \sa boundingRect()*/QSizeF QFontMetricsF::size(int flags, const QString &text, int tabStops, int *tabArray) const{    return boundingRect(QRectF(), flags, text, tabStops, tabArray).size();}/*!  \since 4.3    Returns a tight bounding rectangle around the characters in the    string specified by \a text. The bounding rectangle always covers    at least the set of pixels the text would cover if drawn at (0,    0).    Note that the bounding rectangle may extend to the left of (0, 0),    e.g. for italicized fonts, and that the width of the returned    rectangle might be different than what the width() method returns.    If you want to know the advance width of the string (to layout    a set of strings next to each other), use width() instead.    Newline characters are processed as normal characters, \e not as    linebreaks.    \warning Calling this method is very slow on Windows.    \sa width(), height(), boundingRect()*/QRectF QFontMetricsF::tightBoundingRect(const QString &text) const{    if (text.length() == 0)        return QRect();    QTextEngine layout(text, d);    layout.ignoreBidi = true;    layout.itemize();    glyph_metrics_t gm = layout.tightBoundingBox(0, text.length());    return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal());}/*!    \since 4.2    If the string \a text is wider than \a width, returns an elided    version of the string (i.e., a string with "..." in it).    Otherwise, returns the original string.    The \a mode parameter specifies whether the text is elided on the    left (e.g., "...tech"), in the middle (e.g., "Tr...ch"), or on    the right (e.g., "Trol...").    The \a width is specified in pixels, not characters.    The \a flags argument is optional and currently only supports    Qt::TextShowMnemonic as value.*/QString QFontMetricsF::elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags) const{    QStackTextEngine engine(text, QFont(d));    return engine.elidedText(mode, QFixed::fromReal(width), flags);}/*!    Returns the distance from the base line to where an underscore    should be drawn.    \sa overlinePos(), strikeOutPos(), lineWidth()*/qreal QFontMetricsF::underlinePos() const{    QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);    Q_ASSERT(engine != 0);    return engine->underlinePosition().toReal();}/*!    Returns the distance from the base line to where an overline    should be drawn.    \sa underlinePos(), strikeOutPos(), lineWidth()*/qreal QFontMetricsF::overlinePos() const{    return ascent() + 1;}/*!    Returns the distance from the base line to where the strikeout    line should be drawn.    \sa underlinePos(), overlinePos(), lineWidth()*/qreal QFontMetricsF::strikeOutPos() const{    return ascent() / 3.;}/*!    Returns the width of the underline and strikeout lines, adjusted    for the point size of the font.    \sa underlinePos(), overlinePos(), strikeOutPos()*/qreal QFontMetricsF::lineWidth() const{    QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);    Q_ASSERT(engine != 0);    return engine->lineThickness().toReal();}/*!    \fn QSize QFontMetrics::size(int flags, const QString &text, int len,                                 int tabStops, int *tabArray) const    \compat    Use the size() function in combination with QString::left()    instead.    \oldcode        QSize size = size(flags, str, len, tabstops, tabarray);    \newcode        QSize size = size(flags, str.left(len), tabstops, tabarray);    \endcode*//*!    \fn QRect QFontMetrics::boundingRect(int x, int y, int w, int h, int flags,        const QString& text, int len, int tabStops, int *tabArray) const    \compat    Use the boundingRect() function in combination with    QString::left() and a QRect constructor instead.    \oldcode        QRect rect = boundingRect(x, y, w, h , flags, text, len,                                  tabStops, tabArray);    \newcode        QRect rect = boundingRect(QRect(x, y, w, h), flags, text.left(len),                                  tabstops, tabarray);    \endcode*//*!    \fn QRect QFontMetrics::boundingRect(const QString &text, int len) const    \compat    Use the boundingRect() function in combination with    QString::left() instead.    \oldcode        QRect rect = boundingRect(text, len);    \newcode        QRect rect = boundingRect(text.left(len));    \endcode*/

⌨️ 快捷键说明

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