print: Use inch for US and LR

Closes #143

Part-of: <https://gitlab.gnome.org/GNOME/loupe/-/merge_requests/240>
This commit is contained in:
Sophie Herold 2023-07-29 19:24:25 +02:00 • committed by Christopher Davis
parent 172ce9d976
commit aac476134f
3 changed files with 31 additions and 0 deletions

View file

@ -380,6 +380,20 @@ mod imp {
.round(obj.image().image_size().0 as f64 * obj.width_unit_factor()),
);
// Default to inch for USA and Liberia
if let Some(unit_locale) = getlocale(gettextrs::LocaleCategory::LcMeasurement) {
if let Some(locale) = unit_locale
.split(|x| *x == b'_')
.nth(1)
.and_then(|x| x.get(0..2))
{
if locale == b"US" || locale == b"LR" {
imp.margin_unit.set_selected(Unit::Inch as u32);
imp.size_unit.set_selected(Unit::Inch as u32);
}
}
}
imp.print_operation.cancel();
let orientation = match obj.page_setup().orientation() {
@ -902,3 +916,15 @@ extern "C" {
max: std::ffi::c_double,
);
}
// TODO: Upstream to gettext if possible
pub fn getlocale(category: gettextrs::LocaleCategory) -> Option<Vec<u8>> {
unsafe {
let ret = gettext_sys::setlocale(category as i32, std::ptr::null());
if ret.is_null() {
None
} else {
Some(std::ffi::CStr::from_ptr(ret).to_bytes().to_owned())
}
}
}