Skip to content

Added CTTypesetter APIs in core-text. #734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core-text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
82 changes: 82 additions & 0 deletions core-text/src/typesetter.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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;
}