Skip to content

Commit

Permalink
UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Nov 27, 2024
1 parent d82f8dd commit de9dfff
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
11 changes: 11 additions & 0 deletions shaperglot-web/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;

use skrifa::{raw::tables::name::NameId, FontRef, MetadataProvider};
use wasm_bindgen::prelude::*;
extern crate console_error_panic_hook;
use google_fonts_languages::{RegionProto, ScriptProto, REGIONS, SCRIPTS};
Expand Down Expand Up @@ -35,6 +36,16 @@ pub fn regions() -> Result<String, JsValue> {
serde_json::to_string(&region_hash).map_err(|e| e.to_string().into())
}

#[wasm_bindgen]
pub fn family_name(font_data: &[u8]) -> Result<String, JsValue> {
let font = FontRef::new(font_data).map_err(|e| e.to_string())?;
Ok(font
.localized_strings(NameId::FAMILY_NAME)
.english_or_first()
.map(|s| s.chars().collect())
.unwrap_or_default())
}

#[wasm_bindgen]
pub fn check_font(font_data: &[u8]) -> Result<String, JsValue> {
let checker = Checker::new(font_data).map_err(|e| e.to_string())?;
Expand Down
20 changes: 14 additions & 6 deletions shaperglot-web/www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class Shaperglot {
this.regions = message.regions;
} else if ("results" in message) {
$("#spinnerModal").hide();
if (message.family_name) {
$("#filename").text(message.family_name);
}
this.renderResults(message.results);
}
}
Expand Down Expand Up @@ -230,19 +233,24 @@ class Shaperglot {
let mark = status == "Pass" ? "✅" : "❌";

problem_html.append(
`<dt>${check_name} ${mark} (${Math.round(
score * weight * 100
) / 100}/${weight} points)</dt>`
`<dt>
<details>
<summary>${check_name} ${mark} (${Math.round(
score * weight * 100
) / 100}/${weight} points)
</summary>
<blockquote class="bg-light">${check_description}
</blockquote>
</dt>`
);
let dd = $(`<dd>
<blockquote class="bg-light">${check_description}
</blockquote>
</dd>`);
problem_html.append(dd);
if (problems.length > 0) {
dd.append(`<p><b>Problems:</b><ul></ul></p>`);
} else {
dd.append(`<ul><li>No problems found!</li></ul>`);
problem_html.find("details").last().append(`<ul><li>No problems found!</li></ul>`);
}
for (var problem of problems) {
let { check_name, message, fixes } = problem;
Expand Down
4 changes: 3 additions & 1 deletion shaperglot-web/www/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,6 @@ button.nav-link {
color: #888;
}

dd { margin: 10px 25px 10px 25px; }
dd { margin: 10px 25px 10px 25px; }

dt details blockquote { font-weight: 400; margin: 10px 25px 10px 25px; }
2 changes: 1 addition & 1 deletion shaperglot-web/www/webworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function init() {
const { font } = event.data;
try {
const results = JSON.parse(wasm.check_font(font));
self.postMessage({ results: results });
self.postMessage({ results: results, family_name: wasm.family_name(font) });
} catch (error) {
self.postMessage({ error: error.message });
}
Expand Down

0 comments on commit de9dfff

Please sign in to comment.