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

The LineBox struct. More...

#include <KoSvgTextShape_p.h>

Public Member Functions

LineChunk chunk ()
 
void clearAndAdjust (bool isHorizontal, QPointF current, QPointF indent)
 
bool isEmpty ()
 
 LineBox ()
 
 LineBox (QPointF start, QPointF end, const KoSvgText::ResolutionHandler &resHandler)
 
 LineBox (QVector< QLineF > lineWidths, bool ltr, QPointF indent, const KoSvgText::ResolutionHandler &resHandler)
 
void setCurrentChunk (LineChunk chunk)
 
void setCurrentChunkForPos (QPointF pos, bool isHorizontal)
 

Public Attributes

qreal actualLineBottom = 0
 
qreal actualLineTop = 0
 
QPointF baselineBottom = QPointF()
 Used to identify the bottom of the line for baseline-alignment.
 
QPointF baselineTop = QPointF()
 Used to identify the top of the line for baseline-alignment.
 
QVector< LineChunkchunks
 
int currentChunk = -1
 
qreal expectedLineTop = 0
 Because fonts can affect lineheight mid-line, and this affects wrapping, this estimates the line-height.
 
bool firstLine = false
 
bool justifyLine = false
 
bool lastLine = false
 
bool lineFinalized = false
 
QPointF textIndent = QPointF()
 

Detailed Description

The LineBox struct.

The line box struct is to simplify keeping track of lines inside the wrapping functions. It somewhat corresponds to CSS line boxes, with the caveat that formally, a line split in two in CSS/SVG would be two line boxes, while we instead have two line chunks in a single line box. This is necessary to ensure we can calculate the same line height for boxes split by a shape.

CSS-Inline-3 defines Line Boxes here: https://www.w3.org/TR/css-inline-3/#line-box CSS-Text-3 briefly talks about them here: https://www.w3.org/TR/css-text-3/#bidi-linebox SVG-2 chapter text talks about them here: https://svgwg.org/svg2-draft/text.html#TextLayoutAutoNotes

What is important to us is that all the above specifications, when they talk about Bidi-reordering, agree that the order is dependant on the paragraph/block level direction, and is not affected by the inline content changing direction. Which is good, because that'd make things super hard.

Definition at line 298 of file KoSvgTextShape_p.h.

Constructor & Destructor Documentation

◆ LineBox() [1/3]

LineBox::LineBox ( )
inline

Definition at line 300 of file KoSvgTextShape_p.h.

300 {
301 }

◆ LineBox() [2/3]

LineBox::LineBox ( QPointF start,
QPointF end,
const KoSvgText::ResolutionHandler & resHandler )
inline

Definition at line 303 of file KoSvgTextShape_p.h.

303 {
305 chunk.length = QLineF(resHandler.adjustCeil(start), resHandler.adjustFloor(end));
306 chunks.append(chunk);
307 currentChunk = 0;
308 }
QPointF adjustCeil(const QPointF point) const
Adjusts the point to ceiled pixel values.
QPointF adjustFloor(const QPointF point) const
Adjusts the point to floored pixel values.
LineChunk chunk()
QVector< LineChunk > chunks
QLineF length
Used to measure how long the current line is allowed to be.

References KoSvgText::ResolutionHandler::adjustCeil(), KoSvgText::ResolutionHandler::adjustFloor(), chunk(), chunks, currentChunk, and LineChunk::length.

◆ LineBox() [3/3]

LineBox::LineBox ( QVector< QLineF > lineWidths,
bool ltr,
QPointF indent,
const KoSvgText::ResolutionHandler & resHandler )
inline

Definition at line 310 of file KoSvgTextShape_p.h.

310 {
311 textIndent = indent;
312 if (ltr) {
313 Q_FOREACH(QLineF line, lineWidths) {
315 chunk.length = QLineF(resHandler.adjustCeil(line.p1()), resHandler.adjustFloor(line.p2()));
316 chunks.append(chunk);
317 currentChunk = 0;
318 }
319 } else {
320 Q_FOREACH(QLineF line, lineWidths) {
322 chunk.length = QLineF(resHandler.adjustFloor(line.p2()), resHandler.adjustCeil(line.p1()));
323 chunks.insert(0, chunk);
324 currentChunk = 0;
325 }
326 }
327 }
QPointF textIndent

References KoSvgText::ResolutionHandler::adjustCeil(), KoSvgText::ResolutionHandler::adjustFloor(), chunk(), chunks, currentChunk, LineChunk::length, and textIndent.

Member Function Documentation

◆ chunk()

LineChunk LineBox::chunk ( )
inline

Definition at line 345 of file KoSvgTextShape_p.h.

345 {
346 return chunks.value(currentChunk);
347 }

References chunks, and currentChunk.

◆ clearAndAdjust()

void LineBox::clearAndAdjust ( bool isHorizontal,
QPointF current,
QPointF indent )
inline

Definition at line 358 of file KoSvgTextShape_p.h.

358 {
360 actualLineTop = 0;
362 textIndent = indent;
363 QLineF length = chunks.at(currentChunk).length;
364 if (isHorizontal) {
365 length.setP1(QPointF(length.p1().x(), current.y()));
366 length.setP2(QPointF(length.p2().x(), current.y()));
367 } else {
368 length.setP1(QPointF(current.x(), length.p1().y()));
369 length.setP2(QPointF(current.x(), length.p2().y()));
370 }
371 chunks.clear();
372 currentChunk = 0;
374 chunks.append(chunk);
375 firstLine = false;
376 }
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
qreal actualLineBottom
qreal actualLineTop

References actualLineBottom, actualLineTop, chunk(), chunks, currentChunk, firstLine, LineChunk::length, length(), and textIndent.

◆ isEmpty()

bool LineBox::isEmpty ( )
inline

Definition at line 401 of file KoSvgTextShape_p.h.

401 {
402 if (chunks.isEmpty()) return true;
403 for (int i =0; i < chunks.size(); i++) {
404 if (!chunks.at(i).chunkIndices.isEmpty()) return false;
405 }
406 return true;
407 }

References chunks.

◆ setCurrentChunk()

void LineBox::setCurrentChunk ( LineChunk chunk)
inline

Definition at line 349 of file KoSvgTextShape_p.h.

349 {
350 currentChunk = qMax(currentChunk, 0);
351 if (currentChunk < chunks.size()) {
353 } else {
354 chunks.append(chunk);
355 }
356 }

References chunk(), chunks, and currentChunk.

◆ setCurrentChunkForPos()

void LineBox::setCurrentChunkForPos ( QPointF pos,
bool isHorizontal )
inline

Definition at line 378 of file KoSvgTextShape_p.h.

378 {
379 for (int i=0; i<chunks.size(); i++) {
380 LineChunk chunk = chunks.at(i);
381 if (isHorizontal) {
382 qreal min = qMin(chunk.length.p1().x(), chunk.length.p2().x()) - SHAPE_PRECISION;
383 qreal max = qMax(chunk.length.p1().x(), chunk.length.p2().x()) + SHAPE_PRECISION;
384 if ((pos.x() < max) &&
385 (pos.x() >= min)) {
386 currentChunk = i;
387 break;
388 }
389 } else {
390 qreal min = qMin(chunk.length.p1().y(), chunk.length.p2().y()) - SHAPE_PRECISION;
391 qreal max = qMax(chunk.length.p1().y(), chunk.length.p2().y()) + SHAPE_PRECISION;
392 if ((pos.y() < max) &&
393 (pos.y() >= min)) {
394 currentChunk = i;
395 break;
396 }
397 }
398 }
399 }
constexpr qreal SHAPE_PRECISION
Value that indicates the precision for testing coordinates for text-in-shape layout.
T min(T a, T b, T c)
constexpr std::enable_if< sizeof...(values)==0, size_t >::type max()

References chunk(), chunks, currentChunk, LineChunk::length, and SHAPE_PRECISION.

Member Data Documentation

◆ actualLineBottom

qreal LineBox::actualLineBottom = 0

Definition at line 334 of file KoSvgTextShape_p.h.

◆ actualLineTop

qreal LineBox::actualLineTop = 0

Definition at line 333 of file KoSvgTextShape_p.h.

◆ baselineBottom

QPointF LineBox::baselineBottom = QPointF()

Used to identify the bottom of the line for baseline-alignment.

Definition at line 337 of file KoSvgTextShape_p.h.

◆ baselineTop

QPointF LineBox::baselineTop = QPointF()

Used to identify the top of the line for baseline-alignment.

Definition at line 336 of file KoSvgTextShape_p.h.

◆ chunks

QVector<LineChunk> LineBox::chunks

Definition at line 329 of file KoSvgTextShape_p.h.

◆ currentChunk

int LineBox::currentChunk = -1

Definition at line 330 of file KoSvgTextShape_p.h.

◆ expectedLineTop

qreal LineBox::expectedLineTop = 0

Because fonts can affect lineheight mid-line, and this affects wrapping, this estimates the line-height.

Definition at line 332 of file KoSvgTextShape_p.h.

◆ firstLine

bool LineBox::firstLine = false

Definition at line 340 of file KoSvgTextShape_p.h.

◆ justifyLine

bool LineBox::justifyLine = false

Definition at line 343 of file KoSvgTextShape_p.h.

◆ lastLine

bool LineBox::lastLine = false

Definition at line 341 of file KoSvgTextShape_p.h.

◆ lineFinalized

bool LineBox::lineFinalized = false

Definition at line 342 of file KoSvgTextShape_p.h.

◆ textIndent

QPointF LineBox::textIndent = QPointF()

Definition at line 339 of file KoSvgTextShape_p.h.


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