isolate the Xrender dependant code, so okular can be compile and work even without it

svn path=/trunk/playground/graphics/okular/; revision=596572
remotes/origin/KDE/4.0
Pino Toscano 20 years ago
parent f699d7fa65
commit a5d7d31d33
  1. 5
      CMakeLists.txt
  2. 3
      config-okular.h.cmake
  3. 48
      ui/pageview.cpp

@ -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})

@ -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

@ -16,13 +16,10 @@
* (at your option) any later version. *
***************************************************************************/
#include <X11/Xlib.h>
#include <X11/extensions/Xrender.h>
#include <fixx11h.h>
// qt/kde includes
#include <qcursor.h>
#include <qevent.h>
#include <qimage.h>
#include <qpainter.h>
#include <qtimer.h>
#include <qdatetime.h>
@ -69,6 +66,14 @@
#include "core/generator.h"
#include "settings.h"
#include <config-okular.h>
#ifdef HAVE_XRENDER
#include <X11/Xlib.h>
#include <X11/extensions/Xrender.h>
#include <fixx11h.h>
#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 );

Loading…
Cancel
Save