|
Krita Source Code Documentation
|
#include <KoSvgTextShapeMarkupConverter.h>
Classes | |
| struct | ExtraStyles |
| struct | Private |
Public Types | |
| enum class | WrappingMode { QtLegacy = 0 , WhiteSpacePre , WhiteSpacePreWrap } |
Public Member Functions | |
| bool | convertDocumentToSvg (const QTextDocument *doc, QString *svgText) |
| convertDocumentToSvg | |
| bool | convertFromHtml (const QString &htmlText, QString *svgText, QString *styles) |
| convertFromHtml converted Qt rich text html (and no other: https://doc.qt.io/qt-5/richtext-html-subset.html) to SVG | |
| bool | convertFromSvg (const QString &svgText, const QString &stylesText, const QRectF &boundsInPixels, qreal pixelsPerInch) |
| upload the svg representation of text into the shape | |
| bool | convertSvgToDocument (const QString &svgText, QTextDocument *doc) |
| convertSvgToDocument | |
| bool | convertToHtml (QString *htmlText) |
| convertToHtml convert the text in the text shape to html | |
| bool | convertToSvg (QString *svgText, QString *stylesText) |
| QStringList | errors () const |
| QTextFormat | formatDifference (QTextFormat test, QTextFormat reference) |
| formatDifference A class to get the difference between two text-char formats. | |
| KoSvgTextShapeMarkupConverter (KoSvgTextShape *shape) | |
| QString | style (QTextCharFormat format, QTextBlockFormat blockFormat, QTextCharFormat mostCommon=QTextCharFormat(), bool includeLineHeight=false) |
| style creates a style string based on the blockformat and the format. | |
| QStringList | warnings () const |
| ~KoSvgTextShapeMarkupConverter () | |
Static Public Member Functions | |
| static std::optional< double > | getInlineSize (const QTextFrameFormat &frameFormat) |
| Get the inline-size from the frameFormat of the rootFrame of a QTextDocument. | |
| static WrappingMode | getWrappingMode (const QTextFrameFormat &frameFormat) |
| Get the Wrapping Mode from the frameFormat of the rootFrame of a QTextDocument. | |
| static void | setInlineSize (QTextFrameFormat *frameFormat, double inlineSize) |
| Set or unset the inline-size on a frameFormat to be applied to the rootFrame of a QTextDocument. | |
| static void | setWrappingMode (QTextFrameFormat *frameFormat, WrappingMode wrappingMode) |
| Set the Wrapping Mode on a frame format to be applied to the rootFrame of a QTextDocument. | |
| static QVector< QTextFormat > | stylesFromString (QStringList styles, QTextCharFormat currentCharFormat, QTextBlockFormat currentBlockFormat, ExtraStyles &extraStyles) |
| stylesFromString returns a qvector with two textformats: at 0 is the QTextCharFormat at 1 is the QTextBlockFormat | |
Static Public Attributes | |
| static constexpr QTextFormat::Property | InlineSizeProperty |
| static constexpr QTextFormat::Property | WrappingModeProperty |
Private Attributes | |
| const QScopedPointer< Private > | d |
KoSvgTextShapeMarkupConverter is a utility class for converting a KoSvgTextShape to/from user-editable markup/svg representation.
Please note that the converted SVG is not the same as when saved into .kra! Some attributes are dropped to make the editing is easier for the user.
Definition at line 31 of file KoSvgTextShapeMarkupConverter.h.
|
strong |
The wrapping mode for the conversion between QTextDocument and SVG.
Definition at line 147 of file KoSvgTextShapeMarkupConverter.h.
| KoSvgTextShapeMarkupConverter::KoSvgTextShapeMarkupConverter | ( | KoSvgTextShape * | shape | ) |
Definition at line 71 of file KoSvgTextShapeMarkupConverter.cpp.
| KoSvgTextShapeMarkupConverter::~KoSvgTextShapeMarkupConverter | ( | ) |
Definition at line 76 of file KoSvgTextShapeMarkupConverter.cpp.
| bool KoSvgTextShapeMarkupConverter::convertDocumentToSvg | ( | const QTextDocument * | doc, |
| QString * | svgText ) |
convertDocumentToSvg
| doc | the QTextDocument to convert. |
| svgText | the converted svg text element |
true if the conversion was successful DIRTY-DIRTY-DIRTY HACK ALERT!!!
All the internals of QTextDocument work with the primary screen's DPI. That is, when we ask Qt about font metrics, it returns values scaled to the pixels in the current screen, that is, ptValue * qt_defaultDpi() / 72.0. We need to convert this value back into points before writing as SVG. Therefore, all the metrics returned by the document are scaled with fixQtDpi().
Official Qt's way to workaround this problem is to set logicalDpiX/Y() values on the paint device's associated with the document. But it seems like in our version of Qt (5.12.12, which is rather old) it doesn't work properly.
The alignment rule will be inverted while rendering the text in the text shape (according to the standard the alignment is defined not by "left" or "right", but by "start" and "end", which inverts for rtl text)
Definition at line 576 of file KoSvgTextShapeMarkupConverter.cpp.
References calcLineWidth(), d, findMostCommonFormat(), fixFromQtDpi(), formatDifference(), getInlineSize(), getWrappingMode(), guessIsRightToLeft(), length(), QtLegacy, style(), KisDomUtils::toString(), and WhiteSpacePreWrap.
| bool KoSvgTextShapeMarkupConverter::convertFromHtml | ( | const QString & | htmlText, |
| QString * | svgText, | ||
| QString * | styles ) |
convertFromHtml converted Qt rich text html (and no other: https://doc.qt.io/qt-5/richtext-html-subset.html) to SVG
| htmlText | the input html |
| svgText | the converted svg text element |
| styles |
true if the conversion was successful Definition at line 196 of file KoSvgTextShapeMarkupConverter.cpp.
References d, debugFlake, p, and style().
| bool KoSvgTextShapeMarkupConverter::convertFromSvg | ( | const QString & | svgText, |
| const QString & | stylesText, | ||
| const QRectF & | boundsInPixels, | ||
| qreal | pixelsPerInch ) |
upload the svg representation of text into the shape
| svgText | <text> part of SVG |
| stylesText | <defs> part of SVG (used only for gradients and patterns) |
| boundsInPixels | bounds of the entire image in pixel. Used for parsing percentage units. |
| pixelsPerInch | resolution of the image where we load the shape to |
errors() and warnings() for details. Definition at line 111 of file KoSvgTextShapeMarkupConverter.cpp.
References SvgParser::createDocumentFromSvg(), d, debugFlake, KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, SvgParser::parseDefsElement(), SvgParser::parseTextElement(), and SvgParser::setResolution().
| bool KoSvgTextShapeMarkupConverter::convertSvgToDocument | ( | const QString & | svgText, |
| QTextDocument * | doc ) |
convertSvgToDocument
| svgText | the <text> element and it's children as a string. |
| doc | the QTextDocument that the conversion is written to. |
true if the conversion was successful Definition at line 908 of file KoSvgTextShapeMarkupConverter.cpp.
References d, fixToQtDpi(), KIS_SAFE_ASSERT_RECOVER, KIS_SAFE_ASSERT_RECOVER_NOOP, KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, parseTextAttributes(), postCorrectBlockHeight(), qFuzzyCompare(), QtLegacy, setInlineSize(), setWrappingMode(), KisDomUtils::toDouble(), WhiteSpacePre, and WhiteSpacePreWrap.
| bool KoSvgTextShapeMarkupConverter::convertToHtml | ( | QString * | htmlText | ) |
convertToHtml convert the text in the text shape to html
| htmlText | will be filled with correct html representing the text in the shape |
true on success Definition at line 172 of file KoSvgTextShapeMarkupConverter.cpp.
References d, debugFlake, and HtmlWriter::errors().
| bool KoSvgTextShapeMarkupConverter::convertToSvg | ( | QString * | svgText, |
| QString * | stylesText ) |
Convert the text shape into two strings: text and styles. Styles string is non-empty only when the text has some gradient/pattern attached. It is intended to be places into a separate tab in the GUI.
Definition at line 85 of file KoSvgTextShapeMarkupConverter.cpp.
References d, SvgWriter::saveDetached(), and SvgSavingContext::setStrippedTextMode().
| QStringList KoSvgTextShapeMarkupConverter::errors | ( | ) | const |
A list of errors happened during loading the user's text
Definition at line 1121 of file KoSvgTextShapeMarkupConverter.cpp.
References d.
| QTextFormat KoSvgTextShapeMarkupConverter::formatDifference | ( | QTextFormat | test, |
| QTextFormat | reference ) |
formatDifference A class to get the difference between two text-char formats.
| test | the format to test |
| reference | the format to test against. |
Definition at line 1679 of file KoSvgTextShapeMarkupConverter.cpp.
|
static |
Get the inline-size from the frameFormat of the rootFrame of a QTextDocument.
| frameFormat |
Definition at line 1715 of file KoSvgTextShapeMarkupConverter.cpp.
References InlineSizeProperty.
|
static |
Get the Wrapping Mode from the frameFormat of the rootFrame of a QTextDocument.
| frameFormat |
Definition at line 1701 of file KoSvgTextShapeMarkupConverter.cpp.
References QtLegacy, and WrappingModeProperty.
|
static |
Set or unset the inline-size on a frameFormat to be applied to the rootFrame of a QTextDocument.
| frameFormat | pointer to the frameFormat to be modified |
| inlineSize | the inline-size; pass a negative value to unset the property |
Definition at line 1728 of file KoSvgTextShapeMarkupConverter.cpp.
References InlineSizeProperty.
|
static |
Set the Wrapping Mode on a frame format to be applied to the rootFrame of a QTextDocument.
| frameFormat | pointer to the franeFormat to be modified |
| wrappingMode |
Definition at line 1710 of file KoSvgTextShapeMarkupConverter.cpp.
References WrappingModeProperty.
| QString KoSvgTextShapeMarkupConverter::style | ( | QTextCharFormat | format, |
| QTextBlockFormat | blockFormat, | ||
| QTextCharFormat | mostCommon = QTextCharFormat(), | ||
| bool | includeLineHeight = false ) |
style creates a style string based on the blockformat and the format.
| format | the textCharFormat of the current text. |
| blockFormat | the block format of the current text. |
| mostCommon | the most common format to compare the format to. |
| includeLineHeight | whether the style should include line-height. |
Definition at line 1174 of file KoSvgTextShapeMarkupConverter.cpp.
References compareFormatUnderlineWithMostCommon(), convertFormatUnderlineToSvg(), style(), and warnFile.
|
static |
stylesFromString returns a qvector with two textformats: at 0 is the QTextCharFormat at 1 is the QTextBlockFormat
| styles | a style string split at ";" | |
| currentCharFormat | the current charformat to compare against. | |
| currentBlockFormat | the current blockformat to compare against. | |
| [out] | extraStyles | other styles. |
Definition at line 1398 of file KoSvgTextShapeMarkupConverter.cpp.
References KoSvgTextProperties::defaultProperties(), SvgUtil::fromPercentage(), KoSvgTextShapeMarkupConverter::ExtraStyles::inlineSize, SvgUtil::parseUnitX(), QtLegacy, style(), value(), warnFile, WhiteSpacePre, WhiteSpacePreWrap, and KoSvgTextShapeMarkupConverter::ExtraStyles::wrappingMode.
| QStringList KoSvgTextShapeMarkupConverter::warnings | ( | ) | const |
A list of warnings produced during loading the user's text
Definition at line 1126 of file KoSvgTextShapeMarkupConverter.cpp.
References d.
|
private |
Definition at line 135 of file KoSvgTextShapeMarkupConverter.h.
|
staticconstexpr |
Definition at line 166 of file KoSvgTextShapeMarkupConverter.h.
|
staticconstexpr |
Definition at line 164 of file KoSvgTextShapeMarkupConverter.h.