| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- //
- // GridDrawable.m
- // pdftest
- //
- // Created by Ray on 10/21/16.
- // Copyright © 2016 United Software Applications, Inc. All rights reserved.
- //
- #import "GridDrawable.h"
- #import "GroupDrawable.h"
- @implementation GridDrawable
- -(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
- {
-
-
- NSMutableDictionary* table_data = data[self.drawableTemplate[@"data_source"]];
-
- NSMutableDictionary* celljson = self.drawableTemplate[@"cell"];
- NSString* direction = celljson[@"direction"];
- if(direction==nil)
- direction=@"H";
-
- // 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 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];
-
- PDFDrawable* drawable_obj= [[GroupDrawable alloc] init:celljson];
- drawable_obj.delegate = self.delegate;
- NSMutableDictionary* rows_data = table_data[celljson[@"data_source"]];
- int row_data_count=[rows_data[@"count"] intValue];
- float dy=y;
- float dx=0;
- for(int j=0;j<row_data_count;j++)
- {
-
-
-
- NSMutableDictionary * row_data =rows_data[ [NSString stringWithFormat:@"item_%d",j ] ];
- CGRect row_rect= [drawable_obj Query_Rect:context dataSource:row_data ParentRect:(CGRect)pdfrect startX:0 startY:dy flipHeight:flip_height range:between_header_and_footer];
-
- if(row_rect.size.width>parentrect.size.width||row_rect.size.height>parentrect.size.height)
- {
- // cell 比 grid 还要大,模板有错,直接返回。
- return parentrect;
- }
- if([direction isEqualToString:@"H"])
- {
- if(dy+row_rect.size.height> between_header_and_footer.location+between_header_and_footer.length )
- {
- //越界,新起一页
- if (self.delegate && [self.delegate respondsToSelector:@selector(outofPage:)]) {
- [self.delegate addPageCount:context];
- dy=y;
- dx=0;
- }
- }
- }
- else
- {
- if(/*dy+row_rect.size.height> between_header_and_footer.location+between_header_and_footer.length && */dx+row_rect.size.width>parentrect.size.width )
- {
- //越界,新起一页
- if (self.delegate && [self.delegate respondsToSelector:@selector(outofPage:)]) {
- [self.delegate addPageCount:context];
- dy=y;
- dx=0;
- }
- }
-
- }
-
-
-
-
- // [drawable_obj Draw:context dataSource:row_data ParentRect:(CGRect)pdfrect startX:dx startY:dy flipHeight:flip_height range:between_header_and_footer];
- if([direction isEqualToString:@"H"])
- {
- dx+=row_rect.size.width;
- if(dx+row_rect.size.width>parentrect.size.width)
- {
- dx=0;
- dy+=row_rect.size.height;
- }
-
- }
- else
- {
- dy+=row_rect.size.height;
- if(dy-y+row_rect.size.height>parentrect.size.height)
- {
- dy=y;
- dx+=row_rect.size.width;
- }
-
-
- }
-
-
-
- }
-
-
-
- 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
- {
-
-
- NSMutableDictionary* table_data = data[self.drawableTemplate[@"data_source"]];
-
- NSMutableDictionary* celljson = self.drawableTemplate[@"cell"];
- NSString* direction = celljson[@"direction"];
- if(direction==nil)
- direction=@"H";
-
- // 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 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];
-
- PDFDrawable* drawable_obj= [[GroupDrawable alloc] init:celljson];
- drawable_obj.delegate = self.delegate;
- NSMutableDictionary* rows_data = table_data[celljson[@"data_source"]];
- int row_data_count=[rows_data[@"count"] intValue];
- float dy=y;
- float dx=0;
- for(int j=0;j<row_data_count;j++)
- {
-
-
-
- NSMutableDictionary * row_data =rows_data[ [NSString stringWithFormat:@"item_%d",j ] ];
- CGRect row_rect= [drawable_obj Query_Rect:context dataSource:row_data ParentRect:(CGRect)pdfrect startX:0 startY:dy flipHeight:flip_height range:between_header_and_footer];
-
- if(row_rect.size.width>parentrect.size.width||row_rect.size.height>parentrect.size.height)
- {
- // cell 比 grid 还要大,模板有错,直接返回。
- return parentrect;
- }
- if([direction isEqualToString:@"H"])
- {
- if(dy+row_rect.size.height> between_header_and_footer.location+between_header_and_footer.length )
- {
- //越界,新起一页
- if (self.delegate && [self.delegate respondsToSelector:@selector(outofPage:)]) {
- [self.delegate outofPage:context];
- dy=y;
- dx=0;
- }
- }
- }
- else
- {
- if(/*dy+row_rect.size.height> between_header_and_footer.location+between_header_and_footer.length && */dx+row_rect.size.width>parentrect.size.width )
- {
- //越界,新起一页
- if (self.delegate && [self.delegate respondsToSelector:@selector(outofPage:)]) {
- [self.delegate outofPage:context];
- dy=y;
- dx=0;
- }
- }
-
- }
-
-
-
- [drawable_obj Draw:context dataSource:row_data ParentRect:(CGRect)pdfrect startX:dx startY:dy flipHeight:flip_height range:between_header_and_footer];
- if([direction isEqualToString:@"H"])
- {
- dx+=row_rect.size.width;
- if(dx+row_rect.size.width>parentrect.size.width)
- {
- dx=0;
- dy+=row_rect.size.height;
- }
- }
- else
- {
- dy+=row_rect.size.height;
- if(dy-y+row_rect.size.height>parentrect.size.height)
- {
- dy=y;
- dx+=row_rect.size.width;
- }
-
- }
-
-
-
- }
-
-
-
- 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];
- // }
- }
- @end
|