|
@@ -9,6 +9,8 @@
|
|
|
#import "TextDrawable.h"
|
|
#import "TextDrawable.h"
|
|
|
#import <CoreText/CoreText.h>
|
|
#import <CoreText/CoreText.h>
|
|
|
#import "TextUtils.h"
|
|
#import "TextUtils.h"
|
|
|
|
|
+#define DEBUG_STRING_VALUE0 @"DEBUG OFF"
|
|
|
|
|
+#define DEBUG_STRING_VALUE1 @"DEBUG OFF"
|
|
|
|
|
|
|
|
@implementation TextDrawable
|
|
@implementation TextDrawable
|
|
|
|
|
|
|
@@ -73,19 +75,19 @@
|
|
|
NSLog(@"setDrawableTemplate text align : %@",align);
|
|
NSLog(@"setDrawableTemplate text align : %@",align);
|
|
|
if(align.length==0 || [align.lowercaseString isEqualToString:@"left"])
|
|
if(align.length==0 || [align.lowercaseString isEqualToString:@"left"])
|
|
|
{
|
|
{
|
|
|
- self.textalignment= kCTTextAlignmentLeft;
|
|
|
|
|
|
|
+ self.textalignment= NSTextAlignmentLeft;
|
|
|
}
|
|
}
|
|
|
else if([align.lowercaseString isEqualToString:@"right"])
|
|
else if([align.lowercaseString isEqualToString:@"right"])
|
|
|
{
|
|
{
|
|
|
- self.textalignment= kCTTextAlignmentRight;
|
|
|
|
|
|
|
+ self.textalignment= NSTextAlignmentRight;
|
|
|
}
|
|
}
|
|
|
else if([align.lowercaseString isEqualToString:@"center"])
|
|
else if([align.lowercaseString isEqualToString:@"center"])
|
|
|
{
|
|
{
|
|
|
- self.textalignment= kCTTextAlignmentCenter;
|
|
|
|
|
|
|
+ self.textalignment= NSTextAlignmentCenter;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- self.textalignment= kCTTextAlignmentLeft;
|
|
|
|
|
|
|
+ self.textalignment= NSTextAlignmentLeft;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
self.lineSpace = 0;
|
|
self.lineSpace = 0;
|
|
@@ -120,7 +122,7 @@
|
|
|
|
|
|
|
|
-(CGRect) Query_Rect:(CGContextRef) context dataSource:(NSMutableDictionary*)data ParentRect:(CGRect)p_rect startX:(double) x startY:(double) y flipHeight:(double)flip_height range:(NSRange)between_header_and_footer
|
|
-(CGRect) Query_Rect:(CGContextRef) context dataSource:(NSMutableDictionary*)data ParentRect:(CGRect)p_rect startX:(double) x startY:(double) y flipHeight:(double)flip_height range:(NSRange)between_header_and_footer
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
|
|
+// return p_rect;
|
|
|
bool expand=[self.drawableTemplate[@"expand"] boolValue];
|
|
bool expand=[self.drawableTemplate[@"expand"] boolValue];
|
|
|
if(!expand)
|
|
if(!expand)
|
|
|
{
|
|
{
|
|
@@ -194,7 +196,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
bool bold = [self.drawableTemplate[@"bold"] boolValue];
|
|
bool bold = [self.drawableTemplate[@"bold"] boolValue];
|
|
|
- bool italic = [self.drawableTemplate[@"italic"] boolValue];
|
|
|
|
|
|
|
+// bool italic = [self.drawableTemplate[@"italic"] boolValue];
|
|
|
NSString* font=self.drawableTemplate[@"font"];
|
|
NSString* font=self.drawableTemplate[@"font"];
|
|
|
|
|
|
|
|
// [super flipContext:context ContextHeight:flip_height];
|
|
// [super flipContext:context ContextHeight:flip_height];
|
|
@@ -234,58 +236,68 @@
|
|
|
string = [self richtext2attributedstring:string font:font size:fontsize bold:bold];
|
|
string = [self richtext2attributedstring:string font:font size:fontsize bold:bold];
|
|
|
|
|
|
|
|
|
|
|
|
|
- //设置字体间距
|
|
|
|
|
- long number = self.characterSpace;
|
|
|
|
|
- CFNumberRef num = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt8Type, &number);
|
|
|
|
|
- [string addAttribute:(id)kCTKernAttributeName value:CFBridgingRelease(num) range:NSMakeRange(0, [string length])];
|
|
|
|
|
- //CFRelease(num);
|
|
|
|
|
|
|
+// //设置字体间距
|
|
|
|
|
+// long number = self.characterSpace;
|
|
|
|
|
+// CFNumberRef num = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt8Type, &number);
|
|
|
|
|
+// [string addAttribute:(id)kCTKernAttributeName value:(__bridge NSNumber*)num range:NSMakeRange(0, [string length])];
|
|
|
|
|
+// CFRelease(num);
|
|
|
|
|
|
|
|
|
|
|
|
|
- //创建文本对齐方式
|
|
|
|
|
- CTTextAlignment alignment = self.textalignment;//对齐方
|
|
|
|
|
- CTParagraphStyleSetting alignmentStyle;
|
|
|
|
|
- alignmentStyle.spec=kCTParagraphStyleSpecifierAlignment;
|
|
|
|
|
- alignmentStyle.valueSize=sizeof(alignment);
|
|
|
|
|
- alignmentStyle.value=&alignment;
|
|
|
|
|
|
|
+// //创建文本对齐方式
|
|
|
|
|
+// CTTextAlignment alignment = self.textalignment;//对齐方
|
|
|
|
|
+// CTParagraphStyleSetting alignmentStyle;
|
|
|
|
|
+// alignmentStyle.spec=kCTParagraphStyleSpecifierAlignment;
|
|
|
|
|
+// alignmentStyle.valueSize=sizeof(alignment);
|
|
|
|
|
+// alignmentStyle.value=&alignment;
|
|
|
|
|
|
|
|
- //创建文本, 行间距
|
|
|
|
|
- CGFloat lineSpace=self.lineSpace;//间距数据
|
|
|
|
|
- CTParagraphStyleSetting lineSpaceStyle;
|
|
|
|
|
- lineSpaceStyle.spec=kCTParagraphStyleSpecifierLineSpacing;
|
|
|
|
|
- lineSpaceStyle.valueSize=sizeof(lineSpace);
|
|
|
|
|
- lineSpaceStyle.value=&lineSpace;
|
|
|
|
|
|
|
+// //创建文本, 行间距
|
|
|
|
|
+// CGFloat lineSpace=self.lineSpace;//间距数据
|
|
|
|
|
+// CTParagraphStyleSetting lineSpaceStyle;
|
|
|
|
|
+// lineSpaceStyle.spec=kCTParagraphStyleSpecifierLineSpacing;
|
|
|
|
|
+// lineSpaceStyle.valueSize=sizeof(lineSpace);
|
|
|
|
|
+// lineSpaceStyle.value=&lineSpace;
|
|
|
|
|
|
|
|
- //设置 line break;
|
|
|
|
|
- CTLineBreakMode linebreakmode = kCTLineBreakByTruncatingTail;
|
|
|
|
|
- CTParagraphStyleSetting linebreakStyle;
|
|
|
|
|
- linebreakStyle.spec = kCTParagraphStyleSpecifierLineBreakMode;
|
|
|
|
|
- linebreakStyle.valueSize = sizeof(CGFloat);
|
|
|
|
|
- linebreakStyle.value = &linebreakmode;
|
|
|
|
|
|
|
+// //设置 line break;
|
|
|
|
|
+// CTLineBreakMode linebreakmode = kCTLineBreakByTruncatingTail;
|
|
|
|
|
+// CTParagraphStyleSetting linebreakStyle;
|
|
|
|
|
+// linebreakStyle.spec = kCTParagraphStyleSpecifierLineBreakMode;
|
|
|
|
|
+// linebreakStyle.valueSize = sizeof(CGFloat);
|
|
|
|
|
+// linebreakStyle.value = &linebreakmode;
|
|
|
|
|
|
|
|
|
|
|
|
|
- //设置 段落间距
|
|
|
|
|
- CGFloat paragraph = self.paragraphSpace;
|
|
|
|
|
- CTParagraphStyleSetting paragraphStyle;
|
|
|
|
|
- paragraphStyle.spec = kCTParagraphStyleSpecifierParagraphSpacing;
|
|
|
|
|
- paragraphStyle.valueSize = sizeof(CGFloat);
|
|
|
|
|
- paragraphStyle.value = ¶graph;
|
|
|
|
|
|
|
+// //设置 段落间距
|
|
|
|
|
+// CGFloat paragraph = self.paragraphSpace;
|
|
|
|
|
+// CTParagraphStyleSetting paragraphStyle;
|
|
|
|
|
+// paragraphStyle.spec = kCTParagraphStyleSpecifierParagraphSpacing;
|
|
|
|
|
+// paragraphStyle.valueSize = sizeof(CGFloat);
|
|
|
|
|
+// paragraphStyle.value = ¶graph;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//创建样式数组
|
|
//创建样式数组
|
|
|
- CTParagraphStyleSetting settings[]={
|
|
|
|
|
- alignmentStyle,lineSpaceStyle,paragraphStyle,linebreakStyle
|
|
|
|
|
- };
|
|
|
|
|
|
|
+// CTParagraphStyleSetting settings[]={
|
|
|
|
|
+// alignmentStyle/*,linebreakStyle,lineSpaceStyle,paragraphStyle*/
|
|
|
|
|
+// };
|
|
|
|
|
+//
|
|
|
|
|
+// //设置样式
|
|
|
|
|
+// CTParagraphStyleRef paragraphStyle1 = CTParagraphStyleCreate(settings, sizeof(settings));
|
|
|
|
|
+//
|
|
|
|
|
+// //给字符串添加样式attribute
|
|
|
|
|
+// [string addAttribute:(id)kCTParagraphStyleAttributeName
|
|
|
|
|
+// value:(__bridge id)paragraphStyle1
|
|
|
|
|
+// range:NSMakeRange(0, [string length])];
|
|
|
|
|
+// CFRelease(paragraphStyle1);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
- //设置样式
|
|
|
|
|
- CTParagraphStyleRef paragraphStyle1 = CTParagraphStyleCreate(settings, sizeof(settings));
|
|
|
|
|
|
|
+ NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
|
|
|
|
|
|
|
- //给字符串添加样式attribute
|
|
|
|
|
- [string addAttribute:(id)kCTParagraphStyleAttributeName
|
|
|
|
|
- value:CFBridgingRelease(paragraphStyle1)
|
|
|
|
|
- range:NSMakeRange(0, [string length])];
|
|
|
|
|
|
|
|
|
|
|
|
+ [style setAlignment:self.textalignment];
|
|
|
|
|
+ [style setLineBreakMode:NSLineBreakByTruncatingTail];
|
|
|
|
|
+
|
|
|
|
|
+ [string addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, [string length])];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -301,7 +313,7 @@
|
|
|
//计算文本绘制size ,这里300是文字宽度,你可以自己更改为247,但是要记得,在height 方法里的这个位置,也改为247
|
|
//计算文本绘制size ,这里300是文字宽度,你可以自己更改为247,但是要记得,在height 方法里的这个位置,也改为247
|
|
|
CGSize tmpSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0,0), NULL, CGSizeMake(self.rect.size.width-self.margin_left-self.margin_right, MAXFLOAT), NULL);
|
|
CGSize tmpSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0,0), NULL, CGSizeMake(self.rect.size.width-self.margin_left-self.margin_right, MAXFLOAT), NULL);
|
|
|
//创建textBoxSize以设置view的frame
|
|
//创建textBoxSize以设置view的frame
|
|
|
- CGSize textBoxSize = CGSizeMake((int)tmpSize.width + 1, (int)tmpSize.height + 1);
|
|
|
|
|
|
|
+// CGSize textBoxSize = CGSizeMake((int)tmpSize.width + 1, (int)tmpSize.height + 1);
|
|
|
// DebugLog(@"textBoxSize0 == %f,%f,%f",textBoxSize.width,textBoxSize.height,textBoxSize.width / textBoxSize.height);
|
|
// DebugLog(@"textBoxSize0 == %f,%f,%f",textBoxSize.width,textBoxSize.height,textBoxSize.width / textBoxSize.height);
|
|
|
// self.frame = CGRectMake(0, 0, textBoxSize.width , textBoxSize.height);
|
|
// self.frame = CGRectMake(0, 0, textBoxSize.width , textBoxSize.height);
|
|
|
// [string release];
|
|
// [string release];
|
|
@@ -384,7 +396,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
--(CTFontRef)CreateFont:(NSString*)name size:(double)size bold:(bool)bold
|
|
|
|
|
|
|
+-(UIFont*)CreateFont:(NSString*)name size:(double)size bold:(bool)bold
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
if(name.length==0)
|
|
if(name.length==0)
|
|
@@ -396,31 +408,44 @@
|
|
|
{
|
|
{
|
|
|
size=10;
|
|
size=10;
|
|
|
}
|
|
}
|
|
|
- NSString* style = @"Regular";
|
|
|
|
|
- if(bold)
|
|
|
|
|
- style=@"Bold";
|
|
|
|
|
|
|
+// NSString* style = @"Regular";
|
|
|
|
|
+// if(bold)
|
|
|
|
|
+// style=@"Bold";
|
|
|
|
|
|
|
|
//name=@"Courier";
|
|
//name=@"Courier";
|
|
|
|
|
+
|
|
|
|
|
|
|
|
NSDictionary *fontAttributes =
|
|
NSDictionary *fontAttributes =
|
|
|
[NSDictionary dictionaryWithObjectsAndKeys:
|
|
[NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
- name, (NSString *)kCTFontFamilyNameAttribute,
|
|
|
|
|
- style, (NSString *)kCTFontStyleNameAttribute,
|
|
|
|
|
|
|
+ name, UIFontDescriptorFamilyAttribute,
|
|
|
|
|
+// style, UIFontDescriptorTextStyleAttribute,
|
|
|
[NSNumber numberWithFloat:size],
|
|
[NSNumber numberWithFloat:size],
|
|
|
- (NSString *)kCTFontSizeAttribute,
|
|
|
|
|
|
|
+ UIFontDescriptorSizeAttribute,
|
|
|
nil];
|
|
nil];
|
|
|
- // Create a descriptor.
|
|
|
|
|
- CFDictionaryRef cffontAttributes =(__bridge CFDictionaryRef)fontAttributes;
|
|
|
|
|
- CTFontDescriptorRef descriptor =
|
|
|
|
|
- CTFontDescriptorCreateWithAttributes(cffontAttributes);
|
|
|
|
|
|
|
|
|
|
- // CFBridgingRelease(cffontAttributes);
|
|
|
|
|
|
|
+ UIFontDescriptor* fontdescriptor=[UIFontDescriptor fontDescriptorWithFontAttributes:fontAttributes];
|
|
|
|
|
+
|
|
|
|
|
+ if(bold)
|
|
|
|
|
+ fontdescriptor = [fontdescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];
|
|
|
|
|
|
|
|
- // Create a font using the descriptor.
|
|
|
|
|
- CTFontRef font = CTFontCreateWithFontDescriptor(descriptor, 0.0, NULL);
|
|
|
|
|
- CFBridgingRelease(descriptor);
|
|
|
|
|
|
|
|
|
|
|
|
+ UIFont * font = [UIFont fontWithDescriptor:fontdescriptor size:0.0];
|
|
|
return font;
|
|
return font;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+//
|
|
|
|
|
+// // Create a descriptor.
|
|
|
|
|
+// CFDictionaryRef cffontAttributes =(__bridge CFDictionaryRef)fontAttributes;
|
|
|
|
|
+// CTFontDescriptorRef descriptor =
|
|
|
|
|
+// CTFontDescriptorCreateWithAttributes(cffontAttributes);
|
|
|
|
|
+//
|
|
|
|
|
+// // CFBridgingRelease(cffontAttributes);
|
|
|
|
|
+//
|
|
|
|
|
+// // Create a font using the descriptor.
|
|
|
|
|
+// CTFontRef font = CTFontCreateWithFontDescriptor(descriptor, 0.0, NULL);
|
|
|
|
|
+// CFRelease(descriptor);
|
|
|
|
|
+//
|
|
|
|
|
+// return font;
|
|
|
|
|
|
|
|
// if(bold)
|
|
// if(bold)
|
|
|
// {
|
|
// {
|
|
@@ -452,25 +477,30 @@
|
|
|
// DebugLog(@"%@", attrStr);
|
|
// DebugLog(@"%@", attrStr);
|
|
|
// DebugLog(@"%@", uilabel.attributedText);
|
|
// DebugLog(@"%@", uilabel.attributedText);
|
|
|
|
|
|
|
|
- CTFontRef ctfont = [self CreateFont:font size:size bold:bold];//CTFontCreateWithName(CFSTR("Helvetica"), fontsize, NULL);b
|
|
|
|
|
|
|
+ // CTFontRef ctfont = [self CreateFont:font size:size bold:bold];//CTFontCreateWithName(CFSTR("Helvetica"), fontsize, NULL);b
|
|
|
|
|
+ UIFont* uifont =[self CreateFont:font size:size bold:bold];
|
|
|
|
|
+
|
|
|
|
|
|
|
|
//CTFontCreateWithName(CFSTR("Helvetica"), fontsize, NULL);
|
|
//CTFontCreateWithName(CFSTR("Helvetica"), fontsize, NULL);
|
|
|
// CTFontRef helveticaBold = CTFontCreateWithName(CFSTR("Helvetica"), fontsize, NULL);
|
|
// CTFontRef helveticaBold = CTFontCreateWithName(CFSTR("Helvetica"), fontsize, NULL);
|
|
|
//字体,把helvetica 样式加到整个,string上
|
|
//字体,把helvetica 样式加到整个,string上
|
|
|
- [string addAttribute:(id)kCTFontAttributeName
|
|
|
|
|
- value:CFBridgingRelease(ctfont)
|
|
|
|
|
|
|
+ [string addAttribute:NSFontAttributeName
|
|
|
|
|
+ value:uifont
|
|
|
range:NSMakeRange(0, [string length])];
|
|
range:NSMakeRange(0, [string length])];
|
|
|
|
|
+// CFRelease(ctfont);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
//颜色,此处为黑色,你可以自己改颜色,[UIColor redColor]
|
|
//颜色,此处为黑色,你可以自己改颜色,[UIColor redColor]
|
|
|
- [string addAttribute:(id)kCTForegroundColorAttributeName
|
|
|
|
|
- value:(id)self.textColor.CGColor
|
|
|
|
|
|
|
+ [string addAttribute:NSForegroundColorAttributeName
|
|
|
|
|
+ value:self.textColor
|
|
|
range:NSMakeRange(0, [string length])];
|
|
range:NSMakeRange(0, [string length])];
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!bold)
|
|
if(!bold)
|
|
|
{
|
|
{
|
|
|
- CTFontRef ctfont_bold = [self CreateFont:font size:size bold:true];
|
|
|
|
|
- NSString* newstring= nil;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // NSString* newstring= nil;
|
|
|
// NSString *content = string.string ;
|
|
// NSString *content = string.string ;
|
|
|
NSString *pattern = @"\\<b\\>([\\s\\S]*?)\\<\\/b\\>";
|
|
NSString *pattern = @"\\<b\\>([\\s\\S]*?)\\<\\/b\\>";
|
|
|
// NSArray* matches=[TextUtils expression_varable:content regex:pattern];
|
|
// NSArray* matches=[TextUtils expression_varable:content regex:pattern];
|
|
@@ -482,7 +512,7 @@
|
|
|
// }
|
|
// }
|
|
|
// }
|
|
// }
|
|
|
NSTextCheckingResult * match=[TextUtils expression_findfistMatch:string.string regex:pattern];
|
|
NSTextCheckingResult * match=[TextUtils expression_findfistMatch:string.string regex:pattern];
|
|
|
-
|
|
|
|
|
|
|
+ UIFont* uifontbold = [self CreateFont:font size:size bold:true];
|
|
|
while(match)
|
|
while(match)
|
|
|
{
|
|
{
|
|
|
//for (int i = 0; i < match.numberOfRanges/2; ++i)
|
|
//for (int i = 0; i < match.numberOfRanges/2; ++i)
|
|
@@ -493,9 +523,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
DebugLog(@"string length: %d",string.string.length);
|
|
DebugLog(@"string length: %d",string.string.length);
|
|
|
- [string addAttribute:(id)kCTFontAttributeName
|
|
|
|
|
- value:(__bridge id _Nonnull)(ctfont_bold)
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+// CTFontRef ctfont_bold = [self CreateFont:font size:size bold:true];
|
|
|
|
|
+ [string addAttribute:NSFontAttributeName
|
|
|
|
|
+ value:uifontbold
|
|
|
range:[match rangeAtIndex:i+1]];
|
|
range:[match rangeAtIndex:i+1]];
|
|
|
|
|
+
|
|
|
|
|
|
|
|
[string replaceCharactersInRange:NSMakeRange([match rangeAtIndex:i+1].location+[match rangeAtIndex:i+1].length, [match rangeAtIndex:i].location+[match rangeAtIndex:i].length-([match rangeAtIndex:i+1].location+[match rangeAtIndex:i+1].length)) withString:@""];
|
|
[string replaceCharactersInRange:NSMakeRange([match rangeAtIndex:i+1].location+[match rangeAtIndex:i+1].length, [match rangeAtIndex:i].location+[match rangeAtIndex:i].length-([match rangeAtIndex:i+1].location+[match rangeAtIndex:i+1].length)) withString:@""];
|
|
|
[string replaceCharactersInRange:NSMakeRange([match rangeAtIndex:i].location, [match rangeAtIndex:i+1].location-[match rangeAtIndex:i].location) withString:@""];
|
|
[string replaceCharactersInRange:NSMakeRange([match rangeAtIndex:i].location, [match rangeAtIndex:i+1].location-[match rangeAtIndex:i].location) withString:@""];
|
|
@@ -528,7 +562,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- CFBridgingRelease(ctfont_bold);
|
|
|
|
|
|
|
+// CFRelease(ctfont_bold);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -546,6 +580,8 @@
|
|
|
if([source isEqualToString:@"const"])
|
|
if([source isEqualToString:@"const"])
|
|
|
{
|
|
{
|
|
|
self.text=self.drawableTemplate[@"text"];
|
|
self.text=self.drawableTemplate[@"text"];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
// self.text=[self.text stringByReplacingOccurrencesOfString:@"\r\n" withString:@"<br>"];
|
|
// self.text=[self.text stringByReplacingOccurrencesOfString:@"\r\n" withString:@"<br>"];
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -590,7 +626,10 @@
|
|
|
self.text=@"";
|
|
self.text=@"";
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ if([self.text isEqualToString:DEBUG_STRING_VALUE0])
|
|
|
|
|
+ {
|
|
|
|
|
+ self.text =DEBUG_STRING_VALUE1;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
// if([self.text isEqualToString:@"www.newpacificdirect.com"])
|
|
// if([self.text isEqualToString:@"www.newpacificdirect.com"])
|
|
@@ -600,7 +639,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
bool bold = [self.drawableTemplate[@"bold"] boolValue];
|
|
bool bold = [self.drawableTemplate[@"bold"] boolValue];
|
|
|
- bool italic = [self.drawableTemplate[@"italic"] boolValue];
|
|
|
|
|
|
|
+// bool italic = [self.drawableTemplate[@"italic"] boolValue];
|
|
|
NSString* font=self.drawableTemplate[@"font"];
|
|
NSString* font=self.drawableTemplate[@"font"];
|
|
|
|
|
|
|
|
// [super flipContext:context ContextHeight:flip_height];
|
|
// [super flipContext:context ContextHeight:flip_height];
|
|
@@ -638,7 +677,7 @@
|
|
|
// range:NSMakeRange(0, [string length])];
|
|
// range:NSMakeRange(0, [string length])];
|
|
|
|
|
|
|
|
string = [self richtext2attributedstring:string font:font size:fontsize bold:bold];
|
|
string = [self richtext2attributedstring:string font:font size:fontsize bold:bold];
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
// //设置字体间距
|
|
// //设置字体间距
|
|
|
// long number = self.characterSpace;
|
|
// long number = self.characterSpace;
|
|
@@ -648,11 +687,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
//创建文本对齐方式
|
|
//创建文本对齐方式
|
|
|
- CTTextAlignment alignment = self.textalignment;//对齐方
|
|
|
|
|
- CTParagraphStyleSetting alignmentStyle;
|
|
|
|
|
- alignmentStyle.spec=kCTParagraphStyleSpecifierAlignment;
|
|
|
|
|
- alignmentStyle.valueSize=sizeof(alignment);
|
|
|
|
|
- alignmentStyle.value=&alignment;
|
|
|
|
|
|
|
+// CTTextAlignment alignment = self.textalignment;//对齐方
|
|
|
|
|
+// CTParagraphStyleSetting alignmentStyle;
|
|
|
|
|
+// alignmentStyle.spec=kCTParagraphStyleSpecifierAlignment;
|
|
|
|
|
+// alignmentStyle.valueSize=sizeof(CTTextAlignment);
|
|
|
|
|
+// alignmentStyle.value=&alignment;
|
|
|
//
|
|
//
|
|
|
// //创建文本, 行间距
|
|
// //创建文本, 行间距
|
|
|
// CGFloat lineSpace=self.lineSpace;//间距数据
|
|
// CGFloat lineSpace=self.lineSpace;//间距数据
|
|
@@ -661,12 +700,12 @@
|
|
|
// lineSpaceStyle.valueSize=sizeof(lineSpace);
|
|
// lineSpaceStyle.valueSize=sizeof(lineSpace);
|
|
|
// lineSpaceStyle.value=&lineSpace;
|
|
// lineSpaceStyle.value=&lineSpace;
|
|
|
//
|
|
//
|
|
|
- //设置 line break;
|
|
|
|
|
- CTLineBreakMode linebreakmode = kCTLineBreakByTruncatingTail;
|
|
|
|
|
- CTParagraphStyleSetting linebreakStyle;
|
|
|
|
|
- linebreakStyle.spec = kCTParagraphStyleSpecifierLineBreakMode;
|
|
|
|
|
- linebreakStyle.valueSize = sizeof(CGFloat);
|
|
|
|
|
- linebreakStyle.value = &linebreakmode;
|
|
|
|
|
|
|
+// //设置 line break;
|
|
|
|
|
+// CTLineBreakMode linebreakmode = kCTLineBreakByTruncatingTail;
|
|
|
|
|
+// CTParagraphStyleSetting linebreakStyle;
|
|
|
|
|
+// linebreakStyle.spec = kCTParagraphStyleSpecifierLineBreakMode;
|
|
|
|
|
+// linebreakStyle.valueSize = sizeof(CGFloat);
|
|
|
|
|
+// linebreakStyle.value = &linebreakmode;
|
|
|
//
|
|
//
|
|
|
//
|
|
//
|
|
|
// //设置 段落间距
|
|
// //设置 段落间距
|
|
@@ -679,18 +718,42 @@
|
|
|
//
|
|
//
|
|
|
//
|
|
//
|
|
|
//
|
|
//
|
|
|
- //创建样式数组
|
|
|
|
|
- CTParagraphStyleSetting settings[]={
|
|
|
|
|
- alignmentStyle/*,linebreakStyle,lineSpaceStyle,paragraphStylesetting*/
|
|
|
|
|
- };
|
|
|
|
|
|
|
+// //创建样式数组
|
|
|
|
|
+// CTParagraphStyleSetting settings[]={
|
|
|
|
|
+// alignmentStyle/*,linebreakStyle,lineSpaceStyle,paragraphStylesetting*/
|
|
|
|
|
+// };
|
|
|
|
|
+//
|
|
|
|
|
+// //设置样式
|
|
|
|
|
+// CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(settings, sizeof(settings));
|
|
|
|
|
+//
|
|
|
|
|
+// //给字符串添加样式attribute
|
|
|
|
|
+// [string addAttribute:NSParagraphStyleAttributeName
|
|
|
|
|
+// value:(__bridge id)(paragraphStyle)
|
|
|
|
|
+// range:NSMakeRange(0, [string length])];
|
|
|
|
|
+// CFRelease(paragraphStyle);
|
|
|
|
|
|
|
|
- //设置样式
|
|
|
|
|
- CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(settings, sizeof(settings));
|
|
|
|
|
-
|
|
|
|
|
- //给字符串添加样式attribute
|
|
|
|
|
- [string addAttribute:(id)kCTParagraphStyleAttributeName
|
|
|
|
|
- value:CFBridgingRelease(paragraphStyle)
|
|
|
|
|
- range:NSMakeRange(0, [string length])];
|
|
|
|
|
|
|
+
|
|
|
|
|
+ NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ [style setAlignment:self.textalignment];
|
|
|
|
|
+ [style setLineBreakMode:NSLineBreakByTruncatingTail];
|
|
|
|
|
+ [style setLineBreakMode:NSLineBreakByWordWrapping];
|
|
|
|
|
+ // style SETLINE
|
|
|
|
|
+
|
|
|
|
|
+ [string addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, [string length])];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if([self.text isEqualToString:DEBUG_STRING_VALUE1])
|
|
|
|
|
+ {
|
|
|
|
|
+ bool debug=true;
|
|
|
|
|
+ NSLog(@"textdrawable text:%@",self.text);
|
|
|
|
|
+ NSLog(@"string %@",string);
|
|
|
|
|
+ // NSLog(@"compute size %@", NSStringFromCGSize(CGSizeMake(self.rect.size.width-self.margin_left-self.margin_right, MAXFLOAT)) );
|
|
|
|
|
+ // NSLog(@"tmpSize %@", NSStringFromCGSize(tmpSize) );
|
|
|
|
|
+ // NSLog(@"p_rect %@", NSStringFromCGRect(p_rect) );
|
|
|
|
|
+ // NSLog(@"self.rect %@", NSStringFromCGRect(self.rect) );
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -703,18 +766,18 @@
|
|
|
// [self.text drawInRect:pdfrect withAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:40],NSForegroundColorAttributeName : [UIColor redColor]}];
|
|
// [self.text drawInRect:pdfrect withAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:40],NSForegroundColorAttributeName : [UIColor redColor]}];
|
|
|
|
|
|
|
|
// layout master
|
|
// layout master
|
|
|
- CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)string);
|
|
|
|
|
|
|
+ CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)string);
|
|
|
//计算文本绘制size ,这里300是文字宽度,你可以自己更改为247,但是要记得,在height 方法里的这个位置,也改为247
|
|
//计算文本绘制size ,这里300是文字宽度,你可以自己更改为247,但是要记得,在height 方法里的这个位置,也改为247
|
|
|
CGSize tmpSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0,0), NULL, CGSizeMake(self.rect.size.width-self.margin_left-self.margin_right, MAXFLOAT), NULL);
|
|
CGSize tmpSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0,0), NULL, CGSizeMake(self.rect.size.width-self.margin_left-self.margin_right, MAXFLOAT), NULL);
|
|
|
//创建textBoxSize以设置view的frame
|
|
//创建textBoxSize以设置view的frame
|
|
|
- CGSize textBoxSize = CGSizeMake((int)tmpSize.width + 1, (int)tmpSize.height + 1);
|
|
|
|
|
|
|
+// CGSize textBoxSize = CGSizeMake((int)tmpSize.width + 1, (int)tmpSize.height + 1);
|
|
|
// DebugLog(@"textBoxSize0 == %f,%f,%f",textBoxSize.width,textBoxSize.height,textBoxSize.width / textBoxSize.height);
|
|
// DebugLog(@"textBoxSize0 == %f,%f,%f",textBoxSize.width,textBoxSize.height,textBoxSize.width / textBoxSize.height);
|
|
|
// self.frame = CGRectMake(0, 0, textBoxSize.width , textBoxSize.height);
|
|
// self.frame = CGRectMake(0, 0, textBoxSize.width , textBoxSize.height);
|
|
|
// [string release];
|
|
// [string release];
|
|
|
|
|
|
|
|
//- (void)drawRect:(CGRect)rect;代码
|
|
//- (void)drawRect:(CGRect)rect;代码
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
CGMutablePathRef leftColumnPath = CGPathCreateMutable();
|
|
CGMutablePathRef leftColumnPath = CGPathCreateMutable();
|
|
@@ -738,9 +801,39 @@
|
|
|
|
|
|
|
|
CGRect expand_rect=rect;
|
|
CGRect expand_rect=rect;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if([self.text isEqualToString:DEBUG_STRING_VALUE1])
|
|
|
|
|
+ {
|
|
|
|
|
+ bool debug=true;
|
|
|
|
|
+ NSLog(@"textdrawable text:%@",self.text);
|
|
|
|
|
+ NSLog(@"tmpSize %@", NSStringFromCGSize(tmpSize) );
|
|
|
|
|
+ NSLog(@"p_rect %@", NSStringFromCGRect(p_rect) );
|
|
|
|
|
+ NSLog(@"self.rect %@", NSStringFromCGRect(self.rect) );
|
|
|
|
|
+
|
|
|
|
|
+ NSLog(@"expand %@", expand?@"true":@"false" );
|
|
|
|
|
+ NSLog(@"height %f", height );
|
|
|
|
|
+ NSLog(@"expand_rect %@", NSStringFromCGRect(expand_rect) );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// CGRect rect=[RAUtils rectAlign:parentrect rect:scalerect hAlign:self.hAlign vAlign:self.vAlign];
|
|
// CGRect rect=[RAUtils rectAlign:parentrect rect:scalerect hAlign:self.hAlign vAlign:self.vAlign];
|
|
|
rect=[TextUtils rectVAlign:parentrect rect:rect vAlign:self.vAlign];
|
|
rect=[TextUtils rectVAlign:parentrect rect:rect vAlign:self.vAlign];
|
|
|
|
|
|
|
|
|
|
+ if([self.text isEqualToString:DEBUG_STRING_VALUE1])
|
|
|
|
|
+ {
|
|
|
|
|
+ bool debug=true;
|
|
|
|
|
+ NSLog(@"textdrawable text:%@",self.text);
|
|
|
|
|
+ NSLog(@"tmpSize %@", NSStringFromCGSize(tmpSize) );
|
|
|
|
|
+ NSLog(@"p_rect %@", NSStringFromCGRect(p_rect) );
|
|
|
|
|
+ NSLog(@"self.rect %@", NSStringFromCGRect(self.rect) );
|
|
|
|
|
+
|
|
|
|
|
+ NSLog(@"expand %@", expand?@"true":@"false" );
|
|
|
|
|
+ NSLog(@"height %f", height );
|
|
|
|
|
+ NSLog(@"expand_rect %@", NSStringFromCGRect(expand_rect) );
|
|
|
|
|
+
|
|
|
|
|
+ NSLog(@"rect %@", NSStringFromCGRect(rect) );
|
|
|
|
|
+ NSLog(@"vAlign %@", self.vAlign );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// CGRect pdfrect = [self to_pdf_rect:p_rect pos:self.rect contextHeight:flip_height];
|
|
// CGRect pdfrect = [self to_pdf_rect:p_rect pos:self.rect contextHeight:flip_height];
|
|
|
|
|
|
|
|
rect= [self parent_to_pdf_rect:rect contextHeight:flip_height];
|
|
rect= [self parent_to_pdf_rect:rect contextHeight:flip_height];
|