|
@@ -17,7 +17,7 @@
|
|
|
|
|
|
|
|
[super setDrawableTemplate:drawableTemplate];
|
|
[super setDrawableTemplate:drawableTemplate];
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
NSString* align= drawableTemplate[@"textAlignment"];
|
|
NSString* align= drawableTemplate[@"textAlignment"];
|
|
|
if(align.length==0 || [align.lowercaseString isEqualToString:@"left"])
|
|
if(align.length==0 || [align.lowercaseString isEqualToString:@"left"])
|
|
@@ -46,23 +46,23 @@
|
|
|
unsigned long color = strtoul([colorvalue UTF8String],0,16);
|
|
unsigned long color = strtoul([colorvalue UTF8String],0,16);
|
|
|
self.textColor= UIColorFromRGB(color);
|
|
self.textColor= UIColorFromRGB(color);
|
|
|
}
|
|
}
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- self.textColor= [UIColor blackColor];
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ self.textColor= [UIColor blackColor];
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
-// kCTTextAlignmentJustified CT_ENUM_AVAILABLE(10_8, 6_0) = 3,
|
|
|
|
|
-// kCTTextAlignmentNatural CT_ENUM_AVAILABLE(10_8, 6_0) = 4,
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // kCTTextAlignmentJustified CT_ENUM_AVAILABLE(10_8, 6_0) = 3,
|
|
|
|
|
+ // kCTTextAlignmentNatural CT_ENUM_AVAILABLE(10_8, 6_0) = 4,
|
|
|
|
|
+
|
|
|
|
|
|
|
|
-// _drawableTemplate = drawableTemplate;
|
|
|
|
|
-// self.margin_left=[self.drawableTemplate[@"margin_left"] doubleValue];
|
|
|
|
|
-// self.margin_right=[self.drawableTemplate[@"margin_right"] doubleValue];
|
|
|
|
|
-// self.margin_top=[self.drawableTemplate[@"margin_top"] doubleValue];
|
|
|
|
|
-// self.margin_bottom=[self.drawableTemplate[@"margin_bottom"] doubleValue];
|
|
|
|
|
-// self.rect = CGRectMake(0, 0, [self.drawableTemplate[@"width"] doubleValue], [self.drawableTemplate[@"height"] doubleValue]);
|
|
|
|
|
|
|
+ // _drawableTemplate = drawableTemplate;
|
|
|
|
|
+ // self.margin_left=[self.drawableTemplate[@"margin_left"] doubleValue];
|
|
|
|
|
+ // self.margin_right=[self.drawableTemplate[@"margin_right"] doubleValue];
|
|
|
|
|
+ // self.margin_top=[self.drawableTemplate[@"margin_top"] doubleValue];
|
|
|
|
|
+ // self.margin_bottom=[self.drawableTemplate[@"margin_bottom"] doubleValue];
|
|
|
|
|
+ // self.rect = CGRectMake(0, 0, [self.drawableTemplate[@"width"] doubleValue], [self.drawableTemplate[@"height"] doubleValue]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -75,10 +75,10 @@
|
|
|
-(CTFontRef)CreateFont:(NSString*)name size:(double)size bold:(bool)bold
|
|
-(CTFontRef)CreateFont:(NSString*)name size:(double)size bold:(bool)bold
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
- if(name==nil)
|
|
|
|
|
|
|
+ if(name.length==0)
|
|
|
{
|
|
{
|
|
|
name=@"Helvetica";
|
|
name=@"Helvetica";
|
|
|
-// name=@"DejaVu Sans";
|
|
|
|
|
|
|
+ // name=@"DejaVu Sans";
|
|
|
}
|
|
}
|
|
|
if(size==0)
|
|
if(size==0)
|
|
|
{
|
|
{
|
|
@@ -98,23 +98,26 @@
|
|
|
(NSString *)kCTFontSizeAttribute,
|
|
(NSString *)kCTFontSizeAttribute,
|
|
|
nil];
|
|
nil];
|
|
|
// Create a descriptor.
|
|
// Create a descriptor.
|
|
|
|
|
+ CFDictionaryRef cffontAttributes =(__bridge CFDictionaryRef)fontAttributes;
|
|
|
CTFontDescriptorRef descriptor =
|
|
CTFontDescriptorRef descriptor =
|
|
|
- CTFontDescriptorCreateWithAttributes((CFDictionaryRef)fontAttributes);
|
|
|
|
|
|
|
+ CTFontDescriptorCreateWithAttributes(cffontAttributes);
|
|
|
|
|
+
|
|
|
|
|
+ // CFBridgingRelease(cffontAttributes);
|
|
|
|
|
|
|
|
// Create a font using the descriptor.
|
|
// Create a font using the descriptor.
|
|
|
CTFontRef font = CTFontCreateWithFontDescriptor(descriptor, 0.0, NULL);
|
|
CTFontRef font = CTFontCreateWithFontDescriptor(descriptor, 0.0, NULL);
|
|
|
- CFRelease(descriptor);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ CFBridgingRelease(descriptor);
|
|
|
|
|
+
|
|
|
return font;
|
|
return font;
|
|
|
-
|
|
|
|
|
-// if(bold)
|
|
|
|
|
-// {
|
|
|
|
|
-// CTFontRef font=CTFontCreateWithName((__bridge CFStringRef)name, size, NULL);
|
|
|
|
|
-// CTFontRef font_bold =CTFontCreateCopyWithSymbolicTraits(font, 0.0, NULL, kCTFontBoldTrait, kCTFontBoldTrait);
|
|
|
|
|
-// CFBridgingRelease(font);
|
|
|
|
|
-// return font_bold;
|
|
|
|
|
-// }
|
|
|
|
|
-// return CTFontCreateWithName((__bridge CFStringRef)name, size, NULL);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // if(bold)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // CTFontRef font=CTFontCreateWithName((__bridge CFStringRef)name, size, NULL);
|
|
|
|
|
+ // CTFontRef font_bold =CTFontCreateCopyWithSymbolicTraits(font, 0.0, NULL, kCTFontBoldTrait, kCTFontBoldTrait);
|
|
|
|
|
+ // CFBridgingRelease(font);
|
|
|
|
|
+ // return font_bold;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // return CTFontCreateWithName((__bridge CFStringRef)name, size, NULL);
|
|
|
}
|
|
}
|
|
|
//-(NSString*) QueryFontName:(NSString*)font
|
|
//-(NSString*) QueryFontName:(NSString*)font
|
|
|
//{
|
|
//{
|
|
@@ -130,21 +133,21 @@
|
|
|
//}
|
|
//}
|
|
|
-(NSMutableAttributedString*) richtext2attributedstring:(NSMutableAttributedString*)string font:(NSString*)font size:(double)size bold:(bool)bold
|
|
-(NSMutableAttributedString*) richtext2attributedstring:(NSMutableAttributedString*)string font:(NSString*)font size:(double)size bold:(bool)bold
|
|
|
{
|
|
{
|
|
|
-// UILabel* uilabel=[[UILabel alloc]init];
|
|
|
|
|
-// uilabel.font=[UIFont fontWithName:font size:size];
|
|
|
|
|
-// NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[self.text dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
|
|
|
|
|
-// uilabel.attributedText = attrStr;
|
|
|
|
|
-// NSLog(@"%@", attrStr);
|
|
|
|
|
-// NSLog(@"%@", uilabel.attributedText);
|
|
|
|
|
|
|
+ // UILabel* uilabel=[[UILabel alloc]init];
|
|
|
|
|
+ // uilabel.font=[UIFont fontWithName:font size:size];
|
|
|
|
|
+ // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[self.text dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
|
|
|
|
|
+ // uilabel.attributedText = attrStr;
|
|
|
|
|
+ // NSLog(@"%@", attrStr);
|
|
|
|
|
+ // NSLog(@"%@", 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
|
|
|
|
|
|
|
|
- CTFontRef ctfont_bold = [self CreateFont:font size:size bold:true];//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)
|
|
|
|
|
- range:NSMakeRange(0, [string length])];
|
|
|
|
|
|
|
+ [string addAttribute:(id)kCTFontAttributeName
|
|
|
|
|
+ value:CFBridgingRelease(ctfont)
|
|
|
|
|
+ range:NSMakeRange(0, [string length])];
|
|
|
|
|
|
|
|
//颜色,此处为黑色,你可以自己改颜色,[UIColor redColor]
|
|
//颜色,此处为黑色,你可以自己改颜色,[UIColor redColor]
|
|
|
[string addAttribute:(id)kCTForegroundColorAttributeName
|
|
[string addAttribute:(id)kCTForegroundColorAttributeName
|
|
@@ -154,17 +157,18 @@
|
|
|
|
|
|
|
|
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=[RAUtils expression_varable:content regex:pattern];
|
|
|
|
|
-// if (matches) {
|
|
|
|
|
-// for (NSTextCheckingResult *match in matches) {
|
|
|
|
|
-// for (int i = 0; i < match.numberOfRanges; ++i) {
|
|
|
|
|
-// NSLog(@"%d-> %@",i, [content substringWithRange:[match rangeAtIndex:i]]);
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ // NSArray* matches=[RAUtils expression_varable:content regex:pattern];
|
|
|
|
|
+ // if (matches) {
|
|
|
|
|
+ // for (NSTextCheckingResult *match in matches) {
|
|
|
|
|
+ // for (int i = 0; i < match.numberOfRanges; ++i) {
|
|
|
|
|
+ // NSLog(@"%d-> %@",i, [content substringWithRange:[match rangeAtIndex:i]]);
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
NSTextCheckingResult * match=[RAUtils expression_findfistMatch:string.string regex:pattern];
|
|
NSTextCheckingResult * match=[RAUtils expression_findfistMatch:string.string regex:pattern];
|
|
|
|
|
|
|
|
while(match)
|
|
while(match)
|
|
@@ -180,10 +184,10 @@
|
|
|
[string addAttribute:(id)kCTFontAttributeName
|
|
[string addAttribute:(id)kCTFontAttributeName
|
|
|
value:(__bridge id _Nonnull)(ctfont_bold)
|
|
value:(__bridge id _Nonnull)(ctfont_bold)
|
|
|
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:@""];
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
NSLog(@"string after replace: %@",string.string);
|
|
NSLog(@"string after replace: %@",string.string);
|
|
|
//newstring=[newstring stringByReplacingOccurrencesOfString:[content substringWithRange:[match rangeAtIndex:i]] withString:[content substringWithRange:[match rangeAtIndex:i+1]]];
|
|
//newstring=[newstring stringByReplacingOccurrencesOfString:[content substringWithRange:[match rangeAtIndex:i]] withString:[content substringWithRange:[match rangeAtIndex:i+1]]];
|
|
|
match=[RAUtils expression_findfistMatch:string.string regex:pattern];
|
|
match=[RAUtils expression_findfistMatch:string.string regex:pattern];
|
|
@@ -224,14 +228,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
NSString * source=self.drawableTemplate[@"source_type"];
|
|
NSString * source=self.drawableTemplate[@"source_type"];
|
|
|
if(source==nil)
|
|
if(source==nil)
|
|
|
source=@"const";
|
|
source=@"const";
|
|
|
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>"];
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
else if([source isEqualToString:@"data"])
|
|
else if([source isEqualToString:@"data"])
|
|
@@ -241,13 +244,13 @@
|
|
|
NSString *content = data[self.drawableTemplate[@"source"]];
|
|
NSString *content = data[self.drawableTemplate[@"source"]];
|
|
|
NSString *pattern = @"\\$\\.\\{([\\s\\S]*?)\\}\\.\\$";
|
|
NSString *pattern = @"\\$\\.\\{([\\s\\S]*?)\\}\\.\\$";
|
|
|
NSArray* matches=[RAUtils expression_varable:content regex:pattern];
|
|
NSArray* matches=[RAUtils expression_varable:content regex:pattern];
|
|
|
-// if (matches) {
|
|
|
|
|
-// for (NSTextCheckingResult *match in matches) {
|
|
|
|
|
-// for (int i = 0; i < match.numberOfRanges; ++i) {
|
|
|
|
|
-// NSLog(@"%d-> %@",i, [content substringWithRange:[match rangeAtIndex:i]]);
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ // if (matches) {
|
|
|
|
|
+ // for (NSTextCheckingResult *match in matches) {
|
|
|
|
|
+ // for (int i = 0; i < match.numberOfRanges; ++i) {
|
|
|
|
|
+ // NSLog(@"%d-> %@",i, [content substringWithRange:[match rangeAtIndex:i]]);
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
if (matches)
|
|
if (matches)
|
|
|
{
|
|
{
|
|
|
self.text=content;
|
|
self.text=content;
|
|
@@ -260,14 +263,14 @@
|
|
|
|
|
|
|
|
self.text=[self.text stringByReplacingOccurrencesOfString:[content substringWithRange:[match rangeAtIndex:i]] withString:[NSString stringWithFormat:@"%@",data[[content substringWithRange:[match rangeAtIndex:i+1]]]]];
|
|
self.text=[self.text stringByReplacingOccurrencesOfString:[content substringWithRange:[match rangeAtIndex:i]] withString:[NSString stringWithFormat:@"%@",data[[content substringWithRange:[match rangeAtIndex:i+1]]]]];
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
//self.text=content;
|
|
//self.text=content;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- self.text=data[self.drawableTemplate[@"source"]];
|
|
|
|
|
|
|
+ self.text=data[self.drawableTemplate[@"source"]];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -275,6 +278,9 @@
|
|
|
self.text=@"";
|
|
self.text=@"";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
if([self.text isEqualToString:@"www.newpacificdirect.com"])
|
|
if([self.text isEqualToString:@"www.newpacificdirect.com"])
|
|
|
{
|
|
{
|
|
|
int debug=0;
|
|
int debug=0;
|
|
@@ -285,39 +291,39 @@
|
|
|
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:<#(double)#>
|
|
|
|
|
- CGFloat fontsize = [self.drawableTemplate[@"size"] doubleValue];
|
|
|
|
|
|
|
+ // [super flipContext:context ContextHeight:flip_height];
|
|
|
|
|
+ // super flipContext:context ContextHeight:<#(double)#>
|
|
|
|
|
+ CGFloat fontsize = [self.drawableTemplate[@"size"] doubleValue];
|
|
|
|
|
|
|
|
//NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[title dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
|
|
//NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[title dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
|
|
|
//创建AttributeStringfdsa
|
|
//创建AttributeStringfdsa
|
|
|
|
|
|
|
|
NSMutableAttributedString *string = nil;
|
|
NSMutableAttributedString *string = nil;
|
|
|
-// if([self.drawableTemplate[@"ishtml"] boolValue])
|
|
|
|
|
-// {
|
|
|
|
|
-// string=[[[NSAttributedString alloc] initWithData:[self.text dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil] mutableCopy];
|
|
|
|
|
-//
|
|
|
|
|
-// }
|
|
|
|
|
-// else
|
|
|
|
|
|
|
+ // if([self.drawableTemplate[@"ishtml"] boolValue])
|
|
|
|
|
+ // {
|
|
|
|
|
+ // string=[[[NSAttributedString alloc] initWithData:[self.text dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil] mutableCopy];
|
|
|
|
|
+ //
|
|
|
|
|
+ // }
|
|
|
|
|
+ // else
|
|
|
{
|
|
{
|
|
|
string=[[NSMutableAttributedString alloc] initWithString:self.text];
|
|
string=[[NSMutableAttributedString alloc] initWithString:self.text];
|
|
|
//创建字体以及字体大小
|
|
//创建字体以及字体大小
|
|
|
-// CTFontRef ctfont = [self CreateFont:font size:fontsize bold:bold];//CTFontCreateWithName(CFSTR("Helvetica"), fontsize, NULL);
|
|
|
|
|
-// // CTFontRef helveticaBold = CTFontCreateWithName(CFSTR("Helvetica"), fontsize, NULL);
|
|
|
|
|
-// //字体,把helvetica 样式加到整个,string上
|
|
|
|
|
-// [string addAttribute:(id)kCTFontAttributeName
|
|
|
|
|
-// value:CFBridgingRelease(ctfont)
|
|
|
|
|
-// range:NSMakeRange(0, [string length])];
|
|
|
|
|
-//
|
|
|
|
|
-// //字体样式 ,把helveticaBold 样式加到整个,string上
|
|
|
|
|
-// // [string addAttribute:(id)kCTFontAttributeName
|
|
|
|
|
-// // value:CFBridgingRelease(helveticaBold)
|
|
|
|
|
-// // range:NSMakeRange(0, [string length])];
|
|
|
|
|
-//
|
|
|
|
|
-// //颜色,此处为黑色,你可以自己改颜色,[UIColor redColor]
|
|
|
|
|
-// [string addAttribute:(id)kCTForegroundColorAttributeName
|
|
|
|
|
-// value:(id)self.textColor.CGColor
|
|
|
|
|
-// range:NSMakeRange(0, [string length])];
|
|
|
|
|
|
|
+ // CTFontRef ctfont = [self CreateFont:font size:fontsize bold:bold];//CTFontCreateWithName(CFSTR("Helvetica"), fontsize, NULL);
|
|
|
|
|
+ // // CTFontRef helveticaBold = CTFontCreateWithName(CFSTR("Helvetica"), fontsize, NULL);
|
|
|
|
|
+ // //字体,把helvetica 样式加到整个,string上
|
|
|
|
|
+ // [string addAttribute:(id)kCTFontAttributeName
|
|
|
|
|
+ // value:CFBridgingRelease(ctfont)
|
|
|
|
|
+ // range:NSMakeRange(0, [string length])];
|
|
|
|
|
+ //
|
|
|
|
|
+ // //字体样式 ,把helveticaBold 样式加到整个,string上
|
|
|
|
|
+ // // [string addAttribute:(id)kCTFontAttributeName
|
|
|
|
|
+ // // value:CFBridgingRelease(helveticaBold)
|
|
|
|
|
+ // // range:NSMakeRange(0, [string length])];
|
|
|
|
|
+ //
|
|
|
|
|
+ // //颜色,此处为黑色,你可以自己改颜色,[UIColor redColor]
|
|
|
|
|
+ // [string addAttribute:(id)kCTForegroundColorAttributeName
|
|
|
|
|
+ // value:(id)self.textColor.CGColor
|
|
|
|
|
+ // 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];
|
|
|
|
|
|
|
@@ -326,7 +332,7 @@
|
|
|
long number = self.characterSpace;
|
|
long number = self.characterSpace;
|
|
|
CFNumberRef num = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt8Type, &number);
|
|
CFNumberRef num = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt8Type, &number);
|
|
|
[string addAttribute:(id)kCTKernAttributeName value:CFBridgingRelease(num) range:NSMakeRange(0, [string length])];
|
|
[string addAttribute:(id)kCTKernAttributeName value:CFBridgingRelease(num) range:NSMakeRange(0, [string length])];
|
|
|
- CFRelease(num);
|
|
|
|
|
|
|
+ //CFRelease(num);
|
|
|
|
|
|
|
|
|
|
|
|
|
//创建文本对齐方式
|
|
//创建文本对齐方式
|
|
@@ -371,17 +377,19 @@
|
|
|
|
|
|
|
|
//给字符串添加样式attribute
|
|
//给字符串添加样式attribute
|
|
|
[string addAttribute:(id)kCTParagraphStyleAttributeName
|
|
[string addAttribute:(id)kCTParagraphStyleAttributeName
|
|
|
- value:(id)paragraphStyle1
|
|
|
|
|
|
|
+ value:CFBridgingRelease(paragraphStyle1)
|
|
|
range:NSMakeRange(0, [string length])];
|
|
range:NSMakeRange(0, [string length])];
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // CGRect pdfrect=[self to_parent_rect:p_rect pos:self.rect offsetX:0 offsetY:0];
|
|
|
|
|
- // [string drawInRect:pdfrect];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- // [self.text drawInRect:pdfrect withAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:40],NSForegroundColorAttributeName : [UIColor redColor]}];
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // CGRect pdfrect=[self to_parent_rect:p_rect pos:self.rect offsetX:0 offsetY:0];
|
|
|
|
|
+ // [string drawInRect:pdfrect];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // [self.text drawInRect:pdfrect withAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:40],NSForegroundColorAttributeName : [UIColor redColor]}];
|
|
|
|
|
+
|
|
|
// layout master
|
|
// layout master
|
|
|
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)string);
|
|
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)string);
|
|
|
//计算文本绘制size ,这里300是文字宽度,你可以自己更改为247,但是要记得,在height 方法里的这个位置,也改为247
|
|
//计算文本绘制size ,这里300是文字宽度,你可以自己更改为247,但是要记得,在height 方法里的这个位置,也改为247
|
|
@@ -389,8 +397,8 @@
|
|
|
//创建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);
|
|
|
// NSLog(@"textBoxSize0 == %f,%f,%f",textBoxSize.width,textBoxSize.height,textBoxSize.width / textBoxSize.height);
|
|
// NSLog(@"textBoxSize0 == %f,%f,%f",textBoxSize.width,textBoxSize.height,textBoxSize.width / textBoxSize.height);
|
|
|
- // self.frame = CGRectMake(0, 0, textBoxSize.width , textBoxSize.height);
|
|
|
|
|
-// [string release];
|
|
|
|
|
|
|
+ // self.frame = CGRectMake(0, 0, textBoxSize.width , textBoxSize.height);
|
|
|
|
|
+ // [string release];
|
|
|
|
|
|
|
|
//- (void)drawRect:(CGRect)rect;代码
|
|
//- (void)drawRect:(CGRect)rect;代码
|
|
|
|
|
|
|
@@ -413,10 +421,10 @@
|
|
|
// 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=[RAUtils rectVAlign:parentrect rect:rect vAlign:self.vAlign];
|
|
rect=[RAUtils rectVAlign:parentrect rect:rect 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];
|
|
|
- // pdfrect=CGRectMake(pdfrect.origin.x, flip_height-pdfrect.origin.y, pdfrect.size.width, pdfrect.size.height);
|
|
|
|
|
|
|
+ // pdfrect=CGRectMake(pdfrect.origin.x, flip_height-pdfrect.origin.y, pdfrect.size.width, pdfrect.size.height);
|
|
|
CGPathAddRect(leftColumnPath, NULL,
|
|
CGPathAddRect(leftColumnPath, NULL,
|
|
|
rect);
|
|
rect);
|
|
|
|
|
|
|
@@ -426,32 +434,36 @@
|
|
|
|
|
|
|
|
// NSLog(@"textBoxSize1 == %f,%f",self.frame.size.width,self.frame.size.height);
|
|
// NSLog(@"textBoxSize1 == %f,%f",self.frame.size.width,self.frame.size.height);
|
|
|
// flip the coordinate system
|
|
// flip the coordinate system
|
|
|
-// CGContextRef context = UIGraphicsGetCurrentContext();
|
|
|
|
|
|
|
+ // CGContextRef context = UIGraphicsGetCurrentContext();
|
|
|
|
|
|
|
|
|
|
|
|
|
-// CGContextClearRect(context, self.rect);
|
|
|
|
|
-// CGContextSetFillColorWithColor(context, [[UIColor whiteColor]CGColor]);
|
|
|
|
|
-// CGContextFillRect(context, CGRectMake(0, 0, self.rect.size.width, self.rect.size.height));
|
|
|
|
|
|
|
+ // CGContextClearRect(context, self.rect);
|
|
|
|
|
+ // CGContextSetFillColorWithColor(context, [[UIColor whiteColor]CGColor]);
|
|
|
|
|
+ // CGContextFillRect(context, CGRectMake(0, 0, self.rect.size.width, self.rect.size.height));
|
|
|
|
|
|
|
|
|
|
|
|
|
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
|
|
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
|
|
|
- // CGContextTranslateCTM(context, 0, self.rect.size.height);
|
|
|
|
|
- // CGContextScaleCTM(context, 1.0, -1.0);
|
|
|
|
|
|
|
+ // CGContextTranslateCTM(context, 0, self.rect.size.height);
|
|
|
|
|
+ // CGContextScaleCTM(context, 1.0, -1.0);
|
|
|
|
|
|
|
|
// draw
|
|
// draw
|
|
|
CTFrameDraw(leftFrame, context);
|
|
CTFrameDraw(leftFrame, context);
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ CFRelease(leftFrame);
|
|
|
// cleanup
|
|
// cleanup
|
|
|
|
|
|
|
|
CGPathRelease(leftColumnPath);
|
|
CGPathRelease(leftColumnPath);
|
|
|
CFRelease(framesetter);
|
|
CFRelease(framesetter);
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // return self.rect;
|
|
|
[self DrawBound:context dataSource:data ParentRect:p_rect startX:x startY:y flipHeight:flip_height range:between_header_and_footer];
|
|
[self DrawBound:context dataSource:data ParentRect:p_rect startX:x startY:y flipHeight:flip_height range:between_header_and_footer];
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return parentrect;
|
|
return parentrect;
|
|
|
-// return CGPointMake(parentrect.origin.x+parentrect.size.width, parentrect.origin.y+parentrect.size.height);
|
|
|
|
|
|
|
+ // return CGPointMake(parentrect.origin.x+parentrect.size.width, parentrect.origin.y+parentrect.size.height);
|
|
|
|
|
|
|
|
-// [super restoreFlip:context ContextHeight:flip_height];
|
|
|
|
|
|
|
+ // [super restoreFlip:context ContextHeight:flip_height];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|