Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor QgsTextRenderer internal methods, optimise buffer render #59414

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/PyQt6/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5079,6 +5079,9 @@
"""
# --
Qgis.TextComponent.baseClass = Qgis
Qgis.TextComponents = lambda flags=0: Qgis.TextComponent(flags)
Qgis.TextComponents.baseClass = Qgis
TextComponents = Qgis # dirty hack since SIP seems to introduce the flags in module
QgsTextRenderer.HAlignment = Qgis.TextHorizontalAlignment
# monkey patching scoped based enum
QgsTextRenderer.AlignLeft = Qgis.TextHorizontalAlignment.Left
Expand Down
9 changes: 7 additions & 2 deletions python/PyQt6/core/auto_generated/qgis.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1591,14 +1591,17 @@ The development version
RectangleAscentBased,
};

enum class TextComponent /BaseType=IntEnum/
{
enum class TextComponent /BaseType=IntFlag/
{
Text,
Buffer,
Background,
Shadow,
};

typedef QFlags<Qgis::TextComponent> TextComponents;


enum class TextHorizontalAlignment /BaseType=IntEnum/
{
Left,
Expand Down Expand Up @@ -3333,6 +3336,8 @@ QFlags<Qgis::SymbolPreviewFlag> operator|(Qgis::SymbolPreviewFlag f1, QFlags<Qgi

QFlags<Qgis::SymbolRenderHint> operator|(Qgis::SymbolRenderHint f1, QFlags<Qgis::SymbolRenderHint> f2);

QFlags<Qgis::TextComponent> operator|(Qgis::TextComponent f1, QFlags<Qgis::TextComponent> f2);

QFlags<Qgis::TextRendererFlag> operator|(Qgis::TextRendererFlag f1, QFlags<Qgis::TextRendererFlag> f2);

QFlags<Qgis::TiledSceneProviderCapability> operator|(Qgis::TiledSceneProviderCapability f1, QFlags<Qgis::TiledSceneProviderCapability> f2);
Expand Down
2 changes: 2 additions & 0 deletions python/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5028,6 +5028,8 @@
"""
# --
Qgis.TextComponent.baseClass = Qgis
Qgis.TextComponents.baseClass = Qgis
TextComponents = Qgis # dirty hack since SIP seems to introduce the flags in module
QgsTextRenderer.HAlignment = Qgis.TextHorizontalAlignment
# monkey patching scoped based enum
QgsTextRenderer.AlignLeft = Qgis.TextHorizontalAlignment.Left
Expand Down
7 changes: 6 additions & 1 deletion python/core/auto_generated/qgis.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1592,13 +1592,16 @@ The development version
};

enum class TextComponent
{
{
Text,
Buffer,
Background,
Shadow,
};

typedef QFlags<Qgis::TextComponent> TextComponents;


enum class TextHorizontalAlignment
{
Left,
Expand Down Expand Up @@ -3333,6 +3336,8 @@ QFlags<Qgis::SymbolPreviewFlag> operator|(Qgis::SymbolPreviewFlag f1, QFlags<Qgi

QFlags<Qgis::SymbolRenderHint> operator|(Qgis::SymbolRenderHint f1, QFlags<Qgis::SymbolRenderHint> f2);

QFlags<Qgis::TextComponent> operator|(Qgis::TextComponent f1, QFlags<Qgis::TextComponent> f2);

QFlags<Qgis::TextRendererFlag> operator|(Qgis::TextRendererFlag f1, QFlags<Qgis::TextRendererFlag> f2);

QFlags<Qgis::TiledSceneProviderCapability> operator|(Qgis::TiledSceneProviderCapability f1, QFlags<Qgis::TiledSceneProviderCapability> f2);
Expand Down
21 changes: 19 additions & 2 deletions src/core/labeling/qgsvectorlayerlabelprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,23 @@ void QgsVectorLayerLabelProvider::drawLabelPrivate( pal::LabelPosition *label, Q
// NOTE: this is repeatedly called for multi-part labels
QPainter *painter = context.painter();

Qgis::TextComponents components;
switch ( drawType )
{
case Qgis::TextComponent::Text:
components = Qgis::TextComponent::Text | Qgis::TextComponent::Shadow;
break;

case Qgis::TextComponent::Buffer:
components = Qgis::TextComponent::Buffer | Qgis::TextComponent::Shadow;
break;

case Qgis::TextComponent::Background:
case Qgis::TextComponent::Shadow:
components = drawType;
break;
}

// features are pre-rotated but not scaled/translated,
// so we only disable rotation here. Ideally, they'd be
// also pre-scaled/translated, as suggested here:
Expand Down Expand Up @@ -789,7 +806,7 @@ void QgsVectorLayerLabelProvider::drawLabelPrivate( pal::LabelPosition *label, Q

QgsScopedRenderContextReferenceScaleOverride referenceScaleOverride( context, -1.0 );
const QgsTextDocumentMetrics metrics = QgsTextDocumentMetrics::calculateMetrics( document, tmpLyr.format(), context );
QgsTextRenderer::drawTextInternal( drawType, context, tmpLyr.format(), component, document,
QgsTextRenderer::drawTextInternal( components, context, tmpLyr.format(), component, document,
metrics, hAlign, Qgis::TextVerticalAlignment::Top, Qgis::TextLayoutMode::Labeling );
break;
}
Expand All @@ -806,7 +823,7 @@ void QgsVectorLayerLabelProvider::drawLabelPrivate( pal::LabelPosition *label, Q

component.origin.ry() += verticalAlignOffset;

QgsTextRenderer::drawTextInternal( drawType, context, tmpLyr.format(), component, *document,
QgsTextRenderer::drawTextInternal( components, context, tmpLyr.format(), component, *document,
*documentMetrics, hAlign, Qgis::TextVerticalAlignment::Top, Qgis::TextLayoutMode::Labeling );
break;
}
Expand Down
21 changes: 15 additions & 6 deletions src/core/qgis.h
Original file line number Diff line number Diff line change
Expand Up @@ -2712,15 +2712,23 @@ class CORE_EXPORT Qgis
*
* \since QGIS 3.28
*/
enum class TextComponent SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsTextRenderer, TextPart ) : int
{
Text, //!< Text component
Buffer, //!< Buffer component
Background, //!< Background shape
Shadow, //!< Drop shadow
enum class TextComponent SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsTextRenderer, TextPart ) : int SIP_ENUM_BASETYPE( IntFlag )
{
Text = 1 << 0, //!< Text component
Buffer = 1 << 1, //!< Buffer component
Background = 1 << 2, //!< Background shape
Shadow = 1 << 3, //!< Drop shadow
};
Q_ENUM( TextComponent )

/**
* Text components.
*
* \since QGIS 3.42
*/
Q_DECLARE_FLAGS( TextComponents, TextComponent )
Q_FLAG( TextComponents )

/**
* Text horizontal alignment.
*
Expand Down Expand Up @@ -5735,6 +5743,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::SymbolLayerFlags )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::SymbolLayerUserFlags )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::SymbolPreviewFlags )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::SymbolRenderHints )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::TextComponents )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::TextRendererFlags )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::TiledSceneProviderCapabilities )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::TiledSceneRendererFlags )
Expand Down
Loading
Loading