Skip to content

Commit

Permalink
[text renderer] Fix handling of semi-opaque font colors (i.e. rgba)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn authored and nyalldawson committed May 7, 2021
1 parent 1a3be58 commit 0ee3de2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/core/textrenderer/qgstextrenderer.cpp
Expand Up @@ -1556,7 +1556,7 @@ void QgsTextRenderer::drawTextInternalHorizontal( QgsRenderContext &context, con
path.addText( xOffset, 0, fragmentFont, fragment.text() );

QColor textColor = fragment.characterFormat().textColor().isValid() ? fragment.characterFormat().textColor() : format.color();
textColor.setAlphaF( format.opacity() );
textColor.setAlphaF( fragment.characterFormat().textColor().isValid() ? textColor.alphaF() * format.opacity() : format.opacity() );
textp.setBrush( textColor );
textp.drawPath( path );

Expand Down Expand Up @@ -1604,7 +1604,7 @@ void QgsTextRenderer::drawTextInternalHorizontal( QgsRenderContext &context, con
applyExtraSpacingForLineJustification( fragmentFont, extraWordSpace * fontScale, extraLetterSpace * fontScale );

QColor textColor = fragment.characterFormat().textColor().isValid() ? fragment.characterFormat().textColor() : format.color();
textColor.setAlphaF( format.opacity() );
textColor.setAlphaF( fragment.characterFormat().textColor().isValid() ? textColor.alphaF() * format.opacity() : format.opacity() );

context.painter()->setPen( textColor );
context.painter()->setFont( fragmentFont );
Expand Down Expand Up @@ -1796,7 +1796,7 @@ void QgsTextRenderer::drawTextInternalVertical( QgsRenderContext &context, const
textp.begin( &textPict );
textp.setPen( Qt::NoPen );
QColor textColor = fragment.characterFormat().textColor().isValid() ? fragment.characterFormat().textColor() : format.color();
textColor.setAlphaF( format.opacity() );
textColor.setAlphaF( fragment.characterFormat().textColor().isValid() ? textColor.alphaF() * format.opacity() : format.opacity() );
textp.setBrush( textColor );
textp.scale( 1 / fontScale, 1 / fontScale );
textp.drawPath( path );
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_qgstextrenderer.py
Expand Up @@ -2803,7 +2803,7 @@ def testHtmlFormatting(self):
format.setColor(QColor(0, 255, 0))
format.setAllowHtmlFormatting(True)
assert self.checkRenderPoint(format, 'text_html_formatting', None, text=[
'<s>t</s><span style="text-decoration: overline">e</span><span style="color: red">s<span style="text-decoration: underline">t</span></span>'],
'<s>t</s><span style="text-decoration: overline">e</span><span style="color: red">s<span style="color: rgba(255,0,0,0.5); text-decoration: underline">t</span></span>'],
point=QPointF(50, 200))

def testHtmlFormattingBuffer(self):
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0ee3de2

Please sign in to comment.