use super::*;
pub(in crate::layout) fn inline_fragment_has_visible_text_paint(
fragment: &(impl InlineFragmentAccess + ?Sized),
) -> bool {
fragment.style().color.is_visible()
|| fragment
.style()
.text_decoration_origins
.effective_layers()
.any(|layer| {
layer.decoration.has_visible_line()
&& layer
.decoration
.color
.unwrap_or(fragment.style().color)
.is_visible()
})
|| fragment.style().text_shadow.iter().any(|shadow| {
!shadow.inset && shadow.color.resolve(fragment.style().color).is_visible()
})
}
pub(in crate::layout) fn can_paint_inline_fragments_together(
left: &(impl InlineFragmentAccess + ?Sized),
right: &(impl InlineFragmentAccess + ?Sized),
) -> bool {
let shares_first_letter_group = left
.first_letter_pseudo_group_id()
.zip(right.first_letter_pseudo_group_id())
.is_some_and(|(left, right)| left == right);
(left.mergeable() && right.mergeable() || shares_first_letter_group)
&& inline_text_sources_are_paint_compatible(left.source(), right.source())
&& (left.baseline_shift() - right.baseline_shift()).abs() < 0.01
&& left.visual_offset() == right.visual_offset()
&& left.link_target() == right.link_target()
&& (left.style().font_size - right.style().font_size).abs() < 0.01
&& left.style().vertical_align == right.style().vertical_align
&& left.style().color == right.style().color
&& left.style().font_palette == right.style().font_palette
&& left.style().visibility == right.style().visibility
&& left.style().opacity == right.style().opacity
&& left.style().text_decoration == right.style().text_decoration
&& inline_ancestor_decorations_have_same_text_paint_effect(
left.ancestor_inline_decorations(),
right.ancestor_inline_decorations(),
)
}
pub(in crate::layout) fn inline_text_sources_are_paint_compatible(
left: InlineTextSource,
right: InlineTextSource,
) -> bool {
match (left, right) {
(InlineTextSource::FootnoteCall(left), InlineTextSource::FootnoteCall(right)) => {
left == right
}
(InlineTextSource::FootnoteCall(_), _) | (_, InlineTextSource::FootnoteCall(_)) => false,
(InlineTextSource::BidiControl, InlineTextSource::BidiControl) => true,
(InlineTextSource::BidiControl, _) | (_, InlineTextSource::BidiControl) => false,
(InlineTextSource::BlockEllipsis, InlineTextSource::BlockEllipsis) => true,
(InlineTextSource::BlockEllipsis, _) | (_, InlineTextSource::BlockEllipsis) => false,
(InlineTextSource::WordSpaceTransform(_), InlineTextSource::RunIn)
| (InlineTextSource::RunIn, InlineTextSource::WordSpaceTransform(_)) => false,
(InlineTextSource::WordSpaceTransform(_), _)
| (_, InlineTextSource::WordSpaceTransform(_)) => true,
(InlineTextSource::Marker, InlineTextSource::Marker) => true,
(InlineTextSource::Marker, _) | (_, InlineTextSource::Marker) => false,
(InlineTextSource::RunIn, InlineTextSource::RunIn) => true,
(InlineTextSource::RunIn, _) | (_, InlineTextSource::RunIn) => false,
(
InlineTextSource::Normal | InlineTextSource::Generated | InlineTextSource::GeneratedWbr,
_,
) => true,
}
}