pub struct LiveTextInteraction { /* private fields */ }Implementations§
Source§impl LiveTextInteraction
impl LiveTextInteraction
Sourcepub fn new() -> Result<Self, VisionKitError>
pub fn new() -> Result<Self, VisionKitError>
Examples found in repository?
examples/02_framework_smoke.rs (line 52)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 println!("== VisionKit.framework smoke ==");
14 println!("ImageAnalyzer supported: {}", ImageAnalyzer::is_supported());
15 println!(
16 "document camera available on macOS: {}",
17 VNDocumentCameraViewController::is_available_on_current_platform()?
18 );
19 println!(
20 "data scanner available on macOS: {}",
21 DataScannerViewController::is_available_on_current_platform()?
22 );
23
24 let languages = ImageAnalyzer::supported_text_recognition_languages()?;
25 println!("supported OCR languages: {}", languages.len());
26 println!(
27 "sample OCR languages: {:?}",
28 languages.iter().take(10).collect::<Vec<_>>()
29 );
30
31 if !ImageAnalyzer::is_supported() {
32 println!("ImageAnalyzer is not supported on this Mac");
33 return Ok(());
34 }
35
36 let analyzer = ImageAnalyzer::new()?;
37 let configuration = ImageAnalyzerConfiguration::new(
38 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
39 )
40 .with_locales(["en-US"]);
41 let asset_path = asset_path();
42 let analysis =
43 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?;
44
45 println!(
46 "has text results: {}",
47 analysis.has_results(ImageAnalysisTypes::TEXT)?
48 );
49 let transcript = analysis.transcript()?;
50 println!("transcript: {transcript:?}");
51
52 let interaction = LiveTextInteraction::new()?;
53 interaction.track_image_at_path(&asset_path)?;
54 interaction.set_analysis(&analysis)?;
55 println!(
56 "overlay preferred types: {}",
57 interaction.preferred_interaction_types()?.bits()
58 );
59 let overlay_text = interaction.text();
60 println!("overlay text: {overlay_text:?}");
61 Ok(())
62}Sourcepub fn with_delegate(
delegate: &LiveTextInteractionDelegate,
) -> Result<Self, VisionKitError>
pub fn with_delegate( delegate: &LiveTextInteractionDelegate, ) -> Result<Self, VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 115)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101 if !ImageAnalyzer::is_supported() {
102 println!("ImageAnalyzer is not supported on this Mac");
103 return Ok(());
104 }
105
106 let asset_path = asset_path();
107 let analyzer = ImageAnalyzer::new()?;
108 let analysis = analyzer.analyze_image_at_path(
109 &asset_path,
110 ImageOrientation::Up,
111 &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112 )?;
113
114 let delegate = build_delegate()?;
115 let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116 let tracking_view = LiveTextTrackingImageView::new()?;
117 tracking_view.set_image_at_path(&asset_path)?;
118 interaction.set_tracking_image_view(Some(&tracking_view))?;
119 interaction.track_image_at_path(&asset_path)?;
120 interaction.set_analysis(&analysis)?;
121 interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122 interaction.set_selectable_items_highlighted(true)?;
123 interaction.set_contents_rect_needs_update()?;
124
125 println!("contents rect: {:?}", interaction.contents_rect()?);
126 println!("overlay text: {:?}", interaction.text());
127 println!("delegate events: {}", delegate.recorded_events()?.len());
128 println!(
129 "delegate content view set: {}",
130 interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131 );
132 match interaction.tracking_image_view()? {
133 Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134 None => println!("tracking image size: none"),
135 }
136 match LiveTextMenuTag::copy_image() {
137 Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138 Err(error) => println!("copy image tag: {error}"),
139 }
140 print_selection_state(&interaction)?;
141 print_subject_state(&interaction)?;
142 println!(
143 "live text button visible: {}",
144 interaction.live_text_button_visible()?
145 );
146 println!(
147 "supplementary hidden: {}",
148 interaction.is_supplementary_interface_hidden()?
149 );
150
151 let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152 LiveTextImageData,
153 VisionKitError,
154 > = LiveTextInteraction::image_for_subjects;
155 black_box(image_for_subjects_fn);
156 Ok(())
157}Sourcepub fn set_analysis(
&self,
analysis: &ImageAnalysis,
) -> Result<(), VisionKitError>
pub fn set_analysis( &self, analysis: &ImageAnalysis, ) -> Result<(), VisionKitError>
Examples found in repository?
examples/02_framework_smoke.rs (line 54)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 println!("== VisionKit.framework smoke ==");
14 println!("ImageAnalyzer supported: {}", ImageAnalyzer::is_supported());
15 println!(
16 "document camera available on macOS: {}",
17 VNDocumentCameraViewController::is_available_on_current_platform()?
18 );
19 println!(
20 "data scanner available on macOS: {}",
21 DataScannerViewController::is_available_on_current_platform()?
22 );
23
24 let languages = ImageAnalyzer::supported_text_recognition_languages()?;
25 println!("supported OCR languages: {}", languages.len());
26 println!(
27 "sample OCR languages: {:?}",
28 languages.iter().take(10).collect::<Vec<_>>()
29 );
30
31 if !ImageAnalyzer::is_supported() {
32 println!("ImageAnalyzer is not supported on this Mac");
33 return Ok(());
34 }
35
36 let analyzer = ImageAnalyzer::new()?;
37 let configuration = ImageAnalyzerConfiguration::new(
38 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
39 )
40 .with_locales(["en-US"]);
41 let asset_path = asset_path();
42 let analysis =
43 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?;
44
45 println!(
46 "has text results: {}",
47 analysis.has_results(ImageAnalysisTypes::TEXT)?
48 );
49 let transcript = analysis.transcript()?;
50 println!("transcript: {transcript:?}");
51
52 let interaction = LiveTextInteraction::new()?;
53 interaction.track_image_at_path(&asset_path)?;
54 interaction.set_analysis(&analysis)?;
55 println!(
56 "overlay preferred types: {}",
57 interaction.preferred_interaction_types()?.bits()
58 );
59 let overlay_text = interaction.text();
60 println!("overlay text: {overlay_text:?}");
61 Ok(())
62}More examples
examples/05_live_text_interaction.rs (line 120)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101 if !ImageAnalyzer::is_supported() {
102 println!("ImageAnalyzer is not supported on this Mac");
103 return Ok(());
104 }
105
106 let asset_path = asset_path();
107 let analyzer = ImageAnalyzer::new()?;
108 let analysis = analyzer.analyze_image_at_path(
109 &asset_path,
110 ImageOrientation::Up,
111 &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112 )?;
113
114 let delegate = build_delegate()?;
115 let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116 let tracking_view = LiveTextTrackingImageView::new()?;
117 tracking_view.set_image_at_path(&asset_path)?;
118 interaction.set_tracking_image_view(Some(&tracking_view))?;
119 interaction.track_image_at_path(&asset_path)?;
120 interaction.set_analysis(&analysis)?;
121 interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122 interaction.set_selectable_items_highlighted(true)?;
123 interaction.set_contents_rect_needs_update()?;
124
125 println!("contents rect: {:?}", interaction.contents_rect()?);
126 println!("overlay text: {:?}", interaction.text());
127 println!("delegate events: {}", delegate.recorded_events()?.len());
128 println!(
129 "delegate content view set: {}",
130 interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131 );
132 match interaction.tracking_image_view()? {
133 Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134 None => println!("tracking image size: none"),
135 }
136 match LiveTextMenuTag::copy_image() {
137 Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138 Err(error) => println!("copy image tag: {error}"),
139 }
140 print_selection_state(&interaction)?;
141 print_subject_state(&interaction)?;
142 println!(
143 "live text button visible: {}",
144 interaction.live_text_button_visible()?
145 );
146 println!(
147 "supplementary hidden: {}",
148 interaction.is_supplementary_interface_hidden()?
149 );
150
151 let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152 LiveTextImageData,
153 VisionKitError,
154 > = LiveTextInteraction::image_for_subjects;
155 black_box(image_for_subjects_fn);
156 Ok(())
157}Sourcepub fn track_image_at_path<P: AsRef<Path>>(
&self,
path: P,
) -> Result<(), VisionKitError>
pub fn track_image_at_path<P: AsRef<Path>>( &self, path: P, ) -> Result<(), VisionKitError>
Examples found in repository?
examples/02_framework_smoke.rs (line 53)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 println!("== VisionKit.framework smoke ==");
14 println!("ImageAnalyzer supported: {}", ImageAnalyzer::is_supported());
15 println!(
16 "document camera available on macOS: {}",
17 VNDocumentCameraViewController::is_available_on_current_platform()?
18 );
19 println!(
20 "data scanner available on macOS: {}",
21 DataScannerViewController::is_available_on_current_platform()?
22 );
23
24 let languages = ImageAnalyzer::supported_text_recognition_languages()?;
25 println!("supported OCR languages: {}", languages.len());
26 println!(
27 "sample OCR languages: {:?}",
28 languages.iter().take(10).collect::<Vec<_>>()
29 );
30
31 if !ImageAnalyzer::is_supported() {
32 println!("ImageAnalyzer is not supported on this Mac");
33 return Ok(());
34 }
35
36 let analyzer = ImageAnalyzer::new()?;
37 let configuration = ImageAnalyzerConfiguration::new(
38 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
39 )
40 .with_locales(["en-US"]);
41 let asset_path = asset_path();
42 let analysis =
43 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?;
44
45 println!(
46 "has text results: {}",
47 analysis.has_results(ImageAnalysisTypes::TEXT)?
48 );
49 let transcript = analysis.transcript()?;
50 println!("transcript: {transcript:?}");
51
52 let interaction = LiveTextInteraction::new()?;
53 interaction.track_image_at_path(&asset_path)?;
54 interaction.set_analysis(&analysis)?;
55 println!(
56 "overlay preferred types: {}",
57 interaction.preferred_interaction_types()?.bits()
58 );
59 let overlay_text = interaction.text();
60 println!("overlay text: {overlay_text:?}");
61 Ok(())
62}More examples
examples/05_live_text_interaction.rs (line 119)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101 if !ImageAnalyzer::is_supported() {
102 println!("ImageAnalyzer is not supported on this Mac");
103 return Ok(());
104 }
105
106 let asset_path = asset_path();
107 let analyzer = ImageAnalyzer::new()?;
108 let analysis = analyzer.analyze_image_at_path(
109 &asset_path,
110 ImageOrientation::Up,
111 &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112 )?;
113
114 let delegate = build_delegate()?;
115 let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116 let tracking_view = LiveTextTrackingImageView::new()?;
117 tracking_view.set_image_at_path(&asset_path)?;
118 interaction.set_tracking_image_view(Some(&tracking_view))?;
119 interaction.track_image_at_path(&asset_path)?;
120 interaction.set_analysis(&analysis)?;
121 interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122 interaction.set_selectable_items_highlighted(true)?;
123 interaction.set_contents_rect_needs_update()?;
124
125 println!("contents rect: {:?}", interaction.contents_rect()?);
126 println!("overlay text: {:?}", interaction.text());
127 println!("delegate events: {}", delegate.recorded_events()?.len());
128 println!(
129 "delegate content view set: {}",
130 interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131 );
132 match interaction.tracking_image_view()? {
133 Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134 None => println!("tracking image size: none"),
135 }
136 match LiveTextMenuTag::copy_image() {
137 Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138 Err(error) => println!("copy image tag: {error}"),
139 }
140 print_selection_state(&interaction)?;
141 print_subject_state(&interaction)?;
142 println!(
143 "live text button visible: {}",
144 interaction.live_text_button_visible()?
145 );
146 println!(
147 "supplementary hidden: {}",
148 interaction.is_supplementary_interface_hidden()?
149 );
150
151 let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152 LiveTextImageData,
153 VisionKitError,
154 > = LiveTextInteraction::image_for_subjects;
155 black_box(image_for_subjects_fn);
156 Ok(())
157}Sourcepub fn delegate(
&self,
) -> Result<Option<LiveTextInteractionDelegate>, VisionKitError>
pub fn delegate( &self, ) -> Result<Option<LiveTextInteractionDelegate>, VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 130)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101 if !ImageAnalyzer::is_supported() {
102 println!("ImageAnalyzer is not supported on this Mac");
103 return Ok(());
104 }
105
106 let asset_path = asset_path();
107 let analyzer = ImageAnalyzer::new()?;
108 let analysis = analyzer.analyze_image_at_path(
109 &asset_path,
110 ImageOrientation::Up,
111 &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112 )?;
113
114 let delegate = build_delegate()?;
115 let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116 let tracking_view = LiveTextTrackingImageView::new()?;
117 tracking_view.set_image_at_path(&asset_path)?;
118 interaction.set_tracking_image_view(Some(&tracking_view))?;
119 interaction.track_image_at_path(&asset_path)?;
120 interaction.set_analysis(&analysis)?;
121 interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122 interaction.set_selectable_items_highlighted(true)?;
123 interaction.set_contents_rect_needs_update()?;
124
125 println!("contents rect: {:?}", interaction.contents_rect()?);
126 println!("overlay text: {:?}", interaction.text());
127 println!("delegate events: {}", delegate.recorded_events()?.len());
128 println!(
129 "delegate content view set: {}",
130 interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131 );
132 match interaction.tracking_image_view()? {
133 Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134 None => println!("tracking image size: none"),
135 }
136 match LiveTextMenuTag::copy_image() {
137 Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138 Err(error) => println!("copy image tag: {error}"),
139 }
140 print_selection_state(&interaction)?;
141 print_subject_state(&interaction)?;
142 println!(
143 "live text button visible: {}",
144 interaction.live_text_button_visible()?
145 );
146 println!(
147 "supplementary hidden: {}",
148 interaction.is_supplementary_interface_hidden()?
149 );
150
151 let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152 LiveTextImageData,
153 VisionKitError,
154 > = LiveTextInteraction::image_for_subjects;
155 black_box(image_for_subjects_fn);
156 Ok(())
157}pub fn set_delegate( &self, delegate: Option<&LiveTextInteractionDelegate>, ) -> Result<(), VisionKitError>
Sourcepub fn preferred_interaction_types(
&self,
) -> Result<LiveTextInteractionTypes, VisionKitError>
pub fn preferred_interaction_types( &self, ) -> Result<LiveTextInteractionTypes, VisionKitError>
Examples found in repository?
examples/02_framework_smoke.rs (line 57)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 println!("== VisionKit.framework smoke ==");
14 println!("ImageAnalyzer supported: {}", ImageAnalyzer::is_supported());
15 println!(
16 "document camera available on macOS: {}",
17 VNDocumentCameraViewController::is_available_on_current_platform()?
18 );
19 println!(
20 "data scanner available on macOS: {}",
21 DataScannerViewController::is_available_on_current_platform()?
22 );
23
24 let languages = ImageAnalyzer::supported_text_recognition_languages()?;
25 println!("supported OCR languages: {}", languages.len());
26 println!(
27 "sample OCR languages: {:?}",
28 languages.iter().take(10).collect::<Vec<_>>()
29 );
30
31 if !ImageAnalyzer::is_supported() {
32 println!("ImageAnalyzer is not supported on this Mac");
33 return Ok(());
34 }
35
36 let analyzer = ImageAnalyzer::new()?;
37 let configuration = ImageAnalyzerConfiguration::new(
38 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
39 )
40 .with_locales(["en-US"]);
41 let asset_path = asset_path();
42 let analysis =
43 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?;
44
45 println!(
46 "has text results: {}",
47 analysis.has_results(ImageAnalysisTypes::TEXT)?
48 );
49 let transcript = analysis.transcript()?;
50 println!("transcript: {transcript:?}");
51
52 let interaction = LiveTextInteraction::new()?;
53 interaction.track_image_at_path(&asset_path)?;
54 interaction.set_analysis(&analysis)?;
55 println!(
56 "overlay preferred types: {}",
57 interaction.preferred_interaction_types()?.bits()
58 );
59 let overlay_text = interaction.text();
60 println!("overlay text: {overlay_text:?}");
61 Ok(())
62}Sourcepub fn set_preferred_interaction_types(
&self,
interaction_types: LiveTextInteractionTypes,
) -> Result<(), VisionKitError>
pub fn set_preferred_interaction_types( &self, interaction_types: LiveTextInteractionTypes, ) -> Result<(), VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 121)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101 if !ImageAnalyzer::is_supported() {
102 println!("ImageAnalyzer is not supported on this Mac");
103 return Ok(());
104 }
105
106 let asset_path = asset_path();
107 let analyzer = ImageAnalyzer::new()?;
108 let analysis = analyzer.analyze_image_at_path(
109 &asset_path,
110 ImageOrientation::Up,
111 &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112 )?;
113
114 let delegate = build_delegate()?;
115 let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116 let tracking_view = LiveTextTrackingImageView::new()?;
117 tracking_view.set_image_at_path(&asset_path)?;
118 interaction.set_tracking_image_view(Some(&tracking_view))?;
119 interaction.track_image_at_path(&asset_path)?;
120 interaction.set_analysis(&analysis)?;
121 interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122 interaction.set_selectable_items_highlighted(true)?;
123 interaction.set_contents_rect_needs_update()?;
124
125 println!("contents rect: {:?}", interaction.contents_rect()?);
126 println!("overlay text: {:?}", interaction.text());
127 println!("delegate events: {}", delegate.recorded_events()?.len());
128 println!(
129 "delegate content view set: {}",
130 interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131 );
132 match interaction.tracking_image_view()? {
133 Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134 None => println!("tracking image size: none"),
135 }
136 match LiveTextMenuTag::copy_image() {
137 Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138 Err(error) => println!("copy image tag: {error}"),
139 }
140 print_selection_state(&interaction)?;
141 print_subject_state(&interaction)?;
142 println!(
143 "live text button visible: {}",
144 interaction.live_text_button_visible()?
145 );
146 println!(
147 "supplementary hidden: {}",
148 interaction.is_supplementary_interface_hidden()?
149 );
150
151 let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152 LiveTextImageData,
153 VisionKitError,
154 > = LiveTextInteraction::image_for_subjects;
155 black_box(image_for_subjects_fn);
156 Ok(())
157}pub fn active_interaction_types( &self, ) -> Result<LiveTextInteractionTypes, VisionKitError>
pub fn selectable_items_highlighted(&self) -> Result<bool, VisionKitError>
Sourcepub fn set_selectable_items_highlighted(
&self,
value: bool,
) -> Result<(), VisionKitError>
pub fn set_selectable_items_highlighted( &self, value: bool, ) -> Result<(), VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 122)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101 if !ImageAnalyzer::is_supported() {
102 println!("ImageAnalyzer is not supported on this Mac");
103 return Ok(());
104 }
105
106 let asset_path = asset_path();
107 let analyzer = ImageAnalyzer::new()?;
108 let analysis = analyzer.analyze_image_at_path(
109 &asset_path,
110 ImageOrientation::Up,
111 &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112 )?;
113
114 let delegate = build_delegate()?;
115 let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116 let tracking_view = LiveTextTrackingImageView::new()?;
117 tracking_view.set_image_at_path(&asset_path)?;
118 interaction.set_tracking_image_view(Some(&tracking_view))?;
119 interaction.track_image_at_path(&asset_path)?;
120 interaction.set_analysis(&analysis)?;
121 interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122 interaction.set_selectable_items_highlighted(true)?;
123 interaction.set_contents_rect_needs_update()?;
124
125 println!("contents rect: {:?}", interaction.contents_rect()?);
126 println!("overlay text: {:?}", interaction.text());
127 println!("delegate events: {}", delegate.recorded_events()?.len());
128 println!(
129 "delegate content view set: {}",
130 interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131 );
132 match interaction.tracking_image_view()? {
133 Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134 None => println!("tracking image size: none"),
135 }
136 match LiveTextMenuTag::copy_image() {
137 Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138 Err(error) => println!("copy image tag: {error}"),
139 }
140 print_selection_state(&interaction)?;
141 print_subject_state(&interaction)?;
142 println!(
143 "live text button visible: {}",
144 interaction.live_text_button_visible()?
145 );
146 println!(
147 "supplementary hidden: {}",
148 interaction.is_supplementary_interface_hidden()?
149 );
150
151 let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152 LiveTextImageData,
153 VisionKitError,
154 > = LiveTextInteraction::image_for_subjects;
155 black_box(image_for_subjects_fn);
156 Ok(())
157}Sourcepub fn tracking_image_view(
&self,
) -> Result<Option<LiveTextTrackingImageView>, VisionKitError>
pub fn tracking_image_view( &self, ) -> Result<Option<LiveTextTrackingImageView>, VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 132)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101 if !ImageAnalyzer::is_supported() {
102 println!("ImageAnalyzer is not supported on this Mac");
103 return Ok(());
104 }
105
106 let asset_path = asset_path();
107 let analyzer = ImageAnalyzer::new()?;
108 let analysis = analyzer.analyze_image_at_path(
109 &asset_path,
110 ImageOrientation::Up,
111 &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112 )?;
113
114 let delegate = build_delegate()?;
115 let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116 let tracking_view = LiveTextTrackingImageView::new()?;
117 tracking_view.set_image_at_path(&asset_path)?;
118 interaction.set_tracking_image_view(Some(&tracking_view))?;
119 interaction.track_image_at_path(&asset_path)?;
120 interaction.set_analysis(&analysis)?;
121 interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122 interaction.set_selectable_items_highlighted(true)?;
123 interaction.set_contents_rect_needs_update()?;
124
125 println!("contents rect: {:?}", interaction.contents_rect()?);
126 println!("overlay text: {:?}", interaction.text());
127 println!("delegate events: {}", delegate.recorded_events()?.len());
128 println!(
129 "delegate content view set: {}",
130 interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131 );
132 match interaction.tracking_image_view()? {
133 Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134 None => println!("tracking image size: none"),
135 }
136 match LiveTextMenuTag::copy_image() {
137 Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138 Err(error) => println!("copy image tag: {error}"),
139 }
140 print_selection_state(&interaction)?;
141 print_subject_state(&interaction)?;
142 println!(
143 "live text button visible: {}",
144 interaction.live_text_button_visible()?
145 );
146 println!(
147 "supplementary hidden: {}",
148 interaction.is_supplementary_interface_hidden()?
149 );
150
151 let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152 LiveTextImageData,
153 VisionKitError,
154 > = LiveTextInteraction::image_for_subjects;
155 black_box(image_for_subjects_fn);
156 Ok(())
157}Sourcepub fn set_tracking_image_view(
&self,
view: Option<&LiveTextTrackingImageView>,
) -> Result<(), VisionKitError>
pub fn set_tracking_image_view( &self, view: Option<&LiveTextTrackingImageView>, ) -> Result<(), VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 118)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101 if !ImageAnalyzer::is_supported() {
102 println!("ImageAnalyzer is not supported on this Mac");
103 return Ok(());
104 }
105
106 let asset_path = asset_path();
107 let analyzer = ImageAnalyzer::new()?;
108 let analysis = analyzer.analyze_image_at_path(
109 &asset_path,
110 ImageOrientation::Up,
111 &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112 )?;
113
114 let delegate = build_delegate()?;
115 let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116 let tracking_view = LiveTextTrackingImageView::new()?;
117 tracking_view.set_image_at_path(&asset_path)?;
118 interaction.set_tracking_image_view(Some(&tracking_view))?;
119 interaction.track_image_at_path(&asset_path)?;
120 interaction.set_analysis(&analysis)?;
121 interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122 interaction.set_selectable_items_highlighted(true)?;
123 interaction.set_contents_rect_needs_update()?;
124
125 println!("contents rect: {:?}", interaction.contents_rect()?);
126 println!("overlay text: {:?}", interaction.text());
127 println!("delegate events: {}", delegate.recorded_events()?.len());
128 println!(
129 "delegate content view set: {}",
130 interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131 );
132 match interaction.tracking_image_view()? {
133 Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134 None => println!("tracking image size: none"),
135 }
136 match LiveTextMenuTag::copy_image() {
137 Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138 Err(error) => println!("copy image tag: {error}"),
139 }
140 print_selection_state(&interaction)?;
141 print_subject_state(&interaction)?;
142 println!(
143 "live text button visible: {}",
144 interaction.live_text_button_visible()?
145 );
146 println!(
147 "supplementary hidden: {}",
148 interaction.is_supplementary_interface_hidden()?
149 );
150
151 let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152 LiveTextImageData,
153 VisionKitError,
154 > = LiveTextInteraction::image_for_subjects;
155 black_box(image_for_subjects_fn);
156 Ok(())
157}pub fn has_active_text_selection(&self) -> Result<bool, VisionKitError>
pub fn reset_selection(&self) -> Result<(), VisionKitError>
Sourcepub fn text(&self) -> Result<String, VisionKitError>
pub fn text(&self) -> Result<String, VisionKitError>
Examples found in repository?
examples/02_framework_smoke.rs (line 59)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 println!("== VisionKit.framework smoke ==");
14 println!("ImageAnalyzer supported: {}", ImageAnalyzer::is_supported());
15 println!(
16 "document camera available on macOS: {}",
17 VNDocumentCameraViewController::is_available_on_current_platform()?
18 );
19 println!(
20 "data scanner available on macOS: {}",
21 DataScannerViewController::is_available_on_current_platform()?
22 );
23
24 let languages = ImageAnalyzer::supported_text_recognition_languages()?;
25 println!("supported OCR languages: {}", languages.len());
26 println!(
27 "sample OCR languages: {:?}",
28 languages.iter().take(10).collect::<Vec<_>>()
29 );
30
31 if !ImageAnalyzer::is_supported() {
32 println!("ImageAnalyzer is not supported on this Mac");
33 return Ok(());
34 }
35
36 let analyzer = ImageAnalyzer::new()?;
37 let configuration = ImageAnalyzerConfiguration::new(
38 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
39 )
40 .with_locales(["en-US"]);
41 let asset_path = asset_path();
42 let analysis =
43 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?;
44
45 println!(
46 "has text results: {}",
47 analysis.has_results(ImageAnalysisTypes::TEXT)?
48 );
49 let transcript = analysis.transcript()?;
50 println!("transcript: {transcript:?}");
51
52 let interaction = LiveTextInteraction::new()?;
53 interaction.track_image_at_path(&asset_path)?;
54 interaction.set_analysis(&analysis)?;
55 println!(
56 "overlay preferred types: {}",
57 interaction.preferred_interaction_types()?.bits()
58 );
59 let overlay_text = interaction.text();
60 println!("overlay text: {overlay_text:?}");
61 Ok(())
62}More examples
examples/05_live_text_interaction.rs (line 126)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101 if !ImageAnalyzer::is_supported() {
102 println!("ImageAnalyzer is not supported on this Mac");
103 return Ok(());
104 }
105
106 let asset_path = asset_path();
107 let analyzer = ImageAnalyzer::new()?;
108 let analysis = analyzer.analyze_image_at_path(
109 &asset_path,
110 ImageOrientation::Up,
111 &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112 )?;
113
114 let delegate = build_delegate()?;
115 let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116 let tracking_view = LiveTextTrackingImageView::new()?;
117 tracking_view.set_image_at_path(&asset_path)?;
118 interaction.set_tracking_image_view(Some(&tracking_view))?;
119 interaction.track_image_at_path(&asset_path)?;
120 interaction.set_analysis(&analysis)?;
121 interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122 interaction.set_selectable_items_highlighted(true)?;
123 interaction.set_contents_rect_needs_update()?;
124
125 println!("contents rect: {:?}", interaction.contents_rect()?);
126 println!("overlay text: {:?}", interaction.text());
127 println!("delegate events: {}", delegate.recorded_events()?.len());
128 println!(
129 "delegate content view set: {}",
130 interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131 );
132 match interaction.tracking_image_view()? {
133 Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134 None => println!("tracking image size: none"),
135 }
136 match LiveTextMenuTag::copy_image() {
137 Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138 Err(error) => println!("copy image tag: {error}"),
139 }
140 print_selection_state(&interaction)?;
141 print_subject_state(&interaction)?;
142 println!(
143 "live text button visible: {}",
144 interaction.live_text_button_visible()?
145 );
146 println!(
147 "supplementary hidden: {}",
148 interaction.is_supplementary_interface_hidden()?
149 );
150
151 let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152 LiveTextImageData,
153 VisionKitError,
154 > = LiveTextInteraction::image_for_subjects;
155 black_box(image_for_subjects_fn);
156 Ok(())
157}pub fn selected_text(&self) -> Result<String, VisionKitError>
Sourcepub fn selected_attributed_text(
&self,
) -> Result<LiveTextAttributedText, VisionKitError>
pub fn selected_attributed_text( &self, ) -> Result<LiveTextAttributedText, VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 55)
45fn print_selection_state(
46 interaction: &LiveTextInteraction,
47) -> Result<(), Box<dyn std::error::Error>> {
48 match interaction.selected_ranges() {
49 Ok(ranges) => {
50 interaction.set_selected_ranges(&ranges)?;
51 println!("selected ranges: {}", ranges.len());
52 }
53 Err(error) => println!("selected ranges: {error}"),
54 }
55 match interaction.selected_attributed_text() {
56 Ok(text) => println!("selected attributed text runs: {}", text.runs.len()),
57 Err(error) => println!("selected attributed text runs: {error}"),
58 }
59 match interaction.supplementary_interface_font() {
60 Ok(font) => {
61 interaction.set_supplementary_interface_font(font.as_ref())?;
62 println!("supplementary font set: {}", font.is_some());
63 }
64 Err(error) => println!("supplementary font set: {error}"),
65 }
66 Ok(())
67}Sourcepub fn selected_ranges(&self) -> Result<Vec<LiveTextTextRange>, VisionKitError>
pub fn selected_ranges(&self) -> Result<Vec<LiveTextTextRange>, VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 48)
45fn print_selection_state(
46 interaction: &LiveTextInteraction,
47) -> Result<(), Box<dyn std::error::Error>> {
48 match interaction.selected_ranges() {
49 Ok(ranges) => {
50 interaction.set_selected_ranges(&ranges)?;
51 println!("selected ranges: {}", ranges.len());
52 }
53 Err(error) => println!("selected ranges: {error}"),
54 }
55 match interaction.selected_attributed_text() {
56 Ok(text) => println!("selected attributed text runs: {}", text.runs.len()),
57 Err(error) => println!("selected attributed text runs: {error}"),
58 }
59 match interaction.supplementary_interface_font() {
60 Ok(font) => {
61 interaction.set_supplementary_interface_font(font.as_ref())?;
62 println!("supplementary font set: {}", font.is_some());
63 }
64 Err(error) => println!("supplementary font set: {error}"),
65 }
66 Ok(())
67}Sourcepub fn set_selected_ranges(
&self,
ranges: &[LiveTextTextRange],
) -> Result<(), VisionKitError>
pub fn set_selected_ranges( &self, ranges: &[LiveTextTextRange], ) -> Result<(), VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 50)
45fn print_selection_state(
46 interaction: &LiveTextInteraction,
47) -> Result<(), Box<dyn std::error::Error>> {
48 match interaction.selected_ranges() {
49 Ok(ranges) => {
50 interaction.set_selected_ranges(&ranges)?;
51 println!("selected ranges: {}", ranges.len());
52 }
53 Err(error) => println!("selected ranges: {error}"),
54 }
55 match interaction.selected_attributed_text() {
56 Ok(text) => println!("selected attributed text runs: {}", text.runs.len()),
57 Err(error) => println!("selected attributed text runs: {error}"),
58 }
59 match interaction.supplementary_interface_font() {
60 Ok(font) => {
61 interaction.set_supplementary_interface_font(font.as_ref())?;
62 println!("supplementary font set: {}", font.is_some());
63 }
64 Err(error) => println!("supplementary font set: {error}"),
65 }
66 Ok(())
67}Sourcepub fn contents_rect(&self) -> Result<Rect, VisionKitError>
pub fn contents_rect(&self) -> Result<Rect, VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 125)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101 if !ImageAnalyzer::is_supported() {
102 println!("ImageAnalyzer is not supported on this Mac");
103 return Ok(());
104 }
105
106 let asset_path = asset_path();
107 let analyzer = ImageAnalyzer::new()?;
108 let analysis = analyzer.analyze_image_at_path(
109 &asset_path,
110 ImageOrientation::Up,
111 &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112 )?;
113
114 let delegate = build_delegate()?;
115 let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116 let tracking_view = LiveTextTrackingImageView::new()?;
117 tracking_view.set_image_at_path(&asset_path)?;
118 interaction.set_tracking_image_view(Some(&tracking_view))?;
119 interaction.track_image_at_path(&asset_path)?;
120 interaction.set_analysis(&analysis)?;
121 interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122 interaction.set_selectable_items_highlighted(true)?;
123 interaction.set_contents_rect_needs_update()?;
124
125 println!("contents rect: {:?}", interaction.contents_rect()?);
126 println!("overlay text: {:?}", interaction.text());
127 println!("delegate events: {}", delegate.recorded_events()?.len());
128 println!(
129 "delegate content view set: {}",
130 interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131 );
132 match interaction.tracking_image_view()? {
133 Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134 None => println!("tracking image size: none"),
135 }
136 match LiveTextMenuTag::copy_image() {
137 Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138 Err(error) => println!("copy image tag: {error}"),
139 }
140 print_selection_state(&interaction)?;
141 print_subject_state(&interaction)?;
142 println!(
143 "live text button visible: {}",
144 interaction.live_text_button_visible()?
145 );
146 println!(
147 "supplementary hidden: {}",
148 interaction.is_supplementary_interface_hidden()?
149 );
150
151 let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152 LiveTextImageData,
153 VisionKitError,
154 > = LiveTextInteraction::image_for_subjects;
155 black_box(image_for_subjects_fn);
156 Ok(())
157}Sourcepub fn set_contents_rect_needs_update(&self) -> Result<(), VisionKitError>
pub fn set_contents_rect_needs_update(&self) -> Result<(), VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 123)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101 if !ImageAnalyzer::is_supported() {
102 println!("ImageAnalyzer is not supported on this Mac");
103 return Ok(());
104 }
105
106 let asset_path = asset_path();
107 let analyzer = ImageAnalyzer::new()?;
108 let analysis = analyzer.analyze_image_at_path(
109 &asset_path,
110 ImageOrientation::Up,
111 &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112 )?;
113
114 let delegate = build_delegate()?;
115 let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116 let tracking_view = LiveTextTrackingImageView::new()?;
117 tracking_view.set_image_at_path(&asset_path)?;
118 interaction.set_tracking_image_view(Some(&tracking_view))?;
119 interaction.track_image_at_path(&asset_path)?;
120 interaction.set_analysis(&analysis)?;
121 interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122 interaction.set_selectable_items_highlighted(true)?;
123 interaction.set_contents_rect_needs_update()?;
124
125 println!("contents rect: {:?}", interaction.contents_rect()?);
126 println!("overlay text: {:?}", interaction.text());
127 println!("delegate events: {}", delegate.recorded_events()?.len());
128 println!(
129 "delegate content view set: {}",
130 interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131 );
132 match interaction.tracking_image_view()? {
133 Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134 None => println!("tracking image size: none"),
135 }
136 match LiveTextMenuTag::copy_image() {
137 Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138 Err(error) => println!("copy image tag: {error}"),
139 }
140 print_selection_state(&interaction)?;
141 print_subject_state(&interaction)?;
142 println!(
143 "live text button visible: {}",
144 interaction.live_text_button_visible()?
145 );
146 println!(
147 "supplementary hidden: {}",
148 interaction.is_supplementary_interface_hidden()?
149 );
150
151 let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152 LiveTextImageData,
153 VisionKitError,
154 > = LiveTextInteraction::image_for_subjects;
155 black_box(image_for_subjects_fn);
156 Ok(())
157}pub fn has_interactive_item_at_point( &self, x: f64, y: f64, ) -> Result<bool, VisionKitError>
pub fn has_text_at_point(&self, x: f64, y: f64) -> Result<bool, VisionKitError>
pub fn has_data_detector_at_point( &self, x: f64, y: f64, ) -> Result<bool, VisionKitError>
pub fn has_supplementary_interface_at_point( &self, x: f64, y: f64, ) -> Result<bool, VisionKitError>
pub fn analysis_has_text_at_point( &self, x: f64, y: f64, ) -> Result<bool, VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 144)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101 if !ImageAnalyzer::is_supported() {
102 println!("ImageAnalyzer is not supported on this Mac");
103 return Ok(());
104 }
105
106 let asset_path = asset_path();
107 let analyzer = ImageAnalyzer::new()?;
108 let analysis = analyzer.analyze_image_at_path(
109 &asset_path,
110 ImageOrientation::Up,
111 &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112 )?;
113
114 let delegate = build_delegate()?;
115 let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116 let tracking_view = LiveTextTrackingImageView::new()?;
117 tracking_view.set_image_at_path(&asset_path)?;
118 interaction.set_tracking_image_view(Some(&tracking_view))?;
119 interaction.track_image_at_path(&asset_path)?;
120 interaction.set_analysis(&analysis)?;
121 interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122 interaction.set_selectable_items_highlighted(true)?;
123 interaction.set_contents_rect_needs_update()?;
124
125 println!("contents rect: {:?}", interaction.contents_rect()?);
126 println!("overlay text: {:?}", interaction.text());
127 println!("delegate events: {}", delegate.recorded_events()?.len());
128 println!(
129 "delegate content view set: {}",
130 interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131 );
132 match interaction.tracking_image_view()? {
133 Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134 None => println!("tracking image size: none"),
135 }
136 match LiveTextMenuTag::copy_image() {
137 Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138 Err(error) => println!("copy image tag: {error}"),
139 }
140 print_selection_state(&interaction)?;
141 print_subject_state(&interaction)?;
142 println!(
143 "live text button visible: {}",
144 interaction.live_text_button_visible()?
145 );
146 println!(
147 "supplementary hidden: {}",
148 interaction.is_supplementary_interface_hidden()?
149 );
150
151 let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152 LiveTextImageData,
153 VisionKitError,
154 > = LiveTextInteraction::image_for_subjects;
155 black_box(image_for_subjects_fn);
156 Ok(())
157}Examples found in repository?
examples/05_live_text_interaction.rs (line 148)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101 if !ImageAnalyzer::is_supported() {
102 println!("ImageAnalyzer is not supported on this Mac");
103 return Ok(());
104 }
105
106 let asset_path = asset_path();
107 let analyzer = ImageAnalyzer::new()?;
108 let analysis = analyzer.analyze_image_at_path(
109 &asset_path,
110 ImageOrientation::Up,
111 &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112 )?;
113
114 let delegate = build_delegate()?;
115 let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116 let tracking_view = LiveTextTrackingImageView::new()?;
117 tracking_view.set_image_at_path(&asset_path)?;
118 interaction.set_tracking_image_view(Some(&tracking_view))?;
119 interaction.track_image_at_path(&asset_path)?;
120 interaction.set_analysis(&analysis)?;
121 interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122 interaction.set_selectable_items_highlighted(true)?;
123 interaction.set_contents_rect_needs_update()?;
124
125 println!("contents rect: {:?}", interaction.contents_rect()?);
126 println!("overlay text: {:?}", interaction.text());
127 println!("delegate events: {}", delegate.recorded_events()?.len());
128 println!(
129 "delegate content view set: {}",
130 interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131 );
132 match interaction.tracking_image_view()? {
133 Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134 None => println!("tracking image size: none"),
135 }
136 match LiveTextMenuTag::copy_image() {
137 Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138 Err(error) => println!("copy image tag: {error}"),
139 }
140 print_selection_state(&interaction)?;
141 print_subject_state(&interaction)?;
142 println!(
143 "live text button visible: {}",
144 interaction.live_text_button_visible()?
145 );
146 println!(
147 "supplementary hidden: {}",
148 interaction.is_supplementary_interface_hidden()?
149 );
150
151 let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152 LiveTextImageData,
153 VisionKitError,
154 > = LiveTextInteraction::image_for_subjects;
155 black_box(image_for_subjects_fn);
156 Ok(())
157}pub fn supplementary_interface_content_insets( &self, ) -> Result<EdgeInsets, VisionKitError>
pub fn set_supplementary_interface_content_insets( &self, insets: EdgeInsets, ) -> Result<(), VisionKitError>
Sourcepub fn supplementary_interface_font(
&self,
) -> Result<Option<LiveTextFont>, VisionKitError>
pub fn supplementary_interface_font( &self, ) -> Result<Option<LiveTextFont>, VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 59)
45fn print_selection_state(
46 interaction: &LiveTextInteraction,
47) -> Result<(), Box<dyn std::error::Error>> {
48 match interaction.selected_ranges() {
49 Ok(ranges) => {
50 interaction.set_selected_ranges(&ranges)?;
51 println!("selected ranges: {}", ranges.len());
52 }
53 Err(error) => println!("selected ranges: {error}"),
54 }
55 match interaction.selected_attributed_text() {
56 Ok(text) => println!("selected attributed text runs: {}", text.runs.len()),
57 Err(error) => println!("selected attributed text runs: {error}"),
58 }
59 match interaction.supplementary_interface_font() {
60 Ok(font) => {
61 interaction.set_supplementary_interface_font(font.as_ref())?;
62 println!("supplementary font set: {}", font.is_some());
63 }
64 Err(error) => println!("supplementary font set: {error}"),
65 }
66 Ok(())
67}Sourcepub fn set_supplementary_interface_font(
&self,
font: Option<&LiveTextFont>,
) -> Result<(), VisionKitError>
pub fn set_supplementary_interface_font( &self, font: Option<&LiveTextFont>, ) -> Result<(), VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 61)
45fn print_selection_state(
46 interaction: &LiveTextInteraction,
47) -> Result<(), Box<dyn std::error::Error>> {
48 match interaction.selected_ranges() {
49 Ok(ranges) => {
50 interaction.set_selected_ranges(&ranges)?;
51 println!("selected ranges: {}", ranges.len());
52 }
53 Err(error) => println!("selected ranges: {error}"),
54 }
55 match interaction.selected_attributed_text() {
56 Ok(text) => println!("selected attributed text runs: {}", text.runs.len()),
57 Err(error) => println!("selected attributed text runs: {error}"),
58 }
59 match interaction.supplementary_interface_font() {
60 Ok(font) => {
61 interaction.set_supplementary_interface_font(font.as_ref())?;
62 println!("supplementary font set: {}", font.is_some());
63 }
64 Err(error) => println!("supplementary font set: {error}"),
65 }
66 Ok(())
67}Sourcepub fn begin_subject_analysis_if_necessary(&self) -> Result<(), VisionKitError>
pub fn begin_subject_analysis_if_necessary(&self) -> Result<(), VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 76)
69fn print_subject_state(
70 interaction: &LiveTextInteraction,
71) -> Result<(), Box<dyn std::error::Error>> {
72 println!(
73 "subject unavailable case: {:?}",
74 LiveTextSubjectUnavailable::ImageUnavailable
75 );
76 match interaction.begin_subject_analysis_if_necessary() {
77 Ok(()) => println!("subject analysis started"),
78 Err(error) => println!("subject analysis started: {error}"),
79 }
80 match interaction.subjects() {
81 Ok(subjects) => {
82 println!("subjects: {}", subjects.len());
83 println!(
84 "highlighted subjects: {}",
85 interaction.highlighted_subjects()?.len()
86 );
87 if let Some(subject) = subjects.first() {
88 println!("subject bounds: {:?}", subject.bounds()?);
89 }
90 match interaction.image_for_subjects(&subjects) {
91 Ok(image) => println!("subject image bytes: {}", image.png_data.len()),
92 Err(error) => println!("subject image bytes: {error}"),
93 }
94 }
95 Err(error) => println!("subjects: {error}"),
96 }
97 Ok(())
98}Sourcepub fn subjects(&self) -> Result<Vec<LiveTextSubject>, VisionKitError>
pub fn subjects(&self) -> Result<Vec<LiveTextSubject>, VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 80)
69fn print_subject_state(
70 interaction: &LiveTextInteraction,
71) -> Result<(), Box<dyn std::error::Error>> {
72 println!(
73 "subject unavailable case: {:?}",
74 LiveTextSubjectUnavailable::ImageUnavailable
75 );
76 match interaction.begin_subject_analysis_if_necessary() {
77 Ok(()) => println!("subject analysis started"),
78 Err(error) => println!("subject analysis started: {error}"),
79 }
80 match interaction.subjects() {
81 Ok(subjects) => {
82 println!("subjects: {}", subjects.len());
83 println!(
84 "highlighted subjects: {}",
85 interaction.highlighted_subjects()?.len()
86 );
87 if let Some(subject) = subjects.first() {
88 println!("subject bounds: {:?}", subject.bounds()?);
89 }
90 match interaction.image_for_subjects(&subjects) {
91 Ok(image) => println!("subject image bytes: {}", image.png_data.len()),
92 Err(error) => println!("subject image bytes: {error}"),
93 }
94 }
95 Err(error) => println!("subjects: {error}"),
96 }
97 Ok(())
98}Sourcepub fn highlighted_subjects(
&self,
) -> Result<Vec<LiveTextSubject>, VisionKitError>
pub fn highlighted_subjects( &self, ) -> Result<Vec<LiveTextSubject>, VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 85)
69fn print_subject_state(
70 interaction: &LiveTextInteraction,
71) -> Result<(), Box<dyn std::error::Error>> {
72 println!(
73 "subject unavailable case: {:?}",
74 LiveTextSubjectUnavailable::ImageUnavailable
75 );
76 match interaction.begin_subject_analysis_if_necessary() {
77 Ok(()) => println!("subject analysis started"),
78 Err(error) => println!("subject analysis started: {error}"),
79 }
80 match interaction.subjects() {
81 Ok(subjects) => {
82 println!("subjects: {}", subjects.len());
83 println!(
84 "highlighted subjects: {}",
85 interaction.highlighted_subjects()?.len()
86 );
87 if let Some(subject) = subjects.first() {
88 println!("subject bounds: {:?}", subject.bounds()?);
89 }
90 match interaction.image_for_subjects(&subjects) {
91 Ok(image) => println!("subject image bytes: {}", image.png_data.len()),
92 Err(error) => println!("subject image bytes: {error}"),
93 }
94 }
95 Err(error) => println!("subjects: {error}"),
96 }
97 Ok(())
98}pub fn set_highlighted_subjects( &self, subjects: &[LiveTextSubject], ) -> Result<(), VisionKitError>
pub fn subject_at_point( &self, x: f64, y: f64, ) -> Result<Option<LiveTextSubject>, VisionKitError>
Sourcepub fn image_for_subjects(
&self,
subjects: &[LiveTextSubject],
) -> Result<LiveTextImageData, VisionKitError>
pub fn image_for_subjects( &self, subjects: &[LiveTextSubject], ) -> Result<LiveTextImageData, VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 90)
69fn print_subject_state(
70 interaction: &LiveTextInteraction,
71) -> Result<(), Box<dyn std::error::Error>> {
72 println!(
73 "subject unavailable case: {:?}",
74 LiveTextSubjectUnavailable::ImageUnavailable
75 );
76 match interaction.begin_subject_analysis_if_necessary() {
77 Ok(()) => println!("subject analysis started"),
78 Err(error) => println!("subject analysis started: {error}"),
79 }
80 match interaction.subjects() {
81 Ok(subjects) => {
82 println!("subjects: {}", subjects.len());
83 println!(
84 "highlighted subjects: {}",
85 interaction.highlighted_subjects()?.len()
86 );
87 if let Some(subject) = subjects.first() {
88 println!("subject bounds: {:?}", subject.bounds()?);
89 }
90 match interaction.image_for_subjects(&subjects) {
91 Ok(image) => println!("subject image bytes: {}", image.png_data.len()),
92 Err(error) => println!("subject image bytes: {error}"),
93 }
94 }
95 Err(error) => println!("subjects: {error}"),
96 }
97 Ok(())
98}Trait Implementations§
Source§impl Drop for LiveTextInteraction
impl Drop for LiveTextInteraction
Auto Trait Implementations§
impl Freeze for LiveTextInteraction
impl RefUnwindSafe for LiveTextInteraction
impl !Send for LiveTextInteraction
impl !Sync for LiveTextInteraction
impl Unpin for LiveTextInteraction
impl UnsafeUnpin for LiveTextInteraction
impl UnwindSafe for LiveTextInteraction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more