16#ifndef QGSTEXTRENDERER_H
17#define QGSTEXTRENDERER_H
25#include <QPainterPath>
94 const QStringList &textLines,
97 bool drawAsOutlines =
true,
200 const QPolygonF &line,
204 double offsetAlongLine = 0,
205 double offsetFromLine = 0,
223 const QPolygonF &line,
227 double offsetAlongLine = 0,
228 double offsetFromLine = 0,
250 Q_DECL_DEPRECATED
static void drawPart(
254 const QStringList &textLines,
258 bool drawAsOutlines =
true
279 Q_DECL_DEPRECATED
static void drawPart(
283 const QStringList &textLines,
287 bool drawAsOutlines =
true
326 const QStringList &textLines,
330 double maxLineWidth = 0
403 int firstFragmentIndex = 0;
408 bool useOrigin =
false;
410 double rotation = 0.0;
412 double rotationOffset = 0.0;
426 double pictureBuffer = 0.0;
428 double dpiRatio = 1.0;
433 double extraWordSpacing = 0;
435 double extraLetterSpacing = 0;
458 static void drawParts(
487 static void drawParts(
501 static void drawBackground(
511 static void drawTextInternal(
515 const Component &component,
525 static void calculateExtraSpacingForLineJustification(
double spaceToDistribute,
const QgsTextBlock &block,
double &extraWordSpace,
double &extraLetterSpace );
526 static void applyExtraSpacingForLineJustification( QFont &font,
double extraWordSpace,
double extraLetterSpace );
528 static void drawTextInternalHorizontal(
533 const Component &component,
542 static void drawTextInternalVertical(
547 const Component &component,
556 struct DeferredRenderFragment
571 double backgroundXOffset = 0;
573 double backgroundWidth = 0;
574 double extraWordSpace = 0;
575 double extraLetterSpace = 0;
578 static QVector< QgsTextRenderer::BlockMetrics > calculateBlockMetrics(
582 struct DeferredRenderBlock
586 QVector< DeferredRenderFragment > fragments;
589 static QBrush createBrushForPath( QgsRenderContext &context,
const QString &path );
591 static void renderBlockHorizontal(
592 const QgsTextBlock &block,
594 const QgsTextDocumentMetrics &metrics,
595 QgsRenderContext &context,
596 const QgsTextFormat &format,
598 bool forceRenderAsPaths,
600 double extraWordSpace,
601 double extraLetterSpace,
603 DeferredRenderBlock *deferredRenderBlock
605 static void renderDocumentBackgrounds(
606 QgsRenderContext &context,
607 const QgsTextDocument &document,
608 const QgsTextDocumentMetrics &metrics,
609 const Component &component,
610 const QVector< QgsTextRenderer::BlockMetrics > &blockMetrics,
612 double verticalAlignOffset,
615 static void renderDeferredBlocks(
616 QgsRenderContext &context,
617 const QgsTextFormat &format,
619 const std::vector<DeferredRenderBlock> &deferredBlocks,
620 bool usePathsForText,
622 const Component &component,
625 static void renderDeferredBuffer(
626 QgsRenderContext &context,
const QgsTextFormat &format,
Qgis::TextComponents components,
const std::vector<DeferredRenderBlock> &deferredBlocks,
double fontScale,
const Component &component,
double rotation
628 static void renderDeferredShadowForText(
629 QgsRenderContext &context,
const QgsTextFormat &format,
const std::vector<DeferredRenderBlock> &deferredBlocks,
double fontScale,
const Component &component,
double rotation
631 static void renderDeferredText( QgsRenderContext &context,
const std::vector<DeferredRenderBlock> &deferredBlocks,
bool usePathsForText,
double fontScale,
const Component &component,
double rotation );
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
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 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)
Draws a text document along a line using the specified settings.
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)
Draws text along a line using the specified settings.
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.
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