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
 
int visualIndex = -1
 

Detailed Description

Definition at line 90 of file KoSvgTextShape_p.h.

Member Function Documentation

◆ calculateAndApplyTabsize()

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

Definition at line 133 of file KoSvgTextShape_p.h.

133 {
134 if (!tabSize) return;
135 if (*tabSize == qInf() || qIsNaN(*tabSize)) return;
136
137 if (*tabSize > 0) {
138 qreal remainder = *tabSize - (isHorizontal? fmod(currentPos.x(), *tabSize): fmod(currentPos.y(), *tabSize));
139 advance = resHandler.adjust(isHorizontal? QPointF(remainder, advance.y()): QPointF(advance.x(), remainder));
140 }
141 }
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 266 of file KoSvgTextShape_p.h.

266 {
267 QTransform tf =
268 QTransform::fromTranslate(finalPosition.x(), finalPosition.y());
269 tf.rotateRadians(rotate);
270 return tf;
271 }
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 147 of file KoSvgTextShape_p.h.

147 {
150 }
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 155 of file KoSvgTextShape_p.h.

155 {
156 QRectF lBox = layoutBox();
157 return isHorizontal? lBox.adjusted(0, -scaledHalfLeading, 0, scaledHalfLeading)
158 : lBox.adjusted(-scaledHalfLeading, 0, scaledHalfLeading, 0);
159 }
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 197 of file KoSvgTextShape_p.h.

197 {
198 QTransform scale = QTransform::fromScale(xScale, yScale);
199 if (scale.isIdentity()) return;
200 const bool scaleToZero = !(xScale > 0 && yScale > 0);
201
202 if (Glyph::Outline *outlineGlyph = std::get_if<Glyph::Outline>(&glyph)) {
203 if (!outlineGlyph->path.isEmpty()) {
204 if (scaleToZero) {
205 outlineGlyph->path = QPainterPath();
206 } else {
207 outlineGlyph->path = scale.map(outlineGlyph->path);
208 }
209 }
210 } else if (Glyph::Bitmap *bitmapGlyph = std::get_if<Glyph::Bitmap>(&glyph)) {
211 if (scaleToZero) {
212 bitmapGlyph->drawRects.clear();
213 bitmapGlyph->images.clear();
214 } else {
215 for (int i = 0; i< bitmapGlyph->drawRects.size(); i++) {
216 bitmapGlyph->drawRects[i] = scale.mapRect(bitmapGlyph->drawRects[i]);
217 }
218 }
219 } else if (Glyph::ColorLayers *colorGlyph = std::get_if<Glyph::ColorLayers>(&glyph)) {
220 for (int i = 0; i< colorGlyph->paths.size(); i++) {
221 if (scaleToZero) {
222 colorGlyph->paths[i] = QPainterPath();
223 } else {
224 colorGlyph->paths[i] = scale.map(colorGlyph->paths[i]);
225 }
226 }
227 }
228 advance = scale.map(advance);
230 for (int i = 0; i < cursorInfo.offsets.size(); i++) {
231 cursorInfo.offsets[i] = scale.map(cursorInfo.offsets.at(i));
232 }
234
235 if (isHorizontal) {
236 scaledDescent *= yScale;
237 scaledAscent *= yScale;
238 scaledHalfLeading *= yScale;
239 metrics.scaleBaselines(yScale);
240 if (tabSize) {
241 tabSize = scale.map(QPointF(*tabSize, *tabSize)).x();
242 }
243 } else {
244 scaledDescent *= xScale;
245 scaledAscent *= xScale;
246 scaledHalfLeading *= xScale;
247 metrics.scaleBaselines(xScale);
248 if (tabSize) {
249 tabSize = scale.map(QPointF(*tabSize, *tabSize)).y();
250 }
251 }
252 }
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 254 of file KoSvgTextShape_p.h.

254 {
256 }
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 166 of file KoSvgTextShape_p.h.

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

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 97 of file KoSvgTextShape_p.h.

◆ advance

QPointF CharacterResult::advance

Definition at line 114 of file KoSvgTextShape_p.h.

◆ anchor

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

Definition at line 263 of file KoSvgTextShape_p.h.

◆ anchored_chunk

bool CharacterResult::anchored_chunk = false

whether this is the start of a new chunk.

Definition at line 102 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 112 of file KoSvgTextShape_p.h.

◆ breakType

BreakType CharacterResult::breakType = BreakType::NoBreak

Definition at line 115 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 110 of file KoSvgTextShape_p.h.

◆ cursorInfo

CursorInfo CharacterResult::cursorInfo

Definition at line 261 of file KoSvgTextShape_p.h.

◆ direction

Definition at line 264 of file KoSvgTextShape_p.h.

◆ dominantBaselineOffset

QPointF CharacterResult::dominantBaselineOffset = QPointF()

Definition at line 111 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 124 of file KoSvgTextShape_p.h.

◆ finalPosition

QPointF CharacterResult::finalPosition

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

Definition at line 91 of file KoSvgTextShape_p.h.

◆ fontHalfLeading

qreal CharacterResult::fontHalfLeading

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

Definition at line 125 of file KoSvgTextShape_p.h.

◆ fontStyle

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

Definition at line 258 of file KoSvgTextShape_p.h.

◆ fontWeight

int CharacterResult::fontWeight = 400

Definition at line 259 of file KoSvgTextShape_p.h.

◆ glyph

Glyph::Variant CharacterResult::glyph

Definition at line 104 of file KoSvgTextShape_p.h.

◆ hidden

bool CharacterResult::hidden = false

Definition at line 93 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 106 of file KoSvgTextShape_p.h.

◆ isHanging

bool CharacterResult::isHanging = false

Definition at line 120 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 107 of file KoSvgTextShape_p.h.

◆ justifyAfter

bool CharacterResult::justifyAfter = false

Justification Opportunity follows this character.

Definition at line 119 of file KoSvgTextShape_p.h.

◆ justifyBefore

bool CharacterResult::justifyBefore = false

Justification Opportunity precedes this character.

Definition at line 118 of file KoSvgTextShape_p.h.

◆ lineEnd

LineEdgeBehaviour CharacterResult::lineEnd = LineEdgeBehaviour::NoChange

Definition at line 116 of file KoSvgTextShape_p.h.

◆ lineStart

LineEdgeBehaviour CharacterResult::lineStart = LineEdgeBehaviour::NoChange

Definition at line 117 of file KoSvgTextShape_p.h.

◆ metrics

KoSvgText::FontMetrics CharacterResult::metrics

Fontmetrics for current font, in Freetype scanline coordinates.

Definition at line 126 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 100 of file KoSvgTextShape_p.h.

◆ overflowWrap

bool CharacterResult::overflowWrap = false

Definition at line 122 of file KoSvgTextShape_p.h.

◆ plaintTextIndex

int CharacterResult::plaintTextIndex = -1

Definition at line 109 of file KoSvgTextShape_p.h.

◆ rotate

qreal CharacterResult::rotate = 0.0

Definition at line 92 of file KoSvgTextShape_p.h.

◆ scaledAscent

qreal CharacterResult::scaledAscent {}

Ascender, in pt.

Definition at line 128 of file KoSvgTextShape_p.h.

128{};

◆ scaledDescent

qreal CharacterResult::scaledDescent {}

Descender, in pt.

Definition at line 129 of file KoSvgTextShape_p.h.

129{};

◆ scaledHalfLeading

qreal CharacterResult::scaledHalfLeading {}

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

Definition at line 127 of file KoSvgTextShape_p.h.

127{};

◆ 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 131 of file KoSvgTextShape_p.h.

◆ textLengthApplied

bool CharacterResult::textLengthApplied = false

Definition at line 121 of file KoSvgTextShape_p.h.

◆ visualIndex

int CharacterResult::visualIndex = -1

Definition at line 108 of file KoSvgTextShape_p.h.


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