svg_img: Use system fonts to support CJK characters (#750)
| Before | After | | - | - | | <img width="528" alt="SCR-20250327-mpcz" src="https://github.com/user-attachments/assets/22dc30ea-582a-4133-996a-90bcf8cb54be" /> | <img width="535" alt="SCR-20250327-mnbv" src="https://github.com/user-attachments/assets/5f360d17-8285-44d8-963b-17784c4c0eb5" /> |
This commit is contained in:
parent
aadcf4e1df
commit
9f103bac6f
9 changed files with 9 additions and 26 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -2661,7 +2661,6 @@ dependencies = [
|
||||||
"paste",
|
"paste",
|
||||||
"regex",
|
"regex",
|
||||||
"resvg",
|
"resvg",
|
||||||
"rust-embed",
|
|
||||||
"rust-i18n",
|
"rust-i18n",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,12 @@ default-members = ["crates/story"]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
|
gpui = { git = "https://github.com/huacnlee/zed.git", branch = "webview" }
|
||||||
gpui-component = { path = "crates/ui" }
|
gpui-component = { path = "crates/ui" }
|
||||||
story = { path = "crates/story" }
|
story = { path = "crates/story" }
|
||||||
gpui = { git = "https://github.com/huacnlee/zed.git", branch = "webview" }
|
|
||||||
|
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
rust-embed = "8.5.0"
|
|
||||||
serde = "1.0.203"
|
serde = "1.0.203"
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
smallvec = "1"
|
smallvec = "1"
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,14 @@ chrono = "0.4"
|
||||||
fake = { version = "2.10.0", features = ["dummy"] }
|
fake = { version = "2.10.0", features = ["dummy"] }
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
gpui-component = { workspace = true, features = ["webview"] }
|
gpui-component = { workspace = true, features = ["webview"] }
|
||||||
reqwest_client = { git = "https://github.com/huacnlee/zed.git", branch = "webview" }
|
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
|
raw-window-handle = { version = "0.6", features = ["std"] }
|
||||||
regex = "1"
|
regex = "1"
|
||||||
rust-embed.workspace = true
|
reqwest_client = { git = "https://github.com/huacnlee/zed.git", branch = "webview" }
|
||||||
|
rust-embed = "8.5.0"
|
||||||
serde = "1"
|
serde = "1"
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
unindent = "0.2.3"
|
unindent = "0.2.3"
|
||||||
raw-window-handle = { version = "0.6", features = ["std"] }
|
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ use rust_embed::RustEmbed;
|
||||||
|
|
||||||
#[derive(RustEmbed)]
|
#[derive(RustEmbed)]
|
||||||
#[folder = "../../assets"]
|
#[folder = "../../assets"]
|
||||||
#[include = "fonts/**/*"]
|
|
||||||
#[include = "icons/**/*"]
|
#[include = "icons/**/*"]
|
||||||
#[exclude = "*.DS_Store"]
|
#[exclude = "*.DS_Store"]
|
||||||
pub struct Assets;
|
pub struct Assets;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"border_radius": 8,
|
"border_radius": 8,
|
||||||
"font_family": "Noto Sans",
|
"font_family": "PingFang SC",
|
||||||
"height": 400,
|
"height": 400,
|
||||||
"inner_radius": 30,
|
"inner_radius": 30,
|
||||||
"legend_margin": {
|
"legend_margin": {
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "rose 2",
|
"name": "玫",
|
||||||
"data": [
|
"data": [
|
||||||
38
|
38
|
||||||
]
|
]
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "rose 5",
|
"name": "瑰",
|
||||||
"data": [
|
"data": [
|
||||||
28
|
28
|
||||||
]
|
]
|
||||||
|
|
@ -59,7 +59,7 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"sub_title_text": "Sub Title",
|
"sub_title_text": "副標題",
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"title_text": "Nightingale Chart",
|
"title_text": "Nightingale Chart",
|
||||||
"type": "pie",
|
"type": "pie",
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ once_cell = "1.19.0"
|
||||||
paste = "1"
|
paste = "1"
|
||||||
regex = "1"
|
regex = "1"
|
||||||
resvg = { version = "0.45.0", default-features = false, features = ["text"] }
|
resvg = { version = "0.45.0", default-features = false, features = ["text"] }
|
||||||
rust-embed.workspace = true
|
|
||||||
rust-i18n = "3"
|
rust-i18n = "3"
|
||||||
serde = "1.0.203"
|
serde = "1.0.203"
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -78,16 +78,8 @@ pub use theme::*;
|
||||||
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use rust_embed::RustEmbed;
|
|
||||||
|
|
||||||
rust_i18n::i18n!("locales", fallback = "en");
|
rust_i18n::i18n!("locales", fallback = "en");
|
||||||
|
|
||||||
#[derive(RustEmbed)]
|
|
||||||
#[folder = "./assets"]
|
|
||||||
#[include = "fonts/**/*"]
|
|
||||||
#[exclude = "*.DS_Store"]
|
|
||||||
pub struct Assets;
|
|
||||||
|
|
||||||
/// Initialize the UI module.
|
/// Initialize the UI module.
|
||||||
///
|
///
|
||||||
/// This must be called before using any of the UI components.
|
/// This must be called before using any of the UI components.
|
||||||
|
|
|
||||||
|
|
@ -14,15 +14,10 @@ use smallvec::SmallVec;
|
||||||
|
|
||||||
use image::ImageBuffer;
|
use image::ImageBuffer;
|
||||||
|
|
||||||
use crate::Assets;
|
|
||||||
|
|
||||||
const SCALE: f32 = 2.;
|
const SCALE: f32 = 2.;
|
||||||
const FONT_PATH: &str = "fonts/NotoSans-Regular.ttf";
|
|
||||||
static OPTIONS: LazyLock<usvg::Options> = LazyLock::new(|| {
|
static OPTIONS: LazyLock<usvg::Options> = LazyLock::new(|| {
|
||||||
let mut options = usvg::Options::default();
|
let mut options = usvg::Options::default();
|
||||||
if let Some(font_data) = Assets::get(FONT_PATH).map(|f| f.data) {
|
options.fontdb_mut().load_system_fonts();
|
||||||
options.fontdb_mut().load_font_data(font_data.into());
|
|
||||||
}
|
|
||||||
options
|
options
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue