Skip to content

Commit e02c23a

Browse files
StevenBStevenB
authored andcommittedNov 10, 2007

File tree

1 file changed

+47
-40
lines changed

1 file changed

+47
-40
lines changed
 

‎src/app/composer/qgscomposervectorlegend.cpp

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition,
4040
{
4141
setupUi(this);
4242

43-
std::cout << "QgsComposerVectorLegend::QgsComposerVectorLegend()" << std::endl;
43+
//std::cout << "QgsComposerVectorLegend::QgsComposerVectorLegend()" << std::endl;
4444

4545
mComposition = composition;
4646
mId = id;
@@ -49,8 +49,8 @@ QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition,
4949
init();
5050

5151
// Font and pen
52-
if(fontSize < 6){
53-
fontSize = 6;
52+
if(fontSize < 10){
53+
fontSize = 10;
5454
}
5555
mFont.setPointSize ( fontSize );
5656

@@ -75,7 +75,7 @@ QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition,
7575
QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition, int id )
7676
: QGraphicsRectItem(0,0,10,10,0)
7777
{
78-
std::cout << "QgsComposerVectorLegend::QgsComposerVectorLegend()" << std::endl;
78+
//std::cout << "QgsComposerVectorLegend::QgsComposerVectorLegend()" << std::endl;
7979

8080
setupUi(this);
8181

@@ -145,12 +145,13 @@ void QgsComposerVectorLegend::init ( void )
145145

146146
QgsComposerVectorLegend::~QgsComposerVectorLegend()
147147
{
148-
std::cerr << "QgsComposerVectorLegend::~QgsComposerVectorLegend()" << std::endl;
148+
//std::cerr << "QgsComposerVectorLegend::~QgsComposerVectorLegend()" << std::endl;
149149
}
150150

151+
#define FONT_WORKAROUND_SCALE 10
151152
QRectF QgsComposerVectorLegend::render ( QPainter *p )
152153
{
153-
std::cout << "QgsComposerVectorLegend::render p = " << p << std::endl;
154+
//std::cout << "QgsComposerVectorLegend::render p = " << p << std::endl;
154155

155156
// Painter can be 0, create dummy to avoid many if below
156157
QPainter *painter = NULL;
@@ -162,16 +163,16 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
162163
painter = new QPainter( pixmap );
163164
}
164165

165-
std::cout << "mComposition->scale() = " << mComposition->scale() << std::endl;
166+
//std::cout << "mComposition->scale() = " << mComposition->scale() << std::endl;
166167

167168
// Font size in canvas units
168169
float titleSize = 25.4 * mComposition->scale() * mTitleFont.pointSizeFloat() / 72;
169170
float sectionSize = 25.4 * mComposition->scale() * mSectionFont.pointSizeFloat() / 72;
170171
float size = 25.4 * mComposition->scale() * mFont.pointSizeFloat() / 72;
171172

172-
std::cout << "font sizes = " << titleSize << " " << sectionSize << " " << size << std::endl;
173+
//std::cout << "font sizes = " << titleSize << " " << sectionSize << " " << size << std::endl;
173174

174-
// Metrics
175+
// Create fonts
175176
QFont titleFont ( mTitleFont );
176177
QFont sectionFont ( mSectionFont );
177178
QFont font ( mFont );
@@ -180,43 +181,50 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
180181
sectionFont.setPointSizeFloat ( sectionSize );
181182
font.setPointSizeFloat ( size );
182183

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+
183190
QFontMetrics titleMetrics ( titleFont );
184191
QFontMetrics sectionMetrics ( sectionFont );
185192
QFontMetrics metrics ( font );
186193

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-
192194
if ( plotStyle() == QgsComposition::Postscript) //do we need seperate PostScript rendering settings?
193195
{
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 );
197204
}
198205
else
199206
{
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 );
203210
}
204211

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-
210212
int x, y;
211213

212214
// Legend title -if we do this later, we can center it
213215
y = mMargin + titleMetrics.height();
214216
painter->setPen ( mPen );
215217
painter->setFont ( titleFont );
216218

217-
painter->drawText( (int) (2*mMargin), y, mTitle );
218219

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
220228
int width = 4 * mMargin + titleMetrics.width ( mTitle );
221229
int height = mMargin + mSymbolSpace + titleMetrics.height(); // mSymbolSpace?
222230

@@ -308,9 +316,9 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
308316

309317
if ( itemLabels[icnt].length() == 0 ) {
310318
if ( sym->label().length() > 0 ) {
311-
itemLabels[icnt] = sym->label();
319+
itemLabels[icnt] = sym->label();
312320
} else {
313-
itemLabels[icnt] = sym->lowerValue();
321+
itemLabels[icnt] = sym->lowerValue();
314322
if (sym->upperValue().length() > 0)
315323
itemLabels[icnt] += " - " + sym->upperValue();
316324
}
@@ -334,7 +342,11 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
334342
painter->setPen ( mPen );
335343
painter->setFont ( sectionFont );
336344

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();
338350

339351
int w = 3*mMargin + sectionMetrics.width( sectionTitle );
340352
if ( w > width ) width = w;
@@ -369,20 +381,13 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
369381
QPen pen = sym->pen();
370382
double widthScale = map->widthScale();
371383

372-
std::cout << "widthScale: " << widthScale << std::endl;
373-
374384
pen.setWidthF( ( widthScale * pen.widthF() ) );
375385
painter->setPen ( pen );
376386
painter->setBrush ( sym->brush() );
377387

378388
if ( vector->vectorType() == QGis::Point ) {
379-
double scale = map->symbolScale();// * mComposition->scale();
389+
double scale = map->symbolScale();
380390

381-
/* if (plotStyle() != QgsComposition::Preview)
382-
{
383-
scale /= mComposition->viewScale();
384-
}
385-
*/
386391
// Get the picture of appropriate size directly from catalogue
387392
QPixmap pic = QPixmap::fromImage(sym->getPointSymbolAsImage(widthScale,false,sym->color()));
388393

@@ -417,9 +422,11 @@ std::cout << "widthScale: " << widthScale << std::endl;
417422
QRect br = metrics.boundingRect ( lab );
418423
x = (int) ( 2*mMargin + mSymbolWidth );
419424
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
420427

421-
painter->drawText( x, y, lab );
422-
428+
painter->drawText( x * FONT_WORKAROUND_SCALE, y * FONT_WORKAROUND_SCALE, lab );
429+
painter->restore();
423430
int w = 3*mMargin + mSymbolWidth + metrics.width(lab);
424431
if ( w > width ) width = w;
425432

0 commit comments

Comments
 (0)
Please sign in to comment.