2021-05-24 07:25:56 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2005 Enrico Ros <eros.kde@email.it>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2005-01-27 17:31:07 +00:00
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
#ifndef _OKULAR_PAGEPAINTER_H_
|
|
|
|
#define _OKULAR_PAGEPAINTER_H_
|
2005-01-27 17:31:07 +00:00
|
|
|
|
2018-08-17 18:05:01 +00:00
|
|
|
#include <QBrush>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QPen>
|
2007-04-19 18:30:20 +00:00
|
|
|
|
Add line annotation ending arrows for non PDF documents
Summary:
This implements drawing the various line ending styles for 2 point lines in non-PDF documents.
Looks like this:
{F6833437}
CCBUG: 381629
Test Plan:
- open a *.txt document
- draw line annotations with different arrow styles: Square, Diamond, OpenArrow, ClosedArrow, ROpenArrow, RClosedArrow, Butt, Slash, Circle
- ... as start and as end style (start needs D21238 to be configurable in GUI)
- ... filled or not (fill color can't be configured in GUI yet)
- ... with different leader line settings
- ... at various angles
- rotate and scale page
- leader line with setting 100 gives 100 pixel line at 100% zoom (use kruler to verify)
Reviewers: #okular, aacid, sander
Reviewed By: sander
Subscribers: ngraham, sander, knambiar, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21248
2019-05-10 23:17:09 +00:00
|
|
|
#include "core/annotations.h"
|
2006-10-22 23:00:39 +00:00
|
|
|
#include "core/area.h" // for NormalizedPoint
|
|
|
|
|
2005-01-27 17:31:07 +00:00
|
|
|
class QPainter;
|
|
|
|
class QRect;
|
2006-10-22 23:00:39 +00:00
|
|
|
namespace Okular
|
|
|
|
{
|
2013-02-24 21:58:53 +00:00
|
|
|
class DocumentObserver;
|
2006-10-22 23:00:39 +00:00
|
|
|
class Page;
|
|
|
|
}
|
2005-01-27 17:31:07 +00:00
|
|
|
|
|
|
|
/**
|
2006-09-21 08:45:36 +00:00
|
|
|
* @short Paints a Okular::Page to an open painter using given flags.
|
2005-01-27 17:31:07 +00:00
|
|
|
*/
|
2015-01-28 16:33:09 +00:00
|
|
|
class Q_DECL_EXPORT PagePainter
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// list of flags passed to the painting function. by OR-ing those flags
|
2008-04-13 13:15:15 +00:00
|
|
|
// you can decide whether or not to permit drawing of a certain feature.
|
2005-01-27 17:31:07 +00:00
|
|
|
enum PagePainterFlags { Accessibility = 1, EnhanceLinks = 2, EnhanceImages = 4, Highlights = 8, TextSelection = 16, Annotations = 32 };
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2020-08-01 17:08:50 +00:00
|
|
|
/**
|
|
|
|
* Draw @p page on @p destPainter.
|
|
|
|
*
|
|
|
|
* @param destPainter Page will be drawn on this painter.
|
|
|
|
* @param page Which page do draw.
|
|
|
|
* @param observer Request pixmaps generated for this DocumentObserver.
|
|
|
|
* @param flags PagePainterFlags, which features to draw.
|
|
|
|
* @param scaledWidth The requested width of uncropped page in @p destPainter coordinates.
|
|
|
|
* @param scaledHeight The requested height of uncropped page in @p destPainter coordinates.
|
|
|
|
* @param pageLimits Where to paint in @p destPainter coordinates. (I. e. painter crop.) Should begin at (0, 0).
|
|
|
|
*/
|
2019-12-20 15:40:59 +00:00
|
|
|
static void paintPageOnPainter(QPainter *destPainter, const Okular::Page *page, Okular::DocumentObserver *observer, int flags, int scaledWidth, int scaledHeight, const QRect pageLimits);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2020-08-01 17:08:50 +00:00
|
|
|
/**
|
|
|
|
* Draw @p page on @p destPainter.
|
|
|
|
*
|
|
|
|
* @param destPainter Page will be drawn on this painter.
|
|
|
|
* @param page Which page do draw.
|
|
|
|
* @param observer Request pixmaps generated for this DocumentObserver.
|
|
|
|
* @param flags PagePainterFlags, which features to draw.
|
|
|
|
* @param scaledWidth The requested width of uncropped page in @p destPainter coordinates.
|
|
|
|
* @param scaledHeight The requested height of uncropped page in @p destPainter coordinates.
|
|
|
|
* @param pageLimits Where to paint in @p destPainter coordinates. (I. e. painter crop.) Should begin at (0, 0).
|
|
|
|
* @param crop Which area of the page to paint in @p pageLimits.
|
|
|
|
* @param viewPortPoint Which point of the page to highlight, e. g. a source location. @c nullptr to disable.
|
|
|
|
*/
|
2019-12-20 15:40:59 +00:00
|
|
|
static void paintCroppedPageOnPainter(QPainter *destPainter,
|
|
|
|
const Okular::Page *page,
|
|
|
|
Okular::DocumentObserver *observer,
|
2020-02-20 17:45:46 +00:00
|
|
|
int flags,
|
|
|
|
int scaledWidth,
|
|
|
|
int scaledHeight,
|
|
|
|
const QRect pageLimits,
|
2011-10-17 19:56:45 +00:00
|
|
|
const Okular::NormalizedRect &crop,
|
|
|
|
Okular::NormalizedPoint *viewPortPoint);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2005-03-24 19:59:11 +00:00
|
|
|
private:
|
2020-08-01 17:08:50 +00:00
|
|
|
// BEGIN Change Colors feature
|
|
|
|
/**
|
|
|
|
* Collapse color space (from white to black) to a line from @p foreground to @p background.
|
|
|
|
*/
|
2016-07-24 19:34:56 +00:00
|
|
|
static void recolor(QImage *image, const QColor &foreground, const QColor &background);
|
2020-08-01 17:08:50 +00:00
|
|
|
/**
|
|
|
|
* Collapse color space to a line from white to black,
|
|
|
|
* then move from @p threshold to 128 and stretch the line by @p contrast.
|
|
|
|
*/
|
2020-03-28 19:13:43 +00:00
|
|
|
static void blackWhite(QImage *image, int contrast, int threshold);
|
2020-08-01 17:08:50 +00:00
|
|
|
/**
|
|
|
|
* Invert the lightness axis of the HSL color cone.
|
|
|
|
*/
|
2020-03-28 19:13:43 +00:00
|
|
|
static void invertLightness(QImage *image);
|
|
|
|
/**
|
|
|
|
* Inverts luma of @p image using the luma coefficients @p Y_R, @p Y_G, @p Y_B (should sum up to 1),
|
|
|
|
* and assuming linear 8bit RGB color space.
|
|
|
|
*/
|
|
|
|
static void invertLuma(QImage *image, float Y_R, float Y_G, float Y_B);
|
|
|
|
/**
|
|
|
|
* Inverts luma of a pixel given in @p R, @p G, @p B,
|
|
|
|
* using the luma coefficients @p Y_R, @p Y_G, @p Y_B (should sum up to 1),
|
|
|
|
* and assuming linear 8bit RGB color space.
|
|
|
|
*/
|
|
|
|
static void invertLumaPixel(uchar &R, uchar &G, uchar &B, float Y_R, float Y_G, float Y_B);
|
|
|
|
/**
|
|
|
|
* Shifts hue of each pixel by 120 degrees, by simply swapping channels.
|
|
|
|
*/
|
|
|
|
static void hueShiftPositive(QImage *image);
|
2005-04-08 15:45:40 +00:00
|
|
|
/**
|
|
|
|
* Shifts hue of each pixel by 240 degrees, by simply swapping channels.
|
|
|
|
*/
|
|
|
|
static void hueShiftNegative(QImage *image);
|
2020-08-01 17:08:50 +00:00
|
|
|
// END Change Colors feature
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2005-04-10 13:47:00 +00:00
|
|
|
// my pretty dear raster function
|
2019-12-20 15:40:59 +00:00
|
|
|
typedef QList<Okular::NormalizedPoint> NormalizedPath;
|
2005-04-13 14:49:57 +00:00
|
|
|
enum RasterOperation { Normal, Multiply };
|
2020-08-01 17:08:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw @p normPath on @p image.
|
|
|
|
*
|
|
|
|
* @note @p normPath needs to be normalized in respect to @p image, not to the actual page.
|
|
|
|
*/
|
|
|
|
static void drawShapeOnImage(QImage &image, const NormalizedPath &normPath, bool closeShape, const QPen &pen, const QBrush &brush = QBrush(), double penWidthMultiplier = 1.0, RasterOperation op = Normal);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw an ellipse described by @p rect on @p image.
|
|
|
|
*
|
|
|
|
* @param rect Two NormalizedPoints describing the bounding rect. Need to be normalized in respect to @p image, not to the actual page.
|
|
|
|
*/
|
2020-08-06 22:35:00 +00:00
|
|
|
static void drawEllipseOnImage(QImage &image, const NormalizedPath &rect, const QPen &pen, const QBrush &brush, double penWidthMultiplier, RasterOperation op = Normal);
|
Add line annotation ending arrows for non PDF documents
Summary:
This implements drawing the various line ending styles for 2 point lines in non-PDF documents.
Looks like this:
{F6833437}
CCBUG: 381629
Test Plan:
- open a *.txt document
- draw line annotations with different arrow styles: Square, Diamond, OpenArrow, ClosedArrow, ROpenArrow, RClosedArrow, Butt, Slash, Circle
- ... as start and as end style (start needs D21238 to be configurable in GUI)
- ... filled or not (fill color can't be configured in GUI yet)
- ... with different leader line settings
- ... at various angles
- rotate and scale page
- leader line with setting 100 gives 100 pixel line at 100% zoom (use kruler to verify)
Reviewers: #okular, aacid, sander
Reviewed By: sander
Subscribers: ngraham, sander, knambiar, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21248
2019-05-10 23:17:09 +00:00
|
|
|
|
|
|
|
friend class LineAnnotPainter;
|
|
|
|
};
|
|
|
|
|
2020-08-01 17:08:50 +00:00
|
|
|
/**
|
|
|
|
* @short Painting helper for a single Okular::LineAnnotation.
|
|
|
|
*/
|
Add line annotation ending arrows for non PDF documents
Summary:
This implements drawing the various line ending styles for 2 point lines in non-PDF documents.
Looks like this:
{F6833437}
CCBUG: 381629
Test Plan:
- open a *.txt document
- draw line annotations with different arrow styles: Square, Diamond, OpenArrow, ClosedArrow, ROpenArrow, RClosedArrow, Butt, Slash, Circle
- ... as start and as end style (start needs D21238 to be configurable in GUI)
- ... filled or not (fill color can't be configured in GUI yet)
- ... with different leader line settings
- ... at various angles
- rotate and scale page
- leader line with setting 100 gives 100 pixel line at 100% zoom (use kruler to verify)
Reviewers: #okular, aacid, sander
Reviewed By: sander
Subscribers: ngraham, sander, knambiar, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21248
2019-05-10 23:17:09 +00:00
|
|
|
class LineAnnotPainter
|
|
|
|
{
|
|
|
|
public:
|
2020-08-01 17:08:50 +00:00
|
|
|
/**
|
|
|
|
* @param a The annotation to paint. Accessed by draw().
|
|
|
|
* @param pageSizeA The full size of the page on which to paint.
|
|
|
|
* @param pageScale The scale of the page when you call draw().
|
|
|
|
* @param toNormalizedImage How to transform normalized coordinates of @p a to normalized coordinates of your paint device. (If your paint device represents the whole page, use the unit matrix QTransform().)
|
|
|
|
*/
|
Add line annotation ending arrows for non PDF documents
Summary:
This implements drawing the various line ending styles for 2 point lines in non-PDF documents.
Looks like this:
{F6833437}
CCBUG: 381629
Test Plan:
- open a *.txt document
- draw line annotations with different arrow styles: Square, Diamond, OpenArrow, ClosedArrow, ROpenArrow, RClosedArrow, Butt, Slash, Circle
- ... as start and as end style (start needs D21238 to be configurable in GUI)
- ... filled or not (fill color can't be configured in GUI yet)
- ... with different leader line settings
- ... at various angles
- rotate and scale page
- leader line with setting 100 gives 100 pixel line at 100% zoom (use kruler to verify)
Reviewers: #okular, aacid, sander
Reviewed By: sander
Subscribers: ngraham, sander, knambiar, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21248
2019-05-10 23:17:09 +00:00
|
|
|
LineAnnotPainter(const Okular::LineAnnotation *a, QSizeF pageSizeA, double pageScale, const QTransform &toNormalizedImage);
|
2020-08-01 17:08:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the annotation on @p image.
|
|
|
|
*/
|
Add line annotation ending arrows for non PDF documents
Summary:
This implements drawing the various line ending styles for 2 point lines in non-PDF documents.
Looks like this:
{F6833437}
CCBUG: 381629
Test Plan:
- open a *.txt document
- draw line annotations with different arrow styles: Square, Diamond, OpenArrow, ClosedArrow, ROpenArrow, RClosedArrow, Butt, Slash, Circle
- ... as start and as end style (start needs D21238 to be configurable in GUI)
- ... filled or not (fill color can't be configured in GUI yet)
- ... with different leader line settings
- ... at various angles
- rotate and scale page
- leader line with setting 100 gives 100 pixel line at 100% zoom (use kruler to verify)
Reviewers: #okular, aacid, sander
Reviewed By: sander
Subscribers: ngraham, sander, knambiar, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21248
2019-05-10 23:17:09 +00:00
|
|
|
void draw(QImage &image) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void drawMainLine(QImage &image) const;
|
|
|
|
void drawShortenedLine(double mainSegmentLength, double size, QImage &image, const QTransform &toNormalizedPage) const;
|
|
|
|
void drawLineEnds(double mainSegmentLength, double size, QImage &image, const QTransform &transform) const;
|
|
|
|
void drawLineEndArrow(double xEndPos, double size, double flipX, bool close, const QTransform &toNormalizedPage, QImage &image) const;
|
|
|
|
void drawLineEndButt(double xEndPos, double size, const QTransform &toNormalizedPage, QImage &image) const;
|
|
|
|
void drawLineEndCircle(double xEndPos, double size, const QTransform &toNormalizedPage, QImage &image) const;
|
|
|
|
void drawLineEndSquare(double xEndPos, double size, const QTransform &toNormalizedPage, QImage &image) const;
|
|
|
|
void drawLineEndDiamond(double xEndPos, double size, const QTransform &toNormalizedPage, QImage &image) const;
|
|
|
|
void drawLineEndSlash(double xEndPos, double size, const QTransform &toNormalizedPage, QImage &image) const;
|
|
|
|
void drawLeaderLine(double xEndPos, QImage &image, const QTransform &toNormalizedPage) const;
|
|
|
|
template<typename T> QList<Okular::NormalizedPoint> transformPath(const T &path, const QTransform &transform) const
|
|
|
|
{
|
|
|
|
QList<Okular::NormalizedPoint> transformedPath;
|
|
|
|
for (const Okular::NormalizedPoint &item : path) {
|
|
|
|
Okular::NormalizedPoint p;
|
|
|
|
transform.map(item.x, item.y, &p.x, &p.y);
|
|
|
|
transformedPath.append(p);
|
|
|
|
}
|
|
|
|
return transformedPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
static double shortenForArrow(double size, Okular::LineAnnotation::TermStyle endStyle);
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Okular::LineAnnotation *la;
|
|
|
|
QSizeF pageSize;
|
|
|
|
double pageScale;
|
|
|
|
QTransform toNormalizedImage;
|
|
|
|
double aspectRatio;
|
|
|
|
const QPen linePen;
|
|
|
|
QBrush fillBrush;
|
2005-01-27 17:31:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|