16#ifndef QGSTEXTRENDERER_H
17#define QGSTEXTRENDERER_H
25#include <QPainterPath>
145 bool drawAsOutlines =
true );
189 static void drawTextOnLine(
const QPolygonF &line,
const QString &text,
191 double offsetAlongLine = 0,
double offsetFromLine = 0,
211 double offsetAlongLine = 0,
212 double offsetFromLine = 0,
367 int firstFragmentIndex = 0;
372 bool useOrigin =
false;
374 double rotation = 0.0;
376 double rotationOffset = 0.0;
390 double pictureBuffer = 0.0;
392 double dpiRatio = 1.0;
397 double extraWordSpacing = 0;
399 double extraLetterSpacing = 0;
449 const Component &component,
455 const Component &component,
461 const Component &component,
465 const Component &component,
471 const Component &component,
477 const Component &component,
486 static void calculateExtraSpacingForLineJustification(
double spaceToDistribute,
const QgsTextBlock &block,
double &extraWordSpace,
double &extraLetterSpace );
487 static void applyExtraSpacingForLineJustification( QFont &font,
double extraWordSpace,
double extraLetterSpace );
493 const Component &component,
505 const Component &component,
513 struct DeferredRenderFragment
528 double backgroundXOffset = 0;
530 double backgroundWidth = 0;
531 double extraWordSpace = 0;
532 double extraLetterSpace = 0;
537 struct DeferredRenderBlock
541 QVector< DeferredRenderFragment > fragments;
544 static QBrush createBrushForPath( QgsRenderContext &context,
const QString &path );
546 static void renderBlockHorizontal(
const QgsTextBlock &block,
int blockIndex,
547 const QgsTextDocumentMetrics &metrics, QgsRenderContext &context,
548 const QgsTextFormat &format,
549 QPainter *painter,
bool forceRenderAsPaths,
550 double fontScale,
double extraWordSpace,
double extraLetterSpace,
552 DeferredRenderBlock *deferredRenderBlock );
553 static void renderDocumentBackgrounds( QgsRenderContext &context,
const QgsTextDocument &document,
const QgsTextDocumentMetrics &metrics,
const Component &component,
const QVector< QgsTextRenderer::BlockMetrics > &blockMetrics,
Qgis::TextLayoutMode mode,
double verticalAlignOffset,
double rotation );
554 static void renderDeferredBlocks( QgsRenderContext &context,
const QgsTextFormat &format,
Qgis::TextComponents components,
const std::vector<DeferredRenderBlock> &deferredBlocks,
bool usePathsForText,
double fontScale,
const Component &component,
double rotation );
555 static void renderDeferredBuffer( QgsRenderContext &context,
const QgsTextFormat &format,
Qgis::TextComponents components,
const std::vector<DeferredRenderBlock> &deferredBlocks,
double fontScale,
const Component &component,
double rotation );
556 static void renderDeferredShadowForText( QgsRenderContext &context,
const QgsTextFormat &format,
const std::vector<DeferredRenderBlock> &deferredBlocks,
double fontScale,
const Component &component,
double rotation );
557 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