Skip to content

Commit

Permalink
Implementation of CTTypeSetter via CFRuntimeBase.
Browse files Browse the repository at this point in the history
- Removed the dependency on Foundation
- Removed the private member access of CTTypeSetter
- Code improvements
Fixes #2355
  • Loading branch information
msft-Jeyaram committed Apr 11, 2017
1 parent b79ce19 commit caa03fb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 38 deletions.
55 changes: 26 additions & 29 deletions Frameworks/CoreText/CTTypesetter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,36 @@
#import "DWriteWrapper_CoreText.h"
#import <Foundation/NSAttributedString.h>
#import <algorithm>
#import <CFCppBase.h>
#import "LoggingNative.h"

static const wchar_t* TAG = L"CTTypesetter";

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<CFAttributedStringRef> _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);
}

/**
Expand All @@ -62,20 +64,16 @@ CTTypesetterRef CTTypesetterCreateWithAttributedStringAndOptions(CFAttributedStr

/**
@Status Interoperable
@Notes
*/
CTLineRef CTTypesetterCreateLine(CTTypesetterRef typesetter, CFRange stringRange) {
return CTTypesetterCreateLineWithOffset(typesetter, stringRange, 0.0f);
}

/**
@Status Interoperable
@Notes
*/
CTLineRef CTTypesetterCreateLineWithOffset(CTTypesetterRef ts, CFRange range, double offset) {
_CTFrame* frame = _DWriteGetFrame(static_cast<CFAttributedStringRef>(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) {
Expand All @@ -92,22 +90,23 @@ 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);
}

/**
@Status Interoperable
@Notes
*/
CFIndex CTTypesetterSuggestLineBreakWithOffset(CTTypesetterRef ts, CFIndex index, double width, double offset) {
_CTTypesetter* typesetter = static_cast<_CTTypesetter*>(ts);
_CTFrame* frame = _DWriteGetFrame(static_cast<CFAttributedStringRef>(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;
}

/**
Expand All @@ -129,10 +128,8 @@ CFIndex CTTypesetterSuggestClusterBreakWithOffset(CTTypesetterRef typesetter, CF
}

/**
@Status NotInPlan
@Notes
@Status Interoperable
*/
CFTypeID CTTypesetterGetTypeID() {
UNIMPLEMENTED();
return StubReturn();
return __CTTypesetter::GetTypeID();
}
10 changes: 2 additions & 8 deletions Frameworks/include/CoreTextInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#import <CoreText/CoreText.h>
#import <CoreText/CTParagraphStyle.h>

#import "Starboard.h"
#include <COMIncludes.h>
#import <DWrite.h>
Expand Down Expand Up @@ -46,19 +45,14 @@ inline void _SafeRelease(T** p) {
}
}

@interface _CTTypesetter : NSObject {
@public
StrongId<NSAttributedString> _attributedString;
StrongId<NSString> _string;
}
@end

@interface _CTFramesetter : NSObject {
@public
StrongId<_CTTypesetter> _typesetter;
}
@end

CFAttributedStringRef _CTTypesetterGetAttributedString(CTTypesetterRef typesetter);

@interface _CTRun : NSObject {
@public
StrongId<NSMutableDictionary<NSString*, id>> _attributes;
Expand Down
2 changes: 1 addition & 1 deletion include/CoreText/CTTypesetter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit caa03fb

Please sign in to comment.