| 1 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 |
|
| 5 |
use std::borrow::Cow; |
| 6 |
use std::marker::PhantomData; |
| 7 |
use winapi::ctypes::wchar_t; |
| 8 |
use winapi::um::dwrite::IDWriteTextAnalysisSource; |
| 9 |
use wio::com::ComPtr; |
| 10 |
|
| 11 |
use super::*; |
| 12 |
use crate::com_helpers::Com; |
| 13 |
|
| 14 |
pub struct TextAnalysisSource<'a> { |
| 15 |
native: ComPtr<IDWriteTextAnalysisSource>, |
| 16 |
phantom: PhantomData<CustomTextAnalysisSourceImpl<'a>> |
| 17 |
} |
| 18 |
|
| 19 |
impl<'a> TextAnalysisSource<'a> { |
| 20 |
/// Create a new custom TextAnalysisSource for the given text and a trait |
| 21 |
/// implementation. |
| 22 |
/// |
| 23 |
/// Note: this method has no NumberSubsitution specified. See |
| 24 |
/// `from_text_and_number_subst` if you need number substitution. |
| 25 |
pub fn from_text( |
| 26 |
inner: Box<dyn TextAnalysisSourceMethods + 'a>, |
| 27 |
text: Cow<'a, [wchar_t]>, |
| 28 |
) -> TextAnalysisSource<'a> { |
| 29 |
let native = unsafe { |
| 30 |
ComPtr::from_raw( |
| 31 |
CustomTextAnalysisSourceImpl::from_text_native(inner, text).into_interface() |
| 32 |
) |
| 33 |
}; |
| 34 |
TextAnalysisSource { native, phantom: PhantomData } |
| 35 |
} |
| 36 |
|
| 37 |
/// Create a new custom TextAnalysisSource for the given text and a trait |
| 38 |
/// implementation. |
| 39 |
/// |
| 40 |
/// Note: this method only supports a single `NumberSubstitution` for the |
| 41 |
/// entire string. |
| 42 |
pub fn from_text_and_number_subst( |
| 43 |
inner: Box<dyn TextAnalysisSourceMethods + 'a>, |
| 44 |
text: Cow<'a, [wchar_t]>, |
| 45 |
number_subst: NumberSubstitution, |
| 46 |
) -> TextAnalysisSource<'a> { |
| 47 |
let native = unsafe { |
| 48 |
ComPtr::from_raw( |
| 49 |
CustomTextAnalysisSourceImpl::from_text_and_number_subst_native( |
| 50 |
inner, |
| 51 |
text, |
| 52 |
number_subst, |
| 53 |
) |
| 54 |
.into_interface() |
| 55 |
) |
| 56 |
}; |
| 57 |
TextAnalysisSource { native, phantom: PhantomData } |
| 58 |
} |
| 59 |
|
| 60 |
pub fn as_ptr(&self) -> *mut IDWriteTextAnalysisSource { |
| 61 |
self.native.as_raw() |
| 62 |
} |
| 63 |
} |