📄 pagepainter.cpp.svn-base
字号:
} } // 4B.4. paint annotations [COMPOSITED ONES] if ( bufferedAnnotations ) { // precalc costants for normalizing the quads to the image 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(); // paint all buffered annotations in the page QList< Annotation * >::const_iterator aIt = bufferedAnnotations->begin(), aEnd = bufferedAnnotations->end(); for ( ; aIt != aEnd; ++aIt ) { Annotation * a = *aIt; Annotation::SubType type = a->subType(); // draw TextAnnotation (InPlace) MISSING: all if ( type == Annotation::AText ) { // TODO } // draw LineAnnotation MISSING: all else if ( type == Annotation::ALine ) { // get the annotation LineAnnotation * la = (LineAnnotation *) a; NormalizedPath path; // normalize page point to image NormalizedPoint inkPoint = la->linePoints.first(); NormalizedPoint point; point.x = (inkPoint.x - xOffset) * xScale; point.y = (inkPoint.y - yOffset) * yScale; path.append( point ); inkPoint = la->linePoints.last(); point.x = (inkPoint.x - xOffset) * xScale; point.y = (inkPoint.y - yOffset) * yScale; path.append( point ); // draw the line as normalized path into image drawShapeOnImage( backImage, path, false, QPen( a->style.color,a->style.width ), QBrush(), pageScale ,Multiply); } // draw GeomAnnotation MISSING: all else if ( type == Annotation::AGeom ) { // TODO } // draw HighlightAnnotation MISSING: under/strike width, feather, capping else if ( type == Annotation::AHighlight ) { // get the annotation HighlightAnnotation * ha = (HighlightAnnotation *) a; HighlightAnnotation::HighlightType type = ha->highlightType; // draw each quad of the annotation int quads = ha->highlightQuads.size(); for ( int q = 0; q < quads; q++ ) { NormalizedPath path; const HighlightAnnotation::Quad & quad = ha->highlightQuads[ q ]; // normalize page point to image 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 ); } // draw the normalized path into image switch ( type ) { // highlight the whole rect case HighlightAnnotation::Highlight: drawShapeOnImage( backImage, path, true, QPen(), a->style.color, pageScale, Multiply ); 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; drawShapeOnImage( backImage, path, true, QPen(), a->style.color, pageScale, Multiply ); 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(); drawShapeOnImage( backImage, path, false, QPen( a->style.color, 2 ), QBrush(), pageScale ); 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(); drawShapeOnImage( backImage, path, false, QPen( a->style.color, 2 ), QBrush(), pageScale ); break; } } } // 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; const QLinkedList<NormalizedPoint> & inkPath = ia->inkPaths[ p ]; // normalize page point to image QLinkedList<NormalizedPoint>::const_iterator pIt = inkPath.begin(), pEnd = inkPath.end(); 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 drawShapeOnImage( backImage, path, false, QPen( a->style.color, a->style.width ), QBrush(), pageScale ); } } } // end current annotation drawing } // 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 ); mixedPainter->translate( -limits.left(), -limits.top() ); } /** 5 -- MIXED FLOW. Draw ANNOTATIONS [OPAQUE ONES] on ACTIVE PAINTER **/ if ( unbufferedAnnotations ) { // iterate over annotations and paint AText, AGeom, AStamp QList< Annotation * >::const_iterator aIt = unbufferedAnnotations->begin(), aEnd = unbufferedAnnotations->end(); for ( ; aIt != aEnd; ++aIt ) { Annotation * a = *aIt; // honour opacity settings on supported types unsigned int opacity = (unsigned int)( 255.0 * a->style.opacity ); if ( opacity <= 0 ) continue; // 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() ); Annotation::SubType type = a->subType(); // draw TextAnnotation (NOT only the 'Linked' variant) if ( type == Annotation::AText ) { TextAnnotation * text = (TextAnnotation *)a; if ( text->textType == TextAnnotation::InPlace ) { //Have the square of fixed size and adapting text font QFontMetricsF mf(text->textFont); QRectF rcf=mf.boundingRect(text->inplaceText); QSize sz(int(rcf.width()+5), int(rcf.height()+5)); if(sz.height()<annotBoundary.height()) sz.setHeight(annotBoundary.height()); if(sz.width()<annotBoundary.width()) sz.setWidth(annotBoundary.width()); QPixmap pixmap(sz); pixmap.fill( a->style.color ); QPainter painter; painter.begin( &pixmap ); painter.setPen( Qt::black );//( NoPen ); //painter.setBrush( bule); painter.drawRect( 0, 0, sz.width()-2, sz.height()-2 ); //painter.drawText(2,sz.height()/2+int(rcf.height()/2),text->inplaceText); painter.drawText(0,0,sz.width(),sz.height(), Qt::AlignVCenter|Qt::AlignLeft|Qt::TextWrapAnywhere, text->inplaceText); painter.end(); QImage scaledImage; scalePixmapOnImage( scaledImage, &pixmap, annotBoundary.width(), annotBoundary.height(), innerRect ); //colorizeImage( scaledImage, a->style.color, opacity ); //scaledImage.setAlphaBuffer( true ); pixmap = QPixmap::fromImage( scaledImage ); mixedPainter->drawPixmap( annotRect.topLeft(), pixmap ); } if ( text->textType == TextAnnotation::Linked ) { // 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 ); pixmap = QPixmap::fromImage( scaledImage ); // 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 ); pixmap = QPixmap::fromImage( scaledImage ); // draw the scaled and al mixedPainter->drawPixmap( annotRect.topLeft(), pixmap ); } // draw GeomAnnotation else // WARNING: TEMPORARY CODE! migrate everything to AGG { //GeomAnnotation * geom = (GeomAnnotation *)a; //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 ); mixedPainter->drawImage( annotRect.topLeft(), rectImage ); //} //else if ( geom->geomType == GeomAnnotation::InscribedCircle ) } // draw extents rectangle if ( KpdfSettings::debugDrawAnnotationRect() ) { mixedPainter->setPen( a->style.color );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -