[QGIS Commit] r11179 - branches/symbology-ng-branch/src/plugins/labeling

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Jul 26 07:04:17 EDT 2009


Author: wonder
Date: 2009-07-26 07:04:17 -0400 (Sun, 26 Jul 2009)
New Revision: 11179

Modified:
   branches/symbology-ng-branch/src/plugins/labeling/labelpreview.cpp
   branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp
   branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h
Log:
Fixed drawing of buffers for curved labels, better(?) drawing of buffer (painter path instead of size^2 calls to drawText)


Modified: branches/symbology-ng-branch/src/plugins/labeling/labelpreview.cpp
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/labelpreview.cpp	2009-07-26 11:01:47 UTC (rev 11178)
+++ branches/symbology-ng-branch/src/plugins/labeling/labelpreview.cpp	2009-07-26 11:04:17 UTC (rev 11179)
@@ -26,12 +26,13 @@
 {
   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());
 }

Modified: branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp	2009-07-26 11:01:47 UTC (rev 11178)
+++ branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp	2009-07-26 11:04:17 UTC (rev 11179)
@@ -389,6 +389,11 @@
   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,8 +460,9 @@
     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());
 
@@ -464,34 +470,47 @@
   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);
 }

Modified: branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h	2009-07-26 11:01:47 UTC (rev 11178)
+++ branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h	2009-07-26 11:04:17 UTC (rev 11179)
@@ -123,8 +123,8 @@
 
 
     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:
 



More information about the QGIS-commit mailing list