From caa03fbc2fcb96c0d630f133c8f9622f19f3fda5 Mon Sep 17 00:00:00 2001 From: Jeyaram Jeyaraj Date: Tue, 11 Apr 2017 13:24:12 -0700 Subject: [PATCH] Implementation of CTTypeSetter via CFRuntimeBase. - Removed the dependency on Foundation - Removed the private member access of CTTypeSetter - Code improvements Fixes #2355 --- Frameworks/CoreText/CTTypesetter.mm | 55 +++++++++++++-------------- Frameworks/include/CoreTextInternal.h | 10 +---- include/CoreText/CTTypesetter.h | 2 +- 3 files changed, 29 insertions(+), 38 deletions(-) diff --git a/Frameworks/CoreText/CTTypesetter.mm b/Frameworks/CoreText/CTTypesetter.mm index 8846c83aa8..5c69ad2f10 100644 --- a/Frameworks/CoreText/CTTypesetter.mm +++ b/Frameworks/CoreText/CTTypesetter.mm @@ -21,6 +21,7 @@ #import "DWriteWrapper_CoreText.h" #import #import +#import #import "LoggingNative.h" static const wchar_t* TAG = L"CTTypesetter"; @@ -28,27 +29,28 @@ const CFStringRef kCTTypesetterOptionDisableBidiProcessing = CFSTR("kCTTypesetterOptionDisableBidiProcessing"); const CFStringRef kCTTypesetterOptionForcedEmbeddingLevel = CFSTR("kCTTypesetterOptionForcedEmbeddingLevel"); -@implementation _CTTypesetter -- (instancetype)initWithAttributedString:(NSAttributedString*)str { - _attributedString = str; - _string = [str string]; +struct __CTTypesetter : CoreFoundation::CppBase<__CTTypesetter> { + __CTTypesetter(CFAttributedStringRef attributedString) : _attributedString(attributedString) { + } - return self; -} + inline CFAttributedStringRef AttributedString() const { + return _attributedString; + } + +private: + woc::StrongCF _attributedString; +}; -- (void)dealloc { - _string = nil; - _attributedString = nil; - [super dealloc]; +CFAttributedStringRef _CTTypesetterGetAttributedString(CTTypesetterRef typesetter) { + RETURN_NULL_IF(!typesetter); + return typesetter->AttributedString(); } -@end /** @Status Interoperable */ CTTypesetterRef CTTypesetterCreateWithAttributedString(CFAttributedStringRef string) { - _CTTypesetter* ret = [[_CTTypesetter alloc] initWithAttributedString:(NSAttributedString*)string]; - return (CTTypesetterRef)ret; + return __CTTypesetter::CreateInstance(kCFAllocatorDefault, string); } /** @@ -62,7 +64,6 @@ CTTypesetterRef CTTypesetterCreateWithAttributedStringAndOptions(CFAttributedStr /** @Status Interoperable - @Notes */ CTLineRef CTTypesetterCreateLine(CTTypesetterRef typesetter, CFRange stringRange) { return CTTypesetterCreateLineWithOffset(typesetter, stringRange, 0.0f); @@ -70,12 +71,9 @@ CTLineRef CTTypesetterCreateLine(CTTypesetterRef typesetter, CFRange stringRange /** @Status Interoperable - @Notes */ CTLineRef CTTypesetterCreateLineWithOffset(CTTypesetterRef ts, CFRange range, double offset) { - _CTFrame* frame = _DWriteGetFrame(static_cast(static_cast<_CTTypesetter*>(ts)->_attributedString.get()), - range, - CGRectMake(offset, 0, FLT_MAX, FLT_MAX)); + _CTFrame* frame = _DWriteGetFrame(ts->AttributedString(), range, CGRectMake(offset, 0, FLT_MAX, FLT_MAX)); RETURN_NULL_IF(!frame); if ([frame->_lines count] != 1) { @@ -92,7 +90,6 @@ CTLineRef CTTypesetterCreateLineWithOffset(CTTypesetterRef ts, CFRange range, do /** @Status Interoperable - @Notes */ CFIndex CTTypesetterSuggestLineBreak(CTTypesetterRef typesetter, CFIndex startIndex, double width) { return CTTypesetterSuggestLineBreakWithOffset(typesetter, startIndex, width, 0.0f); @@ -100,14 +97,16 @@ CFIndex CTTypesetterSuggestLineBreak(CTTypesetterRef typesetter, CFIndex startIn /** @Status Interoperable - @Notes */ -CFIndex CTTypesetterSuggestLineBreakWithOffset(CTTypesetterRef ts, CFIndex index, double width, double offset) { - _CTTypesetter* typesetter = static_cast<_CTTypesetter*>(ts); - _CTFrame* frame = _DWriteGetFrame(static_cast(typesetter->_attributedString.get()), - CFRangeMake(index, [typesetter->_string length] - index), +CFIndex CTTypesetterSuggestLineBreakWithOffset(CTTypesetterRef typesetter, CFIndex index, double width, double offset) { + _CTFrame* frame = _DWriteGetFrame(typesetter->AttributedString(), + CFRangeMake(index, CFAttributedStringGetLength(typesetter->AttributedString()) - index), CGRectMake(offset, 0, width, FLT_MAX)); - return ([frame->_lines count] > 0) ? static_cast<_CTLine*>([frame->_lines firstObject])->_strRange.length : 0; + if ([frame->_lines count] > 0) { + return static_cast<_CTLine*>([frame->_lines firstObject])->_strRange.length; + } + + return 0; } /** @@ -129,10 +128,8 @@ CFIndex CTTypesetterSuggestClusterBreakWithOffset(CTTypesetterRef typesetter, CF } /** - @Status NotInPlan - @Notes + @Status Interoperable */ CFTypeID CTTypesetterGetTypeID() { - UNIMPLEMENTED(); - return StubReturn(); + return __CTTypesetter::GetTypeID(); } diff --git a/Frameworks/include/CoreTextInternal.h b/Frameworks/include/CoreTextInternal.h index 85c4174c03..2a94d7454d 100644 --- a/Frameworks/include/CoreTextInternal.h +++ b/Frameworks/include/CoreTextInternal.h @@ -17,7 +17,6 @@ #import #import - #import "Starboard.h" #include #import @@ -46,19 +45,14 @@ inline void _SafeRelease(T** p) { } } -@interface _CTTypesetter : NSObject { -@public - StrongId _attributedString; - StrongId _string; -} -@end - @interface _CTFramesetter : NSObject { @public StrongId<_CTTypesetter> _typesetter; } @end +CFAttributedStringRef _CTTypesetterGetAttributedString(CTTypesetterRef typesetter); + @interface _CTRun : NSObject { @public StrongId> _attributes; diff --git a/include/CoreText/CTTypesetter.h b/include/CoreText/CTTypesetter.h index 1c9264d770..7a8d9e56f3 100644 --- a/include/CoreText/CTTypesetter.h +++ b/include/CoreText/CTTypesetter.h @@ -39,4 +39,4 @@ CORETEXT_EXPORT CFIndex CTTypesetterSuggestClusterBreakWithOffset(CTTypesetterRe CFIndex startIndex, double width, double offset) STUB_METHOD; -CORETEXT_EXPORT CFTypeID CTTypesetterGetTypeID() NOTINPLAN_METHOD; +CORETEXT_EXPORT CFTypeID CTTypesetterGetTypeID();