Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove attributed text from CDKTask

There is a growing amount of OS specific things here. Moving to categories in the respective apps.
  • Loading branch information...
commit e6a61fbbc0a6cc0657a521c5b5a26e7e266d4d80 1 parent 43dff2c
@soffes soffes authored
Showing with 0 additions and 106 deletions.
  1. +0 −3  CheddarKit/CDKTask.h
  2. +0 −103 CheddarKit/CDKTask.m
View
3  CheddarKit/CDKTask.h
@@ -30,9 +30,6 @@
- (void)toggleCompleted;
- (BOOL)hasTag:(CDKTag *)tag;
-- (NSAttributedString *)attributedDisplayText;
-- (void)addEntitiesToAttributedString:(NSMutableAttributedString *)attributedString;
-
@end
View
103 CheddarKit/CDKTask.m
@@ -11,14 +11,8 @@
#import "CDKList.h"
#import "CDKTag.h"
#import "CDKHTTPClient.h"
-#import "CDKDefines.h"
#import "NSString+CheddarKit.h"
-#if TARGET_OS_IPHONE
-#import <CoreText/CoreText.h>
-//#import "TTTAttributedLabel.h"
-#endif
-
@implementation CDKTask
@dynamic archivedAt;
@@ -146,101 +140,4 @@ - (BOOL)hasTag:(CDKTag *)tag {
return [self.tags containsObject:tag];
}
-
-- (NSAttributedString *)attributedDisplayText {
- if (!self.displayText) {
- if (!self.text) {
- return nil;
- }
- return [[NSAttributedString alloc] initWithString:self.text];
- }
-
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.displayText];
- CTFontRef regularFont = CTFontCreateWithName((__bridge CFStringRef)kCDKRegularFontName, 20.0f, NULL);
- if (regularFont) {
- [attributedString addAttribute:(__bridge NSString *)kCTFontAttributeName value:(__bridge id)regularFont range:NSMakeRange(0, self.displayText.length)];
- }
- [self addEntitiesToAttributedString:attributedString];
- return attributedString;
-}
-
-
-- (void)addEntitiesToAttributedString:(NSMutableAttributedString *)attributedString {
- // TODO: Cache fonts
- CTFontRef italicFont = NULL;
- CTFontRef boldFont = NULL;
- CTFontRef boldItalicFont = NULL;
- CTFontRef codeFont = NULL;
-
- // Add entities
- for (NSDictionary *entity in self.entities) {
- NSArray *indices = [entity objectForKey:@"display_indices"];
- NSRange range = NSMakeRange([[indices objectAtIndex:0] unsignedIntegerValue], 0);
- range.length = [[indices objectAtIndex:1] unsignedIntegerValue] - range.location;
- range = [attributedString.string composedRangeWithRange:range];
-
- // Skip malformed entities
- if (range.length > self.displayText.length) {
- continue;
- }
-
- NSString *type = [entity objectForKey:@"type"];
-
- // Italic
- if ([type isEqualToString:@"emphasis"]) {
- if (!italicFont) {
- italicFont = CTFontCreateWithName((__bridge CFStringRef)kCDKItalicFontName, 20.0f, NULL);
- }
- [attributedString addAttribute:(__bridge NSString *)kCTFontAttributeName value:(__bridge id)italicFont range:range];
- }
-
- // Bold
- else if ([type isEqualToString:@"double_emphasis"]) {
- if (!boldFont) {
- boldFont = CTFontCreateWithName((__bridge CFStringRef)kCDKBoldFontName, 20.0f, NULL);
- }
- [attributedString addAttribute:(__bridge NSString *)kCTFontAttributeName value:(__bridge id)boldFont range:range];
- }
-
- // Bold Italic
- else if ([type isEqualToString:@"triple_emphasis"]) {
- if (!boldItalicFont) {
- boldItalicFont = CTFontCreateWithName((__bridge CFStringRef)kCDKBoldItalicFontName, 20.0f, NULL);
- }
- [attributedString addAttribute:(__bridge NSString *)kCTFontAttributeName value:(__bridge id)boldItalicFont range:range];
- }
-
-#if TARGET_OS_IPHONE
- // Strikethrough
-// else if ([type isEqualToString:@"strikethrough"]) {
-// [attributedString addAttribute:kTTTStrikeOutAttributeName value:[NSNumber numberWithBool:YES] range:range];
-// }
-#endif
-
- // Code
- else if ([type isEqualToString:@"code"]) {
- if (!codeFont) {
- codeFont = CTFontCreateWithName((__bridge CFStringRef)@"Courier", 20.0f, NULL);
- }
- [attributedString addAttribute:(__bridge NSString *)kCTFontAttributeName value:(__bridge id)codeFont range:range];
- }
- }
-
- if (italicFont) {
- CFRelease(italicFont);
- }
-
- if (boldFont) {
- CFRelease(boldFont);
- }
-
- if (boldItalicFont) {
- CFRelease(boldItalicFont);
- }
-
- if (codeFont) {
- CFRelease(codeFont);
- }
-}
-
@end
Please sign in to comment.
Something went wrong with that request. Please try again.