Skip to content

Commit ab1faa7

Browse files
StevenBStevenB
StevenB
authored and
StevenB
committed
Fixed a bug that was causing map label font sizes not to match
between the rendered preview and the printout. git-svn-id: http://svn.osgeo.org/qgis/trunk@7254 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a813d5c commit ab1faa7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/app/composer/qgscomposermap.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@
2525
#include "qgsmaprender.h"
2626
#include "qgsvectorlayer.h"
2727

28+
#include "qgslabel.h"
29+
#include "qgslabelattributes.h"
30+
2831
#include <QGraphicsScene>
2932
#include <QGraphicsRectItem>
3033
#include <QPainter>
3134
#include <iostream>
3235
#include <cmath>
36+
3337
// round isn't defined by default in msvc
3438
#ifdef _MSC_VER
3539
#define round(x) ((x) >= 0 ? floor((x)+0.5) : floor((x)-0.5))
@@ -221,7 +225,24 @@ void QgsComposerMap::draw ( QPainter *painter, QgsRect &extent, QgsMapToPixel *t
221225
// should use size metrics.ascent() * 72.0 / mComposition->resolution();
222226
// We could add a factor for metrics.ascent()/size but it is variable
223227
// Add a parrameter in drawLables() ?
224-
fontScale = 72.0 / mComposition->resolution();
228+
229+
QFont tempFont;
230+
tempFont.setFamily(vector->label()->layerAttributes()->family());
231+
232+
double size = vector->label()->layerAttributes()->size();
233+
size = 25.4 * size / 72;
234+
235+
tempFont.setPointSizeF(size);
236+
QFontMetricsF tempMetrics(tempFont);
237+
238+
fontScale = tempMetrics.ascent() * 72.0 / mComposition->resolution();
239+
//std::cout << "fontScale: " << fontScale << std::endl;
240+
241+
fontScale *= mFontScale;
242+
243+
//divide out the font size, since it will be multiplied back in when drawing the labels
244+
fontScale /= vector->label()->layerAttributes()->size();
245+
225246
}
226247
vector->drawLabels ( painter, extent, transform, ct, fontScale );
227248
}

0 commit comments

Comments
 (0)