-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reimplement vello text rendering
- Loading branch information
1 parent
a18d685
commit 4dc90be
Showing
21 changed files
with
486 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
use std::{borrow::Cow, sync::Arc}; | ||
|
||
use url::Url; | ||
|
||
use super::TextStyle; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub struct Font { | ||
inner: Arc<FontData>, | ||
data: FontData, | ||
} | ||
|
||
impl Font { | ||
pub fn new(data: FontData) -> Self { | ||
Self { | ||
inner: Arc::new(data), | ||
} | ||
Self { data } | ||
} | ||
|
||
pub fn from_bytes(bytes: Vec<u8>) -> Self { | ||
Self::new(FontData::Bytes(bytes)) | ||
Self::new(FontData::Bytes(Arc::new(bytes))) | ||
} | ||
|
||
pub fn from_family(family: impl Into<Cow<'static, str>>) -> Self { | ||
Self::new(FontData::Family(family.into())) | ||
} | ||
} | ||
|
||
pub fn from_url(url: Url) -> Self { | ||
Self::new(FontData::Url(url)) | ||
impl AsRef<FontData> for Font { | ||
fn as_ref(&self) -> &FontData { | ||
&self.data | ||
} | ||
} | ||
|
||
pub fn parse_url(url: &str) -> Result<Self, url::ParseError> { | ||
Ok(Self::from_url(Url::parse(url)?)) | ||
} | ||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub enum FontData { | ||
Bytes(Arc<Vec<u8>>), | ||
Family(Cow<'static, str>), | ||
} | ||
|
||
pub fn styled(&self) -> TextStyle { | ||
TextStyle { | ||
font: Some(self.clone()), | ||
impl std::fmt::Debug for FontData { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
struct DebugNonExhaustive; | ||
|
||
..TextStyle::default() | ||
impl std::fmt::Debug for DebugNonExhaustive { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.write_str("..") | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub enum FontData { | ||
Bytes(Vec<u8>), | ||
Family(Cow<'static, str>), | ||
Url(Url), | ||
match self { | ||
Self::Bytes(_) => f.debug_tuple("Bytes").field(&DebugNonExhaustive).finish(), | ||
Self::Family(family) => f.debug_tuple("Family").field(family).finish(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.