Skip to content

Commit

Permalink
Gold plate example page (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham authored Nov 27, 2023
1 parent d00a8d4 commit 9fa7ae9
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 15 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@ wasm-pack build
### Start a local webserver
```
cd www
npm ci
npm run start
```

(Note: `webpack` is currently dealing with an ssl issue (11/2023), and you may need to set `$env:NODE_OPTIONS = "--openssl-legacy-provider"` to work around it)

### 🔬 Test in Headless Browsers with `wasm-pack test`

```
wasm-pack test --headless --firefox
```

### Build docs folder
```
rm ./docs/*.wasm
cd www
npm ci
npm run build
```
12 changes: 6 additions & 6 deletions docs/0.bootstrap.js

Large diffs are not rendered by default.

Binary file removed docs/4b7c6c5e2ff7066c8858.module.wasm
Binary file not shown.
Binary file added docs/9ba67513cebc4b90a306.module.wasm
Binary file not shown.
14 changes: 7 additions & 7 deletions docs/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
/******/ "../pkg/fontdue_you_see_it_bg.wasm": function() {
/******/ return {
/******/ "./fontdue_you_see_it_bg.js": {
/******/ "__wbg_new_693216e109162396": function() {
/******/ return installedModules["../pkg/fontdue_you_see_it_bg.js"].exports["__wbg_new_693216e109162396"]();
/******/ "__wbg_new_abda76e883ba8a5f": function() {
/******/ return installedModules["../pkg/fontdue_you_see_it_bg.js"].exports["__wbg_new_abda76e883ba8a5f"]();
/******/ },
/******/ "__wbg_stack_0ddaca5d1abfb52f": function(p0i32,p1i32) {
/******/ return installedModules["../pkg/fontdue_you_see_it_bg.js"].exports["__wbg_stack_0ddaca5d1abfb52f"](p0i32,p1i32);
/******/ "__wbg_stack_658279fe44541cf6": function(p0i32,p1i32) {
/******/ return installedModules["../pkg/fontdue_you_see_it_bg.js"].exports["__wbg_stack_658279fe44541cf6"](p0i32,p1i32);
/******/ },
/******/ "__wbg_error_09919627ac0992f5": function(p0i32,p1i32) {
/******/ return installedModules["../pkg/fontdue_you_see_it_bg.js"].exports["__wbg_error_09919627ac0992f5"](p0i32,p1i32);
/******/ "__wbg_error_f851667af71bcfc6": function(p0i32,p1i32) {
/******/ return installedModules["../pkg/fontdue_you_see_it_bg.js"].exports["__wbg_error_f851667af71bcfc6"](p0i32,p1i32);
/******/ },
/******/ "__wbindgen_object_drop_ref": function(p0i32) {
/******/ return installedModules["../pkg/fontdue_you_see_it_bg.js"].exports["__wbindgen_object_drop_ref"](p0i32);
Expand Down Expand Up @@ -171,7 +171,7 @@
/******/ promises.push(installedWasmModuleData);
/******/ else {
/******/ var importObject = wasmImportObjects[wasmModuleId]();
/******/ var req = fetch(__webpack_require__.p + "" + {"../pkg/fontdue_you_see_it_bg.wasm":"4b7c6c5e2ff7066c8858"}[wasmModuleId] + ".module.wasm");
/******/ var req = fetch(__webpack_require__.p + "" + {"../pkg/fontdue_you_see_it_bg.wasm":"9ba67513cebc4b90a306"}[wasmModuleId] + ".module.wasm");
/******/ var promise;
/******/ if(importObject instanceof Promise && typeof WebAssembly.compileStreaming === 'function') {
/******/ promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) {
Expand Down
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<label for="input">enter a character:</label>
<input type="text" placeholder="¾" id="input">
</div>
<div class="flex"><p style="flex: 1 0 auto; text-align: center;" id="warning"></p></div>
<div class="flex">
<div style="flex: auto"></div>
<div class="col">
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,14 @@ pub fn render(size: f32, input: char) -> CharRender {
underlying: bitmap
}
}

#[wasm_bindgen]
pub fn has_glyph(input: char) -> bool {
set_panic_hook();
let settings = fontdue::FontSettings {
scale: 24.0,
..fontdue::FontSettings::default()
};
let font = Font::from_bytes(ROBOTO_MONO_REGULAR_TTF, settings).unwrap();
font.has_glyph(input)
}
1 change: 1 addition & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<label for="input">enter a character:</label>
<input type="text" placeholder="¾" id="input">
</div>
<div class="flex"><p style="flex: 1 0 auto; text-align: center;" id="warning"></p></div>
<div class="flex">
<div style="flex: auto"></div>
<div class="col">
Expand Down
7 changes: 5 additions & 2 deletions www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ function renderBuiltinCharacter(char = "¾", xmin, ymin, height = 200, width = 2
function init() {
const input = /** @type {HTMLInputElement} */(document.getElementById("input"));
input.addEventListener("change", function () {
const [height, width, xmin, ymin] = renderFontdueCharacter(this.value);
renderBuiltinCharacter(this.value, xmin, ymin, height, width);
const present = wasm.has_glyph(this.value);
const char = present ? this.value : "?";
const [height, width, xmin, ymin] = renderFontdueCharacter(char);
renderBuiltinCharacter(char, xmin, ymin, height, width);
/** @type {HTMLElement} */(document.getElementById("warning")).innerHTML = present ? "" : "Character missing from font bundled into page.";
});
const [height, width, xmin, ymin] = renderFontdueCharacter();
renderBuiltinCharacter(undefined, xmin, ymin, height, width);
Expand Down

0 comments on commit 9fa7ae9

Please sign in to comment.