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>
|
2018-08-17 18:05:01 +00:00
|
|
|
#include <QDebug>
|
2007-01-09 11:02:04 +00:00
|
|
|
#include <QApplication>
|
2017-10-14 12:47:20 +00:00
|
|
|
#include <QIcon>
|
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"
|
2013-02-24 21:58:53 +00:00
|
|
|
#include "core/page_p.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"
|
2007-12-24 15:02:32 +00:00
|
|
|
#include "guiutils.h"
|
2006-03-28 22:22:10 +00:00
|
|
|
#include "settings.h"
|
2012-11-08 19:46:47 +00:00
|
|
|
#include "core/observer.h"
|
2012-11-08 20:29:09 +00:00
|
|
|
#include "core/tile.h"
|
2012-10-15 22:27:42 +00:00
|
|
|
#include "settings_core.h"
|
2017-01-14 18:15:26 +00:00
|
|
|
#include "ui/debug_ui.h"
|
2005-02-09 17:51:58 +00:00
|
|
|
|
2017-10-14 12:47:20 +00:00
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS( QPixmap, busyPixmap, ( KIconLoader::global()->loadIcon(QLatin1String("okular"), KIconLoader::NoGroup, IconSize(KIconLoader::Desktop), 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
|
|
|
|
|
2008-04-16 16:37:59 +00:00
|
|
|
inline QPen buildPen( const Okular::Annotation *ann, double width, const QColor &color )
|
|
|
|
{
|
|
|
|
QPen p(
|
|
|
|
QBrush( color ),
|
|
|
|
width,
|
|
|
|
ann->style().lineStyle() == Okular::Annotation::Dashed ? Qt::DashLine : Qt::SolidLine,
|
|
|
|
Qt::SquareCap,
|
|
|
|
Qt::MiterJoin
|
|
|
|
);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
void PagePainter::paintPageOnPainter( QPainter * destPainter, const Okular::Page * page,
|
2013-02-24 21:58:53 +00:00
|
|
|
Okular::DocumentObserver *observer, int flags, int scaledWidth, int scaledHeight, const QRect &limits )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
2013-02-24 21:58:53 +00:00
|
|
|
paintCroppedPageOnPainter( destPainter, page, observer, flags, scaledWidth, scaledHeight, limits,
|
2017-09-05 21:27:18 +00:00
|
|
|
Okular::NormalizedRect( 0, 0, 1, 1 ), nullptr );
|
2008-05-19 00:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PagePainter::paintCroppedPageOnPainter( QPainter * destPainter, const Okular::Page * page,
|
2013-02-24 21:58:53 +00:00
|
|
|
Okular::DocumentObserver *observer, int flags, int scaledWidth, int scaledHeight, const QRect &limits,
|
2011-10-17 19:56:45 +00:00
|
|
|
const Okular::NormalizedRect &crop, Okular::NormalizedPoint *viewPortPoint )
|
2008-05-19 00:37:14 +00:00
|
|
|
{
|
2017-10-14 12:47:20 +00:00
|
|
|
qreal dpr = destPainter->device()->devicePixelRatioF();
|
|
|
|
|
2016-03-21 22:20:35 +00:00
|
|
|
/* Calculate the cropped geometry of the page */
|
|
|
|
QRect scaledCrop = crop.geometry( scaledWidth, scaledHeight );
|
2017-10-14 12:47:20 +00:00
|
|
|
|
|
|
|
/* variables prefixed with d are in the device pixels coordinate system, which translates to the rendered output - that means,
|
|
|
|
* multiplied with the device pixel ratio of the target PaintDevice */
|
|
|
|
const QRect dScaledCrop(QRectF(scaledCrop.x() * dpr, scaledCrop.y() * dpr, scaledCrop.width() * dpr, scaledCrop.height() * dpr).toAlignedRect());
|
|
|
|
|
2016-03-21 22:20:35 +00:00
|
|
|
int croppedWidth = scaledCrop.width();
|
|
|
|
int croppedHeight = scaledCrop.height();
|
2008-05-19 00:37:14 +00:00
|
|
|
|
2017-10-14 12:47:20 +00:00
|
|
|
int dScaledWidth = ceil(scaledWidth * dpr);
|
|
|
|
int dScaledHeight = ceil(scaledHeight * dpr);
|
|
|
|
const QRect dLimits(QRectF(limits.x() * dpr, limits.y() * dpr, limits.width() * dpr, limits.height() * dpr).toAlignedRect());
|
|
|
|
|
2012-11-08 16:57:47 +00:00
|
|
|
QColor paperColor = Qt::white;
|
|
|
|
QColor backgroundColor = paperColor;
|
2012-10-15 22:27:42 +00:00
|
|
|
if ( Okular::SettingsCore::changeColors() )
|
2007-09-23 15:30:31 +00:00
|
|
|
{
|
2012-10-15 22:27:42 +00:00
|
|
|
switch ( Okular::SettingsCore::renderMode() )
|
2007-09-23 15:30:31 +00:00
|
|
|
{
|
2012-10-15 22:27:42 +00:00
|
|
|
case Okular::SettingsCore::EnumRenderMode::Inverted:
|
2012-11-08 16:57:47 +00:00
|
|
|
backgroundColor = Qt::black;
|
2007-09-23 15:30:31 +00:00
|
|
|
break;
|
2012-10-15 22:27:42 +00:00
|
|
|
case Okular::SettingsCore::EnumRenderMode::Paper:
|
2012-11-08 23:51:01 +00:00
|
|
|
paperColor = Okular::SettingsCore::paperColor();
|
2012-11-08 16:57:47 +00:00
|
|
|
backgroundColor = paperColor;
|
2007-09-23 15:30:31 +00:00
|
|
|
break;
|
2012-10-15 22:27:42 +00:00
|
|
|
case Okular::SettingsCore::EnumRenderMode::Recolor:
|
2012-11-08 16:57:47 +00:00
|
|
|
backgroundColor = Okular::Settings::recolorBackground();
|
2007-09-23 15:30:31 +00:00
|
|
|
break;
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
}
|
2012-11-08 16:57:47 +00:00
|
|
|
destPainter->fillRect( limits, backgroundColor );
|
2007-09-23 15:30:31 +00:00
|
|
|
|
2014-02-19 22:40:43 +00:00
|
|
|
const bool hasTilesManager = page->hasTilesManager( observer );
|
2017-10-14 12:47:20 +00:00
|
|
|
QPixmap pixmap;
|
2012-11-09 16:19:39 +00:00
|
|
|
|
|
|
|
if ( !hasTilesManager )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
2012-07-07 17:40:52 +00:00
|
|
|
/** 1 - RETRIEVE THE 'PAGE+ID' PIXMAP OR A SIMILAR 'PAGE' ONE **/
|
2017-10-14 12:47:20 +00:00
|
|
|
const QPixmap *p = page->_o_nearestPixmap( observer, dScaledWidth, dScaledHeight );
|
|
|
|
|
|
|
|
if (p != NULL) {
|
|
|
|
pixmap = *p;
|
|
|
|
pixmap.setDevicePixelRatio( qApp->devicePixelRatio() );
|
|
|
|
}
|
2012-07-07 17:40:52 +00:00
|
|
|
|
|
|
|
/** 1B - IF NO PIXMAP, DRAW EMPTY PAGE **/
|
2017-10-14 12:47:20 +00:00
|
|
|
double pixmapRescaleRatio = !pixmap.isNull() ? dScaledWidth / (double)pixmap.width() : -1;
|
|
|
|
long pixmapPixels = !pixmap.isNull() ? (long)pixmap.width() * (long)pixmap.height() : 0;
|
|
|
|
if ( pixmap.isNull() || pixmapRescaleRatio > 20.0 || pixmapRescaleRatio < 0.25 ||
|
|
|
|
(dScaledWidth > pixmap.width() && pixmapPixels > 60000000L) )
|
2006-07-02 15:53:26 +00:00
|
|
|
{
|
2012-07-07 17:40:52 +00:00
|
|
|
// draw something on the blank page: the okular icon or a cross (as a fallback)
|
2014-08-23 15:57:25 +00:00
|
|
|
if ( !busyPixmap()->isNull() )
|
2012-07-07 17:40:52 +00:00
|
|
|
{
|
2017-10-14 12:47:20 +00:00
|
|
|
busyPixmap->setDevicePixelRatio(dpr);
|
2014-08-23 15:57:25 +00:00
|
|
|
destPainter->drawPixmap( QPoint( 10, 10 ), *busyPixmap() );
|
2012-07-07 17:40:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
destPainter->setPen( Qt::gray );
|
|
|
|
destPainter->drawLine( 0, 0, croppedWidth-1, croppedHeight-1 );
|
|
|
|
destPainter->drawLine( 0, croppedHeight-1, croppedWidth-1, 0 );
|
|
|
|
}
|
|
|
|
return;
|
2006-07-02 15:53:26 +00:00
|
|
|
}
|
2005-01-27 17:31:07 +00:00
|
|
|
}
|
|
|
|
|
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();
|
Add annotation resize functionality
Usage:
If you left-click an annotation, it gets selected. Resize handles appear on the selection rectangle. When cursor is moved over one of the 8 resize handles on the corners/edges, the cursor shape changes to indicate resize mode. Everywhere else on the annotation means "move", just as it was before resize feature was added. Pressing ESC or clicking an area outside the annotation cancels a selection. Pressing Del deletes a selected annotation.
Feature is only applicable for annotation types AText, AStamp and AGeom.
Implementation:
It works by eventually changing AnnotationPrivate::m_boundary and notifying generator (i.e. poppler) about that change. Annotation state handling is shifted out of PageView into a new class MouseAnnotation (ui/pageviewmouseannotation.cpp). Some functionality not related to resizing but to annotation interaction in general is also shifted to class MouseAnnotation, to build a single place of responsiblity.
Other changes:
Add method Document::adjustPageAnnotation, backed by a QUndoCommand.
class Okular::AdjustAnnotationCommand.
Add Annotation::adjust and Annotation::canBeResized methods.
Draw resize handles in PagePainter::paintCroppedPageOnPainter.
Resize and move work
-for types AText, AStamp and AGeom
-on all pages of document
-when viewport position changes
-when zoom level changes
-for all page rotations (0°, 90°, 180°, 270°)
Selection is canceled
-when currently selected annotation is deleted
-on mouse click outside of currently selected annotation
-ESC is pressed
Viewport is shifted when mouse cursor during move/resize comes close to viewport border.
Resize to negative is prevented.
Tiny annotations are still selectable.
If mouse is moved over an annotation type that we can focus, and the annotation is not yet focused, mouse cursor shape changes to arrow.
If mouse cursor rests over an annotation A, while annotation B is focused, a tooltip for annotation A is shown.
Selected Annotation is deleted when Del is pressed.
Test for regressions:
-Annotation interaction (focus, move, resize, start playback, ...) are only done in mode EnumMouseMode::Browse.
-If mouse is moved over an annotation type where we can start an action, mouse cursor shape changes to pointing hand.
-If mouse is moved over an annotation type that we can't interact with, mouse cursor shape stays a open hand.
-If mouse cursor rests over an annotation of any type, a tooltip for that annotation is shown.
-Grab/move scroll area (on left click + mouse move) is prevented, if mouse is over focused annotation, or over AMovie/AScreen/AFileAttachment annotation.
-A double click on a annotation starts the "annotator".
REVIEW: 127366
BUG: 177778
BUG: 314843
BUG: 358060
2017-03-19 22:16:06 +00:00
|
|
|
|
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?
|
2017-09-05 21:27:18 +00:00
|
|
|
QList< QPair<QColor, Okular::NormalizedRect> > * bufferedHighlights = nullptr;
|
|
|
|
QList< Okular::Annotation * > * bufferedAnnotations = nullptr;
|
|
|
|
QList< Okular::Annotation * > * unbufferedAnnotations = nullptr;
|
|
|
|
Okular::Annotation *boundingRectOnlyAnn = nullptr; // Paint the bounding rect of this annotation
|
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
|
2017-11-15 23:14:49 +00:00
|
|
|
double nXMin = ( (double)limits.left() / scaledWidth ) + crop.left,
|
|
|
|
nXMax = ( (double)limits.right() / scaledWidth ) + crop.left,
|
|
|
|
nYMin = ( (double)limits.top() / scaledHeight ) + crop.top,
|
|
|
|
nYMax = ( (double)limits.bottom() / scaledHeight ) + crop.top;
|
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 );
|
2008-11-11 18:48:40 +00:00
|
|
|
QLinkedList< Okular::HighlightAreaRect * >::const_iterator h2It = page->m_highlights.constBegin(), hEnd = page->m_highlights.constEnd();
|
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 )
|
2008-11-11 18:48:40 +00:00
|
|
|
for (hIt=(*h2It)->constBegin(); hIt!=(*h2It)->constEnd(); ++hIt)
|
2005-07-15 18:20:57 +00:00
|
|
|
{
|
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();
|
2008-11-11 18:48:40 +00:00
|
|
|
Okular::HighlightAreaRect::const_iterator hIt = textSelection->constBegin(), hEnd = textSelection->constEnd();
|
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
|
|
|
{
|
2008-11-11 18:48:40 +00:00
|
|
|
QLinkedList< Okular::Annotation * >::const_iterator aIt = page->m_annotations.constBegin(), aEnd = page->m_annotations.constEnd();
|
2005-03-24 19:59:11 +00:00
|
|
|
for ( ; aIt != aEnd; ++aIt )
|
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::Annotation * ann = *aIt;
|
2012-05-13 18:25:31 +00:00
|
|
|
int flags = ann->flags();
|
2012-05-13 18:44:22 +00:00
|
|
|
|
2012-05-13 18:25:31 +00:00
|
|
|
if ( flags & Okular::Annotation::Hidden )
|
|
|
|
continue;
|
2012-05-13 18:44:22 +00:00
|
|
|
|
|
|
|
if ( flags & Okular::Annotation::ExternallyDrawn )
|
|
|
|
{
|
|
|
|
// ExternallyDrawn annots are never rendered by PagePainter.
|
Add annotation resize functionality
Usage:
If you left-click an annotation, it gets selected. Resize handles appear on the selection rectangle. When cursor is moved over one of the 8 resize handles on the corners/edges, the cursor shape changes to indicate resize mode. Everywhere else on the annotation means "move", just as it was before resize feature was added. Pressing ESC or clicking an area outside the annotation cancels a selection. Pressing Del deletes a selected annotation.
Feature is only applicable for annotation types AText, AStamp and AGeom.
Implementation:
It works by eventually changing AnnotationPrivate::m_boundary and notifying generator (i.e. poppler) about that change. Annotation state handling is shifted out of PageView into a new class MouseAnnotation (ui/pageviewmouseannotation.cpp). Some functionality not related to resizing but to annotation interaction in general is also shifted to class MouseAnnotation, to build a single place of responsiblity.
Other changes:
Add method Document::adjustPageAnnotation, backed by a QUndoCommand.
class Okular::AdjustAnnotationCommand.
Add Annotation::adjust and Annotation::canBeResized methods.
Draw resize handles in PagePainter::paintCroppedPageOnPainter.
Resize and move work
-for types AText, AStamp and AGeom
-on all pages of document
-when viewport position changes
-when zoom level changes
-for all page rotations (0°, 90°, 180°, 270°)
Selection is canceled
-when currently selected annotation is deleted
-on mouse click outside of currently selected annotation
-ESC is pressed
Viewport is shifted when mouse cursor during move/resize comes close to viewport border.
Resize to negative is prevented.
Tiny annotations are still selectable.
If mouse is moved over an annotation type that we can focus, and the annotation is not yet focused, mouse cursor shape changes to arrow.
If mouse cursor rests over an annotation A, while annotation B is focused, a tooltip for annotation A is shown.
Selected Annotation is deleted when Del is pressed.
Test for regressions:
-Annotation interaction (focus, move, resize, start playback, ...) are only done in mode EnumMouseMode::Browse.
-If mouse is moved over an annotation type where we can start an action, mouse cursor shape changes to pointing hand.
-If mouse is moved over an annotation type that we can't interact with, mouse cursor shape stays a open hand.
-If mouse cursor rests over an annotation of any type, a tooltip for that annotation is shown.
-Grab/move scroll area (on left click + mouse move) is prevented, if mouse is over focused annotation, or over AMovie/AScreen/AFileAttachment annotation.
-A double click on a annotation starts the "annotator".
REVIEW: 127366
BUG: 177778
BUG: 314843
BUG: 358060
2017-03-19 22:16:06 +00:00
|
|
|
// Just paint the boundingRect if the annot is moved or resized.
|
|
|
|
if ( flags & (Okular::Annotation::BeingMoved | Okular::Annotation::BeingResized) )
|
|
|
|
{
|
2012-05-13 18:44:22 +00:00
|
|
|
boundingRectOnlyAnn = ann;
|
Add annotation resize functionality
Usage:
If you left-click an annotation, it gets selected. Resize handles appear on the selection rectangle. When cursor is moved over one of the 8 resize handles on the corners/edges, the cursor shape changes to indicate resize mode. Everywhere else on the annotation means "move", just as it was before resize feature was added. Pressing ESC or clicking an area outside the annotation cancels a selection. Pressing Del deletes a selected annotation.
Feature is only applicable for annotation types AText, AStamp and AGeom.
Implementation:
It works by eventually changing AnnotationPrivate::m_boundary and notifying generator (i.e. poppler) about that change. Annotation state handling is shifted out of PageView into a new class MouseAnnotation (ui/pageviewmouseannotation.cpp). Some functionality not related to resizing but to annotation interaction in general is also shifted to class MouseAnnotation, to build a single place of responsiblity.
Other changes:
Add method Document::adjustPageAnnotation, backed by a QUndoCommand.
class Okular::AdjustAnnotationCommand.
Add Annotation::adjust and Annotation::canBeResized methods.
Draw resize handles in PagePainter::paintCroppedPageOnPainter.
Resize and move work
-for types AText, AStamp and AGeom
-on all pages of document
-when viewport position changes
-when zoom level changes
-for all page rotations (0°, 90°, 180°, 270°)
Selection is canceled
-when currently selected annotation is deleted
-on mouse click outside of currently selected annotation
-ESC is pressed
Viewport is shifted when mouse cursor during move/resize comes close to viewport border.
Resize to negative is prevented.
Tiny annotations are still selectable.
If mouse is moved over an annotation type that we can focus, and the annotation is not yet focused, mouse cursor shape changes to arrow.
If mouse cursor rests over an annotation A, while annotation B is focused, a tooltip for annotation A is shown.
Selected Annotation is deleted when Del is pressed.
Test for regressions:
-Annotation interaction (focus, move, resize, start playback, ...) are only done in mode EnumMouseMode::Browse.
-If mouse is moved over an annotation type where we can start an action, mouse cursor shape changes to pointing hand.
-If mouse is moved over an annotation type that we can't interact with, mouse cursor shape stays a open hand.
-If mouse cursor rests over an annotation of any type, a tooltip for that annotation is shown.
-Grab/move scroll area (on left click + mouse move) is prevented, if mouse is over focused annotation, or over AMovie/AScreen/AFileAttachment annotation.
-A double click on a annotation starts the "annotator".
REVIEW: 127366
BUG: 177778
BUG: 314843
BUG: 358060
2017-03-19 22:16:06 +00:00
|
|
|
}
|
2006-09-14 18:42:28 +00:00
|
|
|
continue;
|
2012-05-13 18:44:22 +00:00
|
|
|
}
|
2006-09-14 18:42:28 +00:00
|
|
|
|
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 **/
|
2012-10-15 22:27:42 +00:00
|
|
|
bool bufferAccessibility = (flags & Accessibility) && Okular::SettingsCore::changeColors() && (Okular::SettingsCore::renderMode() != Okular::SettingsCore::EnumRenderMode::Paper);
|
2011-10-17 19:56:45 +00:00
|
|
|
bool useBackBuffer = bufferAccessibility || bufferedHighlights || bufferedAnnotations || viewPortPoint;
|
2017-09-05 21:27:18 +00:00
|
|
|
QPixmap * backPixmap = nullptr;
|
|
|
|
QPainter * mixedPainter = nullptr;
|
2012-11-15 22:16:13 +00:00
|
|
|
QRect limitsInPixmap = limits.translated( scaledCrop.topLeft() );
|
2017-10-14 12:47:20 +00:00
|
|
|
QRect dLimitsInPixmap = dLimits.translated( dScaledCrop.topLeft() );
|
|
|
|
|
2008-05-19 00:37:14 +00:00
|
|
|
// limits within full (scaled but uncropped) pixmap
|
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
|
|
|
{
|
2012-11-09 16:19:39 +00:00
|
|
|
if ( hasTilesManager )
|
2012-07-07 17:40:52 +00:00
|
|
|
{
|
2012-11-15 19:11:10 +00:00
|
|
|
const Okular::NormalizedRect normalizedLimits( limitsInPixmap, scaledWidth, scaledHeight );
|
2014-02-19 22:40:43 +00:00
|
|
|
const QList<Okular::Tile> tiles = page->tilesAt( observer, normalizedLimits );
|
2012-07-11 05:14:50 +00:00
|
|
|
QList<Okular::Tile>::const_iterator tIt = tiles.constBegin(), tEnd = tiles.constEnd();
|
2012-07-07 17:40:52 +00:00
|
|
|
while ( tIt != tEnd )
|
|
|
|
{
|
2012-11-09 16:45:46 +00:00
|
|
|
const Okular::Tile &tile = *tIt;
|
2012-11-15 22:16:13 +00:00
|
|
|
QRect tileRect = tile.rect().geometry( scaledWidth, scaledHeight ).translated( -scaledCrop.topLeft() );
|
2017-10-14 12:47:20 +00:00
|
|
|
QRect dTileRect = QRectF(tileRect.x() * dpr, tileRect.y() * dpr, tileRect.width() * dpr, tileRect.height() * dpr).toAlignedRect();
|
2012-07-22 15:40:16 +00:00
|
|
|
QRect limitsInTile = limits & tileRect;
|
2017-10-14 12:47:20 +00:00
|
|
|
QRectF dLimitsInTile = dLimits & dTileRect;
|
|
|
|
|
2012-11-11 19:18:02 +00:00
|
|
|
if ( !limitsInTile.isEmpty() )
|
2012-07-22 15:40:16 +00:00
|
|
|
{
|
2017-10-14 12:47:20 +00:00
|
|
|
QPixmap* tilePixmap = tile.pixmap();
|
|
|
|
tilePixmap->setDevicePixelRatio( qApp->devicePixelRatio() );
|
|
|
|
|
|
|
|
if ( tilePixmap->width() == dTileRect.width() && tilePixmap->height() == dTileRect.height() ) {
|
|
|
|
destPainter->drawPixmap( limitsInTile.topLeft(), *tilePixmap,
|
|
|
|
dLimitsInTile.translated( -dTileRect.topLeft() ) );
|
|
|
|
} else {
|
|
|
|
destPainter->drawPixmap( tileRect, *tilePixmap );
|
|
|
|
}
|
2012-07-22 15:40:16 +00:00
|
|
|
}
|
2012-07-07 17:40:52 +00:00
|
|
|
tIt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-14 12:47:20 +00:00
|
|
|
QPixmap scaledCroppedPixmap = pixmap.scaled(dScaledWidth, dScaledHeight).copy(dLimitsInPixmap);
|
|
|
|
scaledCroppedPixmap.setDevicePixelRatio(dpr);
|
|
|
|
destPainter->drawPixmap( limits.topLeft(), scaledCroppedPixmap, QRectF(0, 0, dLimits.width(),dLimits.height()));
|
2012-07-07 17:40:52 +00:00
|
|
|
}
|
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
|
2017-10-14 12:47:20 +00:00
|
|
|
QImage backImage = QImage( dLimits.width(), dLimits.height(), QImage::Format_ARGB32_Premultiplied );
|
|
|
|
backImage.setDevicePixelRatio(dpr);
|
|
|
|
backImage.fill( paperColor );
|
|
|
|
QPainter p( &backImage );
|
2005-01-27 17:31:07 +00:00
|
|
|
|
2012-11-09 16:19:39 +00:00
|
|
|
if ( hasTilesManager )
|
2012-08-16 19:35:41 +00:00
|
|
|
{
|
2012-11-15 19:11:10 +00:00
|
|
|
const Okular::NormalizedRect normalizedLimits( limitsInPixmap, scaledWidth, scaledHeight );
|
2014-02-19 22:40:43 +00:00
|
|
|
const QList<Okular::Tile> tiles = page->tilesAt( observer, normalizedLimits );
|
2012-08-16 19:35:41 +00:00
|
|
|
QList<Okular::Tile>::const_iterator tIt = tiles.constBegin(), tEnd = tiles.constEnd();
|
|
|
|
while ( tIt != tEnd )
|
|
|
|
{
|
2012-11-09 16:45:46 +00:00
|
|
|
const Okular::Tile &tile = *tIt;
|
2012-11-15 22:16:13 +00:00
|
|
|
QRect tileRect = tile.rect().geometry( scaledWidth, scaledHeight ).translated( -scaledCrop.topLeft() );
|
2017-10-14 12:47:20 +00:00
|
|
|
QRect dTileRect(QRectF(tileRect.x() * dpr, tileRect.y() * dpr, tileRect.width() * dpr, tileRect.height() * dpr).toAlignedRect());
|
2012-08-16 19:35:41 +00:00
|
|
|
QRect limitsInTile = limits & tileRect;
|
2017-10-14 12:47:20 +00:00
|
|
|
QRect dLimitsInTile = dLimits & dTileRect;
|
|
|
|
|
2012-11-11 19:18:02 +00:00
|
|
|
if ( !limitsInTile.isEmpty() )
|
2012-08-16 19:35:41 +00:00
|
|
|
{
|
2017-10-14 12:47:20 +00:00
|
|
|
QPixmap* tilePixmap = tile.pixmap();
|
|
|
|
tilePixmap->setDevicePixelRatio( qApp->devicePixelRatio() );
|
|
|
|
|
|
|
|
if ( tilePixmap->width() == dTileRect.width() && tilePixmap->height() == dTileRect.height() )
|
2012-08-16 19:35:41 +00:00
|
|
|
{
|
2017-10-14 12:47:20 +00:00
|
|
|
p.drawPixmap( limitsInTile.translated( -limits.topLeft() ).topLeft(), *tilePixmap,
|
|
|
|
dLimitsInTile.translated( -dTileRect.topLeft() ) );
|
2012-08-16 19:35:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-14 12:47:20 +00:00
|
|
|
double xScale = tilePixmap->width() / (double)dTileRect.width();
|
|
|
|
double yScale = tilePixmap->height() / (double)dTileRect.height();
|
2012-08-16 19:35:41 +00:00
|
|
|
QTransform transform( xScale, 0, 0, yScale, 0, 0 );
|
2017-10-14 12:47:20 +00:00
|
|
|
p.drawPixmap( limitsInTile.translated( -limits.topLeft() ), *tilePixmap,
|
|
|
|
transform.mapRect( dLimitsInTile ).translated( -transform.mapRect( dTileRect ).topLeft() ) );
|
2012-08-16 19:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
++tIt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 4B.1. draw the page pixmap: normal or scaled
|
2017-10-14 12:47:20 +00:00
|
|
|
QPixmap scaledCroppedPixmap = pixmap.scaled(dScaledWidth, dScaledHeight).copy(dLimitsInPixmap);
|
|
|
|
scaledCroppedPixmap.setDevicePixelRatio(dpr);
|
|
|
|
p.drawPixmap( 0, 0, scaledCroppedPixmap );
|
2012-08-16 19:35:41 +00:00
|
|
|
}
|
2005-03-24 19:59:11 +00:00
|
|
|
|
2017-10-14 12:47:20 +00:00
|
|
|
p.end();
|
|
|
|
|
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
|
|
|
{
|
2012-10-15 22:27:42 +00:00
|
|
|
switch ( Okular::SettingsCore::renderMode() )
|
2005-02-03 17:09:33 +00:00
|
|
|
{
|
2012-10-15 22:27:42 +00:00
|
|
|
case Okular::SettingsCore::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;
|
2012-10-15 22:27:42 +00:00
|
|
|
case Okular::SettingsCore::EnumRenderMode::Recolor:
|
2016-07-24 19:34:56 +00:00
|
|
|
recolor(&backImage, Okular::Settings::recolorForeground(), Okular::Settings::recolorBackground());
|
2005-02-03 17:09:33 +00:00
|
|
|
break;
|
2012-10-15 22:27:42 +00:00
|
|
|
case Okular::SettingsCore::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;
|
|
|
|
}
|
|
|
|
}
|
2017-10-14 12:47:20 +00:00
|
|
|
|
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
|
2017-08-03 11:23:28 +00:00
|
|
|
for (const auto& highlight : *bufferedHighlights)
|
2005-02-03 17:09:33 +00:00
|
|
|
{
|
2017-08-03 11:23:28 +00:00
|
|
|
const Okular::NormalizedRect & r = highlight.second;
|
2005-04-08 15:45:40 +00:00
|
|
|
// find out the rect to highlight on pixmap
|
2016-07-24 21:46:53 +00:00
|
|
|
QRect highlightRect = r.geometry( scaledWidth, scaledHeight ).translated( -scaledCrop.topLeft() ).intersected( limits );
|
2006-03-29 16:46:09 +00:00
|
|
|
highlightRect.translate( -limits.left(), -limits.top() );
|
2005-04-08 15:45:40 +00:00
|
|
|
|
2017-08-03 11:23:28 +00:00
|
|
|
const QColor highlightColor = highlight.first;
|
|
|
|
QPainter painter(&backImage);
|
|
|
|
painter.setCompositionMode(QPainter::CompositionMode_Multiply);
|
|
|
|
painter.fillRect(highlightRect, highlightColor);
|
2018-05-18 14:58:22 +00:00
|
|
|
|
|
|
|
auto frameColor = highlightColor.darker(150);
|
|
|
|
const QRect frameRect = r.geometry( scaledWidth, scaledHeight ).translated( -scaledCrop.topLeft() ).translated( -limits.left(), -limits.top() );
|
|
|
|
painter.setPen(frameColor);
|
|
|
|
painter.drawRect(frameRect);
|
2005-02-03 17:09:33 +00:00
|
|
|
}
|
2005-01-27 17:31:07 +00:00
|
|
|
}
|
2017-10-14 12:47:20 +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);
|
2008-05-19 00:37:14 +00:00
|
|
|
// precalc constants for normalizing [0,1] page coordinates into normalized [0,1] limit rect coordinates
|
|
|
|
double pageScale = (double)croppedWidth / page->width();
|
2012-11-15 21:42:56 +00:00
|
|
|
double xOffset = (double)limits.left() / (double)scaledWidth + crop.left,
|
2005-04-13 21:23:54 +00:00
|
|
|
xScale = (double)scaledWidth / (double)limits.width(),
|
2012-11-15 21:42:56 +00:00
|
|
|
yOffset = (double)limits.top() / (double)scaledHeight + crop.top,
|
2005-04-13 21:23:54 +00:00
|
|
|
yScale = (double)scaledHeight / (double)limits.height();
|
2005-04-12 20:44:26 +00:00
|
|
|
|
|
|
|
// paint all buffered annotations in the page
|
2008-11-11 18:48:40 +00:00
|
|
|
QList< Okular::Annotation * >::const_iterator aIt = bufferedAnnotations->constBegin(), aEnd = bufferedAnnotations->constEnd();
|
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();
|
2008-01-24 21:48:03 +00:00
|
|
|
QColor acolor = a->style().color();
|
|
|
|
if ( !acolor.isValid() )
|
|
|
|
acolor = Qt::yellow;
|
|
|
|
acolor.setAlphaF( 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();
|
2008-11-11 18:48:40 +00:00
|
|
|
QLinkedList<Okular::NormalizedPoint>::const_iterator it = points.constBegin();
|
|
|
|
QLinkedList<Okular::NormalizedPoint>::const_iterator itEnd = points.constEnd();
|
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 );
|
|
|
|
}
|
|
|
|
|
2008-04-16 16:37:59 +00:00
|
|
|
const QPen linePen = buildPen( a, a->style().width(), a->style().color() );
|
2012-07-27 02:45:16 +00:00
|
|
|
QBrush fillBrush;
|
|
|
|
|
|
|
|
if ( la->lineClosed() && la->lineInnerColor().isValid() )
|
|
|
|
fillBrush = QBrush( la->lineInnerColor() );
|
2008-04-16 16:37:59 +00:00
|
|
|
|
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(),
|
2008-04-16 16:37:59 +00:00
|
|
|
linePen,
|
2012-07-27 02:45:16 +00:00
|
|
|
fillBrush, 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 );
|
2019-05-10 23:40:44 +00:00
|
|
|
double angle = atan2( delta.y * page->height(), delta.x * page->width() );
|
2006-09-16 14:58:32 +00:00
|
|
|
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] );
|
|
|
|
}
|
|
|
|
|
2008-04-16 16:37:59 +00:00
|
|
|
drawShapeOnImage( backImage, path2, false, linePen, QBrush(), pageScale, Multiply );
|
|
|
|
drawShapeOnImage( backImage, path3, false, linePen, 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();
|
|
|
|
|
2008-04-16 16:37:59 +00:00
|
|
|
const QPen inkPen = buildPen( a, a->style().width(), acolor );
|
|
|
|
|
2006-12-11 07:59:02 +00:00
|
|
|
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
|
2008-11-11 18:48:40 +00:00
|
|
|
QLinkedList<Okular::NormalizedPoint>::const_iterator pIt = inkPath.constBegin(), pEnd = inkPath.constEnd();
|
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
|
2008-04-16 16:37:59 +00:00
|
|
|
drawShapeOnImage( backImage, path, false, inkPen, QBrush(), pageScale );
|
2005-04-12 20:44:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // end current annotation drawing
|
|
|
|
}
|
2011-10-17 19:56:45 +00:00
|
|
|
if(viewPortPoint)
|
|
|
|
{
|
|
|
|
QPainter painter(&backImage);
|
|
|
|
painter.translate( -limits.left(), -limits.top() );
|
|
|
|
painter.setPen( QApplication::palette().color( QPalette::Active, QPalette::Highlight ) );
|
|
|
|
painter.drawLine( 0, viewPortPoint->y * scaledHeight + 1, scaledWidth - 1, viewPortPoint->y * scaledHeight + 1 );
|
|
|
|
// ROTATION CURRENTLY NOT IMPLEMENTED
|
|
|
|
/*
|
|
|
|
if( page->rotation() == Okular::Rotation0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(page->rotation() == Okular::Rotation270)
|
|
|
|
{
|
|
|
|
painter.drawLine( viewPortPoint->y * scaledHeight + 1, 0, viewPortPoint->y * scaledHeight + 1, scaledWidth - 1);
|
|
|
|
}
|
|
|
|
else if(page->rotation() == Okular::Rotation180)
|
|
|
|
{
|
|
|
|
painter.drawLine( 0, (1.0 - viewPortPoint->y) * scaledHeight - 1, scaledWidth - 1, (1.0 - viewPortPoint->y) * scaledHeight - 1 );
|
|
|
|
}
|
|
|
|
else if(page->rotation() == Okular::Rotation90) // not right, rotation clock-wise
|
|
|
|
{
|
|
|
|
painter.drawLine( scaledWidth - (viewPortPoint->y * scaledHeight + 1), 0, scaledWidth - (viewPortPoint->y * scaledHeight + 1), scaledWidth - 1);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
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 ) );
|
2017-10-14 12:47:20 +00:00
|
|
|
backPixmap->setDevicePixelRatio(dpr);
|
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
|
2008-11-11 18:48:40 +00:00
|
|
|
QList< Okular::Annotation * >::const_iterator aIt = unbufferedAnnotations->constBegin(), aEnd = unbufferedAnnotations->constEnd();
|
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
|
Add typewriter annotation tool
Summary:
Typewriter is originally specified by the PDF reference as special FreeText annotation, where Intent=FreeTextTypewriter. It features opaque letters on transparent background, so that users can fill non interactive forms. Herewith typewriter is implemented natively for PDF, and there's also an Okular specific implementation for other document types. The added tool reuses the inline note UI.
This work was done during GSoC 2018. See https://community.kde.org/GSoC/2018/StatusReports/DileepSankhla for details.
FEATURE: 353401
Test Plan:
- okularpartrc is generated (if not yet existing) with typewriter as 10th tool
- typewriter tool is also available in Annotation Tools -> Add, Typ "Typewriter"
- selecting the tool and left click into document opens inline note input dialog
- finishing creates an annotation similar to inline note, but with transparent background
- saving into PDF results in /Subtype FreeText /IT /FreeTextTypeWriter
- saving typewriter into archive stores color with alpha channel = 0x00
- opening annotated archive works, if archive was created with old Okular, and opened in patched Okular
- opening annotated archive works, if archive was created with patched Okular, and opened in old Okular
Reviewers: sander
Reviewed By: sander
Subscribers: ngraham, sander, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D15204
2018-09-21 20:10:04 +00:00
|
|
|
unsigned int opacity = (unsigned int)( a->style().color().alpha() * 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;
|
|
|
|
|
2008-01-24 21:48:03 +00:00
|
|
|
QColor acolor = a->style().color();
|
|
|
|
if ( !acolor.isValid() )
|
|
|
|
acolor = Qt::yellow;
|
|
|
|
acolor.setAlpha( opacity );
|
|
|
|
|
2005-04-08 15:45:40 +00:00
|
|
|
// get annotation boundary and drawn rect
|
2012-11-15 21:42:56 +00:00
|
|
|
QRect annotBoundary = a->transformedBoundingRectangle().geometry( scaledWidth, scaledHeight ).translated( -scaledCrop.topLeft() );
|
2016-07-24 21:46:53 +00:00
|
|
|
QRect annotRect = annotBoundary.intersected( limits );
|
2005-04-08 15:45:40 +00:00
|
|
|
QRect innerRect( annotRect.left() - annotBoundary.left(), annotRect.top() -
|
|
|
|
annotBoundary.top(), annotRect.width(), annotRect.height() );
|
2017-10-14 12:47:20 +00:00
|
|
|
QRectF dInnerRect(innerRect.x() * dpr, innerRect.y() * dpr, innerRect.width() * dpr, innerRect.height() * dpr);
|
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 );
|
2008-01-24 21:48:03 +00:00
|
|
|
image.fill( acolor.rgba() );
|
2006-09-16 21:16:58 +00:00
|
|
|
QPainter painter( &image );
|
2006-12-11 07:59:02 +00:00
|
|
|
painter.setFont( text->textFont() );
|
2018-10-03 14:31:40 +00:00
|
|
|
painter.setPen( text->textColor() );
|
2006-12-11 07:59:02 +00:00
|
|
|
Qt::AlignmentFlag halign = ( text->inplaceAlignment() == 1 ? Qt::AlignHCenter : ( text->inplaceAlignment() == 2 ? Qt::AlignRight : Qt::AlignLeft ) );
|
2013-05-18 15:15:39 +00:00
|
|
|
const double invXScale = (double)page->width() / scaledWidth;
|
|
|
|
const double invYScale = (double)page->height() / scaledHeight;
|
2015-11-24 00:10:46 +00:00
|
|
|
const double borderWidth = text->style().width();
|
2013-05-18 15:15:39 +00:00
|
|
|
painter.scale( 1 / invXScale, 1 / invYScale );
|
2015-11-24 00:10:46 +00:00
|
|
|
painter.drawText( borderWidth * invXScale, borderWidth * invYScale,
|
|
|
|
(image.width() - 2 * borderWidth) * invXScale,
|
|
|
|
(image.height() - 2 * borderWidth) * invYScale,
|
2018-11-08 23:25:13 +00:00
|
|
|
Qt::AlignTop | halign | Qt::TextWordWrap,
|
2013-05-14 07:37:00 +00:00
|
|
|
text->contents() );
|
2007-09-10 13:58:08 +00:00
|
|
|
painter.resetTransform();
|
2015-11-24 00:10:46 +00:00
|
|
|
//Required as asking for a zero width pen results
|
|
|
|
//in a default width pen (1.0) being created
|
|
|
|
if ( borderWidth != 0 )
|
|
|
|
{
|
|
|
|
QPen pen( Qt::black, borderWidth );
|
|
|
|
painter.setPen( pen );
|
|
|
|
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-12-24 15:02:32 +00:00
|
|
|
QPixmap pixmap = GuiUtils::iconLoader()->loadIcon( text->textIcon().toLower(), KIconLoader::User, 32, KIconLoader::DefaultState, QStringList(), &path, true );
|
2006-09-13 18:19:22 +00:00
|
|
|
if ( path.isEmpty() )
|
2007-12-24 15:02:32 +00:00
|
|
|
pixmap = GuiUtils::iconLoader()->loadIcon( text->textIcon().toLower(), KIconLoader::NoGroup, 32 );
|
2017-10-14 12:47:20 +00:00
|
|
|
QRect annotBoundary2 = QRect( annotBoundary.topLeft(), QSize( TEXTANNOTATION_ICONSIZE * dpr, TEXTANNOTATION_ICONSIZE * dpr ) );
|
2016-07-24 21:46:53 +00:00
|
|
|
QRect annotRect2 = annotBoundary2.intersected( limits );
|
2006-09-19 10:19:13 +00:00
|
|
|
QRect innerRect2( annotRect2.left() - annotBoundary2.left(), annotRect2.top() -
|
|
|
|
annotBoundary2.top(), annotRect2.width(), annotRect2.height() );
|
2017-10-14 12:47:20 +00:00
|
|
|
|
|
|
|
QPixmap scaledCroppedPixmap = pixmap.scaled(TEXTANNOTATION_ICONSIZE * dpr, TEXTANNOTATION_ICONSIZE * dpr).copy(dInnerRect.toAlignedRect());
|
|
|
|
scaledCroppedPixmap.setDevicePixelRatio(dpr);
|
|
|
|
QImage scaledCroppedImage = scaledCroppedPixmap.toImage();
|
|
|
|
|
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() )
|
2017-10-14 12:47:20 +00:00
|
|
|
GuiUtils::colorizeImage( scaledCroppedImage, a->style().color(), opacity );
|
|
|
|
pixmap = QPixmap::fromImage( scaledCroppedImage );
|
2005-04-08 15:45:40 +00:00
|
|
|
|
2017-10-14 12:47:20 +00:00
|
|
|
// draw the mangled image to painter
|
|
|
|
mixedPainter->drawPixmap( annotRect.topLeft(), pixmap);
|
2006-08-08 15:31:13 +00:00
|
|
|
}
|
|
|
|
|
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
|
2008-09-19 20:21:57 +00:00
|
|
|
QPixmap pixmap = GuiUtils::loadStamp( stamp->stampIconName(), annotBoundary.size() );
|
2010-03-23 21:50:13 +00:00
|
|
|
if ( !pixmap.isNull() ) // should never happen but can happen on huge sizes
|
|
|
|
{
|
2017-10-14 12:47:20 +00:00
|
|
|
const QRect dInnerRect(QRectF(innerRect.x() * dpr, innerRect.y() * dpr, innerRect.width() * dpr, innerRect.height() * dpr).toAlignedRect());
|
|
|
|
|
|
|
|
QPixmap scaledCroppedPixmap = pixmap.scaled(annotBoundary.width() * dpr, annotBoundary.height() * dpr).copy(dInnerRect);
|
|
|
|
scaledCroppedPixmap.setDevicePixelRatio(dpr);
|
|
|
|
|
|
|
|
QImage scaledCroppedImage = scaledCroppedPixmap.toImage();
|
|
|
|
|
2010-03-23 21:50:13 +00:00
|
|
|
if ( opacity < 255 )
|
2017-10-14 12:47:20 +00:00
|
|
|
changeImageAlpha( scaledCroppedImage, opacity );
|
|
|
|
pixmap = QPixmap::fromImage( scaledCroppedImage );
|
2010-03-23 21:50:13 +00:00
|
|
|
|
|
|
|
// draw the scaled and al
|
|
|
|
mixedPainter->drawPixmap( annotRect.topLeft(), pixmap );
|
|
|
|
}
|
2005-04-08 15:45:40 +00:00
|
|
|
}
|
|
|
|
// draw GeomAnnotation
|
2006-11-19 00:46:01 +00:00
|
|
|
else if ( type == Okular::Annotation::AGeom )
|
|
|
|
{
|
|
|
|
Okular::GeomAnnotation * geom = (Okular::GeomAnnotation *)a;
|
2008-04-07 00:14:29 +00:00
|
|
|
// check whether there's anything to draw
|
|
|
|
if ( geom->style().width() || geom->geometricalInnerColor().isValid() )
|
2006-11-19 00:46:01 +00:00
|
|
|
{
|
2008-04-07 00:14:29 +00:00
|
|
|
mixedPainter->save();
|
2016-01-30 17:15:07 +00:00
|
|
|
const double width = geom->style().width() * Okular::Utils::realDpi(nullptr).width() / ( 72.0 * 2.0 ) * scaledWidth / page->width();
|
2008-04-07 00:14:29 +00:00
|
|
|
QRectF r( .0, .0, annotBoundary.width(), annotBoundary.height() );
|
2006-11-19 00:46:01 +00:00
|
|
|
r.adjust( width, width, -width, -width );
|
2008-04-07 00:14:29 +00:00
|
|
|
r.translate( annotBoundary.topLeft() );
|
|
|
|
if ( geom->geometricalInnerColor().isValid() )
|
|
|
|
{
|
|
|
|
r.adjust( width, width, -width, -width );
|
|
|
|
const QColor color = geom->geometricalInnerColor();
|
|
|
|
mixedPainter->setPen( Qt::NoPen );
|
|
|
|
mixedPainter->setBrush( QColor( color.red(), color.green(), color.blue(), opacity ) );
|
|
|
|
if ( geom->geometricalType() == Okular::GeomAnnotation::InscribedSquare )
|
|
|
|
mixedPainter->drawRect( r );
|
|
|
|
else
|
|
|
|
mixedPainter->drawEllipse( r );
|
|
|
|
r.adjust( -width, -width, width, width );
|
|
|
|
}
|
|
|
|
if ( geom->style().width() ) // need to check the original size here..
|
|
|
|
{
|
2008-04-16 16:37:59 +00:00
|
|
|
mixedPainter->setPen( buildPen( a, width * 2, acolor ) );
|
2008-04-07 00:14:29 +00:00
|
|
|
mixedPainter->setBrush( Qt::NoBrush );
|
|
|
|
if ( geom->geometricalType() == Okular::GeomAnnotation::InscribedSquare )
|
|
|
|
mixedPainter->drawRect( r );
|
|
|
|
else
|
|
|
|
mixedPainter->drawEllipse( r );
|
|
|
|
}
|
|
|
|
mixedPainter->restore();
|
2006-11-19 00:46:01 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-13 18:44:22 +00:00
|
|
|
if ( boundingRectOnlyAnn )
|
|
|
|
{
|
2012-11-15 21:42:56 +00:00
|
|
|
QRect annotBoundary = boundingRectOnlyAnn->transformedBoundingRectangle().geometry( scaledWidth, scaledHeight ).translated( -scaledCrop.topLeft() );
|
2012-05-13 18:44:22 +00:00
|
|
|
mixedPainter->setPen( Qt::DashLine );
|
|
|
|
mixedPainter->drawRect( annotBoundary );
|
|
|
|
}
|
|
|
|
|
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 );
|
2012-11-15 21:42:56 +00:00
|
|
|
mixedPainter->translate( -crop.left, -crop.top );
|
2006-07-13 15:03:18 +00:00
|
|
|
|
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
|
|
|
// 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
|
2008-11-11 18:48:40 +00:00
|
|
|
QLinkedList< Okular::ObjectRect * >::const_iterator lIt = page->m_rects.constBegin(), lEnd = page->m_rects.constEnd();
|
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
|
|
|
{
|
2012-11-15 21:42:56 +00:00
|
|
|
if ( limitsEnlarged.intersects( rect->boundingRect( scaledWidth, scaledHeight ).translated( -scaledCrop.topLeft() ) ) )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
2017-02-01 23:26:23 +00:00
|
|
|
mixedPainter->strokePath( rect->region(), QPen( normalColor, 0 ) );
|
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
|
|
|
{
|
2017-10-14 12:47:20 +00:00
|
|
|
qreal dpr = src->devicePixelRatioF();
|
|
|
|
|
2006-11-20 07:53:32 +00:00
|
|
|
// handle quickly the case in which the whole pixmap has to be converted
|
2017-10-14 12:47:20 +00:00
|
|
|
if ( r == QRect( 0, 0, src->width() / dpr, src->height() / dpr ) )
|
2006-11-03 17:57:32 +00:00
|
|
|
{
|
2006-11-20 07:53:32 +00:00
|
|
|
dest = src->toImage();
|
2007-10-06 23:04:28 +00:00
|
|
|
dest = dest.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
2006-11-20 07:53:32 +00:00
|
|
|
}
|
|
|
|
// else copy a portion of the src to an internal pixmap (smaller) and convert it
|
|
|
|
else
|
|
|
|
{
|
2017-10-14 12:47:20 +00:00
|
|
|
QImage croppedImage( r.width() * dpr, r.height() * dpr, QImage::Format_ARGB32_Premultiplied );
|
|
|
|
croppedImage.setDevicePixelRatio(dpr);
|
2007-09-05 22:01:04 +00:00
|
|
|
QPainter p( &croppedImage );
|
2006-11-20 07:53:32 +00:00
|
|
|
p.drawPixmap( 0, 0, *src, r.left(), r.top(), r.width(), r.height() );
|
2008-06-06 21:41:56 +00:00
|
|
|
p.end();
|
2007-09-05 22:01:04 +00:00
|
|
|
dest = croppedImage;
|
2006-11-03 17:57:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-24 19:34:56 +00:00
|
|
|
void PagePainter::recolor(QImage *image, const QColor &foreground, const QColor &background)
|
|
|
|
{
|
|
|
|
if (image->format() != QImage::Format_ARGB32_Premultiplied) {
|
2017-01-14 18:15:26 +00:00
|
|
|
qCWarning(OkularUiDebug) << "Wrong image format! Converting...";
|
2016-07-24 19:34:56 +00:00
|
|
|
*image = image->convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_ASSERT(image->format() == QImage::Format_ARGB32_Premultiplied);
|
|
|
|
|
|
|
|
const float scaleRed = background.redF() - foreground.redF();
|
|
|
|
const float scaleGreen = background.greenF() - foreground.greenF();
|
|
|
|
const float scaleBlue = background.blueF() - foreground.blueF();
|
|
|
|
|
|
|
|
for (int y=0; y<image->height(); y++) {
|
|
|
|
QRgb *pixels = reinterpret_cast<QRgb*>(image->scanLine(y));
|
|
|
|
|
|
|
|
for (int x=0; x<image->width(); x++) {
|
|
|
|
const int lightness = qGray(pixels[x]);
|
2016-10-29 11:01:31 +00:00
|
|
|
pixels[x] = qRgba(scaleRed * lightness + foreground.red(),
|
|
|
|
scaleGreen * lightness + foreground.green(),
|
|
|
|
scaleBlue * lightness + foreground.blue(),
|
2016-07-24 19:34:56 +00:00
|
|
|
qAlpha(pixels[x]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-01 13:54:26 +00:00
|
|
|
/** Private Helpers :: Image Drawing **/
|
2005-04-08 15:45:40 +00:00
|
|
|
// from Arthur - qt4
|
2013-05-18 20:23:20 +00:00
|
|
|
static inline int qt_div_255(int x) { return (x + (x>>8) + 0x80) >> 8; }
|
2005-04-08 15:45:40 +00:00
|
|
|
|
|
|
|
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;
|
2015-10-29 12:37:11 +00:00
|
|
|
for( unsigned int i = 0; i < pixels; ++i )
|
2005-04-08 15:45:40 +00:00
|
|
|
{ // 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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2013-07-01 22:25:11 +00:00
|
|
|
path.setFillRule( Qt::WindingFill );
|
|
|
|
|
2007-10-03 23:48:38 +00:00
|
|
|
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
|
|
|
}
|
2010-03-23 21:50:13 +00:00
|
|
|
|
|
|
|
/* kate: replace-tabs on; indent-width 4; */
|
|
|
|
|