Răsfoiți Sursa

20170112

FIXED PDF TEXT CRASH
Ray Zhang 9 ani în urmă
părinte
comite
1d8c94c772

+ 1 - 1
RedAnt ERP Mobile/common/AES/AESCrypt.m

@@ -54,7 +54,7 @@
     NSUInteger dataLength = [data length];
     
     int diff = kCCKeySizeAES128 - (dataLength % kCCKeySizeAES128);
-    int newSize = 0;
+    size_t newSize = 0;
     
     if(diff > 0)
     {

+ 1 - 1
RedAnt ERP Mobile/common/PDFUtils.m

@@ -88,7 +88,7 @@
      */
     
     NSString *default_path = [[NSBundle mainBundle] pathForResource:file ofType:nil];
-    const char *filename=[default_path UTF8String];
+//    const char *filename=[default_path UTF8String];
     
     NSLog(@"%@",default_path);
     

+ 1 - 1
RedAnt ERP Mobile/common/RAUtils.h

@@ -41,7 +41,7 @@
 +(NSDictionary*) device_info;
 +(NSDictionary*) error_dict:(NSError*)error;
 + (NSArray*) allFilesAtPath:(NSString*) dirString;
-+(void) enum_font;
+//+(void) enum_font;
 +(NSDictionary*) dictfromfile:(NSString*) path;
 +(NSArray*) expression_varable:(NSString*)content regex:(NSString*) pattern;
 +(NSTextCheckingResult*) expression_findfistMatch:(NSString*)content regex:(NSString*) pattern;

+ 81 - 81
RedAnt ERP Mobile/common/RAUtils.m

@@ -146,22 +146,22 @@
     }
     return true;
 }
-+(void) enum_font
-{
-    return;
-    NSArray *familys = [UIFont familyNames];
-    
-    for (int i = 0; i < familys.count; i++)
-    {
-        NSString *family = [familys objectAtIndex:i];
-        DebugLog(@"=====Fontfamily:%@", family);
-        NSArray *fonts = [UIFont fontNamesForFamilyName:family];
-        for(int j = 0; j < fonts.count; j++)
-        {
-            DebugLog(@"***FontName:%@", [fonts objectAtIndex:j]);
-        }
-    }
-}
+//+(void) enum_font
+//{
+//    return;
+//    NSArray *familys = [UIFont familyNames];
+//    
+//    for (int i = 0; i < familys.count; i++)
+//    {
+//        NSString *family = [familys objectAtIndex:i];
+//        DebugLog(@"=====Fontfamily:%@", family);
+//        NSArray *fonts = [UIFont fontNamesForFamilyName:family];
+//        for(int j = 0; j < fonts.count; j++)
+//        {
+//            DebugLog(@"***FontName:%@", [fonts objectAtIndex:j]);
+//        }
+//    }
+//}
 
 
 +(NSTextCheckingResult*) expression_findfistMatch:(NSString*)content regex:(NSString*) pattern
@@ -487,71 +487,71 @@
     
     
     return [self alert_view:msg title:title];
-    
-    
-    UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
-    //block代码块取代了delegate
-    
-    
-    //        [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
-    //            textField.text = self.save_name;
-    //
-    //
-    //        }];
-    
-    //    UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-    //
-    //        UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Delete Order"];
-    //        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-    //
-    //            NSDictionary* return_json = [iSalesNetwork delete_Order:orderid];
-    //
-    //            dispatch_async(dispatch_get_main_queue(), ^{
-    //                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-    //
-    //
-    //                if([[return_json valueForKey:@"result"] intValue]==2)
-    //                {
-    //
-    //                    [RAUtils error_alert:nil title:@"Order Delete"] ;
-    //                }
-    //                else
-    //                {
-    //                    [RAUtils error_alert:[return_json valueForKey:@"err_msg"] title:@"Delete Order Failed."] ;
-    //                }
-    //
-    //
-    //
-    //
-    //            });
-    //        });
-    //
-    //
-    //    }];
-    
-    UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
-        //DebugLog(@"Cancel");
-    }];
-    // [alertControl addAction:actionOne];
-    
-    [alertControl addAction:alertthree];
-    
-    
-    UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
-    }];
-    [alertControl addAction:alertcancel];
-    //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-    
-    
-    
-    
-    [vc presentViewController:alertControl animated:YES completion:nil];
-    
-    
-    
-    return;
-    
-    
+//    
+//    
+//    UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
+//    //block代码块取代了delegate
+//    
+//    
+//    //        [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
+//    //            textField.text = self.save_name;
+//    //
+//    //
+//    //        }];
+//    
+//    //    UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
+//    //
+//    //        UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Delete Order"];
+//    //        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//    //
+//    //            NSDictionary* return_json = [iSalesNetwork delete_Order:orderid];
+//    //
+//    //            dispatch_async(dispatch_get_main_queue(), ^{
+//    //                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+//    //
+//    //
+//    //                if([[return_json valueForKey:@"result"] intValue]==2)
+//    //                {
+//    //
+//    //                    [RAUtils error_alert:nil title:@"Order Delete"] ;
+//    //                }
+//    //                else
+//    //                {
+//    //                    [RAUtils error_alert:[return_json valueForKey:@"err_msg"] title:@"Delete Order Failed."] ;
+//    //                }
+//    //
+//    //
+//    //
+//    //
+//    //            });
+//    //        });
+//    //
+//    //
+//    //    }];
+//    
+//    UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
+//        //DebugLog(@"Cancel");
+//    }];
+//    // [alertControl addAction:actionOne];
+//    
+//    [alertControl addAction:alertthree];
+//    
+//    
+//    UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
+//    }];
+//    [alertControl addAction:alertcancel];
+//    //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
+//    
+//    
+//    
+//    
+//    [vc presentViewController:alertControl animated:YES completion:nil];
+//    
+//    
+//    
+//    return;
+//    
+//    
     
     
 }

+ 2 - 2
RedAnt ERP Mobile/common/pdfCreator/PDFPage.m

@@ -69,7 +69,7 @@
         // page 去除页眉,页脚后的区域
         NSRange range = NSMakeRange(self.drawable_rect.origin.y+pageHeader.rect.size.height, self.drawable_rect.origin.y+self.drawable_rect.size.height-pageFooter.rect.size.height);
         
-        CGRect rect = self.rect;
+//        CGRect rect = self.rect;
         
         //       CGContextBeginPage(context, &rect);
         //       [pageHeader Draw:context dataSource:data ParentRect:(CGRect)self.drawable_rect startX:0 startY:0 flipHeight:self.rect.size.height range:range];
@@ -149,7 +149,7 @@
         NSRange range = NSMakeRange(0,self.rect.size.height);
 
     
-        CGRect rect = self.rect;
+//        CGRect rect = self.rect;
     
 
             drawable_obj.delegate = self;

+ 1 - 1
RedAnt ERP Mobile/common/pdfCreator/TableDrawable.m

@@ -47,7 +47,7 @@
 */
     
     
-    CGRect pdfrect =  [self to_parent_rect:p_rect pos:self.rect offsetX:0 offsetY:0];
+//    CGRect pdfrect =  [self to_parent_rect:p_rect pos:self.rect offsetX:0 offsetY:0];
     CGRect parentrect =[self to_parent_rect:p_rect pos:self.rect offsetX:0 offsetY:0];
 /*
     

+ 1 - 1
RedAnt ERP Mobile/common/pdfCreator/TextDrawable.h

@@ -18,7 +18,7 @@
 
 @property (nonatomic,strong) UIColor * textColor;
 
-@property CTTextAlignment textalignment;
+@property NSTextAlignment textalignment;
 
 
 

+ 192 - 99
RedAnt ERP Mobile/common/pdfCreator/TextDrawable.m

@@ -9,6 +9,8 @@
 #import "TextDrawable.h"
 #import <CoreText/CoreText.h>
 #import "TextUtils.h"
+#define DEBUG_STRING_VALUE0 @"DEBUG OFF"
+#define DEBUG_STRING_VALUE1 @"DEBUG OFF"
 
 @implementation TextDrawable
 
@@ -73,19 +75,19 @@
         NSLog(@"setDrawableTemplate text align : %@",align);
     if(align.length==0 || [align.lowercaseString isEqualToString:@"left"])
     {
-        self.textalignment= kCTTextAlignmentLeft;
+        self.textalignment= NSTextAlignmentLeft;
     }
     else if([align.lowercaseString isEqualToString:@"right"])
     {
-        self.textalignment= kCTTextAlignmentRight;
+        self.textalignment= NSTextAlignmentRight;
     }
     else if([align.lowercaseString isEqualToString:@"center"])
     {
-        self.textalignment= kCTTextAlignmentCenter;
+        self.textalignment= NSTextAlignmentCenter;
     }
     else
     {
-        self.textalignment= kCTTextAlignmentLeft;
+        self.textalignment= NSTextAlignmentLeft;
     }
     
     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
 {
-    
+//    return p_rect;
     bool expand=[self.drawableTemplate[@"expand"] boolValue];
     if(!expand)
     {
@@ -194,7 +196,7 @@
         
         
         bool bold = [self.drawableTemplate[@"bold"] boolValue];
-        bool italic = [self.drawableTemplate[@"italic"] boolValue];
+//        bool italic = [self.drawableTemplate[@"italic"] boolValue];
         NSString* font=self.drawableTemplate[@"font"];
         
         //    [super flipContext:context ContextHeight:flip_height];
@@ -234,58 +236,68 @@
             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 = &paragraph;
+//            //设置  段落间距
+//            CGFloat paragraph = self.paragraphSpace;
+//            CTParagraphStyleSetting paragraphStyle;
+//            paragraphStyle.spec = kCTParagraphStyleSpecifierParagraphSpacing;
+//            paragraphStyle.valueSize = sizeof(CGFloat);
+//            paragraphStyle.value = &paragraph;
             
             
             
             
             //创建样式数组
-            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
         CGSize tmpSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0,0), NULL, CGSizeMake(self.rect.size.width-self.margin_left-self.margin_right, MAXFLOAT), NULL);
         //创建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);
         //   self.frame = CGRectMake(0, 0, textBoxSize.width , textBoxSize.height);
         //    [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)
@@ -396,31 +408,44 @@
     {
         size=10;
     }
-    NSString* style = @"Regular";
-    if(bold)
-        style=@"Bold";
+//    NSString* style = @"Regular";
+//    if(bold)
+//        style=@"Bold";
     
     //name=@"Courier";
+
     
     NSDictionary *fontAttributes =
     [NSDictionary dictionaryWithObjectsAndKeys:
-     name, (NSString *)kCTFontFamilyNameAttribute,
-     style, (NSString *)kCTFontStyleNameAttribute,
+     name, UIFontDescriptorFamilyAttribute,
+//     style, UIFontDescriptorTextStyleAttribute,
      [NSNumber numberWithFloat:size],
-     (NSString *)kCTFontSizeAttribute,
+     UIFontDescriptorSizeAttribute,
      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;
+
+    
+//    
+//    // 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)
     //    {
@@ -452,25 +477,30 @@
     //    DebugLog(@"%@", attrStr);
     //    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);
     //    CTFontRef helveticaBold = CTFontCreateWithName(CFSTR("Helvetica"), fontsize, NULL);
     //字体,把helvetica 样式加到整个,string上
-    [string addAttribute:(id)kCTFontAttributeName
-                   value:CFBridgingRelease(ctfont)
+    [string addAttribute:NSFontAttributeName
+                   value:uifont
                    range:NSMakeRange(0, [string length])];
+//    CFRelease(ctfont);
+    
+    
     
     //颜色,此处为黑色,你可以自己改颜色,[UIColor redColor]
-    [string addAttribute:(id)kCTForegroundColorAttributeName
-                   value:(id)self.textColor.CGColor
+    [string addAttribute:NSForegroundColorAttributeName
+                   value:self.textColor
                    range:NSMakeRange(0, [string length])];
     
     
     if(!bold)
     {
-        CTFontRef ctfont_bold = [self CreateFont:font size:size bold:true];
-        NSString* newstring= nil;
+        
+      //  NSString* newstring= nil;
         //   NSString *content =  string.string ;
         NSString *pattern = @"\\<b\\>([\\s\\S]*?)\\<\\/b\\>";
         //        NSArray* matches=[TextUtils expression_varable:content regex:pattern];
@@ -482,7 +512,7 @@
         //            }
         //        }
         NSTextCheckingResult * match=[TextUtils expression_findfistMatch:string.string regex:pattern];
-        
+        UIFont* uifontbold = [self CreateFont:font size:size bold:true];
         while(match)
         {
             //for (int i = 0; i < match.numberOfRanges/2; ++i)
@@ -493,9 +523,13 @@
                 
                 
                 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]];
+               
                 
                 [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:@""];
@@ -528,7 +562,7 @@
         
         
         
-        CFBridgingRelease(ctfont_bold);
+//        CFRelease(ctfont_bold);
     }
     
     
@@ -546,6 +580,8 @@
     if([source isEqualToString:@"const"])
     {
         self.text=self.drawableTemplate[@"text"];
+        
+
         //  self.text=[self.text stringByReplacingOccurrencesOfString:@"\r\n" withString:@"<br>"];
         
     }
@@ -590,7 +626,10 @@
         self.text=@"";
     
     
-    
+    if([self.text isEqualToString:DEBUG_STRING_VALUE0])
+    {
+       self.text =DEBUG_STRING_VALUE1;
+    }
     
     
     //    if([self.text isEqualToString:@"www.newpacificdirect.com"])
@@ -600,7 +639,7 @@
     
     
     bool bold = [self.drawableTemplate[@"bold"] boolValue];
-    bool italic = [self.drawableTemplate[@"italic"] boolValue];
+//    bool italic = [self.drawableTemplate[@"italic"] boolValue];
     NSString* font=self.drawableTemplate[@"font"];
     
     //    [super flipContext:context ContextHeight:flip_height];
@@ -638,7 +677,7 @@
         //                       range:NSMakeRange(0, [string length])];
         
         string = [self richtext2attributedstring:string font:font size:fontsize bold:bold];
-        
+
         
 //        //设置字体间距
 //        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;//间距数据
@@ -661,12 +700,12 @@
 //        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;
 //
 //        
 //        //设置  段落间距
@@ -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]}];
     
     // layout master
-    CTFramesetterRef  framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)string);
+    CTFramesetterRef  framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)string);
     //计算文本绘制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);
     //创建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);
     //   self.frame = CGRectMake(0, 0, textBoxSize.width , textBoxSize.height);
     //    [string release];
     
     //- (void)drawRect:(CGRect)rect;代码
     
-    
+
     
     
     CGMutablePathRef leftColumnPath = CGPathCreateMutable();
@@ -738,9 +801,39 @@
     
     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];
     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];
     
     rect= [self parent_to_pdf_rect:rect contextHeight:flip_height];