summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-02-15 03:18:15 +0100
committerLibravatar GitHub <noreply@github.com>2024-02-15 03:18:15 +0100
commit7555487503234cdac0646db8ed47ec652ccfe8f4 (patch)
tree02faede5d49a1abcad37d1a6c287af6d4c2e1e11
parent84cc9f130b4e29219d47db42cdb76548b054c66b (diff)
parentfbf1895f97f6fd0c4311fba614c74983554761d7 (diff)
downloadiced-7555487503234cdac0646db8ed47ec652ccfe8f4.tar.gz
iced-7555487503234cdac0646db8ed47ec652ccfe8f4.tar.bz2
iced-7555487503234cdac0646db8ed47ec652ccfe8f4.zip
Merge pull request #2250 from Koranir/text-alpha-fix
Fix text transparency in tiny_skia renderer
-rw-r--r--CHANGELOG.md1
-rw-r--r--tiny_skia/src/text.rs11
2 files changed, 11 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 978b9c66..94ec3f47 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -80,6 +80,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `PaneGrid` click interaction on the top edge. [#2168](https://github.com/iced-rs/iced/pull/2168)
- `iced_wgpu` not rendering text in SVGs. [#2161](https://github.com/iced-rs/iced/pull/2161)
- Text clipping. [#2154](https://github.com/iced-rs/iced/pull/2154)
+- Text transparency in `iced_tiny_skia`. [#2250](https://github.com/iced-rs/iced/pull/2250)
- Layout invalidation when `Tooltip` changes `overlay`. [#2143](https://github.com/iced-rs/iced/pull/2143)
- `Overlay` composition. [#2142](https://github.com/iced-rs/iced/pull/2142)
- Incorrect GIF for the `progress_bar` example. [#2141](https://github.com/iced-rs/iced/pull/2141)
diff --git a/tiny_skia/src/text.rs b/tiny_skia/src/text.rs
index 8f36f955..d28cc483 100644
--- a/tiny_skia/src/text.rs
+++ b/tiny_skia/src/text.rs
@@ -238,6 +238,12 @@ fn draw(
)
.expect("Create glyph pixel map");
+ let opacity = color.a
+ * glyph
+ .color_opt
+ .map(|c| c.a() as f32 / 255.0)
+ .unwrap_or(1.0);
+
pixels.draw_pixmap(
physical_glyph.x + placement.left,
physical_glyph.y - placement.top
@@ -246,7 +252,10 @@ fn draw(
* transformation.scale_factor())
.round() as i32,
pixmap,
- &tiny_skia::PixmapPaint::default(),
+ &tiny_skia::PixmapPaint {
+ opacity,
+ ..tiny_skia::PixmapPaint::default()
+ },
tiny_skia::Transform::identity(),
clip_mask,
);