From b6b685ca0c84ed7f8c8344503561fe44adf68eef Mon Sep 17 00:00:00 2001 From: Yury Date: Fri, 6 Dec 2024 00:55:53 +0300 Subject: [PATCH] add missing api for vn::RecognizeTextRequest. Refs #29 --- cidre/src/vn/recognize_text_request.rs | 97 ++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/cidre/src/vn/recognize_text_request.rs b/cidre/src/vn/recognize_text_request.rs index 072512f5..009f7aa3 100644 --- a/cidre/src/vn/recognize_text_request.rs +++ b/cidre/src/vn/recognize_text_request.rs @@ -1,5 +1,6 @@ use crate::{arc, define_obj_type, ns, objc, vn}; +#[derive(Debug, Eq, PartialEq, Copy, Clone)] #[repr(isize)] pub enum RecognitionLevel { Accurate = 0, @@ -33,9 +34,105 @@ impl RecognizeTextRequest { #[objc::msg_send(results)] pub fn results(&self) -> Option>>; + + #[objc::msg_send(supportedRecognitionLanguagesAndReturnError:)] + #[objc::available( + macos = 12.0, + maccatalyst = 15.0, + ios = 15.0, + tvos = 15.0, + visionos = 1.0 + )] + pub unsafe fn supported_recognition_langs_err<'ear>( + &self, + err: *mut Option<&'ear ns::Error>, + ) -> Option>>; + + #[objc::available( + macos = 12.0, + maccatalyst = 15.0, + ios = 15.0, + tvos = 15.0, + visionos = 1.0 + )] + pub fn supported_recognition_langs(&self) -> ns::Result>> { + ns::if_none(|err| unsafe { self.supported_recognition_langs_err(err) }) + } + + #[objc::msg_send(recognitionLanguages)] + pub fn recognition_langs(&self) -> arc::R>; + + #[objc::msg_send(setRecognitionLanguages:)] + pub fn set_recognition_langs(&mut self, val: &ns::Array); + + #[objc::msg_send(customWords)] + pub fn custom_words(&self) -> arc::R>; + + #[objc::msg_send(setCustomWords:)] + pub fn set_custom_words(&mut self, val: &ns::Array); + + #[objc::msg_send(recognitionLevel)] + pub fn recognition_level(&self) -> RecognitionLevel; + + #[objc::msg_send(setRecognitionLevel:)] + pub fn set_recognition_level(&mut self, val: RecognitionLevel); + + #[objc::msg_send(usesLanguageCorrection)] + pub fn uses_lang_correction(&self) -> bool; + + #[objc::msg_send(setUsesLanguageCorrection:)] + pub fn set_uses_lang_correction(&mut self, val: bool); + + #[objc::msg_send(automaticallyDetectsLanguage)] + #[objc::available( + macos = 13.0, + maccatalyst = 16.0, + ios = 16.0, + tvos = 16.0, + visionos = 1.0 + )] + pub fn automatically_detects_lang(&self) -> bool; + + #[objc::msg_send(setAutomaticallyDetectsLanguage:)] + #[objc::available( + macos = 13.0, + maccatalyst = 16.0, + ios = 16.0, + tvos = 16.0, + visionos = 1.0 + )] + pub fn set_automatically_detects_lang(&mut self, val: bool); + + #[objc::msg_send(minimumTextHeight)] + pub fn min_text_height(&self) -> f32; + + #[objc::msg_send(setMinimumTextHeight:)] + pub fn set_min_text_height(&mut self, val: f32); } #[link(name = "vn", kind = "static")] extern "C" { static VN_RECOGNIZE_TEXT_REQUEST: &'static objc::Class; } + +#[cfg(test)] +mod tests { + use crate::vn; + + #[test] + fn basics() { + let mut request = vn::RecognizeTextRequest::new(); + request.set_min_text_height(10.0); + let langs = request.supported_recognition_langs().unwrap(); + assert!(!langs.is_empty()); + + request.set_uses_lang_correction(true); + request.set_recognition_level(vn::RequestTextRecognitionLevel::Accurate); + + assert!(!request.automatically_detects_lang()); + request.set_automatically_detects_lang(true); + assert!(request.automatically_detects_lang()); + + assert!(request.custom_words().is_empty()); + } +}