mirror of
https://github.com/crosspoint-reader/crosspoint-reader.git
synced 2026-04-29 10:26:52 -07:00
Correct CSS vertical margin merging
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
|
||||
#include "Epub/css/CssStyle.h"
|
||||
@@ -38,10 +39,11 @@ struct BlockStyle {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Return a copy with the source's bottom margins/padding added to this style's.
|
||||
// Return a copy with bottom margins/padding collapsed (max) with the source's.
|
||||
// Uses CSS margin collapsing: adjacent parent-child margins resolve to the larger value.
|
||||
[[nodiscard]] BlockStyle addBottom(const BlockStyle& source) const {
|
||||
BlockStyle result = *this;
|
||||
result.marginBottom = static_cast<int16_t>(marginBottom + source.marginBottom);
|
||||
result.marginBottom = std::max(marginBottom, source.marginBottom);
|
||||
result.paddingBottom = static_cast<int16_t>(paddingBottom + source.paddingBottom);
|
||||
return result;
|
||||
}
|
||||
@@ -70,8 +72,8 @@ struct BlockStyle {
|
||||
result.textAlignDefined = true;
|
||||
}
|
||||
} else {
|
||||
result.marginTop = static_cast<int16_t>(child.marginTop + marginTop);
|
||||
result.marginBottom = static_cast<int16_t>(child.marginBottom + marginBottom);
|
||||
result.marginTop = std::max(child.marginTop, marginTop);
|
||||
result.marginBottom = std::max(child.marginBottom, marginBottom);
|
||||
result.paddingTop = static_cast<int16_t>(child.paddingTop + paddingTop);
|
||||
result.paddingBottom = static_cast<int16_t>(child.paddingBottom + paddingBottom);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user