@@ -317,8 +317,9 @@ QImage* QgsWMSServer::getLegendGraphics()
317317 // get icon size, spaces between legend items and font from config parser
318318 double boxSpace, layerSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight;
319319 QFont layerFont, itemFont;
320+ QColor layerFontColor, itemFontColor;
320321 legendParameters ( mmToPixelFactor, fontOversamplingFactor, boxSpace, layerSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight,
321- layerFont, itemFont );
322+ layerFont, itemFont, layerFontColor, itemFontColor );
322323
323324 // first find out image dimensions without painting
324325 QStandardItem* rootItem = legendModel.invisibleRootItem ();
@@ -340,8 +341,9 @@ QImage* QgsWMSServer::getLegendGraphics()
340341 if ( layerItem )
341342 {
342343
343- drawLegendLayerItem ( layerItem, 0 , maxTextWidth, maxSymbolWidth, currentY, layerFont, itemFont, boxSpace, layerSpace, symbolSpace,
344- iconLabelSpace, symbolWidth, symbolHeight, fontOversamplingFactor, theImage->dotsPerMeterX () * 0.0254 );
344+ drawLegendLayerItem ( layerItem, 0 , maxTextWidth, maxSymbolWidth, currentY, layerFont, layerFontColor, itemFont, itemFontColor,
345+ boxSpace, layerSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight, fontOversamplingFactor,
346+ theImage->dotsPerMeterX () * 0.0254 );
345347 }
346348 }
347349 currentY += boxSpace;
@@ -359,8 +361,9 @@ QImage* QgsWMSServer::getLegendGraphics()
359361 QgsComposerLayerItem* layerItem = dynamic_cast <QgsComposerLayerItem*>( rootItem->child ( i ) );
360362 if ( layerItem )
361363 {
362- drawLegendLayerItem ( layerItem, &p, maxTextWidth, maxSymbolWidth, currentY, layerFont, itemFont, boxSpace, layerSpace, symbolSpace,
363- iconLabelSpace, symbolWidth, symbolHeight, fontOversamplingFactor, theImage->dotsPerMeterX () * 0.0254 );
364+ drawLegendLayerItem ( layerItem, &p, maxTextWidth, maxSymbolWidth, currentY, layerFont, layerFontColor, itemFont, itemFontColor, boxSpace,
365+ layerSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight, fontOversamplingFactor,
366+ theImage->dotsPerMeterX () * 0.0254 );
364367 }
365368 }
366369
@@ -370,7 +373,7 @@ QImage* QgsWMSServer::getLegendGraphics()
370373}
371374
372375void QgsWMSServer::legendParameters ( double mmToPixelFactor, double fontOversamplingFactor, double & boxSpace, double & layerSpace, double & symbolSpace, double & iconLabelSpace, double & symbolWidth, double & symbolHeight,
373- QFont& layerFont, QFont& itemFont )
376+ QFont& layerFont, QFont& itemFont, QColor& layerFontColor, QColor& itemFontColor )
374377{
375378 // spaces between legend elements
376379 QMap<QString, QString>::const_iterator boxSpaceIt = mParameterMap .find ( " BOXSPACE" );
@@ -418,6 +421,15 @@ void QgsWMSServer::legendParameters( double mmToPixelFactor, double fontOversamp
418421 {
419422 layerFont.setPixelSize ( layerFont.pointSizeF () * 0.3528 * mmToPixelFactor * fontOversamplingFactor );
420423 }
424+ QMap<QString, QString>::const_iterator layerFontColorIt = mParameterMap .find ( " LAYERFONTCOLOR" );
425+ if ( layerFontColorIt != mParameterMap .constEnd () )
426+ {
427+ layerFontColor.setNamedColor ( layerFontColorIt.value () );
428+ }
429+ else
430+ {
431+ layerFontColor = QColor ( 0 , 0 , 0 );
432+ }
421433
422434
423435 itemFont = mConfigParser ->legendItemFont ();
@@ -445,6 +457,15 @@ void QgsWMSServer::legendParameters( double mmToPixelFactor, double fontOversamp
445457 {
446458 itemFont.setPixelSize ( itemFont.pointSizeF () * 0.3528 * mmToPixelFactor * fontOversamplingFactor );
447459 }
460+ QMap<QString, QString>::const_iterator itemFontColorIt = mParameterMap .find ( " ITEMFONTCOLOR" );
461+ if ( itemFontColorIt != mParameterMap .constEnd () )
462+ {
463+ itemFontColor.setNamedColor ( itemFontColorIt.value () );
464+ }
465+ else
466+ {
467+ itemFontColor = QColor ( 0 , 0 , 0 );
468+ }
448469}
449470
450471QDomDocument QgsWMSServer::getStyle ()
@@ -1395,8 +1416,8 @@ QStringList QgsWMSServer::layerSet( const QStringList &layersList,
13951416}
13961417
13971418void QgsWMSServer::drawLegendLayerItem ( QgsComposerLayerItem* item, QPainter* p, double & maxTextWidth, double & maxSymbolWidth, double & currentY, const QFont& layerFont,
1398- const QFont& itemFont, double boxSpace , double layerSpace , double symbolSpace ,
1399- double iconLabelSpace, double symbolWidth, double symbolHeight, double fontOversamplingFactor,
1419+ const QColor& layerFontColor, const QFont& itemFont, const QColor& itemFontColor , double boxSpace , double layerSpace ,
1420+ double symbolSpace, double iconLabelSpace, double symbolWidth, double symbolHeight, double fontOversamplingFactor,
14001421 double dpi ) const
14011422{
14021423 if ( !item )
@@ -1412,6 +1433,7 @@ void QgsWMSServer::drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* p,
14121433 {
14131434 p->save ();
14141435 p->scale ( 1.0 / fontOversamplingFactor, 1.0 / fontOversamplingFactor );
1436+ p->setPen ( layerFontColor );
14151437 p->setFont ( layerFont );
14161438 p->drawText ( boxSpace * fontOversamplingFactor, currentY * fontOversamplingFactor, item->text () );
14171439 p->restore ();
@@ -1435,10 +1457,6 @@ void QgsWMSServer::drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* p,
14351457 }
14361458
14371459 // then draw all the children
1438- if ( p )
1439- {
1440- p->setFont ( itemFont );
1441- }
14421460 QFontMetricsF itemFontMetrics ( itemFont );
14431461
14441462 int nChildItems = item->rowCount ();
@@ -1491,6 +1509,8 @@ void QgsWMSServer::drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* p,
14911509 {
14921510 p->save ();
14931511 p->scale ( 1.0 / fontOversamplingFactor, 1.0 / fontOversamplingFactor );
1512+ p->setPen ( itemFontColor );
1513+ p->setFont ( itemFont );
14941514 p->drawText ( maxSymbolWidth * fontOversamplingFactor,
14951515 ( currentY + symbolItemHeight / 2.0 ) * fontOversamplingFactor + itemFontMetrics.ascent () / 2.0 , currentComposerItem->text () );
14961516 p->restore ();
0 commit comments