Permalink
Browse files

Released Version

  • Loading branch information...
1 parent ce688aa commit c447c88c6ab9e51d5c144a798f7e1e3d57b1fe10 @MinrvaProject MinrvaProject committed Oct 24, 2012
Showing 2,263 changed files with 226,860 additions and 1,780 deletions.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
@@ -0,0 +1,4 @@
+
+The changelog for OHAttributedLabel is maintained as a wiki page on the GitHub repository accessible here:
+
+http://github.com/AliSoftware/OHAttributedLabel/wiki/Revisions-History
@@ -0,0 +1,25 @@
+/***********************************************************************************
+ * This software is under the MIT License quoted below:
+ ***********************************************************************************
+ *
+ * Copyright (c) 2010 Olivier Halligon
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ ***********************************************************************************/
Oops, something went wrong.
@@ -0,0 +1,40 @@
+//
+// CoreTextUtils.h
+// OHAttributedLabel
+//
+// Created by Olivier Halligon on 23/09/12.
+// Copyright (c) 2012 AliSoftware. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+#import <CoreText/CoreText.h>
+
+/////////////////////////////////////////////////////////////////////////////////////
+#pragma mark - Text Alignment Convertion
+/////////////////////////////////////////////////////////////////////////////////////
+
+CTTextAlignment CTTextAlignmentFromUITextAlignment(UITextAlignment alignment);
+CTLineBreakMode CTLineBreakModeFromUILineBreakMode(UILineBreakMode lineBreakMode);
+
+/////////////////////////////////////////////////////////////////////////////////////
+#pragma mark - Flipping Coordinates
+/////////////////////////////////////////////////////////////////////////////////////
+
+CGPoint CGPointFlipped(CGPoint point, CGRect bounds);
+CGRect CGRectFlipped(CGRect rect, CGRect bounds);
+
+/////////////////////////////////////////////////////////////////////////////////////
+#pragma mark - NSRange / CFRange
+/////////////////////////////////////////////////////////////////////////////////////
+
+NSRange NSRangeFromCFRange(CFRange range);
+
+/////////////////////////////////////////////////////////////////////////////////////
+#pragma mark - CoreText CTLine/CTRun utils
+/////////////////////////////////////////////////////////////////////////////////////
+
+CGRect CTLineGetTypographicBoundsAsRect(CTLineRef line, CGPoint lineOrigin);
+CGRect CTRunGetTypographicBoundsAsRect(CTRunRef run, CTLineRef line, CGPoint lineOrigin);
+BOOL CTLineContainsCharactersFromStringRange(CTLineRef line, NSRange range);
+BOOL CTRunContainsCharactersFromStringRange(CTRunRef run, NSRange range);
@@ -0,0 +1,138 @@
+//
+// CoreTextUtils.m
+// OHAttributedLabel
+//
+// Created by Olivier Halligon on 23/09/12.
+// Copyright (c) 2012 AliSoftware. All rights reserved.
+//
+
+#import "CoreTextUtils.h"
+
+/////////////////////////////////////////////////////////////////////////////////////
+#pragma mark - Text Alignment Convertion
+/////////////////////////////////////////////////////////////////////////////////////
+
+
+CTTextAlignment CTTextAlignmentFromUITextAlignment(UITextAlignment alignment)
+{
+ if (alignment == (UITextAlignment)kCTJustifiedTextAlignment)
+ {
+ /* special OOB value, so test it outside of the switch to avoid warning */
+ return kCTJustifiedTextAlignment;
+ }
+ switch (alignment)
+ {
+#if __IPHONE_OS_VERSION_MAX_ALLOWED < 60000
+ case UITextAlignmentLeft: return kCTLeftTextAlignment;
+ case UITextAlignmentCenter: return kCTCenterTextAlignment;
+ case UITextAlignmentRight: return kCTRightTextAlignment;
+#else
+ case NSTextAlignmentLeft: return kCTLeftTextAlignment;
+ case NSTextAlignmentCenter: return kCTCenterTextAlignment;
+ case NSTextAlignmentRight: return kCTRightTextAlignment;
+#endif
+ default: return kCTNaturalTextAlignment;
+ }
+}
+
+CTLineBreakMode CTLineBreakModeFromUILineBreakMode(UILineBreakMode lineBreakMode)
+{
+ switch (lineBreakMode)
+ {
+#if __IPHONE_OS_VERSION_MAX_ALLOWED < 60000
+ case UILineBreakModeWordWrap: return kCTLineBreakByWordWrapping;
+ case UILineBreakModeCharacterWrap: return kCTLineBreakByCharWrapping;
+ case UILineBreakModeClip: return kCTLineBreakByClipping;
+ case UILineBreakModeHeadTruncation: return kCTLineBreakByTruncatingHead;
+ case UILineBreakModeTailTruncation: return kCTLineBreakByTruncatingTail;
+ case UILineBreakModeMiddleTruncation: return kCTLineBreakByTruncatingMiddle;
+#else
+ case NSLineBreakByWordWrapping: return kCTLineBreakByWordWrapping;
+ case NSLineBreakByCharWrapping: return kCTLineBreakByCharWrapping;
+ case NSLineBreakByClipping: return kCTLineBreakByClipping;
+ case NSLineBreakByTruncatingHead: return kCTLineBreakByTruncatingHead;
+ case NSLineBreakByTruncatingTail: return kCTLineBreakByTruncatingTail;
+ case NSLineBreakByTruncatingMiddle: return kCTLineBreakByTruncatingMiddle;
+#endif
+ default: return 0;
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////
+#pragma mark - Flipping Coordinates
+/////////////////////////////////////////////////////////////////////////////////////
+
+// Don't use this method for origins. Origins always depend on the height of the rect.
+CGPoint CGPointFlipped(CGPoint point, CGRect bounds)
+{
+ return CGPointMake(point.x, CGRectGetMaxY(bounds)-point.y);
+}
+
+CGRect CGRectFlipped(CGRect rect, CGRect bounds)
+{
+ return CGRectMake(CGRectGetMinX(rect),
+ CGRectGetMaxY(bounds)-CGRectGetMaxY(rect),
+ CGRectGetWidth(rect),
+ CGRectGetHeight(rect));
+}
+
+/////////////////////////////////////////////////////////////////////////////////////
+#pragma mark - NSRange / CFRange
+/////////////////////////////////////////////////////////////////////////////////////
+
+NSRange NSRangeFromCFRange(CFRange range)
+{
+ return NSMakeRange(range.location, range.length);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////
+#pragma mark - CoreText CTLine/CTRun utils
+/////////////////////////////////////////////////////////////////////////////////////
+
+// Font Metrics: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/FontHandling/Tasks/GettingFontMetrics.html
+CGRect CTLineGetTypographicBoundsAsRect(CTLineRef line, CGPoint lineOrigin)
+{
+ CGFloat ascent = 0;
+ CGFloat descent = 0;
+ CGFloat leading = 0;
+ CGFloat width = CTLineGetTypographicBounds(line, &ascent, &descent, &leading);
+ CGFloat height = ascent + descent;
+
+ return CGRectMake(lineOrigin.x,
+ lineOrigin.y - descent,
+ width,
+ height);
+}
+
+CGRect CTRunGetTypographicBoundsAsRect(CTRunRef run, CTLineRef line, CGPoint lineOrigin)
+{
+ CGFloat ascent = 0;
+ CGFloat descent = 0;
+ CGFloat leading = 0;
+ CGFloat width = CTRunGetTypographicBounds(run, CFRangeMake(0, 0), &ascent, &descent, &leading);
+ CGFloat height = ascent + descent;
+
+ CGFloat xOffset = CTLineGetOffsetForStringIndex(line, CTRunGetStringRange(run).location, NULL);
+
+ return CGRectMake(lineOrigin.x + xOffset,
+ lineOrigin.y - descent,
+ width,
+ height);
+}
+
+BOOL CTLineContainsCharactersFromStringRange(CTLineRef line, NSRange range)
+{
+ NSRange lineRange = NSRangeFromCFRange(CTLineGetStringRange(line));
+ NSRange intersectedRange = NSIntersectionRange(lineRange, range);
+ return (intersectedRange.length > 0);
+}
+
+BOOL CTRunContainsCharactersFromStringRange(CTRunRef run, NSRange range)
+{
+ NSRange runRange = NSRangeFromCFRange(CTRunGetStringRange(run));
+ NSRange intersectedRange = NSIntersectionRange(runRange, range);
+ return (intersectedRange.length > 0);
+}
+
+
+
@@ -0,0 +1,79 @@
+/***********************************************************************************
+ * This software is under the MIT License quoted below:
+ ***********************************************************************************
+ *
+ * Copyright (c) 2010 Olivier Halligon
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ ***********************************************************************************/
+
+
+#import <Foundation/Foundation.h>
+#import <CoreText/CoreText.h>
+#import <UIKit/UIKit.h>
+
+
+/////////////////////////////////////////////////////////////////////////////////////
+#pragma mark - NSAttributedString Additions
+
+@interface NSAttributedString (OHCommodityConstructors)
++(id)attributedStringWithString:(NSString*)string;
++(id)attributedStringWithAttributedString:(NSAttributedString*)attrStr;
+
+//! Commodity method that call the following sizeConstrainedToSize:fitRange: method with NULL for the fitRange parameter
+-(CGSize)sizeConstrainedToSize:(CGSize)maxSize;
+//! if fitRange is not NULL, on return it will contain the used range that actually fits the constrained size.
+//! Note: Use CGFLOAT_MAX for the CGSize's height if you don't want a constraint for the height.
+-(CGSize)sizeConstrainedToSize:(CGSize)maxSize fitRange:(NSRange*)fitRange;
+
+-(CTFontRef)fontAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange;
+-(UIColor*)textColorAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange;
+-(BOOL)textIsUnderlinedAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange;
+//! @return a combination of CTUnderlineStyle & CTUnderlineStyleModifiers
+-(int32_t)textUnderlineStyleAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange;
+-(BOOL)textIsBoldAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange;
+-(CTTextAlignment)textAlignmentAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange;
+-(CTLineBreakMode)lineBreakModeAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange;
+@end
+
+
+/////////////////////////////////////////////////////////////////////////////////////
+#pragma mark - NSMutableAttributedString Additions
+
+@interface NSMutableAttributedString (OHCommodityStyleModifiers)
+-(void)setFont:(UIFont*)font;
+-(void)setFont:(UIFont*)font range:(NSRange)range;
+-(void)setFontName:(NSString*)fontName size:(CGFloat)size;
+-(void)setFontName:(NSString*)fontName size:(CGFloat)size range:(NSRange)range;
+-(void)setFontFamily:(NSString*)fontFamily size:(CGFloat)size bold:(BOOL)isBold italic:(BOOL)isItalic range:(NSRange)range;
+
+-(void)setTextColor:(UIColor*)color;
+-(void)setTextColor:(UIColor*)color range:(NSRange)range;
+-(void)setTextIsUnderlined:(BOOL)underlined;
+-(void)setTextIsUnderlined:(BOOL)underlined range:(NSRange)range;
+//! @param style is a combination of CTUnderlineStyle & CTUnderlineStyleModifiers
+-(void)setTextUnderlineStyle:(int32_t)style range:(NSRange)range;
+-(void)setTextBold:(BOOL)isBold range:(NSRange)range;
+
+-(void)setTextAlignment:(CTTextAlignment)alignment lineBreakMode:(CTLineBreakMode)lineBreakMode;
+-(void)setTextAlignment:(CTTextAlignment)alignment lineBreakMode:(CTLineBreakMode)lineBreakMode range:(NSRange)range;
+@end
+
+
Oops, something went wrong.

0 comments on commit c447c88

Please sign in to comment.