leejunyoung5819 wayland-android-remote
공개Ubuntu(Wayland/X11)에서 Android 기기 화면 미러링 및 원격 제어 (Rust)
| 1 | //! 한글 표시용 시스템 폰트 등록. egui 기본 폰트에는 한글 글리프가 없다. |
| 2 | |
| 3 | use std::process::Command; |
| 4 | use std::sync::Arc; |
| 5 | |
| 6 | use egui::{FontData, FontDefinitions, FontFamily}; |
| 7 | |
| 8 | const FALLBACK_PATH: &str = "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc"; |
| 9 | |
| 10 | /// fontconfig에서 한국어 sans 폰트를 찾아 모든 글꼴 계열의 대체 폰트로 추가한다. |
| 11 | pub fn install_korean_font(ctx: &egui::Context) { |
| 12 | let (path, index) = fc_match_korean().unwrap_or_else(|| (FALLBACK_PATH.to_owned(), 0)); |
| 13 | let bytes = match std::fs::read(&path) { |
| 14 | Ok(b) => b, |
| 15 | Err(e) => { |
| 16 | log::warn!("한글 폰트를 읽지 못했습니다 ({path}): {e}"); |
| 17 | return; |
| 18 | } |
| 19 | }; |
| 20 | |
| 21 | let mut data = FontData::from_owned(bytes); |
| 22 | data.index = index; |
| 23 | |
| 24 | let mut fonts = FontDefinitions::default(); |
| 25 | fonts.font_data.insert("korean".to_owned(), Arc::new(data)); |
| 26 | for family in [FontFamily::Proportional, FontFamily::Monospace] { |
| 27 | fonts |
| 28 | .families |
| 29 | .entry(family) |
| 30 | .or_default() |
| 31 | .push("korean".to_owned()); |
| 32 | } |
| 33 | ctx.set_fonts(fonts); |
| 34 | } |
| 35 | |
| 36 | fn fc_match_korean() -> Option<(String, u32)> { |
| 37 | let out = Command::new("fc-match") |
| 38 | .args(["-f", "%{file}\n%{index}", "sans-serif:lang=ko"]) |
| 39 | .output() |
| 40 | .ok()?; |
| 41 | let text = String::from_utf8(out.stdout).ok()?; |
| 42 | let mut lines = text.lines(); |
| 43 | let path = lines.next()?.trim().to_owned(); |
| 44 | let index = lines.next()?.trim().parse().ok()?; |
| 45 | (!path.is_empty()).then_some((path, index)) |
| 46 | } |