Krita Source Code Documentation
Loading...
Searching...
No Matches
CharacterResult Struct Reference

#include <KoSvgTextShape_p.h>

Public Member Functions

void calculateAndApplyTabsize (QPointF currentPos, bool isHorizontal, const KoSvgText::ResolutionHandler &resHandler)
 
QTransform finalTransform () const
 
QRectF layoutBox () const
 layoutBox
 
QRectF lineHeightBox () const
 lineHeightBox
 
void scaleCharacterResult (qreal xScale, qreal yScale)
 scaleCharacterResult convenience function to scale the whole character result.
 
QPointF totalBaselineOffset () const
 
void translateOrigin (QPointF newOrigin)
 translateOrigin For dominant baseline, we want to move the glyph origin. This encompassed the glyph, the ascent and descent, and the metrics.
 

Public Attributes

bool addressable = true
 
QPointF advance
 
KoSvgText::TextAnchor anchor = KoSvgText::AnchorStart
 
bool anchored_chunk = false
 whether this is the start of a new chunk.
 
QPointF baselineOffset = QPointF()
 
BreakType breakType = BreakType::NoBreak
 
QPointF cssPosition = QPointF()
 the position in accordance with the CSS specs, as opossed to the SVG spec.
 
CursorInfo cursorInfo
 
KoSvgText::Direction direction = KoSvgText::DirectionLeftToRight
 
QPointF dominantBaselineOffset = QPointF()
 
qreal extraFontScaling = 1.0
 Freetype doesn't allow us to scale below 1pt, so we need to do an extra transformation in these cases.
 
QPointF finalPosition
 the final position, taking into account both CSS and SVG positioning considerations.
 
qreal fontHalfLeading
 Leading for both sides, can be either negative or positive.
 
QFont::Style fontStyle = QFont::StyleNormal
 
int fontWeight = 400
 
Glyph::Variant glyph
 
bool hidden = false
 
QRectF inkBoundingBox
 The bounds of the drawn glyph. Different from the bounds the charresult takes up in the layout,.
 
bool isHanging = false
 
bool isHorizontal = true
 Whether the current glyph lays out horizontal or vertical. Currently same as paragraph, but in future may change.
 
bool justifyAfter = false
 Justification Opportunity follows this character.
 
bool justifyBefore = false
 Justification Opportunity precedes this character.
 
LineEdgeBehaviour lineEnd = LineEdgeBehaviour::NoChange
 
LineEdgeBehaviour lineStart = LineEdgeBehaviour::NoChange
 
KoSvgText::FontMetrics metrics
 Fontmetrics for current font, in Freetype scanline coordinates.
 
bool middle = false
 
bool overflowWrap = false
 
int plaintTextIndex = -1
 
qreal rotate = 0.0
 
qreal scaledAscent {}
 Ascender, in pt.
 
qreal scaledDescent {}
 Descender, in pt.
 
qreal scaledHalfLeading {}
 Leading for both sides, can be either negative or positive, in pt.
 
std::optional< qreal > tabSize
 If present, this is a tab and it should align to multiples of this tabSize value.
 
bool textLengthApplied = false
 
QPointF textLengthOffset = QPointF()
 offset caused by textLength
 
QPointF textPathAndAnchoringOffset = QPointF()
 Offset caused by textPath and anchoring.
 
int visualIndex = -1
 

Detailed Description

Definition at line 93 of file KoSvgTextShape_p.h.

Member Function Documentation

◆ calculateAndApplyTabsize()

void CharacterResult::calculateAndApplyTabsize ( QPointF currentPos,
bool isHorizontal,
const KoSvgText::ResolutionHandler & resHandler )
inline

Definition at line 138 of file KoSvgTextShape_p.h.

138 {
139 if (!tabSize) return;
140 if (*tabSize == qInf() || qIsNaN(*tabSize)) return;
141
142 if (*tabSize > 0) {
143 qreal remainder = *tabSize - (isHorizontal? fmod(currentPos.x(), *tabSize): fmod(currentPos.y(), *tabSize));
144 advance = resHandler.adjust(isHorizontal? QPointF(remainder, advance.y()): QPointF(advance.x(), remainder));
145 }
146 }
std::optional< qreal > tabSize
If present, this is a tab and it should align to multiples of this tabSize value.
bool isHorizontal
Whether the current glyph lays out horizontal or vertical. Currently same as paragraph,...
QPointF adjust(const QPointF point) const
Adjusts the point to rounded pixel values, based on whether roundToPixelHorizontal or roundToPixelVer...

References KoSvgText::ResolutionHandler::adjust(), advance, isHorizontal, and tabSize.

◆ finalTransform()

QTransform CharacterResult::finalTransform ( ) const
inline

Definition at line 271 of file KoSvgTextShape_p.h.

271 {
272 QTransform tf =
273 QTransform::fromTranslate(finalPosition.x(), finalPosition.y());
274 tf.rotateRadians(rotate);
275 return tf;
276 }
QPointF finalPosition
the final position, taking into account both CSS and SVG positioning considerations.

References finalPosition, and rotate.

◆ layoutBox()

QRectF CharacterResult::layoutBox ( ) const
inline

layoutBox

Returns
a dynamically calculated layoutBox, this is different from the Ink bounding box.

Definition at line 152 of file KoSvgTextShape_p.h.

152 {
155 }
qreal scaledDescent
Descender, in pt.
qreal scaledAscent
Ascender, in pt.

References advance, isHorizontal, scaledAscent, and scaledDescent.

◆ lineHeightBox()

QRectF CharacterResult::lineHeightBox ( ) const
inline

lineHeightBox

Returns
The box representing the line height of this char.

Definition at line 160 of file KoSvgTextShape_p.h.

160 {
161 QRectF lBox = layoutBox();
162 return isHorizontal? lBox.adjusted(0, -scaledHalfLeading, 0, scaledHalfLeading)
163 : lBox.adjusted(-scaledHalfLeading, 0, scaledHalfLeading, 0);
164 }
qreal scaledHalfLeading
Leading for both sides, can be either negative or positive, in pt.
QRectF layoutBox() const
layoutBox

References isHorizontal, layoutBox(), and scaledHalfLeading.

◆ scaleCharacterResult()

void CharacterResult::scaleCharacterResult ( qreal xScale,
qreal yScale )
inline

scaleCharacterResult convenience function to scale the whole character result.

Parameters
xScale– the factor by which the width should be scaled.
yScale– the factor by which the height should be scaled.

Definition at line 202 of file KoSvgTextShape_p.h.

202 {
203 QTransform scale = QTransform::fromScale(xScale, yScale);
204 if (scale.isIdentity()) return;
205 const bool scaleToZero = !(xScale > 0 && yScale > 0);
206
207 if (Glyph::Outline *outlineGlyph = std::get_if<Glyph::Outline>(&glyph)) {
208 if (!outlineGlyph->path.isEmpty()) {
209 if (scaleToZero) {
210 outlineGlyph->path = QPainterPath();
211 } else {
212 outlineGlyph->path = scale.map(outlineGlyph->path);
213 }
214 }
215 } else if (Glyph::Bitmap *bitmapGlyph = std::get_if<Glyph::Bitmap>(&glyph)) {
216 if (scaleToZero) {
217 bitmapGlyph->drawRects.clear();
218 bitmapGlyph->images.clear();
219 } else {
220 for (int i = 0; i< bitmapGlyph->drawRects.size(); i++) {
221 bitmapGlyph->drawRects[i] = scale.mapRect(bitmapGlyph->drawRects[i]);
222 }
223 }
224 } else if (Glyph::ColorLayers *colorGlyph = std::get_if<Glyph::ColorLayers>(&glyph)) {
225 for (int i = 0; i< colorGlyph->paths.size(); i++) {
226 if (scaleToZero) {
227 colorGlyph->paths[i] = QPainterPath();
228 } else {
229 colorGlyph->paths[i] = scale.map(colorGlyph->paths[i]);
230 }
231 }
232 }
233 advance = scale.map(advance);
235 for (int i = 0; i < cursorInfo.offsets.size(); i++) {
236 cursorInfo.offsets[i] = scale.map(cursorInfo.offsets.at(i));
237 }
239
240 if (isHorizontal) {
241 scaledDescent *= yScale;
242 scaledAscent *= yScale;
243 scaledHalfLeading *= yScale;
244 metrics.scaleBaselines(yScale);
245 if (tabSize) {
246 tabSize = scale.map(QPointF(*tabSize, *tabSize)).x();
247 }
248 } else {
249 scaledDescent *= xScale;
250 scaledAscent *= xScale;
251 scaledHalfLeading *= xScale;
252 metrics.scaleBaselines(xScale);
253 if (tabSize) {
254 tabSize = scale.map(QPointF(*tabSize, *tabSize)).y();
255 }
256 }
257 }
QRectF inkBoundingBox
The bounds of the drawn glyph. Different from the bounds the charresult takes up in the layout,...
Glyph::Variant glyph
KoSvgText::FontMetrics metrics
Fontmetrics for current font, in Freetype scanline coordinates.
QLineF caret
Caret for this characterResult.
QVector< QPointF > offsets
The advance offsets for each grapheme index.
void scaleBaselines(const qreal multiplier)

References advance, CursorInfo::caret, cursorInfo, glyph, inkBoundingBox, isHorizontal, metrics, CursorInfo::offsets, KoSvgText::FontMetrics::scaleBaselines(), scaledAscent, scaledDescent, scaledHalfLeading, and tabSize.

◆ totalBaselineOffset()

QPointF CharacterResult::totalBaselineOffset ( ) const
inline

Definition at line 259 of file KoSvgTextShape_p.h.

259 {
261 }
QPointF dominantBaselineOffset

References baselineOffset, and dominantBaselineOffset.

◆ translateOrigin()

void CharacterResult::translateOrigin ( QPointF newOrigin)
inline

translateOrigin For dominant baseline, we want to move the glyph origin. This encompassed the glyph, the ascent and descent, and the metrics.

Definition at line 171 of file KoSvgTextShape_p.h.

171 {
172 if (newOrigin == QPointF()) return;
173 if (Glyph::Outline *outlineGlyph = std::get_if<Glyph::Outline>(&glyph)) {
174 outlineGlyph->path.translate(-newOrigin);
175 } else if (Glyph::Bitmap *bitmapGlyph = std::get_if<Glyph::Bitmap>(&glyph)) {
176 for (int i = 0; i< bitmapGlyph->drawRects.size(); i++) {
177 bitmapGlyph->drawRects[i].translate(-newOrigin);
178 }
179 } else if (Glyph::ColorLayers *colorGlyph = std::get_if<Glyph::ColorLayers>(&glyph)) {
180 for (int i = 0; i< colorGlyph->paths.size(); i++) {
181 colorGlyph->paths[i].translate(-newOrigin);
182 }
183 }
184 cursorInfo.caret.translate(-newOrigin);
185 inkBoundingBox.translate(-newOrigin);
186
187 if (isHorizontal) {
188 scaledDescent -= newOrigin.y();
189 scaledAscent -= newOrigin.y();
190 } else {
191 scaledDescent -= newOrigin.x();
192 scaledAscent -= newOrigin.x();
193 }
194 }

References CursorInfo::caret, cursorInfo, glyph, inkBoundingBox, isHorizontal, scaledAscent, and scaledDescent.

Member Data Documentation

◆ addressable

bool CharacterResult::addressable = true

whether the character is not discarded for various reasons, this is necessary for determining to which index a given x/y transform is applied, and in this code we also use it to determine if a character is considered for line-breaking.

Definition at line 100 of file KoSvgTextShape_p.h.

◆ advance

QPointF CharacterResult::advance

Definition at line 119 of file KoSvgTextShape_p.h.

◆ anchor

KoSvgText::TextAnchor CharacterResult::anchor = KoSvgText::AnchorStart

Definition at line 268 of file KoSvgTextShape_p.h.

◆ anchored_chunk

bool CharacterResult::anchored_chunk = false

whether this is the start of a new chunk.

Definition at line 105 of file KoSvgTextShape_p.h.

◆ baselineOffset

QPointF CharacterResult::baselineOffset = QPointF()

The computed baseline offset, will be applied when calculating the line-offset during line breaking.

Definition at line 117 of file KoSvgTextShape_p.h.

◆ breakType

BreakType CharacterResult::breakType = BreakType::NoBreak

Definition at line 120 of file KoSvgTextShape_p.h.

◆ cssPosition

QPointF CharacterResult::cssPosition = QPointF()

the position in accordance with the CSS specs, as opossed to the SVG spec.

Definition at line 113 of file KoSvgTextShape_p.h.

◆ cursorInfo

CursorInfo CharacterResult::cursorInfo

Definition at line 266 of file KoSvgTextShape_p.h.

◆ direction

Definition at line 269 of file KoSvgTextShape_p.h.

◆ dominantBaselineOffset

QPointF CharacterResult::dominantBaselineOffset = QPointF()

Definition at line 116 of file KoSvgTextShape_p.h.

◆ extraFontScaling

qreal CharacterResult::extraFontScaling = 1.0

Freetype doesn't allow us to scale below 1pt, so we need to do an extra transformation in these cases.

Definition at line 129 of file KoSvgTextShape_p.h.

◆ finalPosition

QPointF CharacterResult::finalPosition

the final position, taking into account both CSS and SVG positioning considerations.

Definition at line 94 of file KoSvgTextShape_p.h.

◆ fontHalfLeading

qreal CharacterResult::fontHalfLeading

Leading for both sides, can be either negative or positive.

Definition at line 130 of file KoSvgTextShape_p.h.

◆ fontStyle

QFont::Style CharacterResult::fontStyle = QFont::StyleNormal

Definition at line 263 of file KoSvgTextShape_p.h.

◆ fontWeight

int CharacterResult::fontWeight = 400

Definition at line 264 of file KoSvgTextShape_p.h.

◆ glyph

Glyph::Variant CharacterResult::glyph

Definition at line 107 of file KoSvgTextShape_p.h.

◆ hidden

bool CharacterResult::hidden = false

Definition at line 96 of file KoSvgTextShape_p.h.

◆ inkBoundingBox

QRectF CharacterResult::inkBoundingBox

The bounds of the drawn glyph. Different from the bounds the charresult takes up in the layout,.

See also
layoutBox();

Definition at line 109 of file KoSvgTextShape_p.h.

◆ isHanging

bool CharacterResult::isHanging = false

Definition at line 125 of file KoSvgTextShape_p.h.

◆ isHorizontal

bool CharacterResult::isHorizontal = true

Whether the current glyph lays out horizontal or vertical. Currently same as paragraph, but in future may change.

Definition at line 110 of file KoSvgTextShape_p.h.

◆ justifyAfter

bool CharacterResult::justifyAfter = false

Justification Opportunity follows this character.

Definition at line 124 of file KoSvgTextShape_p.h.

◆ justifyBefore

bool CharacterResult::justifyBefore = false

Justification Opportunity precedes this character.

Definition at line 123 of file KoSvgTextShape_p.h.

◆ lineEnd

LineEdgeBehaviour CharacterResult::lineEnd = LineEdgeBehaviour::NoChange

Definition at line 121 of file KoSvgTextShape_p.h.

◆ lineStart

LineEdgeBehaviour CharacterResult::lineStart = LineEdgeBehaviour::NoChange

Definition at line 122 of file KoSvgTextShape_p.h.

◆ metrics

KoSvgText::FontMetrics CharacterResult::metrics

Fontmetrics for current font, in Freetype scanline coordinates.

Definition at line 131 of file KoSvgTextShape_p.h.

◆ middle

bool CharacterResult::middle = false

whether the character is the second of last of a typographic character.

Definition at line 103 of file KoSvgTextShape_p.h.

◆ overflowWrap

bool CharacterResult::overflowWrap = false

Definition at line 127 of file KoSvgTextShape_p.h.

◆ plaintTextIndex

int CharacterResult::plaintTextIndex = -1

Definition at line 112 of file KoSvgTextShape_p.h.

◆ rotate

qreal CharacterResult::rotate = 0.0

Definition at line 95 of file KoSvgTextShape_p.h.

◆ scaledAscent

qreal CharacterResult::scaledAscent {}

Ascender, in pt.

Definition at line 133 of file KoSvgTextShape_p.h.

133{};

◆ scaledDescent

qreal CharacterResult::scaledDescent {}

Descender, in pt.

Definition at line 134 of file KoSvgTextShape_p.h.

134{};

◆ scaledHalfLeading

qreal CharacterResult::scaledHalfLeading {}

Leading for both sides, can be either negative or positive, in pt.

Definition at line 132 of file KoSvgTextShape_p.h.

132{};

◆ tabSize

std::optional<qreal> CharacterResult::tabSize

If present, this is a tab and it should align to multiples of this tabSize value.

Definition at line 136 of file KoSvgTextShape_p.h.

◆ textLengthApplied

bool CharacterResult::textLengthApplied = false

Definition at line 126 of file KoSvgTextShape_p.h.

◆ textLengthOffset

QPointF CharacterResult::textLengthOffset = QPointF()

offset caused by textLength

Definition at line 114 of file KoSvgTextShape_p.h.

◆ textPathAndAnchoringOffset

QPointF CharacterResult::textPathAndAnchoringOffset = QPointF()

Offset caused by textPath and anchoring.

Definition at line 115 of file KoSvgTextShape_p.h.

◆ visualIndex

int CharacterResult::visualIndex = -1

Definition at line 111 of file KoSvgTextShape_p.h.


The documentation for this struct was generated from the following file: