test: propagate text layout engine specification test suite
Formalize the Asteria Qt text layout engine behavior and establish comprehensive test coverage across all 94 Allium specification obligations for two-phase layout, Knuth-Plass line breaking, and reading session state management. - Add `specs/text-layout-engine.allium` detailing layout lifecycle, generation monotonicity, viewport metrics, and contrast safety. - Implement structural equality operators (`operator==`) across layout domain value types (`BoxStyle`, `InlineItem`, `BlockItem`, `ContentChunk`, `KnuthPlass::Item`, positioned line/run elements, and `BookPosition`) to enable deterministic assertion testing. - Introduce `TextLayoutEngineSpecTest` verifying entity fields, value equality, enum comparability, contract signatures, config defaults, lifecycle state transitions, rules, and invariants. - Register `TextLayoutEngineSpecTest` in `CMakeLists.txt` and update test inventory in `AGENTS.md`.
This commit is contained in:
8 files changed
+1681
No files matched your search
@@ -24,22 +24,54 @@ struct PositionedWordRun {
|
||||
bool underline = false;
|
||||
bool strikeOut = false;
|
||||
bool overline = false;
|
||||
|
||||
bool operator==(const PositionedWordRun &o) const
|
||||
{
|
||||
return text == o.text
|
||||
&& rect == o.rect
|
||||
&& qFuzzyCompare(baselineY, o.baselineY)
|
||||
&& font == o.font
|
||||
&& color == o.color
|
||||
&& background == o.background
|
||||
&& surfaceBackground == o.surfaceBackground
|
||||
&& link == o.link
|
||||
&& underline == o.underline
|
||||
&& strikeOut == o.strikeOut
|
||||
&& overline == o.overline;
|
||||
}
|
||||
};
|
||||
|
||||
struct PositionedLine {
|
||||
QRectF rect;
|
||||
qreal baselineY = 0;
|
||||
QVector<PositionedWordRun> runs;
|
||||
|
||||
bool operator==(const PositionedLine &o) const
|
||||
{
|
||||
return rect == o.rect
|
||||
&& qFuzzyCompare(baselineY, o.baselineY)
|
||||
&& runs == o.runs;
|
||||
}
|
||||
};
|
||||
|
||||
struct PositionedImage {
|
||||
QString url;
|
||||
QRectF targetRect;
|
||||
|
||||
bool operator==(const PositionedImage &o) const
|
||||
{
|
||||
return url == o.url && targetRect == o.targetRect;
|
||||
}
|
||||
};
|
||||
|
||||
struct PositionedRule {
|
||||
QRectF rect;
|
||||
QColor color;
|
||||
|
||||
bool operator==(const PositionedRule &o) const
|
||||
{
|
||||
return rect == o.rect && color == o.color;
|
||||
}
|
||||
};
|
||||
|
||||
struct PositionedDecoration {
|
||||
@@ -50,6 +82,17 @@ struct PositionedDecoration {
|
||||
qreal borderTop = 0;
|
||||
qreal borderBottom = 0;
|
||||
qreal borderRight = 0;
|
||||
|
||||
bool operator==(const PositionedDecoration &o) const
|
||||
{
|
||||
return rect == o.rect
|
||||
&& background == o.background
|
||||
&& borderColor == o.borderColor
|
||||
&& qFuzzyCompare(borderLeft, o.borderLeft)
|
||||
&& qFuzzyCompare(borderTop, o.borderTop)
|
||||
&& qFuzzyCompare(borderBottom, o.borderBottom)
|
||||
&& qFuzzyCompare(borderRight, o.borderRight);
|
||||
}
|
||||
};
|
||||
|
||||
struct ChunkLayout {
|
||||
@@ -59,6 +102,16 @@ struct ChunkLayout {
|
||||
QVector<PositionedDecoration> decorations;
|
||||
qreal totalHeight = 0;
|
||||
qreal contentWidth = 0;
|
||||
|
||||
bool operator==(const ChunkLayout &o) const
|
||||
{
|
||||
return lines == o.lines
|
||||
&& images == o.images
|
||||
&& rules == o.rules
|
||||
&& decorations == o.decorations
|
||||
&& qFuzzyCompare(totalHeight, o.totalHeight)
|
||||
&& qFuzzyCompare(contentWidth, o.contentWidth);
|
||||
}
|
||||
};
|
||||
|
||||
struct LayoutParams {
|
||||
@@ -66,6 +119,14 @@ struct LayoutParams {
|
||||
qreal fontSize = 16;
|
||||
qreal lineSpacing = 1.0;
|
||||
QString baseFontFamily;
|
||||
|
||||
bool operator==(const LayoutParams &o) const
|
||||
{
|
||||
return qFuzzyCompare(contentWidth, o.contentWidth)
|
||||
&& qFuzzyCompare(fontSize, o.fontSize)
|
||||
&& qFuzzyCompare(lineSpacing, o.lineSpacing)
|
||||
&& baseFontFamily == o.baseFontFamily;
|
||||
}
|
||||
};
|
||||
|
||||
namespace ChunkLayoutEngine {
|
||||
|
||||
@@ -54,6 +54,17 @@ struct InlineItem {
|
||||
qreal cssWidth = -1; // px, -1 = auto
|
||||
qreal cssHeight = -1;
|
||||
qreal cssMaxWidth = -1;
|
||||
|
||||
bool operator==(const InlineItem &o) const
|
||||
{
|
||||
return kind == o.kind
|
||||
&& text == o.text
|
||||
&& style == o.style
|
||||
&& imageUrl == o.imageUrl
|
||||
&& qFuzzyCompare(cssWidth, o.cssWidth)
|
||||
&& qFuzzyCompare(cssHeight, o.cssHeight)
|
||||
&& qFuzzyCompare(cssMaxWidth, o.cssMaxWidth);
|
||||
}
|
||||
};
|
||||
|
||||
struct BoxStyle {
|
||||
@@ -72,6 +83,24 @@ struct BoxStyle {
|
||||
{
|
||||
return paddingBottom > 0 || borderBottom > 0 || borderLeft > 0 || borderRight > 0 || background.isValid();
|
||||
}
|
||||
|
||||
bool operator==(const BoxStyle &o) const
|
||||
{
|
||||
return qFuzzyCompare(marginTop, o.marginTop)
|
||||
&& qFuzzyCompare(marginBottom, o.marginBottom)
|
||||
&& qFuzzyCompare(marginLeft, o.marginLeft)
|
||||
&& qFuzzyCompare(marginRight, o.marginRight)
|
||||
&& qFuzzyCompare(paddingTop, o.paddingTop)
|
||||
&& qFuzzyCompare(paddingBottom, o.paddingBottom)
|
||||
&& qFuzzyCompare(paddingLeft, o.paddingLeft)
|
||||
&& qFuzzyCompare(paddingRight, o.paddingRight)
|
||||
&& qFuzzyCompare(borderTop, o.borderTop)
|
||||
&& qFuzzyCompare(borderBottom, o.borderBottom)
|
||||
&& qFuzzyCompare(borderLeft, o.borderLeft)
|
||||
&& qFuzzyCompare(borderRight, o.borderRight)
|
||||
&& borderColor == o.borderColor
|
||||
&& background == o.background;
|
||||
}
|
||||
};
|
||||
|
||||
struct BlockItem {
|
||||
@@ -90,6 +119,21 @@ struct BlockItem {
|
||||
QVector<InlineItem> inlines;
|
||||
|
||||
QColor ruleColor; // Rule only; invalid = theme dim colour
|
||||
|
||||
bool operator==(const BlockItem &o) const
|
||||
{
|
||||
return kind == o.kind
|
||||
&& box == o.box
|
||||
&& align == o.align
|
||||
&& qFuzzyCompare(textIndent, o.textIndent)
|
||||
&& qFuzzyCompare(lineHeight, o.lineHeight)
|
||||
&& qFuzzyCompare(fontSize, o.fontSize)
|
||||
&& preformatted == o.preformatted
|
||||
&& marker == o.marker
|
||||
&& markerStyle == o.markerStyle
|
||||
&& inlines == o.inlines
|
||||
&& ruleColor == o.ruleColor;
|
||||
}
|
||||
};
|
||||
|
||||
struct ParseParams {
|
||||
@@ -105,6 +149,15 @@ struct ContentChunk {
|
||||
int unnestedContainers = 0;
|
||||
|
||||
bool isEmpty() const { return blocks.isEmpty(); }
|
||||
|
||||
bool operator==(const ContentChunk &o) const
|
||||
{
|
||||
return sectionHref == o.sectionHref
|
||||
&& blocks == o.blocks
|
||||
&& wordCount == o.wordCount
|
||||
&& charCount == o.charCount
|
||||
&& unnestedContainers == o.unnestedContainers;
|
||||
}
|
||||
};
|
||||
|
||||
class QDomElement;
|
||||
|
||||
@@ -36,6 +36,17 @@ struct Item {
|
||||
{
|
||||
Item i; i.type = ItemType::Penalty; i.width = w; i.penalty = p; i.flagged = flagged; i.tag = tag; return i;
|
||||
}
|
||||
|
||||
bool operator==(const Item &o) const
|
||||
{
|
||||
return type == o.type
|
||||
&& qFuzzyCompare(width, o.width)
|
||||
&& qFuzzyCompare(stretch, o.stretch)
|
||||
&& qFuzzyCompare(shrink, o.shrink)
|
||||
&& qFuzzyCompare(penalty, o.penalty)
|
||||
&& flagged == o.flagged
|
||||
&& tag == o.tag;
|
||||
}
|
||||
};
|
||||
|
||||
struct Params {
|
||||
|
||||
Reference in new issue
Block a user