Skip to content

Commit

Permalink
test: pixglyph
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Sep 29, 2024
1 parent b176082 commit ee12d75
Show file tree
Hide file tree
Showing 210 changed files with 58,672 additions and 108 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/conversion/vec2canvas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ web-sys = { workspace = true, features = [
"HtmlDivElement",
"HtmlCanvasElement",
"Url",
"ImageData",
"OffscreenCanvas",
"OffscreenCanvasRenderingContext2d",
"BlobPropertyBag",
"Window",
"Document",
Expand Down
99 changes: 88 additions & 11 deletions crates/conversion/vec2canvas/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ use reflexo_vec2bbox::Vec2BBoxPass;
use crate::utils::EmptyFuture;
use ecow::EcoVec;

use std::{fmt::Debug, pin::Pin, sync::Arc};
use std::{
fmt::Debug,
pin::Pin,
sync::{
atomic::{AtomicBool, Ordering},
Arc, Mutex,
},
};

use js_sys::Promise;
use tiny_skia as sk;
Expand All @@ -18,6 +25,74 @@ use super::{rasterize_image, set_transform, BBoxAt, CanvasBBox, CanvasStateGuard

/// A reference to a canvas element.
pub type CanvasNode = Arc<CanvasElem>;
/// 2d Context
type Context2d = web_sys::CanvasRenderingContext2d;

type CancelToken = Arc<AtomicBool>;

fn cancel(token: &CancelToken) {
token.store(true, Ordering::SeqCst)
}

// , kern: &IncrDocClient

#[wasm_bindgen::prelude::wasm_bindgen]
struct Result {
cancelled: bool,
rendered: bool,
}

type ResultFuture = js_sys::Promise;

struct Kern {}

struct CoreState {}

struct ResourceState {}

pub struct ManagedCanvasOps {
core: Mutex<CoreState>,
resources: Mutex<ResourceState>,
offscreens: Mutex<Vec<web_sys::OffscreenCanvas>>,
}

impl ManagedCanvasOps {
fn render(self: &Arc<Self>, kern: &Kern, page: usize) -> ResultFuture {
let mut core = self.core.lock().unwrap();
// if cancel {
// let tok = core.currentCancel.clone();
// tok.store(true, Ordering::Relaxed);
// }

let task = RenderTask {
cancel: CancelToken::default(),
};

let resp = task.run_checkout();

drop(core);

resp
}

fn realize(self: &Arc<Self>) {}
}

pub struct RenderTask {
cancel: CancelToken,
}

impl RenderTask {
fn run_checkout(self) -> ResultFuture {
wasm_bindgen_futures::future_to_promise(async move {
Ok(Result {
cancelled: false,
rendered: true,
}
.into())
})
}
}

/// The trait for all the operations that can be performed on some canvas
/// element.
Expand Down Expand Up @@ -485,21 +560,23 @@ impl CanvasOp for CanvasGlyphElem {
}
}

async fn realize(&self, rts: sk::Transform, canvas: &web_sys::CanvasRenderingContext2d) {
if rts.sx == 0. || rts.sy == 0. {
async fn realize(&self, ts: sk::Transform, canvas: &web_sys::CanvasRenderingContext2d) {
if ts.sx == 0. || ts.sy == 0. {
return;
}

web_sys::console::log_1(&format!("realize glyph {:?} at {:?}", self.glyph_data, ts).into());

// we test that if we forcely put rts to identity, the glyph will be rendered
// without bad quality.
let ts = sk::Transform {
sx: (rts.sx * 10.).ceil(),
sy: (rts.sx * 10.).ceil(),
tx: rts.tx.ceil(),
ty: rts.ty.ceil(),
kx: 0.,
ky: 0.,
};
// let ts = sk::Transform {
// sx: (rts.sx * 10.).ceil(),
// sy: (rts.sx * 10.).ceil(),
// tx: rts.tx.ceil(),
// ty: rts.ty.ceil(),
// kx: 0.,
// ky: 0.,
// };
// web_sys::console::log_1(
// &format!(
// "realize glyph {:?} at {:?} => {:?}",
Expand Down
24 changes: 24 additions & 0 deletions crates/reflexo/src/vector/ir/geom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,14 @@ impl Rect {
}
}

pub fn cano(&self) -> Self {
let Rect { lo, hi } = self;
Self {
lo: Point::new(lo.x.min(hi.x), lo.y.min(hi.y)),
hi: Point::new(lo.x.max(hi.x), lo.y.max(hi.y)),
}
}

pub fn is_empty(&self) -> bool {
self.lo.x >= self.hi.x || self.lo.y >= self.hi.y
}
Expand Down Expand Up @@ -390,6 +398,22 @@ impl Rect {
pub fn height(&self) -> Scalar {
self.hi.y - self.lo.y
}

pub fn left(&self) -> Scalar {
self.lo.x
}

pub fn right(&self) -> Scalar {
self.hi.x
}

pub fn top(&self) -> Scalar {
self.lo.y
}

pub fn bottom(&self) -> Scalar {
self.hi.y
}
}

impl From<tiny_skia_path::Rect> for Rect {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@
"md3": "cargo run --bin typst-ts-cli -- compile --workspace . --entry ./github-pages/docs/data-flow-standalone.dark.typ --format=svg"
},
"devDependencies": {
"cross-env": "^7.0.3",
"@babel/runtime": "^7.22.6",
"@types/node": "^20.6.3",
"prettier": "^3.0.2",
"vite": "^5.4.2",
"vite-plugin-singlefile": "^0.13.5",
"eslint-plugin-html": "^7.1.0",
"eslint": "^8.52.0",
"eslint-config-prettier": "^9.0.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ reflexo-typst = { workspace = true, default-features = false, features = [
reflexo-typst2vec = { workspace = true }
reflexo-vec2canvas = { workspace = true, optional = true }
reflexo-vec2sema = { workspace = true }
reflexo-vec2bbox = { workspace = true }
reflexo-vec2svg = { workspace = true, optional = true }
reflexo-vec2dom = { workspace = true, optional = true }
console_error_panic_hook.workspace = true
svgtypes.workspace = true

[dev-dependencies]
reflexo.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion packages/renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"publish:lib": "npm publish --access public || exit 0",
"test:chrome:verbose": "wasm-pack test --chrome --headless --release --features web_verbose",
"test:firefox:verbose": "wasm-pack test --firefox --headless --release --features web_verbose",
"test:chrome": "wasm-pack test --chrome --release",
"test:chrome": "cross-env WASM_BINDGEN_TEST_NO_ORIGIN_ISOLATION=1 wasm-pack test --chrome --release",
"test:firefox": "wasm-pack test --firefox --headless --release"
}
}
Loading

0 comments on commit ee12d75

Please sign in to comment.