Skip to content

Commit fe14e52

Browse files
committedMay 12, 2020
General cleanups, and add support for underline/overline/strikethrough formatting tags
1 parent 173e209 commit fe14e52

File tree

3 files changed

+315
-72
lines changed

3 files changed

+315
-72
lines changed
 

‎python/core/auto_generated/qgstextrenderer.sip.in

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,9 +1998,9 @@ Draws text at a point origin using the specified settings.
19981998
as of QGIS 3.4.3 and the text format should be set using QgsRenderContext.setTextRenderFormat() instead.
19991999
%End
20002000

2001-
static void drawPart( const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines,
2002-
QgsRenderContext &context, const QgsTextFormat &format,
2003-
TextPart part, bool drawAsOutlines = true );
2001+
static void drawPart( const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines,
2002+
QgsRenderContext &context, const QgsTextFormat &format,
2003+
TextPart part, bool drawAsOutlines = true ) /Deprecated/;
20042004
%Docstring
20052005
Draws a single component of rendered text using the specified settings.
20062006

@@ -2017,12 +2017,14 @@ Draws a single component of rendered text using the specified settings.
20172017
formats like SVG to maintain text as text objects, but at the cost of degraded
20182018
rendering and may result in side effects like misaligned text buffers. This setting is deprecated and has no effect
20192019
as of QGIS 3.4.3 and the text format should be set using QgsRenderContext.setTextRenderFormat() instead.
2020-
%End
20212020

2021+
.. deprecated::
2022+
Private API only, will be removed in 4.0
2023+
%End
20222024

2023-
static void drawPart( QPointF origin, double rotation, HAlignment alignment, const QStringList &textLines,
2024-
QgsRenderContext &context, const QgsTextFormat &format,
2025-
TextPart part, bool drawAsOutlines = true );
2025+
static void drawPart( QPointF origin, double rotation, HAlignment alignment, const QStringList &textLines,
2026+
QgsRenderContext &context, const QgsTextFormat &format,
2027+
TextPart part, bool drawAsOutlines = true ) /Deprecated/;
20262028
%Docstring
20272029
Draws a single component of rendered text using the specified settings.
20282030

@@ -2039,8 +2041,10 @@ Draws a single component of rendered text using the specified settings.
20392041
formats like SVG to maintain text as text objects, but at the cost of degraded
20402042
rendering and may result in side effects like misaligned text buffers. This setting is deprecated and has no effect
20412043
as of QGIS 3.4.3 and the text format should be set using QgsRenderContext.setTextRenderFormat() instead.
2042-
%End
20432044

2045+
.. deprecated::
2046+
Private API only, will be removed in 4.0
2047+
%End
20442048

20452049
static QFontMetricsF fontMetrics( QgsRenderContext &context, const QgsTextFormat &format );
20462050
%Docstring

‎src/core/qgstextrenderer.cpp

Lines changed: 147 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,17 +2649,19 @@ void QgsTextRenderer::drawText( const QRectF &rect, double rotation, QgsTextRend
26492649
tmpFormat.updateDataDefinedProperties( context );
26502650
tmpFormat = updateShadowPosition( tmpFormat );
26512651

2652+
const QgsTextDocument document = format.allowHtmlFormatting() ? QgsTextDocument::fromHtml( textLines ) : QgsTextDocument::fromPlainText( textLines );
2653+
26522654
if ( tmpFormat.background().enabled() )
26532655
{
2654-
drawPart( rect, rotation, alignment, textLines, context, tmpFormat, Background );
2656+
drawPart( rect, rotation, alignment, document, context, tmpFormat, Background );
26552657
}
26562658

26572659
if ( tmpFormat.buffer().enabled() )
26582660
{
2659-
drawPart( rect, rotation, alignment, textLines, context, tmpFormat, Buffer );
2661+
drawPart( rect, rotation, alignment, document, context, tmpFormat, Buffer );
26602662
}
26612663

2662-
drawPart( rect, rotation, alignment, textLines, context, tmpFormat, Text );
2664+
drawPart( rect, rotation, alignment, document, context, tmpFormat, Text );
26632665
}
26642666

26652667
void QgsTextRenderer::drawText( QPointF point, double rotation, QgsTextRenderer::HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool )
@@ -2669,17 +2671,19 @@ void QgsTextRenderer::drawText( QPointF point, double rotation, QgsTextRenderer:
26692671
tmpFormat.updateDataDefinedProperties( context );
26702672
tmpFormat = updateShadowPosition( tmpFormat );
26712673

2674+
const QgsTextDocument document = format.allowHtmlFormatting() ? QgsTextDocument::fromHtml( textLines ) : QgsTextDocument::fromPlainText( textLines );
2675+
26722676
if ( tmpFormat.background().enabled() )
26732677
{
2674-
drawPart( point, rotation, alignment, textLines, context, tmpFormat, Background );
2678+
drawPart( point, rotation, alignment, document, context, tmpFormat, Background );
26752679
}
26762680

26772681
if ( tmpFormat.buffer().enabled() )
26782682
{
2679-
drawPart( point, rotation, alignment, textLines, context, tmpFormat, Buffer );
2683+
drawPart( point, rotation, alignment, document, context, tmpFormat, Buffer );
26802684
}
26812685

2682-
drawPart( point, rotation, alignment, textLines, context, tmpFormat, Text );
2686+
drawPart( point, rotation, alignment, document, context, tmpFormat, Text );
26832687
}
26842688

26852689
QgsTextFormat QgsTextRenderer::updateShadowPosition( const QgsTextFormat &format )
@@ -2706,7 +2710,9 @@ QgsTextFormat QgsTextRenderer::updateShadowPosition( const QgsTextFormat &format
27062710
void QgsTextRenderer::drawPart( const QRectF &rect, double rotation, HAlignment alignment,
27072711
const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, QgsTextRenderer::TextPart part, bool )
27082712
{
2709-
drawPart( rect, rotation, alignment, QgsTextDocument( textLines ), context, format, part );
2713+
const QgsTextDocument document = format.allowHtmlFormatting() ? QgsTextDocument::fromHtml( textLines ) : QgsTextDocument::fromPlainText( textLines );
2714+
2715+
drawPart( rect, rotation, alignment, document, context, format, part );
27102716
}
27112717

27122718
void QgsTextRenderer::drawPart( const QRectF &rect, double rotation, QgsTextRenderer::HAlignment alignment, const QgsTextDocument &document, QgsRenderContext &context, const QgsTextFormat &format, QgsTextRenderer::TextPart part )
@@ -2775,7 +2781,8 @@ void QgsTextRenderer::drawPart( const QRectF &rect, double rotation, QgsTextRend
27752781

27762782
void QgsTextRenderer::drawPart( QPointF origin, double rotation, QgsTextRenderer::HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, QgsTextRenderer::TextPart part, bool )
27772783
{
2778-
drawPart( origin, rotation, alignment, QgsTextDocument( textLines ), context, format, part );
2784+
const QgsTextDocument document = format.allowHtmlFormatting() ? QgsTextDocument::fromHtml( textLines ) : QgsTextDocument::fromPlainText( textLines );
2785+
drawPart( origin, rotation, alignment, document, context, format, part );
27792786
}
27802787

27812788
void QgsTextRenderer::drawPart( QPointF origin, double rotation, QgsTextRenderer::HAlignment alignment, const QgsTextDocument &document, QgsRenderContext &context, const QgsTextFormat &format, QgsTextRenderer::TextPart part )
@@ -3795,25 +3802,30 @@ void QgsTextRenderer::drawTextInternal( TextPart drawType,
37953802
QPainter textp;
37963803
textp.begin( &textPict );
37973804
textp.setPen( Qt::NoPen );
3798-
QFont font = format.scaledFont( context );
3805+
const QFont font = format.scaledFont( context );
37993806

38003807
double xOffset = 0;
38013808
for ( const QgsTextFragment &fragment : block )
38023809
{
38033810
// draw text, QPainterPath method
38043811
QPainterPath path;
38053812
path.setFillRule( Qt::WindingFill );
3806-
path.addText( xOffset, 0, font, fragment.text() );
3813+
3814+
QFont fragmentFont = font;
3815+
fragment.characterFormat().updateFontForFormat( fragmentFont );
3816+
QFontMetricsF fragmentMetrics = QFontMetricsF( fragmentFont );
3817+
3818+
path.addText( xOffset, 0, fragmentFont, fragment.text() );
38073819

38083820
QColor textColor = fragment.characterFormat().textColor().isValid() ? fragment.characterFormat().textColor() : format.color();
38093821
textColor.setAlphaF( format.opacity() );
38103822
textp.setBrush( textColor );
38113823
textp.drawPath( path );
38123824

38133825
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
3814-
xOffset += fontMetrics->width( fragment.text() );
3826+
xOffset += fragmentMetrics.width( fragment.text() );
38153827
#else
3816-
xOffset += fontMetrics->horizontalAdvance( fragment.text() );
3828+
xOffset += fragmentMetrics.horizontalAdvance( fragment.text() );
38173829
#endif
38183830
// TODO: why are some font settings lost on drawPicture() when using drawText() inside QPicture?
38193831
// e.g. some capitalization options, but not others
@@ -4201,6 +4213,13 @@ QgsTextFormat::TextOrientation QgsTextRendererUtils::decodeTextOrientation( cons
42014213

42024214
QgsTextCharacterFormat::QgsTextCharacterFormat( const QTextCharFormat &format )
42034215
: mTextColor( format.hasProperty( QTextFormat::ForegroundBrush ) ? format.foreground().color() : QColor() )
4216+
#if 0 // settings which affect font metrics are disabled for now
4217+
, mFontWeight( format.hasProperty( QTextFormat::FontWeight ) ? format.fontWeight() : -1 )
4218+
, mItalic( format.hasProperty( QTextFormat::FontItalic ) ? ( format.fontItalic() ? BooleanValue::True : BooleanValue::False ) : BooleanValue::NotSet )
4219+
#endif
4220+
, mStrikethrough( format.hasProperty( QTextFormat::FontStrikeOut ) ? ( format.fontStrikeOut() ? BooleanValue::True : BooleanValue::False ) : BooleanValue::NotSet )
4221+
, mUnderline( format.hasProperty( QTextFormat::FontUnderline ) ? ( format.fontUnderline() ? BooleanValue::True : BooleanValue::False ) : BooleanValue::NotSet )
4222+
, mOverline( format.hasProperty( QTextFormat::FontOverline ) ? ( format.fontOverline() ? BooleanValue::True : BooleanValue::False ) : BooleanValue::NotSet )
42044223
{
42054224

42064225
}
@@ -4215,6 +4234,75 @@ void QgsTextCharacterFormat::setTextColor( const QColor &textColor )
42154234
mTextColor = textColor;
42164235
}
42174236

4237+
QgsTextCharacterFormat::BooleanValue QgsTextCharacterFormat::strikeOut() const
4238+
{
4239+
return mStrikethrough;
4240+
}
4241+
4242+
void QgsTextCharacterFormat::setStrikeOut( BooleanValue strikethrough )
4243+
{
4244+
mStrikethrough = strikethrough;
4245+
}
4246+
4247+
QgsTextCharacterFormat::BooleanValue QgsTextCharacterFormat::underline() const
4248+
{
4249+
return mUnderline;
4250+
}
4251+
4252+
void QgsTextCharacterFormat::setUnderline( BooleanValue underline )
4253+
{
4254+
mUnderline = underline;
4255+
}
4256+
4257+
QgsTextCharacterFormat::BooleanValue QgsTextCharacterFormat::overline() const
4258+
{
4259+
return mOverline;
4260+
}
4261+
4262+
void QgsTextCharacterFormat::setOverline( QgsTextCharacterFormat::BooleanValue enabled )
4263+
{
4264+
mOverline = enabled;
4265+
}
4266+
4267+
void QgsTextCharacterFormat::updateFontForFormat( QFont &font ) const
4268+
{
4269+
if ( mUnderline != BooleanValue::NotSet )
4270+
font.setUnderline( mUnderline == QgsTextCharacterFormat::BooleanValue::True );
4271+
if ( mOverline != BooleanValue::NotSet )
4272+
font.setOverline( mOverline == QgsTextCharacterFormat::BooleanValue::True );
4273+
if ( mStrikethrough != QgsTextCharacterFormat::BooleanValue::NotSet )
4274+
font.setStrikeOut( mStrikethrough == QgsTextCharacterFormat::BooleanValue::True );
4275+
4276+
#if 0 // settings which affect font metrics are disabled for now
4277+
if ( mItalic != QgsTextCharacterFormat::BooleanValue::NotSet )
4278+
font.setItalic( mItalic == QgsTextCharacterFormat::BooleanValue::True );
4279+
if ( mFontWeight != -1 )
4280+
font.setWeight( mFontWeight );
4281+
#endif
4282+
}
4283+
4284+
#if 0 // settings which affect font metrics are disabled for now
4285+
QgsTextCharacterFormat::BooleanValue QgsTextCharacterFormat::italic() const
4286+
{
4287+
return mItalic;
4288+
}
4289+
4290+
void QgsTextCharacterFormat::setItalic( QgsTextCharacterFormat::BooleanValue enabled )
4291+
{
4292+
mItalic = enabled;
4293+
}
4294+
4295+
int QgsTextCharacterFormat::fontWeight() const
4296+
{
4297+
return mFontWeight;
4298+
}
4299+
4300+
void QgsTextCharacterFormat::setFontWeight( int fontWeight )
4301+
{
4302+
mFontWeight = fontWeight;
4303+
}
4304+
#endif
4305+
42184306
//
42194307
// QgsTextFragment
42204308
//
@@ -4223,6 +4311,13 @@ QgsTextFragment::QgsTextFragment( const QString &text, const QgsTextCharacterFor
42234311
, mCharFormat( format )
42244312
{}
42254313

4314+
QgsTextFragment::QgsTextFragment( const QTextFragment &fragment )
4315+
: mText( fragment.text() )
4316+
, mCharFormat( QgsTextCharacterFormat( fragment.charFormat() ) )
4317+
{
4318+
4319+
}
4320+
42264321
QString QgsTextFragment::text() const
42274322
{
42284323
return mText;
@@ -4259,11 +4354,48 @@ QgsTextDocument::QgsTextDocument( const QgsTextFragment &fragment )
42594354
append( QgsTextBlock( fragment ) );
42604355
}
42614356

4262-
QgsTextDocument::QgsTextDocument( const QStringList &lines )
4357+
QgsTextDocument QgsTextDocument::fromPlainText( const QStringList &lines )
42634358
{
4264-
reserve( lines.size() );
4359+
QgsTextDocument document;
4360+
document.reserve( lines.size() );
42654361
for ( const QString &line : lines )
4266-
append( QgsTextBlock( QgsTextFragment( line ) ) );
4362+
document.append( QgsTextBlock( QgsTextFragment( line ) ) );
4363+
return document;
4364+
}
4365+
4366+
QgsTextDocument QgsTextDocument::fromHtml( const QStringList &lines )
4367+
{
4368+
QgsTextDocument document;
4369+
4370+
document.reserve( lines.size() );
4371+
for ( const QString &line : lines )
4372+
{
4373+
QTextDocument sourceDoc;
4374+
sourceDoc.setHtml( line );
4375+
4376+
QTextBlock sourceBlock = sourceDoc.firstBlock();
4377+
while ( true )
4378+
{
4379+
auto it = sourceBlock.begin();
4380+
QgsTextBlock block;
4381+
while ( !it.atEnd() )
4382+
{
4383+
const QTextFragment fragment = it.fragment();
4384+
if ( fragment.isValid() )
4385+
{
4386+
block.append( QgsTextFragment( fragment ) );
4387+
}
4388+
it++;
4389+
}
4390+
if ( !block.isEmpty() )
4391+
document << block;
4392+
4393+
sourceBlock = sourceBlock.next();
4394+
if ( !sourceBlock.isValid() )
4395+
break;
4396+
}
4397+
}
4398+
return document;
42674399
}
42684400

42694401
QStringList QgsTextDocument::toPlainText() const

‎src/core/qgstextrenderer.h

Lines changed: 156 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,14 @@ class CORE_EXPORT QgsTextCharacterFormat
16571657
*/
16581658
QgsTextCharacterFormat( const QTextCharFormat &format );
16591659

1660+
//! Status values for boolean format properties
1661+
enum class BooleanValue
1662+
{
1663+
NotSet, //!< Property is not set
1664+
True, //!< Property is set and TRUE
1665+
False, //!< Property is set and FALSE
1666+
};
1667+
16601668
/**
16611669
* Returns the character's text color, or an invalid color if no color override
16621670
* is set and the default format color should be used.
@@ -1675,10 +1683,101 @@ class CORE_EXPORT QgsTextCharacterFormat
16751683
*/
16761684
void setTextColor( const QColor &textColor );
16771685

1686+
#if 0
1687+
1688+
/**
1689+
* Returns the font weight, or -1 if the font weight is not set
1690+
* and should be inherited.
1691+
*
1692+
* \see setFontWeight()
1693+
*/
1694+
int fontWeight() const;
1695+
1696+
/**
1697+
* Sets the font \a weight.
1698+
*
1699+
* Set \a weight to -1 if the font weight is not set
1700+
* and should be inherited.
1701+
*
1702+
* \see fontWeight()
1703+
*/
1704+
void setFontWeight( int fontWeight );
1705+
1706+
/**
1707+
* Returns whether the format has italic enabled.
1708+
*
1709+
* \see setItalic()
1710+
*/
1711+
BooleanValue italic() const;
1712+
1713+
/**
1714+
* Sets whether the format has italic \a enabled.
1715+
*
1716+
* \see italic()
1717+
*/
1718+
void setItalic( BooleanValue enabled );
1719+
#endif
1720+
1721+
/**
1722+
* Returns whether the format has strikethrough enabled.
1723+
*
1724+
* \see setStrikeOut()
1725+
*/
1726+
BooleanValue strikeOut() const;
1727+
1728+
/**
1729+
* Sets whether the format has strikethrough \a enabled.
1730+
*
1731+
* \see strikeOut()
1732+
*/
1733+
void setStrikeOut( BooleanValue enabled );
1734+
1735+
/**
1736+
* Returns whether the format has underline enabled.
1737+
*
1738+
* \see setUnderline()
1739+
*/
1740+
BooleanValue underline() const;
1741+
1742+
/**
1743+
* Sets whether the format has underline \a enabled.
1744+
*
1745+
* \see underline()
1746+
*/
1747+
void setUnderline( BooleanValue enabled );
1748+
1749+
/**
1750+
* Returns whether the format has overline enabled.
1751+
*
1752+
* \see setUnderline()
1753+
*/
1754+
BooleanValue overline() const;
1755+
1756+
/**
1757+
* Sets whether the format has overline \a enabled.
1758+
*
1759+
* \see overline()
1760+
*/
1761+
void setOverline( BooleanValue enabled );
1762+
1763+
/**
1764+
* Updates the specified \a font in place, applying character formatting options which
1765+
* are applicable on a font level.
1766+
*/
1767+
void updateFontForFormat( QFont &font ) const;
1768+
16781769
private:
16791770

16801771
QColor mTextColor;
16811772

1773+
#if 0 // settings which affect font metrics are disabled for now
1774+
int mFontWeight = -1;
1775+
BooleanValue mItalic = BooleanValue::NotSet;
1776+
#endif
1777+
1778+
BooleanValue mStrikethrough = BooleanValue::NotSet;
1779+
BooleanValue mUnderline = BooleanValue::NotSet;
1780+
BooleanValue mOverline = BooleanValue::NotSet;
16821781
};
16831782

16841783
/**
@@ -1697,6 +1796,11 @@ class CORE_EXPORT QgsTextFragment
16971796
*/
16981797
explicit QgsTextFragment( const QString &text, const QgsTextCharacterFormat &format = QgsTextCharacterFormat() );
16991798

1799+
/**
1800+
* Constructor for QgsTextFragment, based on the specified QTextFragment \a fragment.
1801+
*/
1802+
explicit QgsTextFragment( const QTextFragment &fragment );
1803+
17001804
/**
17011805
* Returns the text content of the fragment.
17021806
*
@@ -1779,7 +1883,12 @@ class CORE_EXPORT QgsTextDocument : public QVector< QgsTextBlock >
17791883
/**
17801884
* Constructor for QgsTextDocument consisting of a set of plain text \a lines.
17811885
*/
1782-
explicit QgsTextDocument( const QStringList &lines );
1886+
static QgsTextDocument fromPlainText( const QStringList &lines );
1887+
1888+
/**
1889+
* Constructor for QgsTextDocument consisting of a set of HTML formatted \a lines.
1890+
*/
1891+
static QgsTextDocument fromHtml( const QStringList &lines );
17831892

17841893
/**
17851894
* Returns a list of plain text lines of text representing the document.
@@ -1896,31 +2005,12 @@ class CORE_EXPORT QgsTextRenderer
18962005
* formats like SVG to maintain text as text objects, but at the cost of degraded
18972006
* rendering and may result in side effects like misaligned text buffers. This setting is deprecated and has no effect
18982007
* as of QGIS 3.4.3 and the text format should be set using QgsRenderContext::setTextRenderFormat() instead.
2008+
*
2009+
* \deprecated Private API only, will be removed in 4.0
18992010
*/
1900-
static void drawPart( const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines,
1901-
QgsRenderContext &context, const QgsTextFormat &format,
1902-
TextPart part, bool drawAsOutlines = true );
1903-
1904-
#ifndef SIP_RUN
1905-
1906-
/**
1907-
* Draws a single component of rendered text using the specified settings.
1908-
* \param rect destination rectangle for text
1909-
* \param rotation text rotation
1910-
* \param alignment horizontal alignment
1911-
* \param document text document to draw
1912-
* \param context render context
1913-
* \param format text format
1914-
* \param part component of text to draw. Note that Shadow parts cannot be drawn
1915-
* individually and instead are drawn with their associated part (e.g., drawn together
1916-
* with the text or background parts)
1917-
* \note Not available in Python bindings
1918-
* \since QGIS 3.14
1919-
*/
1920-
static void drawPart( const QRectF &rect, double rotation, HAlignment alignment, const QgsTextDocument &document,
1921-
QgsRenderContext &context, const QgsTextFormat &format,
1922-
TextPart part );
1923-
#endif
2011+
Q_DECL_DEPRECATED static void drawPart( const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines,
2012+
QgsRenderContext &context, const QgsTextFormat &format,
2013+
TextPart part, bool drawAsOutlines = true ) SIP_DEPRECATED;
19242014

19252015
/**
19262016
* Draws a single component of rendered text using the specified settings.
@@ -1937,31 +2027,12 @@ class CORE_EXPORT QgsTextRenderer
19372027
* formats like SVG to maintain text as text objects, but at the cost of degraded
19382028
* rendering and may result in side effects like misaligned text buffers. This setting is deprecated and has no effect
19392029
* as of QGIS 3.4.3 and the text format should be set using QgsRenderContext::setTextRenderFormat() instead.
2030+
*
2031+
* \deprecated Private API only, will be removed in 4.0
19402032
*/
1941-
static void drawPart( QPointF origin, double rotation, HAlignment alignment, const QStringList &textLines,
1942-
QgsRenderContext &context, const QgsTextFormat &format,
1943-
TextPart part, bool drawAsOutlines = true );
1944-
1945-
#ifndef SIP_RUN
1946-
1947-
/**
1948-
* Draws a single component of rendered text using the specified settings.
1949-
* \param origin origin for start of text. Y coordinate will be used as baseline.
1950-
* \param rotation text rotation
1951-
* \param alignment horizontal alignment
1952-
* \param document document to draw
1953-
* \param context render context
1954-
* \param format text format
1955-
* \param part component of text to draw. Note that Shadow parts cannot be drawn
1956-
* individually and instead are drawn with their associated part (e.g., drawn together
1957-
* with the text or background parts)
1958-
* \note Not available in Python bindings
1959-
* \since QGIS 3.14
1960-
*/
1961-
static void drawPart( QPointF origin, double rotation, HAlignment alignment, const QgsTextDocument &document,
1962-
QgsRenderContext &context, const QgsTextFormat &format,
1963-
TextPart part );
1964-
#endif
2033+
Q_DECL_DEPRECATED static void drawPart( QPointF origin, double rotation, HAlignment alignment, const QStringList &textLines,
2034+
QgsRenderContext &context, const QgsTextFormat &format,
2035+
TextPart part, bool drawAsOutlines = true ) SIP_DEPRECATED;
19652036

19662037
/**
19672038
* Returns the font metrics for the given text \a format, when rendered
@@ -2026,6 +2097,42 @@ class CORE_EXPORT QgsTextRenderer
20262097
HAlignment hAlign = AlignLeft;
20272098
};
20282099

2100+
/**
2101+
* Draws a single component of rendered text using the specified settings.
2102+
* \param rect destination rectangle for text
2103+
* \param rotation text rotation
2104+
* \param alignment horizontal alignment
2105+
* \param document text document to draw
2106+
* \param context render context
2107+
* \param format text format
2108+
* \param part component of text to draw. Note that Shadow parts cannot be drawn
2109+
* individually and instead are drawn with their associated part (e.g., drawn together
2110+
* with the text or background parts)
2111+
* \note Not available in Python bindings
2112+
* \since QGIS 3.14
2113+
*/
2114+
static void drawPart( const QRectF &rect, double rotation, HAlignment alignment, const QgsTextDocument &document,
2115+
QgsRenderContext &context, const QgsTextFormat &format,
2116+
TextPart part );
2117+
2118+
/**
2119+
* Draws a single component of rendered text using the specified settings.
2120+
* \param origin origin for start of text. Y coordinate will be used as baseline.
2121+
* \param rotation text rotation
2122+
* \param alignment horizontal alignment
2123+
* \param document document to draw
2124+
* \param context render context
2125+
* \param format text format
2126+
* \param part component of text to draw. Note that Shadow parts cannot be drawn
2127+
* individually and instead are drawn with their associated part (e.g., drawn together
2128+
* with the text or background parts)
2129+
* \note Not available in Python bindings
2130+
* \since QGIS 3.14
2131+
*/
2132+
static void drawPart( QPointF origin, double rotation, HAlignment alignment, const QgsTextDocument &document,
2133+
QgsRenderContext &context, const QgsTextFormat &format,
2134+
TextPart part );
2135+
20292136
static void drawBuffer( QgsRenderContext &context,
20302137
const Component &component,
20312138
const QgsTextFormat &format,

0 commit comments

Comments
 (0)
Please sign in to comment.