From a5d7d31d3388eae859226b70f8355304c6ddc9bc Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 17 Oct 2006 21:26:43 +0000 Subject: [PATCH] isolate the Xrender dependant code, so okular can be compile and work even without it svn path=/trunk/playground/graphics/okular/; revision=596572 --- CMakeLists.txt | 5 ++++- config-okular.h.cmake | 3 +++ ui/pageview.cpp | 48 ++++++++++++++++++++++++++++--------------- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3292a000e..852c7cf43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,7 +100,10 @@ kde4_add_plugin(okularpart WITH_PREFIX ${okularpart_SRCS}) kde4_install_libtool_file( ${PLUGIN_INSTALL_DIR} okularpart ) -target_link_libraries(okularpart okularcore ${KDE4_KPARTS_LIBS} ${KDE4_KDEPRINT_LIBS} ${KDE4_KNEWSTUFF_LIBS} ${KDE4_KHTML_LIBS} m ${X11_Xrender_LIB} ) +target_link_libraries(okularpart okularcore ${KDE4_KPARTS_LIBS} ${KDE4_KDEPRINT_LIBS} ${KDE4_KNEWSTUFF_LIBS} ${KDE4_KHTML_LIBS} m ) +if ( X11_Xrender_FOUND ) + target_link_libraries( okularpart ${X11_Xrender_LIB} ) +endif ( X11_Xrender_FOUND ) install(TARGETS okularpart DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/config-okular.h.cmake b/config-okular.h.cmake index 86a5ddad1..2d80a828e 100644 --- a/config-okular.h.cmake +++ b/config-okular.h.cmake @@ -1,5 +1,8 @@ /* Defines if force the use DRM in okular */ #define OKULAR_FORCE_DRM ${_OKULAR_FORCE_DRM} +/* Defines if the Xrender X11 extension if available */ +#define HAVE_XRENDER ${X11_Xrender_FOUND} + /* Defined if we have the HEAD version of the Poppler library */ #cmakedefine HAVE_POPPLER_HEAD 1 diff --git a/ui/pageview.cpp b/ui/pageview.cpp index b194b62e9..ab82765e2 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -16,13 +16,10 @@ * (at your option) any later version. * ***************************************************************************/ -#include -#include -#include - // qt/kde includes #include #include +#include #include #include #include @@ -69,6 +66,14 @@ #include "core/generator.h" #include "settings.h" +#include + +#ifdef HAVE_XRENDER +#include +#include +#include +#endif + #define ROUND(x) (int(x + 0.5)) static int pageflags = PagePainter::Accessibility | PagePainter::EnhanceLinks | @@ -748,15 +753,6 @@ void PageView::contentsPaintEvent(QPaintEvent *pe) QPainter pixmapPainter( &doubleBuffer ); pixmapPainter.translate( -contentsRect.left(), -contentsRect.top() ); - // calculate the color - XRenderColor col; - float alpha=0.2f; - QColor blCol=selBlendColor.dark(140); - col.red=(int)((float)( (blCol.red() << 8) | blCol.red() ) * alpha); - col.green=(int)((float)( (blCol.green() << 8) | blCol.green() )*alpha ); - col.blue=(int)((float)( (blCol.blue() << 8) | blCol.blue())*alpha ); - col.alpha=( int )(alpha*(float)0xffff); - // 1) Layer 0: paint items and clear bg on unpainted rects drawDocumentOnPainter( contentsRect, &pixmapPainter ); // 2) Layer 1a: paint (blend) transparent selection @@ -767,19 +763,39 @@ void PageView::contentsPaintEvent(QPaintEvent *pe) // skip rectangles covered by the selection's border if ( blendRect.isValid() ) { +#ifdef HAVE_XRENDER // grab current pixmap into a new one to colorize contents QPixmap blendedPixmap( blendRect.width(), blendRect.height() ); QPainter p( &blendedPixmap ); p.drawPixmap( 0, 0, doubleBuffer, blendRect.left() - contentsRect.left(), blendRect.top() - contentsRect.top(), blendRect.width(), blendRect.height() ); - // blend selBlendColor into the background pixmap - // QImage blendedImage = blendedPixmap.convertToImage(); - // KImageEffect::blend( selBlendColor.dark(140), blendedImage, 0.2 ); + + // calculate the color + XRenderColor col; + float alpha = 0.2f; + QColor blCol = selBlendColor.dark( 140 ); + col.red = (int)((float)( (blCol.red() << 8) | blCol.red() ) * alpha); + col.green = (int)((float)( (blCol.green() << 8) | blCol.green() )*alpha ); + col.blue = (int)((float)( (blCol.blue() << 8) | blCol.blue())*alpha ); + col.alpha = (int)(alpha*(float)0xffff); + XRenderFillRectangle(x11Info().display(), PictOpOver, blendedPixmap.x11PictureHandle(), &col, 0,0, blendRect.width(), blendRect.height()); // copy the blended pixmap back to its place pixmapPainter.drawPixmap( blendRect.left(), blendRect.top(), blendedPixmap ); +#else + // grab current pixmap into a new image to colorize contents + QImage blendedImage( blendRect.width(), blendRect.height(), QImage::Format_ARGB32 ); + QPainter p( &blendedImage ); + p.drawPixmap( 0, 0, doubleBuffer, + blendRect.left() - contentsRect.left(), blendRect.top() - contentsRect.top(), + blendRect.width(), blendRect.height() ); + + // blend selBlendColor into the background pixmap + KImageEffect::blend( selBlendColor.dark( 140 ), blendedImage, 0.2 ); + pixmapPainter.drawImage( blendRect.left(), blendRect.top(), blendedImage ); +#endif } // draw border (red if the selection is too small) pixmapPainter.setPen( selBlendColor );