QImage *QgsPaintEffect::sourceAsImage( QgsRenderContext &context ) { //have we already created a source image? if so, return it if ( mSourceImage ) { return mSourceImage; } if ( !mPicture ) return nullptr; //else create it //TODO - test with premultiplied image for speed QRectF bounds = imageBoundingRect( context ); mSourceImage = new QImage( bounds.width(), bounds.height(), QImage::Format_ARGB32 ); mSourceImage->fill( Qt::transparent ); QPainter imagePainter( mSourceImage ); imagePainter.setRenderHint( QPainter::Antialiasing ); imagePainter.translate( -bounds.left(), -bounds.top() ); imagePainter.drawPicture( 0, 0, *mPicture ); imagePainter.end(); mOwnsImage = true; return mSourceImage; }
QPointF QgsPaintEffect::imageOffset( const QgsRenderContext &context ) const { return imageBoundingRect( context ).topLeft(); }
void BoxBuilder::handleGlyphRun_(const QGlyphRun& glyphRun) { QPainter painter_(&pixmap_); painter_.setPen(glyphPen_); painter_.drawGlyphRun(glyphPosition_,glyphRun); QVector<quint32> indices = glyphRun.glyphIndexes(); QVector<QPointF> positions = glyphRun.positions(); if(indices.size() != positions.size()) log_ << "the number of indices and the number of positions are different: " << indices.size() << " and " << positions.size() << std::endl; QVector<QPointF>::Iterator posit = positions.begin(); qreal posx = glyphPosition_.x(), posy = glyphPosition_.y(); for(QVector<quint32>::iterator ixIt = indices.begin();ixIt != indices.end();++ixIt) { QRawFont rawFont = glyphRun.rawFont(); QPainterPath painterPath = rawFont.pathForGlyph(*ixIt); QRectF glyphBoundingRect = painterPath.boundingRect(); QVector<uint> blockTextIndices(blockText_.length()); int blockTextIndicesSize = blockTextIndices.size(); rawFont.glyphIndexesForChars(blockText_.begin(),blockText_.length(),blockTextIndices.begin(),&blockTextIndicesSize); std::map<uint,QChar> glyphIndicesToChars; std::wstring blockTextStdw = blockText_.toStdWString(); // build index for acessing chars in text, since glyphs order may not correspond chars order in text for(int i = 0; i < blockTextIndices.size(); ++i) glyphIndicesToChars[blockTextIndices[i] ] = blockText_.at(i); QChar currentChar = glyphIndicesToChars[*ixIt]; unsigned histValue = 0; if(histogram.find(currentChar) == histogram.end()) histogram[currentChar] = 0; else histValue = ++histogram[currentChar]; maxHistogramValue = std::max(maxHistogramValue,histValue); //std::wcout << "processing \" "<< QString(currentChar).toStdWString() << " \"... " << std::endl; // // //log_ << "glyphBoundingRect = (" << glyphBoundingRect.x() << "," << glyphBoundingRect.y() << // "," << glyphBoundingRect.width() << "," << glyphBoundingRect.height() << ")" << std::endl; QRect screenBoundingRect( posx + posit->x() + glyphBoundingRect.x(), posy + posit->y() + glyphBoundingRect.y(), glyphBoundingRect.width()+1, glyphBoundingRect.height()+1); /* log_ << "screen layout position = (" << posx << "," << posy << ")" << std::endl; log_ << "screen glyph position = (" << posit->x() << "," << posit->y() << ")" << std::endl; log_ << "screenBoundingRect = (" << screenBoundingRect.x() << "," << screenBoundingRect.y() << "," << screenBoundingRect.width() << "," << screenBoundingRect.height() << ")" << std::end*/; QRect imageBoundingRect(QPoint( screenBoundingRect.x(), pixmap_.height()-1 - screenBoundingRect.y() - screenBoundingRect.height()+1), QPoint( screenBoundingRect.x() + screenBoundingRect.width()-1, pixmap_.height() - screenBoundingRect.y()-1) ); //log_ << "imageBoundingRect = (" << imageBoundingRect.x() << "," << imageBoundingRect.y() << // "," << imageBoundingRect.width() << "," << imageBoundingRect.height() << ")" << std::endl; if(glyphBoundingRect.width()&&glyphBoundingRect.height()) boxes_.push_back(box(glyphIndicesToChars[*ixIt],imageBoundingRect)); //painter_.setPen(boxPen_); painter_.setPen(Qt::green); //painter_.drawRect(screenBoundingRect); ++posit; } }