mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Migrate fonts to be stored as resources (#4165)
* Good start
* Impl
* allow responses.add(async { Message::NoOp });
* Fix
* Cache font blob in text node
* Refactor font handling to use Font struct direcly
* Fix fmt
* Embedd Font Resources by default
* Review
* Review
* Cache font info based on ResourceHash
This commit is contained in:
@@ -26,6 +26,10 @@ impl Resource {
|
||||
pub fn hash(&self) -> ResourceHash {
|
||||
self.hash
|
||||
}
|
||||
|
||||
pub fn empty() -> Self {
|
||||
Self::new([])
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Resource> for Arc<dyn AsRef<[u8]> + Send + Sync> {
|
||||
@@ -67,7 +71,7 @@ impl CacheHash for Resource {
|
||||
}
|
||||
|
||||
/// Blake3 content hash of a resource, represented as 32 bytes
|
||||
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord, DynAny)]
|
||||
#[derive(Clone, Copy, Default, Hash, PartialEq, Eq, PartialOrd, Ord, DynAny)]
|
||||
pub struct ResourceHash([u8; 32]);
|
||||
|
||||
impl From<&[u8]> for ResourceHash {
|
||||
@@ -135,6 +139,12 @@ impl std::str::FromStr for ResourceHash {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for ResourceHash {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(&String::from(self))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ResourceHashParseError {
|
||||
InvalidLength { found: usize },
|
||||
@@ -238,6 +248,18 @@ impl ResourceId {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for ResourceId {
|
||||
fn from(value: u64) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ResourceId> for u64 {
|
||||
fn from(id: ResourceId) -> Self {
|
||||
id.0
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for ResourceId {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
|
||||
Reference in New Issue
Block a user