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. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
// qt / kde includes
|
|
|
|
#include <qrect.h>
|
|
|
|
#include <qpainter.h>
|
|
|
|
#include <qpixmap.h>
|
|
|
|
#include <qimage.h>
|
|
|
|
#include <qapplication.h>
|
|
|
|
#include <kimageeffect.h>
|
2005-03-24 19:59:11 +00:00
|
|
|
#include <kiconloader.h>
|
2005-07-15 18:20:57 +00:00
|
|
|
#include <kdebug.h>
|
2005-01-27 17:31:07 +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
|
|
|
|
#include "pagepainter.h"
|
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-03-28 22:22:10 +00:00
|
|
|
#include "settings.h"
|
2005-02-09 17:51:58 +00:00
|
|
|
|
2005-04-01 16:24:11 +00:00
|
|
|
void PagePainter::paintPageOnPainter( QPainter * destPainter, const KPDFPage * page,
|
|
|
|
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 **/
|
|
|
|
const QPixmap * pixmap = 0;
|
2005-01-27 17:31:07 +00:00
|
|
|
|
|
|
|
// if a pixmap is present for given id, use it
|
2005-04-01 16:24:11 +00:00
|
|
|
if ( page->m_pixmaps.contains( pixID ) )
|
|
|
|
pixmap = page->m_pixmaps[ pixID ];
|
2005-01-27 17:31:07 +00:00
|
|
|
|
|
|
|
// else find the closest match using pixmaps of other IDs (great optim!)
|
2005-03-24 19:59:11 +00:00
|
|
|
else if ( !page->m_pixmaps.isEmpty() )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
|
|
|
int minDistance = -1;
|
|
|
|
QMap< int,QPixmap * >::const_iterator it = page->m_pixmaps.begin(), end = page->m_pixmaps.end();
|
|
|
|
for ( ; it != end; ++it )
|
|
|
|
{
|
|
|
|
int pixWidth = (*it)->width(),
|
2005-04-01 13:54:26 +00:00
|
|
|
distance = pixWidth > scaledWidth ? pixWidth - scaledWidth : scaledWidth - pixWidth;
|
2005-01-27 17:31:07 +00:00
|
|
|
if ( minDistance == -1 || distance < minDistance )
|
|
|
|
{
|
|
|
|
pixmap = *it;
|
|
|
|
minDistance = distance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-24 19:59:11 +00:00
|
|
|
/** 1B - IF NO PIXMAP, DRAW EMPTY PAGE **/
|
2005-04-01 13:54:26 +00:00
|
|
|
double pixmapRescaleRatio = pixmap ? scaledWidth / (double)pixmap->width() : -1;
|
2005-04-07 20:26:49 +00:00
|
|
|
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
|
|
|
{
|
2005-11-04 11:59:51 +00:00
|
|
|
if ( KpdfSettings::changeColors() &&
|
|
|
|
KpdfSettings::renderMode() == KpdfSettings::EnumRenderMode::Paper )
|
|
|
|
destPainter->fillRect( limits, KpdfSettings::paperColor() );
|
2005-01-27 17:31:07 +00:00
|
|
|
else
|
|
|
|
destPainter->fillRect( limits, Qt::white );
|
|
|
|
|
|
|
|
// draw a cross (to that the pixmap as not yet been loaded)
|
|
|
|
// helps a lot on pages that take much to render
|
|
|
|
destPainter->setPen( Qt::gray );
|
2005-04-01 13:54:26 +00:00
|
|
|
destPainter->drawLine( 0, 0, scaledWidth-1, scaledHeight-1 );
|
|
|
|
destPainter->drawLine( 0, scaledHeight-1, scaledWidth-1, 0 );
|
2005-02-03 17:09:33 +00:00
|
|
|
// idea here: draw a hourglass (or kpdf icon :-) on top-left corner
|
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();
|
|
|
|
bool canDrawAnnotations = (flags & Annotations) && !page->m_annotations.isEmpty();
|
2005-11-04 11:59:51 +00:00
|
|
|
bool enhanceLinks = (flags & EnhanceLinks) && KpdfSettings::highlightLinks();
|
|
|
|
bool enhanceImages = (flags & EnhanceImages) && KpdfSettings::highlightImages();
|
2005-04-08 15:45:40 +00:00
|
|
|
// vectors containing objects to draw
|
2005-07-15 18:20:57 +00:00
|
|
|
// make this a qcolor, rect map, since we dont need
|
|
|
|
// to know s_id here! we are only drawing this right?
|
2006-03-23 19:02:55 +00:00
|
|
|
QList< QPair<QColor, NormalizedRect *> > * bufferedHighlights = 0;
|
|
|
|
QList< Annotation * > * bufferedAnnotations = 0;
|
|
|
|
QList< Annotation * > * unbufferedAnnotations = 0;
|
2005-04-08 15:45:40 +00:00
|
|
|
// fill up lists with visible annotation/highlight objects
|
|
|
|
if ( canDrawHighlights || 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-03-23 19:02:55 +00:00
|
|
|
bufferedHighlights = new QList< QPair<QColor, NormalizedRect *> >();
|
2005-07-15 18:20:57 +00:00
|
|
|
/* else
|
|
|
|
{*/
|
|
|
|
|
|
|
|
NormalizedRect* limitRect = new NormalizedRect(nXMin, nYMin, nXMax, nYMax );
|
2006-03-23 19:02:55 +00:00
|
|
|
QLinkedList< HighlightAreaRect * >::const_iterator h2It = page->m_highlights.begin(), hEnd = page->m_highlights.end();
|
|
|
|
QList< NormalizedRect * >::const_iterator hIt;
|
2005-07-15 18:20:57 +00:00
|
|
|
for ( ; h2It != hEnd; ++h2It )
|
|
|
|
for (hIt=(*h2It)->begin(); hIt!=(*h2It)->end(); ++hIt)
|
|
|
|
{
|
|
|
|
if ((*hIt)->intersects(limitRect))
|
|
|
|
bufferedHighlights->append( qMakePair((*h2It)->color,*hIt) );
|
|
|
|
}
|
|
|
|
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-03-23 19:02:55 +00:00
|
|
|
QLinkedList< 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 )
|
|
|
|
{
|
2005-04-08 15:45:40 +00:00
|
|
|
Annotation * ann = *aIt;
|
|
|
|
if ( ann->boundary.intersects( nXMin, nYMin, nXMax, nYMax ) )
|
2005-03-24 19:59:11 +00:00
|
|
|
{
|
2005-04-08 15:45:40 +00:00
|
|
|
Annotation::SubType type = ann->subType();
|
|
|
|
if ( type == Annotation::ALine || type == Annotation::AHighlight ||
|
|
|
|
type == Annotation::AInk /*|| (type == Annotation::AGeom && ann->style.opacity < 0.99)*/ )
|
|
|
|
{
|
|
|
|
if ( !bufferedAnnotations )
|
2006-03-23 19:02:55 +00:00
|
|
|
bufferedAnnotations = new QList< Annotation * >();
|
2005-04-08 15:45:40 +00:00
|
|
|
bufferedAnnotations->append( ann );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( !unbufferedAnnotations )
|
2006-03-23 19:02:55 +00:00
|
|
|
unbufferedAnnotations = new QList< 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 **/
|
2005-11-18 20:48:01 +00:00
|
|
|
bool bufferAccessibility = (flags & Accessibility) && KpdfSettings::changeColors() && (KpdfSettings::renderMode() != KpdfSettings::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
|
2005-04-01 13:54:26 +00:00
|
|
|
if ( pixmap->width() == scaledWidth && pixmap->height() == scaledHeight )
|
2005-03-24 19:59:11 +00:00
|
|
|
destPainter->drawPixmap( limits.topLeft(), *pixmap, limits );
|
|
|
|
// else draw a scaled portion of the magnified pixmap
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QImage destImage;
|
2005-04-01 16:24:11 +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
|
2005-04-01 13:54:26 +00:00
|
|
|
if ( pixmap->width() == scaledWidth && pixmap->height() == scaledHeight )
|
2005-04-01 16:24:11 +00:00
|
|
|
cropPixmapOnImage( backImage, pixmap, limits );
|
2005-03-24 19:59:11 +00:00
|
|
|
else
|
2005-04-01 16:24:11 +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
|
|
|
{
|
2005-11-04 11:59:51 +00:00
|
|
|
switch ( KpdfSettings::renderMode() )
|
2005-02-03 17:09:33 +00:00
|
|
|
{
|
2005-11-04 11:59:51 +00:00
|
|
|
case KpdfSettings::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;
|
2005-11-04 11:59:51 +00:00
|
|
|
case KpdfSettings::EnumRenderMode::Recolor:
|
2005-02-03 17:09:33 +00:00
|
|
|
// Recolor image using KImageEffect::flatten with dither:0
|
2005-11-04 11:59:51 +00:00
|
|
|
KImageEffect::flatten( backImage, KpdfSettings::recolorForeground(), KpdfSettings::recolorBackground() );
|
2005-02-03 17:09:33 +00:00
|
|
|
break;
|
2005-11-04 11:59:51 +00:00
|
|
|
case KpdfSettings::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(),
|
2005-11-04 11:59:51 +00:00
|
|
|
con = KpdfSettings::bWContrast(), thr = 255 - KpdfSettings::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-03-23 19:02:55 +00:00
|
|
|
QList< QPair<QColor, NormalizedRect *> >::const_iterator hIt = bufferedHighlights->begin(), hEnd = bufferedHighlights->end();
|
2005-02-03 17:09:33 +00:00
|
|
|
for ( ; hIt != hEnd; ++hIt )
|
|
|
|
{
|
2005-07-15 18:20:57 +00:00
|
|
|
NormalizedRect * r = (*hIt).second;
|
2005-04-08 15:45:40 +00:00
|
|
|
// find out the rect to highlight on pixmap
|
|
|
|
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
|
|
|
{
|
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-03-23 19:02:55 +00:00
|
|
|
QList< Annotation * >::const_iterator aIt = bufferedAnnotations->begin(), aEnd = bufferedAnnotations->end();
|
2005-04-10 13:47:00 +00:00
|
|
|
for ( ; aIt != aEnd; ++aIt )
|
|
|
|
{
|
|
|
|
Annotation * a = *aIt;
|
|
|
|
Annotation::SubType type = a->subType();
|
|
|
|
|
2005-04-12 20:44:26 +00:00
|
|
|
// draw TextAnnotation (InPlace) MISSING: all
|
|
|
|
if ( type == Annotation::AText )
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
// draw LineAnnotation MISSING: all
|
|
|
|
else if ( type == Annotation::ALine )
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
// get the annotation
|
|
|
|
/*LineAnnotation * la = (LineAnnotation *) a;
|
|
|
|
|
|
|
|
NormalizedPath path;
|
|
|
|
// normalize page point to image
|
|
|
|
const NormalizedPoint & inkPoint = *pIt;
|
|
|
|
NormalizedPoint point;
|
|
|
|
point.x = (inkPoint.x - xOffset) * xScale;
|
|
|
|
point.y = (inkPoint.y - yOffset) * yScale;
|
|
|
|
path.append( point );
|
|
|
|
// draw the normalized path into image
|
2005-04-13 21:23:54 +00:00
|
|
|
drawShapeOnImage( backImage, path, false, QPen( a->style.color ), QBrush(), pageScale );
|
2005-04-12 20:44:26 +00:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
// draw GeomAnnotation MISSING: all
|
|
|
|
else if ( type == Annotation::AGeom )
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
// draw HighlightAnnotation MISSING: under/strike width, feather, capping
|
|
|
|
else if ( type == Annotation::AHighlight )
|
2005-04-10 13:47:00 +00:00
|
|
|
{
|
|
|
|
// get the annotation
|
|
|
|
HighlightAnnotation * ha = (HighlightAnnotation *) a;
|
2005-04-12 20:44:26 +00:00
|
|
|
HighlightAnnotation::HighlightType type = ha->highlightType;
|
2005-04-10 13:47:00 +00:00
|
|
|
|
|
|
|
// draw each quad of the annotation
|
2005-04-12 20:44:26 +00:00
|
|
|
int quads = ha->highlightQuads.size();
|
2005-04-10 13:47:00 +00:00
|
|
|
for ( int q = 0; q < quads; q++ )
|
|
|
|
{
|
|
|
|
NormalizedPath path;
|
|
|
|
const 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++ )
|
|
|
|
{
|
|
|
|
NormalizedPoint point;
|
|
|
|
point.x = (quad.points[ i ].x - xOffset) * xScale;
|
|
|
|
point.y = (quad.points[ i ].y - yOffset) * yScale;
|
|
|
|
path.append( point );
|
|
|
|
}
|
2005-04-12 20:44:26 +00:00
|
|
|
// draw the normalized path into image
|
|
|
|
switch ( type )
|
|
|
|
{
|
|
|
|
// highlight the whole rect
|
|
|
|
case HighlightAnnotation::Highlight:
|
2005-04-13 21:23:54 +00:00
|
|
|
drawShapeOnImage( backImage, path, true, QPen(), a->style.color, pageScale, Multiply );
|
2005-04-12 20:44:26 +00:00
|
|
|
break;
|
|
|
|
// highlight the bottom part of the rect
|
|
|
|
case HighlightAnnotation::Squiggly:
|
|
|
|
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;
|
2005-04-13 21:23:54 +00:00
|
|
|
drawShapeOnImage( backImage, path, true, QPen(), a->style.color, pageScale, Multiply );
|
2005-04-12 20:44:26 +00:00
|
|
|
break;
|
|
|
|
// make a line at 3/4 of the height
|
|
|
|
case HighlightAnnotation::Underline:
|
|
|
|
path[ 0 ].x = ( path[ 0 ].x + 3*path[ 3 ].x ) / 4.0;
|
|
|
|
path[ 0 ].y = ( path[ 0 ].y + 3*path[ 3 ].y ) / 4.0;
|
|
|
|
path[ 1 ].x = ( path[ 1 ].x + 3*path[ 2 ].x ) / 4.0;
|
|
|
|
path[ 1 ].y = ( path[ 1 ].y + 3*path[ 2 ].y ) / 4.0;
|
|
|
|
path.pop_back();
|
|
|
|
path.pop_back();
|
2005-04-13 21:23:54 +00:00
|
|
|
drawShapeOnImage( backImage, path, false, QPen( a->style.color, 2 ), QBrush(), pageScale );
|
2005-04-12 20:44:26 +00:00
|
|
|
break;
|
|
|
|
// make a line at 1/2 of the height
|
|
|
|
case HighlightAnnotation::StrikeOut:
|
|
|
|
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();
|
2005-04-13 21:23:54 +00:00
|
|
|
drawShapeOnImage( backImage, path, false, QPen( a->style.color, 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
|
|
|
|
else if ( type == Annotation::AInk )
|
|
|
|
{
|
|
|
|
// get the annotation
|
|
|
|
InkAnnotation * ia = (InkAnnotation *) a;
|
|
|
|
|
|
|
|
// draw each ink path
|
|
|
|
int paths = ia->inkPaths.size();
|
|
|
|
for ( int p = 0; p < paths; p++ )
|
|
|
|
{
|
|
|
|
NormalizedPath path;
|
2006-03-23 19:02:55 +00:00
|
|
|
const QLinkedList<NormalizedPoint> & inkPath = ia->inkPaths[ p ];
|
2005-04-12 20:44:26 +00:00
|
|
|
|
|
|
|
// normalize page point to image
|
2006-03-23 19:02:55 +00:00
|
|
|
QLinkedList<NormalizedPoint>::const_iterator pIt = inkPath.begin(), pEnd = inkPath.end();
|
2005-04-12 20:44:26 +00:00
|
|
|
for ( ; pIt != pEnd; ++pIt )
|
|
|
|
{
|
|
|
|
const NormalizedPoint & inkPoint = *pIt;
|
|
|
|
NormalizedPoint point;
|
|
|
|
point.x = (inkPoint.x - xOffset) * xScale;
|
|
|
|
point.y = (inkPoint.y - yOffset) * yScale;
|
|
|
|
path.append( point );
|
|
|
|
}
|
|
|
|
// draw the normalized path into image
|
2005-04-13 21:23:54 +00:00
|
|
|
drawShapeOnImage( backImage, path, false, QPen( a->style.color, 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
|
|
|
|
backPixmap = new QPixmap( backImage );
|
|
|
|
|
|
|
|
// 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-03-23 19:02:55 +00:00
|
|
|
QList< Annotation * >::const_iterator aIt = unbufferedAnnotations->begin(), aEnd = unbufferedAnnotations->end();
|
2005-03-12 08:35:22 +00:00
|
|
|
for ( ; aIt != aEnd; ++aIt )
|
|
|
|
{
|
|
|
|
Annotation * a = *aIt;
|
2005-03-24 19:59:11 +00:00
|
|
|
|
2005-04-08 15:45:40 +00:00
|
|
|
// honour opacity settings on supported types
|
|
|
|
unsigned int opacity = (unsigned int)( 255.0 * a->style.opacity );
|
|
|
|
if ( opacity <= 0 )
|
2005-03-24 19:59:11 +00:00
|
|
|
continue;
|
|
|
|
|
2005-04-08 15:45:40 +00:00
|
|
|
// get annotation boundary and drawn rect
|
|
|
|
QRect annotBoundary = a->boundary.geometry( scaledWidth, scaledHeight );
|
|
|
|
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
|
|
|
|
|
|
|
Annotation::SubType type = a->subType();
|
|
|
|
|
2005-04-08 15:45:40 +00:00
|
|
|
// draw TextAnnotation (only the 'Linked' variant)
|
|
|
|
if ( type == Annotation::AText )
|
|
|
|
{
|
|
|
|
TextAnnotation * text = (TextAnnotation *)a;
|
|
|
|
if ( text->textType != TextAnnotation::Linked )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// get pixmap, colorize and alpha-blend it
|
|
|
|
QPixmap pixmap = DesktopIcon( text->textIcon );
|
|
|
|
QImage scaledImage;
|
|
|
|
scalePixmapOnImage( scaledImage, &pixmap, annotBoundary.width(),
|
|
|
|
annotBoundary.height(), innerRect );
|
|
|
|
colorizeImage( scaledImage, a->style.color, opacity );
|
|
|
|
scaledImage.setAlphaBuffer( true );
|
2006-04-13 14:51:05 +00:00
|
|
|
pixmap = QPixmap::fromImage( scaledImage );
|
2005-04-08 15:45:40 +00:00
|
|
|
|
|
|
|
// draw the mangled image to painter
|
|
|
|
mixedPainter->drawPixmap( annotRect.topLeft(), pixmap );
|
|
|
|
}
|
|
|
|
// draw StampAnnotation
|
|
|
|
else if ( type == Annotation::AStamp )
|
|
|
|
{
|
|
|
|
StampAnnotation * stamp = (StampAnnotation *)a;
|
|
|
|
|
|
|
|
// get pixmap and alpha blend it if needed
|
|
|
|
QPixmap pixmap = DesktopIcon( stamp->stampIconName );
|
|
|
|
QImage scaledImage;
|
|
|
|
scalePixmapOnImage( scaledImage, &pixmap, annotBoundary.width(),
|
|
|
|
annotBoundary.height(), innerRect );
|
|
|
|
if ( opacity < 255 )
|
|
|
|
changeImageAlpha( scaledImage, opacity );
|
|
|
|
scaledImage.setAlphaBuffer( true );
|
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
|
2005-04-12 20:44:26 +00:00
|
|
|
else // WARNING: TEMPORARY CODE! migrate everything to AGG
|
2005-03-24 19:59:11 +00:00
|
|
|
{
|
2005-04-10 13:47:00 +00:00
|
|
|
//GeomAnnotation * geom = (GeomAnnotation *)a;
|
2005-04-08 15:45:40 +00:00
|
|
|
//if ( geom->geomType == GeomAnnotation::InscribedSquare )
|
|
|
|
//{
|
|
|
|
QImage rectImage( innerRect.width(), innerRect.height(), 32 );
|
|
|
|
const QColor & c = a->style.color;
|
|
|
|
unsigned int color = qRgba( c.red(), c.green(), c.blue(), opacity );
|
|
|
|
rectImage.fill( color );
|
|
|
|
rectImage.setAlphaBuffer( true );
|
2006-05-13 13:59:09 +00:00
|
|
|
mixedPainter->drawImage( annotRect.topLeft(), rectImage );
|
2005-04-08 15:45:40 +00:00
|
|
|
//}
|
|
|
|
//else if ( geom->geomType == GeomAnnotation::InscribedCircle )
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw extents rectangle
|
2005-11-04 11:59:51 +00:00
|
|
|
if ( KpdfSettings::debugDrawAnnotationRect() )
|
2005-04-08 15:45:40 +00:00
|
|
|
{
|
|
|
|
mixedPainter->setPen( a->style.color );
|
|
|
|
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
|
|
|
{
|
|
|
|
QColor normalColor = QApplication::palette().active().highlight();
|
|
|
|
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-03-23 19:02:55 +00:00
|
|
|
QLinkedList< 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 )
|
|
|
|
{
|
2005-02-09 17:45:16 +00:00
|
|
|
ObjectRect * rect = *lIt;
|
|
|
|
if ( (enhanceLinks && rect->objectType() == ObjectRect::Link) ||
|
|
|
|
(enhanceImages && rect->objectType() == ObjectRect::Image) )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
2005-04-01 13:54:26 +00:00
|
|
|
QRect rectGeometry = rect->geometry( scaledWidth, scaledHeight );
|
2005-01-27 17:31:07 +00:00
|
|
|
if ( rectGeometry.intersects( limitsEnlarged ) )
|
|
|
|
{
|
|
|
|
// expand rect and draw inner border
|
2006-03-29 16:46:09 +00:00
|
|
|
rectGeometry.adjust( -1,-1,1,1 );
|
2005-04-01 13:54:26 +00:00
|
|
|
mixedPainter->setPen( lightColor );
|
|
|
|
mixedPainter->drawRect( rectGeometry );
|
2005-01-27 17:31:07 +00:00
|
|
|
// expand rect to draw outer border
|
2006-03-29 16:46:09 +00:00
|
|
|
rectGeometry.adjust( -1,-1,1,1 );
|
2005-04-01 13:54:26 +00:00
|
|
|
mixedPainter->setPen( normalColor );
|
|
|
|
mixedPainter->drawRect( rectGeometry );
|
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
|
|
|
|
|
|
|
|
2005-04-01 13:54:26 +00:00
|
|
|
/** Private Helpers :: Pixmap conversion **/
|
2005-04-01 16:24:11 +00:00
|
|
|
void PagePainter::cropPixmapOnImage( QImage & dest, const QPixmap * src, const QRect & r )
|
2005-03-24 19:59:11 +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-04-05 17:49:44 +00:00
|
|
|
dest = src->toImage();
|
2005-03-24 19:59:11 +00:00
|
|
|
}
|
|
|
|
// else copy a portion of the src to an internal pixmap (smaller) and convert it
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QPixmap croppedPixmap( r.width(), r.height() );
|
|
|
|
copyBlt( &croppedPixmap, 0, 0, src, r.left(), r.top(), r.width(), r.height() );
|
2006-04-05 17:49:44 +00:00
|
|
|
dest = croppedPixmap.toImage();
|
2005-03-24 19:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-01 16:24:11 +00:00
|
|
|
void PagePainter::scalePixmapOnImage ( QImage & dest, const QPixmap * src,
|
2005-04-01 13:54:26 +00:00
|
|
|
int scaledWidth, int scaledHeight, const QRect & cropRect )
|
2005-03-24 19:59:11 +00:00
|
|
|
{
|
|
|
|
// {source, destination, scaling} params
|
|
|
|
int srcWidth = src->width(),
|
|
|
|
srcHeight = src->height(),
|
|
|
|
destLeft = cropRect.left(),
|
|
|
|
destTop = cropRect.top(),
|
|
|
|
destWidth = cropRect.width(),
|
|
|
|
destHeight = cropRect.height();
|
|
|
|
|
|
|
|
// destination image (same geometry as the pageLimits rect)
|
|
|
|
dest = QImage( destWidth, destHeight, 32 );
|
|
|
|
unsigned int * destData = (unsigned int *)dest.bits();
|
|
|
|
|
|
|
|
// source image (1:1 conversion from pixmap)
|
2006-04-05 17:49:44 +00:00
|
|
|
QImage srcImage = src->toImage();
|
2005-03-24 19:59:11 +00:00
|
|
|
unsigned int * srcData = (unsigned int *)srcImage.bits();
|
|
|
|
|
|
|
|
// precalc the x correspondancy conversion in a lookup table
|
|
|
|
unsigned int xOffset[ destWidth ];
|
|
|
|
for ( int x = 0; x < destWidth; x++ )
|
2005-04-01 13:54:26 +00:00
|
|
|
xOffset[ x ] = ((x + destLeft) * srcWidth) / scaledWidth;
|
2005-03-24 19:59:11 +00:00
|
|
|
|
|
|
|
// for each pixel of the destination image apply the color of the
|
|
|
|
// corresponsing pixel on the source image (note: keep parenthesis)
|
|
|
|
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
|
|
|
|
2005-04-12 20:44:26 +00:00
|
|
|
//BEGIN of Anti-Grain dependant code
|
|
|
|
/** Shape Drawing using Anti-Grain Geometry library **/
|
|
|
|
// The following code uses the AGG2.3 lib imported into the "painter_agg2"
|
|
|
|
// directory. This is to be replaced by Arthur calls for drawing antialiased
|
|
|
|
// primitives, but until that AGG2 does its job very fast and good-looking.
|
|
|
|
|
2005-04-13 14:49:57 +00:00
|
|
|
#include "kpdf_pixfmt_rgba.h"
|
2005-04-12 20:44:26 +00:00
|
|
|
#include "agg_rendering_buffer.h"
|
|
|
|
#include "agg_renderer_base.h"
|
|
|
|
#include "agg_scanline_u.h"
|
|
|
|
#include "agg_rasterizer_scanline_aa.h"
|
|
|
|
#include "agg_renderer_scanline.h"
|
|
|
|
#include "agg_conv_stroke.h"
|
|
|
|
#include "agg_path_storage.h"
|
|
|
|
|
2005-04-10 13:47:00 +00:00
|
|
|
void PagePainter::drawShapeOnImage(
|
|
|
|
QImage & image,
|
2005-04-12 20:44:26 +00:00
|
|
|
const NormalizedPath & normPath,
|
|
|
|
bool closeShape,
|
2005-04-10 13:47:00 +00:00
|
|
|
const QPen & pen,
|
|
|
|
const QBrush & brush,
|
2005-04-13 21:23:54 +00:00
|
|
|
double penWidthMultiplier,
|
2005-04-13 14:49:57 +00:00
|
|
|
RasterOperation op
|
2005-04-12 20:44:26 +00:00
|
|
|
//float antiAliasRadius
|
|
|
|
)
|
2005-04-10 13:47:00 +00:00
|
|
|
{
|
|
|
|
// safety checks
|
2005-04-12 20:44:26 +00:00
|
|
|
int pointsNumber = normPath.size();
|
|
|
|
if ( pointsNumber < 2 )
|
2005-04-10 13:47:00 +00:00
|
|
|
return;
|
|
|
|
|
2005-04-12 20:44:26 +00:00
|
|
|
int imageWidth = image.width();
|
|
|
|
int imageHeight = image.height();
|
|
|
|
double fImageWidth = (double)imageWidth;
|
|
|
|
double fImageHeight = (double)imageHeight;
|
|
|
|
|
|
|
|
// create a 'path'
|
|
|
|
agg::path_storage path;
|
|
|
|
path.move_to( normPath[ 0 ].x * fImageWidth, normPath[ 0 ].y * fImageHeight );
|
|
|
|
for ( int i = 1; i < pointsNumber; i++ )
|
|
|
|
path.line_to( normPath[ i ].x * fImageWidth, normPath[ i ].y * fImageHeight );
|
2005-04-24 10:03:25 +00:00
|
|
|
//path.curve4( normPath[ i ].x * fImageWidth + 2, normPath[ i ].y * fImageHeight - 2,
|
|
|
|
// normPath[ i ].x * fImageWidth, normPath[ i ].y * fImageHeight );
|
2005-04-12 20:44:26 +00:00
|
|
|
if ( closeShape )
|
|
|
|
path.close_polygon();
|
|
|
|
|
|
|
|
// create the 'rendering buffer' over qimage memory
|
|
|
|
agg::rendering_buffer buffer( image.bits(), imageWidth, imageHeight, imageWidth << 2 );
|
|
|
|
// create 'pixel buffer', 'clipped renderer', 'scanline renderer' on bgra32 format
|
|
|
|
typedef agg::pixfmt_bgra32 bgra32;
|
|
|
|
typedef agg::renderer_base< bgra32 > rb_bgra32;
|
2005-04-13 14:49:57 +00:00
|
|
|
bgra32 pixels( buffer, op == Multiply ? 1 : 0 );
|
|
|
|
rb_bgra32 rb( pixels );
|
2005-04-12 20:44:26 +00:00
|
|
|
agg::renderer_scanline_aa_solid< rb_bgra32 > render( rb );
|
|
|
|
// create rasterizer and scaline
|
|
|
|
agg::rasterizer_scanline_aa<> rasterizer;
|
|
|
|
agg::scanline_u8 scanline;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
//draw RAINBOW
|
|
|
|
agg::rgba8 span[ imageWidth ];
|
|
|
|
for( int x = 0; x < imageWidth; x++ )
|
2005-04-10 13:47:00 +00:00
|
|
|
{
|
2005-04-12 20:44:26 +00:00
|
|
|
agg::rgba c( 380.0 + 400.0 * x / imageWidth, 0.8 );
|
|
|
|
span[ x ] = agg::rgba8(c);
|
2005-04-10 13:47:00 +00:00
|
|
|
}
|
2005-04-12 20:44:26 +00:00
|
|
|
for( int y = 0; y < imageHeight; y++ )
|
2005-04-24 10:03:25 +00:00
|
|
|
pixels.blend_color_hspan( 0, y, imageWidth, span, 0, (123*y)/imageHeight );
|
2005-04-12 20:44:26 +00:00
|
|
|
#endif
|
2005-04-10 13:47:00 +00:00
|
|
|
|
2005-04-12 20:44:26 +00:00
|
|
|
// fill rect
|
|
|
|
if ( brush.style() != Qt::NoBrush )
|
2005-04-10 13:47:00 +00:00
|
|
|
{
|
2005-04-12 20:44:26 +00:00
|
|
|
const QColor & brushColor = brush.color();
|
|
|
|
render.color( agg::rgba8( brushColor.red(), brushColor.green(), brushColor.blue() ) );
|
|
|
|
rasterizer.add_path( path );
|
|
|
|
agg::render_scanlines( rasterizer, scanline, render );
|
|
|
|
rasterizer.reset();
|
2005-04-10 13:47:00 +00:00
|
|
|
}
|
|
|
|
|
2005-04-12 20:44:26 +00:00
|
|
|
// stroke outline
|
2005-04-13 21:23:54 +00:00
|
|
|
double penWidth = (double)pen.width() * penWidthMultiplier;
|
|
|
|
if ( penWidth > 0.1 )
|
2005-04-10 13:47:00 +00:00
|
|
|
{
|
2005-04-12 20:44:26 +00:00
|
|
|
const QColor & penColor = pen.color();
|
|
|
|
render.color( agg::rgba8( penColor.red(), penColor.green(), penColor.blue() ) );
|
2005-04-24 10:03:25 +00:00
|
|
|
#if 0
|
|
|
|
// BSPLINE curve over path
|
|
|
|
typedef agg::conv_bspline< agg::path_storage > conv_bspline_type;
|
|
|
|
conv_bspline_type bspline( path );
|
|
|
|
bspline.interpolation_step( 0.2 );
|
|
|
|
agg::conv_stroke< conv_bspline_type > strokedPath( bspline );
|
|
|
|
#else
|
2005-04-12 20:44:26 +00:00
|
|
|
agg::conv_stroke< agg::path_storage > strokedPath( path );
|
2005-04-24 11:03:33 +00:00
|
|
|
#endif
|
2005-04-13 21:23:54 +00:00
|
|
|
strokedPath.width( penWidth );
|
2005-04-12 20:44:26 +00:00
|
|
|
rasterizer.add_path( strokedPath );
|
|
|
|
agg::render_scanlines( rasterizer, scanline, render );
|
2005-04-10 13:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
2005-04-12 20:44:26 +00:00
|
|
|
|
|
|
|
//END of Anti-Grain dependant code
|