From a886e050c02f20de505543d0b11adad68c01a391 Mon Sep 17 00:00:00 2001 From: Guido Sabatini Date: Thu, 21 Jul 2016 10:13:36 +0200 Subject: [PATCH 1/5] fixed issue of WPHotspotLabel not calculating correct number of attributed string lines --- Extras/WPHotspotLabel.m | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Extras/WPHotspotLabel.m b/Extras/WPHotspotLabel.m index 258ab29..e4a42c5 100644 --- a/Extras/WPHotspotLabel.m +++ b/Extras/WPHotspotLabel.m @@ -51,19 +51,22 @@ -(NSDictionary*)textAttributesAtPoint:(CGPoint)pt { // Locate the attributes of the text within the label at the specified point NSDictionary* dictionary = nil; + CFRange currentRange = CFRangeMake(0, 0); // First, create a CoreText framesetter CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)self.attributedText); + // get the real height needed by the attributed string assuming the width of the label is fixed + CGSize size = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, currentRange, NULL, CGSizeMake(self.frame.size.width, CGFLOAT_MAX), NULL); CGMutablePathRef framePath = CGPathCreateMutable(); - CGPathAddRect(framePath, NULL, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)); + + CGPathAddRect(framePath, NULL, CGRectMake(0, 0, size.width, size.height)); // Get the frame that will do the rendering. - CFRange currentRange = CFRangeMake(0, 0); CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL); CGPathRelease(framePath); - + // Get each of the typeset lines - NSArray *lines = (__bridge id)CTFrameGetLines(frameRef); + NSArray* lines = (__bridge id)CTFrameGetLines(frameRef); CFIndex linesCount = [lines count]; CGPoint *lineOrigins = (CGPoint *) malloc(sizeof(CGPoint) * linesCount); From 0e656d15c9fedd07bec879474c2b82e80aedc6e1 Mon Sep 17 00:00:00 2001 From: Guido Sabatini Date: Thu, 21 Jul 2016 10:21:53 +0200 Subject: [PATCH 2/5] pod version --- WPAttributedMarkup.podspec | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/WPAttributedMarkup.podspec b/WPAttributedMarkup.podspec index 8f3ac94..0fc8eac 100644 --- a/WPAttributedMarkup.podspec +++ b/WPAttributedMarkup.podspec @@ -9,14 +9,12 @@ Pod::Spec.new do |s| s.name = "WPAttributedMarkup" - s.version = "1.0.0" + s.version = "1.0.0_sysdata" s.summary = "WPAttributedMarkup creates an attributed string from text with markup tags and a style dictionary." s.homepage = "https://github.com/nigelgrange/WPAttributedMarkup" - # s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2" s.license = 'MIT' s.author = { "Nigel Grange" => "nigel_grange@hotmail.com" } - s.source = { :git => "https://github.com/nigelgrange/WPAttributedMarkup.git", :tag => s.version.to_s } - # s.social_media_url = 'https://twitter.com/' + s.source = { :git => "https://github.com/sysdatadigital/WPAttributedMarkup.git", :tag => s.version.to_s } s.platform = :ios, '7.0' s.requires_arc = true From ce6fecaedf895bd59cc19e87d0cb474ff5d99ea6 Mon Sep 17 00:00:00 2001 From: Guido Sabatini Date: Thu, 21 Jul 2016 10:41:04 +0200 Subject: [PATCH 3/5] pod version --- WPAttributedMarkup.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WPAttributedMarkup.podspec b/WPAttributedMarkup.podspec index 0fc8eac..b8cf8be 100644 --- a/WPAttributedMarkup.podspec +++ b/WPAttributedMarkup.podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |s| s.name = "WPAttributedMarkup" - s.version = "1.0.0_sysdata" + s.version = "1.0.1" s.summary = "WPAttributedMarkup creates an attributed string from text with markup tags and a style dictionary." s.homepage = "https://github.com/nigelgrange/WPAttributedMarkup" s.license = 'MIT' From a193093e1c54ea2de4706d68552d70314bc867fc Mon Sep 17 00:00:00 2001 From: Guido Sabatini Date: Mon, 1 Aug 2016 18:14:08 +0200 Subject: [PATCH 4/5] fixed issue that causes wrong backward line origin calculation; now the array of lineOrigins is only reversed and not recalculated --- Extras/WPHotspotLabel.m | 61 +++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/Extras/WPHotspotLabel.m b/Extras/WPHotspotLabel.m index e4a42c5..977b896 100644 --- a/Extras/WPHotspotLabel.m +++ b/Extras/WPHotspotLabel.m @@ -14,40 +14,43 @@ @implementation WPHotspotLabel -- (instancetype)initWithCoder:(NSCoder *)coder +- (instancetype) initWithCoder:(NSCoder*)coder { self = [super initWithCoder:coder]; - if (self) { + if (self) + { [self addHotspotHandler]; } return self; } -- (instancetype)initWithFrame:(CGRect)frame +- (instancetype) initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; - if (self) { + if (self) + { [self addHotspotHandler]; } return self; } --(void)addHotspotHandler +- (void) addHotspotHandler { __weak WPHotspotLabel* weakSelf = self; + [self setOnTap:^(CGPoint pt) { // Locate the text attributes at the touched position NSDictionary* attributes = [weakSelf textAttributesAtPoint:pt]; // If the touched attributes contains our custom action style, execute the action block WPAttributedStyleAction* actionStyle = attributes[@"WPAttributedStyleAction"]; - if (actionStyle) { + if (actionStyle) + { actionStyle.action(); } }]; } - --(NSDictionary*)textAttributesAtPoint:(CGPoint)pt +- (NSDictionary*) textAttributesAtPoint:(CGPoint)pt { // Locate the attributes of the text within the label at the specified point NSDictionary* dictionary = nil; @@ -55,7 +58,7 @@ -(NSDictionary*)textAttributesAtPoint:(CGPoint)pt // First, create a CoreText framesetter CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)self.attributedText); - // get the real height needed by the attributed string assuming the width of the label is fixed + // get the real height needed by the attributed string assuming the width of the label is fixed CGSize size = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, currentRange, NULL, CGSizeMake(self.frame.size.width, CGFLOAT_MAX), NULL); CGMutablePathRef framePath = CGPathCreateMutable(); @@ -63,13 +66,15 @@ -(NSDictionary*)textAttributesAtPoint:(CGPoint)pt CGPathAddRect(framePath, NULL, CGRectMake(0, 0, size.width, size.height)); // Get the frame that will do the rendering. CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL); + CGRect boh = CGPathGetPathBoundingBox(framePath); CGPathRelease(framePath); // Get each of the typeset lines NSArray* lines = (__bridge id)CTFrameGetLines(frameRef); CFIndex linesCount = [lines count]; - CGPoint *lineOrigins = (CGPoint *) malloc(sizeof(CGPoint) * linesCount); + + CGPoint* lineOrigins = (CGPoint*)malloc(sizeof(CGPoint) * linesCount); CTFrameGetLineOrigins(frameRef, CFRangeMake(0, linesCount), lineOrigins); CTLineRef line = NULL; @@ -78,28 +83,35 @@ -(NSDictionary*)textAttributesAtPoint:(CGPoint)pt // Correct each of the typeset lines (which have origin (0,0)) to the correct orientation (typesetting offsets from the bottom of the frame) CGFloat bottom = self.frame.size.height; - for(CFIndex i = 0; i < linesCount; ++i) { - lineOrigins[i].y = self.frame.size.height - lineOrigins[i].y; - bottom = lineOrigins[i].y; + CGPoint* lineOriginsReversed = (CGPoint*)malloc(sizeof(CGPoint) * linesCount); + for (CFIndex i = 0; i < linesCount; ++i) + { + lineOriginsReversed[linesCount - i -1] = lineOrigins[i]; } + free(lineOrigins); + lineOrigins = lineOriginsReversed; // Offset the touch point by the amount of space between the top of the label frame and the text - pt.y -= (self.frame.size.height - bottom)/2; + pt.y -= (self.frame.size.height - bottom) / 2; // Scan through each line to find the line containing the touch point y position - for(CFIndex i = 0; i < linesCount; ++i) { + for (CFIndex i = 0; i < linesCount; ++i) + { line = (__bridge CTLineRef)[lines objectAtIndex:i]; lineOrigin = lineOrigins[i]; CGFloat descent, ascent; CGFloat width = CTLineGetTypographicBounds(line, &ascent, &descent, nil); - if(pt.y < (floor(lineOrigin.y) + floor(descent))) { - + if (pt.y < (floor(lineOrigin.y) + floor(descent))) + { // Cater for text alignment set in the label itself (not in the attributed string) - if (self.textAlignment == NSTextAlignmentCenter) { - pt.x -= (self.frame.size.width - width)/2; - } else if (self.textAlignment == NSTextAlignmentRight) { + if (self.textAlignment == NSTextAlignmentCenter) + { + pt.x -= (self.frame.size.width - width) / 2; + } + else if (self.textAlignment == NSTextAlignmentRight) + { pt.x -= (self.frame.size.width - width); } @@ -113,15 +125,18 @@ -(NSDictionary*)textAttributesAtPoint:(CGPoint)pt // Iterate through each of the glyph runs to find the run containing the character index NSArray* glyphRuns = (__bridge id)CTLineGetGlyphRuns(line); CFIndex runCount = [glyphRuns count]; - for (CFIndex run=0; run= range.location && i<= range.location+range.length) { + if (i >= range.location && i <= range.location + range.length) + { dictionary = (__bridge NSDictionary*)CTRunGetAttributes(glyphRun); break; } } - if (dictionary) { + if (dictionary) + { break; } } From 390b9e7634552dec23449545cc8d151afebdbdd4 Mon Sep 17 00:00:00 2001 From: Guido Sabatini Date: Mon, 1 Aug 2016 18:15:41 +0200 Subject: [PATCH 5/5] pod version --- WPAttributedMarkup.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WPAttributedMarkup.podspec b/WPAttributedMarkup.podspec index b8cf8be..6d2941e 100644 --- a/WPAttributedMarkup.podspec +++ b/WPAttributedMarkup.podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |s| s.name = "WPAttributedMarkup" - s.version = "1.0.1" + s.version = "1.0.2" s.summary = "WPAttributedMarkup creates an attributed string from text with markup tags and a style dictionary." s.homepage = "https://github.com/nigelgrange/WPAttributedMarkup" s.license = 'MIT'