Fix handling of font family from HTML on Qt 6 builds

At some stage we'll likely need to update QgsTextCharacterFormat to
use a list of families to match the Qt 6 changes, but for now just
get the first listed font.
This commit is contained in:
Nyall Dawson 2024-02-15 10:15:34 +10:00
parent 1a231417ca
commit 8139887d02
3 changed files with 17 additions and 4 deletions

View File

@ -64,7 +64,6 @@ PyQgsTextRenderer
PyQgsOGRProvider PyQgsOGRProvider
PyQgsSpatialiteProvider PyQgsSpatialiteProvider
PyQgsSymbolLayerReadSld PyQgsSymbolLayerReadSld
PyQgsTextDocument
PyQgsVectorLayerCache PyQgsVectorLayerCache
PyQgsVectorLayerEditBuffer PyQgsVectorLayerEditBuffer
PyQgsVectorLayerEditUtils PyQgsVectorLayerEditUtils

View File

@ -48,12 +48,22 @@ QgsTextCharacterFormat::QgsTextCharacterFormat( const QTextCharFormat &format )
, mStyleName( format.font().styleName() ) , mStyleName( format.font().styleName() )
, mItalic( format.hasProperty( QTextFormat::FontItalic ) ? ( format.fontItalic() ? BooleanValue::SetTrue : BooleanValue::SetFalse ) : BooleanValue::NotSet ) , mItalic( format.hasProperty( QTextFormat::FontItalic ) ? ( format.fontItalic() ? BooleanValue::SetTrue : BooleanValue::SetFalse ) : BooleanValue::NotSet )
, mFontPointSize( format.hasProperty( QTextFormat::FontPointSize ) ? format.fontPointSize() : - 1 ) , mFontPointSize( format.hasProperty( QTextFormat::FontPointSize ) ? format.fontPointSize() : - 1 )
, mFontFamily( format.hasProperty( QTextFormat::FontFamily ) ? format.fontFamily() : QString() )
, mStrikethrough( format.hasProperty( QTextFormat::FontStrikeOut ) ? ( format.fontStrikeOut() ? BooleanValue::SetTrue : BooleanValue::SetFalse ) : BooleanValue::NotSet ) , mStrikethrough( format.hasProperty( QTextFormat::FontStrikeOut ) ? ( format.fontStrikeOut() ? BooleanValue::SetTrue : BooleanValue::SetFalse ) : BooleanValue::NotSet )
, mUnderline( format.hasProperty( QTextFormat::FontUnderline ) ? ( format.fontUnderline() ? BooleanValue::SetTrue : BooleanValue::SetFalse ) : BooleanValue::NotSet ) , mUnderline( format.hasProperty( QTextFormat::FontUnderline ) ? ( format.fontUnderline() ? BooleanValue::SetTrue : BooleanValue::SetFalse ) : BooleanValue::NotSet )
, mOverline( format.hasProperty( QTextFormat::FontOverline ) ? ( format.fontOverline() ? BooleanValue::SetTrue : BooleanValue::SetFalse ) : BooleanValue::NotSet ) , mOverline( format.hasProperty( QTextFormat::FontOverline ) ? ( format.fontOverline() ? BooleanValue::SetTrue : BooleanValue::SetFalse ) : BooleanValue::NotSet )
{ {
mVerticalAlign = convertTextCharFormatVAlign( format, mHasVerticalAlignSet ); mVerticalAlign = convertTextCharFormatVAlign( format, mHasVerticalAlignSet );
if ( format.hasProperty( QTextFormat::FontFamily ) )
{
mFontFamily = format.fontFamily();
}
if ( mFontFamily.isEmpty() && format.hasProperty( QTextFormat::FontFamilies ) )
{
const QStringList families = format.fontFamilies().toStringList();
if ( !families.isEmpty() )
mFontFamily = families.at( 0 );
}
} }
QColor QgsTextCharacterFormat::textColor() const QColor QgsTextCharacterFormat::textColor() const

View File

@ -11,9 +11,10 @@ __author__ = 'Nyall Dawson'
__date__ = '12/05/2020' __date__ = '12/05/2020'
__copyright__ = 'Copyright 2020, The QGIS Project' __copyright__ = 'Copyright 2020, The QGIS Project'
from qgis.PyQt.QtCore import QT_VERSION_STR
from qgis.core import ( from qgis.core import (
Qgis, Qgis,
QgsFontUtils,
QgsStringUtils, QgsStringUtils,
QgsTextBlock, QgsTextBlock,
QgsTextCharacterFormat, QgsTextCharacterFormat,
@ -72,7 +73,10 @@ class TestQgsTextDocument(QgisTestCase):
self.assertEqual(doc[1][0].text(), 'def') self.assertEqual(doc[1][0].text(), 'def')
self.assertEqual(doc[1][0].characterFormat().underline(), QgsTextCharacterFormat.BooleanValue.SetTrue) self.assertEqual(doc[1][0].characterFormat().underline(), QgsTextCharacterFormat.BooleanValue.SetTrue)
self.assertEqual(doc[1][0].characterFormat().italic(), QgsTextCharacterFormat.BooleanValue.SetTrue) self.assertEqual(doc[1][0].characterFormat().italic(), QgsTextCharacterFormat.BooleanValue.SetTrue)
self.assertEqual(doc[1][0].characterFormat().fontWeight(), 75) if int(QT_VERSION_STR.split('.')[0]) >= 6:
self.assertEqual(doc[1][0].characterFormat().fontWeight(), 700)
else:
self.assertEqual(doc[1][0].characterFormat().fontWeight(), 75)
self.assertEqual(doc[1][0].characterFormat().family(), 'Serif') self.assertEqual(doc[1][0].characterFormat().family(), 'Serif')
self.assertEqual(doc[1][0].characterFormat().textColor().name(), '#ff0000') self.assertEqual(doc[1][0].characterFormat().textColor().name(), '#ff0000')
self.assertEqual(doc[1][0].characterFormat().fontPointSize(), 15) self.assertEqual(doc[1][0].characterFormat().fontPointSize(), 15)