summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/Cargo.toml1
-rw-r--r--graphics/src/compositor.rs2
-rw-r--r--graphics/src/damage.rs5
-rw-r--r--graphics/src/geometry/stroke.rs4
-rw-r--r--graphics/src/text.rs25
-rw-r--r--graphics/src/text/paragraph.rs4
6 files changed, 25 insertions, 16 deletions
diff --git a/graphics/Cargo.toml b/graphics/Cargo.toml
index 7e2d767b..43191a59 100644
--- a/graphics/Cargo.toml
+++ b/graphics/Cargo.toml
@@ -33,7 +33,6 @@ bytemuck.workspace = true
cosmic-text.workspace = true
half.workspace = true
log.workspace = true
-once_cell.workspace = true
raw-window-handle.workspace = true
rustc-hash.workspace = true
thiserror.workspace = true
diff --git a/graphics/src/compositor.rs b/graphics/src/compositor.rs
index 3026bead..0b862bdb 100644
--- a/graphics/src/compositor.rs
+++ b/graphics/src/compositor.rs
@@ -90,7 +90,6 @@ pub trait Compositor: Sized {
fn screenshot<T: AsRef<str>>(
&mut self,
renderer: &mut Self::Renderer,
- surface: &mut Self::Surface,
viewport: &Viewport,
background_color: Color,
overlay: &[T],
@@ -201,7 +200,6 @@ impl Compositor for () {
fn screenshot<T: AsRef<str>>(
&mut self,
_renderer: &mut Self::Renderer,
- _surface: &mut Self::Surface,
_viewport: &Viewport,
_background_color: Color,
_overlay: &[T],
diff --git a/graphics/src/damage.rs b/graphics/src/damage.rs
index 17d60451..8aa42798 100644
--- a/graphics/src/damage.rs
+++ b/graphics/src/damage.rs
@@ -45,15 +45,12 @@ pub fn list<T>(
/// Groups the given damage regions that are close together inside the given
/// bounds.
pub fn group(mut damage: Vec<Rectangle>, bounds: Rectangle) -> Vec<Rectangle> {
- use std::cmp::Ordering;
-
const AREA_THRESHOLD: f32 = 20_000.0;
damage.sort_by(|a, b| {
a.center()
.distance(Point::ORIGIN)
- .partial_cmp(&b.center().distance(Point::ORIGIN))
- .unwrap_or(Ordering::Equal)
+ .total_cmp(&b.center().distance(Point::ORIGIN))
});
let mut output = Vec::new();
diff --git a/graphics/src/geometry/stroke.rs b/graphics/src/geometry/stroke.rs
index b8f4515e..88a5fd7b 100644
--- a/graphics/src/geometry/stroke.rs
+++ b/graphics/src/geometry/stroke.rs
@@ -23,7 +23,7 @@ pub struct Stroke<'a> {
pub line_dash: LineDash<'a>,
}
-impl<'a> Stroke<'a> {
+impl Stroke<'_> {
/// Sets the color of the [`Stroke`].
pub fn with_color(self, color: Color) -> Self {
Stroke {
@@ -48,7 +48,7 @@ impl<'a> Stroke<'a> {
}
}
-impl<'a> Default for Stroke<'a> {
+impl Default for Stroke<'_> {
fn default() -> Self {
Stroke {
style: Style::Solid(Color::BLACK),
diff --git a/graphics/src/text.rs b/graphics/src/text.rs
index feb9932a..7694ff1f 100644
--- a/graphics/src/text.rs
+++ b/graphics/src/text.rs
@@ -14,9 +14,9 @@ use crate::core::font::{self, Font};
use crate::core::text::{Shaping, Wrapping};
use crate::core::{Color, Pixels, Point, Rectangle, Size, Transformation};
-use once_cell::sync::OnceCell;
use std::borrow::Cow;
-use std::sync::{Arc, RwLock, Weak};
+use std::collections::HashSet;
+use std::sync::{Arc, OnceLock, RwLock, Weak};
/// A text primitive.
#[derive(Debug, Clone, PartialEq)]
@@ -146,16 +146,17 @@ impl Text {
/// The regular variant of the [Fira Sans] font.
///
-/// It is loaded as part of the default fonts in Wasm builds.
+/// It is loaded as part of the default fonts when the `fira-sans`
+/// feature is enabled.
///
/// [Fira Sans]: https://mozilla.github.io/Fira/
-#[cfg(all(target_arch = "wasm32", feature = "fira-sans"))]
-pub const FIRA_SANS_REGULAR: &'static [u8] =
+#[cfg(feature = "fira-sans")]
+pub const FIRA_SANS_REGULAR: &[u8] =
include_bytes!("../fonts/FiraSans-Regular.ttf").as_slice();
/// Returns the global [`FontSystem`].
pub fn font_system() -> &'static RwLock<FontSystem> {
- static FONT_SYSTEM: OnceCell<RwLock<FontSystem>> = OnceCell::new();
+ static FONT_SYSTEM: OnceLock<RwLock<FontSystem>> = OnceLock::new();
FONT_SYSTEM.get_or_init(|| {
RwLock::new(FontSystem {
@@ -163,11 +164,12 @@ pub fn font_system() -> &'static RwLock<FontSystem> {
cosmic_text::fontdb::Source::Binary(Arc::new(
include_bytes!("../fonts/Iced-Icons.ttf").as_slice(),
)),
- #[cfg(all(target_arch = "wasm32", feature = "fira-sans"))]
+ #[cfg(feature = "fira-sans")]
cosmic_text::fontdb::Source::Binary(Arc::new(
include_bytes!("../fonts/FiraSans-Regular.ttf").as_slice(),
)),
]),
+ loaded_fonts: HashSet::new(),
version: Version::default(),
})
})
@@ -177,6 +179,7 @@ pub fn font_system() -> &'static RwLock<FontSystem> {
#[allow(missing_debug_implementations)]
pub struct FontSystem {
raw: cosmic_text::FontSystem,
+ loaded_fonts: HashSet<usize>,
version: Version,
}
@@ -188,6 +191,14 @@ impl FontSystem {
/// Loads a font from its bytes.
pub fn load_font(&mut self, bytes: Cow<'static, [u8]>) {
+ if let Cow::Borrowed(bytes) = bytes {
+ let address = bytes.as_ptr() as usize;
+
+ if !self.loaded_fonts.insert(address) {
+ return;
+ }
+ }
+
let _ = self.raw.db_mut().load_font_source(
cosmic_text::fontdb::Source::Binary(Arc::new(bytes.into_owned())),
);
diff --git a/graphics/src/text/paragraph.rs b/graphics/src/text/paragraph.rs
index 07ddbb82..48c8e9e6 100644
--- a/graphics/src/text/paragraph.rs
+++ b/graphics/src/text/paragraph.rs
@@ -80,6 +80,8 @@ impl core::text::Paragraph for Paragraph {
Some(text.bounds.height),
);
+ buffer.set_wrap(font_system.raw(), text::to_wrap(text.wrapping));
+
buffer.set_text(
font_system.raw(),
text.content,
@@ -122,6 +124,8 @@ impl core::text::Paragraph for Paragraph {
Some(text.bounds.height),
);
+ buffer.set_wrap(font_system.raw(), text::to_wrap(text.wrapping));
+
buffer.set_rich_text(
font_system.raw(),
text.content.iter().enumerate().map(|(i, span)| {