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

📄 pagepainter.cpp.svn-base

📁 okular
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
                mixedPainter->drawRect( annotBoundary );            }        }    }    /** 6 -- MIXED FLOW. Draw LINKS+IMAGES BORDER on ACTIVE PAINTER  **/    if ( enhanceLinks || enhanceImages )    {        mixedPainter->save();        mixedPainter->scale( scaledWidth, scaledHeight );        QColor normalColor = QApplication::palette().color( QPalette::Active, QPalette::Highlight );        QColor lightColor = normalColor.light( 140 );        // enlarging limits for intersection is like growing the 'rectGeometry' below        QRect limitsEnlarged = limits;        limitsEnlarged.adjust( -2, -2, 2, 2 );        // draw rects that are inside the 'limits' paint region as opaque rects        QLinkedList< ObjectRect * >::const_iterator lIt = page->m_rects.begin(), lEnd = page->m_rects.end();        for ( ; lIt != lEnd; ++lIt )        {            ObjectRect * rect = *lIt;            if ( (enhanceLinks && rect->objectType() == ObjectRect::Link) ||                 (enhanceImages && rect->objectType() == ObjectRect::Image) )            {                if ( limitsEnlarged.intersects( rect->boundingRect( scaledWidth, scaledHeight ) ) )                {                    mixedPainter->strokePath( rect->region(), QPen( normalColor ) );                }            }        }        mixedPainter->restore();    }    /** 7 -- BUFFERED FLOW. Copy BACKPIXMAP on DESTINATION PAINTER **/    if ( useBackBuffer )    {        delete mixedPainter;        destPainter->drawPixmap( limits.left(), limits.top(), *backPixmap );        delete backPixmap;    }    // delete object containers    delete bufferedHighlights;    delete bufferedAnnotations;    delete unbufferedAnnotations;}/** Private Helpers :: Pixmap conversion **/void PagePainter::cropPixmapOnImage( QImage & dest, const QPixmap * src, const QRect & r ){    // handle quickly the case in which the whole pixmap has to be converted    if ( r == QRect( 0, 0, src->width(), src->height() ) )    {        dest = src->toImage();    }    // else copy a portion of the src to an internal pixmap (smaller) and convert it    else    {        QPixmap croppedPixmap( r.width(), r.height() );        copyBlt( &croppedPixmap, 0, 0, src, r.left(), r.top(), r.width(), r.height() );        dest = croppedPixmap.toImage();    }}void PagePainter::scalePixmapOnImage ( QImage & dest, const QPixmap * src,    int scaledWidth, int scaledHeight, const QRect & cropRect ){    // {source, destination, scaling} params    int srcWidth = src->width(),        srcHeight = src->height(),        destLeft = cropRect.left(),        destTop = cropRect.top(),        destWidth = cropRect.width(),        destHeight = cropRect.height();    // destination image (same geometry as the pageLimits rect)    dest = QImage( destWidth, destHeight, 32 );    unsigned int * destData = (unsigned int *)dest.bits();    // source image (1:1 conversion from pixmap)    QImage srcImage = src->toImage();    unsigned int * srcData = (unsigned int *)srcImage.bits();    // precalc the x correspondancy conversion in a lookup table    unsigned int xOffset[ destWidth ];    for ( int x = 0; x < destWidth; x++ )        xOffset[ x ] = ((x + destLeft) * srcWidth) / scaledWidth;    // for each pixel of the destination image apply the color of the    // corresponsing pixel on the source image (note: keep parenthesis)    for ( int y = 0; y < destHeight; y++ )    {        unsigned int srcOffset = srcWidth * (((destTop + y) * srcHeight) / scaledHeight);        for ( int x = 0; x < destWidth; x++ )            (*destData++) = srcData[ srcOffset + xOffset[x] ];    }}/** Private Helpers :: Image Drawing **/// from Arthur - qt4inline int qt_div_255(int x) { return (x + (x>>8) + 0x80) >> 8; }void PagePainter::changeImageAlpha( QImage & image, unsigned int destAlpha ){    // iterate over all pixels changing the alpha component value    unsigned int * data = (unsigned int *)image.bits();    unsigned int pixels = image.width() * image.height();    int source, sourceAlpha;    for( register unsigned int i = 0; i < pixels; ++i )    {   // optimize this loop keeping byte order into account        source = data[i];        if ( (sourceAlpha = qAlpha( source )) == 255 )        {            // use destAlpha            data[i] = qRgba( qRed(source), qGreen(source), qBlue(source), destAlpha );        }        else        {            // use destAlpha * sourceAlpha product            sourceAlpha = qt_div_255( destAlpha * sourceAlpha );            data[i] = qRgba( qRed(source), qGreen(source), qBlue(source), sourceAlpha );        }    }}void PagePainter::colorizeImage( QImage & grayImage, const QColor & color,    unsigned int destAlpha ){    // iterate over all pixels changing the alpha component value    unsigned int * data = (unsigned int *)grayImage.bits();    unsigned int pixels = grayImage.width() * grayImage.height();    int red = color.red(),        green = color.green(),        blue = color.blue();    int source, sourceSat, sourceAlpha;    for( register unsigned int i = 0; i < pixels; ++i )    {   // optimize this loop keeping byte order into account        source = data[i];        sourceSat = qRed( source );        int newR = qt_div_255( sourceSat * red ),            newG = qt_div_255( sourceSat * green ),            newB = qt_div_255( sourceSat * blue );        if ( (sourceAlpha = qAlpha( source )) == 255 )        {            // use destAlpha            data[i] = qRgba( newR, newG, newB, destAlpha );        }        else        {            // use destAlpha * sourceAlpha product            if ( destAlpha < 255 )                sourceAlpha = qt_div_255( destAlpha * sourceAlpha );            data[i] = qRgba( newR, newG, newB, sourceAlpha );        }    }}//BEGIN of Anti-Grain dependant code/** Shape Drawing using Anti-Grain Geometry library **/// The following code uses the AGG2.3 lib imported into the "painter_agg2"// directory. This is to be replaced by Arthur calls for drawing antialiased// primitives, but until that AGG2 does its job very fast and good-looking.#include "kpdf_pixfmt_rgba.h"#include "agg_rendering_buffer.h"#include "agg_renderer_base.h"#include "agg_scanline_u.h"#include "agg_rasterizer_scanline_aa.h"#include "agg_renderer_scanline.h"#include "agg_conv_stroke.h"#include "agg_path_storage.h"void PagePainter::drawShapeOnImage(    QImage & image,    const NormalizedPath & normPath,    bool closeShape,    const QPen & pen,    const QBrush & brush,    double penWidthMultiplier,    RasterOperation op    //float antiAliasRadius    ){    // safety checks    int pointsNumber = normPath.size();    if ( pointsNumber < 2 )        return;    int imageWidth = image.width();    int imageHeight = image.height();    double fImageWidth = (double)imageWidth;    double fImageHeight = (double)imageHeight;    // create a 'path'    agg::path_storage path;    path.move_to( normPath[ 0 ].x * fImageWidth, normPath[ 0 ].y * fImageHeight );    for ( int i = 1; i < pointsNumber; i++ )        path.line_to( normPath[ i ].x * fImageWidth, normPath[ i ].y * fImageHeight );        //path.curve4( normPath[ i ].x * fImageWidth + 2, normPath[ i ].y * fImageHeight - 2,        //             normPath[ i ].x * fImageWidth, normPath[ i ].y * fImageHeight );    if ( closeShape )        path.close_polygon();    // create the 'rendering buffer' over qimage memory    agg::rendering_buffer buffer( image.bits(), imageWidth, imageHeight, imageWidth << 2 );    // create 'pixel buffer', 'clipped renderer', 'scanline renderer' on bgra32 format    typedef agg::pixfmt_bgra32 bgra32;    typedef agg::renderer_base< bgra32 > rb_bgra32;    bgra32 pixels( buffer, op == Multiply ? 1 : 0 );    rb_bgra32 rb( pixels );    agg::renderer_scanline_aa_solid< rb_bgra32 > render( rb );    // create rasterizer and scaline    agg::rasterizer_scanline_aa<> rasterizer;    agg::scanline_u8 scanline;#if 0    //draw RAINBOW    agg::rgba8 span[ imageWidth ];    for( int x = 0; x < imageWidth; x++ )    {        agg::rgba c( 380.0 + 400.0 * x / imageWidth, 0.8 );        span[ x ] = agg::rgba8(c);    }    for( int y = 0; y < imageHeight; y++ )        pixels.blend_color_hspan( 0, y, imageWidth, span, 0, (123*y)/imageHeight );#endif    // fill rect    if ( brush.style() != Qt::NoBrush )    {        const QColor & brushColor = brush.color();        render.color( agg::rgba8( brushColor.red(), brushColor.green(), brushColor.blue() ) );        rasterizer.add_path( path );        agg::render_scanlines( rasterizer, scanline, render );        rasterizer.reset();    }    // stroke outline    double penWidth = (double)pen.width() * penWidthMultiplier;    if ( penWidth > 0.1 )    {        const QColor & penColor = pen.color();        render.color( agg::rgba8( penColor.red(), penColor.green(), penColor.blue() ) );#if 0        // BSPLINE curve over path        typedef agg::conv_bspline< agg::path_storage > conv_bspline_type;        conv_bspline_type bspline( path );        bspline.interpolation_step( 0.2 );        agg::conv_stroke< conv_bspline_type > strokedPath( bspline );#else        agg::conv_stroke< agg::path_storage > strokedPath( path );#endif        strokedPath.width( penWidth );        rasterizer.add_path( strokedPath );        agg::render_scanlines( rasterizer, scanline, render );    }}//END of Anti-Grain dependant code

⌨️ 快捷键说明

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