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

📄 render_text.cpp

📁 monqueror一个很具有参考价值的源玛
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    // updating the pen if the text color is still correct - this saves    // quite some time    if(m_style->color() != p->pen().color())        p->setPen( m_style->color() );    // as the textslaves are ordered from top to bottom    // as soon as we find one that is "below" our    // printing range, we can quit    // ### better if textslaves are placed in a double linked list    bool breakallowed = false;    while(s)    {        if(s->checkVerticalPoint(y, ty, h))        {            breakallowed = true;            s->print(p, tx, ty);        }        else if(breakallowed)            break;        s=s->next();    }    int d = m_style->textDecoration();    if(d != TDNONE && hasKeyboardFocus==DOM::ActivationOff)    {        p->setPen( m_style->textDecorationColor() );        s = m_first;        bool breakallowed = false;        while(s)        {            if(s->checkVerticalPoint(y, ty, h))            {                breakallowed = true;                s->printDecoration(p, tx, ty, d);            }            else if(breakallowed)                break;            s=s->next();        }    }    s = m_first;    if (selectionState() != SelectionNone)    {        int endPos, startPos;        bool breakAtEnd = false;        if (selectionState()==SelectionInside)        {            startPos = 0;            endPos = -1;        }        else        {            selectionStartEnd(startPos,endPos);            breakAtEnd = true;            if(selectionState() == SelectionStart) {                endPos = -1;                breakAtEnd = false;            }            else if(selectionState() == SelectionEnd)                startPos = 0;//          kdDebug( 6040 ) << "selectionstartend start=" << startPos << " end=" << endPos << endl;        }        breakallowed = false;        while(s && endPos)        {            if(s->checkVerticalPoint(y, ty, h))            {                breakallowed = true;                s->printSelection(p, this, tx, ty, startPos, endPos);            }            else if(breakallowed)                break;            int diff;            if(s->next())                diff = s->next()->m_text - s->m_text;            else                diff = s->len;            endPos -= diff;            startPos -= diff;            if(breakAtEnd && endPos < 0) break;            s=s->next();        }    }    if (hasKeyboardFocus!=DOM::ActivationOff)    {        bool clip = p->hasClipping();	p->setClipping(false);	p->setRasterOp(MG::XorROP);        if (hasKeyboardFocus==DOM::ActivationPassive)          p->setPen(MGColor("white"));        else          p->setPen(MGColor("blue"));        breakallowed = false;        while(s)        {            if(s->checkVerticalPoint(y, ty, h))            {                breakallowed = true;                s->printActivation(p, tx, ty);            }            else if(breakallowed)                break;            int diff;            if(s->next())                diff = s->next()->m_text - s->m_text;            else                diff = s->len;            s=s->next();        }	p->setRasterOp(MG::CopyROP);	p->setClipping(clip);    }#ifdef BIDI_DEBUG    p->setPen(MGPen(MGColor("#00CC00"), 1, MG::DashLine));    p->setBrush( MG::NoBrush );    p->drawRect(tx + boundingRect.x(), ty + boundingRect.y(), boundingRect.width(), boundingRect.height());#endif}void RenderText::print( MGPainter *p, int x, int y, int w, int h,                      int tx, int ty){    if ( !m_visible )        return;#if 0    RECT rc;    rc.left = x; rc.top = y; rc.right = x + w, rc.bottom = y +h;    if (!RectVisible (p->getHdc (), &rc))        return;#endif    printObject(p, x, y, w, h, tx, ty);}void RenderText::calcMinMaxWidth(){    if(minMaxKnown()) return;    // ### calc Min and Max width...    m_minWidth = 0;    m_maxWidth = 0;    int currMinWidth = 0;    int currMaxWidth = 0;    int len = str->l;    for(int i = 0; i < len; i++)    {        int wordlen = 0;        char c = str->s[i];#if CODE_BY_YMWEI        wordlen = fm->getFirstWordLen (                QConstString(str->s+i, len - i).string(), len-i);#else        do {            wordlen++;        } while( !(isBreakable( str->s+i+wordlen )) && i+wordlen < len); // && c != '-'        if (i+wordlen < len) wordlen--;#endif        if (wordlen)        {            int w = fm->width(QConstString(str->s+i, wordlen).string());            currMinWidth += w;            currMaxWidth += w;        }        if(i+wordlen < len)        {            if ( c == '\n' )            {                if(currMinWidth > m_minWidth) m_minWidth = currMinWidth;                currMinWidth = 0;                if(currMaxWidth > m_maxWidth) m_maxWidth = currMaxWidth;                currMaxWidth = 0;            }            else            {                if(currMinWidth > m_minWidth) m_minWidth = currMinWidth;                currMinWidth = 0;                currMaxWidth += fm->width( *(str->s+i+wordlen) );            }            /* else if( c == '-')            {                currMinWidth += minus_width;                if(currMinWidth > m_minWidth) m_minWidth = currMinWidth;                currMinWidth = 0;                currMaxWidth += minus_width;            }*/        }        i += wordlen;    }    if(currMinWidth > m_minWidth) m_minWidth = currMinWidth;    currMinWidth = 0;    if(currMaxWidth > m_maxWidth) m_maxWidth = currMaxWidth;    currMaxWidth = 0;    setMinMaxKnown();}int RenderText::xPos() const{    if (m_first)        return m_first->x;    else        return 0;}int RenderText::yPos() const{    if (m_first)        return m_first->y;    else        return 0;}const MGFont &RenderText::font(){    return parent()->style()->font();}void RenderText::setText(DOMStringImpl *text){    if(str) str->deref();    str = text;    if(str) str->ref();    setLayouted(false);    containingBlock()->setLayouted(false);    containingBlock()->layout();#ifdef DEBUG_LAYOUT    QConstString cstr(str->s, str->l);    kdDebug( 6040 ) << "RenderText::setText '" << (const char *)cstr.string().utf8() << "'" << endl;#endif}int RenderText::height() const{    return m_contentHeight        + m_style->borderTopWidth() + m_style->borderBottomWidth();   // ### padding is relative to the _width_ of the containing block    //+ m_style->paddingTop() + m_style->paddingBottom() }int RenderText::bidiHeight() const{    return m_contentHeight;}short RenderText::baselineOffset() const{    return (m_contentHeight - fm->height())/2 + fm->ascent();}short RenderText::verticalPositionHint() const{    return (m_contentHeight - fm->height())/2 + fm->ascent();}void RenderText::position(int x, int y, int from, int len, int width, bool reverse){    // ### should not be needed!!!    if(len == 0) return;    QChar *ch;    bool deleteChar = false;#if QT_VERSION < 221	assert( false );    // Qt still uses the old BiDi code with 8859-6/8...    if((reverse && (( !m_style->visuallyOrdered() &&                      font().charSet() != MGFont::ISO_8859_8 &&                      font().charSet() != MGFont::ISO_8859_6)                    ||                    ( m_style->visuallyOrdered() &&                      ( font().charSet() == MGFont::ISO_8859_8 ||                        font().charSet() == MGFont::ISO_8859_6))        )))    {        deleteChar = true;        // reverse String        QString aStr = QConstString(str->s+from, len).string();#ifdef DEBUG_LAYOUT        kdDebug( 6040 ) << "reversing '" << (const char *)aStr.utf8() << "' len=" << aStr.length() << " oldlen=" << len << endl;#endif        len = aStr.length();        ch = QT_ALLOC_QCHAR_VEC(len);        int half =  len/2;        const QChar *s = aStr.unicode();        for(int i = 0; i <= half; i++)        {            ch[len-1-i] = s[i];            ch[i] = s[len-1-i];            if(ch[i].mirrored() && !m_style->visuallyOrdered())                ch[i] = ch[i].mirroredChar();            if(ch[len-1-i].mirrored() && !m_style->visuallyOrdered() && i != len-1-i)                ch[len-1-i] = ch[len-1-i].mirroredChar();        }    }    else if ( reverse && !m_style->visuallyOrdered() &&              (font().charSet() == MGFont::ISO_8859_8 || font().charSet() == MGFont::ISO_8859_6 ) ) {        deleteChar = true;        QString aStr = QConstString(str->s+from, len).string();        len = aStr.length();        ch = QT_ALLOC_QCHAR_VEC(len);        const QChar *s = aStr.unicode();        for( int i = 0; i < len; i++ ) {            if( s[i].mirrored() )                ch[i] = s[i].mirroredChar();            else                ch[i] = s[i];        }    }    else        ch = str->s+from;#else    if ( reverse && !m_style->visuallyOrdered() ) {		assert( false );        deleteChar = true;        // reverse String        QString aStr = QConstString(str->s+from, len).string();#ifdef DEBUG_LAYOUT        kdDebug( 6040 ) << "reversing '" << (const char *)aStr.utf8() << "' len=" << aStr.length() << " oldlen=" << len << endl;#endif        len = aStr.length();        ch = QT_ALLOC_QCHAR_VEC(len);        int half =  len/2;        const QChar *s = aStr.unicode();        for(int i = 0; i <= half; i++)        {            ch[len-1-i] = s[i];            ch[i] = s[len-1-i];            if(ch[i].mirrored() && !m_style->visuallyOrdered())                ch[i] = ch[i].mirroredChar();            if(ch[len-1-i].mirrored() && !m_style->visuallyOrdered() && i != len-1-i)                ch[len-1-i] = ch[len-1-i].mirroredChar();        }    }    else        ch = str->s+from;#endif    // ### margins and RTL    if(from == 0 && m_parent->isInline() && m_parent->firstChild()==this)    {        x += paddingLeft() + borderLeft() + marginLeft();        width -= marginLeft();    }    if(from + len == int(str->l) && m_parent->isInline() && m_parent->lastChild()==this)        width -= marginRight();#ifdef DEBUG_LAYOUT    QConstString cstr(ch, len);    kdDebug( 6040 ) << "setting slave text to '" << (const char *)cstr.string().utf8() << "' len=" << len << " width=" << width << " at (" << x << "/" << y << ")" << " height=" << bidiHeight() << " fontHeight=" << fm->height() << " ascent =" << fm->ascent() << endl;#endif    TextSlave *s = new TextSlave(x, y, ch, len,                                 bidiHeight(), baselineOffset(), width, deleteChar);    if(!m_first)        m_first = m_last = s;    else    {        m_last->setNext(s);        m_last = s;    }}unsigned int RenderText::width( int from, int len) const{    if(!str->s) return 0;    int w;    if( len == 1)        w = fm->width( *(str->s+from) );    else        w = fm->width(QConstString(str->s+from, len).string());    // ### add margins and support for RTL    if(m_parent->isInline())    {        if(from == 0 && m_parent->firstChild() == static_cast<const RenderObject*>(this))            w += borderLeft() + paddingLeft() + marginLeft();        if(from + len == int(str->l) &&           m_parent->lastChild() == static_cast<const RenderObject*>(this))            w += borderRight() + paddingRight() +marginRight();;    }    return w;}void RenderText::repaint(){    RenderObject *cb = containingBlock();    if(cb != this)        cb->repaint();}bool RenderText::isFixedWidthFont() const{#if CODE_BY_YMWEI    return fm->fixedPitch ();#else    return MGFontInfo(m_style->font()).fixedPitch();#endif}#undef BIDI_DEBUG

⌨️ 快捷键说明

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