PDFStampViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. //
  2. // PDFStampViewController.m
  3. // PDFReader
  4. //
  5. // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // The PDF Reader Sample applications are licensed with a modified BSD license.
  8. // Please see License for details. This notice may not be removed from this file.
  9. //
  10. #import "PDFStampViewController.h"
  11. #import "StampCollectionViewCell.h"
  12. #import "StampPreview.h"
  13. #import "StampFileManager.h"
  14. #import "StampImageViewController.h"
  15. #import "StampTextViewController.h"
  16. #import <ComPDFKit/ComPDFKit.h>
  17. #define kStamp_Cell_Height 60
  18. extern PDFAnnotationStampKey PDFAnnotationStampKeyType = @"PDFAnnotationStampKeyType";
  19. extern PDFAnnotationStampKey PDFAnnotationStampKeyImagePath = @"PDFAnnotationStampKeyImagePath";
  20. extern PDFAnnotationStampKey PDFAnnotationStampKeyText = @"PDFAnnotationStampKeyText";
  21. extern PDFAnnotationStampKey PDFAnnotationStampKeyShowDate = @"PDFAnnotationStampKeyShowDate";
  22. extern PDFAnnotationStampKey PDFAnnotationStampKeyShowTime = @"PDFAnnotationStampKeyShowTime";
  23. extern PDFAnnotationStampKey PDFAnnotationStampKeyStyle = @"PDFAnnotationStampKeyStyle";
  24. extern PDFAnnotationStampKey PDFAnnotationStampKeyShape = @"PDFAnnotationStampKeyShape";
  25. @interface PDFStampViewController () <UIPopoverPresentationControllerDelegate,UICollectionViewDelegate,UICollectionViewDataSource,StampHeaderViewDelegate>
  26. @property (nonatomic,retain) UICollectionView *collectView;
  27. @property (nonatomic,retain) UISegmentedControl *segmentedControl;
  28. @property (nonatomic,retain) NSArray *standardArray;
  29. @property (nonatomic,retain) NSArray *customTextArray;
  30. @property (nonatomic,retain) NSArray *customImageArray;
  31. @property (nonatomic,retain) NSMutableDictionary *imgDicCache;
  32. @property (nonatomic,retain) StampFileManager *stampFileManager;
  33. @end
  34. @implementation PDFStampViewController
  35. #pragma mark - Init Methods
  36. - (void)dealloc {
  37. Block_release(_callback);
  38. [_stampFileManager release];
  39. [_imgDicCache release];
  40. [_standardArray release];
  41. [_customTextArray release];
  42. [_customImageArray release];
  43. _collectView.dataSource = nil;
  44. _collectView.delegate = nil;
  45. [_collectView release];
  46. [_segmentedControl release];
  47. [super dealloc];
  48. }
  49. #pragma mark - UIViewController Methods
  50. - (void)viewDidLoad {
  51. [super viewDidLoad];
  52. // Do any additional setup after loading the view.
  53. self.view.backgroundColor = [UIColor colorWithRed:250.0/255.0 green:250.0/255.0 blue:250.0/255.0 alpha:1.0];
  54. [self.navigationController.navigationBar setTranslucent:NO];
  55. if (UIUserInterfaceIdiomPhone == UI_USER_INTERFACE_IDIOM()) {
  56. self.preferredContentSize = CGSizeMake(300, 400);
  57. } else {
  58. self.preferredContentSize = CGSizeMake(360, 480);
  59. }
  60. NSMutableArray *array = [NSMutableArray array];
  61. for (int i=1; i<13; i++) {
  62. NSString *tPicName = nil;
  63. if (i<10) {
  64. tPicName = [NSString stringWithFormat:@"stamp-0%d.png",i];
  65. } else {
  66. tPicName = [NSString stringWithFormat:@"stamp-%d.png",i];
  67. }
  68. [array addObject:tPicName];
  69. }
  70. [array addObjectsFromArray:@[@"stamp-13.png",
  71. @"stamp-14.png",
  72. @"stamp-15.png",
  73. @"stamp-16.png",
  74. @"stamp-20.png",
  75. @"stamp-18.png",
  76. @"stamp_chick.png",
  77. @"stamp_cross.png",
  78. @"stamp_circle_01.png"]];
  79. self.standardArray = array;
  80. self.imgDicCache = [NSMutableDictionary dictionary];
  81. self.stampFileManager = [[[StampFileManager alloc] init] autorelease];
  82. [self.stampFileManager readStampDataFromFile];
  83. self.customTextArray = [self.stampFileManager getTextStampData];
  84. self.customImageArray = [self.stampFileManager getImageStampData];
  85. [self.view addSubview:self.collectView];
  86. self.navigationItem.titleView = self.segmentedControl;
  87. }
  88. - (void)viewWillAppear:(BOOL)animated {
  89. [super viewWillAppear:animated];
  90. if (self.editing) {
  91. self.navigationItem.titleView.hidden = YES;
  92. } else {
  93. self.navigationItem.titleView.hidden = NO;
  94. }
  95. [self.collectView reloadData];
  96. }
  97. - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
  98. [super setEditing:editing animated:animated];
  99. if (editing) {
  100. UIBarButtonItem *tLeftItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
  101. target:self
  102. action:self.editButtonItem.action];
  103. [self.navigationItem setRightBarButtonItem:tLeftItem];
  104. [tLeftItem release];
  105. UIBarButtonItem *tRightItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash
  106. target:self
  107. action:@selector(buttonItemClicked_Delete:)];
  108. if (self.customTextArray.count + self.customImageArray.count > 0){
  109. [self.navigationItem setLeftBarButtonItem:tRightItem];
  110. } else {
  111. self.navigationItem.leftBarButtonItem = nil;
  112. }
  113. [tRightItem release];
  114. self.navigationItem.titleView.hidden = YES;
  115. self.collectView.allowsMultipleSelection = YES;
  116. } else {
  117. if (self.segmentedControl.selectedSegmentIndex == 1) {
  118. UIBarButtonItem *tLeftItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit
  119. target:self
  120. action:self.editButtonItem.action];
  121. [self.navigationItem setRightBarButtonItem:tLeftItem];
  122. [tLeftItem release];
  123. [self.navigationItem setLeftBarButtonItem:nil];
  124. } else {
  125. [self.navigationItem setRightBarButtonItem:nil];
  126. [self.navigationItem setLeftBarButtonItem:nil];
  127. }
  128. [self.navigationItem setLeftBarButtonItem:nil];
  129. self.navigationItem.titleView.hidden = NO;
  130. self.collectView.allowsMultipleSelection = NO;
  131. }
  132. for (StampCollectionViewCell *cell in [self.collectView visibleCells]) {
  133. cell.editing = self.editing;
  134. }
  135. }
  136. #pragma mark - getter && setter Methods
  137. - (UICollectionView *)collectView {
  138. if (!_collectView) {
  139. UICollectionViewFlowLayout *layout = [[[UICollectionViewFlowLayout alloc] init] autorelease];
  140. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  141. layout.minimumInteritemSpacing = 10;
  142. layout.minimumLineSpacing = 10;
  143. layout.itemSize = CGSizeMake((self.preferredContentSize.width - 60)/2,80);
  144. layout.sectionInset = UIEdgeInsetsMake(5, 20, 5, 20);
  145. _collectView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
  146. _collectView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  147. _collectView.delegate = self;
  148. _collectView.dataSource = self;
  149. _collectView.backgroundColor = [UIColor clearColor];
  150. [_collectView registerClass:[StampCollectionHeaderView class]
  151. forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
  152. withReuseIdentifier:@"header"];
  153. [_collectView registerClass:[StampCollectionHeaderView1 class]
  154. forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
  155. withReuseIdentifier:@"header1"];
  156. [_collectView registerClass:[StampCollectionViewCell class]
  157. forCellWithReuseIdentifier:@"TStampViewCell"];
  158. if (@available(iOS 11.0, *)) {
  159. _collectView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways;
  160. }
  161. }
  162. return _collectView;
  163. }
  164. - (UISegmentedControl *)segmentedControl {
  165. if (!_segmentedControl) {
  166. _segmentedControl = [[UISegmentedControl alloc] initWithItems:@[NSLocalizedString(@"Standard", nil), NSLocalizedString(@"Custom",nil)]];
  167. _segmentedControl.selectedSegmentIndex = 0;
  168. [_segmentedControl addTarget:self action:@selector(segmentedControlValueChanged_Mode:) forControlEvents:UIControlEventValueChanged];
  169. }
  170. return _segmentedControl;
  171. }
  172. #pragma mark - Button Event Action
  173. - (void)segmentedControlValueChanged_Mode:(id)sender {
  174. if (self.segmentedControl.selectedSegmentIndex == 1 &&
  175. ![[CPDFKit sharedInstance] allowsFeature:CPDFKitFeatureAnnotationCustomizedStamp]) {
  176. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
  177. style:UIAlertActionStyleCancel
  178. handler:nil];
  179. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil
  180. message:NSLocalizedString(@"Your license does not support this feature, please upgrade your license privilege.", nil)
  181. preferredStyle:UIAlertControllerStyleAlert];
  182. [alert addAction:cancelAction];
  183. [self presentViewController:alert animated:YES completion:nil];
  184. [self.segmentedControl setSelectedSegmentIndex:0];
  185. return;
  186. }
  187. self.editing = NO;
  188. [self.collectView reloadData];
  189. }
  190. - (void)buttonItemClicked_Delete:(id)sender {
  191. NSArray *selectedArray = [self.collectView indexPathsForSelectedItems];
  192. if (selectedArray.count < 1)
  193. return;
  194. NSMutableArray *selectArrayTxt = [NSMutableArray array];
  195. NSMutableArray *selectArrayImage = [NSMutableArray array];
  196. for (NSIndexPath *indexPath in selectedArray) {
  197. if (indexPath.section == 0) {
  198. [selectArrayTxt addObject:@(indexPath.row)];
  199. } else {
  200. [selectArrayImage addObject:@(indexPath.row)];
  201. }
  202. }
  203. NSArray *tempArray1 = [[[selectArrayTxt sortedArrayUsingSelector:@selector(compare:)] reverseObjectEnumerator] allObjects];
  204. NSArray *tempArray2 = [[[selectArrayImage sortedArrayUsingSelector:@selector(compare:)] reverseObjectEnumerator] allObjects];
  205. for (NSNumber *tNum in tempArray1) {
  206. int tIndex = [tNum intValue];
  207. [self.stampFileManager removeStampItem:tIndex type:PDFStampCustomType_Text];
  208. }
  209. for (NSNumber *tNum in tempArray2) {
  210. int tIndex = [tNum intValue];
  211. [self.stampFileManager removeStampItem:tIndex type:PDFStampCustomType_Image];
  212. }
  213. [self.collectView reloadData];
  214. if (self.customImageArray.count + self.customTextArray.count == 0) {
  215. self.navigationItem.leftBarButtonItem = nil;
  216. }
  217. }
  218. #pragma mark - Private Methods
  219. - (UIImage *)compressImage:(UIImage *)image {
  220. CGFloat maxWH = kStamp_Cell_Height;
  221. if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
  222. maxWH *=[UIScreen mainScreen].scale;
  223. CGFloat imageScale = 1.0;
  224. if (image.size.width > maxWH || image.size.height>maxWH)
  225. imageScale = MIN(maxWH / image.size.width, maxWH / image.size.height);
  226. CGSize newSize = CGSizeMake(image.size.width * imageScale, image.size.height * imageScale);
  227. UIGraphicsBeginImageContext(newSize);
  228. [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
  229. UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
  230. UIGraphicsEndImageContext();
  231. return newImage;
  232. }
  233. #pragma mark - Public Methods
  234. - (void)showViewController:(UIViewController *)viewController inRect:(CGRect)rect {
  235. UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:self] autorelease];
  236. navigationController.modalPresentationStyle = UIModalPresentationPopover;
  237. UIPopoverPresentationController *popVC = navigationController.popoverPresentationController;
  238. popVC.delegate = self;
  239. popVC.sourceRect = rect;
  240. popVC.sourceView = viewController.view;
  241. [viewController presentViewController:navigationController animated:YES completion:nil];
  242. }
  243. #pragma mark - UIPopoverPresentationControllerDelegate
  244. - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection {
  245. return UIModalPresentationNone;
  246. }
  247. - (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController {
  248. if (self.callback) {
  249. self.callback(-1, nil);
  250. self.callback = nil;
  251. }
  252. }
  253. #pragma mark - UICollectionViewDataSource & UICollectionViewDelegate
  254. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  255. if (self.segmentedControl.selectedSegmentIndex == 0) {
  256. return 1;
  257. } else {
  258. return 2;
  259. }
  260. }
  261. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  262. if (self.segmentedControl.selectedSegmentIndex == 0) {
  263. return self.standardArray.count;
  264. } else {
  265. switch (section) {
  266. case 0:
  267. return self.customTextArray.count;
  268. case 1:
  269. return self.customImageArray.count;
  270. default:
  271. return 0;
  272. }
  273. }
  274. }
  275. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  276. StampCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TStampViewCell" forIndexPath:indexPath];
  277. cell.backgroundColor = [UIColor whiteColor];
  278. if (self.segmentedControl.selectedSegmentIndex == 0) {
  279. cell.editing = NO;
  280. cell.stampImage.image =[UIImage imageNamed:self.standardArray[indexPath.item]];
  281. } else {
  282. cell.editing = self.editing;
  283. NSUInteger txtLength = indexPath.item;
  284. NSUInteger imgLength = indexPath.item;
  285. NSUInteger location = indexPath.item;
  286. NSUInteger length;
  287. NSRange range;
  288. length = indexPath.section ? imgLength : txtLength;
  289. range = NSMakeRange(location, length);
  290. if (0 == indexPath.section) {
  291. NSDictionary *tDic = _customTextArray[indexPath.item];
  292. NSString *tText = [tDic objectForKey:@"text"];
  293. NSInteger tStyle = [[tDic objectForKey:@"style"] integerValue];
  294. BOOL tHaveDate = [[tDic objectForKey:@"haveDate"] boolValue];
  295. BOOL tHaveTime = [[tDic objectForKey:@"haveTime"] boolValue];
  296. StampPreview *tPreview = [[StampPreview alloc] initWithFrame:CGRectMake(0, 0, 320, kStamp_Cell_Height)];
  297. [tPreview setTextStampText:tText];
  298. [tPreview setTextStampStyle:tStyle];
  299. [tPreview setTextStampHaveDate:tHaveDate];
  300. [tPreview setTextStampHaveTime:tHaveTime];
  301. tPreview.leftMargin = 0;
  302. UIImage *tImg = [tPreview renderImage];
  303. cell.stampImage.image = tImg;
  304. [tPreview release];
  305. } else {
  306. NSDictionary *tDic = self.customImageArray[indexPath.item];
  307. UIImage *img = [self.imgDicCache objectForKey:tDic];
  308. if (!img) {
  309. NSString *tPath = [tDic objectForKey:@"path"];
  310. NSString *tFileName = [[NSFileManager defaultManager] displayNameAtPath:tPath];
  311. NSString *tRealPath = [NSString stringWithFormat:@"%@/%@",kPDFStampDataFolder,tFileName];
  312. UIImage *tImg = [UIImage imageWithContentsOfFile:tRealPath];
  313. img = [self compressImage:tImg];
  314. [self.imgDicCache setObject:img forKey:tDic];
  315. }
  316. cell.stampImage.image = img;
  317. }
  318. }
  319. return cell;
  320. }
  321. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  322. if (self.segmentedControl.selectedSegmentIndex == 1) {
  323. if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
  324. if (indexPath.section == 0) {
  325. StampCollectionHeaderView1 *headerView = [_collectView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header1" forIndexPath:indexPath];
  326. headerView.delegate = self;
  327. if ([self.customTextArray count] > 0) {
  328. headerView.textLabel.hidden = NO;
  329. headerView.textLabel.text = NSLocalizedString(@"New Text Stamp", nil);
  330. } else {
  331. headerView.textLabel.hidden = YES;
  332. }
  333. return headerView;
  334. } else {
  335. StampCollectionHeaderView *headerView = [_collectView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
  336. if (self.customImageArray.count > 0) {
  337. headerView.textLabel.hidden = NO;
  338. headerView.textLabel.text = NSLocalizedString(@"New Image Stamp", nil);
  339. } else {
  340. headerView.textLabel.hidden = YES;
  341. }
  342. return headerView;
  343. }
  344. }
  345. }
  346. return nil;
  347. }
  348. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  349. if (self.segmentedControl.selectedSegmentIndex == 1) {
  350. if (section == 0) {
  351. if ([self.customTextArray count] > 0) {
  352. return CGSizeMake(self.preferredContentSize.width, 100);
  353. } else {
  354. return CGSizeMake(self.preferredContentSize.width, 80);
  355. }
  356. } else {
  357. if ([self.customImageArray count] > 0) {
  358. return CGSizeMake(self.preferredContentSize.width, 20);
  359. }
  360. }
  361. }
  362. return CGSizeZero;
  363. }
  364. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  365. if (!self.editing) {
  366. if (self.segmentedControl.selectedSegmentIndex == 0) {
  367. [self dismissViewControllerAnimated:YES completion:^{
  368. if (self.callback) {
  369. self.callback(indexPath.row, nil);
  370. self.callback = nil;
  371. }
  372. }];
  373. } else {
  374. if (indexPath.section == 0) {
  375. NSDictionary *tDict = self.customTextArray[indexPath.row];
  376. NSString *tText = [tDict objectForKey:@"text"];
  377. BOOL tHaveDate = [[tDict objectForKey:@"haveDate"] boolValue];
  378. BOOL tHaveTime = [[tDict objectForKey:@"haveTime"] boolValue];
  379. NSInteger tStyle = [[tDict objectForKey:@"style"] integerValue];
  380. NSInteger stampStype = 0;
  381. NSInteger stampShape = 0;
  382. switch (tStyle) {
  383. case TextStampColorType_Black:
  384. {
  385. stampStype = 0;
  386. stampShape = 0;
  387. }
  388. break;
  389. case TextStampColorType_Red:
  390. case TextStampColorType_RedLeft:
  391. case TextStampColorType_RedRight:
  392. {
  393. stampStype = 1;
  394. if (TextStampColorType_RedRight== tStyle) {
  395. stampShape = 2;
  396. } else if (TextStampColorType_RedLeft == tStyle) {
  397. stampShape = 1;
  398. } else {
  399. stampShape = 0;
  400. }
  401. }
  402. break;
  403. case TextStampColorType_Green:
  404. case TextStampColorType_GreenLeft:
  405. case TextStampColorType_GreenRight:
  406. {
  407. stampStype = 2;
  408. if (TextStampColorType_GreenRight== tStyle) {
  409. stampShape = 2;
  410. } else if (TextStampColorType_GreenLeft == tStyle) {
  411. stampShape = 1;
  412. } else {
  413. stampShape = 0;
  414. }
  415. }
  416. break;
  417. case TextStampColorType_Blue:
  418. case TextStampColorType_BlueLeft:
  419. case TextStampColorType_BlueRight:
  420. {
  421. stampStype = 3;
  422. if (TextStampColorType_BlueRight== tStyle) {
  423. stampShape = 2;
  424. } else if (TextStampColorType_BlueLeft == tStyle) {
  425. stampShape = 1;
  426. } else {
  427. stampShape = 0;
  428. }
  429. }
  430. break;
  431. }
  432. [self dismissViewControllerAnimated:YES completion:^{
  433. if (self.callback) {
  434. self.callback(indexPath.row, @{PDFAnnotationStampKeyText : tText,
  435. PDFAnnotationStampKeyShowDate : @(tHaveDate),
  436. PDFAnnotationStampKeyShowTime : @(tHaveTime),
  437. PDFAnnotationStampKeyStyle : @(stampStype),
  438. PDFAnnotationStampKeyShape : @(stampShape)});
  439. self.callback = nil;
  440. }
  441. }];
  442. } else {
  443. NSDictionary *tDict = self.customImageArray[indexPath.row];
  444. NSString *tPath = [tDict objectForKey:@"path"];
  445. NSString *tFileName = [[NSFileManager defaultManager] displayNameAtPath:tPath];
  446. NSString *tRealPath = [NSString stringWithFormat:@"%@/%@",kPDFStampDataFolder,tFileName];
  447. [self dismissViewControllerAnimated:YES completion:^{
  448. if (self.callback) {
  449. self.callback(indexPath.row, @{PDFAnnotationStampKeyImagePath : tRealPath});
  450. self.callback = nil;
  451. }
  452. }];
  453. }
  454. }
  455. }
  456. }
  457. #pragma mark - TStampHeaderViewDelegate
  458. - (void)addImageWithHeaderView:(StampCollectionHeaderView1 *)headerView {
  459. self.editing = NO;
  460. StampImageViewController *vc = [[StampImageViewController alloc] init];
  461. vc.callback = ^(UIImage *image) {
  462. NSString *tPath = [self.stampFileManager saveStampWithImage:image];
  463. if (tPath) {
  464. NSMutableDictionary *tStampItem = [[NSMutableDictionary alloc] init];
  465. [tStampItem setObject:tPath forKey:@"path"];
  466. [self.stampFileManager insertStampItem:tStampItem type:PDFStampCustomType_Image];
  467. [tStampItem release];
  468. }
  469. };
  470. [self.navigationController pushViewController:vc animated:YES];
  471. [vc release];
  472. }
  473. - (void)addTextWithHeaderView:(StampCollectionHeaderView1 *)headerView {
  474. self.editing = NO;
  475. StampTextViewController *vc = [[StampTextViewController alloc] init];
  476. vc.callback = ^(NSDictionary *dictionary) {
  477. [self.stampFileManager insertStampItem:dictionary type:PDFStampCustomType_Text];
  478. };
  479. [self.navigationController pushViewController:vc animated:YES];
  480. [vc release];
  481. }
  482. @end