mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Fix various clippy warnings on OpenHarmony (#34281)
* ohos: Fix more clippy warnings Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com> Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> * Remove unnecessary `macro_use` We can use `use` instead. Removes a warning about unused macro_use on OpenHarmony. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> --------- Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com> Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
parent
caf2467649
commit
09684a3501
8 changed files with 37 additions and 51 deletions
|
@ -22,16 +22,16 @@ use crate::{
|
|||
FontTemplateDescriptor, LocalFontIdentifier, LowercaseFontFamilyName,
|
||||
};
|
||||
|
||||
static FONT_LIST: LazyLock<FontList> = LazyLock::new(|| FontList::new());
|
||||
static FONT_LIST: LazyLock<FontList> = LazyLock::new(FontList::new);
|
||||
|
||||
/// When testing the ohos font code on linux, we can pass the fonts directory of the SDK
|
||||
/// via an environment variable.
|
||||
#[cfg(ohos_mock)]
|
||||
static OHOS_FONTS_DIR: &'static str = env!("OHOS_SDK_FONTS_DIR");
|
||||
static OHOS_FONTS_DIR: &str = env!("OHOS_SDK_FONTS_DIR");
|
||||
|
||||
/// On OpenHarmony devices the fonts are always located here.
|
||||
#[cfg(not(ohos_mock))]
|
||||
static OHOS_FONTS_DIR: &'static str = "/system/fonts";
|
||||
static OHOS_FONTS_DIR: &str = "/system/fonts";
|
||||
|
||||
#[allow(unused)]
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
|
@ -80,15 +80,13 @@ struct FontList {
|
|||
|
||||
fn enumerate_font_files() -> io::Result<Vec<PathBuf>> {
|
||||
let mut font_list = vec![];
|
||||
for elem in fs::read_dir(OHOS_FONTS_DIR)? {
|
||||
if let Ok(e) = elem {
|
||||
if e.file_type().unwrap().is_file() {
|
||||
let name = e.file_name();
|
||||
let raw_name = name.as_bytes();
|
||||
if raw_name.ends_with(b".ttf".as_ref()) || raw_name.ends_with(b".ttc".as_ref()) {
|
||||
debug!("Found font {}", e.file_name().to_str().unwrap());
|
||||
font_list.push(e.path())
|
||||
}
|
||||
for elem in fs::read_dir(OHOS_FONTS_DIR)?.flatten() {
|
||||
if elem.file_type().unwrap().is_file() {
|
||||
let name = elem.file_name();
|
||||
let raw_name = name.as_bytes();
|
||||
if raw_name.ends_with(b".ttf".as_ref()) || raw_name.ends_with(b".ttc".as_ref()) {
|
||||
debug!("Found font {}", elem.file_name().to_str().unwrap());
|
||||
font_list.push(elem.path())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,7 +174,7 @@ fn split_noto_font_name(name: &str) -> Vec<String> {
|
|||
}
|
||||
}
|
||||
}
|
||||
if current_word.len() > 0 {
|
||||
if !current_word.is_empty() {
|
||||
name_components.push(current_word);
|
||||
}
|
||||
name_components
|
||||
|
@ -291,11 +289,10 @@ fn parse_font_filenames(font_files: Vec<PathBuf>) -> Vec<FontFamily> {
|
|||
}
|
||||
}
|
||||
|
||||
let families = families
|
||||
families
|
||||
.into_iter()
|
||||
.map(|(name, fonts)| FontFamily { name, fonts })
|
||||
.collect();
|
||||
families
|
||||
.collect()
|
||||
}
|
||||
|
||||
impl FontList {
|
||||
|
@ -310,7 +307,7 @@ impl FontList {
|
|||
fn detect_installed_font_families() -> Vec<FontFamily> {
|
||||
let mut families = enumerate_font_files()
|
||||
.inspect_err(|e| error!("Failed to enumerate font files due to `{e:?}`"))
|
||||
.and_then(|font_files| Ok(parse_font_filenames(font_files)))
|
||||
.map(|font_files| parse_font_filenames(font_files))
|
||||
.unwrap_or_else(|_| FontList::fallback_font_families());
|
||||
families.extend(Self::hardcoded_font_families());
|
||||
families
|
||||
|
@ -325,14 +322,14 @@ impl FontList {
|
|||
FontFamily {
|
||||
name: "HMOS Color Emoji".to_string(),
|
||||
fonts: vec![Font {
|
||||
filepath: FontList::font_absolute_path("HMOSColorEmojiCompat.ttf".into()),
|
||||
filepath: FontList::font_absolute_path("HMOSColorEmojiCompat.ttf"),
|
||||
..Default::default()
|
||||
}],
|
||||
},
|
||||
FontFamily {
|
||||
name: "HMOS Color Emoji Flags".to_string(),
|
||||
fonts: vec![Font {
|
||||
filepath: FontList::font_absolute_path("HMOSColorEmojiFlags.ttf".into()),
|
||||
filepath: FontList::font_absolute_path("HMOSColorEmojiFlags.ttf"),
|
||||
..Default::default()
|
||||
}],
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue