Skip to content

Commit 8288cd9

Browse files
committed
style: rust indent changed from 2 to 4 spaces
1 parent abc7530 commit 8288cd9

File tree

8 files changed

+886
-879
lines changed

8 files changed

+886
-879
lines changed

.cargo/config.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ linker = "arm-linux-gnueabihf-gcc"
66

77
[target.x86_64-unknown-linux-musl]
88
rustflags = [
9-
"-C",
10-
"target-feature=-crt-static",
9+
"-C",
10+
"target-feature=-crt-static",
1111
]
1212

1313
[target.aarch64-unknown-linux-musl]

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ end_of_line = lf
1010
insert_final_newline = true
1111
trim_trailing_whitespace = true
1212

13+
[*.{rs,toml}]
14+
indent_size = 4
15+
1316
[*.md]
1417
insert_final_newline = false

build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
extern crate napi_build;
33

44
fn main() {
5-
#[cfg(not(target_arch = "wasm32"))]
6-
napi_build::setup();
5+
#[cfg(not(target_arch = "wasm32"))]
6+
napi_build::setup();
77
}

rustfmt.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Docs: https://rust-lang.github.io/rustfmt/?version=v1.4.38
2-
tab_spaces = 2
32
edition = "2021"
43
wrap_comments = true
54
comment_width = 100

src/error.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@ use thiserror::Error;
66

77
#[derive(Error, Debug)]
88
pub enum Error {
9-
#[error(transparent)]
10-
SVG(#[from] svgtypes::Error),
11-
#[error(transparent)]
12-
USvg(#[from] usvg::Error),
13-
#[error(transparent)]
14-
Encoding(#[from] png::EncodingError),
15-
#[error(transparent)]
16-
Utf8(#[from] std::string::FromUtf8Error),
17-
#[error("Target size is zero (please do not set the width/height/zoom options to 0)")]
18-
ZeroSized,
19-
#[error("Input must be string or Uint8Array")]
20-
InvalidInput,
21-
#[error("Unrecognized image buffer")]
22-
UnrecognizedBuffer,
9+
#[error(transparent)]
10+
SVG(#[from] svgtypes::Error),
11+
#[error(transparent)]
12+
USvg(#[from] usvg::Error),
13+
#[error(transparent)]
14+
Encoding(#[from] png::EncodingError),
15+
#[error(transparent)]
16+
Utf8(#[from] std::string::FromUtf8Error),
17+
#[error("Target size is zero (please do not set the width/height/zoom options to 0)")]
18+
ZeroSized,
19+
#[error("Input must be string or Uint8Array")]
20+
InvalidInput,
21+
#[error("Unrecognized image buffer")]
22+
UnrecognizedBuffer,
2323
}
2424

2525
#[cfg(not(target_arch = "wasm32"))]
2626
impl From<Error> for napi::Error {
27-
fn from(e: Error) -> Self {
28-
napi::Error::from_reason(format!("{}", e))
29-
}
27+
fn from(e: Error) -> Self {
28+
napi::Error::from_reason(format!("{}", e))
29+
}
3030
}
3131

3232
#[cfg(target_arch = "wasm32")]
3333
impl From<Error> for js_sys::Error {
34-
fn from(e: Error) -> Self {
35-
js_sys::Error::new(&format!("{}", e))
36-
}
34+
fn from(e: Error) -> Self {
35+
js_sys::Error::new(&format!("{}", e))
36+
}
3737
}

src/fonts.rs

+57-57
Original file line numberDiff line numberDiff line change
@@ -14,70 +14,70 @@ use usvg::fontdb::Database;
1414
/// Loads fonts.
1515
#[cfg(not(target_arch = "wasm32"))]
1616
pub fn load_fonts(font_options: &JsFontOptions) -> Database {
17-
// Create a new font database
18-
let mut fontdb = Database::new();
19-
let now = std::time::Instant::now();
17+
// Create a new font database
18+
let mut fontdb = Database::new();
19+
let now = std::time::Instant::now();
2020

21-
// 加载系统字体
22-
// https://github.com/RazrFalcon/fontdb/blob/052d74b9eb45f2c4f446846a53f33bd965e2662d/src/lib.rs#L261
23-
if font_options.load_system_fonts {
24-
fontdb.load_system_fonts();
25-
}
21+
// 加载系统字体
22+
// https://github.com/RazrFalcon/fontdb/blob/052d74b9eb45f2c4f446846a53f33bd965e2662d/src/lib.rs#L261
23+
if font_options.load_system_fonts {
24+
fontdb.load_system_fonts();
25+
}
2626

27-
// 加载指定路径的字体
28-
for path in &font_options.font_files {
29-
if let Err(e) = fontdb.load_font_file(path) {
30-
warn!("Failed to load '{}' cause {}.", path, e);
27+
// 加载指定路径的字体
28+
for path in &font_options.font_files {
29+
if let Err(e) = fontdb.load_font_file(path) {
30+
warn!("Failed to load '{}' cause {}.", path, e);
31+
}
3132
}
32-
}
3333

34-
// Load font directories
35-
for path in &font_options.font_dirs {
36-
fontdb.load_fonts_dir(path);
37-
}
34+
// Load font directories
35+
for path in &font_options.font_dirs {
36+
fontdb.load_fonts_dir(path);
37+
}
3838

39-
// Set generic font families
40-
// - `serif` - Times New Roman
41-
// - `sans-serif` - Arial
42-
// - `cursive` - Comic Sans MS
43-
// - `fantasy` - Impact (Papyrus on macOS)
44-
// - `monospace` - Courier New
45-
fontdb.set_serif_family(&font_options.serif_family);
46-
fontdb.set_sans_serif_family(&font_options.sans_serif_family);
47-
fontdb.set_cursive_family(&font_options.cursive_family);
48-
fontdb.set_fantasy_family(&font_options.fantasy_family);
49-
fontdb.set_monospace_family(&font_options.monospace_family);
50-
debug!(
51-
"Loaded {} font faces in {}ms.",
52-
fontdb.len(),
53-
now.elapsed().as_micros() as f64 / 1000.0
54-
);
39+
// Set generic font families
40+
// - `serif` - Times New Roman
41+
// - `sans-serif` - Arial
42+
// - `cursive` - Comic Sans MS
43+
// - `fantasy` - Impact (Papyrus on macOS)
44+
// - `monospace` - Courier New
45+
fontdb.set_serif_family(&font_options.serif_family);
46+
fontdb.set_sans_serif_family(&font_options.sans_serif_family);
47+
fontdb.set_cursive_family(&font_options.cursive_family);
48+
fontdb.set_fantasy_family(&font_options.fantasy_family);
49+
fontdb.set_monospace_family(&font_options.monospace_family);
50+
debug!(
51+
"Loaded {} font faces in {}ms.",
52+
fontdb.len(),
53+
now.elapsed().as_micros() as f64 / 1000.0
54+
);
5555

56-
// 查找指定字体的路径
57-
let font_family: &str = &font_options.default_font_family;
58-
let query = fontdb::Query {
59-
families: &[fontdb::Family::Name(font_family)],
60-
..fontdb::Query::default()
61-
};
56+
// 查找指定字体的路径
57+
let font_family: &str = &font_options.default_font_family;
58+
let query = fontdb::Query {
59+
families: &[fontdb::Family::Name(font_family)],
60+
..fontdb::Query::default()
61+
};
6262

63-
let now = std::time::Instant::now();
64-
// 当前使用的字体是否存在
65-
match fontdb.query(&query) {
66-
Some(id) => {
67-
let (src, index) = fontdb.face_source(id).unwrap();
68-
if let fontdb::Source::File(ref path) = &src {
69-
debug!(
70-
"Font '{}':{} found in {}ms.",
71-
path.display(),
72-
index,
73-
now.elapsed().as_micros() as f64 / 1000.0
74-
);
75-
}
76-
}
77-
None => {
78-
warn!("Warning: The default font '{}' not found.", font_family);
63+
let now = std::time::Instant::now();
64+
// 当前使用的字体是否存在
65+
match fontdb.query(&query) {
66+
Some(id) => {
67+
let (src, index) = fontdb.face_source(id).unwrap();
68+
if let fontdb::Source::File(ref path) = &src {
69+
debug!(
70+
"Font '{}':{} found in {}ms.",
71+
path.display(),
72+
index,
73+
now.elapsed().as_micros() as f64 / 1000.0
74+
);
75+
}
76+
}
77+
None => {
78+
warn!("Warning: The default font '{}' not found.", font_family);
79+
}
7980
}
80-
}
8181

82-
fontdb
82+
fontdb
8383
}

0 commit comments

Comments
 (0)