Prechádzať zdrojové kódy

161129
fix pdf create bugs

Ray Zhang 9 rokov pred
rodič
commit
aba5466a44

BIN
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/Ray.xcuserdatad/UserInterfaceState.xcuserstate


+ 257 - 17
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/Ray.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -10,11 +10,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/pdfCreator/TextDrawable.m"
-            timestampString = "501753905.380716"
+            timestampString = "502181073.545326"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "457"
-            endingLineNumber = "457"
+            startingLineNumber = "725"
+            endingLineNumber = "725"
             landmarkName = "-Draw:dataSource:ParentRect:startX:startY:flipHeight:range:"
             landmarkType = "7">
          </BreakpointContent>
@@ -153,16 +153,80 @@
             shouldBeEnabled = "No"
             ignoreCount = "0"
             continueAfterRunningActions = "No"
-            filePath = "common/pdfCreator/GroupDrawable.m"
-            timestampString = "502013962.916099"
+            filePath = "common/pdfCreator/TextDrawable.m"
+            timestampString = "502181073.545326"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "26"
-            endingLineNumber = "26"
+            startingLineNumber = "491"
+            endingLineNumber = "491"
             landmarkName = "-Draw:dataSource:ParentRect:startX:startY:flipHeight:range:"
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/pdfCreator/TableDrawable.m"
+            timestampString = "502183311.600647"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "267"
+            endingLineNumber = "267"
+            landmarkName = "-Draw:dataSource:ParentRect:startX:startY:flipHeight:range:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/pdfCreator/LineDrawable.m"
+            timestampString = "502015343.621354"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "41"
+            endingLineNumber = "41"
+            landmarkName = "-Draw:dataSource:ParentRect:startX:startY:flipHeight:range:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/pdfCreator/GroupDrawable.m"
+            timestampString = "502207083.017302"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "77"
+            endingLineNumber = "77"
+            landmarkName = "-Query_Rect:dataSource:ParentRect:startX:startY:flipHeight:range:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/pdfCreator/GroupDrawable.m"
+            timestampString = "502207083.017302"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "79"
+            endingLineNumber = "79"
+            landmarkName = "-Query_Rect:dataSource:ParentRect:startX:startY:flipHeight:range:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent
@@ -170,11 +234,91 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/pdfCreator/TextDrawable.m"
-            timestampString = "502014005.341012"
+            timestampString = "502182111.780792"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "273"
+            endingLineNumber = "273"
+            landmarkName = "-Query_Rect:dataSource:ParentRect:startX:startY:flipHeight:range:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/pdfCreator/GroupDrawable.m"
+            timestampString = "502207083.017302"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "116"
+            endingLineNumber = "116"
+            landmarkName = "-Draw:dataSource:ParentRect:startX:startY:flipHeight:range:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/pdfCreator/GroupDrawable.m"
+            timestampString = "502207083.017302"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "99"
+            endingLineNumber = "99"
+            landmarkName = "-Draw:dataSource:ParentRect:startX:startY:flipHeight:range:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/pdfCreator/GroupDrawable.m"
+            timestampString = "502207083.017302"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "231"
-            endingLineNumber = "231"
+            startingLineNumber = "117"
+            endingLineNumber = "117"
+            landmarkName = "-Draw:dataSource:ParentRect:startX:startY:flipHeight:range:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/pdfCreator/GroupDrawable.m"
+            timestampString = "502183590.957222"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "20"
+            endingLineNumber = "20"
+            landmarkName = "-Query_Rect:dataSource:ParentRect:startX:startY:flipHeight:range:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/pdfCreator/GroupDrawable.m"
+            timestampString = "502207083.017302"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "104"
+            endingLineNumber = "104"
             landmarkName = "-Draw:dataSource:ParentRect:startX:startY:flipHeight:range:"
             landmarkType = "7">
          </BreakpointContent>
@@ -186,11 +330,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/pdfCreator/TableDrawable.m"
-            timestampString = "502015230.728214"
+            timestampString = "502188644.25389"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "268"
-            endingLineNumber = "268"
+            startingLineNumber = "278"
+            endingLineNumber = "278"
             landmarkName = "-Draw:dataSource:ParentRect:startX:startY:flipHeight:range:"
             landmarkType = "7">
          </BreakpointContent>
@@ -201,12 +345,108 @@
             shouldBeEnabled = "No"
             ignoreCount = "0"
             continueAfterRunningActions = "No"
-            filePath = "common/pdfCreator/LineDrawable.m"
-            timestampString = "502015343.621354"
+            filePath = "common/pdfCreator/PDFDrawable.m"
+            timestampString = "502206923.552717"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "41"
-            endingLineNumber = "41"
+            startingLineNumber = "20"
+            endingLineNumber = "20"
+            landmarkName = "-init:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/pdfCreator/PDFDrawable.m"
+            timestampString = "502206923.552717"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "22"
+            endingLineNumber = "22"
+            landmarkName = "-init:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/pdfCreator/GroupDrawable.m"
+            timestampString = "502207083.017302"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "115"
+            endingLineNumber = "115"
+            landmarkName = "-Draw:dataSource:ParentRect:startX:startY:flipHeight:range:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/pdfCreator/TableDrawable.m"
+            timestampString = "502190687.266425"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "242"
+            endingLineNumber = "242"
+            landmarkName = "-Draw:dataSource:ParentRect:startX:startY:flipHeight:range:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/pdfCreator/PDFDrawable.m"
+            timestampString = "502249887.685783"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "31"
+            endingLineNumber = "31"
+            landmarkName = "-setDrawableTemplate:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/pdfCreator/PDFPage.m"
+            timestampString = "502270796.950487"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "146"
+            endingLineNumber = "146"
+            landmarkName = "-Draw:dataSource:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/pdfCreator/TableDrawable.m"
+            timestampString = "502273200.873872"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "290"
+            endingLineNumber = "290"
             landmarkName = "-Draw:dataSource:ParentRect:startX:startY:flipHeight:range:"
             landmarkType = "7">
          </BreakpointContent>

+ 96 - 4
RedAnt ERP Mobile/common/pdfCreator/GroupDrawable.m

@@ -16,9 +16,82 @@
 
 -(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 parentrect = [self to_parent_rect:p_rect pos:self.rect offsetX:0 offsetY:0];
+    
+    bool expand = [self.drawableTemplate[@"expand"] boolValue];
+    if(!expand)
+    {
+    CGRect parentrect = [self to_parent_rect:p_rect pos:self.rect offsetX:0 offsetY:y];
     
     return parentrect;
+    }
+    else
+    {
+        
+        NSMutableDictionary* items = self.drawableTemplate[@"items"];
+        int count = [items[@"count"] intValue];
+
+        
+        //    CGRect pdfrect = /*CGRectMake(self.rect.origin.x+self.margin_left+p_rect.origin.x, self.rect.origin.y+self.margin_top+p_rect.origin.y, self.rect.size.width-self.margin_right, self.rect.size.height-self.margin_bottom);//*/[self to_pdf_rect:p_rect pos:self.rect offsetX:0 offsetY:0];
+        
+        CGRect parentrect =[self to_parent_rect:p_rect pos:self.rect offsetX:x offsetY:y];
+        CGRect pdfrect =  [self to_parent_rect:p_rect pos:self.rect offsetX:x offsetY:y];
+        
+        CGRect expand_rect=parentrect;
+        for(int i=0;i<count;i++)
+        {
+            NSMutableDictionary * item =items[ [NSString stringWithFormat:@"item_%d",i ] ];
+//            if([item[@"height"] floatValue]==-1)
+//                item[@"height"]= [NSNumber numberWithFloat:self.rect.size.height];
+
+            PDFDrawable* drawable_obj=nil;
+            if([item[@"type"] isEqualToString:@"img"])
+            {
+                drawable_obj= [[ImageDrawable alloc] init:item];
+                
+            }
+            else if([item[@"type"] isEqualToString:@"line"])
+            {
+                drawable_obj= [[LineDrawable alloc] init:item];
+                
+            }
+            else if([item[@"type"] isEqualToString:@"text"])
+            {
+                drawable_obj= [[TextDrawable alloc] init:item];
+                
+            }
+            else if([item[@"type"] isEqualToString:@"group"])
+            {
+                drawable_obj= [[GroupDrawable alloc] init:item];
+                
+            }
+            else if([item[@"type"] isEqualToString:@"table"])
+            {
+                drawable_obj= [[TableDrawable alloc] init:item];
+                
+            }
+            drawable_obj.delegate=self.delegate;
+            CGRect item_rect=[drawable_obj Query_Rect:context dataSource:data ParentRect:(CGRect)pdfrect startX:0 startY:0 flipHeight:flip_height range:between_header_and_footer];
+            
+            if(expand)
+            {
+                if(item_rect.origin.y+item_rect.size.height>pdfrect.origin.y+pdfrect.size.height)
+                {
+                    self.rect=CGRectMake(self.rect.origin.x, self.rect.origin.y, self.rect.size.width, item_rect.origin.y+item_rect.size.height-pdfrect.origin.y+self.margin_bottom+self.margin_top);
+                    expand_rect=CGRectMake(parentrect.origin.x, parentrect.origin.y, parentrect.size.width, item_rect.origin.y+item_rect.size.height-pdfrect.origin.y);
+                }
+            }
+        }
+    //    [self DrawBound:context dataSource:data ParentRect:p_rect startX:x startY:y flipHeight:flip_height range:between_header_and_footer];
+        
+        if(expand)
+            return expand_rect;
+        else
+            return parentrect;
+        //    return CGPointMake(parentrect.origin.x+parentrect.size.width, parentrect.origin.y+parentrect.size.height);
+        //    if (self.delegate && [self.delegate respondsToSelector:@selector(outofPage:)]) {
+        //        [self.delegate outofPage:context];
+        //    }
+    }
 }
 -(CGRect) Draw:(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
 {
@@ -26,13 +99,20 @@
     NSMutableDictionary* items = self.drawableTemplate[@"items"];
     int count = [items[@"count"] intValue];
     
+    bool expand = [self.drawableTemplate[@"expand"] boolValue];
+    if(expand)
+       [self Query_Rect:context dataSource:data ParentRect:p_rect startX:x startY:y flipHeight:flip_height range:between_header_and_footer];
 //    CGRect pdfrect = /*CGRectMake(self.rect.origin.x+self.margin_left+p_rect.origin.x, self.rect.origin.y+self.margin_top+p_rect.origin.y, self.rect.size.width-self.margin_right, self.rect.size.height-self.margin_bottom);//*/[self to_pdf_rect:p_rect pos:self.rect offsetX:0 offsetY:0];
     
     CGRect parentrect =[self to_parent_rect:p_rect pos:self.rect offsetX:x offsetY:y];
     CGRect pdfrect =  [self to_parent_rect:p_rect pos:self.rect offsetX:x offsetY:y];
+    
+    CGRect expand_rect=parentrect;
     for(int i=0;i<count;i++)
     {
         NSMutableDictionary * item =items[ [NSString stringWithFormat:@"item_%d",i ] ];
+        if([item[@"height"] floatValue]==-1)
+            item[@"height"]= [NSNumber numberWithFloat:self.rect.size.height];
         PDFDrawable* drawable_obj=nil;
         if([item[@"type"] isEqualToString:@"img"])
         {
@@ -60,11 +140,23 @@
             
         }
         drawable_obj.delegate=self.delegate;
-        [drawable_obj Draw:context dataSource:data ParentRect:(CGRect)pdfrect startX:0 startY:0 flipHeight:flip_height range:between_header_and_footer];
+        CGRect item_rect=[drawable_obj Draw:context dataSource:data ParentRect:(CGRect)pdfrect startX:0 startY:0 flipHeight:flip_height range:between_header_and_footer];
+        
+        if(expand)
+        {
+            if(item_rect.origin.y+item_rect.size.height>pdfrect.origin.y+pdfrect.size.height)
+            {
+                self.rect=CGRectMake(self.rect.origin.x, self.rect.origin.y, self.rect.size.width, item_rect.origin.y+item_rect.size.height-pdfrect.origin.y+self.margin_top+self.margin_bottom);
+                expand_rect=CGRectMake(parentrect.origin.x, parentrect.origin.y, parentrect.size.width, item_rect.origin.y+item_rect.size.height-pdfrect.origin.y);
+            }
+        }
     }
     [self DrawBound:context dataSource:data ParentRect:p_rect startX:x startY:y flipHeight:flip_height range:between_header_and_footer];
-
-    return parentrect;
+    
+    if(expand)
+        return expand_rect;
+    else
+        return parentrect;
 //    return CGPointMake(parentrect.origin.x+parentrect.size.width, parentrect.origin.y+parentrect.size.height);    
 //    if (self.delegate && [self.delegate respondsToSelector:@selector(outofPage:)]) {
 //        [self.delegate outofPage:context];

+ 6 - 2
RedAnt ERP Mobile/common/pdfCreator/PDFDrawable.m

@@ -9,6 +9,7 @@
 #import "PDFDrawable.h"
 #import "LineDrawable.h"
 #import "config.h"
+#import "RAUtils.h"
 
 
 @implementation PDFDrawable
@@ -16,8 +17,11 @@
 {
     
     if (self = [super init]) {
-        [self setDrawableTemplate:drawableTemplate];
-        
+//        NSMutableDictionary* m1=[drawableTemplate mutableCopy];
+//        NSMutableDictionary* m2=[drawableTemplate mutableCopy];
+//        [self setDrawableTemplate:[[RAUtils string2dict:[RAUtils dict2string:drawableTemplate]]  mutableCopy] ];
+        [self setDrawableTemplate:[NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:drawableTemplate]] ];
+
     }
     return self;
     

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

@@ -143,7 +143,7 @@
     // while (true)
     {
         // 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-pageHeader.rect.size.height);
+        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-pageHeader.rect.size.height);
 //        NSRange range = NSMakeRange(self.drawable_rect.origin.y+pageHeader.rect.size.height, self.drawable_rect.size.height-pageFooter.rect.size.height+self.drawable_rect.size.height);
         CGRect rect = self.rect;
         

+ 41 - 6
RedAnt ERP Mobile/common/pdfCreator/TableDrawable.m

@@ -259,8 +259,7 @@
     
     {
         NSMutableDictionary * rowjson =rows[ [NSString stringWithFormat:@"row_%d",i ] ];
-        PDFDrawable* drawable_obj= [[GroupDrawable alloc] init:rowjson];
-        drawable_obj.delegate = self.delegate;
+
         
         
         if(rowjson[@"separator"]!=nil)
@@ -276,7 +275,8 @@
         while(true)
 //        for(int j=0;j<row_data_count;j++)
         {
-            
+            PDFDrawable* drawable_obj= [[GroupDrawable alloc] init:rowjson];
+            drawable_obj.delegate = self.delegate;
             if(i!=count-1&& j==row_data_count)
                 break;
 
@@ -309,10 +309,25 @@
                 return parentrect;
             }
 
-                if(dy+row_rect.size.height> between_header_and_footer.location+between_header_and_footer.length )
+            
+            if([self.drawableTemplate[@"split"] boolValue])
+            {
+                if(/*dy+row_rect.size.height+self.margin_top+self.margin_bottom+self.rect.origin.y*/(row_rect.origin.y+row_rect.size.height> between_header_and_footer.location+between_header_and_footer.length) )
                 {
                     if(j<row_data_count)
                     {
+                        //把表格剩余部分补满
+                        double height = between_header_and_footer.location+between_header_and_footer.length-(row_rect.origin.y);
+                        if(height>0)
+                        {
+                            NSMutableDictionary * fixjson =[NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:rowjson]];
+                            fixjson[@"height"]=[NSNumber numberWithInt:height];
+                            fixjson[@"expand"]=@"false";
+                            PDFDrawable* fix_obj= [[GroupDrawable alloc] init:fixjson];
+                            fix_obj.delegate = self.delegate;
+                            [fix_obj Draw:context dataSource:nil ParentRect:(CGRect)pdfrect startX:0 startY:dy flipHeight:flip_height range:between_header_and_footer];
+                        }
+
                         //越界,新起一页
                         if (self.delegate && [self.delegate respondsToSelector:@selector(outofPage:)]) {
                             [self.delegate outofPage:context];
@@ -328,12 +343,32 @@
                     }
                     else
                     {
+                        //把表格剩余部分补满
+                        double height = between_header_and_footer.location+between_header_and_footer.length-(row_rect.origin.y);
+                        if(height>0)
+                        {
+                            NSMutableDictionary * fixjson =[NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:rowjson]];
+                            fixjson[@"height"]=[NSNumber numberWithInt:height];
+                            fixjson[@"expand"]=@"false";
+                            PDFDrawable* fix_obj= [[GroupDrawable alloc] init:fixjson];
+                            fix_obj.delegate = self.delegate;
+                            [fix_obj Draw:context dataSource:nil ParentRect:(CGRect)pdfrect startX:0 startY:dy flipHeight:flip_height range:between_header_and_footer];
+                        }
+
                         break;
-                    //    goto finish_draw;
+                        //    goto finish_draw;
                     }
                     
-
+                    
                 }
+            }
+            else
+            {
+                if(j>row_data_count)
+                    break;
+            }
+
+            
             
             [drawable_obj Draw:context dataSource:row_data ParentRect:(CGRect)pdfrect startX:0 startY:dy flipHeight:flip_height range:between_header_and_footer];
 //            if([direction isEqualToString:@"H"])

+ 274 - 4
RedAnt ERP Mobile/common/pdfCreator/TextDrawable.m

@@ -68,9 +68,269 @@
 
 -(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
 {
+    
+            bool expand=[self.drawableTemplate[@"expand"] boolValue];
+    if(!expand)
+    {
     CGRect parentrect = [self to_parent_rect:p_rect pos:self.rect offsetX:0 offsetY:0];
     
     return parentrect;
+    }
+    else
+    {
+        
+        
+        
+        
+        NSString * source=self.drawableTemplate[@"source_type"];
+        if(source==nil)
+            source=@"const";
+        if([source isEqualToString:@"const"])
+        {
+            self.text=self.drawableTemplate[@"text"];
+            //  self.text=[self.text stringByReplacingOccurrencesOfString:@"\r\n" withString:@"<br>"];
+            
+        }
+        else if([source isEqualToString:@"data"])
+        {
+            if([self.drawableTemplate[@"source_isexpression"] boolValue])
+            {
+                NSString *content =  data[self.drawableTemplate[@"source"]];
+                NSString *pattern = @"\\$\\.\\{([\\s\\S]*?)\\}\\.\\$";
+                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)
+                {
+                    self.text=content;
+                    for (NSTextCheckingResult *match in matches)
+                    {
+                        
+                        for (int i = 0; i < match.numberOfRanges/2; ++i) {
+                            NSLog(@"%d-> %@",i, [content substringWithRange:[match rangeAtIndex:i]]);
+                            NSLog(@"%d-> %@",i+1, [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;
+                
+            }
+            else
+            {
+                self.text=data[self.drawableTemplate[@"source"]];
+            }
+        }
+        
+        if(self.text==nil)
+            self.text=@"";
+        
+        
+        
+        
+        
+        if([self.text isEqualToString:@"www.newpacificdirect.com"])
+        {
+            int debug=0;
+        }
+        
+        
+        bool bold = [self.drawableTemplate[@"bold"] boolValue];
+        bool italic = [self.drawableTemplate[@"italic"] boolValue];
+        NSString* font=self.drawableTemplate[@"font"];
+        
+        //    [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];
+        //创建AttributeStringfdsa
+        
+        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
+        {
+            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])];
+            
+            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);
+            
+            
+            //创建文本对齐方式
+            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;
+            
+            //设置  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;
+            
+            
+            
+            
+            //创建样式数组
+            CTParagraphStyleSetting settings[]={
+                alignmentStyle,lineSpaceStyle,paragraphStyle,linebreakStyle
+            };
+            
+            //设置样式
+            CTParagraphStyleRef paragraphStyle1 = CTParagraphStyleCreate(settings, sizeof(settings));
+            
+            //给字符串添加样式attribute
+            [string addAttribute:(id)kCTParagraphStyleAttributeName
+                           value:CFBridgingRelease(paragraphStyle1)
+                           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]}];
+        
+        // layout master
+        CTFramesetterRef  framesetter = CTFramesetterCreateWithAttributedString((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);
+        //    NSLog(@"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();
+        
+        CGRect parentrect = [self to_parent_rect:p_rect pos:self.rect offsetX:0 offsetY:0];
+        
+
+        double height =0;
+        if(tmpSize.height<parentrect.size.height)
+            height=tmpSize.height;
+        else
+            if(expand)
+            {
+                height=tmpSize.height;
+                self.rect = CGRectMake(self.rect.origin.x, self.rect.origin.y, self.rect.size.width, height+self.margin_top+self.margin_bottom);
+            }
+            else
+                height=parentrect.size.height;
+        
+        CGRect rect=CGRectMake(parentrect.origin.x, parentrect.origin.y, parentrect.size.width, height);
+        
+        CGRect expand_rect=rect;
+        
+        //    CGRect rect=[RAUtils rectAlign:parentrect rect:scalerect hAlign:self.hAlign 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];
+        //
+        //    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);
+        //    CGPathAddRect(leftColumnPath, NULL,
+        //                  rect);
+        //
+        //    CTFrameRef leftFrame = CTFramesetterCreateFrame(framesetter,
+        //                                                    CFRangeMake(0, 0),
+        //                                                    leftColumnPath, NULL);
+        //
+        //    //    NSLog(@"textBoxSize1  == %f,%f",self.frame.size.width,self.frame.size.height);
+        //    // flip the coordinate system
+        //    //    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));
+        //    
+        //    
+        //    CGContextSetTextMatrix(context, CGAffineTransformIdentity);
+        //    //   CGContextTranslateCTM(context, 0, self.rect.size.height);
+        //    //   CGContextScaleCTM(context, 1.0, -1.0);
+        //    
+        //    // draw
+        //    CTFrameDraw(leftFrame, context);
+        //    
+        //    
+        //    CFRelease(leftFrame);
+        //    // cleanup
+        //    
+        //    CGPathRelease(leftColumnPath);
+        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];
+        if(expand&&expand_rect.size.height>parentrect.size.height)
+            return expand_rect;
+        else
+            return parentrect;
+        //    return CGPointMake(parentrect.origin.x+parentrect.size.width, parentrect.origin.y+parentrect.size.height);
+        
+        //    [super restoreFlip:context ContextHeight:flip_height];
+    }
+    
+    
 }
 -(CTFontRef)CreateFont:(NSString*)name  size:(double)size bold:(bool)bold
 {
@@ -409,15 +669,23 @@
     
     CGRect parentrect = [self to_parent_rect:p_rect pos:self.rect offsetX:0 offsetY:0];
     
-    
+    bool expand=[self.drawableTemplate[@"expand"] boolValue];
     double height =0;
     if(tmpSize.height<parentrect.size.height)
         height=tmpSize.height;
     else
-        height=parentrect.size.height;
+        if(expand)
+        {
+            height=tmpSize.height;
+            self.rect = CGRectMake(self.rect.origin.x, self.rect.origin.y, self.rect.size.width, height+self.margin_top+self.margin_bottom);
+        }
+        else
+            height=parentrect.size.height;
     
     CGRect rect=CGRectMake(parentrect.origin.x, parentrect.origin.y, parentrect.size.width, height);
     
+    CGRect expand_rect=rect;
+    
     //    CGRect rect=[RAUtils rectAlign:parentrect rect:scalerect hAlign:self.hAlign vAlign:self.vAlign];
     rect=[RAUtils rectVAlign:parentrect rect:rect vAlign:self.vAlign];
     
@@ -459,8 +727,10 @@
     
     //    return self.rect;
     [self DrawBound:context dataSource:data ParentRect:p_rect startX:x startY:y flipHeight:flip_height range:between_header_and_footer];
-    
-    return parentrect;
+    if(expand&&expand_rect.size.height>parentrect.size.height)
+        return expand_rect;
+    else
+        return parentrect;
     //    return CGPointMake(parentrect.origin.x+parentrect.size.width, parentrect.origin.y+parentrect.size.height);
     
     //    [super restoreFlip:context ContextHeight:flip_height];

+ 13 - 10
RedAnt ERP Mobile/iSales-NPD/so.json

@@ -931,6 +931,7 @@
                     "data_source": "table_model",
                     "x": 0,
                     "y": 5,
+                    "split":true,
                     "width": 571,
                     "height": 297,
                     "header_repeat": true,
@@ -1109,6 +1110,7 @@
                             "y": 0,
                             "width": 571,
                             "height": 21,
+                            "expand":true,
                             "items": {
                                 "count": 7,
                                 "item_0": {
@@ -1131,7 +1133,7 @@
                                     "x": 0,
                                     "y": 0,
                                     "width": 30,
-                                    "height": 21
+                                    "height": -1
                                 },
                                 "item_1": {
                                     "type": "text",
@@ -1153,7 +1155,7 @@
                                     "x": 30,
                                     "y": 0,
                                     "width": 70,
-                                    "height": 21
+                                    "height": -1
                                 },
                                 "item_2": {
                                     "type": "text",
@@ -1162,15 +1164,16 @@
                                     "source_isexpression": false,
                                     "margin_left":2,
                                     "margin_top":2,
-                                    "draw_bound": true,
+                                    "expand":true,
+                                    "draw_bound": false,
                                     "line_width": [
                                                    0,
-                                                   1,
+                                                   0,
                                                    0,
                                                    0
                                                    ],
                                     "textAlignment": "left",
-                                    "size": "8",
+                                    "size": "10",
                                     "vAlign": "top",
                                     "x": 100,
                                     "y": 0,
@@ -1188,7 +1191,7 @@
                                                    0,
                                                    1,
                                                    0,
-                                                   0
+                                                   1
                                                    ],
                                     "source_isexpression": false,
                                     "textAlignment": "CENTER",
@@ -1197,7 +1200,7 @@
                                     "x": 287,
                                     "y": 0,
                                     "width": 40,
-                                    "height": 21
+                                    "height": -1
                                 },
                                 "item_4": {
                                     "type": "text",
@@ -1219,7 +1222,7 @@
                                     "x": 327,
                                     "y": 0,
                                     "width": 84,
-                                    "height": 21
+                                    "height": -1
                                 },
                                 "item_5": {
                                     "type": "text",
@@ -1241,7 +1244,7 @@
                                     "x": 411,
                                     "y": 0,
                                     "width": 80,
-                                    "height": 21
+                                    "height": -1
                                 },
                                 "item_6": {
                                     "type": "text",
@@ -1263,7 +1266,7 @@
                                     "x": 491,
                                     "y": 0,
                                     "width": 80,
-                                    "height": 21
+                                    "height": -1
                                 }
                             }
                         },

+ 1 - 0
RedAnt ERP Mobile/iSales-NPD/so_thumb.json

@@ -929,6 +929,7 @@
                 "item_0": {
                     "type": "table",
                     "data_source": "table_model",
+                    "split":true,
                     "x": 0,
                     "y": 5,
                     "width": 571,