16#ifndef QGSTEXTRENDERER_H
17#define QGSTEXTRENDERER_H
25#include <QPainterPath>
94 const QStringList &textLines,
97 bool drawAsOutlines =
true,
202 const QPolygonF &line,
206 double offsetAlongLine = 0,
207 double offsetFromLine = 0,
228 const QPolygonF &line,
232 double offsetAlongLine = 0,
233 double offsetFromLine = 0,
256 Q_DECL_DEPRECATED
static void drawPart(
260 const QStringList &textLines,
264 bool drawAsOutlines =
true
285 Q_DECL_DEPRECATED
static void drawPart(
289 const QStringList &textLines,
293 bool drawAsOutlines =
true
332 const QStringList &textLines,
336 double maxLineWidth = 0
409 int firstFragmentIndex = 0;
414 bool useOrigin =
false;
416 double rotation = 0.0;
418 double rotationOffset = 0.0;
432 double pictureBuffer = 0.0;
434 double dpiRatio = 1.0;
439 double extraWordSpacing = 0;
441 double extraLetterSpacing = 0;
464 static void drawParts(
493 static void drawParts(
507 static void drawBackground(
517 static void drawTextInternal(
521 const Component &component,
531 static void calculateExtraSpacingForLineJustification(
double spaceToDistribute,
const QgsTextBlock &block,
double &extraWordSpace,
double &extraLetterSpace );
532 static void applyExtraSpacingForLineJustification( QFont &font,
double extraWordSpace,
double extraLetterSpace );
534 static void drawTextInternalHorizontal(
539 const Component &component,
548 static void drawTextInternalVertical(
553 const Component &component,
562 struct DeferredRenderFragment
577 double backgroundXOffset = 0;
579 double backgroundWidth = 0;
580 double extraWordSpace = 0;
581 double extraLetterSpace = 0;
584 static QVector< QgsTextRenderer::BlockMetrics > calculateBlockMetrics(
588 struct DeferredRenderBlock
592 QVector< DeferredRenderFragment > fragments;
595 static QBrush createBrushForPath( QgsRenderContext &context,
const QString &path );
597 static void renderBlockHorizontal(
598 const QgsTextBlock &block,
600 const QgsTextDocumentMetrics &metrics,
601 QgsRenderContext &context,
602 const QgsTextFormat &format,
604 bool forceRenderAsPaths,
606 double extraWordSpace,
607 double extraLetterSpace,
609 DeferredRenderBlock *deferredRenderBlock
611 static void renderDocumentBackgrounds(
612 QgsRenderContext &context,
613 const QgsTextDocument &document,
614 const QgsTextDocumentMetrics &metrics,
615 const Component &component,
616 const QVector< QgsTextRenderer::BlockMetrics > &blockMetrics,
618 double verticalAlignOffset,
621 static void renderDeferredBlocks(
622 QgsRenderContext &context,
623 const QgsTextFormat &format,
625 const std::vector<DeferredRenderBlock> &deferredBlocks,
626 bool usePathsForText,
628 const Component &component,
631 static void renderDeferredBuffer(
632 QgsRenderContext &context,
const QgsTextFormat &format,
Qgis::TextComponents components,
const std::vector<DeferredRenderBlock> &deferredBlocks,
double fontScale,
const Component &component,
double rotation
634 static void renderDeferredShadowForText(
635 QgsRenderContext &context,
const QgsTextFormat &format,
const std::vector<DeferredRenderBlock> &deferredBlocks,
double fontScale,
const Component &component,
double rotation
637 static void renderDeferredText( QgsRenderContext &context,
const std::vector<DeferredRenderBlock> &deferredBlocks,
bool usePathsForText,
double fontScale,
const Component &component,
double rotation );
TextAnchorPoint
Anchor point of label text.
@ StartOfText
Anchor using start of text.
TextLayoutMode
Text layout modes.
@ Point
Text at point of origin layout mode.
@ Rectangle
Text within rectangle layout mode.
QFlags< TextRendererFlag > TextRendererFlags
TextOrientation
Text orientations.
RenderUnit
Rendering size units.
TextVerticalAlignment
Text vertical alignment.
@ TruncateStringWhenLineIsTooShort
When a string is too long for the line, truncate characters instead of aborting the placement.
@ UseBaselinePlacement
Generate placement based on the character baselines instead of centers.
QFlags< TextComponent > TextComponents
Text components.
TextHorizontalAlignment
Text horizontal alignment.
QFlags< CurvedTextFlag > CurvedTextFlags
Flags controlling behavior of curved text generation.
TextComponent
Text components.
Struct for storing maximum and minimum scales for measurements in map units.
Contains information about the context of a rendering operation.
Represents a block of text consisting of one or more QgsTextFragment objects.
Contains pre-calculated metrics of a QgsTextDocument.
Represents a document consisting of one or more QgsTextBlock objects.
Container for all settings relating to text rendering.
Handles rendering text using rich formatting options, including drop shadows, buffers and background ...
static Qgis::TextVerticalAlignment convertQtVAlignment(Qt::Alignment alignment)
Converts a Qt vertical alignment flag to a Qgis::TextVerticalAlignment value.
static double textWidth(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, QFontMetricsF *fontMetrics=nullptr)
Returns the width of a text based on a given format.
static void drawDocument(const QRectF &rect, const QgsTextFormat &format, const QgsTextDocument &document, const QgsTextDocumentMetrics &metrics, QgsRenderContext &context, Qgis::TextHorizontalAlignment horizontalAlignment=Qgis::TextHorizontalAlignment::Left, Qgis::TextVerticalAlignment verticalAlignment=Qgis::TextVerticalAlignment::Top, double rotation=0, Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Rectangle, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags())
Draws a text document within a rectangle using the specified settings.
static int sizeToPixel(double size, const QgsRenderContext &c, Qgis::RenderUnit unit, const QgsMapUnitScale &mapUnitScale=QgsMapUnitScale())
Calculates pixel size (considering output size should be in pixel or map units, scale factors and opt...
static Q_DECL_DEPRECATED void drawPart(const QRectF &rect, double rotation, Qgis::TextHorizontalAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, Qgis::TextComponent part, bool drawAsOutlines=true)
Draws a single component of rendered text using the specified settings.
static void drawText(const QRectF &rect, double rotation, Qgis::TextHorizontalAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, Qgis::TextVerticalAlignment vAlignment=Qgis::TextVerticalAlignment::Top, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Rectangle)
Draws text within a rectangle using the specified settings.
static bool textRequiresWrapping(const QgsRenderContext &context, const QString &text, double width, const QgsTextFormat &format)
Returns true if the specified text requires line wrapping in order to fit within the specified width ...
static QFontMetricsF fontMetrics(QgsRenderContext &context, const QgsTextFormat &format, double scaleFactor=1.0)
Returns the font metrics for the given text format, when rendered in the specified render context.
static double calculateScaleFactorForFormat(const QgsRenderContext &context, const QgsTextFormat &format)
Returns the scale factor used for upscaling font sizes and downscaling destination painter devices.
static QStringList wrappedText(const QgsRenderContext &context, const QString &text, double width, const QgsTextFormat &format)
Wraps a text string to multiple lines, such that each individual line will fit within the specified w...
friend class QgsLabelPreview
static void drawTextOnLine(const QPolygonF &line, const QString &text, QgsRenderContext &context, const QgsTextFormat &format, double offsetAlongLine=0, double offsetFromLine=0, Qgis::CurvedTextFlags flags=Qgis::CurvedTextFlag::UseBaselinePlacement|Qgis::CurvedTextFlag::TruncateStringWhenLineIsTooShort, Qgis::TextAnchorPoint textAnchor=Qgis::TextAnchorPoint::StartOfText)
Draws text along a line using the specified settings.
friend class QgsVectorLayerLabelProvider
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Point, QFontMetricsF *fontMetrics=nullptr, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), double maxLineWidth=0)
Returns the height of a text based on a given format.
static constexpr double SUPERSCRIPT_SUBSCRIPT_FONT_SIZE_SCALING_FACTOR
Scale factor to use for super or subscript text which doesn't have an explicit font size set.
static constexpr double FONT_WORKAROUND_SCALE
Scale factor for upscaling font sizes and downscaling destination painter devices.
static Qgis::TextHorizontalAlignment convertQtHAlignment(Qt::Alignment alignment)
Converts a Qt horizontal alignment flag to a Qgis::TextHorizontalAlignment value.
static void drawDocumentOnLine(const QPolygonF &line, const QgsTextFormat &format, const QgsTextDocument &document, QgsRenderContext &context, double offsetAlongLine=0, double offsetFromLine=0, Qgis::CurvedTextFlags flags=Qgis::CurvedTextFlag::UseBaselinePlacement|Qgis::CurvedTextFlag::TruncateStringWhenLineIsTooShort, Qgis::TextAnchorPoint textAnchor=Qgis::TextAnchorPoint::StartOfText)
Draws a text document along a line using the specified settings.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c