First try to fix font scale problem for map labels

git-svn-id: http://svn.osgeo.org/qgis/trunk@9557 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mhugent 2008-10-31 12:09:27 +00:00
parent 5c1a061256
commit 31725ec599
6 changed files with 20 additions and 35 deletions

View File

@ -47,7 +47,7 @@ public:
void renderLabel ( QPainter* painter, QgsRect& viewExtent,
QgsCoordinateTransform* coordinateTransform,
QgsMapToPixel *transform,
QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes=0, double sizeScale = 1);
QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes=0, double sizeScale = 1, double rasterScaleFactor = 1);
/** Reads the renderer configuration from an XML file
@param rnode the Dom node to read

View File

@ -298,11 +298,6 @@ public:
/** Draws the layer labels using coordinate transformation */
void drawLabels(QgsRenderContext& rendererContext);
/** \brief Draws the layer labels using coordinate transformation
* \param scale size scale, applied to all values in pixels
*/
void drawLabels(QPainter * p, const QgsRect& viewExtent, const QgsMapToPixel* cXf, const QgsCoordinateTransform* ct, double scale);
/** returns list of attributes */
QList<int> pendingAllAttributesList();

View File

@ -86,7 +86,7 @@ void QgsLabel::renderLabel( QPainter * painter, const QgsRect& viewExtent,
const QgsCoordinateTransform* coordinateTransform,
const QgsMapToPixel *transform,
QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes,
double sizeScale )
double sizeScale, double rasterScaleFactor )
{
QPen pen;
@ -155,6 +155,11 @@ void QgsLabel::renderLabel( QPainter * painter, const QgsRect& viewExtent,
double sizeMM = size * 0.3527;
size = sizeMM * sizeScale;
}
//Request font larger (multiplied by rasterScaleFactor) as a workaround for the Qt font bug
//and scale the painter down by rasterScaleFactor when drawing the label
size *= rasterScaleFactor;
if ( size > 0.0 )
{
font.setPixelSize( size );
@ -349,7 +354,7 @@ void QgsLabel::renderLabel( QPainter * painter, const QgsRect& viewExtent,
{
renderLabel( painter, overridePoint, coordinateTransform,
transform, text, font, pen, dx, dy,
xoffset, yoffset, ang, width, height, alignment, sizeScale );
xoffset, yoffset, ang, width, height, alignment, sizeScale, rasterScaleFactor );
}
else
{
@ -359,7 +364,7 @@ void QgsLabel::renderLabel( QPainter * painter, const QgsRect& viewExtent,
{
renderLabel( painter, points[i], coordinateTransform,
transform, text, font, pen, dx, dy,
xoffset, yoffset, ang, width, height, alignment, sizeScale );
xoffset, yoffset, ang, width, height, alignment, sizeScale, rasterScaleFactor );
}
}
}
@ -371,7 +376,7 @@ void QgsLabel::renderLabel( QPainter* painter, QgsPoint point,
int dx, int dy,
double xoffset, double yoffset,
double ang,
int width, int height, int alignment, double sizeScale )
int width, int height, int alignment, double sizeScale, double rasterScaleFactor )
{
// Convert point to projected units
if ( coordinateTransform )
@ -397,10 +402,13 @@ void QgsLabel::renderLabel( QPainter* painter, QgsPoint point,
x = x + xoffset * cos( rad ) - yoffset * sin( rad );
y = y - xoffset * sin( rad ) - yoffset * cos( rad );
painter->save();
painter->setFont( font );
painter->translate( x, y );
//correct oversampled font size back by scaling painter down
painter->scale(1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor);
painter->rotate( -ang );
//
@ -408,7 +416,7 @@ void QgsLabel::renderLabel( QPainter* painter, QgsPoint point,
//
if ( mLabelAttributes->bufferSizeIsSet() && mLabelAttributes->bufferEnabled() )
{
double myBufferSize = mLabelAttributes->bufferSize() * 0.3527 * sizeScale;
double myBufferSize = mLabelAttributes->bufferSize() * 0.3527 * sizeScale * rasterScaleFactor;
QPen bufferPen;
if ( mLabelAttributes->bufferColorIsSet() )
{
@ -427,7 +435,7 @@ void QgsLabel::renderLabel( QPainter* painter, QgsPoint point,
}
else //draw more dense in case of logical devices
{
bufferStepSize = 0.1;
bufferStepSize = 1 / rasterScaleFactor;
}
for ( double i = dx - myBufferSize; i <= dx + myBufferSize; i += bufferStepSize )

View File

@ -88,7 +88,7 @@ class CORE_EXPORT QgsLabel
void renderLabel( QPainter* painter, const QgsRect& viewExtent,
const QgsCoordinateTransform* coordinateTransform,
const QgsMapToPixel *transform,
QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes = 0, double sizeScale = 1. );
QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes = 0, double sizeScale = 1., double rasterScaleFactor = 1.0);
/** Reads the renderer configuration from an XML file
@param rnode the Dom node to read
@ -134,7 +134,7 @@ class CORE_EXPORT QgsLabel
int dx, int dy,
double xoffset, double yoffset,
double ang,
int width, int height, int alignment, double sizeScale = 1.0 );
int width, int height, int alignment, double sizeScale = 1.0, double rasterScaleFactor = 1.0);
/** Get label point for simple feature in map units */
void labelPoint( std::vector<QgsPoint>&, QgsFeature &feature );

View File

@ -279,20 +279,10 @@ void QgsVectorLayer::setDisplayField( QString fldName )
}
}
void QgsVectorLayer::drawLabels( QgsRenderContext& rendererContext )
{
QPainter* thePainter = rendererContext.painter();
if ( !thePainter )
{
return;
}
drawLabels( thePainter, rendererContext.extent(), &( rendererContext.mapToPixel() ), rendererContext.coordinateTransform(), rendererContext.scaleFactor() );
}
// NOTE this is a temporary method added by Tim to prevent label clipping
// which was occurring when labeller was called in the main draw loop
// This method will probably be removed again in the near future!
void QgsVectorLayer::drawLabels( QPainter * p, const QgsRect& viewExtent, const QgsMapToPixel* theMapToPixelTransform, const QgsCoordinateTransform* ct, double scale )
void QgsVectorLayer::drawLabels( QgsRenderContext& rendererContext )
{
QgsDebugMsg( "Starting draw of labels" );
@ -311,7 +301,7 @@ void QgsVectorLayer::drawLabels( QPainter * p, const QgsRect& viewExtent, const
{
// select the records in the extent. The provider sets a spatial filter
// and sets up the selection set for retrieval
select( attributes, viewExtent );
select( attributes, rendererContext.extent() );
QgsFeature fet;
while ( nextFeature( fet ) )
@ -319,7 +309,7 @@ void QgsVectorLayer::drawLabels( QPainter * p, const QgsRect& viewExtent, const
if ( mRenderer->willRenderFeature( &fet ) )
{
bool sel = mSelectedFeatureIds.contains( fet.id() );
mLabel->renderLabel( p, viewExtent, ct, theMapToPixelTransform, fet, sel, 0, scale );
mLabel->renderLabel( rendererContext.painter(), rendererContext.extent(), rendererContext.coordinateTransform(), &(rendererContext.mapToPixel()), fet, sel, 0, rendererContext.scaleFactor(), rendererContext.rasterScaleFactor());
}
featureCount++;
}

View File

@ -357,14 +357,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** Draws the layer labels using coordinate transformation */
void drawLabels( QgsRenderContext& rendererContext );
/** \brief Draws the layer labels using coordinate transformation
* \param scale size scale, applied to all values in pixels
*/
void drawLabels( QPainter * p, const QgsRect& viewExtent,
const QgsMapToPixel* cXf,
const QgsCoordinateTransform* ct,
double scale );
/** returns field list in the to-be-committed state */
const QgsFieldMap &pendingFields();