use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;
#[cfg(feature = "objc2-core-graphics")]
use objc2_core_graphics::*;
use crate::*;
#[doc(alias = "CTLineRef")]
#[repr(C)]
pub struct CTLine {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CTLine {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CTLine"> for CTLine {}
);
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CTLineBoundsOptions(pub CFOptionFlags);
bitflags::bitflags! {
impl CTLineBoundsOptions: CFOptionFlags {
#[doc(alias = "kCTLineBoundsExcludeTypographicLeading")]
const ExcludeTypographicLeading = 1<<0;
#[doc(alias = "kCTLineBoundsExcludeTypographicShifts")]
const ExcludeTypographicShifts = 1<<1;
#[doc(alias = "kCTLineBoundsUseHangingPunctuation")]
const UseHangingPunctuation = 1<<2;
#[doc(alias = "kCTLineBoundsUseGlyphPathBounds")]
const UseGlyphPathBounds = 1<<3;
#[doc(alias = "kCTLineBoundsUseOpticalBounds")]
const UseOpticalBounds = 1<<4;
#[doc(alias = "kCTLineBoundsIncludeLanguageExtents")]
const IncludeLanguageExtents = 1<<5;
}
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CTLineBoundsOptions {
const ENCODING: Encoding = CFOptionFlags::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CTLineBoundsOptions {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CTLineTruncationType(pub u32);
impl CTLineTruncationType {
#[doc(alias = "kCTLineTruncationStart")]
pub const Start: Self = Self(0);
#[doc(alias = "kCTLineTruncationEnd")]
pub const End: Self = Self(1);
#[doc(alias = "kCTLineTruncationMiddle")]
pub const Middle: Self = Self(2);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CTLineTruncationType {
const ENCODING: Encoding = u32::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CTLineTruncationType {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
unsafe impl ConcreteType for CTLine {
#[doc(alias = "CTLineGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CTLineGetTypeID() -> CFTypeID;
}
unsafe { CTLineGetTypeID() }
}
}
impl CTLine {
#[doc(alias = "CTLineCreateWithAttributedString")]
#[inline]
pub unsafe fn with_attributed_string(attr_string: &CFAttributedString) -> CFRetained<CTLine> {
extern "C-unwind" {
fn CTLineCreateWithAttributedString(
attr_string: &CFAttributedString,
) -> Option<NonNull<CTLine>>;
}
let ret = unsafe { CTLineCreateWithAttributedString(attr_string) };
let ret =
ret.expect("function was marked as returning non-null, but actually returned NULL");
unsafe { CFRetained::from_raw(ret) }
}
#[doc(alias = "CTLineCreateTruncatedLine")]
#[inline]
pub unsafe fn truncated_line(
&self,
width: c_double,
truncation_type: CTLineTruncationType,
truncation_token: Option<&CTLine>,
) -> Option<CFRetained<CTLine>> {
extern "C-unwind" {
fn CTLineCreateTruncatedLine(
line: &CTLine,
width: c_double,
truncation_type: CTLineTruncationType,
truncation_token: Option<&CTLine>,
) -> Option<NonNull<CTLine>>;
}
let ret =
unsafe { CTLineCreateTruncatedLine(self, width, truncation_type, truncation_token) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CTLineCreateJustifiedLine")]
#[inline]
pub unsafe fn justified_line(
&self,
justification_factor: CGFloat,
justification_width: c_double,
) -> Option<CFRetained<CTLine>> {
extern "C-unwind" {
fn CTLineCreateJustifiedLine(
line: &CTLine,
justification_factor: CGFloat,
justification_width: c_double,
) -> Option<NonNull<CTLine>>;
}
let ret =
unsafe { CTLineCreateJustifiedLine(self, justification_factor, justification_width) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CTLineGetGlyphCount")]
#[inline]
pub unsafe fn glyph_count(&self) -> CFIndex {
extern "C-unwind" {
fn CTLineGetGlyphCount(line: &CTLine) -> CFIndex;
}
unsafe { CTLineGetGlyphCount(self) }
}
#[doc(alias = "CTLineGetGlyphRuns")]
#[inline]
pub unsafe fn glyph_runs(&self) -> CFRetained<CFArray> {
extern "C-unwind" {
fn CTLineGetGlyphRuns(line: &CTLine) -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CTLineGetGlyphRuns(self) };
let ret =
ret.expect("function was marked as returning non-null, but actually returned NULL");
unsafe { CFRetained::retain(ret) }
}
#[doc(alias = "CTLineGetStringRange")]
#[inline]
pub unsafe fn string_range(&self) -> CFRange {
extern "C-unwind" {
fn CTLineGetStringRange(line: &CTLine) -> CFRange;
}
unsafe { CTLineGetStringRange(self) }
}
#[doc(alias = "CTLineGetPenOffsetForFlush")]
#[inline]
pub unsafe fn pen_offset_for_flush(
&self,
flush_factor: CGFloat,
flush_width: c_double,
) -> c_double {
extern "C-unwind" {
fn CTLineGetPenOffsetForFlush(
line: &CTLine,
flush_factor: CGFloat,
flush_width: c_double,
) -> c_double;
}
unsafe { CTLineGetPenOffsetForFlush(self, flush_factor, flush_width) }
}
#[doc(alias = "CTLineDraw")]
#[cfg(feature = "objc2-core-graphics")]
#[inline]
pub unsafe fn draw(&self, context: &CGContext) {
extern "C-unwind" {
fn CTLineDraw(line: &CTLine, context: &CGContext);
}
unsafe { CTLineDraw(self, context) }
}
#[doc(alias = "CTLineGetTypographicBounds")]
#[inline]
pub unsafe fn typographic_bounds(
&self,
ascent: *mut CGFloat,
descent: *mut CGFloat,
leading: *mut CGFloat,
) -> c_double {
extern "C-unwind" {
fn CTLineGetTypographicBounds(
line: &CTLine,
ascent: *mut CGFloat,
descent: *mut CGFloat,
leading: *mut CGFloat,
) -> c_double;
}
unsafe { CTLineGetTypographicBounds(self, ascent, descent, leading) }
}
#[doc(alias = "CTLineGetBoundsWithOptions")]
#[inline]
pub unsafe fn bounds_with_options(&self, options: CTLineBoundsOptions) -> CGRect {
extern "C-unwind" {
fn CTLineGetBoundsWithOptions(line: &CTLine, options: CTLineBoundsOptions) -> CGRect;
}
unsafe { CTLineGetBoundsWithOptions(self, options) }
}
#[doc(alias = "CTLineGetTrailingWhitespaceWidth")]
#[inline]
pub unsafe fn trailing_whitespace_width(&self) -> c_double {
extern "C-unwind" {
fn CTLineGetTrailingWhitespaceWidth(line: &CTLine) -> c_double;
}
unsafe { CTLineGetTrailingWhitespaceWidth(self) }
}
#[doc(alias = "CTLineGetImageBounds")]
#[cfg(feature = "objc2-core-graphics")]
#[inline]
pub unsafe fn image_bounds(&self, context: Option<&CGContext>) -> CGRect {
extern "C-unwind" {
fn CTLineGetImageBounds(line: &CTLine, context: Option<&CGContext>) -> CGRect;
}
unsafe { CTLineGetImageBounds(self, context) }
}
#[doc(alias = "CTLineGetStringIndexForPosition")]
#[inline]
pub unsafe fn string_index_for_position(&self, position: CGPoint) -> CFIndex {
extern "C-unwind" {
fn CTLineGetStringIndexForPosition(line: &CTLine, position: CGPoint) -> CFIndex;
}
unsafe { CTLineGetStringIndexForPosition(self, position) }
}
#[doc(alias = "CTLineGetOffsetForStringIndex")]
#[inline]
pub unsafe fn offset_for_string_index(
&self,
char_index: CFIndex,
secondary_offset: *mut CGFloat,
) -> CGFloat {
extern "C-unwind" {
fn CTLineGetOffsetForStringIndex(
line: &CTLine,
char_index: CFIndex,
secondary_offset: *mut CGFloat,
) -> CGFloat;
}
unsafe { CTLineGetOffsetForStringIndex(self, char_index, secondary_offset) }
}
#[doc(alias = "CTLineEnumerateCaretOffsets")]
#[cfg(feature = "block2")]
#[inline]
pub unsafe fn enumerate_caret_offsets(
&self,
block: &block2::DynBlock<dyn Fn(c_double, CFIndex, bool, NonNull<bool>)>,
) {
extern "C-unwind" {
fn CTLineEnumerateCaretOffsets(
line: &CTLine,
block: &block2::DynBlock<dyn Fn(c_double, CFIndex, bool, NonNull<bool>)>,
);
}
unsafe { CTLineEnumerateCaretOffsets(self, block) }
}
}
#[deprecated = "renamed to `CTLine::with_attributed_string`"]
#[inline]
pub unsafe extern "C-unwind" fn CTLineCreateWithAttributedString(
attr_string: &CFAttributedString,
) -> CFRetained<CTLine> {
extern "C-unwind" {
fn CTLineCreateWithAttributedString(
attr_string: &CFAttributedString,
) -> Option<NonNull<CTLine>>;
}
let ret = unsafe { CTLineCreateWithAttributedString(attr_string) };
let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
unsafe { CFRetained::from_raw(ret) }
}
#[deprecated = "renamed to `CTLine::truncated_line`"]
#[inline]
pub unsafe extern "C-unwind" fn CTLineCreateTruncatedLine(
line: &CTLine,
width: c_double,
truncation_type: CTLineTruncationType,
truncation_token: Option<&CTLine>,
) -> Option<CFRetained<CTLine>> {
extern "C-unwind" {
fn CTLineCreateTruncatedLine(
line: &CTLine,
width: c_double,
truncation_type: CTLineTruncationType,
truncation_token: Option<&CTLine>,
) -> Option<NonNull<CTLine>>;
}
let ret = unsafe { CTLineCreateTruncatedLine(line, width, truncation_type, truncation_token) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CTLine::justified_line`"]
#[inline]
pub unsafe extern "C-unwind" fn CTLineCreateJustifiedLine(
line: &CTLine,
justification_factor: CGFloat,
justification_width: c_double,
) -> Option<CFRetained<CTLine>> {
extern "C-unwind" {
fn CTLineCreateJustifiedLine(
line: &CTLine,
justification_factor: CGFloat,
justification_width: c_double,
) -> Option<NonNull<CTLine>>;
}
let ret = unsafe { CTLineCreateJustifiedLine(line, justification_factor, justification_width) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CTLine::glyph_count`"]
pub fn CTLineGetGlyphCount(line: &CTLine) -> CFIndex;
}
#[deprecated = "renamed to `CTLine::glyph_runs`"]
#[inline]
pub unsafe extern "C-unwind" fn CTLineGetGlyphRuns(line: &CTLine) -> CFRetained<CFArray> {
extern "C-unwind" {
fn CTLineGetGlyphRuns(line: &CTLine) -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CTLineGetGlyphRuns(line) };
let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
unsafe { CFRetained::retain(ret) }
}
extern "C-unwind" {
#[deprecated = "renamed to `CTLine::string_range`"]
pub fn CTLineGetStringRange(line: &CTLine) -> CFRange;
}
extern "C-unwind" {
#[deprecated = "renamed to `CTLine::pen_offset_for_flush`"]
pub fn CTLineGetPenOffsetForFlush(
line: &CTLine,
flush_factor: CGFloat,
flush_width: c_double,
) -> c_double;
}
extern "C-unwind" {
#[cfg(feature = "objc2-core-graphics")]
#[deprecated = "renamed to `CTLine::draw`"]
pub fn CTLineDraw(line: &CTLine, context: &CGContext);
}
extern "C-unwind" {
#[deprecated = "renamed to `CTLine::typographic_bounds`"]
pub fn CTLineGetTypographicBounds(
line: &CTLine,
ascent: *mut CGFloat,
descent: *mut CGFloat,
leading: *mut CGFloat,
) -> c_double;
}
extern "C-unwind" {
#[deprecated = "renamed to `CTLine::bounds_with_options`"]
pub fn CTLineGetBoundsWithOptions(line: &CTLine, options: CTLineBoundsOptions) -> CGRect;
}
extern "C-unwind" {
#[deprecated = "renamed to `CTLine::trailing_whitespace_width`"]
pub fn CTLineGetTrailingWhitespaceWidth(line: &CTLine) -> c_double;
}
extern "C-unwind" {
#[cfg(feature = "objc2-core-graphics")]
#[deprecated = "renamed to `CTLine::image_bounds`"]
pub fn CTLineGetImageBounds(line: &CTLine, context: Option<&CGContext>) -> CGRect;
}
extern "C-unwind" {
#[deprecated = "renamed to `CTLine::string_index_for_position`"]
pub fn CTLineGetStringIndexForPosition(line: &CTLine, position: CGPoint) -> CFIndex;
}
extern "C-unwind" {
#[deprecated = "renamed to `CTLine::offset_for_string_index`"]
pub fn CTLineGetOffsetForStringIndex(
line: &CTLine,
char_index: CFIndex,
secondary_offset: *mut CGFloat,
) -> CGFloat;
}
extern "C-unwind" {
#[cfg(feature = "block2")]
#[deprecated = "renamed to `CTLine::enumerate_caret_offsets`"]
pub fn CTLineEnumerateCaretOffsets(
line: &CTLine,
block: &block2::DynBlock<dyn Fn(c_double, CFIndex, bool, NonNull<bool>)>,
);
}