summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-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.rs20
4 files changed, 19 insertions, 12 deletions
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..ca3fc6fc 100644
--- a/graphics/src/text.rs
+++ b/graphics/src/text.rs
@@ -16,6 +16,7 @@ use crate::core::{Color, Pixels, Point, Rectangle, Size, Transformation};
use once_cell::sync::OnceCell;
use std::borrow::Cow;
+use std::collections::HashSet;
use std::sync::{Arc, RwLock, Weak};
/// A text primitive.
@@ -146,11 +147,12 @@ 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`].
@@ -163,11 +165,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 +180,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 +192,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())),
);