Skip to content
Permalink
Browse files

Fixed drawing of buffers for curved labels, better(?) drawing of buff…

…er (painter path instead of size^2 calls to drawText)

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11179 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jul 26, 2009
1 parent 6b93874 commit 3d049846746979fb8209abcbaffc3038caabc101
Showing with 38 additions and 18 deletions.
  1. +3 −2 src/plugins/labeling/labelpreview.cpp
  2. +33 −14 src/plugins/labeling/pallabeling.cpp
  3. +2 −2 src/plugins/labeling/pallabeling.h
@@ -26,12 +26,13 @@ void LabelPreview::paintEvent(QPaintEvent* e)
{
QPainter p(this);

p.setRenderHint(QPainter::Antialiasing);
p.setFont(font());
p.setPen(mTextColor);
p.translate(10, 20); // uhm...

if (mBufferSize != 0)
PalLabeling::drawLabelBuffer(&p, text(), mBufferSize, mBufferColor);
PalLabeling::drawLabelBuffer(&p, text(), font(), mBufferSize, mBufferColor);

p.setPen(mTextColor);
p.drawText(0,0, text());
}
@@ -389,6 +389,11 @@ void PalLabeling::doLabeling(QPainter* painter, QgsRectangle extent)
std::list<LabelPosition*>::iterator it = labels->begin();
for ( ; it != labels->end(); ++it)
{
const LayerSettings& lyr = layer((*it)->getLayerName());

if (lyr.bufferSize != 0)
drawLabel( *it, painter, xform, true);

drawLabel( *it, painter, xform );
}

@@ -455,43 +460,57 @@ void PalLabeling::drawLabelCandidateRect( pal::LabelPosition* lp, QPainter* pain
drawLabelCandidateRect(lp->getNextPart(), painter, xform);
}

#include "qgslogger.h"

void PalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, const QgsMapToPixel* xform)
void PalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, const QgsMapToPixel* xform, bool drawBuffer)
{
QgsPoint outPt = xform->transform(label->getX(), label->getY());

// TODO: optimize access :)
const LayerSettings& lyr = layer(label->getLayerName());

QString text = ((MyLabel*)label->getFeature()->getUserGeometry())->text();
QString txt = ( label->getPartId() == -1 ? text : QString( text[label->getPartId()] ) );

QgsDebugMsg("drawLabel " + QString::number(drawBuffer) + " " + txt);

// shift by one as we have 2px border
painter->save();
painter->translate( QPointF(outPt.x()+1, outPt.y()-1-lyr.fontBaseline) );
painter->rotate(-label->getAlpha() * 180 / M_PI );
painter->setFont( lyr.textFont );

if (lyr.bufferSize != 0)
drawLabelBuffer(painter, text, lyr.bufferSize, lyr.bufferColor);

painter->setPen( lyr.textColor );
if (label->getPartId() == -1)
painter->drawText(0,0, text);
if (drawBuffer)
{
// we're drawing buffer
drawLabelBuffer(painter, txt, lyr.textFont, lyr.bufferSize, lyr.bufferColor);
}
else
painter->drawText(0,0, QString( text[label->getPartId()] ) );
{
// we're drawing real label
painter->setFont( lyr.textFont );
painter->setPen( lyr.textColor );
painter->drawText(0,0, txt);
}
painter->restore();

if (label->getNextPart())
drawLabel( label->getNextPart(), painter, xform );
drawLabel( label->getNextPart(), painter, xform, drawBuffer );
}


void PalLabeling::drawLabelBuffer(QPainter* p, QString text, int size, QColor color)
void PalLabeling::drawLabelBuffer(QPainter* p, QString text, const QFont& font, int size, QColor color)
{
p->save();
p->setPen(color);
/*
p->setFont( font );
p->setPen( color );
for (int x = -size; x <= size; x++)
for (int y = -size; y <= size; y++)
p->drawText(x,y, text);
p->restore();
*/

QPainterPath path;
path.addText(0,0, font, text);
p->setPen( QPen(color, size) );
p->setBrush( color );
p->drawPath(path);
}
@@ -123,8 +123,8 @@ class PalLabeling


void drawLabelCandidateRect( pal::LabelPosition* lp, QPainter* painter, const QgsMapToPixel* xform );
void drawLabel( pal::LabelPosition* label, QPainter* painter, const QgsMapToPixel* xform);
static void drawLabelBuffer(QPainter* p, QString text, int size, QColor color);
void drawLabel( pal::LabelPosition* label, QPainter* painter, const QgsMapToPixel* xform, bool drawBuffer = false);
static void drawLabelBuffer(QPainter* p, QString text, const QFont& font, int size, QColor color);

protected:

0 comments on commit 3d04984

Please sign in to comment.
You can’t perform that action at this time.