Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of https://github.com/Cocoanetics/DTCoreText

  • Loading branch information...
commit 15c0e00bde134ccde07e17b52f038c312c048696 2 parents 3d90bb6 + bcac407
@BrianDoig BrianDoig authored
View
16 Core/Source/DTAttributedTextContentView.m
@@ -219,7 +219,19 @@ - (void)layoutSubviewsInRect:(CGRect)rect
else
{
// individual glyph run
- frameForSubview = oneRun.frame;
+
+ if (attachment)
+ {
+ // frame might be different due to image vertical alignment
+ CGFloat ascender = [attachment ascentForLayout];
+ CGFloat descender = [attachment descentForLayout];
+
+ frameForSubview = CGRectMake(oneRun.frame.origin.x, oneLine.baselineOrigin.y - ascender, oneRun.frame.size.width, ascender+descender);
+ }
+ else
+ {
+ frameForSubview = oneRun.frame;
+ }
}
if (CGRectIsEmpty(frameForSubview))
@@ -660,7 +672,7 @@ - (DTCoreTextLayoutFrame *)layoutFrame
if (_delegateFlags.delegateSupportsNotificationBeforeTextBoxDrawing)
{
- DTAttributedTextContentView *weakself = self;
+ __unsafe_unretained DTAttributedTextContentView *weakself = self;
[_layoutFrame setTextBlockHandler:^(DTTextBlock *textBlock, CGRect frame, CGContextRef context, BOOL *shouldDrawDefaultBackground) {
BOOL result = [weakself->_delegate attributedTextContentView:weakself shouldDrawBackgroundForTextBlock:textBlock frame:frame context:context forLayoutFrame:weakself->_layoutFrame];
View
8 Core/Source/DTAttributedTextView.h
@@ -23,4 +23,12 @@
@property (nonatomic, unsafe_unretained) IBOutlet id <DTAttributedTextContentViewDelegate> textDelegate;
+
+/**
+ Scrolls the receiver to the anchor with the given name to the top.
+ @param anchorName The name of the href anchor.
+ @param animated `YES` if the movement should be animated.
+ */
+- (void)scrollToAnchorNamed:(NSString *)anchorName animated:(BOOL)animated;
+
@end
View
20 Core/Source/DTAttributedTextView.m
@@ -85,6 +85,25 @@ - (Class)classForContentView
return [DTAttributedTextContentView class];
}
+#pragma mark External Methods
+- (void)scrollToAnchorNamed:(NSString *)anchorName animated:(BOOL)animated
+{
+ NSRange range = [self.contentView.attributedString rangeOfAnchorNamed:anchorName];
+
+ if (range.length != NSNotFound)
+ {
+ // get the line of the first index of the anchor range
+ DTCoreTextLayoutLine *line = [self.contentView.layoutFrame lineContainingIndex:range.location];
+
+ // make sure we don't scroll too far
+ CGFloat maxScrollPos = self.contentSize.height - self.bounds.size.height + self.contentInset.bottom + self.contentInset.top;
+ CGFloat scrollPos = MIN(line.frame.origin.y, maxScrollPos);
+
+ // scroll
+ [self setContentOffset:CGPointMake(0, scrollPos) animated:animated];
+ }
+}
+
#pragma mark Notifications
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
@@ -95,7 +114,6 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
}
}
-
#pragma mark Properties
- (DTAttributedTextContentView *)contentView
{
View
18 Core/Source/DTCSSStylesheet.m
@@ -28,11 +28,21 @@ @implementation DTCSSStylesheet
+ (DTCSSStylesheet *)defaultStyleSheet
{
- // get the data from the external symbol
- NSData *data = [NSData dataWithBytes:default_css length:default_css_len];
- NSString *cssString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+ static DTCSSStylesheet *defaultDTCSSStylesheet = nil;
+ if (defaultDTCSSStylesheet != nil) {
+ return defaultDTCSSStylesheet;
+ }
- return [[DTCSSStylesheet alloc] initWithStyleBlock:cssString];
+ @synchronized(self) {
+ if (defaultDTCSSStylesheet == nil) {
+ // get the data from the external symbol
+ NSData *data = [NSData dataWithBytes:default_css length:default_css_len];
+ NSString *cssString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+
+ defaultDTCSSStylesheet = [[DTCSSStylesheet alloc] initWithStyleBlock:cssString];
+ }
+ }
+ return defaultDTCSSStylesheet;
}
- (id)initWithStyleBlock:(NSString *)css
View
30 Core/Source/DTCompatibility.h
@@ -0,0 +1,30 @@
+//
+// DTCompatibility.h
+// DTCoreText
+//
+// Created by Oliver Letterer on 09.04.12.
+// Copyright (c) 2012 Drobnik.com. All rights reserved.
+//
+
+// DTColor is UIColor on iOS, NSColor on Mac
+#if TARGET_OS_IPHONE
+@compatibility_alias DTColor UIColor;
+#else
+@compatibility_alias DTColor NSColor;
+#endif
+
+// DTImage is UIImage on iOS, NSImage on Mac
+#if TARGET_OS_IPHONE
+@compatibility_alias DTImage UIImage;
+#else
+@compatibility_alias DTImage NSImage;
+#endif
+
+// DTEdgeInsets is UIEdgeInsets on iOS, NSEdgeInsets on Mac
+#if TARGET_OS_IPHONE
+#define DTEdgeInsets UIEdgeInsets
+#define DTEdgeInsetsMake(a, b, c, d) UIEdgeInsetsMake(a, b, c, d)
+#else
+#define DTEdgeInsets NSEdgeInsets
+#define DTEdgeInsetsMake(a, b, c, d) NSEdgeInsetsMake(a, b, c, d)
+#endif
View
25 Core/Source/DTCoreText.h
@@ -4,34 +4,11 @@
// global constants
#import "DTCoreTextConstants.h"
-
-// DTColor is UIColor on iOS, NSColor on Mac
-#if TARGET_OS_IPHONE
-@compatibility_alias DTColor UIColor;
-#else
-@compatibility_alias DTColor NSColor;
-#endif
+#import "DTCompatibility.h"
#import "DTColor+HTML.h"
-
-// DTImage is UIImage on iOS, NSImage on Mac
-#if TARGET_OS_IPHONE
-@compatibility_alias DTImage UIImage;
-#else
-@compatibility_alias DTImage NSImage;
-#endif
-
#import "DTImage+HTML.h"
-// DTEdgeInsets is UIEdgeInsets on iOS, NSEdgeInsets on Mac
-#if TARGET_OS_IPHONE
-#define DTEdgeInsets UIEdgeInsets
-#define DTEdgeInsetsMake(a, b, c, d) UIEdgeInsetsMake(a, b, c, d)
-#else
-#define DTEdgeInsets NSEdgeInsets
-#define DTEdgeInsetsMake(a, b, c, d) NSEdgeInsetsMake(a, b, c, d)
-#endif
-
// common utilities
#import "CGUtils.h"
View
1  Core/Source/DTCoreTextConstants.h
@@ -30,6 +30,7 @@ extern NSString *DTDefaultStyleSheet;
extern NSString *DTTextListsAttribute;
extern NSString *DTAttachmentParagraphSpacingAttribute;
extern NSString *DTLinkAttribute;
+extern NSString *DTAnchorAttribute;
extern NSString *DTGUIDAttribute;
extern NSString *DTHeaderLevelAttribute;
extern NSString *DTPreserveNewlinesAttribute;
View
1  Core/Source/DTCoreTextConstants.m
@@ -27,6 +27,7 @@
NSString *DTTextListsAttribute = @"DTTextLists";
NSString *DTAttachmentParagraphSpacingAttribute = @"DTAttachmentParagraphSpacing";
NSString *DTLinkAttribute = @"DTLink";
+NSString *DTAnchorAttribute = @"DTAnchor";
NSString *DTGUIDAttribute = @"DTGUID";
NSString *DTHeaderLevelAttribute = @"DTHeaderLevel";
NSString *DTPreserveNewlinesAttribute = @"DTPreserveNewlines";
View
9 Core/Source/DTCoreTextFontDescriptor.m
@@ -7,7 +7,10 @@
//
#import "DTCoreTextFontDescriptor.h"
+
+#if TARGET_OS_IPHONE
#import "UIDevice+DTVersion.h"
+#endif
static NSCache *_fontCache = nil;
static NSMutableDictionary *_fontOverrides = nil;
@@ -63,13 +66,15 @@ + (void)initialize
}
}
- // workaround for iOS 5.0 bug: global font cascade table has incorrect bold font for Chinese characters in Chinese locale
+#if TARGET_OS_IPHONE
+ // workaround for iOS 5.x bug: global font cascade table has incorrect bold font for Chinese characters in Chinese locale
DTVersion version = [[UIDevice currentDevice] osVersion];
- if (version.major==5 && version.minor == 0)
+ if (version.major>4)
{
_needsChineseFontCascadeFix = YES;
}
+#endif
}
+ (void)setSmallCapsFontName:(NSString *)fontName forFontFamily:(NSString *)fontFamily bold:(BOOL)bold italic:(BOOL)italic
View
6 Core/Source/DTCoreTextLayoutFrame.m
@@ -975,8 +975,12 @@ - (void)drawInContext:(CGContextRef)context drawImages:(BOOL)drawImages
{
DTImage *image = (id)attachment.contents;
+ // frame might be different due to image vertical alignment
+ CGFloat ascender = [attachment ascentForLayout];
+ CGFloat descender = [attachment descentForLayout];
+
CGPoint origin = oneRun.frame.origin;
- origin.y = self.frame.size.height - origin.y - oneRun.ascent;
+ origin.y = self.frame.size.height - origin.y - ascender - descender;
CGRect flippedRect = CGRectMake(roundf(origin.x), roundf(origin.y), attachment.displaySize.width, attachment.displaySize.height);
CGContextDrawImage(context, flippedRect, image.CGImage);
View
21 Core/Source/DTCoreTextParagraphStyle.m
@@ -42,6 +42,23 @@ + (DTCoreTextParagraphStyle *)defaultParagraphStyle
return [[DTCoreTextParagraphStyle alloc] init];
}
++ (NSString *)niceKeyFromParagraghStyle:(CTParagraphStyleRef)ctParagraphStyle {
+
+ // this is naughty: CTParagraphStyle has a description
+ NSString *key = [(__bridge id)ctParagraphStyle description];
+
+ NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"0x[0123456789abcdef]{1,8}"
+ options:NSRegularExpressionCaseInsensitive
+ error:nil];
+
+ NSString *newKey = [regex stringByReplacingMatchesInString:key
+ options:0
+ range:NSMakeRange(0, [key length])
+ withTemplate:@""];
+
+ return newKey;
+}
+
+ (DTCoreTextParagraphStyle *)paragraphStyleWithCTParagraphStyle:(CTParagraphStyleRef)ctParagraphStyle
{
DTCoreTextParagraphStyle *returnParagraphStyle = NULL;
@@ -58,9 +75,7 @@ + (DTCoreTextParagraphStyle *)paragraphStyleWithCTParagraphStyle:(CTParagraphSty
dispatch_semaphore_wait(selfLock, DISPATCH_TIME_FOREVER);
{
- // this is naughty: CTParagraphStyle has a description
- NSString *key = [(__bridge id)ctParagraphStyle description];
-
+ NSString *key = [self niceKeyFromParagraghStyle:ctParagraphStyle];
returnParagraphStyle = [_paragraphStyleCache objectForKey:key];
if (!returnParagraphStyle)
View
7 Core/Source/DTHTMLAttributedStringBuilder.m
@@ -419,6 +419,10 @@ - (void)_registerTagStartHandlers
}
currentTag.link = link;
+
+
+ // the name attribute of A becomes an anchor
+ currentTag.anchorName = [currentTag attributeForKey:@"name"];
};
[_tagStartHandlers setObject:[aBlock copy] forKey:@"a"];
@@ -738,6 +742,9 @@ - (void)_registerTagEndHandlers
// because we have multiple paragraph styles per paragraph still, we need to extend towards the begin of the paragraph
NSRange paragraphRange = [[tmpString string] rangeOfParagraphAtIndex:effectiveRange.location];
+ // iOS 4.3 bug: need to remove previous attribute or else CTParagraphStyleRef leaks
+ [tmpString removeAttribute:(id)kCTParagraphStyleAttributeName range:paragraphRange];
+
[tmpString addAttribute:(id)kCTParagraphStyleAttributeName value:CFBridgingRelease(newParagraphStyle) range:paragraphRange];
}
}
View
1  Core/Source/DTHTMLElement.h
@@ -41,6 +41,7 @@ typedef enum
@property (nonatomic, copy) DTCoreTextParagraphStyle *paragraphStyle;
@property (nonatomic, strong) DTTextAttachment *textAttachment;
@property (nonatomic, copy) NSURL *link;
+@property (nonatomic, copy) NSString *anchorName;
@property (nonatomic, strong) DTColor *textColor;
@property (nonatomic, strong) DTColor *backgroundColor;
@property (nonatomic, copy) NSString *tagName;
View
9 Core/Source/DTHTMLElement.m
@@ -29,6 +29,7 @@ @implementation DTHTMLElement
DTTextAttachment *_textAttachment;
DTTextAttachmentVerticalAlignment _textAttachmentAlignment;
NSURL *_link;
+ NSString *_anchorName;
DTColor *_textColor;
DTColor *backgroundColor;
@@ -149,6 +150,12 @@ - (NSDictionary *)attributesDictionary
[tmpDict setObject:_linkGUID forKey:DTGUIDAttribute];
}
+ // add anchor
+ if (_anchorName)
+ {
+ [tmpDict setObject:_anchorName forKey:DTAnchorAttribute];
+ }
+
// add strikout if applicable
if (strikeOut)
{
@@ -899,6 +906,7 @@ - (id)copyWithZone:(NSZone *)zone
newObject.shadows = self.shadows;
newObject.link = self.link; // copy
+ newObject.anchorName = self.anchorName; // copy
newObject.linkGUID = _linkGUID; // transfer the GUID
newObject.preserveNewlines = self.preserveNewlines;
@@ -1010,6 +1018,7 @@ - (void)setLink:(NSURL *)link
@synthesize tagName;
@synthesize text;
@synthesize link = _link;
+@synthesize anchorName = _anchorName;
@synthesize underlineStyle;
@synthesize textAttachment = _textAttachment;
@synthesize tagContentInvisible;
View
2  Core/Source/DTTextBlock.h
@@ -6,7 +6,7 @@
// Copyright (c) 2012 Drobnik.com. All rights reserved.
//
-#import "DTCoreText.h"
+#import "DTCompatibility.h"
/**
Class that represents a block of text with attributes like padding or a background color.
View
1  Core/Source/DTTextBlock.m
@@ -7,6 +7,7 @@
//
#import "DTTextBlock.h"
+#import "DTCoreText.h"
@implementation DTTextBlock
{
View
10 Core/Source/NSAttributedString+DTCoreText.h
@@ -65,9 +65,17 @@
- (NSRange)rangeOfTextBlock:(DTTextBlock *)textBlock atIndex:(NSUInteger)location;
/**
- @name Converting to Other Representations
+ Returns the range of the given href anchor.
+
+ @param list The text block.
+ @param anchorName The name of the anchor.
+ @returns The range of the given anchor.
*/
+- (NSRange)rangeOfAnchorNamed:(NSString *)anchorName;
+/**
+ @name Converting to Other Representations
+ */
/**
Encodes the receiver into a generic HTML prepresentation.
View
33 Core/Source/NSAttributedString+DTCoreText.m
@@ -197,6 +197,21 @@ - (NSRange)rangeOfTextBlock:(DTTextBlock *)textBlock atIndex:(NSUInteger)locatio
return [self _rangeOfObject:textBlock inArrayBehindAttribute:DTTextBlocksAttribute atIndex:location];
}
+- (NSRange)rangeOfAnchorNamed:(NSString *)anchorName
+{
+ __block NSRange foundRange = NSMakeRange(0, NSNotFound);
+
+ [self enumerateAttribute:DTAnchorAttribute inRange:NSMakeRange(0, [self length]) options:0 usingBlock:^(NSString *value, NSRange range, BOOL *stop) {
+ if ([value isEqualToString:anchorName])
+ {
+ *stop = YES;
+ foundRange = range;
+ }
+ }];
+
+ return foundRange;
+}
+
#pragma mark HTML Encoding
@@ -339,19 +354,23 @@ - (NSString *)htmlString
NSInteger location = 0;
NSArray *previousListStyles = nil;
-
- for (NSString *oneParagraph in paragraphs)
+
+ for (int i=0; i<[paragraphs count]; i++)
{
+ NSString *oneParagraph = [paragraphs objectAtIndex:i];
NSRange paragraphRange = NSMakeRange(location, [oneParagraph length]);
- BOOL needsToRemovePrefix = NO;
-
- // skip empty paragraph at end
- if (oneParagraph == [paragraphs lastObject] && !paragraphRange.length)
+ // skip empty paragraph at the end
+ if (i==[paragraphs count]-1)
{
- continue;
+ if (!paragraphRange.length)
+ {
+ continue;
+ }
}
+ BOOL needsToRemovePrefix = NO;
+
BOOL fontIsBlockLevel = NO;
// check if font is same in all paragraph
View
3  Core/Test/Source/UIColorHTMLTest.m
@@ -6,8 +6,9 @@
// Copyright 2011 Drobnik.com. All rights reserved.
//
+#import "DTCoreText.h"
#import "UIColorHTMLTest.h"
-#import "DTColor+HTML.h"
+#import "DTCoreText.h"
@implementation UIColorHTMLTest
View
4 DTCoreText.podspec
@@ -1,9 +1,9 @@
Pod::Spec.new do |spec|
spec.name = 'DTCoreText'
- spec.version = '1.0.0'
+ spec.version = '1.0.1'
spec.platform = :ios
spec.license = 'BSD'
- spec.source = { :git => 'https://github.com/Cocoanetics/DTCoreText.git', :tag => '1.0.0' }
+ spec.source = { :git => 'https://github.com/Cocoanetics/DTCoreText.git', :tag => '1.0.1' }
spec.source_files = 'Core/Source/*.{h,m,c}'
spec.clean_paths = 'Core/Test/', 'Core/DTCoreText-Info.plist', 'Core/DTCoreText-Prefix.pch', 'DTCoreText.xcodeproj/', 'Demo/', '.gitignore'
spec.frameworks = 'MediaPlayer', 'QuartzCore', 'CoreText', 'CoreGraphics', 'ImageIO'
View
32 DTCoreText.xcodeproj/project.pbxproj
@@ -252,6 +252,8 @@
A7949AA314CC5BDF00A8CCDE /* DTHTMLAttributedStringBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = A7949A4614CAF58C00A8CCDE /* DTHTMLAttributedStringBuilder.m */; };
A7949AA514CD3C5D00A8CCDE /* DTHTMLParser.m in Sources */ = {isa = PBXBuildFile; fileRef = A7949A4914CAF5A300A8CCDE /* DTHTMLParser.m */; };
A7949AA614CD3C5E00A8CCDE /* DTHTMLParser.m in Sources */ = {isa = PBXBuildFile; fileRef = A7949A4914CAF5A300A8CCDE /* DTHTMLParser.m */; };
+ A7A672BA1532F2D100920A18 /* DTCompatibility.h in Headers */ = {isa = PBXBuildFile; fileRef = A7A672B91532F2D100920A18 /* DTCompatibility.h */; };
+ A7A672BB1532F2D100920A18 /* DTCompatibility.h in Headers */ = {isa = PBXBuildFile; fileRef = A7A672B91532F2D100920A18 /* DTCompatibility.h */; };
A7A95D9514F3F45E002E3F7E /* LineHeight.html in Resources */ = {isa = PBXBuildFile; fileRef = A7A95D9414F3F45E002E3F7E /* LineHeight.html */; };
A7A95D9714F3F496002E3F7E /* LineHeight.html in Resources */ = {isa = PBXBuildFile; fileRef = A7A95D9414F3F45E002E3F7E /* LineHeight.html */; };
A7B0B56814D9921F0091C2C9 /* NSAttributedString+DTCoreText.h in Headers */ = {isa = PBXBuildFile; fileRef = A7B0B56614D9921F0091C2C9 /* NSAttributedString+DTCoreText.h */; };
@@ -509,6 +511,7 @@
A7949A6D14CC45B400A8CCDE /* MacUnitTest-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "MacUnitTest-Info.plist"; sourceTree = "<group>"; };
A7949A6E14CC45B500A8CCDE /* MacUnitTest-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MacUnitTest-Prefix.pch"; sourceTree = "<group>"; };
A7949A9C14CC565F00A8CCDE /* DTCoreTextConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = DTCoreTextConstants.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
+ A7A672B91532F2D100920A18 /* DTCompatibility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DTCompatibility.h; path = Core/Source/DTCompatibility.h; sourceTree = "<group>"; };
A7A95D9414F3F45E002E3F7E /* LineHeight.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = LineHeight.html; sourceTree = "<group>"; };
A7B0B56614D9921F0091C2C9 /* NSAttributedString+DTCoreText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSAttributedString+DTCoreText.h"; sourceTree = "<group>"; };
A7B0B56714D9921F0091C2C9 /* NSAttributedString+DTCoreText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSAttributedString+DTCoreText.m"; sourceTree = "<group>"; };
@@ -715,6 +718,7 @@
isa = PBXGroup;
children = (
A70B4C9E1486558200873A4A /* DTCoreText.h */,
+ A7A672B91532F2D100920A18 /* DTCompatibility.h */,
A788CA1514863EC600E1AFD9 /* DTCoreText-Prefix.pch */,
A788CA1614863EC600E1AFD9 /* DTCoreText-Info.plist */,
A788C90D14863E8700E1AFD9 /* Source */,
@@ -965,6 +969,7 @@
A7B0B56814D9921F0091C2C9 /* NSAttributedString+DTCoreText.h in Headers */,
A760F54114F56E9000AD1B0E /* DTImage+HTML.h in Headers */,
A7081EA315036460002987F1 /* DTTextBlock.h in Headers */,
+ A7A672BA1532F2D100920A18 /* DTCompatibility.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1010,6 +1015,7 @@
A70B4CA01486558200873A4A /* DTCoreText.h in Headers */,
A760F54014F56E8E00AD1B0E /* DTImage+HTML.h in Headers */,
A7081EA415036460002987F1 /* DTTextBlock.h in Headers */,
+ A7A672BB1532F2D100920A18 /* DTCompatibility.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1117,7 +1123,7 @@
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0420;
+ LastUpgradeCheck = 0430;
ORGANIZATIONNAME = Drobnik.com;
};
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "DTCoreText" */;
@@ -1499,6 +1505,7 @@
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Demo/DemoApp-Prefix.pch";
+ GCC_THUMB_SUPPORT = NO;
INFOPLIST_FILE = "Demo/DemoApp-Info.plist";
OTHER_LDFLAGS = (
"-all_load",
@@ -1516,6 +1523,7 @@
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Demo/DemoApp-Prefix.pch";
+ GCC_THUMB_SUPPORT = NO;
INFOPLIST_FILE = "Demo/DemoApp-Info.plist";
OTHER_LDFLAGS = (
"-all_load",
@@ -1548,6 +1556,7 @@
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_THUMB_SUPPORT = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "Core/DTCoreText-Info.plist";
INFOPLIST_PATH = "$(UNLOCALIZED_RESOURCES_FOLDER_PATH)/Info.plist";
@@ -1575,6 +1584,7 @@
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Core/DTCoreText-Prefix.pch";
+ GCC_THUMB_SUPPORT = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "Core/DTCoreText-Info.plist";
INFOPLIST_PATH = "$(UNLOCALIZED_RESOURCES_FOLDER_PATH)/Info.plist";
@@ -1593,6 +1603,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = (
+ "$(ARCHS_STANDARD_32_BIT)",
+ armv6,
+ );
COPY_PHASE_STRIP = NO;
DSTROOT = /tmp/DTCoreText.dst;
GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -1605,6 +1619,7 @@
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_THUMB_SUPPORT = NO;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = DTCoreText;
PUBLIC_HEADERS_FOLDER_PATH = ../../DTCoreText;
@@ -1616,11 +1631,16 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = (
+ "$(ARCHS_STANDARD_32_BIT)",
+ armv6,
+ );
COPY_PHASE_STRIP = YES;
DSTROOT = /tmp/DTCoreText.dst;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Core/DTCoreText-Prefix.pch";
+ GCC_THUMB_SUPPORT = NO;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = DTCoreText;
PUBLIC_HEADERS_FOLDER_PATH = ../../DTCoreText;
@@ -1632,6 +1652,7 @@
A7174BC614F288F900C57464 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ GCC_THUMB_SUPPORT = NO;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
@@ -1639,6 +1660,7 @@
A7174BC714F288F900C57464 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ GCC_THUMB_SUPPORT = NO;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
@@ -1662,6 +1684,7 @@
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_THUMB_SUPPORT = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "Core/Test/UnitTest-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1682,6 +1705,7 @@
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Core/Test/UnitTest-Prefix.pch";
+ GCC_THUMB_SUPPORT = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "Core/Test/UnitTest-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1752,11 +1776,12 @@
CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
+ GCC_THUMB_SUPPORT = NO;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = /usr/include/libxml2;
- IPHONEOS_DEPLOYMENT_TARGET = 4.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 5.0;
SDKROOT = iphoneos;
};
name = Debug;
@@ -1771,11 +1796,12 @@
CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
+ GCC_THUMB_SUPPORT = NO;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = /usr/include/libxml2;
- IPHONEOS_DEPLOYMENT_TARGET = 4.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 5.0;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
SDKROOT = iphoneos;
};
View
31 Demo/Resources/CurrentTest.html
@@ -1,2 +1,29 @@
-<p style="font-size:30px">some text 中文</p>
-<p style="font-size:30px"><b>some text 中文</b></p>
+<a href="#kapitel2">Go To Chapter2</a>
+<a name="kapitel1" href="#kapitel1">Kapitel 1</a>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<a name="kapitel2">Chapter2</a>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
+<p>text</p>
View
21 Demo/Source/DemoTextViewController.m
@@ -396,7 +396,26 @@ - (BOOL)attributedTextContentView:(DTAttributedTextContentView *)attributedTextC
- (void)linkPushed:(DTLinkButton *)button
{
- [[UIApplication sharedApplication] openURL:[button.URL absoluteURL]];
+ NSURL *URL = button.URL;
+
+ if ([[UIApplication sharedApplication] canOpenURL:[URL absoluteURL]])
+ {
+ [[UIApplication sharedApplication] openURL:[URL absoluteURL]];
+ }
+ else
+ {
+ if (![URL host] && ![URL path])
+ {
+
+ // possibly a local anchor link
+ NSString *fragment = [URL fragment];
+
+ if (fragment)
+ {
+ [_textView scrollToAnchorNamed:fragment animated:NO];
+ }
+ }
+ }
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
View
13 Readme.markdown
@@ -52,16 +52,18 @@ The best way to use DTCoreText with Xcode 4.2 is to add it in Xcode as a subproj
#import "DTCoreText.h"
-4. In your application target's Build Phases add all of the below to the Link Binary With Libraries phase (you can also do this from the Target's Summary view in the Linked Frameworks and Libraries):
+4. In your application target's Build Phases add the "Static Library" from the DTCoreText sub-project as a dependency.
+
+5. In your application target's Build Phases add all of the below to the Link Binary With Libraries phase (you can also do this from the Target's Summary view in the Linked Frameworks and Libraries):
The "Static Library" target from the DTCoreText sub-project
ImageIO.framework
QuartzCore.framework
libxml2.dylib
-5. Go to File: Project Settings… and change the derived data location to project-relative.
-6. Add the DerivedData folder to your git ignore.
-7. In your application's target Build Settings:
+6. Go to File: Project Settings… and change the derived data location to project-relative.
+7. Add the DerivedData folder to your git ignore.
+8. In your application's target Build Settings:
- Set the "User Header Search Paths" to the directory containing your project with recrusive set to YES.
- Set the Header Search Paths to /usr/include/libxml2.
- Set "Always Search User Paths" to YES.
@@ -71,7 +73,8 @@ If you do not want to deal with Git submodules simply add DTCoreText to your pro
LINKER SETTINGS:
- - add the -ObjC and -all_load to your app target's "Other Linker Flags". This is needed whenever you link in any static library that contains Objective-C classes and categories.
+ - add the -ObjC to your app target's "Other Linker Flags". This is needed whenever you link in any static library that contains Objective-C classes and categories.
+ - if you find that your app crashes with an unrecognized selector from one of this library's categories, you might also need the -all_load linker flag. Alternatively you can use -force-load with the full path to the static library. This causes the linker to load all categories from the static library.
- If your app does not use ARC yet (but DTCoreText does) then you also need the -fobjc-arc linker flag.
*Other Options (only mentioned for completeness)*
Please sign in to comment.
Something went wrong with that request. Please try again.