mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-03 11:37:03 +00:00
feat(fonts): add font picker to book setup
Add a Typography section to book setup with one-click preset pairings, an advanced body/heading picker, and a live sample. Enumerate installed fonts via a new list_system_fonts Tauri command (fontdb) so they appear alongside the bundled set, with a note that system fonts may not embed in exports.
This commit is contained in:
1 parent
28367b6670
commit
9a38976000
8 files changed
+251
-4
No files matched your search
Generated
+2
-1
@@ -4704,9 +4704,10 @@ checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
|
||||
|
||||
[[package]]
|
||||
name = "margin-app"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"fontdb",
|
||||
"harper-core",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
||||
@@ -27,6 +27,7 @@ serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
base64 = "0.22"
|
||||
zip = "2"
|
||||
fontdb = "0.23"
|
||||
typst = "0.14.2"
|
||||
typst-pdf = "0.14.2"
|
||||
typst-as-lib = "0.15.5"
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
use fontdb::{Database, Family, Query};
|
||||
|
||||
fn system_db() -> Database {
|
||||
let mut db = Database::new();
|
||||
db.load_system_fonts();
|
||||
db
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
pub fn list_system_fonts() -> Vec<String> {
|
||||
let db = system_db();
|
||||
let mut names: Vec<String> = db
|
||||
.faces()
|
||||
.filter_map(|face| face.families.first().map(|(name, _)| name.clone()))
|
||||
.collect();
|
||||
names.sort();
|
||||
names.dedup();
|
||||
names
|
||||
}
|
||||
|
||||
pub fn system_font_bytes(family: &str) -> Vec<Vec<u8>> {
|
||||
let db = system_db();
|
||||
let mut out = Vec::new();
|
||||
let styles = [
|
||||
(fontdb::Weight::NORMAL, fontdb::Style::Normal),
|
||||
(fontdb::Weight::NORMAL, fontdb::Style::Italic),
|
||||
(fontdb::Weight::BOLD, fontdb::Style::Normal),
|
||||
(fontdb::Weight::BOLD, fontdb::Style::Italic),
|
||||
];
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
for (weight, style) in styles {
|
||||
let query = Query {
|
||||
families: &[Family::Name(family)],
|
||||
weight,
|
||||
style,
|
||||
..Query::default()
|
||||
};
|
||||
if let Some(id) = db.query(&query) {
|
||||
if seen.insert(id) {
|
||||
if let Some(bytes) = db.with_face_data(id, |data, _index| data.to_vec()) {
|
||||
out.push(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
mod epub;
|
||||
mod fonts;
|
||||
mod library;
|
||||
mod pdf;
|
||||
mod project;
|
||||
@@ -83,6 +84,7 @@ pub fn run() {
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
epub::package_epub,
|
||||
epub::unzip_epub,
|
||||
fonts::list_system_fonts,
|
||||
pdf::compile_pdf,
|
||||
project::read_file,
|
||||
project::write_file,
|
||||
|
||||
Reference in new issue
Block a user