Skip to content

Commit

Permalink
add missing api for vn::RecognizeTextRequest. Refs #29
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Dec 5, 2024
1 parent 1ef660f commit b6b685c
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions cidre/src/vn/recognize_text_request.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -33,9 +34,105 @@ impl RecognizeTextRequest {

#[objc::msg_send(results)]
pub fn results(&self) -> Option<arc::R<ns::Array<vn::RecognizedTextObservation>>>;

#[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<arc::R<ns::Array<ns::String>>>;

#[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<arc::R<ns::Array<ns::String>>> {
ns::if_none(|err| unsafe { self.supported_recognition_langs_err(err) })
}

#[objc::msg_send(recognitionLanguages)]
pub fn recognition_langs(&self) -> arc::R<ns::Array<ns::String>>;

#[objc::msg_send(setRecognitionLanguages:)]
pub fn set_recognition_langs(&mut self, val: &ns::Array<ns::String>);

#[objc::msg_send(customWords)]
pub fn custom_words(&self) -> arc::R<ns::Array<ns::String>>;

#[objc::msg_send(setCustomWords:)]
pub fn set_custom_words(&mut self, val: &ns::Array<ns::String>);

#[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<RecognizeTextRequest>;
}

#[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());
}
}

0 comments on commit b6b685c

Please sign in to comment.