kobo_core/rendering/
common.rs1use std::sync::atomic::{AtomicBool, Ordering};
6
7static IS_RTL: AtomicBool = AtomicBool::new(false);
8
9pub fn set_rtl(rtl: bool) {
10 IS_RTL.store(rtl, Ordering::Relaxed);
11}
12
13pub fn is_rtl() -> bool {
14 IS_RTL.load(Ordering::Relaxed)
15}
16
17pub fn lang_is_rtl(lang: Option<&str>) -> bool {
21 let prefix = lang
22 .and_then(|l| l.split('-').next())
23 .unwrap_or("")
24 .to_ascii_lowercase();
25 matches!(
26 prefix.as_str(),
27 "ar" | "ur" | "fa" | "he" | "yi" | "ps" | "sd"
28 )
29}
30
31pub const BODY_PX: f32 = 36.0;
32
33pub fn slice_as_bytes<T>(buf: &[T]) -> &[u8] {
38 unsafe { std::slice::from_raw_parts(buf.as_ptr() as *const u8, std::mem::size_of_val(buf)) }
39}
40
41pub fn slice_as_bytes_mut<T>(buf: &mut [T]) -> &mut [u8] {
45 unsafe {
46 std::slice::from_raw_parts_mut(buf.as_mut_ptr() as *mut u8, std::mem::size_of_val(buf))
47 }
48}