From 22e5f7bda14133bf8d331e1baded0b284318f180 Mon Sep 17 00:00:00 2001 From: bluepython508 <16466646+bluepython508@users.noreply.github.com> Date: Mon, 23 Feb 2026 12:12:34 +0000 Subject: [PATCH] Drop document_get_information: it was failing for no apparent reason anyway --- src/lib.rs | 165 +---------------------------------------------------- 1 file changed, 2 insertions(+), 163 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c5067bc..6de89e3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,11 +58,11 @@ pub static zathura_plugin_6_7: zathura::zathura_plugin_definition_s = document_save_as: Some(document_save_as), document_attachments_get: None, document_attachment_save: None, - document_get_information: Some(document_get_information), + document_get_information: None, page_init: Some(page_init), page_clear: Some(page_clear), page_search_text: None, // TODO? - page_links_get: Some(page_links_get), + page_links_get: None page_form_fields_get: None, page_images_get: None, // TODO? page_image_get_cairo: None, @@ -102,71 +102,6 @@ unsafe extern "C" fn document_free(_: *mut zathura_document_s, data: *mut c_void ZathuraResult::OK } -unsafe extern "C" fn document_get_information( - _: *mut zathura_document_s, - doc: *mut c_void, - res: *mut ZathuraResult, -) -> *mut girara_list_t { - let res = if let Some(mut r) = NonNull::new(res) { - unsafe { - r.write(ZathuraResult::Unknown); - r.as_mut() - } - } else { - &mut ZathuraResult::OK - }; - - let doc = unsafe { &mut *(doc as *mut TypstDocument) }; - let i = &doc.doc.info; - let mut lst = unsafe { - GiraraList::::from_raw( - zathura_document_information_entry_list_new(), - ) - }; - [ - ( - zathura_document_information_type_e_ZATHURA_DOCUMENT_INFORMATION_TITLE, - i.title.clone().unwrap_or_default().to_string(), - ), - ( - zathura_document_information_type_e_ZATHURA_DOCUMENT_INFORMATION_AUTHOR, - i.author.join(", "), - ), - ( - zathura_document_information_type_e_ZATHURA_DOCUMENT_INFORMATION_KEYWORDS, - i.keywords.join(", "), - ), - ( - zathura_document_information_type_e_ZATHURA_DOCUMENT_INFORMATION_CREATION_DATE, - i.date.unwrap_or_default().map_or(String::new(), |d| { - d.display(Default::default()) - .expect("Defaults do the right thing") - .to_string() - }), - ), - ( - zathura_document_information_type_e_ZATHURA_DOCUMENT_INFORMATION_PRODUCER, - "Typst (via zathura-plugin-typst)".to_owned(), - ), - ] - .into_iter() - .filter(|(_, st)| !st.is_empty()) - .map(|(ty, st)| { - unsafe extern "C" { - safe fn calloc(n: usize, s: usize) -> *mut c_void; - } - let st_m = calloc(st.len() + 1, 1); - unsafe { slice::from_raw_parts_mut(st_m as *mut u8, st.len()) } - .copy_from_slice(st.as_bytes()); - (ty, st_m as *const i8) - }) - .for_each(|(ty, st)| { - unsafe { lst.append_allocated(zathura_document_information_entry_new(ty, st)) }; - }); - *res = ZathuraResult::OK; - lst.into_raw() -} - unsafe extern "C" fn document_save_as( _: *mut zathura_document_s, data: *mut c_void, @@ -409,102 +344,6 @@ unsafe extern "C" fn page_get_selection( .into_raw() } -unsafe extern "C" fn page_links_get( - zpage: *mut zathura_page_t, - page: *mut c_void, - res: *mut ZathuraResult, -) -> *mut girara_list_t { - let res = if let Some(mut r) = NonNull::new(res) { - unsafe { - r.write(ZathuraResult::Unknown); - r.as_mut() - } - } else { - &mut ZathuraResult::OK - }; - let doc = unsafe { - &mut (*(zathura_document_get_data(zathura_page_get_document(zpage)) as *mut TypstDocument)) - }; - - let page: &Page = unsafe { &*(page as *const _) }; - - let links = FrameItemIterator::new(&page.frame) - .filter_map(|(point, item)| { - if let FrameItem::Link(dst, size) = item { - Some((Rect::from_pos_size(point, *size), dst)) - } else { - None - } - }) - .map(|(rect, dst)| { - let (ty, target) = match dst { - Destination::Url(url) => ( - if url.starts_with("file://") { - zathura_link_type_e_ZATHURA_LINK_GOTO_REMOTE - } else { - zathura_link_type_e_ZATHURA_LINK_URI - }, - zathura_link_target_s { - destination_type: - zathura_link_destination_type_e_ZATHURA_LINK_DESTINATION_UNKNOWN, - value: doc - .cstring_cache - .entry(url.to_string()) - .or_insert_with(|| { - CString::new(url.as_bytes()).expect("URL shouldn't contain NUL") - }) - .as_ptr() as *mut i8, - page_number: 0, - left: -1., - right: -1., - top: -1., - bottom: -1., - zoom: 0., - }, - ), - Destination::Position(position) => ( - zathura_link_type_e_ZATHURA_LINK_GOTO_DEST, - zathura_link_target_s { - destination_type: - zathura_link_destination_type_e_ZATHURA_LINK_DESTINATION_XYZ, - value: ptr::null_mut(), - page_number: position.page.get() as u32 - 1, - left: position.point.x.to_pt(), - right: -1., - top: position.point.y.to_pt(), - bottom: -1., - zoom: 0., - }, - ), - Destination::Location(location) => { - let position = doc.doc.introspector().position(*location); - ( - zathura_link_type_e_ZATHURA_LINK_GOTO_DEST, - zathura_link_target_s { - destination_type: - zathura_link_destination_type_e_ZATHURA_LINK_DESTINATION_XYZ, - value: ptr::null_mut(), - page_number: position.page.get() as u32 - 1, - left: position.point.x.to_pt(), - right: -1., - top: position.point.y.to_pt(), - bottom: -1., - zoom: 0., - }, - ) - } - }; - unsafe { zathura_link_new(ty, rect.into(), target) } - }); - - unsafe { - let mut links_ = GiraraList::new_with_free(zathura_link_free); - links_.extend_allocated(links); - *res = ZathuraResult::OK; - links_.into_raw() - } -} - unsafe extern "C" fn page_get_label( zpage: *mut zathura_page_t, page: *mut c_void,