@@ -1393,6 +1393,8 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF *fm, const QSt
1393
1393
}
1394
1394
QgsRenderContext *rc = context ? context : scopedRc.get ();
1395
1395
1396
+ const bool htmlFormatting = mFormat .allowHtmlFormatting ();
1397
+
1396
1398
QString wrapchr = wrapChar;
1397
1399
int evalAutoWrapLength = autoWrapLength;
1398
1400
double multilineH = mFormat .lineHeight ();
@@ -1531,7 +1533,7 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF *fm, const QSt
1531
1533
1532
1534
double w = 0.0 , h = 0.0 , rw = 0.0 , rh = 0.0 ;
1533
1535
double labelHeight = fm->ascent () + fm->descent (); // ignore +1 for baseline
1534
- const QStringList multiLineSplit = QgsPalLabeling::splitToLines ( textCopy, wrapchr, evalAutoWrapLength, useMaxLineLengthForAutoWrap );
1536
+ const QStringList multiLineSplit = QgsPalLabeling::splitToLines ( textCopy, wrapchr, evalAutoWrapLength, useMaxLineLengthForAutoWrap, htmlFormatting );
1535
1537
int lines = multiLineSplit.size ();
1536
1538
1537
1539
switch ( orientation )
@@ -3548,33 +3550,49 @@ bool QgsPalLabeling::geometryRequiresPreparation( const QgsGeometry &geometry, Q
3548
3550
return false ;
3549
3551
}
3550
3552
3551
- QStringList QgsPalLabeling::splitToLines ( const QString &text, const QString &wrapCharacter, const int autoWrapLength, const bool useMaxLineLengthWhenAutoWrapping )
3553
+ QStringList QgsPalLabeling::splitToLines ( const QString &text, const QString &wrapCharacter, const int autoWrapLength, const bool useMaxLineLengthWhenAutoWrapping, const bool allowHtmlFormatting )
3552
3554
{
3553
3555
QStringList multiLineSplit;
3554
- if ( !wrapCharacter. isEmpty () && wrapCharacter != QLatin1String ( " \n " ) )
3556
+ auto splitLine = [ & ]( const QString & input )
3555
3557
{
3556
- // wrap on both the wrapchr and new line characters
3557
- const QStringList lines = text.split ( wrapCharacter );
3558
- for ( const QString &line : lines )
3558
+ QStringList thisParts;
3559
+ if ( !wrapCharacter.isEmpty () && wrapCharacter != QLatin1String ( " \n " ) )
3559
3560
{
3560
- multiLineSplit.append ( line.split ( ' \n ' ) );
3561
+ // wrap on both the wrapchr and new line characters
3562
+ const QStringList lines = input.split ( wrapCharacter );
3563
+ for ( const QString &line : lines )
3564
+ {
3565
+ thisParts.append ( line.split ( ' \n ' ) );
3566
+ }
3567
+ }
3568
+ else
3569
+ {
3570
+ thisParts = input.split ( ' \n ' );
3561
3571
}
3562
- }
3563
- else
3564
- {
3565
- multiLineSplit = text.split ( ' \n ' );
3566
- }
3567
3572
3568
- // apply auto wrapping to each manually created line
3569
- if ( autoWrapLength != 0 )
3570
- {
3571
- QStringList autoWrappedLines;
3572
- autoWrappedLines.reserve ( multiLineSplit.count () );
3573
- for ( const QString &line : qgis::as_const ( multiLineSplit ) )
3573
+ // apply auto wrapping to each manually created line
3574
+ if ( autoWrapLength != 0 )
3574
3575
{
3575
- autoWrappedLines.append ( QgsStringUtils::wordWrap ( line, autoWrapLength, useMaxLineLengthWhenAutoWrapping ).split ( ' \n ' ) );
3576
+ QStringList autoWrappedLines;
3577
+ autoWrappedLines.reserve ( thisParts.count () );
3578
+ for ( const QString &line : qgis::as_const ( thisParts ) )
3579
+ {
3580
+ autoWrappedLines.append ( QgsStringUtils::wordWrap ( line, autoWrapLength, useMaxLineLengthWhenAutoWrapping ).split ( ' \n ' ) );
3581
+ }
3582
+ thisParts = autoWrappedLines;
3576
3583
}
3577
- multiLineSplit = autoWrappedLines;
3584
+ multiLineSplit.append ( thisParts );
3585
+ };
3586
+
3587
+ if ( allowHtmlFormatting )
3588
+ {
3589
+ const QStringList htmlBlocks = QgsTextRenderer::extractTextBlocksFromHtml ( text );
3590
+ for ( const QString &block : htmlBlocks )
3591
+ splitLine ( block );
3592
+ }
3593
+ else
3594
+ {
3595
+ splitLine ( text );
3578
3596
}
3579
3597
return multiLineSplit;
3580
3598
}
0 commit comments