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

Constructor & Destructor Documentation

◆ LineBox() [1/3]

LineBox::LineBox ( )
inline

Definition at line 306 of file KoSvgTextShape_p.h.

306 {
307 }

◆ LineBox() [2/3]

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

Definition at line 309 of file KoSvgTextShape_p.h.

309 {
311 chunk.length = QLineF(resHandler.adjustCeil(start), resHandler.adjustFloor(end));
312 chunks.append(chunk);
313 currentChunk = 0;
314 }
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 316 of file KoSvgTextShape_p.h.

316 {
317 textIndent = indent;
318 if (ltr) {
319 Q_FOREACH(QLineF line, lineWidths) {
321 chunk.length = QLineF(resHandler.adjustCeil(line.p1()), resHandler.adjustFloor(line.p2()));
322 chunks.append(chunk);
323 currentChunk = 0;
324 }
325 } else {
326 Q_FOREACH(QLineF line, lineWidths) {
328 chunk.length = QLineF(resHandler.adjustFloor(line.p2()), resHandler.adjustCeil(line.p1()));
329 chunks.insert(0, chunk);
330 currentChunk = 0;
331 }
332 }
333 }
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 351 of file KoSvgTextShape_p.h.

351 {
352 return chunks.value(currentChunk);
353 }

References chunks, and currentChunk.

◆ clearAndAdjust()

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

Definition at line 364 of file KoSvgTextShape_p.h.

364 {
366 actualLineTop = 0;
368 textIndent = indent;
369 QLineF length = chunks.at(currentChunk).length;
370 if (isHorizontal) {
371 length.setP1(QPointF(length.p1().x(), current.y()));
372 length.setP2(QPointF(length.p2().x(), current.y()));
373 } else {
374 length.setP1(QPointF(current.x(), length.p1().y()));
375 length.setP2(QPointF(current.x(), length.p2().y()));
376 }
377 chunks.clear();
378 currentChunk = 0;
380 chunks.append(chunk);
381 firstLine = false;
382 }
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 407 of file KoSvgTextShape_p.h.

407 {
408 if (chunks.isEmpty()) return true;
409 for (int i =0; i < chunks.size(); i++) {
410 if (!chunks.at(i).chunkIndices.isEmpty()) return false;
411 }
412 return true;
413 }

References chunks.

◆ setCurrentChunk()

void LineBox::setCurrentChunk ( LineChunk chunk)
inline

Definition at line 355 of file KoSvgTextShape_p.h.

355 {
356 currentChunk = qMax(currentChunk, 0);
357 if (currentChunk < chunks.size()) {
359 } else {
360 chunks.append(chunk);
361 }
362 }

References chunk(), chunks, and currentChunk.

◆ setCurrentChunkForPos()

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

Definition at line 384 of file KoSvgTextShape_p.h.

384 {
385 for (int i=0; i<chunks.size(); i++) {
386 LineChunk chunk = chunks.at(i);
387 if (isHorizontal) {
388 qreal min = qMin(chunk.length.p1().x(), chunk.length.p2().x()) - SHAPE_PRECISION;
389 qreal max = qMax(chunk.length.p1().x(), chunk.length.p2().x()) + SHAPE_PRECISION;
390 if ((pos.x() < max) &&
391 (pos.x() >= min)) {
392 currentChunk = i;
393 break;
394 }
395 } else {
396 qreal min = qMin(chunk.length.p1().y(), chunk.length.p2().y()) - SHAPE_PRECISION;
397 qreal max = qMax(chunk.length.p1().y(), chunk.length.p2().y()) + SHAPE_PRECISION;
398 if ((pos.y() < max) &&
399 (pos.y() >= min)) {
400 currentChunk = i;
401 break;
402 }
403 }
404 }
405 }
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 340 of file KoSvgTextShape_p.h.

◆ actualLineTop

qreal LineBox::actualLineTop = 0

Definition at line 339 of file KoSvgTextShape_p.h.

◆ baselineBottom

QPointF LineBox::baselineBottom = QPointF()

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

Definition at line 343 of file KoSvgTextShape_p.h.

◆ baselineTop

QPointF LineBox::baselineTop = QPointF()

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

Definition at line 342 of file KoSvgTextShape_p.h.

◆ chunks

QVector<LineChunk> LineBox::chunks

Definition at line 335 of file KoSvgTextShape_p.h.

◆ currentChunk

int LineBox::currentChunk = -1

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

◆ firstLine

bool LineBox::firstLine = false

Definition at line 346 of file KoSvgTextShape_p.h.

◆ justifyLine

bool LineBox::justifyLine = false

Definition at line 349 of file KoSvgTextShape_p.h.

◆ lastLine

bool LineBox::lastLine = false

Definition at line 347 of file KoSvgTextShape_p.h.

◆ lineFinalized

bool LineBox::lineFinalized = false

Definition at line 348 of file KoSvgTextShape_p.h.

◆ textIndent

QPointF LineBox::textIndent = QPointF()

Definition at line 345 of file KoSvgTextShape_p.h.


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