@@ -1415,10 +1415,16 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString t
1415
1415
}
1416
1416
}
1417
1417
w /= rasterCompressFactor;
1418
- QgsPoint ptSize = xform->toMapCoordinatesF ( w, h );
1419
1418
1419
+ #if 0 // XXX strk
1420
+ QgsPoint ptSize = xform->toMapCoordinatesF( w, h );
1420
1421
labelX = qAbs( ptSize.x() - ptZero.x() );
1421
1422
labelY = qAbs( ptSize.y() - ptZero.y() );
1423
+ #else
1424
+ double uPP = xform->mapUnitsPerPixel ();
1425
+ labelX = w * uPP;
1426
+ labelY = h * uPP;
1427
+ #endif
1422
1428
}
1423
1429
1424
1430
void QgsPalLayerSettings::registerFeature ( QgsFeature& f, const QgsRenderContext& context, QString dxfLayer )
@@ -4115,12 +4121,37 @@ QgsPalLabeling::Search QgsPalLabeling::searchMethod() const
4115
4121
void QgsPalLabeling::drawLabelCandidateRect ( pal::LabelPosition* lp, QPainter* painter, const QgsMapToPixel* xform )
4116
4122
{
4117
4123
QgsPoint outPt = xform->transform ( lp->getX (), lp->getY () );
4118
- QgsPoint outPt2 = xform->transform ( lp->getX () + lp->getWidth (), lp->getY () + lp->getHeight () );
4119
4124
4120
4125
painter->save ();
4121
- painter->translate ( QPointF ( outPt.x (), outPt.y () ) );
4126
+
4127
+ #if 1 // TODO: generalize some of this
4128
+ double w = lp->getWidth ();
4129
+ double h = lp->getHeight ();
4130
+ double cx = lp->getX () + w/2.0 ;
4131
+ double cy = lp->getY () + h/2.0 ;
4132
+ double scale = 1.0 /xform->mapUnitsPerPixel ();
4133
+ double rotation = xform->mapRotation ();
4134
+ double sw = w * scale;
4135
+ double sh = h * scale;
4136
+ QRectF rect ( -sw/2 , -sh/2 , sw, sh );
4137
+
4138
+ painter->translate ( xform->transform ( QPointF (cx, cy) ).toQPointF () );
4139
+ if ( rotation ) {
4140
+ // Only if not horizontal
4141
+ if ( lp->getFeaturePart ()->getLayer ()->getArrangement () != P_HORIZ ) {
4142
+ painter->rotate ( rotation );
4143
+ }
4144
+ }
4145
+ painter->translate ( rect.bottomLeft () );
4122
4146
painter->rotate ( -lp->getAlpha () * 180 / M_PI );
4147
+ painter->translate ( -rect.bottomLeft () );
4148
+ #else
4149
+ QgsPoint outPt2 = xform->transform( lp->getX() + lp->getWidth(), lp->getY() + lp->getHeight() );
4123
4150
QRectF rect( 0, 0, outPt2.x() - outPt.x(), outPt2.y() - outPt.y() );
4151
+ painter->translate( QPointF( outPt.x(), outPt.y() ) );
4152
+ painter->rotate( -lp->getAlpha() * 180 / M_PI );
4153
+ #endif
4154
+
4124
4155
painter->drawRect ( rect );
4125
4156
painter->restore ();
4126
4157
@@ -4172,7 +4203,7 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QgsRenderContext& con
4172
4203
drawLabelBackground ( context, component, tmpLyr );
4173
4204
}
4174
4205
4175
- if ( drawType == QgsPalLabeling::LabelBuffer
4206
+ else if ( drawType == QgsPalLabeling::LabelBuffer
4176
4207
|| drawType == QgsPalLabeling::LabelText )
4177
4208
{
4178
4209
@@ -4255,8 +4286,30 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QgsRenderContext& con
4255
4286
for ( int i = 0 ; i < lines; ++i )
4256
4287
{
4257
4288
painter->save ();
4289
+ #if 1 // TODO: generalize some of this
4290
+ LabelPosition* lp = label;
4291
+ double w = lp->getWidth ();
4292
+ double h = lp->getHeight ();
4293
+ double cx = lp->getX () + w/2.0 ;
4294
+ double cy = lp->getY () + h/2.0 ;
4295
+ double scale = 1.0 /xform->mapUnitsPerPixel ();
4296
+ double rotation = xform->mapRotation ();
4297
+ double sw = w * scale;
4298
+ double sh = h * scale;
4299
+ QRectF rect ( -sw/2 , -sh/2 , sw, sh );
4300
+ painter->translate ( xform->transform ( QPointF (cx, cy) ).toQPointF () );
4301
+ if ( rotation ) {
4302
+ // Only if not horizontal
4303
+ if ( lp->getFeaturePart ()->getLayer ()->getArrangement () != P_HORIZ ) {
4304
+ painter->rotate ( rotation );
4305
+ }
4306
+ }
4307
+ painter->translate ( rect.bottomLeft () );
4308
+ painter->rotate ( -lp->getAlpha () * 180 / M_PI );
4309
+ #else
4258
4310
painter->translate( QPointF( outPt.x(), outPt.y() ) );
4259
4311
painter->rotate( -label->getAlpha() * 180 / M_PI );
4312
+ #endif
4260
4313
4261
4314
// scale down painter: the font size has been multiplied by raster scale factor
4262
4315
// to workaround a Qt font scaling bug with small font sizes
0 commit comments