-
-
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.
Merge pull request #47 from nixon-voxell/feature/bevy_vello
Renaming `typst_motiongfx` to `bevy_typst`, use `bevy_vello` instead of bevy_vello_renderer`
- Loading branch information
Showing
78 changed files
with
646 additions
and
673 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "bevy_typst" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "MIT OR Apache-2.0" | ||
|
||
[dependencies] | ||
bevy = "0.13" | ||
bevy_vello = "0.3" | ||
# typst dependencies | ||
typst = "0.11" | ||
typst-svg = "0.11" | ||
typst-assets = { version = "0.11", optional = true } | ||
comemo = "0.4" # in sync with typst | ||
fontdb = { version = "0.16", features = ["memmap", "fontconfig"] } | ||
chrono = { version = "0.4.24", default-features = false, features = ["clock", "std"] } | ||
ureq = "2" | ||
dirs = "5" | ||
tar = "0.4" | ||
flate2 = "1" | ||
codespan-reporting = "0.11" | ||
ecow = { version = "0.2", features = ["serde"] } | ||
env_proxy = "0.4" | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[features] | ||
default = ["embed-fonts"] | ||
embed-fonts = ["dep:typst-assets"] |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use bevy::{ | ||
asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext}, | ||
prelude::*, | ||
utils::{ | ||
thiserror::{self, Error}, | ||
BoxedFuture, | ||
}, | ||
}; | ||
|
||
pub struct TypstAssetPlugin; | ||
|
||
impl Plugin for TypstAssetPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.init_asset::<RawTypstAsset>() | ||
.init_asset_loader::<RawTypstAssetLoader>(); | ||
} | ||
} | ||
|
||
#[derive(Asset, TypePath)] | ||
pub struct RawTypstAsset(String); | ||
|
||
impl RawTypstAsset { | ||
pub fn content(&self) -> &str { | ||
&self.0 | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct RawTypstAssetLoader; | ||
|
||
impl AssetLoader for RawTypstAssetLoader { | ||
type Asset = RawTypstAsset; | ||
|
||
type Settings = (); | ||
|
||
type Error = RawTypstAssetLoaderError; | ||
|
||
fn load<'a>( | ||
&'a self, | ||
reader: &'a mut Reader, | ||
_settings: &'a Self::Settings, | ||
_load_context: &'a mut LoadContext, | ||
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> { | ||
Box::pin(async move { | ||
let mut string = String::new(); | ||
reader.read_to_string(&mut string).await?; | ||
Ok(RawTypstAsset(string)) | ||
}) | ||
} | ||
|
||
fn extensions(&self) -> &[&str] { | ||
&["typ"] | ||
} | ||
} | ||
|
||
/// Possible errors that can be produced by [`RawTypstAssetLoader`] | ||
#[non_exhaustive] | ||
#[derive(Debug, Error)] | ||
pub enum RawTypstAssetLoaderError { | ||
/// An [Io](std::io) Error | ||
#[error("Could not load typst file: {0}")] | ||
Io(#[from] std::io::Error), | ||
} |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::path::PathBuf; | ||
|
||
use bevy::prelude::*; | ||
use typst::{diag::SourceResult, eval::Tracer, model::Document}; | ||
|
||
use world::TypstWorld; | ||
|
||
pub mod fonts; | ||
pub mod world; | ||
|
||
mod download; | ||
mod package; | ||
|
||
#[derive(Default)] | ||
pub struct TypstCompilerPlugin { | ||
font_paths: Vec<PathBuf>, | ||
} | ||
|
||
impl TypstCompilerPlugin { | ||
pub fn new(font_paths: Vec<PathBuf>) -> Self { | ||
Self { font_paths } | ||
} | ||
} | ||
|
||
impl Plugin for TypstCompilerPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.insert_resource(TypstCompiler::new(&self.font_paths)); | ||
} | ||
} | ||
|
||
/// A resource compiler for compiling Typst content. | ||
#[derive(Resource)] | ||
pub struct TypstCompiler { | ||
world: TypstWorld, | ||
tracer: Tracer, | ||
} | ||
|
||
impl TypstCompiler { | ||
pub fn new(font_paths: &[PathBuf]) -> Self { | ||
let mut assets = PathBuf::from("."); | ||
assets.push("assets"); | ||
Self { | ||
world: TypstWorld::new(assets, font_paths).unwrap(), | ||
tracer: Tracer::new(), | ||
} | ||
} | ||
|
||
/// Compile a raw Typst string into a document. | ||
pub fn compile(&mut self, text: &str) -> SourceResult<Document> { | ||
let source = self.world.get_main_source_mut(); | ||
source.replace(text); | ||
typst::compile(&self.world, &mut self.tracer) | ||
} | ||
} |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pub mod prelude { | ||
pub use crate::compiler::{world::TypstWorld, TypstCompiler, TypstCompilerPlugin}; | ||
} | ||
|
||
pub mod asset; | ||
pub mod compiler; |
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
Oops, something went wrong.