From 510ed73ad74f54bf4ad12a4e59f7bb45a6f2b97e Mon Sep 17 00:00:00 2001 From: toolscode <46835624+toolscode@users.noreply.github.com> Date: Tue, 10 Jun 2025 21:29:44 +0900 Subject: [PATCH] Added CTTypesetter APIs. CTTypesetterCreateLine CTTypesetterSuggestLineBreak CTTypesetterCreateLineWithOffset CTTypesetterSuggestClusterBreak CTTypesetterSuggestClusterBreakWithOffset --- core-text/src/lib.rs | 1 + core-text/src/typesetter.rs | 82 +++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 core-text/src/typesetter.rs diff --git a/core-text/src/lib.rs b/core-text/src/lib.rs index 8311c8b3..5756c1be 100644 --- a/core-text/src/lib.rs +++ b/core-text/src/lib.rs @@ -23,5 +23,6 @@ pub mod font_manager; pub mod frame; pub mod framesetter; pub mod line; +pub mod typesetter; pub mod run; pub mod string_attributes; diff --git a/core-text/src/typesetter.rs b/core-text/src/typesetter.rs new file mode 100644 index 00000000..dad4bb42 --- /dev/null +++ b/core-text/src/typesetter.rs @@ -0,0 +1,82 @@ +// Copyright 2013 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// 20250606 added by jwhur + +use super::line::{CTLine, CTLineRef}; +use core_foundation::attributed_string::CFAttributedStringRef; +use core_foundation::base::{CFIndex, CFRange, CFTypeID, TCFType}; +use core_foundation::dictionary::CFDictionaryRef; +use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType}; +use core_graphics::geometry::CGSize; +use core_graphics::path::{CGPath, CGPathRef}; +use foreign_types::{ForeignType, ForeignTypeRef}; +use std::ptr::null; + +#[repr(C)] +pub struct __CTTypesetter(core::ffi::c_void); + +pub type CTTypesetterRef = *const __CTTypesetter; + +declare_TCFType! { + CTTypesetter, CTTypesetterRef +} +impl_TCFType!(CTTypesetter, CTTypesetterRef, CTTypesetterGetTypeID); +impl_CFTypeDescription!(CTTypesetter); + +impl CTTypesetter { + pub fn new_with_attributed_string(string: CFAttributedStringRef) -> Self { + unsafe { + let ptr = CTTypesetterCreateWithAttributedString(string); + CTTypesetter::wrap_under_create_rule(ptr) + } + } + + pub fn create_line(&self, string_range: CFRange) -> CTLine { + unsafe { + let ptr = CTTypesetterCreateLine( + self.as_concrete_TypeRef(), + string_range + ); + + CTLine::wrap_under_create_rule(ptr) + } + } +} + +#[cfg_attr(feature = "link", link(name = "CoreText", kind = "framework"))] +extern "C" { + fn CTTypesetterGetTypeID() -> CFTypeID; + fn CTTypesetterCreateWithAttributedString(string: CFAttributedStringRef) -> CTTypesetterRef; + fn CTTypesetterCreateLine( + typesetter: CTTypesetterRef, + string_range: CFRange, + ) -> CTLineRef; + fn CTTypesetterSuggestLineBreak( + typesetter: CTTypesetterRef, + startIndex: CFIndex, + width: f64, + ) -> CFIndex; + fn CTTypesetterCreateLineWithOffset( + typesetter: CTTypesetterRef, + startIndex: CFIndex, + offset: f64, + ) -> CFIndex; + fn CTTypesetterSuggestClusterBreak( + typesetter: CTTypesetterRef, + startIndex: CFIndex, + width: f64, + ) -> CFIndex; + fn CTTypesetterSuggestClusterBreakWithOffset( + typesetter: CTTypesetterRef, + startIndex: CFIndex, + width: f64, + offset: f64, + ) -> CFIndex; +}