40
40
41
41
#include " diagram/qgsdiagram.h"
42
42
#include " qgsdiagramrendererv2.h"
43
+ #include " qgsfontutils.h"
43
44
#include " qgslabelsearchtree.h"
44
45
#include " qgsexpression.h"
45
46
#include " qgsdatadefined.h"
@@ -783,27 +784,6 @@ void QgsPalLayerSettings::readDataDefinedProperty( QgsVectorLayer* layer,
783
784
}
784
785
}
785
786
786
- void QgsPalLayerSettings::updateFontViaStyle ( QFont& font, const QString & fontstyle )
787
- {
788
- if ( !fontstyle.isEmpty () )
789
- {
790
- QFont styledfont = mFontDB .font ( font.family (), fontstyle, 12 );
791
- if ( QApplication::font ().toString () != styledfont.toString () )
792
- {
793
- if ( font.pointSizeF () != -1 )
794
- {
795
- styledfont.setPointSizeF ( font.pointSizeF () );
796
- }
797
- else if ( font.pixelSize () != -1 )
798
- {
799
- styledfont.setPixelSize ( font.pixelSize () );
800
- }
801
-
802
- font = styledfont;
803
- }
804
- }
805
- }
806
-
807
787
void QgsPalLayerSettings::readFromLayer ( QgsVectorLayer* layer )
808
788
{
809
789
if ( layer->customProperty ( " labeling" ).toString () != QString ( " pal" ) )
@@ -824,7 +804,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
824
804
textFont = QFont ( fontFamily, fontSize, fontWeight, fontItalic );
825
805
textFont.setPointSizeF ( fontSize ); // double precision needed because of map units
826
806
textNamedStyle = layer->customProperty ( " labeling/namedStyle" , QVariant ( " " ) ).toString ();
827
- updateFontViaStyle ( textFont, textNamedStyle ); // must come after textFont.setPointSizeF()
807
+ QgsFontUtils:: updateFontViaStyle ( textFont, textNamedStyle ); // must come after textFont.setPointSizeF()
828
808
textFont.setCapitalization (( QFont::Capitalization )layer->customProperty ( " labeling/fontCapitals" , QVariant ( 0 ) ).toUInt () );
829
809
textFont.setUnderline ( layer->customProperty ( " labeling/fontUnderline" ).toBool () );
830
810
textFont.setStrikeOut ( layer->customProperty ( " labeling/fontStrikeout" ).toBool () );
@@ -2319,12 +2299,14 @@ void QgsPalLayerSettings::parseTextStyle( QFont& labelFont,
2319
2299
QString family = exprVal.toString ().trimmed ();
2320
2300
QgsDebugMsgLevel ( QString ( " exprVal Font family:%1" ).arg ( family ), 4 );
2321
2301
2322
- // testing for mFontDB.families().contains( ddFontFamily ) doesn't always work,
2323
- // because the families list needs looped to test for 'family [foundry]'
2324
- // which could bring unnecessary overhead, so fall back to default font instead
2325
2302
if ( labelFont.family () != family )
2326
2303
{
2327
- ddFontFamily = family;
2304
+ // testing for ddFontFamily in QFontDatabase.families() may be slow to do for every feature
2305
+ // (i.e. don't use QgsFontUtils::fontFamilyMatchOnSystem( family ) here)
2306
+ if ( QgsFontUtils::fontFamilyOnSystem ( family ) )
2307
+ {
2308
+ ddFontFamily = family;
2309
+ }
2328
2310
}
2329
2311
}
2330
2312
@@ -2355,7 +2337,10 @@ void QgsPalLayerSettings::parseTextStyle( QFont& labelFont,
2355
2337
ddItalic = italic ;
2356
2338
}
2357
2339
2340
+ // TODO: update when pref for how to resolve missing family (use matching algorithm or just default font) is implemented
2341
+ // (currently defaults to what has been read in from layer settings)
2358
2342
QFont newFont;
2343
+ QFont appFont = QApplication::font ();
2359
2344
bool newFontBuilt = false ;
2360
2345
if ( ddBold || ddItalic )
2361
2346
{
@@ -2371,24 +2356,24 @@ void QgsPalLayerSettings::parseTextStyle( QFont& labelFont,
2371
2356
if ( !ddFontFamily.isEmpty () )
2372
2357
{
2373
2358
// both family and style are different, build font from database
2374
- QFont styledfont = mFontDB .font ( ddFontFamily, ddFontStyle, 12 );
2375
- if ( QApplication::font (). toString () != styledfont. toString () )
2359
+ QFont styledfont = mFontDB .font ( ddFontFamily, ddFontStyle, appFont. pointSize () );
2360
+ if ( appFont != styledfont )
2376
2361
{
2377
2362
newFont = styledfont;
2378
2363
newFontBuilt = true ;
2379
2364
}
2380
2365
}
2381
2366
2382
2367
// update the font face style
2383
- updateFontViaStyle ( newFontBuilt ? newFont : labelFont, ddFontStyle );
2368
+ QgsFontUtils:: updateFontViaStyle ( newFontBuilt ? newFont : labelFont, ddFontStyle );
2384
2369
}
2385
2370
else if ( !ddFontFamily.isEmpty () )
2386
2371
{
2387
2372
if ( ddFontStyle.compare ( " Ignore" , Qt::CaseInsensitive ) != 0 )
2388
2373
{
2389
2374
// just family is different, build font from database
2390
- QFont styledfont = mFontDB .font ( ddFontFamily, textNamedStyle, 12 );
2391
- if ( QApplication::font (). toString () != styledfont. toString () )
2375
+ QFont styledfont = mFontDB .font ( ddFontFamily, textNamedStyle, appFont. pointSize () );
2376
+ if ( appFont != styledfont )
2392
2377
{
2393
2378
newFont = styledfont;
2394
2379
newFontBuilt = true ;
0 commit comments