0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-04 13:50:12 -05:00

Merge pull request #5454 from penpot/ladybenko-9512-serialization-docs

📚 Serialization docs
This commit is contained in:
Aitor Moreno 2024-12-12 10:36:40 +01:00 committed by GitHub
commit d4b829ed19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 66 additions and 0 deletions

25
render-wasm/README.md Normal file
View file

@ -0,0 +1,25 @@
# render-wasm
Canvas-based WebAssembly render engine for Penpot.
This is a Rust crate that targets [Emscripten](https://emscripten.org/) (`wasm32-unknown-emscripten`). Underneath, it uses Skia via [custom binaries](https://github.com/penpot/skia-binaries/releases/) of the [rust-skia crate](https://github.com/rust-skia/rust-skia).
## How to build
With the [Penpot Development Environment](https://help.penpot.app/technical-guide/developer/devenv/) running, create a new tab in the tmux.
```sh
cd penpot/render-wasm
./build
```
The build script will compile the project and copy the `.js` and `.wasm` files to their correct location within the frontend app.
Edit your local `frontend/resources/public/js/config.js` to add the following flags:
- `enable-feature-render-wasm` to enable this render engine.
- `enable-render-wasm-dpr` (optional), to enable using the device pixel ratio.
## Docs
- [Serialization](./docs/serialization.md)

View file

@ -0,0 +1,41 @@
# Serialization
## Paths
Paths are made of segments of **28 bytes** each. The layout (assuming positions in a `Uint8Array`) is the following:
| Offset | Length (bytes) | Data Type | Field |
| ------ | -------------- | --------- | ------- |
| 0 | 2 | `u16` | Command |
| 2 | 2 | `u16` | Flags |
| 4 | 4 | `f32` | `c1_x` |
| 8 | 4 | `f32` | `c1_y` |
| 12 | 4 | `f32` | `c2_x` |
| 16 | 4 | `f32` | `c2_y` |
| 20 | 4 | `f32` | `x` |
| 24 | 4 | `f32` | `y` |
**Command** can be one of these values:
- `:move-to`: `1`
- `:line-to`: `2`
- `:curve-to`: `3`
- `:close-path`: `4`
**Flags** is not being used at the moment.
## Gradient stops
Gradient stops are serialized in a `Uint8Array`, each stop taking **5 bytes**.
| Offset | Length (bytes) | Data Type | Field |
| ------ | -------------- | --------- | ----------- |
| 0 | 1 | `u8` | Red |
| 1 | 1 | `u8` | Green |
| 2 | 1 | `u8` | Blue |
| 3 | 1 | `u8` | Alpha |
| 4 | 1 | `u8` | Stop Offset |
**Red**, **Green**, **Blue** and **Alpha** are the RGBA components of the stop.
**Stop offset** is the offset, being integer values ranging from `0` to `100` (both inclusive).