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

Constructor & Destructor Documentation

◆ LineBox() [1/3]

LineBox::LineBox ( )
inline

Definition at line 305 of file KoSvgTextShape_p.h.

305 {
306 }

◆ LineBox() [2/3]

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

Definition at line 308 of file KoSvgTextShape_p.h.

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

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

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

References chunks, and currentChunk.

◆ clearAndAdjust()

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

Definition at line 363 of file KoSvgTextShape_p.h.

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

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

References chunks.

◆ setCurrentChunk()

void LineBox::setCurrentChunk ( LineChunk chunk)
inline

Definition at line 354 of file KoSvgTextShape_p.h.

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

References chunk(), chunks, and currentChunk.

◆ setCurrentChunkForPos()

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

Definition at line 383 of file KoSvgTextShape_p.h.

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

◆ actualLineTop

qreal LineBox::actualLineTop = 0

Definition at line 338 of file KoSvgTextShape_p.h.

◆ baselineBottom

QPointF LineBox::baselineBottom = QPointF()

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

Definition at line 342 of file KoSvgTextShape_p.h.

◆ baselineTop

QPointF LineBox::baselineTop = QPointF()

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

Definition at line 341 of file KoSvgTextShape_p.h.

◆ chunks

QVector<LineChunk> LineBox::chunks

Definition at line 334 of file KoSvgTextShape_p.h.

◆ currentChunk

int LineBox::currentChunk = -1

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

◆ firstLine

bool LineBox::firstLine = false

Definition at line 345 of file KoSvgTextShape_p.h.

◆ justifyLine

bool LineBox::justifyLine = false

Definition at line 348 of file KoSvgTextShape_p.h.

◆ lastLine

bool LineBox::lastLine = false

Definition at line 346 of file KoSvgTextShape_p.h.

◆ lineFinalized

bool LineBox::lineFinalized = false

Definition at line 347 of file KoSvgTextShape_p.h.

◆ textIndent

QPointF LineBox::textIndent = QPointF()

Definition at line 344 of file KoSvgTextShape_p.h.


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