KMPDFPosterPrintWindowController.m 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. //
  2. // KMPDFPosterPrintWindowController.m
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by 丁林圭 on 2018/4/3.
  6. //
  7. #import "PDF_Reader_Pro-Swift.h"
  8. #import "KMPDFPosterPrintWindowController.h"
  9. #import "KMPosterPrintManager.h"
  10. //#import "TextFieldFormatter.h"
  11. //#import "KMFileAttribute.h"
  12. //#import "KMBookletMaskView.h"
  13. //#import "PasswordWindowController.h"
  14. //#import "KMSavePanelAccessoryController.h"
  15. //#import "NSWindowController_SKExtensions.h"
  16. //#import "KMPageSizeTool.h"
  17. #define maxPrintWidth 300
  18. #define kPrintFolderPath [[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:[NSBundle mainBundle].bundleIdentifier]
  19. #define kPosterPrintFolderPath [[[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:[NSBundle mainBundle].bundleIdentifier] stringByAppendingPathComponent:@"PosterPrint"]
  20. #define kPosterPrintFileSavePath [[[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:[NSBundle mainBundle].bundleIdentifier] stringByAppendingPathComponent:@"PosterPrint.pdf"]
  21. #pragma mark KMPDFPosterPrintContentView
  22. @interface KMPDFPosterPrintContentView : NSView
  23. @property (nonatomic,retain) NSArray *horizontals;
  24. @property (nonatomic,retain) NSArray *verticals;
  25. @property (nonatomic,assign) CGFloat overlap;
  26. @property (nonatomic,assign) CGFloat spaceWidth;
  27. @property (nonatomic,assign) CGFloat spaceHeight;
  28. @property (nonatomic,assign) CGFloat scanle;
  29. @end
  30. @implementation KMPDFPosterPrintContentView
  31. -(void)dealloc
  32. {
  33. }
  34. -(void)drawRect:(NSRect)dirtyRect
  35. {
  36. [super drawRect:dirtyRect];
  37. CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];// 获取画布
  38. CGFloat width = self.bounds.size.width;
  39. CGFloat height = self.bounds.size.height;
  40. if (_horizontals.count> 0 || _verticals.count > 0) {
  41. NSArray *hourArray = _horizontals;
  42. NSArray *vertArray = _verticals;
  43. [NSGraphicsContext saveGraphicsState];
  44. if (context) {
  45. [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO]];
  46. }
  47. CGContextSetStrokeColorWithColor(context, [NSColor colorWithRed:51.0/255.0 green:186.0/255.0 blue:234.0/255.0 alpha:1.0].CGColor);
  48. CGContextSetLineWidth(context, 1.0);
  49. for (NSUInteger i =0; i< vertArray.count -1; i ++) {
  50. CGContextMoveToPoint(context, 0,height - ([vertArray[i] floatValue] /_scanle + _spaceHeight));
  51. CGContextAddLineToPoint(context,width, height - ([vertArray[i] floatValue] /_scanle +_spaceHeight));
  52. }
  53. for (NSUInteger j =0; j< hourArray.count - 1; j ++) {
  54. CGContextMoveToPoint(context, [hourArray[j] floatValue]/_scanle + _spaceWidth, 0);
  55. CGContextAddLineToPoint(context,[hourArray[j] floatValue]/_scanle + _spaceWidth, height);
  56. }
  57. CGFloat arr[] = {8,1};
  58. CGContextSetLineDash(context, 0, arr, 1);
  59. CGContextDrawPath(context, kCGPathStroke);
  60. [NSGraphicsContext restoreGraphicsState];
  61. }
  62. }
  63. @end
  64. #pragma mark -KMPDFPosterPrintWindowController
  65. @interface KMPDFPosterPrintWindowController ()<NSComboBoxDelegate>
  66. @property (nonatomic,retain) PDFDocument *PDFDocument;
  67. @property (nonatomic,retain) NSString *password;
  68. @property (nonatomic,retain) KMPDFPosterPrint *PDFPrint;
  69. @property (nonatomic,assign) IBOutlet NSTextField *currentPageLabel;
  70. @property (nonatomic,assign) IBOutlet NSTextField *totalPageLabel;
  71. @property (assign) IBOutlet NSTextField *scaleTextField;
  72. @property (assign) IBOutlet NSButton *cutMarksButton;
  73. @property (assign) IBOutlet NSButton *labelButton;
  74. @property (assign) IBOutlet NSButton *portraitButton;
  75. @property (assign) IBOutlet NSButton *landscapeButton;
  76. @property (nonatomic,assign) IBOutlet NSTextField *pageRangeLabel;
  77. @property (nonatomic,assign) IBOutlet NSComboBox *pageRangeComboBox;
  78. @property (nonatomic,assign) IBOutlet NSTextField *splitSizeLabel;
  79. @property (nonatomic,assign) IBOutlet NSComboBox *splitSizeComboBox;
  80. @property (nonatomic,assign) IBOutlet NSTextField *overlapLabel;
  81. @property (nonatomic,assign) IBOutlet NSTextField *overlapUnit;
  82. @property (assign) IBOutlet NSTextField *overlapTextField;
  83. @property (assign) IBOutlet NSTextField *sizeLabel;
  84. @property (assign) IBOutlet NSTextField *zoomLabel;
  85. @property (nonatomic,assign) IBOutlet NSComboBox *unitComboBox;
  86. @property (nonatomic,assign) IBOutlet NSImageView *thumImageView;
  87. @property (assign) IBOutlet NSLayoutConstraint *PDFHeight;
  88. @property (assign) IBOutlet NSLayoutConstraint *PDFWidth;
  89. @property (nonatomic,assign) IBOutlet NSView *PDFContentView;
  90. @property (assign) IBOutlet NSLayoutConstraint *contentHeight;
  91. @property (assign) IBOutlet NSLayoutConstraint *contentWidth;
  92. @property (assign) IBOutlet NSButton *cancelButton;
  93. @property (assign) IBOutlet NSButton *saveButton;
  94. @property (assign) IBOutlet NSButton *printButton;
  95. @property (assign,nonatomic) IBOutlet NSTextField *orientationLabel;
  96. @property (assign,nonatomic) IBOutlet NSTextField *unitLabel;
  97. @property (assign,nonatomic) IBOutlet NSTextField *titleScanlLabel;
  98. @property (assign,nonatomic) IBOutlet NSTextField *labelTextField;
  99. @property (assign,nonatomic) IBOutlet NSButton *reverseButton;
  100. @property (nonatomic,assign) IBOutlet NSTextField *commentsFormsLabel;
  101. @property (nonatomic,assign) IBOutlet NSComboBox *commentsFormsComboBox;
  102. @property (nonatomic,assign) IBOutlet NSTextField *pagesPerLabel;
  103. @property (nonatomic,assign) IBOutlet NSComboBox *selectPerComboBox;
  104. @property (assign,nonatomic) IBOutlet NSTextField *lineCountText;
  105. @property (assign,nonatomic) IBOutlet NSTextField *columnCountText;
  106. @property (assign,nonatomic) IBOutlet NSTextField *filePageSizeLabel;
  107. @property (assign,nonatomic) IBOutlet NSComboBox *filePageSizeBox;
  108. @property (assign) IBOutlet NSTextField *pageWidthTextField;
  109. @property (assign) IBOutlet NSTextField *pageHeightTextField;
  110. @property (assign) IBOutlet NSTextField *unitTLabel;
  111. @property (assign) IBOutlet NSTextField *paperWidthTextField;
  112. @property (assign) IBOutlet NSTextField *paperHeightTextField;
  113. @property (assign) IBOutlet NSTextField *unitT1Label;
  114. @property (assign) IBOutlet NSTabView *tableView;
  115. @property (nonatomic,retain) KMPDFPosterPrintContentView *preview;
  116. @property (nonatomic, retain) KMBookletMaskView *posterMaskView;
  117. @property (nonatomic,assign) NSUInteger currentPageIndex;
  118. @property (nonatomic,retain) NSArray * pages;;
  119. @end
  120. @implementation KMPDFPosterPrintWindowController
  121. - (void)dealloc
  122. {
  123. NSFileManager *manager = [NSFileManager defaultManager];
  124. if ([manager fileExistsAtPath:kPosterPrintFileSavePath]) {
  125. [manager removeItemAtPath:kPosterPrintFileSavePath error:nil];
  126. }
  127. }
  128. - (id)initWithPDFDocument:(PDFDocument *)pdfDocument
  129. {
  130. if (self = [super initWithWindowNibName:@"KMPDFPosterPrintWindowController"]) {
  131. [self showWaitting];
  132. NSDate *date = [NSDate date];
  133. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  134. [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
  135. NSString *contextString = [NSString stringWithFormat:@"(column,row) %@ %@",[pdfDocument.documentURL.path lastPathComponent],[formatter stringFromDate:date]];
  136. [self.labelTextField.cell setPlaceholderString:contextString];
  137. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  138. if (![[NSFileManager defaultManager] fileExistsAtPath:kPrintFolderPath]) {
  139. if (![[NSFileManager defaultManager] createDirectoryAtPath:kPrintFolderPath withIntermediateDirectories:NO attributes:nil error:nil]) {
  140. return;
  141. }
  142. }
  143. [pdfDocument writeToURL:[NSURL fileURLWithPath:kPosterPrintFileSavePath]];
  144. self.PDFDocument = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:kPosterPrintFileSavePath]];
  145. dispatch_async(dispatch_get_main_queue(), ^{
  146. [self hideWaitting];
  147. if (self.PDFDocument) {
  148. [self getDrawPages];
  149. [self reloadPDFData];
  150. [self reloadPDFView];
  151. }else{
  152. [self close];
  153. }
  154. });
  155. });
  156. }
  157. return self;
  158. }
  159. - (id)initWithPDFFilePath:(NSString *)filePath password:(nullable NSString *)password{
  160. if (self = [super initWithWindowNibName:@"KMPDFPosterPrintWindowController"]) {
  161. PDFDocument * pdf = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:filePath]];
  162. self.PDFDocument = pdf;
  163. self.password = password;
  164. }
  165. return self;
  166. }
  167. - (BOOL)windowShouldClose:(id)sender
  168. {
  169. [self close];
  170. return YES;
  171. }
  172. - (void)close {
  173. if (self.window.isSheet) {
  174. [self.window.sheetParent endSheet:self.window];
  175. // [self dismissSheet:nil];
  176. } else {
  177. [super close];
  178. }
  179. }
  180. - (void)windowDidLoad
  181. {
  182. [super windowDidLoad];
  183. [self localizedString];
  184. _PDFContentView.wantsLayer = YES;
  185. _PDFContentView.layer.borderWidth = 2.0;
  186. _PDFContentView.layer.borderColor = [NSColor blackColor].CGColor;
  187. _PDFContentView.layer.backgroundColor = [NSColor whiteColor].CGColor;
  188. self.currentPageIndex = 0;
  189. self.scaleTextField.stringValue = @"100";
  190. [self.scaleTextField setFormatter:[[TextFieldFormatter alloc] init]];
  191. self.columnCountText.stringValue = [NSString stringWithFormat:@"%ld",self.PDFPrint.columnCount]?:@"";
  192. self.lineCountText.stringValue = [NSString stringWithFormat:@"%ld",self.PDFPrint.lineCount]?:@"";
  193. self.overlapTextField.stringValue = @"0";
  194. [self.overlapTextField setFormatter:[[TextFieldFormatter alloc] init]];
  195. [self.labelTextField setEditable:NO];
  196. if (!self.PDFDocument) {
  197. return;
  198. }
  199. if (![self.PDFDocument isLocked] && [self.PDFDocument unlockWithPassword:self.password]) {
  200. [self getDrawPages];
  201. [self reloadPDFData];
  202. [self reloadPDFView];
  203. NSDate *date = [NSDate date];
  204. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  205. [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
  206. NSString *contextString = [NSString stringWithFormat:@"(column,row) %@ %@",[self.PDFDocument.documentURL.path lastPathComponent],[formatter stringFromDate:date]];
  207. [self.labelTextField.cell setPlaceholderString:contextString];
  208. } else {
  209. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  210. // PasswordWindowController *com = [[PasswordWindowController alloc] initWithWindowNibName:@"PasswordWindowController"];
  211. // com.fileURL = self.PDFDocument.documentURL;
  212. // [com beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
  213. // if (password) {
  214. // [self.PDFDocument unlockWithPassword:password];
  215. // self.password = password;
  216. // [self getDrawPages];
  217. // [self reloadPDFData];
  218. // [self reloadPDFView];
  219. //
  220. // NSDate *date = [NSDate date];
  221. // NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
  222. // [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
  223. // NSString *contextString = [NSString stringWithFormat:@"(column,row) %@ %@",[self.PDFDocument.documentURL.path lastPathComponent],[formatter stringFromDate:date]];
  224. //
  225. // [self.labelTextField.cell setPlaceholderString:contextString];
  226. //
  227. // } else {
  228. // [self close];
  229. //
  230. // }
  231. // }];
  232. // [com release];
  233. // });
  234. }
  235. }
  236. - (void)localizedString
  237. {
  238. self.window.title = NSLocalizedString(@"Poster", nil);
  239. self.pageRangeLabel.stringValue = NSLocalizedString(@"Page Range", nil);
  240. self.orientationLabel.stringValue = NSLocalizedString(@"Orientation:", nil);
  241. self.unitLabel.stringValue = NSLocalizedString(@"Unit:", nil);
  242. self.unitTLabel.stringValue = self.unitT1Label.stringValue = self.overlapUnit.stringValue = NSLocalizedString(@"mm", nil);
  243. self.titleScanlLabel.stringValue = NSLocalizedString(@"Tile Scale:", nil);
  244. self.overlapLabel.stringValue = NSLocalizedString(@"Overlap:",nil);
  245. self.commentsFormsLabel.stringValue = NSLocalizedString(@"Comments & Forms:",nil);
  246. [self.pageRangeComboBox addItemsWithObjectValues:@[NSLocalizedString(@"All Pages", nil),
  247. NSLocalizedString(@"Odd Pages Only", nil),
  248. NSLocalizedString(@"Even Pages Only",nil),
  249. NSLocalizedString(@"e.g. 1,3-5,10",nil)]];
  250. [self.pageRangeComboBox.cell setPlaceholderString:NSLocalizedString(@"e.g. 1,3-5,10", nil)];
  251. [self.commentsFormsComboBox addItemsWithObjectValues:@[NSLocalizedString(@"Document", nil),
  252. NSLocalizedString(@"Document and Markups", nil),
  253. NSLocalizedString(@"Document and Stamps",nil)
  254. ]];
  255. [self.commentsFormsComboBox selectItemAtIndex:1];
  256. [self.commentsFormsComboBox setEditable:NO];
  257. self.splitSizeLabel.stringValue = NSLocalizedString(@"Page size:", nil);
  258. [self.cancelButton setTitle:NSLocalizedString(@"Cancel", nil)];
  259. [self.saveButton setTitle:NSLocalizedString(@"Save as PDF", nil)];
  260. [self.printButton setTitle:NSLocalizedString(@"Print", nil)];
  261. [self.portraitButton setTitle:NSLocalizedString(@"Portrait",nil)];
  262. [self.landscapeButton setTitle:NSLocalizedString(@"Landscape",nil)];
  263. [self.cutMarksButton setTitle:NSLocalizedString(@"Cut Marks",nil)];
  264. [self.labelButton setTitle:NSLocalizedString(@"Label",nil)];
  265. [self.reverseButton setTitle:NSLocalizedString(@"Reverse pages",nil)];
  266. self.pagesPerLabel.stringValue = NSLocalizedString(@"Pages per sheet:", nil);
  267. self.filePageSizeLabel.stringValue = NSLocalizedString(@"Destination paper Size:", nil);
  268. [[self.tableView tabViewItemAtIndex:0] setLabel:NSLocalizedString(@"Tile", nil)];
  269. [[self.tableView tabViewItemAtIndex:1] setLabel:NSLocalizedString(@"Split", nil)];
  270. [self.pageRangeComboBox selectItemAtIndex:0];
  271. [self.pageRangeComboBox setEditable:NO];
  272. [self.unitComboBox selectItemAtIndex:1];
  273. NSArray *paperArray = [KMPageSizeTool paperSize];
  274. NSMutableArray *tPaperArray = [NSMutableArray arrayWithArray:paperArray];
  275. [tPaperArray addObject:NSLocalizedString(@"Custom",nil)];
  276. [self.splitSizeComboBox addItemsWithObjectValues:tPaperArray];
  277. [self.splitSizeComboBox selectItemAtIndex:1];
  278. [self.splitSizeComboBox setEditable:NO];
  279. self.pageWidthTextField.enabled = NO;
  280. self.pageHeightTextField.enabled = NO;
  281. NSMutableArray *tFileArray = [NSMutableArray arrayWithArray:paperArray];
  282. [tFileArray insertObject:NSLocalizedString(@"Actual Size", nil) atIndex:0];
  283. [tFileArray addObject:NSLocalizedString(@"Custom", nil)];
  284. [self.filePageSizeBox addItemsWithObjectValues:tFileArray];
  285. [self.filePageSizeBox selectItemAtIndex:0];
  286. [self.filePageSizeBox setEditable:NO];
  287. self.paperWidthTextField.enabled = NO;
  288. self.paperHeightTextField.enabled = NO;
  289. [self.selectPerComboBox addItemsWithObjectValues:@[@"2",
  290. @"4",
  291. @"6",
  292. @"9",
  293. @"16",
  294. NSLocalizedString(@"Custom", nil)]];
  295. [self.selectPerComboBox selectItemAtIndex:5];
  296. [self.selectPerComboBox setEditable:NO];
  297. }
  298. - (KMPDFPosterPrint *)PDFPrint
  299. {
  300. if (!_PDFPrint) {
  301. _PDFPrint = [[KMPDFPosterPrint alloc] init];
  302. _PDFPrint.scale = 1.0;
  303. _PDFPrint.direction = kKMPDFPosterPrintDirection_Portrait;
  304. _PDFPrint.commentsForms = kKMPDFPosterCommentsForms_DocumentMarkups;
  305. _PDFPrint.splitType = kKMPDFPosterSplitType_PageSize;
  306. _PDFPrint.lineCount = 2;
  307. _PDFPrint.columnCount = 2;
  308. _PDFPrint.isCut = NO;
  309. _PDFPrint.isLabel = NO;
  310. _PDFPrint.isOriginalPageSize = YES;
  311. _PDFPrint.fullPageSize =
  312. _PDFPrint.splitSize = CGSizeMake(595, 842);
  313. _PDFPrint.edgeInsets = NSEdgeInsetsMake(50, 60, 50, 60);
  314. _PDFPrint.fullPageEdgeInsets = NSEdgeInsetsMake(50, 60, 50, 60);
  315. }
  316. return _PDFPrint;
  317. }
  318. -(void)reloadPDFView
  319. {
  320. NSInteger indexPage = self.currentPageIndex;
  321. if (_PDFPrint.isReversePage) {
  322. indexPage = self.pages.count - self.currentPageIndex - 1;
  323. }
  324. PDFPage *page = self.pages[indexPage];
  325. CGRect rect = [page boundsForBox:kPDFDisplayBoxCropBox];
  326. [[KMPosterPrintManager defaultManager] posterPrintPage:page posterPrint:self.PDFPrint completionHandler:^(NSArray *horizontals, NSArray *verticals) {
  327. NSData *pageData = page.dataRepresentation;
  328. NSImage *img = [[NSImage alloc] initWithData:pageData];
  329. self.thumImageView.image = img;
  330. CGFloat printWidth = 0;
  331. CGFloat printHeight = 0;
  332. if (kKMPDFPosterPrintDirection_Landscape == self.PDFPrint.direction) {
  333. printHeight = self.PDFPrint.splitSize.width - self.PDFPrint.edgeInsets.top - self.PDFPrint.edgeInsets.bottom;
  334. printWidth = self.PDFPrint.splitSize.height- self.PDFPrint.edgeInsets.left - self.PDFPrint.edgeInsets.right;
  335. } else {
  336. printWidth = self.PDFPrint.splitSize.width - self.PDFPrint.edgeInsets.left - self.PDFPrint.edgeInsets.right;
  337. printHeight = self.PDFPrint.splitSize.height- self.PDFPrint.edgeInsets.top - self.PDFPrint.edgeInsets.bottom;
  338. }
  339. printWidth /= self.PDFPrint.scale;
  340. printHeight /= self.PDFPrint.scale;
  341. CGFloat contentWidth = printWidth + (printWidth - self.PDFPrint.overlap) * (horizontals.count -1); //裁剪Page的总宽度
  342. CGFloat contentHeight = printHeight + (printHeight- self.PDFPrint.overlap) * (verticals.count - 1); //裁剪Page的总高度
  343. CGFloat realityPDFW = rect.size.width;
  344. CGFloat realityPDFH = rect.size.height;
  345. NSInteger rotate = page.rotation;
  346. if (90 == rotate || 270 == rotate) {
  347. realityPDFW = rect.size.height;
  348. realityPDFH = rect.size.width;
  349. }
  350. if (self.PDFPrint.splitType == kKMPDFPosterSplitType_PageNumber) {
  351. contentWidth = realityPDFW;
  352. contentHeight = realityPDFH;
  353. }
  354. CGFloat max = MAX((contentWidth/maxPrintWidth), (contentHeight/maxPrintWidth));
  355. self.contentWidth.constant = contentWidth/max;
  356. self.contentHeight.constant = contentHeight/max;
  357. self.PDFWidth.constant = realityPDFW/max;
  358. self.PDFHeight.constant = realityPDFH/max;
  359. self.preview.frame = CGRectMake(0, 0, self.contentWidth.constant, self.contentHeight.constant);
  360. self.preview.horizontals = horizontals;
  361. self.preview.verticals = verticals;
  362. self.preview.overlap = self.PDFPrint.overlap / max;
  363. self.preview.scanle = max;
  364. self.preview.spaceWidth = (self.contentWidth.constant - self.PDFWidth.constant)/2;
  365. self.preview.spaceHeight = (self.contentHeight.constant - self.PDFHeight.constant)/2;
  366. CGSize paperSize = CGSizeZero;
  367. NSInteger tScale = 0;
  368. if (self.PDFPrint.splitType == kKMPDFPosterSplitType_PageNumber) {
  369. CGFloat w = (realityPDFW + self.PDFPrint.overlap * (horizontals.count -1))/self.PDFPrint.columnCount;
  370. CGFloat h = (realityPDFH + self.PDFPrint.overlap * (verticals.count -1))/self.PDFPrint.lineCount;
  371. if (self.PDFPrint.isOriginalPageSize) {
  372. tScale = 100;
  373. paperSize = CGSizeMake(realityPDFW/self.PDFPrint.columnCount, realityPDFW/self.PDFPrint.lineCount);
  374. }else {
  375. tScale = MIN(self.PDFPrint.fullPageSize.width/w, self.PDFPrint.fullPageSize.height/h) * 100;
  376. paperSize = self.PDFPrint.fullPageSize;
  377. }
  378. } else {
  379. paperSize = self.PDFPrint.splitSize;
  380. tScale = (NSInteger)(((realityPDFW + self.PDFPrint.overlap * (horizontals.count -1))/realityPDFW) *self.PDFPrint.scale*100);
  381. }
  382. NSInteger tPagesCount = (NSInteger)(verticals.count* horizontals.count);
  383. self.zoomLabel.stringValue = [NSString stringWithFormat:@"%@ %ld%% %@ %ld", NSLocalizedString(@"Scale:", nil), tScale, NSLocalizedString(@"Pages:", nil), tPagesCount];
  384. CGFloat W = (self.PDFPrint.splitSize.width *horizontals.count)/(595/210.0);
  385. CGFloat H = (self.PDFPrint.splitSize.height *verticals.count)/(842/297.0);
  386. paperSize.width = paperSize.width/(595/210.0);
  387. paperSize.height = paperSize.height/(842/297.0);
  388. self.sizeLabel.stringValue = [NSString stringWithFormat:@"%@ x %@ %@",[KMPageSizeTool conversionWithUnit:self.unitComboBox.stringValue value:W],[KMPageSizeTool conversionWithUnit:self.unitComboBox.stringValue value:H],self.unitComboBox.stringValue] ?:@"";
  389. self.pageWidthTextField.stringValue = [KMPageSizeTool conversionWithUnit:self.unitComboBox.stringValue value:(self.PDFPrint.splitSize.width/595 * 210)]?:@"";
  390. self.pageHeightTextField.stringValue = [KMPageSizeTool conversionWithUnit:self.unitComboBox.stringValue value:(self.PDFPrint.splitSize.height/842 * 297)]?:@"";
  391. if ([self.filePageSizeBox indexOfSelectedItem] == 0) {
  392. self.paperWidthTextField.stringValue = [KMPageSizeTool conversionWithUnit:self.unitComboBox.stringValue value:(self.PDFPrint.fullPageSize.width/585.0 * 210)];
  393. self.paperHeightTextField.stringValue = [KMPageSizeTool conversionWithUnit:self.unitComboBox.stringValue value:(self.PDFPrint.splitSize.height/842 * 297)]?:@"";
  394. } else {
  395. self.paperWidthTextField.stringValue = [KMPageSizeTool conversionWithUnit:self.unitComboBox.stringValue value:paperSize.width];
  396. self.paperHeightTextField.stringValue = [KMPageSizeTool conversionWithUnit:self.unitComboBox.stringValue value:paperSize.height]?:@"";
  397. }
  398. [self.preview setNeedsDisplay:YES];
  399. }];
  400. }
  401. - (KMPDFPosterPrintContentView *)preview
  402. {
  403. if (!_preview) {
  404. _preview = [[KMPDFPosterPrintContentView alloc] init];
  405. [self.PDFContentView addSubview:self.preview];
  406. }
  407. return _preview;
  408. }
  409. -(void)bringSubviewToFront:(NSView*)view
  410. {
  411. [view removeFromSuperview];
  412. [self.PDFContentView addSubview:view];
  413. }
  414. - (void)reloadPDFData
  415. {
  416. NSInteger pageCount = self.pages.count;
  417. self.currentPageLabel.stringValue = [NSString stringWithFormat:@"%@",@(self.currentPageIndex+1)];
  418. self.totalPageLabel.stringValue = [NSString stringWithFormat:@" / %@",@(pageCount)];
  419. }
  420. - (void)viewFileAtFinder:(NSString *)fileName
  421. {
  422. NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
  423. NSURL *url = [NSURL fileURLWithPath:fileName];
  424. [workspace activateFileViewerSelectingURLs:[NSArray arrayWithObject:url]];
  425. }
  426. - (void)getDrawPages
  427. {
  428. NSMutableArray * pages = [NSMutableArray array];
  429. if (0 == self.pageRangeComboBox.indexOfSelectedItem) {
  430. for (NSUInteger i = 0; i<self.PDFDocument.pageCount; i++) {
  431. PDFPage * page = [self.PDFDocument pageAtIndex:i];
  432. [pages addObject:page];
  433. }
  434. } else if (1 == self.pageRangeComboBox.indexOfSelectedItem) {
  435. for (NSUInteger i = 0; i < self.PDFDocument.pageCount; i ++) {
  436. if (i % 2 == 0) {
  437. PDFPage * page = [self.PDFDocument pageAtIndex:i];
  438. [pages addObject:page];
  439. }
  440. }
  441. } else if (2 == self.pageRangeComboBox.indexOfSelectedItem) {
  442. for (NSUInteger i = 0; i < self.PDFDocument.pageCount; i ++) {
  443. if (i % 2 != 0) {
  444. PDFPage * page = [self.PDFDocument pageAtIndex:i];
  445. [pages addObject:page];
  446. }
  447. }
  448. } else {
  449. KMFileAttribute *fileAttribute = [[KMFileAttribute alloc] init];
  450. fileAttribute.filePath = [self.PDFDocument.documentURL path];
  451. fileAttribute.bAllPage = NO;
  452. fileAttribute.pagesString = _pageRangeComboBox.stringValue;
  453. if (![fileAttribute fetchSelectPages]) {
  454. NSAlert *alert = [[NSAlert alloc] init];
  455. [alert setAlertStyle:NSCriticalAlertStyle];
  456. [alert setMessageText:[NSString stringWithFormat:@"%@ %@",[fileAttribute.filePath lastPathComponent],NSLocalizedString(@"Invalid page range or the page number is out of range. Please try again.", nil)]];
  457. [alert runModal];
  458. return;
  459. }
  460. for (NSNumber * num in [fileAttribute fetchSelectPages]) {
  461. PDFPage * page = [self.PDFDocument pageAtIndex:(num.integerValue - 1)];
  462. [pages addObject:page];
  463. }
  464. }
  465. self.pages = pages;
  466. }
  467. #pragma mark - Button Event
  468. - (IBAction)buttonItemClick_Done:(id)sender
  469. {
  470. [self.window makeFirstResponder:self.preview];
  471. if (self.pages.count < 1) {
  472. NSAlert *alert = [[NSAlert alloc] init];
  473. [alert setAlertStyle:NSCriticalAlertStyle];
  474. [alert setMessageText:[NSString stringWithFormat:@"%@ %@",[[self.PDFDocument.documentURL path]lastPathComponent],NSLocalizedString(@"Invalid page range or the page number is out of range. Please try again.", nil)]];
  475. [alert runModal];
  476. return;
  477. }
  478. self.PDFPrint.cropPages = self.pages;
  479. if (self.PDFPrint.isLabel) {
  480. self.PDFPrint.labelString = self.labelTextField.stringValue;
  481. }
  482. NSString * fileName = [NSString stringWithFormat:@"%@_Poster",self.PDFDocument.documentURL.lastPathComponent.stringByDeletingPathExtension];
  483. KMSavePanelAccessoryController *panelAccessoryController = [[KMSavePanelAccessoryController alloc] init];
  484. NSSavePanel *savePanel = [NSSavePanel savePanel];
  485. savePanel.nameFieldStringValue = fileName;
  486. savePanel.allowedFileTypes = @[@"pdf"];
  487. savePanel.accessoryView = panelAccessoryController.view;
  488. [savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
  489. if (result) {
  490. [self showWaitting];
  491. [[KMPosterPrintManager defaultManager] savePath:savePanel.URL.path posterPrint:self.PDFPrint completionHandler:^(BOOL success) {
  492. [self hideWaitting];
  493. if (success) {
  494. if (panelAccessoryController.openAutomaticButton.state == NSControlStateValueOn) {
  495. [self close];
  496. [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:savePanel.URL display:YES completionHandler:^(NSDocument * _Nullable document, BOOL documentWasAlreadyOpen, NSError * _Nullable error) {
  497. }];
  498. } else {
  499. [self viewFileAtFinder:savePanel.URL.path];
  500. }
  501. }
  502. }];
  503. }
  504. }];
  505. }
  506. - (IBAction)buttonItemClick_Cancel:(id)sender
  507. {
  508. [self close];
  509. }
  510. - (IBAction)buttonItemClick_Print:(id)sender
  511. {
  512. [self.window makeFirstResponder:self.preview];
  513. if (self.pages.count < 1) {
  514. NSAlert *alert = [[NSAlert alloc] init];
  515. [alert setAlertStyle:NSCriticalAlertStyle];
  516. [alert setMessageText:[NSString stringWithFormat:@"%@ %@",[[self.PDFDocument.documentURL path]lastPathComponent],NSLocalizedString(@"Invalid page range or the page number is out of range. Please try again.", nil)]];
  517. [alert runModal];
  518. return;
  519. }
  520. self.PDFPrint.cropPages = self.pages;
  521. if (self.PDFPrint.isLabel) {
  522. self.PDFPrint.labelString = self.labelTextField.stringValue;
  523. }
  524. NSString * fileName = nil;
  525. if (![[NSFileManager defaultManager] fileExistsAtPath:kPosterPrintFolderPath]) {
  526. if (![[NSFileManager defaultManager] createDirectoryAtPath:kPosterPrintFolderPath withIntermediateDirectories:NO attributes:nil error:nil]) {
  527. return;
  528. }
  529. }
  530. fileName = @"Poster.pdf";
  531. fileName = [kPosterPrintFolderPath stringByAppendingPathComponent:fileName];
  532. [self showWaitting];
  533. [[KMPosterPrintManager defaultManager] savePath:fileName posterPrint:self.PDFPrint completionHandler:^(BOOL success) {
  534. [self hideWaitting];
  535. if (success) {
  536. PDFDocument * pdf = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:fileName]];
  537. NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
  538. NSPrintOperation *printOperation = nil;
  539. if ([pdf respondsToSelector:@selector(printOperationForPrintInfo:scalingMode:autoRotate:)]){
  540. printOperation = [pdf printOperationForPrintInfo:printInfo scalingMode:kPDFPrintPageScaleNone autoRotate:YES];
  541. }
  542. [printOperation runOperationModalForWindow:self.window delegate:self didRunSelector:nil contextInfo:NULL];
  543. }
  544. }];
  545. }
  546. - (IBAction)buttonItemClick_CutMarks:(id)sender
  547. {
  548. if ( NSOnState == self.cutMarksButton.state) {
  549. self.PDFPrint.isCut = YES;
  550. } else {
  551. self.PDFPrint.isCut = NO;
  552. }
  553. }
  554. - (IBAction)buttonItemClick_Labels:(id)sender
  555. {
  556. if ( NSOnState == self.labelButton.state) {
  557. self.PDFPrint.isLabel = YES;
  558. [self.labelTextField setEditable:YES];
  559. [self.labelTextField becomeFirstResponder];
  560. } else {
  561. self.PDFPrint.isLabel = NO;
  562. [self.labelTextField setEditable:NO];
  563. self.labelTextField.stringValue = @"";
  564. }
  565. }
  566. - (IBAction)buttonItemClick_Orientation:(id)sender
  567. {
  568. if ( NSOnState == self.landscapeButton.state) {
  569. self.PDFPrint.direction = kKMPDFPosterPrintDirection_Landscape;
  570. } else if(NSOnState == self.portraitButton.state){
  571. self.PDFPrint.direction = kKMPDFPosterPrintDirection_Portrait;
  572. }
  573. [self reloadPDFView];
  574. }
  575. - (IBAction)buttonItemClick_Next:(id)sender
  576. {
  577. if (self.pages.count > self.currentPageIndex + 1) {
  578. self.currentPageIndex ++;
  579. [self reloadPDFData];
  580. [self reloadPDFView];
  581. }
  582. }
  583. - (IBAction)buttonItemClick_Previous:(id)sender
  584. {
  585. if (self.currentPageIndex != 0) {
  586. self.currentPageIndex --;
  587. [self reloadPDFData];
  588. [self reloadPDFView];
  589. }
  590. }
  591. - (IBAction)comboBoxItemClick_PageRange:(id)sender
  592. {
  593. if (0 == [self.pageRangeComboBox indexOfSelectedItem] ||
  594. 1 == [self.pageRangeComboBox indexOfSelectedItem] ||
  595. 2 == [self.pageRangeComboBox indexOfSelectedItem]) {
  596. self.pageRangeComboBox.delegate = nil;
  597. [self.window makeFirstResponder:self];
  598. [self.pageRangeComboBox setEditable:NO];
  599. [self getDrawPages];
  600. if (self.pages.count > 0) {
  601. self.currentPageIndex = 0;
  602. [self reloadPDFView];
  603. [self reloadPDFData];
  604. }
  605. } else if (3 == [self.pageRangeComboBox indexOfSelectedItem]) {
  606. self.pageRangeComboBox.delegate = self;
  607. [self.pageRangeComboBox setStringValue:@""];
  608. [self.pageRangeComboBox setEditable:YES];
  609. [self.window makeFirstResponder:self.pageRangeComboBox];
  610. }
  611. }
  612. - (IBAction)comboBoxItemClick_SplitSize:(id)sender
  613. {
  614. self.overlapTextField.stringValue = @"0";
  615. self.PDFPrint.overlap = 0;
  616. self.pageWidthTextField.enabled = NO;
  617. self.pageHeightTextField.enabled = NO;
  618. if ([_splitSizeComboBox indexOfSelectedItem] == _splitSizeComboBox.numberOfItems - 1) {
  619. self.PDFPrint.splitSize = CGSizeMake(595, 842);
  620. self.pageWidthTextField.enabled = YES;
  621. self.pageHeightTextField.enabled = YES;
  622. } else {
  623. CGSize tSize = [KMPageSizeTool getPaperSizeWithPaperName:self.splitSizeComboBox.stringValue];
  624. self.PDFPrint.splitSize = CGSizeMake(tSize.width * 595.0/210, tSize.height * 842.0/297.0);
  625. }
  626. CGFloat multiple = (MAX(self.PDFPrint.splitSize.height, self.PDFPrint.splitSize.width)/842);
  627. _PDFPrint.edgeInsets = NSEdgeInsetsMake(50 * multiple, 60 * multiple, 50 * multiple, 60 * multiple);
  628. [self reloadPDFView];
  629. }
  630. - (IBAction)comboBoxItemClick_fullPageSize:(id)sender
  631. {
  632. self.PDFPrint.isOriginalPageSize = NO;
  633. self.paperWidthTextField.enabled = NO;
  634. self.paperHeightTextField.enabled = NO;
  635. if ([self.filePageSizeBox indexOfSelectedItem] == 0) {
  636. self.PDFPrint.isOriginalPageSize = YES;
  637. } else if ([self.filePageSizeBox indexOfSelectedItem] == _splitSizeComboBox.numberOfItems - 1){
  638. self.PDFPrint.fullPageSize = CGSizeMake(595, 842);
  639. self.paperWidthTextField.enabled = YES;
  640. self.paperHeightTextField.enabled = YES;
  641. } else {
  642. CGSize tSize = [KMPageSizeTool getPaperSizeWithPaperName:self.filePageSizeBox.stringValue];
  643. self.PDFPrint.fullPageSize = CGSizeMake(tSize.width * 595.0/210, tSize.height * 842.0/297);
  644. }
  645. self.overlapTextField.stringValue = @"0";
  646. self.PDFPrint.overlap = 0;
  647. CGFloat multiple = (MAX(self.PDFPrint.fullPageSize.height, self.PDFPrint.fullPageSize.width)/842);
  648. _PDFPrint.fullPageEdgeInsets = NSEdgeInsetsMake(50 * multiple, 60 * multiple, 50 * multiple, 60 * multiple);
  649. [self reloadPDFView];
  650. }
  651. - (IBAction)buttonItemClick_ReversePage:(id)sender
  652. {
  653. if (NSOnState == self.reverseButton.state) {
  654. self.PDFPrint.isReversePage = YES;
  655. } else {
  656. self.PDFPrint.isReversePage = NO;
  657. }
  658. [self reloadPDFView];
  659. }
  660. - (IBAction)comboBoxItemClick_Unit:(id)sender
  661. {
  662. if ([self.unitComboBox indexOfSelectedItem] == 1) {
  663. self.unitTLabel.stringValue = self.unitT1Label.stringValue = self.overlapUnit.stringValue = NSLocalizedString(@"mm", nil);
  664. } else if([self.unitComboBox indexOfSelectedItem] == 0){
  665. self.unitTLabel.stringValue = self.unitT1Label.stringValue = self.overlapUnit.stringValue = NSLocalizedString(@"cm", nil);
  666. } else {
  667. self.unitTLabel.stringValue = self.unitT1Label.stringValue = self.overlapUnit.stringValue = NSLocalizedString(@"in", nil);
  668. }
  669. self.overlapTextField.stringValue = @"0";
  670. self.PDFPrint.overlap = self.overlapTextField.integerValue;
  671. [self reloadPDFView];
  672. }
  673. - (IBAction)comboBoxItemClick_CommentsForms:(id)sender
  674. {
  675. if (0 == [self.commentsFormsComboBox indexOfSelectedItem]) {
  676. self.PDFPrint.commentsForms = kKMPDFPosterCommentsForms_Documents;
  677. } else if(1 == [self.commentsFormsComboBox indexOfSelectedItem]){
  678. self.PDFPrint.commentsForms = kKMPDFPosterCommentsForms_DocumentMarkups;
  679. } else if(2 == [self.commentsFormsComboBox indexOfSelectedItem]){
  680. self.PDFPrint.commentsForms = kKMPDFPosterCommentsForms_DocumentStamps;
  681. }
  682. [self reloadPDFView];
  683. }
  684. - (IBAction)comboBoxItemClick_PagesPer:(id)sender
  685. {
  686. if ( 5!= [self.selectPerComboBox indexOfSelectedItem]) {
  687. self.columnCountText.editable = NO;
  688. self.lineCountText.editable = NO;
  689. if (0 == [self.selectPerComboBox indexOfSelectedItem]) {
  690. self.PDFPrint.columnCount = 1;
  691. self.PDFPrint.lineCount = 2;
  692. } else if(1 == [self.selectPerComboBox indexOfSelectedItem]){
  693. self.PDFPrint.columnCount = 2;
  694. self.PDFPrint.lineCount = 2;
  695. } else if(2 == [self.selectPerComboBox indexOfSelectedItem]){
  696. self.PDFPrint.columnCount = 2;
  697. self.PDFPrint.lineCount = 3;
  698. } else if(3 == [self.selectPerComboBox indexOfSelectedItem]){
  699. self.PDFPrint.columnCount = 3;
  700. self.PDFPrint.lineCount = 3;
  701. } else if(4 == [self.selectPerComboBox indexOfSelectedItem]){
  702. self.PDFPrint.columnCount = 4;
  703. self.PDFPrint.lineCount = 4;
  704. }
  705. self.columnCountText.stringValue = [NSString stringWithFormat:@"%ld",self.PDFPrint.columnCount];
  706. self.lineCountText.stringValue = [NSString stringWithFormat:@"%ld",self.PDFPrint.lineCount];
  707. self.columnCountText.selectable = NO;
  708. self.lineCountText.selectable = NO;
  709. } else {
  710. self.PDFPrint.columnCount = 2;
  711. self.PDFPrint.lineCount = 2;
  712. self.columnCountText.stringValue = @"2";
  713. self.lineCountText.stringValue = @"2";
  714. self.columnCountText.editable = YES;
  715. self.lineCountText.editable = YES;
  716. self.columnCountText.selectable = YES;
  717. self.lineCountText.selectable = YES;
  718. }
  719. [self reloadPDFView];
  720. }
  721. - (void)tabView:(NSTabView *)tabView willSelectTabViewItem:(nullable NSTabViewItem *)tabViewItem
  722. {
  723. self.overlapTextField.stringValue = @"0";
  724. self.PDFPrint.overlap = 0;
  725. NSString * identifier = (NSString *)tabViewItem.identifier;
  726. if ([identifier isEqualToString:@"1"]) {
  727. _PDFPrint.splitType = kKMPDFPosterSplitType_PageSize;
  728. } else {
  729. _PDFPrint.splitType = kKMPDFPosterSplitType_PageNumber;
  730. }
  731. [self reloadPDFView];
  732. }
  733. #pragma mark - NSTextFieldDelegate Methods
  734. - (void)controlTextDidEndEditing:(NSNotification *)notification
  735. {
  736. NSTextField *textField = (NSTextField *)[notification object];
  737. if (textField == self.currentPageLabel) {
  738. NSInteger index = [[self.currentPageLabel stringValue] integerValue];
  739. NSInteger pageCount = self.pages.count;
  740. if (index > 0 && index <= pageCount) {
  741. self.currentPageIndex = index - 1;
  742. [self reloadPDFView];
  743. } else {
  744. self.currentPageLabel.stringValue = [NSString stringWithFormat:@"%@",@(1)];
  745. }
  746. } else if (textField == self.scaleTextField) {
  747. if (self.scaleTextField.integerValue <= 0) {
  748. self.scaleTextField.stringValue = @"100";
  749. }
  750. self.PDFPrint.scale = self.scaleTextField.integerValue / 100.0;
  751. [self reloadPDFView];
  752. } else if (textField == self.pageRangeComboBox) {
  753. [self getDrawPages];
  754. if (self.pages.count > 0) {
  755. self.currentPageIndex = 0;
  756. [self reloadPDFView];
  757. [self reloadPDFData];
  758. }
  759. } else if (textField == self.columnCountText) {
  760. if ( 5!= [self.selectPerComboBox indexOfSelectedItem]) {
  761. return;
  762. }
  763. if (self.columnCountText.integerValue < 1) {
  764. self.columnCountText.stringValue = @"1";
  765. } else if (self.columnCountText.integerValue > 99){
  766. self.columnCountText.stringValue = @"99";
  767. }
  768. self.PDFPrint.columnCount = self.columnCountText.integerValue;
  769. [self reloadPDFView];
  770. } else if (textField == self.lineCountText) {
  771. if ( 5!= [self.selectPerComboBox indexOfSelectedItem]) {
  772. return;
  773. }
  774. if (self.lineCountText.integerValue < 1) {
  775. self.lineCountText.stringValue = @"1";
  776. } else if (self.lineCountText.integerValue > 99){
  777. self.lineCountText.stringValue = @"99";
  778. }
  779. self.PDFPrint.lineCount = self.lineCountText.integerValue;
  780. [self reloadPDFView];
  781. } else if (textField == self.pageWidthTextField || textField == self.paperWidthTextField) {
  782. self.overlapTextField.stringValue = @"0";
  783. self.PDFPrint.overlap = 0;
  784. CGFloat over = [[textField stringValue] floatValue];
  785. if ([self.unitComboBox indexOfSelectedItem] == 0) {
  786. over *= 595.0/21;
  787. } else if([self.unitComboBox indexOfSelectedItem] == 3){
  788. over *= 595.0/210 * 25.4;
  789. } else {
  790. over *= 595.0/210;
  791. }
  792. CGSize size = CGSizeZero;
  793. if (textField == self.pageWidthTextField ) {
  794. size = self.PDFPrint.splitSize;
  795. size.width = over;
  796. self.PDFPrint.splitSize = size;
  797. } else {
  798. size = self.PDFPrint.fullPageSize;
  799. size.width = over;
  800. self.PDFPrint.fullPageSize = size;
  801. }
  802. [self reloadPDFView];
  803. } else if (textField == self.pageHeightTextField || textField == self.paperHeightTextField) {
  804. self.overlapTextField.stringValue = @"0";
  805. self.PDFPrint.overlap = 0;
  806. CGFloat over = [[textField stringValue] floatValue];
  807. if ([self.unitComboBox indexOfSelectedItem] == 0) {
  808. over *= 842.0/29.7;
  809. } else if([self.unitComboBox indexOfSelectedItem] == 3){
  810. over *= 842.0/297 * 25.4;
  811. } else {
  812. over *= 842.0/297;
  813. }
  814. CGSize size = CGSizeZero;
  815. if (textField == self.pageHeightTextField ) {
  816. size = self.PDFPrint.splitSize;
  817. size.height = over;
  818. self.PDFPrint.splitSize = size;
  819. } else {
  820. size = self.PDFPrint.fullPageSize;
  821. size.height = over;
  822. self.PDFPrint.fullPageSize = size;
  823. }
  824. [self reloadPDFView];
  825. }
  826. }
  827. - (void)controlTextDidChange:(NSNotification *)notification {
  828. NSTextField *textField = (NSTextField *)[notification object];
  829. if (textField == self.currentPageLabel || textField == self.columnCountText || textField == self.lineCountText) {
  830. NSString *string = [textField.formatter stringFromNumber:[NSNumber numberWithFloat:[textField.stringValue integerValue]]];
  831. textField.stringValue = string;
  832. } else if (textField == self.overlapTextField){
  833. CGFloat maxOverlap = MIN(self.PDFPrint.splitSize.width, self.PDFPrint.splitSize.height);
  834. if (self.PDFPrint.splitType == kKMPDFPosterSplitType_PageNumber) {
  835. maxOverlap = MIN(self.PDFPrint.fullPageSize.width, self.PDFPrint.fullPageSize.height);
  836. }
  837. CGFloat over = [[textField stringValue] floatValue];
  838. if ([self.unitComboBox indexOfSelectedItem] == 0) {
  839. over *= 28.4;
  840. } else if([self.unitComboBox indexOfSelectedItem] == 3){
  841. over *= 72.0;
  842. } else {
  843. over *= 2.84; //595/210
  844. }
  845. if (over <= 0 || over > maxOverlap/2) {
  846. self.overlapTextField.stringValue = @"0";
  847. self.PDFPrint.overlap = 0;
  848. } else {
  849. self.PDFPrint.overlap = over;
  850. }
  851. [self reloadPDFView];
  852. }
  853. }
  854. #pragma mark - show / hide Waiting
  855. - (void)showWaitting
  856. {
  857. if (!_posterMaskView) {
  858. _posterMaskView = [[KMBookletMaskView alloc] initWithFrame:NSMakeRect(0, 0, self.window.frame.size.width, self.window.frame.size.height)];
  859. }
  860. [self.window.contentView addSubview:self.posterMaskView];
  861. }
  862. - (void)hideWaitting
  863. {
  864. [self.posterMaskView removeFromSuperview];
  865. }
  866. @end