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

📄 kwqpainter.cpp

📁 khtml在gtk上的移植版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{    drawPixmap(x, y, sw, sh, pixmap, sx, sy, sw, sh, compositeOperator, context);}void QPainter::drawPixmap( int x, int y, int w, int h, const QPixmap &pixmap,                           int sx, int sy, int sw, int sh, int compositeOperator, CGContextRef context ){    if (data->state.paintingDisabled)        return;    if (pixmap.isNull())        return;    if (!context) {        context = data->context;    } else {    }        if (sw < 0) sw = pixmap.width();    if (sh < 0) sh = pixmap.height();    if (w < 0) w = pixmap.width();    if (h < 0) h = pixmap.height();            GdkRectangle inRect;    initGdkRectangle(&inRect, x, y, w, h);    GdkRectangle fromRect;    initGdkRectangle(&fromRect, sx, sy, w, h);    pixmap.image()->drawImageInRect(&inRect, &fromRect, NSCompositingOperation(compositeOperator), context);}void QPainter::drawTiledPixmap( int x, int y, int w, int h,                                const QPixmap &pixmap, int sx, int sy, CGContextRef context){    ASSERT(w >= 0);    ASSERT(h >= 0);    if (data->state.paintingDisabled)        return;    if (pixmap.isNull())        return;    if (!context) {        context = data->context;    }    /** sw = source width, sh = source height*/    int sw = pixmap.width(), sh = pixmap.height();     if (sx <0) sx = 0;    if (sy <0) sy = 0;    /* (due to translation) we might get negative -x (not drawn)         clip it to 0 and adjust other params too*/    if (x < 0) {        sx += -x;        w += x;        x = 0;    }        /* (due to translation) we might get negative -y (not drawn)  */    if (y < 0) {        sy += -y;        h += y;        y = 0;            }    /* if source start value is bigger than source dim, adjust it to mean same but be within       the source dim */    if (sx >= sw)         sx %= sw;        if (sy >= sh)        sy %= sh;    if (w <= 0 || h <= 0)        return;    GdkRectangle inRect;        initGdkRectangle(&inRect, x, y, w, h);    GdkRectangle fromRect;    initGdkRectangle(&fromRect, x, y, w, h);    pixmap.image()->tileInRect(&inRect, sx, sy, context);        }void QPainter::_updateRenderer(){    if (data->textRenderer == 0 || data->state.font != data->textRendererFont) {        data->textRendererFont = data->state.font;        WebCoreTextRenderer* oldRenderer = data->textRenderer;        data->textRenderer =             WebCoreTextRendererFactory::sharedFactory()->rendererWithFont(data->textRendererFont.getNSFont(),                                                                          data->textRendererFont.isPrinterFont());                KWQRetain(data->textRenderer);        ASSERT(data->textRenderer);        KWQRelease(oldRenderer);    }}void QPainter::drawText(int x, int y, int, int, int alignmentFlags, const QString &qstring){    if (data->state.paintingDisabled)        return;    // Avoid allocations, use stack array to pass font families.  Normally these    // css fallback lists are small <= 3.    CREATE_FAMILY_ARRAY(data->state.font, families);    _updateRenderer();    const UniChar* str = (const UniChar*)qstring.unicode();    WebCoreTextRun run(str, qstring.length(), 0, qstring.length());    WebCoreTextStyle style;    data->state.pen.color().getGdkColor(&style.textColor);    style.families = families;        if (alignmentFlags & Qt::AlignRight)        x -= ROUND_TO_INT(data->textRenderer->floatWidthForRun(&run, &style, 0));    data->textRenderer->setContext(data->context);    data->textRenderer->drawRun(&run, &style, x, y);}void QPainter::drawText(int x, int y, const QChar *str, int len, int from, int to, int toAdd, const QColor &backgroundColor, QPainter::TextDirection d, bool visuallyOrdered, int letterSpacing, int wordSpacing, bool smallCaps)    {    if (data->state.paintingDisabled || len <= 0)        return;    // Avoid allocations, use stack array to pass font families.  Normally these    // css fallback lists are small <= 3.    CREATE_FAMILY_ARRAY(data->state.font, families);    _updateRenderer();    if (from < 0)        from = 0;    if (to < 0)        to = len;    WebCoreTextRun run((const UniChar *)str, len, from, to);    WebCoreTextStyle style;    data->state.pen.color().getGdkColor(&style.textColor);    backgroundColor.getGdkColor(&style.backgroundColor); // !isValid() => sets style.backgroundColor "nil"    style.rtl = d == RTL ? true : false;    style.visuallyOrdered =  visuallyOrdered;    style.letterSpacing = letterSpacing;    style.wordSpacing = wordSpacing;    style.smallCaps = smallCaps;    style.padding = toAdd;    style.families = families;    data->textRenderer->setContext(data->context);    data->textRenderer->drawRun(&run, &style, x, y );}void QPainter::drawHighlightForText(int x, int minX, int maxX, int y, int h,                                     const QChar *str, int len, int from, int to, int toAdd,                                    const QColor& backgroundColor, QPainter::TextDirection d, bool visuallyOrdered,                                    int letterSpacing, int wordSpacing, bool smallCaps){    if (data->state.paintingDisabled || len <= 0)        return;    // Avoid allocations, use stack array to pass font families.  Normally these    // css fallback lists are small <= 3.    CREATE_FAMILY_ARRAY(data->state.font, families);    _updateRenderer();        if (from < 0)        from = 0;    if (to < 0)        to = len;    WebCoreTextRun run((const UniChar *)str, len, from, to);    WebCoreTextStyle style;    data->state.pen.color().getGdkColor(&style.textColor);    backgroundColor.getGdkColor(&style.backgroundColor); // !isValid() => sets style.backgroundcolor "nil"    style.rtl = d == RTL ? true : false;    style.visuallyOrdered = visuallyOrdered;            style.letterSpacing = letterSpacing;    style.wordSpacing = wordSpacing;    style.smallCaps = smallCaps;    style.padding = toAdd;    style.families = families;    WebCoreTextGeometry geometry(x,y, y, h, minX, maxX, false);    data->textRenderer->setContext(data->context);    data->textRenderer->drawHighlightForRun(&run, &style, &geometry);}void QPainter::drawLineForText(int x, int y, int yOffset, int width){    if (data->state.paintingDisabled)        return;	    drawLine(x, y+yOffset+1, x+width, y+yOffset+1);    #if 0    GdkColor col;    data->state.pen.color().getGdkColor(&col);    data->textRenderer->drawLineForCharacters(x, y,                                              yOffset,                                              width,                                              col);#endif        }QColor QPainter::selectedTextBackgroundColor() const{    static QColor secondarySelectedControlColor("gray");    static QColor selectedTextBackgroundColor(qRgba((int)(255*0.1f),                                                    (int)(255*0.1f),                                                    (int)(255*1.0f),                                                    (int) (255 * 0.3f)));        return _usesInactiveTextBackgroundColor ?  secondarySelectedControlColor : selectedTextBackgroundColor;}#if !KWIQvoid QPainter::_fillRect(float x, float y, float w, float h, const QColor& col){    [col.getNSColor() set];    NSRectFillUsingOperation(NSMakeRect(x,y,w,h), NSCompositeSourceOver);}#endifvoid QPainter::fillRect(int x, int y, int w, int h, const QBrush &brush){    if (data->state.paintingDisabled)        return;    if (brush.style() == SolidPattern) {        QBrush old = this->brush();        setBrush(brush);        _setColorFromBrush();        gdk_draw_rectangle(data->context->drawable, data->context->gc, TRUE, x, y, w, h);        setBrush(old);    }}void QPainter::addClip(const QRect &rect){    GdkRectangle gr;            rect.getGdkRectangle(&gr);    data->context->addClip(&gr);}Qt::RasterOp QPainter::rasterOp() const{    return CopyROP;}void QPainter::setRasterOp(RasterOp){}void QPainter::setPaintingDisabled(bool f){    data->state.paintingDisabled = f;}bool QPainter::paintingDisabled() const{    return data->state.paintingDisabled;}void QPainter::setContext(CGContextRef context){    if (context == data->context)         return;    data->context = context;    // FIXME: init with current state.}CGContextRef QPainter::currentContext(){    return data->context;}void QPainter::beginTransparencyLayer(float opacity){#if 0    [NSGraphicsContext saveGraphicsState];    CGContextRef context = (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]);    CGContextSetAlpha(context, opacity);    CGContextBeginTransparencyLayer(context, 0);#endif}void QPainter::endTransparencyLayer(){#if 0    CGContextRef context = (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]);    CGContextEndTransparencyLayer(context);    [NSGraphicsContext restoreGraphicsState];#endif}void QPainter::setShadow(int x, int y, int blur, const QColor& color){#if !KWIQ    // Check for an invalid color, as this means that the color was not set for the shadow    // and we should therefore just use the default shadow color.    CGContextRef context = (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]);    if (!color.isValid())        CGContextSetShadow(context, CGSizeMake(x,-y), blur); // y is flipped.    else {        NSColor* deviceColor = [color.getNSColor() colorUsingColorSpaceName: @"NSDeviceRGBColorSpace"];        float red = [deviceColor redComponent];        float green = [deviceColor greenComponent];        float blue = [deviceColor blueComponent];        float alpha = [deviceColor alphaComponent];        const float components[] = { red, green, blue, alpha };        CGContextSetShadowWithColor(context,                                    CGSizeMake(x,-y), // y is flipped.                                    blur,                                    CGColorCreate(CGColorSpaceCreateDeviceRGB(),                                                  components));    }#endif}void QPainter::clearShadow(){#if !KWIQ    CGContextRef context = (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]);    CGContextSetShadowWithColor(context, CGSizeZero, 0, NULL);#endif}void QPainter::initFocusRing(int width, int offset){#if 0    if (!_drawsFocusRing)        return;    clearFocusRing();    data->focusRingWidth = width;    data->hasFocusRingColor = false;    data->focusRingOffset = offset;    data->focusRingPath = [[NSBezierPath alloc] init];    [data->focusRingPath setWindingRule:NSNonZeroWindingRule];#endif     }void QPainter::initFocusRing(int width, int offset, const QColor &color){#if 0        if (!_drawsFocusRing)        return;    initFocusRing(width, offset);    data->hasFocusRingColor = true;    data->focusRingColor = color;#endif    }void QPainter::addFocusRingRect(int x, int y, int width, int height){#if 0    if (!_drawsFocusRing)        return;    ASSERT(data->focusRingPath);    NSRect rect = NSMakeRect(x, y, width, height);    int offset = (data->focusRingWidth-1)/2 + data->focusRingOffset;    rect = NSInsetRect(rect, -offset, -offset);    [data->focusRingPath appendBezierPathWithRect:rect];#endif    }void QPainter::drawFocusRing(){#if 0    if (!_drawsFocusRing)        return;        ASSERT(data->focusRingPath);    if (data->state.paintingDisabled)        return;    if ([data->focusRingPath elementCount] == 0) {        ERROR("Request to draw focus ring with no control points");        return;    }        NSRect bounds = [data->focusRingPath bounds];    if (!NSIsEmptyRect(bounds)) {        int radius = (data->focusRingWidth-1)/2;        NSColor *color = data->hasFocusRingColor ? data->focusRingColor.getNSColor() : nil;        [NSGraphicsContext saveGraphicsState];        [[WebCoreGraphicsBridge sharedBridge] setFocusRingStyle:NSFocusRingOnly radius:radius color:color];        [data->focusRingPath fill];        [NSGraphicsContext restoreGraphicsState];       }#endif    }void QPainter::clearFocusRing(){#if 0        if (data->focusRingPath) {        [data->focusRingPath release];        data->focusRingPath = nil;    }#endif}

⌨️ 快捷键说明

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