47 lines
2.2 KiB
Markdown
47 lines
2.2 KiB
Markdown
# Covergen
|
|
|
|
Just generates some magic PDF invoice covers using straight up dark magic.
|
|
|
|
## Building it
|
|
|
|
```shell
|
|
# Builds the CLI
|
|
make build
|
|
|
|
# Builds the WASM blob
|
|
make wasm
|
|
```
|
|
|
|
## Custom font notes
|
|
|
|
The PDF uses the font `Mark`, which isn't a commonly available font.
|
|
For this reason they have been vendored into the repository in `pkg/covergen/fonts` together with
|
|
the `cp1252` character map (used in most PDFs because UTF-8 hasn't been invented yet in the PDF world).
|
|
For usage in `fpdf` they need to be encoded, which is done throught he `makefont` tool provided by `fpdf`, see
|
|
[https://github.com/go-pdf/fpdf#nonstandard-fonts](https://github.com/go-pdf/fpdf#nonstandard-fonts).
|
|
The section linked will also provide instructions on how to use it, but for this specific repo, the call to regenerate
|
|
or add more fonts is:
|
|
```shell
|
|
makefont --embed --enc=pkg/covergen/fonts/cp1252.map --dst=pkg/covergen/font_embed pkg/covergen/fonts/*.ttf
|
|
```
|
|
|
|
To get the `makefont` binary, clone the `go-fpdf/fpdf` repo and run `go build` in the `makefont` directory.
|
|
|
|
## A note on WASM
|
|
|
|
An interesting architectural note about how WASM binaries are run in browsers is that you should not see it
|
|
as a shell command 'exec'-ing out into a new binary, but rather as two processes living side by side.
|
|
The calling a method exposed by WASM behaves more like doing IPC between the two processes.
|
|
You can sort of see this happening in `cmd/wasm/main.go` where the `main` function is actually used.
|
|
It registers the two exposed commands to the `global` scope (in browsers: `window`) before just deadlocking
|
|
by waiting on an anonymous channel.
|
|
|
|
The most important note you should take from that is that the WASM binary **can crash**.
|
|
If it crashes, it doesn't just 'boot itself' again.
|
|
And the JS -> WASM boundary is *very*, ***very*** unsafe.
|
|
Like 'do the smallest thing wrong and the program crashes' level of unsafe.
|
|
No, type safety won't help you, you're literally playing with the equivalent of void pointers.
|
|
Even panic recovery (present in the two exposed methods) doesn't protect against all of it.
|
|
|
|
I think where I'm going is just a strong warning to be *very* careful at that boundary.
|
|
Don't trust any `js.Value`. Parse it thoroughly and quickly into golang-specified types. |