Skip to content

Commit

Permalink
implement font family and font size switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
niusia-ua committed Jan 22, 2025
1 parent b91b2e7 commit 7a112b9
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 60 deletions.
168 changes: 154 additions & 14 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ ordered-float = { version = "4.6.0", features = ["borsh"] }
dyn-clone = "1.0.17"
nutype = { git = "https://github.com/niusia-ua/nutype.git", branch = "feat/borsh", features = ["borsh"] }
tempfile = "3.15.0"
font-kit = "0.14.2"
10 changes: 10 additions & 0 deletions src-tauri/resources/locales/en/preferences.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

preferences-title = Preferences
preferences-font-family = Font Family
preferences-font-size = Font Size (Scaling)
preferences-font-size-xx-small = Smallest
preferences-font-size-x-small = Smaller
preferences-font-size-small = Small
preferences-font-size-medium = Medium
preferences-font-size-large = Large
preferences-font-size-x-large = Larger
preferences-font-size-xx-large = Largest
preferences-theme = Theme
preferences-theme-dark = Dark
preferences-theme-light = Light
Expand Down
10 changes: 10 additions & 0 deletions src-tauri/resources/locales/uk/preferences.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

preferences-title = Налаштування
preferences-font-family = Шрифт
preferences-font-size = Розмір шрифту (масштабування)
preferences-font-size-xx-small = Найменший
preferences-font-size-x-small = Менший
preferences-font-size-small = Маленький
preferences-font-size-medium = Середній
preferences-font-size-large = Великий
preferences-font-size-x-large = Більший
preferences-font-size-xx-large = Найбільший
preferences-theme = Тема
preferences-theme-dark = Темна
preferences-theme-light = Світла
Expand Down
7 changes: 7 additions & 0 deletions src-tauri/src/commands/fonts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::error::CommandResult;

#[tauri::command]
pub fn get_all_text_font_families() -> CommandResult<Vec<String>> {
let source = font_kit::source::SystemSource::new();
Ok(source.all_families()?)
}
1 change: 1 addition & 0 deletions src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod fabric;
pub mod fonts;
pub mod grid;
pub mod history;
pub mod palette;
Expand Down
6 changes: 6 additions & 0 deletions src-tauri/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ impl From<tauri::Error> for CommandError {
}
}

impl From<font_kit::error::SelectionError> for CommandError {
fn from(error: font_kit::error::SelectionError) -> Self {
Self(anyhow::Error::from(error))
}
}

impl serde::Serialize for CommandError {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error> {
serializer.serialize_str(&format!("{:#}", self.0))
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub fn setup_app<R: tauri::Runtime>(builder: tauri::Builder<R>) -> tauri::App<R>
commands::stitches::remove_stitch,
commands::history::undo,
commands::history::redo,
commands::fonts::get_all_text_font_families,
])
.build(tauri::generate_context!())
.expect("Failed to build Embroidery Studio")
Expand Down
5 changes: 5 additions & 0 deletions src/api/fonts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { invoke } from "@tauri-apps/api/core";

export function getAllTextFontFamilies() {
return invoke<string[]>("get_all_text_font_families");
}
1 change: 1 addition & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * as GridApi from "./grid";
export * as StitchesApi from "./stitches";
export * as HistoryApi from "./history";
export * as PathApi from "./path";
export * as FontsApi from "./fonts";
Loading

0 comments on commit 7a112b9

Please sign in to comment.