Skip to content

Commit

Permalink
Implementation of CTFramesetter via CFRuntimeBase.
Browse files Browse the repository at this point in the history
- Removed the dependency on Foundation
- Removed the private member access of CTFramesetter
- Code improvements
Fixes #2358
  • Loading branch information
msft-Jeyaram committed Apr 11, 2017
1 parent b9603c0 commit 37ba3a8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 38 deletions.
60 changes: 29 additions & 31 deletions Frameworks/CoreText/CTFramesetter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,45 @@
#import <algorithm>
#import "CoreTextInternal.h"
#import "CGPathInternal.h"
#import <CFCppBase.h>
#import "DWriteWrapper_CoreText.h"

@implementation _CTFramesetter : NSObject
@end
struct __CTFramesetter : CoreFoundation::CppBase<__CTFramesetter> {
__CTFramesetter(CTTypesetterRef typesetter) : _typesetter(typesetter) {
}

inline CTTypesetterRef Typesetter() const {
return _typesetter;
}

private:
woc::StrongCF<CTTypesetterRef> _typesetter;
};

/**
@Status Interoperable
*/
CTFramesetterRef CTFramesetterCreateWithAttributedString(CFAttributedStringRef string) {
_CTFramesetter* ret = [_CTFramesetter alloc];
ret->_typesetter.attach(static_cast<_CTTypesetter*>(CTTypesetterCreateWithAttributedString(string)));
return static_cast<CTFramesetterRef>(ret);
auto typesetter = woc::MakeStrongCF<CTTypesetterRef>(CTTypesetterCreateWithAttributedString(string));
return __CTFramesetter::CreateInstance(kCFAllocatorDefault, typesetter);
}

/**
@Status Caveat
@Notes frameAttributes parameter ignored
*/
CTFrameRef CTFramesetterCreateFrame(CTFramesetterRef framesetterRef, CFRange range, CGPathRef path, CFDictionaryRef frameAttributes) {
RETURN_NULL_IF(framesetterRef == nil || path == nullptr);
CTFrameRef CTFramesetterCreateFrame(CTFramesetterRef framesetter, CFRange range, CGPathRef path, CFDictionaryRef frameAttributes) {
RETURN_NULL_IF(framesetter == nil || path == nullptr);

CGRect frameRect = CGPathGetBoundingBox(path);
_CTFramesetter* framesetter = static_cast<_CTFramesetter*>(framesetterRef);

// Call _DWriteWrapper to get _CTLine object list that makes up this frame
_CTTypesetter* typesetter = static_cast<_CTTypesetter*>(framesetter->_typesetter);
CFAttributedStringRef attributedString = _CTTypesetterGetAttributedString(framesetter->Typesetter());
if (range.length == 0L) {
range.length = [typesetter->_string length] - range.location;
range.length = CFAttributedStringGetLength(attributedString) - range.location;
}

StrongId<_CTFrame> ret = _DWriteGetFrame(static_cast<CFAttributedStringRef>(typesetter->_attributedString.get()), range, frameRect);
StrongId<_CTFrame> ret = _DWriteGetFrame(attributedString, range, frameRect);
ret->_path.reset(CGPathRetain(path));
ret->_frameRect.origin = frameRect.origin;

Expand All @@ -57,10 +66,8 @@ CTFrameRef CTFramesetterCreateFrame(CTFramesetterRef framesetterRef, CFRange ran
return static_cast<CTFrameRef>(ret.detach());
}

CTParagraphStyleRef settings =
static_cast<CTParagraphStyleRef>([typesetter->_attributedString attribute:static_cast<NSString*>(kCTParagraphStyleAttributeName)
atIndex:range.location
effectiveRange:nullptr]);
CTParagraphStyleRef settings = static_cast<CTParagraphStyleRef>(
CFAttributedStringGetAttribute(attributedString, range.location, kCTParagraphStyleAttributeName, nullptr));

if (settings == nullptr) {
return static_cast<CTFrameRef>(ret.detach());
Expand Down Expand Up @@ -107,34 +114,25 @@ CTFrameRef CTFramesetterCreateFrame(CTFramesetterRef framesetterRef, CFRange ran

/**
@Status Interoperable
@Notes
*/
CTTypesetterRef CTFramesetterGetTypesetter(CTFramesetterRef framesetter) {
return framesetter ? static_cast<CTTypesetterRef>(static_cast<_CTFramesetter*>(framesetter)->_typesetter.get()) : nil;
RETURN_NULL_IF(!framesetter);
return framesetter->Typesetter();
}

/**
@Status Caveat
@Notes frameAttributes parameter ignored
@Notes
*/
CGSize CTFramesetterSuggestFrameSizeWithConstraints(
CTFramesetterRef framesetter, CFRange stringRange, CFDictionaryRef frameAttributes, CGSize constraints, CFRange* fitRange) {
if (framesetter == nil) {
return CGSizeZero;
}

CFAttributedStringRef string =
static_cast<CFAttributedStringRef>(static_cast<_CTFramesetter*>(framesetter)->_typesetter->_attributedString.get());

return _DWriteGetFrameSize(string, stringRange, constraints, fitRange);
RETURN_RESULT_IF_NULL(framesetter, CGSizeZero);
return _DWriteGetFrameSize(_CTTypesetterGetAttributedString(framesetter->Typesetter()), stringRange, constraints, fitRange);
}

/**
@Status Stub
@Notes
@Status Interoperable
*/
CFTypeID CTFramesetterGetTypeID() {
UNIMPLEMENTED();
return StubReturn();
}
return __CTFramesetter::GetTypeID();
}
6 changes: 0 additions & 6 deletions Frameworks/include/CoreTextInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ inline void _SafeRelease(T** p) {
}
}

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

CFAttributedStringRef _CTTypesetterGetAttributedString(CTTypesetterRef typesetter);

@interface _CTRun : NSObject {
Expand Down
2 changes: 1 addition & 1 deletion include/CoreText/CTFramesetter.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ CORETEXT_EXPORT CTFrameRef CTFramesetterCreateFrame(CTFramesetterRef framesetter
CORETEXT_EXPORT CTTypesetterRef CTFramesetterGetTypesetter(CTFramesetterRef framesetter);
CORETEXT_EXPORT CGSize CTFramesetterSuggestFrameSizeWithConstraints(
CTFramesetterRef framesetter, CFRange stringRange, CFDictionaryRef frameAttributes, CGSize constraints, CFRange* fitRange);
CORETEXT_EXPORT CFTypeID CTFramesetterGetTypeID() STUB_METHOD;
CORETEXT_EXPORT CFTypeID CTFramesetterGetTypeID();

0 comments on commit 37ba3a8

Please sign in to comment.