Skip to content

RTextRenderer

Class in Entity Module
Header: #include <src/core/RTextRenderer.h>

Renders formatted text into painter paths.

Scriptable: This class is available in script environments.

enum Target { PainterPaths, RichText }
RTextRenderer(const RTextBasedData &textData, bool draft, RTextRenderer::Target target, double fontHeightFactor=1.0)
RBox getBoundingBox() const
double getHeight() const
QList< RPainterPath > getPainterPaths() const
QString getRichText() const
QList< RTextLayout > getTextLayouts() const
double getWidth() const
void render()
Renders the text data into painter paths.
void renderSimple()
Renders the text data into painter paths.
static void lockForDrawing()
static void unlockForDrawing()
static QChar chDegree
static QChar chDiameter
static QChar chPlusMinus
static QRegularExpression escDegree
static QString escDegreeStr
static QRegularExpression escDiameter
static QString escDiameterStr
static QRegularExpression escNoOp
static QString escNoOpStr
static QRegularExpression escPlusMinus
static QString escPlusMinusStr
static QRegularExpression escUnderline
static QString escUnderlineStr
static QRegularExpression rxAlignmentCenter
static QString rxAlignmentCenterStr
static QRegularExpression rxAlignmentChange
static QRegularExpression rxAlignmentChangeBlock
static QString rxAlignmentChangeBlockStr
static QString rxAlignmentChangeStr
static QRegularExpression rxAlignmentLeft
static QString rxAlignmentLeftStr
static QRegularExpression rxAlignmentRight
static QString rxAlignmentRightStr
static QRegularExpression rxAll
static QRegularExpression rxAllBreak
static QString rxAllBreakStr
static QString rxAllStr
static QRegularExpression rxBackslash
static QString rxBackslashStr
static QRegularExpression rxBeginBlock
static QString rxBeginBlockStr
static QRegularExpression rxColorChangeCustom
static QString rxColorChangeCustomStr
static QRegularExpression rxColorChangeIndex
static QString rxColorChangeIndexStr
static QRegularExpression rxCurlyClose
static QString rxCurlyCloseStr
static QRegularExpression rxCurlyOpen
static QString rxCurlyOpenStr
static QRegularExpression rxDegree
static QString rxDegreeStr
static QRegularExpression rxDiameter
static QString rxDiameterStr
static QRegularExpression rxEndBlock
static QString rxEndBlockStr
static QRegularExpression rxFontChangeCad
static QString rxFontChangeCadStr
static QRegularExpression rxFontChangeTtf
static QString rxFontChangeTtfStr
static QRegularExpression rxHeightChange
static QString rxHeightChangeStr
static QRegularExpression rxLineFeed
static QString rxLineFeedStr
static QRegularExpression rxMif
static QString rxMifStr
static QRegularExpression rxNonBreakingSpace
static QString rxNonBreakingSpaceStr
static QRegularExpression rxNoOp
static QRegularExpression rxNoOpEnd
static QString rxNoOpEndStr
static QString rxNoOpStr
static QRegularExpression rxObliqueAngleChange
static QString rxObliqueAngleChangeStr
static QRegularExpression rxOptionalBreak
static QString rxOptionalBreakStr
static QRegularExpression rxOverlineOff
static QString rxOverlineOffStr
static QRegularExpression rxOverlineOn
static QString rxOverlineOnStr
static QRegularExpression rxParagraphFeed
static QString rxParagraphFeedStr
static QRegularExpression rxPlusMinus
static QString rxPlusMinusStr
static QRegularExpression rxStackedText
static QString rxStackedTextStr
static QRegularExpression rxStrikethroughOff
static QString rxStrikethroughOffStr
static QRegularExpression rxStrikethroughOn
static QString rxStrikethroughOnStr
static QRegularExpression rxTabIN
static QString rxTabINStr
static QRegularExpression rxTabMM
static QString rxTabMMStr
static QRegularExpression rxTrackChange
static QString rxTrackChangeStr
static QRegularExpression rxUnderline
static QRegularExpression rxUnderlineChange
static QString rxUnderlineChangeStr
static QRegularExpression rxUnderlineOff
static QString rxUnderlineOffStr
static QRegularExpression rxUnderlineOn
static QString rxUnderlineOnStr
static QString rxUnderlineStr
static QRegularExpression rxUnicode
static QString rxUnicodeStr
static QRegularExpression rxWidthChange
static QString rxWidthChangeStr
static QRegularExpression rxXAlignmentCenter
static QString rxXAlignmentCenterStr
static QRegularExpression rxXAlignmentLeft
static QString rxXAlignmentLeftStr
static QRegularExpression rxXAlignmentRight
static QString rxXAlignmentRightStr
static QRegularExpression rxXFeed
static QString rxXFeedStr
static QRegularExpression rxXSpaceMText
static QString rxXSpaceMTextStr
bool getBlockBold() const
QString getBlockFont() const
QString getBlockFontFile() const
double getBlockHeight() const
bool getBlockItalic() const
bool getBlockUnderline() const
QRectF getCharacterRect(const QFont &font, const QChar &ch) const
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
QRectF getCharacterRect(const QString &fontName, const QChar &ch) const
QTextCharFormat getCurrentFormat() const
QList< RPainterPath > getPainterPathsForBlock(const QString &blockText, const QList< QTextLayout::FormatRange > &formats, double &horizontalAdvance, double &horizontalAdvanceNoSpacing, double &horizontalAdvanceNoTrailingSpace, double &ascent, double &descent, double &usedHeight)
QList< RPainterPath > getPainterPathsForBlockCad(const QString &blockText, const QList< QTextLayout::FormatRange > &formats, double &horizontalAdvance, double &horizontalAdvanceNoSpacing, double &horizontalAdvanceNoTrailingSpace, double &ascent, double &descent, double &usedHeight)
QList< RPainterPath > getPainterPathsForBlockTtf(const QString &blockText, const QList< QTextLayout::FormatRange > &formats, double &horizontalAdvance, double &horizontalAdvanceNoSpacing, double &horizontalAdvanceNoTrailingSpace, double &ascent, double &descent, double &usedHeight)
QString getRichTextForBlock(const QString &blockText, const QList< QTextLayout::FormatRange > &formats)
bool getUseCadFont() const
void preparePath(RPainterPath &path, const RColor &color, double cursor, double cxfScale)
void preparePathColor(RPainterPath &path, const RColor &color)
void preparePathTransform(RPainterPath &path, double cursor, double cxfScale)
void setBlockBold(bool on)
void setBlockFont(const QString &f)
void setBlockFontFile(const QString &f)
void setBlockHeight(double h)
void setBlockItalic(bool on)
void setBlockUnderline(bool on)
void setCurrentFormat(QTextCharFormat f)
void setUseCadFont(bool on)
QStack< bool > blockBold
QStack< QString > blockFont
QStack< QString > blockFontFile
QStack< double > blockHeight
QStack< bool > blockItalic
QStack< bool > blockUnderline
RBox boundingBox
QStack< QTextCharFormat > currentFormat
bool draft
double fontHeightFactor
double height
QList< QTransform > lineBlockTransforms
QStack< QStringList > openTags
QList< RPainterPath > painterPaths
QString richText
Target target
const RTextBasedData & textData
QList< RTextLayout > textLayouts
QStack< bool > useCadFont
double width
static QMutex m

enum Target
Value Description
PainterPaths = 0x01
RichText = 0x02

RTextRenderer::RTextRenderer(const RTextBasedData &textData, bool draft, RTextRenderer::Target target, double fontHeightFactor=1.0)

RBox RTextRenderer::getBoundingBox() const

inline const

double RTextRenderer::getHeight() const

inline const

QList< RPainterPath > RTextRenderer::getPainterPaths() const

inline const

QString RTextRenderer::getRichText() const

inline const

QList< RTextLayout > RTextRenderer::getTextLayouts() const

inline const

double RTextRenderer::getWidth() const

inline const

void RTextRenderer::render()

Renders the text data into painter paths.

void RTextRenderer::renderSimple()

Renders the text data into painter paths.

static void RTextRenderer::lockForDrawing()

static inline

static void RTextRenderer::unlockForDrawing()

static inline

static QChar RTextRenderer::chDegree = QChar(0x00b0)

static

All rights reserved.

This file is part of the QCAD project.

QCAD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

QCAD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with QCAD.

static QChar RTextRenderer::chDiameter = QChar(0x00f8)

static

static QChar RTextRenderer::chPlusMinus = QChar(0x00b1)

static

static QRegularExpression RTextRenderer::escDegree

static

static QString RTextRenderer::escDegreeStr = "%%d"

static

static QRegularExpression RTextRenderer::escDiameter

static

static QString RTextRenderer::escDiameterStr = "%%c"

static

static QRegularExpression RTextRenderer::escNoOp

static

static QString RTextRenderer::escNoOpStr = "%%"

static

static QRegularExpression RTextRenderer::escPlusMinus

static

static QString RTextRenderer::escPlusMinusStr = "%%p"

static

static QRegularExpression RTextRenderer::escUnderline

static

static QString RTextRenderer::escUnderlineStr = "%%u"

static

static QRegularExpression RTextRenderer::rxAlignmentCenter

static

static QString RTextRenderer::rxAlignmentCenterStr = "\\\\pqc;"

static

static QRegularExpression RTextRenderer::rxAlignmentChange

static

static QRegularExpression RTextRenderer::rxAlignmentChangeBlock

static

static QString RTextRenderer::rxAlignmentChangeBlockStr = "\\\\A(\\d+)"

static

static QString RTextRenderer::rxAlignmentChangeStr = "\\\\A(\\d+);"

static

static QRegularExpression RTextRenderer::rxAlignmentLeft

static

static QString RTextRenderer::rxAlignmentLeftStr = "\\\\pql;"

static

static QRegularExpression RTextRenderer::rxAlignmentRight

static

static QString RTextRenderer::rxAlignmentRightStr = "\\\\pqr;"

static

static QRegularExpression RTextRenderer::rxAll

static

static QRegularExpression RTextRenderer::rxAllBreak

static

static QString RTextRenderer::rxAllBreakStr = "(" + rxAllTmp + "|" + RTextRenderer::rxOptionalBreakStr + ")"

static

static QString RTextRenderer::rxAllStr = "(" + rxAllTmp + ")"

static

static QRegularExpression RTextRenderer::rxBackslash

static

static QString RTextRenderer::rxBackslashStr = "\\\\\\\\"

static

static QRegularExpression RTextRenderer::rxBeginBlock

static

static QString RTextRenderer::rxBeginBlockStr = "\\{"

static

static QRegularExpression RTextRenderer::rxColorChangeCustom

static

static QString RTextRenderer::rxColorChangeCustomStr ="\\\\c(\\d+);"

static

static QRegularExpression RTextRenderer::rxColorChangeIndex

static

static QString RTextRenderer::rxColorChangeIndexStr = "\\\\C(\\d+);"

static

static QRegularExpression RTextRenderer::rxCurlyClose

static

static QString RTextRenderer::rxCurlyCloseStr = "\\\\\\}"

static

static QRegularExpression RTextRenderer::rxCurlyOpen

static

static QString RTextRenderer::rxCurlyOpenStr = "\\\\\\{"

static

static QRegularExpression RTextRenderer::rxDegree

static

static QString RTextRenderer::rxDegreeStr = "%%[dD]"

static

static QRegularExpression RTextRenderer::rxDiameter

static

static QString RTextRenderer::rxDiameterStr = "%%[cC]"

static

static QRegularExpression RTextRenderer::rxEndBlock

static

static QString RTextRenderer::rxEndBlockStr = "\\}"

static

static QRegularExpression RTextRenderer::rxFontChangeCad

static

static QString RTextRenderer::rxFontChangeCadStr = "\\\\F([^|;]*)"
"[^;]*"
";"

static

static QRegularExpression RTextRenderer::rxFontChangeTtf

static

static QString RTextRenderer::rxFontChangeTtfStr = "\\\\f([^|;]*)"
"(?:\\|+([bicp])(\\d+))?"
"(?:\\|+([bicp])(\\d+))?"
"(?:\\|+([bicp])(\\d+))?"
"(?:\\|+([bicp])(\\d+))?"
"([^;]*)"
";"

static

static QRegularExpression RTextRenderer::rxHeightChange

static

static QString RTextRenderer::rxHeightChangeStr = "\\\\H(\\d*\\.?\\d*)(x?);"

static

static QRegularExpression RTextRenderer::rxLineFeed

static

static QString RTextRenderer::rxLineFeedStr = "\\\\p(?:x?i(-?\\d*\\.?\\d*)(?:,l-?\\d*\\.?\\d*)(?:,t-?\\d*\\.?\\d*);)?"

static

static QRegularExpression RTextRenderer::rxMif

static

static QString RTextRenderer::rxMifStr = "\\\\M\\+5([0-9A-F]{4})"

static

static QRegularExpression RTextRenderer::rxNonBreakingSpace

static

static QString RTextRenderer::rxNonBreakingSpaceStr = "\\\\~"

static

static QRegularExpression RTextRenderer::rxNoOp

static

static QRegularExpression RTextRenderer::rxNoOpEnd

static

static QString RTextRenderer::rxNoOpEndStr = "%%$"

static

static QString RTextRenderer::rxNoOpStr = "%%([^uUcCpPdD])"

static

static QRegularExpression RTextRenderer::rxObliqueAngleChange

static

static QString RTextRenderer::rxObliqueAngleChangeStr = "\\\\Q(\\d*\\.?\\d*);"

static

static QRegularExpression RTextRenderer::rxOptionalBreak

static

static QString RTextRenderer::rxOptionalBreakStr = QString::fromWCharArray(L"[\\s\u200B]+")

static

static QRegularExpression RTextRenderer::rxOverlineOff

static

static QString RTextRenderer::rxOverlineOffStr = "\\\\o"

static

static QRegularExpression RTextRenderer::rxOverlineOn

static

static QString RTextRenderer::rxOverlineOnStr = "\\\\O"

static

static QRegularExpression RTextRenderer::rxParagraphFeed

static

static QString RTextRenderer::rxParagraphFeedStr = "\\\\P"

static

static QRegularExpression RTextRenderer::rxPlusMinus

static

static QString RTextRenderer::rxPlusMinusStr = "%%[pP]"

static

static QRegularExpression RTextRenderer::rxStackedText

static

static QString RTextRenderer::rxStackedTextStr = "\\\\S([^^]*)\\^([^;]*);"

static

static QRegularExpression RTextRenderer::rxStrikethroughOff

static

static QString RTextRenderer::rxStrikethroughOffStr = "\\\\k"

static

static QRegularExpression RTextRenderer::rxStrikethroughOn

static

static QString RTextRenderer::rxStrikethroughOnStr = "\\\\K"

static

static QRegularExpression RTextRenderer::rxTabIN

static

static QString RTextRenderer::rxTabINStr = "\\\\pxt(\\d*\\.?\\d*,?)*;"

static

static QRegularExpression RTextRenderer::rxTabMM

static

static QString RTextRenderer::rxTabMMStr = "\\\\pt(\\d*\\.?\\d*,?)*;"

static

static QRegularExpression RTextRenderer::rxTrackChange

static

static QString RTextRenderer::rxTrackChangeStr = "\\\\T(\\d*\\.?\\d*);"

static

static QRegularExpression RTextRenderer::rxUnderline

static

static QRegularExpression RTextRenderer::rxUnderlineChange

static

static QString RTextRenderer::rxUnderlineChangeStr = "\\\\L|\\\\l"

static

static QRegularExpression RTextRenderer::rxUnderlineOff

static

static QString RTextRenderer::rxUnderlineOffStr = "\\\\l"

static

static QRegularExpression RTextRenderer::rxUnderlineOn

static

static QString RTextRenderer::rxUnderlineOnStr = "\\\\L"

static

static QString RTextRenderer::rxUnderlineStr = "%%[uU]"

static

static QRegularExpression RTextRenderer::rxUnicode

static

static QString RTextRenderer::rxUnicodeStr = "\\\\[Uu]\\+([0-9a-fA-F]{4})"

static

static QRegularExpression RTextRenderer::rxWidthChange

static

static QString RTextRenderer::rxWidthChangeStr = "\\\\W(\\d*\\.?\\d*)x?;"

static

static QRegularExpression RTextRenderer::rxXAlignmentCenter

static

static QString RTextRenderer::rxXAlignmentCenterStr = "\\\\pxqc;"

static

static QRegularExpression RTextRenderer::rxXAlignmentLeft

static

static QString RTextRenderer::rxXAlignmentLeftStr = "\\\\pxql;"

static

static QRegularExpression RTextRenderer::rxXAlignmentRight

static

static QString RTextRenderer::rxXAlignmentRightStr = "\\\\pxqr;"

static

static QRegularExpression RTextRenderer::rxXFeed

static

static QString RTextRenderer::rxXFeedStr = "\\\\X"

static

static QRegularExpression RTextRenderer::rxXSpaceMText

static

static QString RTextRenderer::rxXSpaceMTextStr = "\\\\pxsm(\\d*\\.?\\d*),?[a-z]*;"

static

bool RTextRenderer::getBlockBold() const

inline const private

QString RTextRenderer::getBlockFont() const

inline const private

QString RTextRenderer::getBlockFontFile() const

inline const private

double RTextRenderer::getBlockHeight() const

inline const private

bool RTextRenderer::getBlockItalic() const

inline const private

bool RTextRenderer::getBlockUnderline() const

inline const private

QRectF RTextRenderer::getCharacterRect(const QFont &font, const QChar &ch) const

const private

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

QRectF RTextRenderer::getCharacterRect(const QString &fontName, const QChar &ch) const

const private

Returns: Bounding box of the given character with the given font in size ‘1’, rendered at 0/0. Used to find out the CAD relevant height, ascent and descent of the font.

QTextCharFormat RTextRenderer::getCurrentFormat() const

inline const private

QList< RPainterPath > RTextRenderer::getPainterPathsForBlock(const QString &blockText, const QList< QTextLayout::FormatRange > &formats, double &horizontalAdvance, double &horizontalAdvanceNoSpacing, double &horizontalAdvanceNoTrailingSpace, double &ascent, double &descent, double &usedHeight)

private

QList< RPainterPath > RTextRenderer::getPainterPathsForBlockCad(const QString &blockText, const QList< QTextLayout::FormatRange > &formats, double &horizontalAdvance, double &horizontalAdvanceNoSpacing, double &horizontalAdvanceNoTrailingSpace, double &ascent, double &descent, double &usedHeight)

private

Returns: Painter paths for the given text block in CAD font, positioned at 0/0 (bottom left corner) and with a font size of 1 drawing unit.

QList< RPainterPath > RTextRenderer::getPainterPathsForBlockTtf(const QString &blockText, const QList< QTextLayout::FormatRange > &formats, double &horizontalAdvance, double &horizontalAdvanceNoSpacing, double &horizontalAdvanceNoTrailingSpace, double &ascent, double &descent, double &usedHeight)

private

Returns: Painter paths for the given text block in TTF font, positioned at 0/0 (bottom left corner) and with a font size of 1 drawing unit.

QString RTextRenderer::getRichTextForBlock(const QString &blockText, const QList< QTextLayout::FormatRange > &formats)

private

bool RTextRenderer::getUseCadFont() const

inline const private

void RTextRenderer::preparePath(RPainterPath &path, const RColor &color, double cursor, double cxfScale)

private

void RTextRenderer::preparePathColor(RPainterPath &path, const RColor &color)

private

void RTextRenderer::preparePathTransform(RPainterPath &path, double cursor, double cxfScale)

private

void RTextRenderer::setBlockBold(bool on)

inline private

void RTextRenderer::setBlockFont(const QString &f)

inline private

void RTextRenderer::setBlockFontFile(const QString &f)

inline private

void RTextRenderer::setBlockHeight(double h)

inline private

void RTextRenderer::setBlockItalic(bool on)

inline private

void RTextRenderer::setBlockUnderline(bool on)

inline private

void RTextRenderer::setCurrentFormat(QTextCharFormat f)

inline private

void RTextRenderer::setUseCadFont(bool on)

inline private

QStack<bool> RTextRenderer::blockBold

private

QStack<QString> RTextRenderer::blockFont

private

QStack<QString> RTextRenderer::blockFontFile

private

QStack<double> RTextRenderer::blockHeight

private

QStack<bool> RTextRenderer::blockItalic

private

QStack<bool> RTextRenderer::blockUnderline

private

RBox RTextRenderer::boundingBox

private

QStack<QTextCharFormat> RTextRenderer::currentFormat

private

bool RTextRenderer::draft

private

double RTextRenderer::fontHeightFactor

private

double RTextRenderer::height

private

QList<QTransform> RTextRenderer::lineBlockTransforms

private

QStack<QStringList> RTextRenderer::openTags

private

QList<RPainterPath> RTextRenderer::painterPaths

private

QString RTextRenderer::richText

private

Target RTextRenderer::target

private

const RTextBasedData& RTextRenderer::textData

private

QList<RTextLayout> RTextRenderer::textLayouts

private

QStack<bool> RTextRenderer::useCadFont

private

double RTextRenderer::width

private

static QMutex RTextRenderer::m

static private