Merge branch 'imbris/fix-font-selection' into 'master'

Properly use localization specified fonts, fix swedish translation by adding...

Closes #834

See merge request veloren/veloren!1521
This commit is contained in:
Imbris 2020-11-15 03:18:29 +00:00
commit 4872d285c3
6 changed files with 66 additions and 12 deletions

View File

@ -23,7 +23,24 @@
asset_key: "voxygen.font.OpenSans-Regular",
scale_ratio: 1.0,
),
"metamorph": Font (
asset_key: "voxygen.font.Metamorphous-Regular",
scale_ratio: 1.0,
),
"alkhemi": Font (
asset_key: "voxygen.font.Alkhemikal",
scale_ratio: 1.0,
),
"wizard": Font (
asset_key: "voxygen.font.wizard",
scale_ratio: 1.0,
),
"cyri": Font (
asset_key: "voxygen.font.haxrcorp_4089_cyrillic_altgr_extended",
scale_ratio: 1.0,
),
},
string_map: {
/// Start Common section
// Texts used in multiple locations with the same formatting

View File

@ -1404,12 +1404,10 @@ impl CharSelectionUi {
let font = {
use std::io::Read;
let mut buf = Vec::new();
common::assets::load_file("voxygen.font.haxrcorp_4089_cyrillic_altgr_extended", &[
"ttf",
])
.unwrap()
.read_to_end(&mut buf)
.unwrap();
common::assets::load_file(&i18n.fonts.get("cyri").unwrap().asset_key, &["ttf"])
.unwrap()
.read_to_end(&mut buf)
.unwrap();
ui::ice::Font::try_from_vec(buf).unwrap()
};
@ -1472,7 +1470,17 @@ impl CharSelectionUi {
}
pub fn update_language(&mut self, i18n: std::sync::Arc<Localization>) {
let font = {
use std::io::Read;
let mut buf = Vec::new();
common::assets::load_file(&i18n.fonts.get("cyri").unwrap().asset_key, &["ttf"])
.unwrap()
.read_to_end(&mut buf)
.unwrap();
ui::ice::Font::try_from_vec(buf).unwrap()
};
self.controls.i18n = i18n;
self.ui.clear_fonts(font);
self.controls.fonts = Fonts::load(&self.controls.i18n.fonts, &mut self.ui)
.expect("Impossible to load fonts!");
}

View File

@ -490,12 +490,10 @@ impl<'a> MainMenuUi {
let font = {
use std::io::Read;
let mut buf = Vec::new();
common::assets::load_file("voxygen.font.haxrcorp_4089_cyrillic_altgr_extended", &[
"ttf",
])
.unwrap()
.read_to_end(&mut buf)
.unwrap();
common::assets::load_file(&i18n.fonts.get("cyri").unwrap().asset_key, &["ttf"])
.unwrap()
.read_to_end(&mut buf)
.unwrap();
Font::try_from_vec(buf).unwrap()
};
@ -522,7 +520,17 @@ impl<'a> MainMenuUi {
}
pub fn update_language(&mut self, i18n: std::sync::Arc<Localization>, settings: &Settings) {
let font = {
use std::io::Read;
let mut buf = Vec::new();
common::assets::load_file(&i18n.fonts.get("cyri").unwrap().asset_key, &["ttf"])
.unwrap()
.read_to_end(&mut buf)
.unwrap();
Font::try_from_vec(buf).unwrap()
};
self.controls.i18n = i18n;
self.ui.clear_fonts(font);
self.controls.fonts = Fonts::load(&self.controls.i18n.fonts, &mut self.ui)
.expect("Impossible to load fonts!");
let language_metadatas = crate::i18n::list_localizations();

View File

@ -69,6 +69,21 @@ impl Cache {
FontId(id)
}
/// Allows clearing out the fonts when switching languages
pub fn clear_fonts(&mut self, default_font: Font) {
self.glyph_brush = RefCell::new(
self.glyph_brush
.get_mut()
.to_builder()
.replace_fonts(|mut fonts| {
fonts.clear();
fonts.push(default_font);
fonts
})
.build(),
);
}
pub fn graphic_cache(&self) -> &GraphicCache { &self.graphic_cache }
pub fn graphic_cache_mut(&mut self) -> &mut GraphicCache { &mut self.graphic_cache }

View File

@ -65,6 +65,9 @@ impl IcedUi {
/// Add a new font that is referncable via the returned Id
pub fn add_font(&mut self, font: RawFont) -> FontId { self.renderer.add_font(font) }
/// Allows clearing out the fonts when switching languages
pub fn clear_fonts(&mut self, default_font: Font) { self.renderer.clear_fonts(default_font); }
/// Add a new graphic that is referencable via the returned Id
pub fn add_graphic(&mut self, graphic: Graphic) -> graphic::Id {
self.renderer.add_graphic(graphic)

View File

@ -146,6 +146,9 @@ impl IcedRenderer {
pub fn add_font(&mut self, font: RawFont) -> FontId { self.cache.add_font(font) }
/// Allows clearing out the fonts when switching languages
pub fn clear_fonts(&mut self, default_font: Font) { self.cache.clear_fonts(default_font); }
pub fn add_graphic(&mut self, graphic: Graphic) -> graphic::Id {
self.cache.add_graphic(graphic)
}