@@ -282,7 +282,7 @@ QDomElement QgsFontUtils::toXmlElement( const QFont& font, QDomDocument& documen
282
282
{
283
283
QDomElement fontElem = document.createElement ( elementName );
284
284
fontElem.setAttribute ( " description" , font.toString () );
285
- fontElem.setAttribute ( " style" , font.styleName () );
285
+ fontElem.setAttribute ( " style" , untranslateNamedStyle ( font.styleName () ) );
286
286
return fontElem;
287
287
}
288
288
@@ -296,7 +296,7 @@ bool QgsFontUtils::setFromXmlElement( QFont& font, const QDomElement& element )
296
296
font.fromString ( element.attribute ( " description" ) );
297
297
if ( element.hasAttribute ( " style" ) )
298
298
{
299
- ( void )updateFontViaStyle ( font, element.attribute ( " style" ) );
299
+ ( void )updateFontViaStyle ( font, translateNamedStyle ( element.attribute ( " style" ) ) );
300
300
}
301
301
302
302
return true ;
@@ -320,3 +320,42 @@ bool QgsFontUtils::setFromXmlChildNode( QFont& font, const QDomElement& element,
320
320
return false ;
321
321
}
322
322
}
323
+
324
+ static QMap<QString, QString> createTranslatedStyleMap ()
325
+ {
326
+ QMap<QString, QString> translatedStyleMap;
327
+ QStringList words = QStringList () << " Normal" << " Light" << " Bold" << " Black" << " Demi" << " Italic" << " Oblique" ;
328
+ foreach ( const QString& word, words )
329
+ {
330
+ translatedStyleMap.insert ( QCoreApplication::translate ( " QFontDatabase" , qPrintable ( word ) ), word );
331
+ }
332
+ return translatedStyleMap;
333
+ }
334
+
335
+ QString QgsFontUtils::translateNamedStyle ( const QString& namedStyle )
336
+ {
337
+ QStringList words = namedStyle.split ( " " , QString::SkipEmptyParts );
338
+ for ( int i = 0 , n = words.length (); i < n; ++i )
339
+ {
340
+ words[i] = QCoreApplication::translate ( " QFontDatabase" , words[i].toUtf8 (), 0 , QCoreApplication::UnicodeUTF8 );
341
+ }
342
+ return words.join ( " " );
343
+ }
344
+
345
+ QString QgsFontUtils::untranslateNamedStyle ( const QString& namedStyle )
346
+ {
347
+ static QMap<QString, QString> translatedStyleMap = createTranslatedStyleMap ();
348
+ QStringList words = namedStyle.split ( " " , QString::SkipEmptyParts );
349
+ for ( int i = 0 , n = words.length (); i < n; ++i )
350
+ {
351
+ if ( translatedStyleMap.contains ( words[i] ) )
352
+ {
353
+ words[i] = translatedStyleMap.value ( words[i] );
354
+ }
355
+ else
356
+ {
357
+ QgsDebugMsg ( QString ( " Warning: style map does not contain %1" ).arg ( words[i] ) );
358
+ }
359
+ }
360
+ return words.join ( " " );
361
+ }
0 commit comments