Skip to content

Commit

Permalink
fix alignment-baseline and dominant-baseline logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Dec 20, 2024
1 parent 3c52b8c commit 969917a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion source/cssparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3390,12 +3390,13 @@ RefPtr<CSSValue> CSSParser::consumeLonghand(CSSTokenStream& input, CSSPropertyID

case CSSPropertyID::AlignmentBaseline: {
static const CSSIdentValueEntry table[] = {
{"auto", CSSValueID::Auto},
{"baseline", CSSValueID::Baseline},
{"before-edge", CSSValueID::BeforeEdge},
{"text-before-edge", CSSValueID::TextBeforeEdge},
{"middle", CSSValueID::Middle},
{"central", CSSValueID::Central},
{"after-Edge", CSSValueID::AfterEdge},
{"after-edge", CSSValueID::AfterEdge},
{"text-after-edge", CSSValueID::TextAfterEdge},
{"ideographic", CSSValueID::Ideographic},
{"alphabetic", CSSValueID::Alphabetic},
Expand Down
4 changes: 3 additions & 1 deletion source/layout/boxstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,8 @@ AlignmentBaseline BoxStyle::alignmentBaseline() const
return AlignmentBaseline::Baseline;
auto& ident = to<CSSIdentValue>(*value);
switch(ident.value()) {
case CSSValueID::Auto:
return AlignmentBaseline::Auto;
case CSSValueID::Baseline:
return AlignmentBaseline::Baseline;
case CSSValueID::BeforeEdge:
Expand All @@ -1421,7 +1423,7 @@ AlignmentBaseline BoxStyle::alignmentBaseline() const
assert(false);
}

return AlignmentBaseline::Baseline;
return AlignmentBaseline::Auto;
}

DominantBaseline BoxStyle::dominantBaseline() const
Expand Down
1 change: 1 addition & 0 deletions source/layout/boxstyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ class BorderEdge {
};

enum class AlignmentBaseline : uint8_t {
Auto,
Baseline,
BeforeEdge,
TextBeforeEdge,
Expand Down
14 changes: 11 additions & 3 deletions source/layout/svglinelayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static AlignmentBaseline resolveDominantBaseline(const Box* box)
switch(style->dominantBaseline()) {
case DominantBaseline::Auto:
case DominantBaseline::UseScript:
return AlignmentBaseline::Alphabetic;
return AlignmentBaseline::Auto;
case DominantBaseline::NoChange:
case DominantBaseline::ResetSize:
return resolveDominantBaseline(box->parentBox());
Expand All @@ -241,16 +241,24 @@ static AlignmentBaseline resolveDominantBaseline(const Box* box)
assert(false);
}

return AlignmentBaseline::Alphabetic;
return AlignmentBaseline::Auto;
}

static float calculateBaselineOffset(const Box* box)
{
const auto* style = box->style();
auto baseline = style->alignmentBaseline();
if(baseline == AlignmentBaseline::Baseline)
if(baseline == AlignmentBaseline::Auto || baseline == AlignmentBaseline::Baseline) {
baseline = resolveDominantBaseline(box);
}

auto baselineShift = calculateBaselineShift(style);
auto parent = box->parentBox();
while(parent && (parent->isSVGTSpanBox() || parent->isSVGTextBox())) {
baselineShift += calculateBaselineShift(parent->style());
parent = parent->parentBox();
}

switch(baseline) {
case AlignmentBaseline::BeforeEdge:
case AlignmentBaseline::TextBeforeEdge:
Expand Down

0 comments on commit 969917a

Please sign in to comment.