Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions examples/assets/text-shadow.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Shadow Examples</title>
<style>
body {
font-family: system-ui, sans-serif;
padding: 32px;
line-height: 1.6;
color: #1f2937;
background: white;
}

p {
margin: 24px 0;
font-size: 32px;
font-weight: 700;
}

.soft-shadow {
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.35);
}

.glow {
color: #2563eb;
text-shadow: 0 0 8px rgba(37, 99, 235, 0.75);
}

.offset-red {
text-shadow: 4px 3px 0 #ef4444;
}

.layered {
color: #111827;
text-shadow: 1px 1px 0 #facc15, 3px 3px 0 #f97316;
}

.blurred-purple {
color: #7c3aed;
text-shadow: -3px 3px 6px rgba(124, 58, 237, 0.55);
}
</style>
</head>
<body>
<p class="soft-shadow">Soft shadow</p>
<p class="glow">Blue glow</p>
<p class="offset-red">Red offset</p>
<p class="layered">Layered shadow</p>
<p class="blurred-purple">Purple blur</p>
</body>
</html>
44 changes: 35 additions & 9 deletions packages/blitz-paint/src/filters.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use blitz_dom::util::ToColorColor as _;
use style::color::AbsoluteColor;
pub(crate) use style::computed_values::filter::single_value::T as StyloFilter;
pub(crate) use style::properties::generated::longhands::text_shadow::computed_value::T as StyloTextShadows;
use style::values::computed::SimpleShadow as StyloSimpleShadow;

use anyrender::filters::{Filter, FilterEffect};

Expand All @@ -14,6 +16,36 @@ pub(crate) fn convert_filters(filters: &[StyloFilter]) -> Option<Filter> {
))
}

pub(crate) fn convert_text_shadows(
shadows: &StyloTextShadows,
current_color: &AbsoluteColor,
scale: f32,
) -> Option<Filter> {
if shadows.0.is_empty() {
return None;
}

Some(Filter::linear_list(shadows.0.iter().map(|shadow| {
convert_simple_shadow(shadow, current_color, scale)
})))
}

fn convert_simple_shadow(
shadow: &StyloSimpleShadow,
current_color: &AbsoluteColor,
scale: f32,
) -> FilterEffect {
FilterEffect::drop_shadow(
shadow.horizontal.px() * scale,
shadow.vertical.px() * scale,
shadow.blur.px() * scale,
shadow
.color
.resolve_to_absolute(current_color)
.as_color_color(),
)
}

pub(crate) fn convert_single_filter(filter: &StyloFilter) -> Option<FilterEffect> {
Some(match filter {
StyloFilter::Blur(radius) => FilterEffect::blur(radius.px()),
Expand All @@ -25,16 +57,10 @@ pub(crate) fn convert_single_filter(filter: &StyloFilter) -> Option<FilterEffect
StyloFilter::Opacity(amount) => FilterEffect::opacity(amount.0),
StyloFilter::Saturate(amount) => FilterEffect::saturate(amount.0),
StyloFilter::Sepia(amount) => FilterEffect::sepia(amount.0),
StyloFilter::DropShadow(shadow) => FilterEffect::drop_shadow(
shadow.horizontal.px(),
shadow.vertical.px(),
shadow.blur.px(),
StyloFilter::DropShadow(shadow) => {
// TODO: pass in correct currentColor
shadow
.color
.resolve_to_absolute(&AbsoluteColor::BLACK)
.as_color_color(),
),
convert_simple_shadow(shadow, &AbsoluteColor::BLACK, 1.0)
}
StyloFilter::Url(_) => return None,
})
}
Loading
Loading