@@ -40,7 +40,7 @@ QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition,
40
40
{
41
41
setupUi (this );
42
42
43
- std::cout << " QgsComposerVectorLegend::QgsComposerVectorLegend()" << std::endl;
43
+ // std::cout << "QgsComposerVectorLegend::QgsComposerVectorLegend()" << std::endl;
44
44
45
45
mComposition = composition;
46
46
mId = id;
@@ -49,8 +49,8 @@ QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition,
49
49
init ();
50
50
51
51
// Font and pen
52
- if (fontSize < 6 ){
53
- fontSize = 6 ;
52
+ if (fontSize < 10 ){
53
+ fontSize = 10 ;
54
54
}
55
55
mFont .setPointSize ( fontSize );
56
56
@@ -75,7 +75,7 @@ QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition,
75
75
QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition, int id )
76
76
: QGraphicsRectItem(0 ,0 ,10 ,10 ,0 )
77
77
{
78
- std::cout << " QgsComposerVectorLegend::QgsComposerVectorLegend()" << std::endl;
78
+ // std::cout << "QgsComposerVectorLegend::QgsComposerVectorLegend()" << std::endl;
79
79
80
80
setupUi (this );
81
81
@@ -145,12 +145,13 @@ void QgsComposerVectorLegend::init ( void )
145
145
146
146
QgsComposerVectorLegend::~QgsComposerVectorLegend ()
147
147
{
148
- std::cerr << " QgsComposerVectorLegend::~QgsComposerVectorLegend()" << std::endl;
148
+ // std::cerr << "QgsComposerVectorLegend::~QgsComposerVectorLegend()" << std::endl;
149
149
}
150
150
151
+ #define FONT_WORKAROUND_SCALE 10
151
152
QRectF QgsComposerVectorLegend::render ( QPainter *p )
152
153
{
153
- std::cout << " QgsComposerVectorLegend::render p = " << p << std::endl;
154
+ // std::cout << "QgsComposerVectorLegend::render p = " << p << std::endl;
154
155
155
156
// Painter can be 0, create dummy to avoid many if below
156
157
QPainter *painter = NULL ;
@@ -162,16 +163,16 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
162
163
painter = new QPainter ( pixmap );
163
164
}
164
165
165
- std::cout << " mComposition->scale() = " << mComposition ->scale () << std::endl;
166
+ // std::cout << "mComposition->scale() = " << mComposition->scale() << std::endl;
166
167
167
168
// Font size in canvas units
168
169
float titleSize = 25.4 * mComposition ->scale () * mTitleFont .pointSizeFloat () / 72 ;
169
170
float sectionSize = 25.4 * mComposition ->scale () * mSectionFont .pointSizeFloat () / 72 ;
170
171
float size = 25.4 * mComposition ->scale () * mFont .pointSizeFloat () / 72 ;
171
172
172
- std::cout << " font sizes = " << titleSize << " " << sectionSize << " " << size << std::endl;
173
+ // std::cout << "font sizes = " << titleSize << " " << sectionSize << " " << size << std::endl;
173
174
174
- // Metrics
175
+ // Create fonts
175
176
QFont titleFont ( mTitleFont );
176
177
QFont sectionFont ( mSectionFont );
177
178
QFont font ( mFont );
@@ -180,43 +181,50 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
180
181
sectionFont.setPointSizeFloat ( sectionSize );
181
182
font.setPointSizeFloat ( size );
182
183
184
+ // Not sure about Style Strategy, QFont::PreferMatch?
185
+ titleFont.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias) );
186
+ sectionFont.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias) );
187
+ font.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias) );
188
+
189
+
183
190
QFontMetrics titleMetrics ( titleFont );
184
191
QFontMetrics sectionMetrics ( sectionFont );
185
192
QFontMetrics metrics ( font );
186
193
187
- // Fonts for Postscript rendering
188
- double psTitleSize = titleMetrics.ascent () * 72.0 / mComposition ->resolution (); // What??
189
- double psSectionSize = sectionMetrics.ascent () * 72.0 / mComposition ->resolution ();
190
- double psSize = metrics.ascent () * 72.0 / mComposition ->resolution ();
191
-
192
194
if ( plotStyle () == QgsComposition::Postscript) // do we need seperate PostScript rendering settings?
193
195
{
194
- titleFont.setPointSizeFloat ( psTitleSize );
195
- sectionFont.setPointSizeFloat ( psSectionSize );
196
- font.setPointSizeFloat ( psSize );
196
+ // Fonts sizes for Postscript rendering
197
+ double psTitleSize = titleMetrics.ascent () * 72.0 / mComposition ->resolution (); // What??
198
+ double psSectionSize = sectionMetrics.ascent () * 72.0 / mComposition ->resolution ();
199
+ double psSize = metrics.ascent () * 72.0 / mComposition ->resolution ();
200
+
201
+ titleFont.setPointSizeFloat ( psTitleSize * FONT_WORKAROUND_SCALE );
202
+ sectionFont.setPointSizeFloat ( psSectionSize * FONT_WORKAROUND_SCALE );
203
+ font.setPointSizeFloat ( psSize * FONT_WORKAROUND_SCALE );
197
204
}
198
205
else
199
206
{
200
- titleFont.setPointSizeFloat ( titleSize );
201
- sectionFont.setPointSizeFloat ( sectionSize );
202
- font.setPointSizeFloat ( size );
207
+ titleFont.setPointSizeFloat ( titleSize * FONT_WORKAROUND_SCALE );
208
+ sectionFont.setPointSizeFloat ( sectionSize * FONT_WORKAROUND_SCALE );
209
+ font.setPointSizeFloat ( size * FONT_WORKAROUND_SCALE );
203
210
}
204
211
205
- // Not sure about Style Strategy, QFont::PreferMatch?
206
- titleFont.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias) );
207
- sectionFont.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias) );
208
- font.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias) );
209
-
210
212
int x, y;
211
213
212
214
// Legend title -if we do this later, we can center it
213
215
y = mMargin + titleMetrics.height ();
214
216
painter->setPen ( mPen );
215
217
painter->setFont ( titleFont );
216
218
217
- painter->drawText ( (int ) (2 *mMargin ), y, mTitle );
218
219
219
- // used to keep track of total width and height
220
+ painter->save (); // Save the painter state so we can undo the scaling later
221
+ painter->scale (1 ./FONT_WORKAROUND_SCALE, 1 ./FONT_WORKAROUND_SCALE); // scale the painter to work around the font bug
222
+
223
+ painter->drawText ( 2 * mMargin * FONT_WORKAROUND_SCALE, y * FONT_WORKAROUND_SCALE, mTitle );
224
+
225
+ painter->restore ();
226
+
227
+ // used to keep track of total width and height - probably should be changed to float/double
220
228
int width = 4 * mMargin + titleMetrics.width ( mTitle );
221
229
int height = mMargin + mSymbolSpace + titleMetrics.height (); // mSymbolSpace?
222
230
@@ -308,9 +316,9 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
308
316
309
317
if ( itemLabels[icnt].length () == 0 ) {
310
318
if ( sym->label ().length () > 0 ) {
311
- itemLabels[icnt] = sym->label ();
319
+ itemLabels[icnt] = sym->label ();
312
320
} else {
313
- itemLabels[icnt] = sym->lowerValue ();
321
+ itemLabels[icnt] = sym->lowerValue ();
314
322
if (sym->upperValue ().length () > 0 )
315
323
itemLabels[icnt] += " - " + sym->upperValue ();
316
324
}
@@ -334,7 +342,11 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
334
342
painter->setPen ( mPen );
335
343
painter->setFont ( sectionFont );
336
344
337
- painter->drawText ( x, y, sectionTitle );
345
+ painter->save (); // Save the painter state so we can undo the scaling later
346
+ painter->scale (1 ./FONT_WORKAROUND_SCALE, 1 ./FONT_WORKAROUND_SCALE); // scale the painter to work around the font bug
347
+
348
+ painter->drawText ( x * FONT_WORKAROUND_SCALE, y * FONT_WORKAROUND_SCALE, sectionTitle );
349
+ painter->restore ();
338
350
339
351
int w = 3 *mMargin + sectionMetrics.width ( sectionTitle );
340
352
if ( w > width ) width = w;
@@ -369,20 +381,13 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
369
381
QPen pen = sym->pen ();
370
382
double widthScale = map->widthScale ();
371
383
372
- std::cout << " widthScale: " << widthScale << std::endl;
373
-
374
384
pen.setWidthF ( ( widthScale * pen.widthF () ) );
375
385
painter->setPen ( pen );
376
386
painter->setBrush ( sym->brush () );
377
387
378
388
if ( vector->vectorType () == QGis::Point ) {
379
- double scale = map->symbolScale ();// * mComposition->scale();
389
+ double scale = map->symbolScale ();
380
390
381
- /* if (plotStyle() != QgsComposition::Preview)
382
- {
383
- scale /= mComposition->viewScale();
384
- }
385
- */
386
391
// Get the picture of appropriate size directly from catalogue
387
392
QPixmap pic = QPixmap::fromImage (sym->getPointSymbolAsImage (widthScale,false ,sym->color ()));
388
393
@@ -417,9 +422,11 @@ std::cout << "widthScale: " << widthScale << std::endl;
417
422
QRect br = metrics.boundingRect ( lab );
418
423
x = (int ) ( 2 *mMargin + mSymbolWidth );
419
424
y = (int ) ( localHeight + symbolHeight/2 + ( metrics.height ()/2 - metrics.descent ()) );
425
+ painter->save (); // Save the painter state so we can undo the scaling later
426
+ painter->scale (1 ./FONT_WORKAROUND_SCALE, 1 ./FONT_WORKAROUND_SCALE); // scale the painter to work around the font bug
420
427
421
- painter->drawText ( x, y, lab );
422
-
428
+ painter->drawText ( x * FONT_WORKAROUND_SCALE , y * FONT_WORKAROUND_SCALE , lab );
429
+ painter-> restore ();
423
430
int w = 3 *mMargin + mSymbolWidth + metrics.width (lab);
424
431
if ( w > width ) width = w;
425
432
0 commit comments