2005-01-27 17:31:07 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2005 by Enrico Ros <eros.kde@email.it> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2007-04-19 18:30:20 +00:00
|
|
|
#include "pagepainter.h"
|
|
|
|
|
2005-01-27 17:31:07 +00:00
|
|
|
// qt / kde includes
|
|
|
|
#include <qrect.h>
|
|
|
|
#include <qpainter.h>
|
2007-01-03 00:17:31 +00:00
|
|
|
#include <qpalette.h>
|
2005-01-27 17:31:07 +00:00
|
|
|
#include <qpixmap.h>
|
2006-09-19 09:09:30 +00:00
|
|
|
#include <qvarlengtharray.h>
|
2005-03-24 19:59:11 +00:00
|
|
|
#include <kiconloader.h>
|
2005-07-15 18:20:57 +00:00
|
|
|
#include <kdebug.h>
|
2007-01-09 11:02:04 +00:00
|
|
|
#include <QApplication>
|
2007-09-11 07:36:54 +00:00
|
|
|
#include <qimageblitz.h>
|
2007-04-19 18:30:20 +00:00
|
|
|
|
2005-04-10 13:47:00 +00:00
|
|
|
// system includes
|
|
|
|
#include <math.h>
|
|
|
|
|
2005-01-27 17:31:07 +00:00
|
|
|
// local includes
|
2005-07-15 18:20:57 +00:00
|
|
|
#include "core/area.h"
|
2005-01-27 17:31:07 +00:00
|
|
|
#include "core/page.h"
|
2005-02-18 18:24:45 +00:00
|
|
|
#include "core/annotations.h"
|
2006-11-19 00:46:01 +00:00
|
|
|
#include "core/utils.h"
|
2006-03-28 22:22:10 +00:00
|
|
|
#include "settings.h"
|
2005-02-09 17:51:58 +00:00
|
|
|
|
2007-10-03 14:50:20 +00:00
|
|
|
K_GLOBAL_STATIC_WITH_ARGS( QPixmap, busyPixmap, ( KIconLoader::global()->loadIcon("graphics-viewer-document", KIconLoader::NoGroup, 32, KIconLoader::DefaultState, QStringList(), 0, true) ) )
|
2006-07-02 15:53:26 +00:00
|
|
|
|
2006-09-19 10:19:13 +00:00
|
|
|
#define TEXTANNOTATION_ICONSIZE 24
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
void PagePainter::paintPageOnPainter( QPainter * destPainter, const Okular::Page * page,
|
2006-11-20 07:53:32 +00:00
|
|
|
int pixID, int flags, int scaledWidth, int scaledHeight, const QRect &limits )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
2005-03-24 19:59:11 +00:00
|
|
|
/** 1 - RETRIEVE THE 'PAGE+ID' PIXMAP OR A SIMILAR 'PAGE' ONE **/
|
2007-03-25 22:36:41 +00:00
|
|
|
const QPixmap * pixmap = page->_o_nearestPixmap( pixID, scaledWidth, scaledHeight );
|
2005-01-27 17:31:07 +00:00
|
|
|
|
2007-09-23 15:30:31 +00:00
|
|
|
QColor color = Qt::white;
|
|
|
|
if ( Okular::Settings::changeColors() )
|
|
|
|
{
|
|
|
|
switch ( Okular::Settings::renderMode() )
|
|
|
|
{
|
|
|
|
case Okular::Settings::EnumRenderMode::Inverted:
|
|
|
|
color = Qt::black;
|
|
|
|
break;
|
|
|
|
case Okular::Settings::EnumRenderMode::Paper:
|
|
|
|
color = Okular::Settings::paperColor();
|
|
|
|
break;
|
|
|
|
case Okular::Settings::EnumRenderMode::Recolor:
|
|
|
|
color = Okular::Settings::recolorBackground();
|
|
|
|
break;
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
destPainter->fillRect( limits, color );
|
|
|
|
|
2005-03-24 19:59:11 +00:00
|
|
|
/** 1B - IF NO PIXMAP, DRAW EMPTY PAGE **/
|
2006-11-20 07:53:32 +00:00
|
|
|
double pixmapRescaleRatio = pixmap ? scaledWidth / (double)pixmap->width() : -1;
|
|
|
|
long pixmapPixels = pixmap ? (long)pixmap->width() * (long)pixmap->height() : 0;
|
|
|
|
if ( !pixmap || pixmapRescaleRatio > 20.0 || pixmapRescaleRatio < 0.25 ||
|
|
|
|
(scaledWidth != pixmap->width() && pixmapPixels > 6000000L) )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
2006-07-02 15:53:26 +00:00
|
|
|
// draw something on the blank page: the okular icon or a cross (as a fallback)
|
2007-04-21 10:44:18 +00:00
|
|
|
if ( !busyPixmap->isNull() )
|
2006-07-02 15:53:26 +00:00
|
|
|
{
|
|
|
|
destPainter->drawPixmap( QPoint( 10, 10 ), *busyPixmap );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
destPainter->setPen( Qt::gray );
|
|
|
|
destPainter->drawLine( 0, 0, scaledWidth-1, scaledHeight-1 );
|
|
|
|
destPainter->drawLine( 0, scaledHeight-1, scaledWidth-1, 0 );
|
|
|
|
}
|
2005-01-27 17:31:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-03-24 19:59:11 +00:00
|
|
|
/** 2 - FIND OUT WHAT TO PAINT (Flags + Configuration + Presence) **/
|
2005-04-08 15:45:40 +00:00
|
|
|
bool canDrawHighlights = (flags & Highlights) && !page->m_highlights.isEmpty();
|
2007-03-30 14:08:20 +00:00
|
|
|
bool canDrawTextSelection = (flags & TextSelection) && page->textSelection();
|
2005-04-08 15:45:40 +00:00
|
|
|
bool canDrawAnnotations = (flags & Annotations) && !page->m_annotations.isEmpty();
|
2006-09-21 08:45:36 +00:00
|
|
|
bool enhanceLinks = (flags & EnhanceLinks) && Okular::Settings::highlightLinks();
|
|
|
|
bool enhanceImages = (flags & EnhanceImages) && Okular::Settings::highlightImages();
|
2005-04-08 15:45:40 +00:00
|
|
|
// vectors containing objects to draw
|
2006-10-21 22:07:05 +00:00
|
|
|
// make this a qcolor, rect map, since we don't need
|
2005-07-15 18:20:57 +00:00
|
|
|
// to know s_id here! we are only drawing this right?
|
2006-12-24 18:19:18 +00:00
|
|
|
QList< QPair<QColor, Okular::NormalizedRect> > * bufferedHighlights = 0;
|
2006-09-21 08:45:36 +00:00
|
|
|
QList< Okular::Annotation * > * bufferedAnnotations = 0;
|
|
|
|
QList< Okular::Annotation * > * unbufferedAnnotations = 0;
|
2006-09-26 22:22:01 +00:00
|
|
|
// fill up lists with visible annotation/highlight objects/text selections
|
|
|
|
if ( canDrawHighlights || canDrawTextSelection || canDrawAnnotations )
|
2005-02-02 18:18:26 +00:00
|
|
|
{
|
2005-02-03 17:09:33 +00:00
|
|
|
// precalc normalized 'limits rect' for intersection
|
2005-04-01 13:54:26 +00:00
|
|
|
double nXMin = (double)limits.left() / (double)scaledWidth,
|
|
|
|
nXMax = (double)limits.right() / (double)scaledWidth,
|
|
|
|
nYMin = (double)limits.top() / (double)scaledHeight,
|
|
|
|
nYMax = (double)limits.bottom() / (double)scaledHeight;
|
2005-04-08 15:45:40 +00:00
|
|
|
// append all highlights inside limits to their list
|
|
|
|
if ( canDrawHighlights )
|
2005-02-02 18:18:26 +00:00
|
|
|
{
|
2005-07-15 18:20:57 +00:00
|
|
|
if ( !bufferedHighlights )
|
2006-12-24 18:19:18 +00:00
|
|
|
bufferedHighlights = new QList< QPair<QColor, Okular::NormalizedRect> >();
|
2005-07-15 18:20:57 +00:00
|
|
|
/* else
|
|
|
|
{*/
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::NormalizedRect* limitRect = new Okular::NormalizedRect(nXMin, nYMin, nXMax, nYMax );
|
|
|
|
QLinkedList< Okular::HighlightAreaRect * >::const_iterator h2It = page->m_highlights.begin(), hEnd = page->m_highlights.end();
|
2006-12-24 18:19:18 +00:00
|
|
|
Okular::HighlightAreaRect::const_iterator hIt;
|
2005-07-15 18:20:57 +00:00
|
|
|
for ( ; h2It != hEnd; ++h2It )
|
|
|
|
for (hIt=(*h2It)->begin(); hIt!=(*h2It)->end(); ++hIt)
|
|
|
|
{
|
2006-12-24 18:19:18 +00:00
|
|
|
if ((*hIt).intersects(limitRect))
|
2005-07-15 18:20:57 +00:00
|
|
|
bufferedHighlights->append( qMakePair((*h2It)->color,*hIt) );
|
|
|
|
}
|
2006-09-26 22:22:01 +00:00
|
|
|
delete limitRect;
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
if ( canDrawTextSelection )
|
|
|
|
{
|
|
|
|
if ( !bufferedHighlights )
|
2006-12-24 18:19:18 +00:00
|
|
|
bufferedHighlights = new QList< QPair<QColor, Okular::NormalizedRect> >();
|
2006-09-26 22:22:01 +00:00
|
|
|
/* else
|
|
|
|
{*/
|
|
|
|
Okular::NormalizedRect* limitRect = new Okular::NormalizedRect(nXMin, nYMin, nXMax, nYMax );
|
2007-03-30 14:08:20 +00:00
|
|
|
const Okular::RegularAreaRect *textSelection = page->textSelection();
|
|
|
|
Okular::HighlightAreaRect::const_iterator hIt = textSelection->begin(), hEnd = textSelection->end();
|
2006-09-26 22:22:01 +00:00
|
|
|
for ( ; hIt != hEnd; ++hIt )
|
|
|
|
{
|
2006-12-24 18:19:18 +00:00
|
|
|
if ( (*hIt).intersects( limitRect ) )
|
2007-03-30 14:08:20 +00:00
|
|
|
bufferedHighlights->append( qMakePair( page->textSelectionColor(), *hIt ) );
|
2006-09-26 22:22:01 +00:00
|
|
|
}
|
2005-07-15 18:20:57 +00:00
|
|
|
delete limitRect;
|
|
|
|
//}
|
2005-03-24 19:59:11 +00:00
|
|
|
}
|
2005-04-08 15:45:40 +00:00
|
|
|
// append annotations inside limits to the un/buffered list
|
|
|
|
if ( canDrawAnnotations )
|
2005-03-24 19:59:11 +00:00
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
QLinkedList< Okular::Annotation * >::const_iterator aIt = page->m_annotations.begin(), aEnd = page->m_annotations.end();
|
2005-03-24 19:59:11 +00:00
|
|
|
for ( ; aIt != aEnd; ++aIt )
|
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::Annotation * ann = *aIt;
|
2007-09-10 21:34:07 +00:00
|
|
|
if ( ann->flags() & ( Okular::Annotation::Hidden | Okular::Annotation::External ) )
|
2006-09-14 18:42:28 +00:00
|
|
|
continue;
|
|
|
|
|
2006-12-05 11:05:50 +00:00
|
|
|
bool intersects = ann->transformedBoundingRectangle().intersects( nXMin, nYMin, nXMax, nYMax );
|
2006-09-21 08:45:36 +00:00
|
|
|
if ( ann->subType() == Okular::Annotation::AText )
|
2006-09-19 10:19:13 +00:00
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::TextAnnotation * ta = static_cast< Okular::TextAnnotation * >( ann );
|
2006-12-11 07:59:02 +00:00
|
|
|
if ( ta->textType() == Okular::TextAnnotation::Linked )
|
2006-09-19 10:19:13 +00:00
|
|
|
{
|
2006-12-05 11:05:50 +00:00
|
|
|
Okular::NormalizedRect iconrect( ann->transformedBoundingRectangle().left,
|
|
|
|
ann->transformedBoundingRectangle().top,
|
|
|
|
ann->transformedBoundingRectangle().left + TEXTANNOTATION_ICONSIZE / page->width(),
|
|
|
|
ann->transformedBoundingRectangle().top + TEXTANNOTATION_ICONSIZE / page->height() );
|
2006-09-19 10:19:13 +00:00
|
|
|
intersects = iconrect.intersects( nXMin, nYMin, nXMax, nYMax );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( intersects )
|
2005-03-24 19:59:11 +00:00
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::Annotation::SubType type = ann->subType();
|
|
|
|
if ( type == Okular::Annotation::ALine || type == Okular::Annotation::AHighlight ||
|
2006-12-05 11:05:50 +00:00
|
|
|
type == Okular::Annotation::AInk /*|| (type == Annotation::AGeom && ann->style().opacity() < 0.99)*/ )
|
2005-04-08 15:45:40 +00:00
|
|
|
{
|
|
|
|
if ( !bufferedAnnotations )
|
2006-09-21 08:45:36 +00:00
|
|
|
bufferedAnnotations = new QList< Okular::Annotation * >();
|
2005-04-08 15:45:40 +00:00
|
|
|
bufferedAnnotations->append( ann );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( !unbufferedAnnotations )
|
2006-09-21 08:45:36 +00:00
|
|
|
unbufferedAnnotations = new QList< Okular::Annotation * >();
|
2005-04-08 15:45:40 +00:00
|
|
|
unbufferedAnnotations->append( ann );
|
|
|
|
}
|
2005-03-24 19:59:11 +00:00
|
|
|
}
|
2005-02-02 18:18:26 +00:00
|
|
|
}
|
|
|
|
}
|
2005-04-08 15:45:40 +00:00
|
|
|
// end of intersections checking
|
2005-02-18 18:24:45 +00:00
|
|
|
}
|
2005-02-02 18:18:26 +00:00
|
|
|
|
2005-03-24 19:59:11 +00:00
|
|
|
/** 3 - ENABLE BACKBUFFERING IF DIRECT IMAGE MANIPULATION IS NEEDED **/
|
2006-09-21 08:45:36 +00:00
|
|
|
bool bufferAccessibility = (flags & Accessibility) && Okular::Settings::changeColors() && (Okular::Settings::renderMode() != Okular::Settings::EnumRenderMode::Paper);
|
2005-04-08 15:45:40 +00:00
|
|
|
bool useBackBuffer = bufferAccessibility || bufferedHighlights || bufferedAnnotations;
|
2005-01-27 17:31:07 +00:00
|
|
|
QPixmap * backPixmap = 0;
|
2005-04-01 13:54:26 +00:00
|
|
|
QPainter * mixedPainter = 0;
|
2005-03-24 19:59:11 +00:00
|
|
|
|
|
|
|
/** 4A -- REGULAR FLOW. PAINT PIXMAP NORMAL OR RESCALED USING GIVEN QPAINTER **/
|
|
|
|
if ( !useBackBuffer )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
2005-03-24 19:59:11 +00:00
|
|
|
// 4A.1. if size is ok, draw the page pixmap using painter
|
2006-11-20 07:53:32 +00:00
|
|
|
if ( pixmap->width() == scaledWidth && pixmap->height() == scaledHeight )
|
|
|
|
destPainter->drawPixmap( limits.topLeft(), *pixmap, limits );
|
|
|
|
|
2005-03-24 19:59:11 +00:00
|
|
|
// else draw a scaled portion of the magnified pixmap
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QImage destImage;
|
2006-11-20 07:53:32 +00:00
|
|
|
scalePixmapOnImage( destImage, pixmap, scaledWidth, scaledHeight, limits );
|
2006-03-23 19:02:55 +00:00
|
|
|
destPainter->drawImage( limits.left(), limits.top(), destImage, 0, 0,
|
2005-03-24 19:59:11 +00:00
|
|
|
limits.width(),limits.height() );
|
|
|
|
}
|
2005-01-27 17:31:07 +00:00
|
|
|
|
2005-03-24 19:59:11 +00:00
|
|
|
// 4A.2. active painter is the one passed to this method
|
2005-04-01 13:54:26 +00:00
|
|
|
mixedPainter = destPainter;
|
2005-03-24 19:59:11 +00:00
|
|
|
}
|
|
|
|
/** 4B -- BUFFERED FLOW. IMAGE PAINTING + OPERATIONS. QPAINTER OVER PIXMAP **/
|
2005-01-27 17:31:07 +00:00
|
|
|
else
|
|
|
|
{
|
2005-03-24 19:59:11 +00:00
|
|
|
// the image over which we are going to draw
|
|
|
|
QImage backImage;
|
2005-01-27 17:31:07 +00:00
|
|
|
|
2005-03-24 19:59:11 +00:00
|
|
|
// 4B.1. draw the page pixmap: normal or scaled
|
2006-11-20 07:53:32 +00:00
|
|
|
if ( pixmap->width() == scaledWidth && pixmap->height() == scaledHeight )
|
|
|
|
cropPixmapOnImage( backImage, pixmap, limits );
|
2005-03-24 19:59:11 +00:00
|
|
|
else
|
2006-11-20 07:53:32 +00:00
|
|
|
scalePixmapOnImage( backImage, pixmap, scaledWidth, scaledHeight, limits );
|
2005-03-24 19:59:11 +00:00
|
|
|
|
|
|
|
// 4B.2. modify pixmap following accessibility settings
|
2005-04-08 15:45:40 +00:00
|
|
|
if ( bufferAccessibility )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
switch ( Okular::Settings::renderMode() )
|
2005-02-03 17:09:33 +00:00
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
case Okular::Settings::EnumRenderMode::Inverted:
|
2005-02-03 17:09:33 +00:00
|
|
|
// Invert image pixels using QImage internal function
|
2006-04-05 17:49:44 +00:00
|
|
|
backImage.invertPixels(QImage::InvertRgb);
|
2005-02-03 17:09:33 +00:00
|
|
|
break;
|
2006-09-21 08:45:36 +00:00
|
|
|
case Okular::Settings::EnumRenderMode::Recolor:
|
2007-09-07 22:52:11 +00:00
|
|
|
// Recolor image using Blitz::flatten with dither:0
|
|
|
|
Blitz::flatten( backImage, Okular::Settings::recolorForeground(), Okular::Settings::recolorBackground() );
|
2005-02-03 17:09:33 +00:00
|
|
|
break;
|
2006-09-21 08:45:36 +00:00
|
|
|
case Okular::Settings::EnumRenderMode::BlackWhite:
|
2005-02-03 17:09:33 +00:00
|
|
|
// Manual Gray and Contrast
|
|
|
|
unsigned int * data = (unsigned int *)backImage.bits();
|
|
|
|
int val, pixels = backImage.width() * backImage.height(),
|
2006-09-21 08:45:36 +00:00
|
|
|
con = Okular::Settings::bWContrast(), thr = 255 - Okular::Settings::bWThreshold();
|
2005-02-03 17:09:33 +00:00
|
|
|
for( int i = 0; i < pixels; ++i )
|
|
|
|
{
|
|
|
|
val = qGray( data[i] );
|
|
|
|
if ( val > thr )
|
|
|
|
val = 128 + (127 * (val - thr)) / (255 - thr);
|
|
|
|
else if ( val < thr )
|
|
|
|
val = (128 * val) / thr;
|
|
|
|
if ( con > 2 )
|
|
|
|
{
|
|
|
|
val = con * ( val - thr ) / 2 + thr;
|
|
|
|
if ( val > 255 )
|
|
|
|
val = 255;
|
|
|
|
else if ( val < 0 )
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
data[i] = qRgba( val, val, val, 255 );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-03-24 19:59:11 +00:00
|
|
|
// 4B.3. highlight rects in page
|
2005-04-08 15:45:40 +00:00
|
|
|
if ( bufferedHighlights )
|
2005-02-03 17:09:33 +00:00
|
|
|
{
|
|
|
|
// draw highlights that are inside the 'limits' paint region
|
2006-12-24 18:19:18 +00:00
|
|
|
QList< QPair<QColor, Okular::NormalizedRect> >::const_iterator hIt = bufferedHighlights->begin(), hEnd = bufferedHighlights->end();
|
2005-02-03 17:09:33 +00:00
|
|
|
for ( ; hIt != hEnd; ++hIt )
|
|
|
|
{
|
2006-12-24 18:19:18 +00:00
|
|
|
const Okular::NormalizedRect & r = (*hIt).second;
|
2005-04-08 15:45:40 +00:00
|
|
|
// find out the rect to highlight on pixmap
|
2006-12-24 18:19:18 +00:00
|
|
|
QRect highlightRect = r.geometry( scaledWidth, scaledHeight ).intersect( limits );
|
2006-03-29 16:46:09 +00:00
|
|
|
highlightRect.translate( -limits.left(), -limits.top() );
|
2005-04-08 15:45:40 +00:00
|
|
|
|
|
|
|
// highlight composition (product: highlight color * destcolor)
|
|
|
|
unsigned int * data = (unsigned int *)backImage.bits();
|
|
|
|
int val, newR, newG, newB,
|
2005-07-15 18:20:57 +00:00
|
|
|
rh = (*hIt).first.red(),
|
|
|
|
gh = (*hIt).first.green(),
|
|
|
|
bh = (*hIt).first.blue(),
|
2005-04-08 15:45:40 +00:00
|
|
|
offset = highlightRect.top() * backImage.width();
|
|
|
|
for( int y = highlightRect.top(); y <= highlightRect.bottom(); ++y )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
2005-04-08 15:45:40 +00:00
|
|
|
for( int x = highlightRect.left(); x <= highlightRect.right(); ++x )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
2005-04-08 15:45:40 +00:00
|
|
|
val = data[ x + offset ];
|
|
|
|
newR = (qRed(val) * rh) / 255;
|
|
|
|
newG = (qGreen(val) * gh) / 255;
|
|
|
|
newB = (qBlue(val) * bh) / 255;
|
|
|
|
data[ x + offset ] = qRgba( newR, newG, newB, 255 );
|
2005-01-27 17:31:07 +00:00
|
|
|
}
|
2005-04-08 15:45:40 +00:00
|
|
|
offset += backImage.width();
|
2005-01-27 17:31:07 +00:00
|
|
|
}
|
2005-02-03 17:09:33 +00:00
|
|
|
}
|
2005-01-27 17:31:07 +00:00
|
|
|
}
|
2005-03-24 19:59:11 +00:00
|
|
|
// 4B.4. paint annotations [COMPOSITED ONES]
|
2005-04-08 15:45:40 +00:00
|
|
|
if ( bufferedAnnotations )
|
2005-02-18 18:24:45 +00:00
|
|
|
{
|
2007-09-05 22:01:04 +00:00
|
|
|
// Albert: This is quite "heavy" but all the backImage that reach here are QImage::Format_ARGB32_Premultiplied
|
|
|
|
// and have to be so that the QPainter::CompositionMode_Multiply works
|
|
|
|
// we could also put a
|
|
|
|
// backImage = backImage.convertToFormat(QImage::Format_ARGB32_Premultiplied)
|
|
|
|
// that would be almost a noop, but we'll leave the assert for now
|
|
|
|
Q_ASSERT(backImage.format() == QImage::Format_ARGB32_Premultiplied);
|
2005-04-12 20:44:26 +00:00
|
|
|
// precalc costants for normalizing the quads to the image
|
2005-04-13 21:23:54 +00:00
|
|
|
double pageScale = (double)scaledWidth / page->width();
|
|
|
|
double xOffset = (double)limits.left() / (double)scaledWidth,
|
|
|
|
xScale = (double)scaledWidth / (double)limits.width(),
|
|
|
|
yOffset = (double)limits.top() / (double)scaledHeight,
|
|
|
|
yScale = (double)scaledHeight / (double)limits.height();
|
2005-04-12 20:44:26 +00:00
|
|
|
|
|
|
|
// paint all buffered annotations in the page
|
2006-09-21 08:45:36 +00:00
|
|
|
QList< Okular::Annotation * >::const_iterator aIt = bufferedAnnotations->begin(), aEnd = bufferedAnnotations->end();
|
2005-04-10 13:47:00 +00:00
|
|
|
for ( ; aIt != aEnd; ++aIt )
|
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::Annotation * a = *aIt;
|
|
|
|
Okular::Annotation::SubType type = a->subType();
|
2007-09-10 08:51:43 +00:00
|
|
|
QColor acolor( a->style().color().red(), a->style().color().green(), a->style().color().blue(), (int)( 255.0 * a->style().opacity() ) );
|
2005-04-10 13:47:00 +00:00
|
|
|
|
2005-04-12 20:44:26 +00:00
|
|
|
// draw LineAnnotation MISSING: all
|
2006-09-21 08:45:36 +00:00
|
|
|
if ( type == Okular::Annotation::ALine )
|
2006-07-13 15:03:18 +00:00
|
|
|
{
|
|
|
|
// get the annotation
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::LineAnnotation * la = (Okular::LineAnnotation *) a;
|
2006-07-13 15:03:18 +00:00
|
|
|
|
|
|
|
NormalizedPath path;
|
|
|
|
// normalize page point to image
|
2006-12-11 07:59:02 +00:00
|
|
|
const QLinkedList<Okular::NormalizedPoint> points = la->transformedLinePoints();
|
|
|
|
QLinkedList<Okular::NormalizedPoint>::const_iterator it = points.begin();
|
|
|
|
QLinkedList<Okular::NormalizedPoint>::const_iterator itEnd = points.end();
|
2006-09-11 11:51:10 +00:00
|
|
|
for ( ; it != itEnd; ++it )
|
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::NormalizedPoint point;
|
2006-09-11 11:51:10 +00:00
|
|
|
point.x = ( (*it).x - xOffset) * xScale;
|
|
|
|
point.y = ( (*it).y - yOffset) * yScale;
|
|
|
|
path.append( point );
|
|
|
|
}
|
|
|
|
|
2006-07-13 15:03:18 +00:00
|
|
|
// draw the line as normalized path into image
|
2006-12-11 07:59:02 +00:00
|
|
|
drawShapeOnImage( backImage, path, la->lineClosed(),
|
2006-12-05 11:05:50 +00:00
|
|
|
QPen( a->style().color(), a->style().width() ),
|
|
|
|
QBrush(), pageScale ,Multiply);
|
2006-07-08 17:52:42 +00:00
|
|
|
|
2006-12-11 07:59:02 +00:00
|
|
|
if ( path.count() == 2 && fabs( la->lineLeadingForwardPoint() ) > 0.1 )
|
2006-09-16 14:58:32 +00:00
|
|
|
{
|
2006-12-11 07:59:02 +00:00
|
|
|
Okular::NormalizedPoint delta( la->transformedLinePoints().last().x - la->transformedLinePoints().first().x, la->transformedLinePoints().first().y - la->transformedLinePoints().last().y );
|
2006-09-16 14:58:32 +00:00
|
|
|
double angle = atan2( delta.y, delta.x );
|
|
|
|
if ( delta.y < 0 )
|
|
|
|
angle += 2 * M_PI;
|
|
|
|
|
2006-12-11 07:59:02 +00:00
|
|
|
int sign = la->lineLeadingForwardPoint() > 0.0 ? 1 : -1;
|
|
|
|
double LLx = fabs( la->lineLeadingForwardPoint() ) * cos( angle + sign * M_PI_2 + 2 * M_PI ) / page->width();
|
|
|
|
double LLy = fabs( la->lineLeadingForwardPoint() ) * sin( angle + sign * M_PI_2 + 2 * M_PI ) / page->height();
|
2006-09-16 14:58:32 +00:00
|
|
|
|
|
|
|
NormalizedPath path2;
|
|
|
|
NormalizedPath path3;
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::NormalizedPoint point;
|
2006-12-11 07:59:02 +00:00
|
|
|
point.x = ( la->transformedLinePoints().first().x + LLx - xOffset ) * xScale;
|
|
|
|
point.y = ( la->transformedLinePoints().first().y - LLy - yOffset ) * yScale;
|
2006-09-16 14:58:32 +00:00
|
|
|
path2.append( point );
|
2006-12-11 07:59:02 +00:00
|
|
|
point.x = ( la->transformedLinePoints().last().x + LLx - xOffset ) * xScale;
|
|
|
|
point.y = ( la->transformedLinePoints().last().y - LLy - yOffset ) * yScale;
|
2006-09-16 14:58:32 +00:00
|
|
|
path3.append( point );
|
|
|
|
// do we have the extension on the "back"?
|
2006-12-11 07:59:02 +00:00
|
|
|
if ( fabs( la->lineLeadingBackwardPoint() ) > 0.1 )
|
2006-09-16 14:58:32 +00:00
|
|
|
{
|
2006-12-11 07:59:02 +00:00
|
|
|
double LLEx = la->lineLeadingBackwardPoint() * cos( angle - sign * M_PI_2 + 2 * M_PI ) / page->width();
|
|
|
|
double LLEy = la->lineLeadingBackwardPoint() * sin( angle - sign * M_PI_2 + 2 * M_PI ) / page->height();
|
|
|
|
point.x = ( la->transformedLinePoints().first().x + LLEx - xOffset ) * xScale;
|
|
|
|
point.y = ( la->transformedLinePoints().first().y - LLEy - yOffset ) * yScale;
|
2006-09-16 14:58:32 +00:00
|
|
|
path2.append( point );
|
2006-12-11 07:59:02 +00:00
|
|
|
point.x = ( la->transformedLinePoints().last().x + LLEx - xOffset ) * xScale;
|
|
|
|
point.y = ( la->transformedLinePoints().last().y - LLEy - yOffset ) * yScale;
|
2006-09-16 14:58:32 +00:00
|
|
|
path3.append( point );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path2.append( path[0] );
|
|
|
|
path3.append( path[1] );
|
|
|
|
}
|
|
|
|
|
2006-12-05 11:05:50 +00:00
|
|
|
drawShapeOnImage( backImage, path2, false, QPen( a->style().color(), a->style().width() ), QBrush(), pageScale, Multiply );
|
|
|
|
drawShapeOnImage( backImage, path3, false, QPen( a->style().color(), a->style().width() ), QBrush(), pageScale, Multiply );
|
2006-09-16 14:58:32 +00:00
|
|
|
}
|
2005-04-12 20:44:26 +00:00
|
|
|
}
|
|
|
|
// draw HighlightAnnotation MISSING: under/strike width, feather, capping
|
2006-09-21 08:45:36 +00:00
|
|
|
else if ( type == Okular::Annotation::AHighlight )
|
2005-04-10 13:47:00 +00:00
|
|
|
{
|
|
|
|
// get the annotation
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::HighlightAnnotation * ha = (Okular::HighlightAnnotation *) a;
|
2006-12-11 07:59:02 +00:00
|
|
|
Okular::HighlightAnnotation::HighlightType type = ha->highlightType();
|
2005-04-10 13:47:00 +00:00
|
|
|
|
|
|
|
// draw each quad of the annotation
|
2006-12-11 07:59:02 +00:00
|
|
|
int quads = ha->highlightQuads().size();
|
2005-04-10 13:47:00 +00:00
|
|
|
for ( int q = 0; q < quads; q++ )
|
|
|
|
{
|
|
|
|
NormalizedPath path;
|
2006-12-11 07:59:02 +00:00
|
|
|
const Okular::HighlightAnnotation::Quad & quad = ha->highlightQuads()[ q ];
|
2005-04-12 20:44:26 +00:00
|
|
|
// normalize page point to image
|
2005-04-10 13:47:00 +00:00
|
|
|
for ( int i = 0; i < 4; i++ )
|
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::NormalizedPoint point;
|
2006-12-11 07:59:02 +00:00
|
|
|
point.x = (quad.transformedPoint( i ).x - xOffset) * xScale;
|
|
|
|
point.y = (quad.transformedPoint( i ).y - yOffset) * yScale;
|
2005-04-10 13:47:00 +00:00
|
|
|
path.append( point );
|
|
|
|
}
|
2005-04-12 20:44:26 +00:00
|
|
|
// draw the normalized path into image
|
|
|
|
switch ( type )
|
|
|
|
{
|
|
|
|
// highlight the whole rect
|
2006-09-21 08:45:36 +00:00
|
|
|
case Okular::HighlightAnnotation::Highlight:
|
2007-09-10 08:51:43 +00:00
|
|
|
drawShapeOnImage( backImage, path, true, Qt::NoPen, acolor, pageScale, Multiply );
|
2005-04-12 20:44:26 +00:00
|
|
|
break;
|
|
|
|
// highlight the bottom part of the rect
|
2006-09-21 08:45:36 +00:00
|
|
|
case Okular::HighlightAnnotation::Squiggly:
|
2006-10-29 09:50:57 +00:00
|
|
|
path[ 3 ].x = ( path[ 0 ].x + path[ 3 ].x ) / 2.0;
|
|
|
|
path[ 3 ].y = ( path[ 0 ].y + path[ 3 ].y ) / 2.0;
|
|
|
|
path[ 2 ].x = ( path[ 1 ].x + path[ 2 ].x ) / 2.0;
|
|
|
|
path[ 2 ].y = ( path[ 1 ].y + path[ 2 ].y ) / 2.0;
|
2007-09-10 08:51:43 +00:00
|
|
|
drawShapeOnImage( backImage, path, true, Qt::NoPen, acolor, pageScale, Multiply );
|
2005-04-12 20:44:26 +00:00
|
|
|
break;
|
|
|
|
// make a line at 3/4 of the height
|
2006-09-21 08:45:36 +00:00
|
|
|
case Okular::HighlightAnnotation::Underline:
|
2006-10-29 09:50:57 +00:00
|
|
|
path[ 0 ].x = ( 3 * path[ 0 ].x + path[ 3 ].x ) / 4.0;
|
|
|
|
path[ 0 ].y = ( 3 * path[ 0 ].y + path[ 3 ].y ) / 4.0;
|
|
|
|
path[ 1 ].x = ( 3 * path[ 1 ].x + path[ 2 ].x ) / 4.0;
|
|
|
|
path[ 1 ].y = ( 3 * path[ 1 ].y + path[ 2 ].y ) / 4.0;
|
2005-04-12 20:44:26 +00:00
|
|
|
path.pop_back();
|
|
|
|
path.pop_back();
|
2007-09-10 08:51:43 +00:00
|
|
|
drawShapeOnImage( backImage, path, false, QPen( acolor, 2 ), QBrush(), pageScale );
|
2005-04-12 20:44:26 +00:00
|
|
|
break;
|
|
|
|
// make a line at 1/2 of the height
|
2006-09-21 08:45:36 +00:00
|
|
|
case Okular::HighlightAnnotation::StrikeOut:
|
2005-04-12 20:44:26 +00:00
|
|
|
path[ 0 ].x = ( path[ 0 ].x + path[ 3 ].x ) / 2.0;
|
|
|
|
path[ 0 ].y = ( path[ 0 ].y + path[ 3 ].y ) / 2.0;
|
|
|
|
path[ 1 ].x = ( path[ 1 ].x + path[ 2 ].x ) / 2.0;
|
|
|
|
path[ 1 ].y = ( path[ 1 ].y + path[ 2 ].y ) / 2.0;
|
|
|
|
path.pop_back();
|
|
|
|
path.pop_back();
|
2007-09-10 08:51:43 +00:00
|
|
|
drawShapeOnImage( backImage, path, false, QPen( acolor, 2 ), QBrush(), pageScale );
|
2005-04-12 20:44:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-04-10 13:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
2005-04-12 20:44:26 +00:00
|
|
|
// draw InkAnnotation MISSING:invar width, PENTRACER
|
2006-09-21 08:45:36 +00:00
|
|
|
else if ( type == Okular::Annotation::AInk )
|
2005-04-12 20:44:26 +00:00
|
|
|
{
|
|
|
|
// get the annotation
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::InkAnnotation * ia = (Okular::InkAnnotation *) a;
|
2005-04-12 20:44:26 +00:00
|
|
|
|
|
|
|
// draw each ink path
|
2006-12-11 07:59:02 +00:00
|
|
|
const QList< QLinkedList<Okular::NormalizedPoint> > transformedInkPaths = ia->transformedInkPaths();
|
|
|
|
|
|
|
|
int paths = transformedInkPaths.size();
|
2005-04-12 20:44:26 +00:00
|
|
|
for ( int p = 0; p < paths; p++ )
|
|
|
|
{
|
|
|
|
NormalizedPath path;
|
2006-12-11 07:59:02 +00:00
|
|
|
const QLinkedList<Okular::NormalizedPoint> & inkPath = transformedInkPaths[ p ];
|
2005-04-12 20:44:26 +00:00
|
|
|
|
|
|
|
// normalize page point to image
|
2006-09-21 08:45:36 +00:00
|
|
|
QLinkedList<Okular::NormalizedPoint>::const_iterator pIt = inkPath.begin(), pEnd = inkPath.end();
|
2005-04-12 20:44:26 +00:00
|
|
|
for ( ; pIt != pEnd; ++pIt )
|
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
const Okular::NormalizedPoint & inkPoint = *pIt;
|
|
|
|
Okular::NormalizedPoint point;
|
2005-04-12 20:44:26 +00:00
|
|
|
point.x = (inkPoint.x - xOffset) * xScale;
|
|
|
|
point.y = (inkPoint.y - yOffset) * yScale;
|
|
|
|
path.append( point );
|
|
|
|
}
|
|
|
|
// draw the normalized path into image
|
2006-12-05 11:05:50 +00:00
|
|
|
drawShapeOnImage( backImage, path, false, QPen( acolor, a->style().width() ), QBrush(), pageScale );
|
2005-04-12 20:44:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // end current annotation drawing
|
|
|
|
}
|
2005-03-24 19:59:11 +00:00
|
|
|
|
2006-05-13 14:48:16 +00:00
|
|
|
// 4B.5. create the back pixmap converting from the local image
|
2006-08-30 14:17:22 +00:00
|
|
|
backPixmap = new QPixmap( QPixmap::fromImage( backImage ) );
|
2006-05-13 14:48:16 +00:00
|
|
|
|
|
|
|
// 4B.6. create a painter over the pixmap and set it as the active one
|
|
|
|
mixedPainter = new QPainter( backPixmap );
|
2005-04-01 13:54:26 +00:00
|
|
|
mixedPainter->translate( -limits.left(), -limits.top() );
|
2005-02-18 18:24:45 +00:00
|
|
|
}
|
|
|
|
|
2005-03-24 19:59:11 +00:00
|
|
|
/** 5 -- MIXED FLOW. Draw ANNOTATIONS [OPAQUE ONES] on ACTIVE PAINTER **/
|
2005-04-08 15:45:40 +00:00
|
|
|
if ( unbufferedAnnotations )
|
2005-03-12 08:35:22 +00:00
|
|
|
{
|
2005-04-08 15:45:40 +00:00
|
|
|
// iterate over annotations and paint AText, AGeom, AStamp
|
2006-09-21 08:45:36 +00:00
|
|
|
QList< Okular::Annotation * >::const_iterator aIt = unbufferedAnnotations->begin(), aEnd = unbufferedAnnotations->end();
|
2005-03-12 08:35:22 +00:00
|
|
|
for ( ; aIt != aEnd; ++aIt )
|
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::Annotation * a = *aIt;
|
2005-03-24 19:59:11 +00:00
|
|
|
|
2006-10-21 22:07:05 +00:00
|
|
|
// honor opacity settings on supported types
|
2006-12-05 11:05:50 +00:00
|
|
|
unsigned int opacity = (unsigned int)( 255.0 * a->style().opacity() );
|
2006-11-12 00:48:30 +00:00
|
|
|
// skip the annotation drawing if all the annotation is fully
|
|
|
|
// transparent, but not with text annotations
|
|
|
|
if ( opacity <= 0 && a->subType() != Okular::Annotation::AText )
|
2005-03-24 19:59:11 +00:00
|
|
|
continue;
|
|
|
|
|
2005-04-08 15:45:40 +00:00
|
|
|
// get annotation boundary and drawn rect
|
2006-12-05 11:05:50 +00:00
|
|
|
QRect annotBoundary = a->transformedBoundingRectangle().geometry( scaledWidth, scaledHeight );
|
2005-04-08 15:45:40 +00:00
|
|
|
QRect annotRect = annotBoundary.intersect( limits );
|
|
|
|
QRect innerRect( annotRect.left() - annotBoundary.left(), annotRect.top() -
|
|
|
|
annotBoundary.top(), annotRect.width(), annotRect.height() );
|
2005-03-24 19:59:11 +00:00
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::Annotation::SubType type = a->subType();
|
2005-03-24 19:59:11 +00:00
|
|
|
|
2006-09-16 21:16:58 +00:00
|
|
|
// draw TextAnnotation
|
2006-09-21 08:45:36 +00:00
|
|
|
if ( type == Okular::Annotation::AText )
|
2005-04-08 15:45:40 +00:00
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::TextAnnotation * text = (Okular::TextAnnotation *)a;
|
2006-12-11 07:59:02 +00:00
|
|
|
if ( text->textType() == Okular::TextAnnotation::InPlace )
|
2006-09-16 21:16:58 +00:00
|
|
|
{
|
2007-09-10 13:58:08 +00:00
|
|
|
QImage image( annotBoundary.size(), QImage::Format_ARGB32 );
|
2006-12-05 11:05:50 +00:00
|
|
|
image.fill( qRgba( a->style().color().red(), a->style().color().green(), a->style().color().blue(), opacity ) );
|
2006-09-16 21:16:58 +00:00
|
|
|
QPainter painter( &image );
|
|
|
|
painter.setPen( Qt::black );
|
2006-12-11 07:59:02 +00:00
|
|
|
painter.setFont( text->textFont() );
|
|
|
|
Qt::AlignmentFlag halign = ( text->inplaceAlignment() == 1 ? Qt::AlignHCenter : ( text->inplaceAlignment() == 2 ? Qt::AlignRight : Qt::AlignLeft ) );
|
2007-09-10 13:58:08 +00:00
|
|
|
painter.scale( 1.0 * scaledWidth / page->width(), 1.0 * scaledHeight / page->height() );
|
2006-09-16 21:16:58 +00:00
|
|
|
painter.drawText( 2, 2, image.width() - 2, image.height() - 2,
|
|
|
|
Qt::AlignTop | halign | Qt::TextWordWrap,
|
2006-12-11 07:59:02 +00:00
|
|
|
text->inplaceText() );
|
2007-09-10 13:58:08 +00:00
|
|
|
painter.resetTransform();
|
|
|
|
painter.drawRect( 0, 0, image.width() - 1, image.height() - 1 );
|
2006-09-16 21:16:58 +00:00
|
|
|
painter.end();
|
|
|
|
|
|
|
|
mixedPainter->drawImage( annotBoundary.topLeft(), image );
|
|
|
|
}
|
2006-12-11 07:59:02 +00:00
|
|
|
else if ( text->textType() == Okular::TextAnnotation::Linked )
|
2006-08-08 15:31:13 +00:00
|
|
|
{
|
2005-04-08 15:45:40 +00:00
|
|
|
// get pixmap, colorize and alpha-blend it
|
2006-09-13 18:19:22 +00:00
|
|
|
QString path;
|
2007-10-01 15:10:42 +00:00
|
|
|
QPixmap pixmap = KIconLoader::global()->loadIcon( text->textIcon().toLower(), KIconLoader::User, 32, KIconLoader::DefaultState, QStringList(), &path, true );
|
2006-09-13 18:19:22 +00:00
|
|
|
if ( path.isEmpty() )
|
2007-10-01 15:10:42 +00:00
|
|
|
pixmap = KIconLoader::global()->loadIcon( text->textIcon().toLower(), KIconLoader::NoGroup, 32 );
|
2006-08-08 15:31:13 +00:00
|
|
|
QImage scaledImage;
|
2006-09-19 10:19:13 +00:00
|
|
|
QRect annotBoundary2 = QRect( annotBoundary.topLeft(), QSize( TEXTANNOTATION_ICONSIZE, TEXTANNOTATION_ICONSIZE ) );
|
|
|
|
QRect annotRect2 = annotBoundary2.intersect( limits );
|
|
|
|
QRect innerRect2( annotRect2.left() - annotBoundary2.left(), annotRect2.top() -
|
|
|
|
annotBoundary2.top(), annotRect2.width(), annotRect2.height() );
|
2006-08-08 15:31:13 +00:00
|
|
|
scalePixmapOnImage( scaledImage, &pixmap,
|
2006-09-19 10:19:13 +00:00
|
|
|
TEXTANNOTATION_ICONSIZE, TEXTANNOTATION_ICONSIZE,
|
2006-09-27 10:04:17 +00:00
|
|
|
innerRect2, QImage::Format_ARGB32 );
|
2006-09-12 20:15:28 +00:00
|
|
|
// if the annotation color is valid (ie it was set), then
|
|
|
|
// use it to colorize the icon, otherwise the icon will be
|
|
|
|
// "gray"
|
2006-12-05 11:05:50 +00:00
|
|
|
if ( a->style().color().isValid() )
|
|
|
|
colorizeImage( scaledImage, a->style().color(), opacity );
|
2006-08-08 15:31:13 +00:00
|
|
|
pixmap = QPixmap::fromImage( scaledImage );
|
2005-04-08 15:45:40 +00:00
|
|
|
|
|
|
|
// draw the mangled image to painter
|
2006-08-08 15:31:13 +00:00
|
|
|
mixedPainter->drawPixmap( annotRect.topLeft(), pixmap );
|
|
|
|
}
|
|
|
|
|
2005-04-08 15:45:40 +00:00
|
|
|
}
|
|
|
|
// draw StampAnnotation
|
2006-09-21 08:45:36 +00:00
|
|
|
else if ( type == Okular::Annotation::AStamp )
|
2005-04-08 15:45:40 +00:00
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::StampAnnotation * stamp = (Okular::StampAnnotation *)a;
|
2005-04-08 15:45:40 +00:00
|
|
|
|
|
|
|
// get pixmap and alpha blend it if needed
|
2006-09-13 18:19:22 +00:00
|
|
|
QString path;
|
2007-10-01 15:10:42 +00:00
|
|
|
QPixmap pixmap = KIconLoader::global()->loadIcon( stamp->stampIconName().toLower(), KIconLoader::User, qMin( annotBoundary.width(), annotBoundary.height() ), KIconLoader::DefaultState, QStringList(), &path, true );
|
2006-09-13 18:19:22 +00:00
|
|
|
if ( path.isEmpty() )
|
2007-10-01 15:10:42 +00:00
|
|
|
pixmap = KIconLoader::global()->loadIcon( stamp->stampIconName().toLower(), KIconLoader::NoGroup, qMin( annotBoundary.width(), annotBoundary.height() ) );
|
2005-04-08 15:45:40 +00:00
|
|
|
QImage scaledImage;
|
|
|
|
scalePixmapOnImage( scaledImage, &pixmap, annotBoundary.width(),
|
2006-09-27 10:04:17 +00:00
|
|
|
annotBoundary.height(), innerRect, QImage::Format_ARGB32 );
|
2005-04-08 15:45:40 +00:00
|
|
|
if ( opacity < 255 )
|
|
|
|
changeImageAlpha( scaledImage, opacity );
|
2006-04-13 14:51:05 +00:00
|
|
|
pixmap = QPixmap::fromImage( scaledImage );
|
2005-04-08 15:45:40 +00:00
|
|
|
|
|
|
|
// draw the scaled and al
|
|
|
|
mixedPainter->drawPixmap( annotRect.topLeft(), pixmap );
|
|
|
|
}
|
|
|
|
// draw GeomAnnotation
|
2006-11-19 00:46:01 +00:00
|
|
|
else if ( type == Okular::Annotation::AGeom )
|
|
|
|
{
|
|
|
|
Okular::GeomAnnotation * geom = (Okular::GeomAnnotation *)a;
|
|
|
|
QImage shape( annotBoundary.size(), QImage::Format_ARGB32 );
|
|
|
|
shape.fill( qRgba( 0, 0, 0, 0 ) );
|
|
|
|
// width is already divided by two
|
2006-12-11 07:59:02 +00:00
|
|
|
double width = geom->geometricalPointWidth() * Okular::Utils::dpiX() / ( 72.0 * 2.0 ) * scaledWidth / page->width();
|
2006-11-19 00:46:01 +00:00
|
|
|
QPainter p( &shape );
|
2006-12-05 11:05:50 +00:00
|
|
|
p.setPen( QPen( QBrush( QColor( a->style().color().red(), a->style().color().green(), a->style().color().blue(), opacity ) ), width * 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin ) );
|
2006-11-19 00:46:01 +00:00
|
|
|
QRectF r( .0, .0, annotBoundary.width(), annotBoundary.height() );
|
|
|
|
r.adjust( width, width, -width, -width );
|
2006-12-11 07:59:02 +00:00
|
|
|
if ( geom->geometricalType() == Okular::GeomAnnotation::InscribedSquare )
|
2006-11-19 00:46:01 +00:00
|
|
|
p.drawRect( r );
|
|
|
|
else
|
|
|
|
p.drawEllipse( r );
|
2006-12-11 07:59:02 +00:00
|
|
|
if ( geom->geometricalInnerColor().isValid() )
|
2006-11-19 00:46:01 +00:00
|
|
|
{
|
|
|
|
p.setPen( Qt::NoPen );
|
2006-12-11 07:59:02 +00:00
|
|
|
const QColor color = geom->geometricalInnerColor();
|
|
|
|
p.setBrush( QColor( color.red(), color.green(), color.blue(), opacity ) );
|
2006-11-19 00:46:01 +00:00
|
|
|
r.adjust( width, width, -width, -width );
|
2006-12-11 07:59:02 +00:00
|
|
|
if ( geom->geometricalType() == Okular::GeomAnnotation::InscribedSquare )
|
2006-11-19 00:46:01 +00:00
|
|
|
p.drawRect( r );
|
|
|
|
else
|
|
|
|
p.drawEllipse( r );
|
|
|
|
}
|
|
|
|
p.end();
|
|
|
|
mixedPainter->drawImage( annotBoundary.topLeft(), shape );
|
|
|
|
}
|
2005-04-08 15:45:40 +00:00
|
|
|
|
|
|
|
// draw extents rectangle
|
2006-09-21 08:45:36 +00:00
|
|
|
if ( Okular::Settings::debugDrawAnnotationRect() )
|
2005-04-08 15:45:40 +00:00
|
|
|
{
|
2006-12-05 11:05:50 +00:00
|
|
|
mixedPainter->setPen( a->style().color() );
|
2005-04-08 15:45:40 +00:00
|
|
|
mixedPainter->drawRect( annotBoundary );
|
2005-03-24 19:59:11 +00:00
|
|
|
}
|
2005-03-12 08:35:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-24 19:59:11 +00:00
|
|
|
/** 6 -- MIXED FLOW. Draw LINKS+IMAGES BORDER on ACTIVE PAINTER **/
|
2005-02-03 17:09:33 +00:00
|
|
|
if ( enhanceLinks || enhanceImages )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
2006-07-13 15:03:18 +00:00
|
|
|
mixedPainter->save();
|
|
|
|
mixedPainter->scale( scaledWidth, scaledHeight );
|
|
|
|
|
2006-05-27 20:50:00 +00:00
|
|
|
QColor normalColor = QApplication::palette().color( QPalette::Active, QPalette::Highlight );
|
2005-01-27 17:31:07 +00:00
|
|
|
QColor lightColor = normalColor.light( 140 );
|
|
|
|
// enlarging limits for intersection is like growing the 'rectGeometry' below
|
|
|
|
QRect limitsEnlarged = limits;
|
2006-03-29 16:46:09 +00:00
|
|
|
limitsEnlarged.adjust( -2, -2, 2, 2 );
|
2005-01-27 17:31:07 +00:00
|
|
|
// draw rects that are inside the 'limits' paint region as opaque rects
|
2006-09-21 08:45:36 +00:00
|
|
|
QLinkedList< Okular::ObjectRect * >::const_iterator lIt = page->m_rects.begin(), lEnd = page->m_rects.end();
|
2005-01-27 17:31:07 +00:00
|
|
|
for ( ; lIt != lEnd; ++lIt )
|
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::ObjectRect * rect = *lIt;
|
2007-04-20 12:37:12 +00:00
|
|
|
if ( (enhanceLinks && rect->objectType() == Okular::ObjectRect::Action) ||
|
2006-09-21 08:45:36 +00:00
|
|
|
(enhanceImages && rect->objectType() == Okular::ObjectRect::Image) )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
2006-07-13 15:03:18 +00:00
|
|
|
if ( limitsEnlarged.intersects( rect->boundingRect( scaledWidth, scaledHeight ) ) )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
2006-07-13 15:03:18 +00:00
|
|
|
mixedPainter->strokePath( rect->region(), QPen( normalColor ) );
|
2005-01-27 17:31:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-07-13 15:03:18 +00:00
|
|
|
mixedPainter->restore();
|
2005-01-27 17:31:07 +00:00
|
|
|
}
|
|
|
|
|
2005-03-24 19:59:11 +00:00
|
|
|
/** 7 -- BUFFERED FLOW. Copy BACKPIXMAP on DESTINATION PAINTER **/
|
|
|
|
if ( useBackBuffer )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
2005-04-01 13:54:26 +00:00
|
|
|
delete mixedPainter;
|
2005-01-27 17:31:07 +00:00
|
|
|
destPainter->drawPixmap( limits.left(), limits.top(), *backPixmap );
|
|
|
|
delete backPixmap;
|
|
|
|
}
|
2005-04-08 15:45:40 +00:00
|
|
|
|
|
|
|
// delete object containers
|
|
|
|
delete bufferedHighlights;
|
|
|
|
delete bufferedAnnotations;
|
|
|
|
delete unbufferedAnnotations;
|
2005-01-27 17:31:07 +00:00
|
|
|
}
|
2005-03-24 19:59:11 +00:00
|
|
|
|
|
|
|
|
2006-11-20 07:53:32 +00:00
|
|
|
/** Private Helpers :: Pixmap conversion **/
|
|
|
|
void PagePainter::cropPixmapOnImage( QImage & dest, const QPixmap * src, const QRect & r )
|
2005-03-24 19:59:11 +00:00
|
|
|
{
|
2006-11-20 07:53:32 +00:00
|
|
|
// handle quickly the case in which the whole pixmap has to be converted
|
|
|
|
if ( r == QRect( 0, 0, src->width(), src->height() ) )
|
2006-11-03 17:57:32 +00:00
|
|
|
{
|
2006-11-20 07:53:32 +00:00
|
|
|
dest = src->toImage();
|
|
|
|
}
|
|
|
|
// else copy a portion of the src to an internal pixmap (smaller) and convert it
|
|
|
|
else
|
|
|
|
{
|
2007-09-05 22:01:04 +00:00
|
|
|
QImage croppedImage( r.width(), r.height(), QImage::Format_ARGB32_Premultiplied );
|
|
|
|
QPainter p( &croppedImage );
|
2006-11-20 07:53:32 +00:00
|
|
|
p.drawPixmap( 0, 0, *src, r.left(), r.top(), r.width(), r.height() );
|
2007-09-05 22:01:04 +00:00
|
|
|
dest = croppedImage;
|
2006-11-03 17:57:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-20 07:53:32 +00:00
|
|
|
void PagePainter::scalePixmapOnImage ( QImage & dest, const QPixmap * src,
|
2006-11-03 17:57:32 +00:00
|
|
|
int scaledWidth, int scaledHeight, const QRect & cropRect, QImage::Format format )
|
|
|
|
{
|
|
|
|
// {source, destination, scaling} params
|
2006-11-20 07:53:32 +00:00
|
|
|
int srcWidth = src->width(),
|
|
|
|
srcHeight = src->height(),
|
2006-11-03 17:57:32 +00:00
|
|
|
destLeft = cropRect.left(),
|
|
|
|
destTop = cropRect.top(),
|
|
|
|
destWidth = cropRect.width(),
|
|
|
|
destHeight = cropRect.height();
|
|
|
|
|
|
|
|
// destination image (same geometry as the pageLimits rect)
|
|
|
|
dest = QImage( destWidth, destHeight, format );
|
|
|
|
unsigned int * destData = (unsigned int *)dest.bits();
|
|
|
|
|
|
|
|
// source image (1:1 conversion from pixmap)
|
2006-11-20 07:53:32 +00:00
|
|
|
QImage srcImage = src->toImage();
|
|
|
|
unsigned int * srcData = (unsigned int *)srcImage.bits();
|
2006-11-03 17:57:32 +00:00
|
|
|
|
|
|
|
// precalc the x correspondancy conversion in a lookup table
|
|
|
|
QVarLengthArray<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)
|
2005-03-24 19:59:11 +00:00
|
|
|
for ( int y = 0; y < destHeight; y++ )
|
|
|
|
{
|
2005-04-01 13:54:26 +00:00
|
|
|
unsigned int srcOffset = srcWidth * (((destTop + y) * srcHeight) / scaledHeight);
|
2005-03-24 19:59:11 +00:00
|
|
|
for ( int x = 0; x < destWidth; x++ )
|
|
|
|
(*destData++) = srcData[ srcOffset + xOffset[x] ];
|
|
|
|
}
|
|
|
|
}
|
2005-04-01 13:54:26 +00:00
|
|
|
|
|
|
|
/** Private Helpers :: Image Drawing **/
|
2005-04-08 15:45:40 +00:00
|
|
|
// from Arthur - qt4
|
|
|
|
inline 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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-04-01 13:54:26 +00:00
|
|
|
|
2007-04-22 14:01:03 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
// stroke outline
|
|
|
|
double penWidth = (double)pen.width() * penWidthMultiplier;
|
|
|
|
QPainter painter(&image);
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
QPen pen2 = pen;
|
|
|
|
pen2.setWidthF(penWidth);
|
|
|
|
painter.setPen(pen2);
|
|
|
|
painter.setBrush(brush);
|
|
|
|
|
|
|
|
if (op == Multiply) {
|
|
|
|
painter.setCompositionMode(QPainter::CompositionMode_Multiply);
|
|
|
|
}
|
|
|
|
|
2007-10-03 23:48:38 +00:00
|
|
|
if ( brush.style() == Qt::NoBrush )
|
|
|
|
{
|
|
|
|
// create a polygon
|
|
|
|
QPolygonF poly( closeShape ? pointsNumber + 1 : pointsNumber );
|
|
|
|
for ( int i = 0; i < pointsNumber; ++i )
|
|
|
|
{
|
|
|
|
poly[ i ] = QPointF( normPath[ i ].x * fImageWidth, normPath[ i ].y * fImageHeight );
|
|
|
|
}
|
|
|
|
if ( closeShape )
|
|
|
|
poly[ pointsNumber ] = poly[ 0 ];
|
|
|
|
|
|
|
|
painter.drawPolyline( poly );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// create a 'path'
|
|
|
|
QPainterPath path;
|
|
|
|
path.moveTo( normPath[ 0 ].x * fImageWidth, normPath[ 0 ].y * fImageHeight );
|
|
|
|
for ( int i = 1; i < pointsNumber; i++ )
|
|
|
|
{
|
|
|
|
path.lineTo( normPath[ i ].x * fImageWidth, normPath[ i ].y * fImageHeight );
|
|
|
|
}
|
|
|
|
if ( closeShape )
|
|
|
|
path.closeSubpath();
|
|
|
|
|
|
|
|
painter.drawPath( path );
|
|
|
|
}
|
2007-04-22 14:01:03 +00:00
|
|
|
}
|