diff --git a/engine/src/xetex_font_manager_fontconfig.rs b/engine/src/xetex_font_manager_fontconfig.rs index a65826772c..1b71ea4442 100644 --- a/engine/src/xetex_font_manager_fontconfig.rs +++ b/engine/src/xetex_font_manager_fontconfig.rs @@ -568,121 +568,107 @@ pub unsafe extern "C" fn XeTeXFontMgr_FC_searchForHostPlatformFonts( } else { hyph = 0i32 } - let mut found: bool = 0i32 != 0; + let mut found = false; loop { - let mut f: libc::c_int = 0i32; - while f < (*(*real_self).allFonts).nfont { + 'traverse_fonts: for f in 0..(*(*real_self).allFonts).nfont { let mut pat: *mut FcPattern = *(*(*real_self).allFonts).fonts.offset(f as isize); if !(*(*self_0).m_platformRefToFont).contains_key(&pat) { - if (*real_self).cachedAll { - // failed to find it via FC; add everything to our maps (potentially slow) as a last resort - let mut names: *mut XeTeXFontMgrNameCollection = + continue; + } + + if (*real_self).cachedAll { + // failed to find it via FC; add everything to our maps (potentially slow) as a last resort + let mut names: *mut XeTeXFontMgrNameCollection = + XeTeXFontMgr_readNames(self_0, pat); + XeTeXFontMgr_addToMaps(self_0, pat, names); + XeTeXFontMgrNameCollection_delete(names); + continue; + } + + let mut s: *mut libc::c_char = 0 as *mut libc::c_char; + let mut i = 0; + while FcPatternGetString( + pat, + b"fullname\x00" as *const u8 as *const libc::c_char, + i, + &mut s as *mut *mut libc::c_char as *mut *mut FcChar8, + ) == FcResultMatch + { + if CStr::from_ptr(name) == CStr::from_ptr(s) { + let mut names_0: *mut XeTeXFontMgrNameCollection = XeTeXFontMgr_readNames(self_0, pat); - XeTeXFontMgr_addToMaps(self_0, pat, names); - XeTeXFontMgrNameCollection_delete(names); - } else { - let mut s: *mut libc::c_char = 0 as *mut libc::c_char; - let mut i: libc::c_int = 0; - i = 0i32; - let mut current_block: u64; - loop { - if !(FcPatternGetString( - pat, - b"fullname\x00" as *const u8 as *const libc::c_char, - i, - &mut s as *mut *mut libc::c_char as *mut *mut FcChar8, - ) as libc::c_uint - == FcResultMatch as libc::c_int as libc::c_uint) - { - current_block = 3437258052017859086; - break; - } - if CStr::from_ptr(name) == CStr::from_ptr(s) { - let mut names_0: *mut XeTeXFontMgrNameCollection = - XeTeXFontMgr_readNames(self_0, pat); - XeTeXFontMgr_addToMaps(self_0, pat, names_0); - XeTeXFontMgr_cacheFamilyMembers(self_0, (*names_0).m_familyNames); - XeTeXFontMgrNameCollection_delete(names_0); - found = 1i32 != 0; - current_block = 12209867499936983673; - break; - } else { - i += 1 - } - } - match current_block { - 12209867499936983673 => {} - _ => { - i = 0i32; - 's_144: while FcPatternGetString( - pat, - b"family\x00" as *const u8 as *const libc::c_char, - i, - &mut s as *mut *mut libc::c_char as *mut *mut FcChar8, - ) as libc::c_uint - == FcResultMatch as libc::c_int as libc::c_uint - { - if CStr::from_ptr(name) == CStr::from_ptr(s) - || hyph != 0 && (&**famName == CStr::from_ptr(s)) - { - let mut names_1: *mut XeTeXFontMgrNameCollection = - XeTeXFontMgr_readNames(self_0, pat); - XeTeXFontMgr_addToMaps(self_0, pat, names_1); - XeTeXFontMgr_cacheFamilyMembers( - self_0, - (*names_1).m_familyNames, - ); - XeTeXFontMgrNameCollection_delete(names_1); - found = 1i32 != 0; - break; - } else { - let mut t: *mut libc::c_char = 0 as *mut libc::c_char; - let mut j: libc::c_int = 0i32; - while FcPatternGetString( - pat, - b"style\x00" as *const u8 as *const libc::c_char, - j, - &mut t as *mut *mut libc::c_char as *mut *mut FcChar8, - ) as libc::c_uint - == FcResultMatch as libc::c_int as libc::c_uint - { - let mut full: *mut CppStdString = CppStdString_create(); - CppStdString_append_const_char_ptr(full, s); - CppStdString_append_const_char_ptr( - full, - b" \x00" as *const u8 as *const libc::c_char, - ); - CppStdString_append_const_char_ptr(full, t); - let mut matched: bool = &**full == CStr::from_ptr(name); - CppStdString_delete(full); - if matched { - let mut names_2: *mut XeTeXFontMgrNameCollection = - XeTeXFontMgr_readNames(self_0, pat); - XeTeXFontMgr_addToMaps(self_0, pat, names_2); - XeTeXFontMgr_cacheFamilyMembers( - self_0, - (*names_2).m_familyNames, - ); - XeTeXFontMgrNameCollection_delete(names_2); - found = 1i32 != 0; - break 's_144; - } else { - j += 1 - } - } - i += 1 - } - } - } + XeTeXFontMgr_addToMaps(self_0, pat, names_0); + XeTeXFontMgr_cacheFamilyMembers(self_0, (*names_0).m_familyNames); + XeTeXFontMgrNameCollection_delete(names_0); + found = true; + continue 'traverse_fonts; + } + i += 1; + } + + let mut i = 0; + while FcPatternGetString( + pat, + b"family\x00" as *const u8 as *const libc::c_char, + i, + &mut s as *mut *mut libc::c_char as *mut *mut FcChar8, + ) == FcResultMatch + { + if CStr::from_ptr(name) == CStr::from_ptr(s) + || hyph != 0 && (&**famName == CStr::from_ptr(s)) + { + let mut names_1: *mut XeTeXFontMgrNameCollection = + XeTeXFontMgr_readNames(self_0, pat); + XeTeXFontMgr_addToMaps(self_0, pat, names_1); + XeTeXFontMgr_cacheFamilyMembers( + self_0, + (*names_1).m_familyNames, + ); + XeTeXFontMgrNameCollection_delete(names_1); + found = true; + continue 'traverse_fonts; + } + + let mut t: *mut libc::c_char = 0 as _; + let mut j = 0; + while FcPatternGetString( + pat, + b"style\x00" as *const u8 as *const libc::c_char, + j, + &mut t as *mut *mut libc::c_char as *mut *mut FcChar8, + ) == FcResultMatch + { + let mut full: *mut CppStdString = CppStdString_create(); + CppStdString_append_const_char_ptr(full, s); + CppStdString_append_const_char_ptr( + full, + b" \x00" as *const u8 as *const libc::c_char, + ); + CppStdString_append_const_char_ptr(full, t); + let mut matched: bool = &**full == CStr::from_ptr(name); + CppStdString_delete(full); + if matched { + let mut names_2: *mut XeTeXFontMgrNameCollection = + XeTeXFontMgr_readNames(self_0, pat); + XeTeXFontMgr_addToMaps(self_0, pat, names_2); + XeTeXFontMgr_cacheFamilyMembers( + self_0, + (*names_2).m_familyNames, + ); + XeTeXFontMgrNameCollection_delete(names_2); + found = true; + continue 'traverse_fonts; } + j += 1; } + i += 1; } - f += 1 } - if found as libc::c_int != 0 || (*real_self).cachedAll as libc::c_int != 0 { + + if found || (*real_self).cachedAll { break; } - (*real_self).cachedAll = 1i32 != 0 + (*real_self).cachedAll = true; } CppStdString_delete(famName); } diff --git a/engine/src/xetex_io.rs b/engine/src/xetex_io.rs index 34cede3faf..186a5b4999 100644 --- a/engine/src/xetex_io.rs +++ b/engine/src/xetex_io.rs @@ -629,96 +629,47 @@ pub unsafe extern "C" fn u_close(mut f: *mut UFILE) { } #[no_mangle] pub unsafe extern "C" fn get_uni_c(mut f: *mut UFILE) -> i32 { - let mut current_block: u64; let mut rval: i32 = 0; let mut c: i32 = 0; - if (*f).savedChar != -1i32 as i64 { + if (*f).savedChar != -1 { rval = (*f).savedChar as i32; - (*f).savedChar = -1i32 as i64; + (*f).savedChar = -1; return rval; } let handle = (*f).handle.as_mut().unwrap(); - match (*f).encodingMode as i32 { + match (*f).encodingMode { 1 => { rval = ttstub_input_getc(handle); c = rval; - if rval != -1i32 { + if rval != -1 { let mut extraBytes: u16 = bytesFromUTF8[rval as usize] as u16; - match extraBytes as i32 { - 3 => { - /* note: code falls through cases! */ - c = ttstub_input_getc(handle); - if c < 0x80i32 || c >= 0xc0i32 { - current_block = 4870039662467851697; - } else { - rval <<= 6i32; + match extraBytes { + 0..=3 => { + for _ in 0..extraBytes { + c = ttstub_input_getc(handle); + if c < 0x80 || c >= 0xC0 { + if c != -1 { + ttstub_input_ungetc(handle, c); + } + bad_utf8_warning(); + return 0xFFFD; /* return without adjusting by offsetsFromUTF8 */ + } + rval <<= 6; rval += c; - current_block = 11439173586221378108; } } - 2 => { - current_block = 11439173586221378108; - } - 1 => { - current_block = 223857376187897572; - } 5 | 4 => { - current_block = 8891683451182524030; - } - 0 | _ => { - current_block = 15925075030174552612; - } - } - match current_block { - 11439173586221378108 => { - c = ttstub_input_getc(handle); - if c < 0x80i32 || c >= 0xc0i32 { - current_block = 4870039662467851697; - } else { - rval <<= 6i32; - rval += c; - current_block = 223857376187897572; - } - } - _ => {} - } - match current_block { - 223857376187897572 => { - c = ttstub_input_getc(handle); - if c < 0x80i32 || c >= 0xc0i32 { - current_block = 4870039662467851697; - } else { - rval <<= 6i32; - rval += c; - current_block = 15925075030174552612; - } - } - _ => {} - } - match current_block { - 15925075030174552612 => { - rval = (rval as u32).wrapping_sub(offsetsFromUTF8[extraBytes as usize]) - as i32 as i32; - if rval < 0i32 || rval > 0x10ffffi32 { - bad_utf8_warning(); - return 0xfffdi32; - } - current_block = 317151059986244064; - } - 4870039662467851697 => { - if c != -1i32 { - ttstub_input_ungetc(handle, c); - } - current_block = 8891683451182524030; + bad_utf8_warning(); + return 0xFFFD; /* return without adjusting by offsetsFromUTF8 */ } _ => {} } - match current_block { - 317151059986244064 => {} - _ => { - bad_utf8_warning(); - return 0xfffdi32; - } + + rval -= offsetsFromUTF8[extraBytes as usize] as i32; + + if rval < 0 || rval > 0x10ffff { + bad_utf8_warning(); + return 0xfffd; } } } @@ -789,84 +740,15 @@ pub unsafe extern "C" fn make_utf16_name() { t = name_of_file16; while s < (name_of_file as *mut u8).offset(name_length as isize) { let mut extraBytes: u16 = 0; - let fresh7 = s; + rval = *s as u32; s = s.offset(1); - rval = *fresh7 as u32; extraBytes = bytesFromUTF8[rval as usize] as u16; - let mut current_block_23: u64; - match extraBytes as i32 { - 5 => { - /* note: code falls through cases! */ - rval <<= 6i32; - if *s != 0 { - let fresh8 = s; - s = s.offset(1); - rval = (rval as u32).wrapping_add(*fresh8 as u32) as u32 - } - current_block_23 = 1933956893526356233; - } - 4 => { - current_block_23 = 1933956893526356233; - } - 3 => { - current_block_23 = 15901505722045918842; - } - 2 => { - current_block_23 = 5484884370842436748; - } - 1 => { - current_block_23 = 1843389027537967668; - } - 0 | _ => { - current_block_23 = 14648156034262866959; - } - } - match current_block_23 { - 1933956893526356233 => { - rval <<= 6i32; - if *s != 0 { - let fresh9 = s; - s = s.offset(1); - rval = (rval as u32).wrapping_add(*fresh9 as u32) as u32 - } - current_block_23 = 15901505722045918842; - } - _ => {} - } - match current_block_23 { - 15901505722045918842 => { - rval <<= 6i32; - if *s != 0 { - let fresh10 = s; - s = s.offset(1); - rval = (rval as u32).wrapping_add(*fresh10 as u32) as u32 - } - current_block_23 = 5484884370842436748; - } - _ => {} - } - match current_block_23 { - 5484884370842436748 => { - rval <<= 6i32; - if *s != 0 { - let fresh11 = s; - s = s.offset(1); - rval = (rval as u32).wrapping_add(*fresh11 as u32) as u32 - } - current_block_23 = 1843389027537967668; - } - _ => {} - } - match current_block_23 { - 1843389027537967668 => { - rval <<= 6i32; - if *s != 0 { - let fresh12 = s; - s = s.offset(1); - rval = (rval as u32).wrapping_add(*fresh12 as u32) as u32 - } + for _ in 0..extraBytes { + rval <<= 6; + if *s != 0 { + rval = (rval as u32).wrapping_add(*s as u32); + s = s.offset(1); } - _ => {} } rval = (rval as u32).wrapping_sub(offsetsFromUTF8[extraBytes as usize]) as u32; if rval > 0xffff_u32 { diff --git a/engine/src/xetex_linebreak.rs b/engine/src/xetex_linebreak.rs index 5d57c86570..2385ae5df7 100644 --- a/engine/src/xetex_linebreak.rs +++ b/engine/src/xetex_linebreak.rs @@ -4003,7 +4003,6 @@ unsafe extern "C" fn reconstitute( j } unsafe extern "C" fn total_pw(mut q: i32, mut p: i32) -> scaled_t { - let mut current_block: u64; let mut l: i32 = 0; let mut r: i32 = 0; let mut n: i32 = 0; @@ -4029,7 +4028,7 @@ unsafe extern "C" fn total_pw(mut q: i32, mut p: i32) -> scaled_t { if l != -0xfffffffi32 && (*mem.offset(l as isize)).b16.s1 as i32 == 7i32 { if (*mem.offset((l + 1i32) as isize)).b32.s1 != -0xfffffffi32 { l = (*mem.offset((l + 1i32) as isize)).b32.s1; - current_block = 15424580701460361554; + return char_pw(l, 0) + char_pw(r, 1); } else { n = (*mem.offset(l as isize)).b16.s0 as i32; l = (*mem.offset(l as isize)).b32.s1; @@ -4039,16 +4038,10 @@ unsafe extern "C" fn total_pw(mut q: i32, mut p: i32) -> scaled_t { } n -= 1 } - current_block = 15089075282327824602; } - } else { - current_block = 15089075282327824602; - } - match current_block { - 15089075282327824602 => l = find_protchar_left(l, 1i32 != 0), - _ => {} } - char_pw(l, 0i32 as small_number) + char_pw(r, 1i32 as small_number) + l = find_protchar_left(l, true); + char_pw(l, 0) + char_pw(r, 1) } unsafe extern "C" fn find_protchar_left(mut l: i32, mut d: bool) -> i32 { let mut t: i32 = 0;