Skip to content
Permalink
Browse files

Fix label size for painting main map with higher dpi

  • Loading branch information
mhugent committed Nov 28, 2013
1 parent 6cb2612 commit e07f51136e0541c34c016cccae7f70050f7a84e2
Showing with 15 additions and 20 deletions.
  1. +14 −19 src/core/qgspallabeling.cpp
  2. +1 −1 src/core/qgspallabeling.h
@@ -3845,6 +3845,15 @@ void QgsPalLabeling::drawLabeling( QgsRenderContext& context )

painter->setRenderHint( QPainter::Antialiasing );

//dpi ration for QPicture
QPicture localPict;
QPainter localp;
localp.begin( &localPict );
double localdpi = ( localp.device()->logicalDpiX() + localp.device()->logicalDpiY() ) / 2;
double contextdpi = ( painter->device()->logicalDpiX() + painter->device()->logicalDpiY() ) / 2;
double dpiRatio = localdpi / contextdpi;
localp.end();

// draw the labels
std::list<LabelPosition*>::iterator it = labels->begin();
for ( ; it != labels->end(); ++it )
@@ -3939,15 +3948,15 @@ void QgsPalLabeling::drawLabeling( QgsRenderContext& context )

if ( tmpLyr.shapeDraw )
{
drawLabel( *it, context, tmpLyr, LabelShape );
drawLabel( *it, context, tmpLyr, LabelShape, dpiRatio );
}

if ( tmpLyr.bufferDraw )
{
drawLabel( *it, context, tmpLyr, LabelBuffer );
drawLabel( *it, context, tmpLyr, LabelBuffer, dpiRatio );
}

drawLabel( *it, context, tmpLyr, LabelText );
drawLabel( *it, context, tmpLyr, LabelText, dpiRatio );

if ( mLabelSearchTree )
{
@@ -4075,28 +4084,14 @@ void QgsPalLabeling::drawLabelCandidateRect( pal::LabelPosition* lp, QPainter* p
drawLabelCandidateRect( lp->getNextPart(), painter, xform );
}

void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QgsRenderContext& context, QgsPalLayerSettings& tmpLyr, DrawLabelType drawType )
void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QgsRenderContext& context, QgsPalLayerSettings& tmpLyr, DrawLabelType drawType, double dpiRatio )
{
// NOTE: this is repeatedly called for multi-part labels
QPainter* painter = context.painter();
const QgsMapToPixel* xform = &context.mapToPixel();

QgsLabelComponent component;

// account for print output or image saving @ specific dpi
if ( !qgsDoubleNear( context.rasterScaleFactor(), 1.0, 0.1 ) )
{
// find relative dpi scaling for local painter
QPicture localPict;
QPainter localp;
localp.begin( &localPict );

double localdpi = ( localp.device()->logicalDpiX() + localp.device()->logicalDpiY() ) / 2;
double contextdpi = ( painter->device()->logicalDpiX() + painter->device()->logicalDpiY() ) / 2;
component.setDpiRatio( localdpi / contextdpi );

localp.end();
}
component.setDpiRatio( dpiRatio );

QgsPoint outPt = xform->transform( label->getX(), label->getY() );
// QgsPoint outPt2 = xform->transform( label->getX() + label->getWidth(), label->getY() + label->getHeight() );
@@ -723,7 +723,7 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
void drawLabelCandidateRect( pal::LabelPosition* lp, QPainter* painter, const QgsMapToPixel* xform );
//!drawLabel
//! @note not available in python bindings
void drawLabel( pal::LabelPosition* label, QgsRenderContext& context, QgsPalLayerSettings& tmpLyr, DrawLabelType drawType );
void drawLabel( pal::LabelPosition* label, QgsRenderContext& context, QgsPalLayerSettings& tmpLyr, DrawLabelType drawType, double dpiRatio = 1.0 );

static void drawLabelBuffer( QgsRenderContext& context,
QgsLabelComponent component,

0 comments on commit e07f511

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