-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
NSAttributedStringRunDelegates.m
53 lines (47 loc) · 1.33 KB
/
NSAttributedStringRunDelegates.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// NSAttributedStringRunDelegates.m
// CoreTextExtensions
//
// Created by Oliver on 14.01.11.
// Copyright 2011 Drobnik.com. All rights reserved.
//
#import "NSAttributedStringRunDelegates.h"
#import "DTTextAttachment.h"
void embeddedObjectDeallocCallback(void *context)
{
}
CGFloat embeddedObjectGetAscentCallback(void *context)
{
if ([(__bridge id)context isKindOfClass:[DTTextAttachment class]])
{
return [(__bridge DTTextAttachment *)context ascentForLayout];
}
return 0;
}
CGFloat embeddedObjectGetDescentCallback(void *context)
{
if ([(__bridge id)context isKindOfClass:[DTTextAttachment class]])
{
return [(__bridge DTTextAttachment *)context descentForLayout];
}
return 0;
}
CGFloat embeddedObjectGetWidthCallback(void * context)
{
if ([(__bridge id)context isKindOfClass:[DTTextAttachment class]])
{
return [(__bridge DTTextAttachment *)context displaySize].width;
}
return 35;
}
CTRunDelegateRef createEmbeddedObjectRunDelegate(id obj)
{
CTRunDelegateCallbacks callbacks;
callbacks.version = kCTRunDelegateCurrentVersion;
callbacks.dealloc = embeddedObjectDeallocCallback;
callbacks.getAscent = embeddedObjectGetAscentCallback;
callbacks.getDescent = embeddedObjectGetDescentCallback;
callbacks.getWidth = embeddedObjectGetWidthCallback;
return CTRunDelegateCreate(&callbacks, (__bridge void *)obj);
return NULL;
}