//
//  NSString+drawiOS7.m
//  X-BASIC for iOS
//
//  Created by 今井 彰彦(iMac) on 2014/09/13.
//  Copyright (c) 2014年 AIG-Soft. All rights reserved.
//

#import "NSString+drawiOS7.h"

/** iOS7で非推奨になったメソッドの代替処理
 NSStringの
 - (CGSize)drawAtPoint:(CGPoint)point withFont:(UIFont *)font
 - (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font
 上記2メソッドは[UIColor set]で設定された現在の描画色で描画されるが、
 代替メソッドとされている
 - (void)drawAtPoint:(CGPoint)point withAttributes:(NSDictionary *)attrs
 - (void)drawInRect:(CGRect)rect withAttributes:(NSDictionary *)attrs
 はリターン値はない上に、現在の描画色ではなくatrbでしていた色で描画する。
 色指定がないときは黒になってしまう。
 */

@implementation NSString (drawiOS7)

-(NSDictionary *)getAtrb:(UIFont *)font	color:(UIColor *)color
{
	NSDictionary *atrb=@{
						 NSFontAttributeName : font,
						 NSForegroundColorAttributeName:color
						 };
	return atrb;
}

- (NSDictionary *)drawAtPoint7NoReturn:(CGPoint)point withFont:(UIFont *)font withColor:(UIColor *)color
{
	NSDictionary *atrb=[self getAtrb:font color:color];
	[self drawAtPoint:point withAttributes:atrb];
	return atrb;
}

- (NSDictionary *)drawInRect7NoReturn:(CGRect)rect withFont:(UIFont *)font withColor:color
{
	NSDictionary *atrb=[self getAtrb:font color:color];
	[self drawInRect:rect 	withAttributes:[self getAtrb:font color:color]];
	return atrb;
}

-(NSDictionary *)drawInRect7NoReturn:(CGRect)rect withFont:(UIFont *)font withColor:color
			 lineBreakMode:(NSLineBreakMode)lineBreakMode
				 alignment:(NSTextAlignment)alignment
{
	NSMutableParagraphStyle *pstyle=[[NSMutableParagraphStyle alloc]init];
	pstyle.alignment	=alignment;
	pstyle.lineBreakMode=lineBreakMode;
	NSDictionary *atrb=@{
						 NSFontAttributeName : font,
						 NSForegroundColorAttributeName:color,
						 NSParagraphStyleAttributeName:pstyle,
						 };
	[self drawInRect:rect 	withAttributes:atrb];
	return atrb;
}

//----------------------

- (CGSize)drawAtPoint7:(CGPoint)point withFont:(UIFont *)font withColor:(UIColor *)color
{
	NSDictionary *atrb=[self drawAtPoint7NoReturn:point withFont:font withColor:color];
	return [self sizeWithAttributes:atrb];
}

- (CGSize)drawInRect7:(CGRect)rect withFont:(UIFont *)font withColor:(UIColor *)color
{
	NSDictionary *atrb=[self drawInRect7NoReturn:rect withFont:font withColor:color];
	return [self sizeWithAttributes:atrb];
}

-(CGSize)drawInRect7:(CGRect)rect withFont:(UIFont *)font withColor:color
			 lineBreakMode:(NSLineBreakMode)lineBreakMode
				 alignment:(NSTextAlignment)alignment
{
	NSDictionary *atrb=[self drawInRect7NoReturn:rect withFont:font withColor:color lineBreakMode:lineBreakMode alignment:alignment];
	return [self sizeWithAttributes:atrb];
}


@end
