|
18 | 18 | #include "qgspallabeling.h" |
19 | 19 | #include "qgstextlabelfeature.h" |
20 | 20 | #include "qgsunittypes.h" |
| 21 | +#include "qgsstringutils.h" |
21 | 22 |
|
22 | 23 | #include <list> |
23 | 24 |
|
@@ -2283,6 +2284,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont |
2283 | 2284 |
|
2284 | 2285 | // calculate rest of font attributes and store any data defined values |
2285 | 2286 | // this is done here for later use in making label backgrounds part of collision management (when implemented) |
| 2287 | + labelFont.setCapitalization( QFont::MixedCase ); // reset this - we don't use QFont's handling as it breaks with curved labels |
2286 | 2288 | parseTextStyle( labelFont, fontunits, context ); |
2287 | 2289 | parseTextFormatting( context ); |
2288 | 2290 | parseTextBuffer( context ); |
@@ -2316,6 +2318,41 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont |
2316 | 2318 | labelText = v.isNull() ? "" : v.toString(); |
2317 | 2319 | } |
2318 | 2320 |
|
| 2321 | + // apply capitalization |
| 2322 | + QgsStringUtils::Capitalization capitalization = QgsStringUtils::MixedCase; |
| 2323 | + // maintain API - capitalization may have been set in textFont |
| 2324 | + if ( textFont.capitalization() != QFont::MixedCase ) |
| 2325 | + { |
| 2326 | + capitalization = static_cast< QgsStringUtils::Capitalization >( textFont.capitalization() ); |
| 2327 | + } |
| 2328 | + // data defined font capitalization? |
| 2329 | + if ( dataDefinedEvaluate( QgsPalLayerSettings::FontCase, exprVal, &context.expressionContext() ) ) |
| 2330 | + { |
| 2331 | + QString fcase = exprVal.toString().trimmed(); |
| 2332 | + QgsDebugMsgLevel( QString( "exprVal FontCase:%1" ).arg( fcase ), 4 ); |
| 2333 | + |
| 2334 | + if ( !fcase.isEmpty() ) |
| 2335 | + { |
| 2336 | + if ( fcase.compare( "NoChange", Qt::CaseInsensitive ) == 0 ) |
| 2337 | + { |
| 2338 | + capitalization = QgsStringUtils::MixedCase; |
| 2339 | + } |
| 2340 | + else if ( fcase.compare( "Upper", Qt::CaseInsensitive ) == 0 ) |
| 2341 | + { |
| 2342 | + capitalization = QgsStringUtils::AllUppercase; |
| 2343 | + } |
| 2344 | + else if ( fcase.compare( "Lower", Qt::CaseInsensitive ) == 0 ) |
| 2345 | + { |
| 2346 | + capitalization = QgsStringUtils::AllLowercase; |
| 2347 | + } |
| 2348 | + else if ( fcase.compare( "Capitalize", Qt::CaseInsensitive ) == 0 ) |
| 2349 | + { |
| 2350 | + capitalization = QgsStringUtils::ForceFirstLetterToCapital; |
| 2351 | + } |
| 2352 | + } |
| 2353 | + } |
| 2354 | + labelText = QgsStringUtils::capitalize( labelText, capitalization ); |
| 2355 | + |
2319 | 2356 | // data defined format numbers? |
2320 | 2357 | bool formatnum = formatNumbers; |
2321 | 2358 | if ( dataDefinedEvaluate( QgsPalLayerSettings::NumFormat, exprVal, &context.expressionContext(), formatNumbers ) ) |
@@ -3356,7 +3393,6 @@ void QgsPalLayerSettings::parseTextStyle( QFont& labelFont, |
3356 | 3393 | // copy over existing font settings |
3357 | 3394 | //newFont = newFont.resolve( labelFont ); // should work, but let's be sure what's being copied |
3358 | 3395 | newFont.setPixelSize( labelFont.pixelSize() ); |
3359 | | - newFont.setCapitalization( labelFont.capitalization() ); |
3360 | 3396 | newFont.setUnderline( labelFont.underline() ); |
3361 | 3397 | newFont.setStrikeOut( labelFont.strikeOut() ); |
3362 | 3398 | newFont.setWordSpacing( labelFont.wordSpacing() ); |
@@ -3393,39 +3429,6 @@ void QgsPalLayerSettings::parseTextStyle( QFont& labelFont, |
3393 | 3429 | } |
3394 | 3430 | labelFont.setLetterSpacing( QFont::AbsoluteSpacing, scaleToPixelContext( letterspace, context, fontunits, false, fontSizeMapUnitScale ) ); |
3395 | 3431 |
|
3396 | | - // data defined font capitalization? |
3397 | | - QFont::Capitalization fontcaps = labelFont.capitalization(); |
3398 | | - if ( dataDefinedEvaluate( QgsPalLayerSettings::FontCase, exprVal, &context.expressionContext() ) ) |
3399 | | - { |
3400 | | - QString fcase = exprVal.toString().trimmed(); |
3401 | | - QgsDebugMsgLevel( QString( "exprVal FontCase:%1" ).arg( fcase ), 4 ); |
3402 | | - |
3403 | | - if ( !fcase.isEmpty() ) |
3404 | | - { |
3405 | | - if ( fcase.compare( "NoChange", Qt::CaseInsensitive ) == 0 ) |
3406 | | - { |
3407 | | - fontcaps = QFont::MixedCase; |
3408 | | - } |
3409 | | - else if ( fcase.compare( "Upper", Qt::CaseInsensitive ) == 0 ) |
3410 | | - { |
3411 | | - fontcaps = QFont::AllUppercase; |
3412 | | - } |
3413 | | - else if ( fcase.compare( "Lower", Qt::CaseInsensitive ) == 0 ) |
3414 | | - { |
3415 | | - fontcaps = QFont::AllLowercase; |
3416 | | - } |
3417 | | - else if ( fcase.compare( "Capitalize", Qt::CaseInsensitive ) == 0 ) |
3418 | | - { |
3419 | | - fontcaps = QFont::Capitalize; |
3420 | | - } |
3421 | | - |
3422 | | - if ( fontcaps != labelFont.capitalization() ) |
3423 | | - { |
3424 | | - labelFont.setCapitalization( fontcaps ); |
3425 | | - } |
3426 | | - } |
3427 | | - } |
3428 | | - |
3429 | 3432 | // data defined strikeout font style? |
3430 | 3433 | if ( dataDefinedEvaluate( QgsPalLayerSettings::Strikeout, exprVal, &context.expressionContext(), labelFont.strikeOut() ) ) |
3431 | 3434 | { |
|
0 commit comments