use std::ffi::c_void;
use crate::{arc, cf, define_cf_type};
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[repr(u8)]
pub enum TextAlignment {
Left = 0,
Right = 1,
Center = 2,
Justified = 3,
Natural = 4,
}
#[repr(u8)]
pub enum LineBreakMode {
WordWrapping = 0,
CharWrapping = 1,
Clipping = 2,
TruncatingHead = 3,
TruncatingTail = 4,
TruncatingMiddle = 5,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(i8)]
pub enum WritingDirection {
Natural = -1,
LeftToRight = 0,
RightToLeft = 1,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[repr(u32)]
pub enum ParagraphStyleSpecifier {
Alignment = 0,
FirstLineHeadIndent = 1,
HeadIndent = 2,
TailIndent = 3,
TabStops = 4,
DefaultTabInterval = 5,
LineBreakMode = 6,
LineHeightMultiple = 7,
MaximumLineHeight = 8,
MinimumLineHeight = 9,
ParagraphSpacing = 11,
ParagraphSpacingBefore = 12,
BaseWritingDirection = 13,
MaximumLineSpacing = 14,
MinimumLineSpacing = 15,
LineSpacingAdjustment = 16,
LineBoundsOptions = 17,
}
#[repr(C)]
pub struct ParagraphStyleSetting {
pub spec: ParagraphStyleSpecifier,
pub value_size: usize,
pub value: *const c_void,
}
define_cf_type!(ParagraphStyle(cf::Type));
impl ParagraphStyle {
#[inline]
pub fn type_id() -> cf::TypeId {
unsafe { CTParagraphStyleGetTypeID() }
}
#[inline]
pub fn with_settings(settings: &[ParagraphStyleSetting]) -> Option<arc::R<Self>> {
unsafe { CTParagraphStyleCreate(settings.as_ptr(), settings.len()) }
}
#[inline]
pub fn copy(&self) -> arc::R<Self> {
unsafe { CTParagraphStyleCreateCopy(self) }
}
#[inline]
pub fn value_for_spec(
&self,
spec: ParagraphStyleSpecifier,
value_buf_size: usize,
value_buf: *mut c_void,
) -> bool {
unsafe { CTParagraphStyleGetValueForSpecifier(self, spec, value_buf_size, value_buf) }
}
}
#[link(name = "CoreText", kind = "framework")]
unsafe extern "C-unwind" {
fn CTParagraphStyleGetTypeID() -> cf::TypeId;
fn CTParagraphStyleCreate(
settings: *const ParagraphStyleSetting,
setting_count: usize,
) -> Option<arc::R<ParagraphStyle>>;
fn CTParagraphStyleCreateCopy(ps: &ParagraphStyle) -> arc::R<ParagraphStyle>;
fn CTParagraphStyleGetValueForSpecifier(
ps: &ParagraphStyle,
spec: ParagraphStyleSpecifier,
value_buf_size: usize,
value_buf: *mut c_void,
) -> bool;
}
#[cfg(test)]
mod tests {
use crate::ct;
#[test]
fn basics() {
let style = ct::ParagraphStyle::with_settings(&[]).unwrap();
let _style_copy = style.copy();
style.show();
}
}