Permalink
Browse files

Renamed internal methods, added docs to small caps

  • Loading branch information...
1 parent 04051ed commit a568d8f9fc274bc63dd3e24447f8f4df86b26efa @odrobnik odrobnik committed Feb 23, 2012
@@ -26,8 +26,8 @@
// two correction methods used by the deprecated way of layouting to work around Core Text bugs
@interface DTCoreTextLayoutFrame ()
-- (void)correctAttachmentHeights;
-- (void)correctLineOrigins;
+- (void)_correctAttachmentHeights;
+- (void)_correctLineOrigins;
@end
@@ -42,11 +42,6 @@ @implementation DTCoreTextLayoutFrame
NSInteger tag;
}
-+ (void)setShouldDrawDebugFrames:(BOOL)debugFrames
-{
- _DTCoreTextLayoutFramesShouldDrawDebugFrames = debugFrames;
-}
-
// makes a frame for a specific part of the attributed string of the layouter
- (id)initWithFrame:(CGRect)frame layouter:(DTCoreTextLayouter *)layouter range:(NSRange)range
{
@@ -320,14 +315,14 @@ - (void)_buildLinesWithStandardFramesetter
_stringRange.length = fittingRange.length;
// line origins are wrong on last line of paragraphs
- [self correctLineOrigins];
+ [self _correctLineOrigins];
// --- begin workaround for image squishing bug in iOS < 4.2
DTVersion version = [[UIDevice currentDevice] osVersion];
if (version.major<4 || (version.major==4 && version.minor < 2))
{
- [self correctAttachmentHeights];
+ [self _correctAttachmentHeights];
}
// at this point we can correct the frame if it is open-ended
@@ -419,7 +414,9 @@ - (NSArray *)linesContainedInRect:(CGRect)rect
return tmpArray;
}
-- (void)setShadowInContext:(CGContextRef)context fromDictionary:(NSDictionary *)dictionary
+#pragma mark Drawing
+
+- (void)_setShadowInContext:(CGContextRef)context fromDictionary:(NSDictionary *)dictionary
{
DTColor *color = [dictionary objectForKey:@"Color"];
CGSize offset = [[dictionary objectForKey:@"Offset"] CGSizeValue];
@@ -664,7 +661,7 @@ - (void)drawInContext:(CGContextRef)context drawImages:(BOOL)drawImages
for (NSDictionary *shadowDict in shadows)
{
- [self setShadowInContext:context fromDictionary:shadowDict];
+ [self _setShadowInContext:context fromDictionary:shadowDict];
// draw once per shadow
[oneRun drawInContext:context];
@@ -710,22 +707,7 @@ - (void)drawInContext:(CGContextRef)context drawImages:(BOOL)drawImages
CGContextRestoreGState(context);
}
-// assume we want to draw images statically
-- (void)drawInContext:(CGContextRef)context
-{
- [self drawInContext:context drawImages:YES];
-}
-
-
-- (NSRange)visibleStringRange
-{
- if (!_textFrame)
- {
- return NSMakeRange(0, 0);
- }
-
- return _stringRange;
-}
+#pragma mark Text Attachments
- (NSArray *)textAttachments
{
@@ -759,11 +741,26 @@ - (NSArray *)textAttachmentsWithPredicate:(NSPredicate *)predicate
}
#pragma mark Calculations
-- (NSArray *)stringIndices {
+
+- (NSRange)visibleStringRange
+{
+ if (!_textFrame)
+ {
+ return NSMakeRange(0, 0);
+ }
+
+ return _stringRange;
+}
+
+- (NSArray *)stringIndices
+{
NSMutableArray *array = [NSMutableArray arrayWithCapacity:[self.lines count]];
- for (DTCoreTextLayoutLine *oneLine in self.lines) {
+
+ for (DTCoreTextLayoutLine *oneLine in self.lines)
+ {
[array addObjectsFromArray:[oneLine stringIndices]];
}
+
return array;
}
@@ -911,8 +908,14 @@ - (NSRange)paragraphRangeContainingStringRange:(NSRange)stringRange
return NSMakeRange(firstParagraphIndex, lastParagraphIndex - firstParagraphIndex + 1);
}
+#pragma mark Debugging
++ (void)setShouldDrawDebugFrames:(BOOL)debugFrames
+{
+ _DTCoreTextLayoutFramesShouldDrawDebugFrames = debugFrames;
+}
+
#pragma mark Corrections
-- (void)correctAttachmentHeights
+- (void)_correctAttachmentHeights
{
CGFloat downShiftSoFar = 0;
@@ -939,7 +942,7 @@ - (void)correctAttachmentHeights
// a bug in CoreText shifts the last line of paragraphs slightly down
-- (void)correctLineOrigins
+- (void)_correctLineOrigins
{
DTCoreTextLayoutLine *previousLine = nil;
@@ -6,11 +6,21 @@
// Copyright (c) 2012 Drobnik.com. All rights reserved.
//
-#import <Foundation/Foundation.h>
+/**
+ Methods that generated an attributed string with Small Caps, even if the used fonts don't support them natively.
+
+ This category works equally for Mac and iOS attributed strings.
+ */
@interface NSAttributedString (SmallCaps)
-// utilities
+/**
+ Creates an `NSAttributedString` from the given text and attributes and synthesizes small caps. On iPad there is only one font that has native small caps, for all other fonts the small caps are synthesized by reduzing the font size for all lowercase characters.
+
+ @param text The string to convert into an attributed string
+ @param attributes A dictionary with attributes for the attributed string
+ @returns An attributed string with synthesized small caps.
+*/
+ (NSAttributedString *)synthesizedSmallCapsAttributedStringWithText:(NSString *)text attributes:(NSDictionary *)attributes;
@end
@@ -21,7 +21,6 @@ + (NSAttributedString *)synthesizedSmallCapsAttributedStringWithText:(NSString *
NSMutableDictionary *smallAttributes = [attributes mutableCopy];
[smallAttributes setObject:CFBridgingRelease(smallerFont) forKey:(id)kCTFontAttributeName];
- //CFRelease(smallerFont);
NSMutableAttributedString *tmpString = [[NSMutableAttributedString alloc] init];
NSScanner *scanner = [NSScanner scannerWithString:text];
@@ -47,7 +46,6 @@ + (NSAttributedString *)synthesizedSmallCapsAttributedStringWithText:(NSString *
}
}
-
return tmpString;
}

0 comments on commit a568d8f

Please sign in to comment.