| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- //
- // TableDrawable.m
- // pdftest
- //
- // Created by Ray on 10/18/16.
- // Copyright © 2016 United Software Applications, Inc. All rights reserved.
- //
- #import "TableDrawable.h"
- #import "GroupDrawable.h"
- @implementation TableDrawable
- -(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* rows = self.drawableTemplate[@"rows"];
- int count = [rows[@"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 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];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary * rowjson =rows[ [NSString stringWithFormat:@"row_%d",i ] ];
- PDFDrawable* drawable_obj= [[GroupDrawable alloc] init:rowjson];
- drawable_obj.delegate = self.delegate;
- NSMutableDictionary* rows_data = table_data[rowjson[@"data_source"]];
- int row_data_count=[rows_data[@"count"] intValue];
- float dy=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(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=0;
- }
- }
- // [drawable_obj Draw:context dataSource:row_data ParentRect:(CGRect)pdfrect startX:0 startY:dy flipHeight:flip_height range:between_header_and_footer];
- dy+=row_rect.size.height;
- // pos = CGPointMake(0, rowpos.y+pos.y);
- }
-
- }
-
- return parentrect;
- }
- -(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* rows = self.drawableTemplate[@"rows"];
- int count = [rows[@"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 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];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary * rowjson =rows[ [NSString stringWithFormat:@"row_%d",i ] ];
- PDFDrawable* drawable_obj= [[GroupDrawable alloc] init:rowjson];
- drawable_obj.delegate = self.delegate;
- NSMutableDictionary* rows_data = table_data[rowjson[@"data_source"]];
- int row_data_count=[rows_data[@"count"] intValue];
- float dy=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(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=0;
- }
- }
- [drawable_obj Draw:context dataSource:row_data ParentRect:(CGRect)pdfrect startX:0 startY:dy flipHeight:flip_height range:between_header_and_footer];
- dy+=row_rect.size.height;
- // pos = CGPointMake(0, rowpos.y+pos.y);
- }
-
- }
-
- 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
|