Commits

Anonymous committed 94f503e

rendering kinda works

Comments (0)

Files changed (5)

 
 @property (nonatomic, readonly) pdftron::PDF::PDFDoc * tronPDFDoc;
 
--(NSRect) makeDocRect;
-
 @end
     [super dealloc];
 }
 
-- (NSRect) makeDocRect {
-    return NSMakeRect(0.0, 0.0, 1200.0, 1200.0);
-}
-
 @end
 
 - (void)setDocument:(MyPDFDoc*) myDoc;
 
+- (void)windowResized:(NSNotification *)notification;
 
 
 @end
 - (void)awakeFromNib {
     [super awakeFromNib];
     _tronPDFView = new pdftron::PDF::PDFView();
+    /*
+    NSRect bound = [self bounds];
+    double width = (double) bound.size.width;
+    double height = (double) bound.size.height;
+    _tronPDFView->OnSize(width, height);
+     */
 }
 
 - (void)drawRect:(NSRect)dirtyRect {
-    NSRect svFrame = [[self superview] frame];
-    NSRect svBound = [[self superview] bounds];
-    NSRect rect = [self bounds];
-    NSPoint p = rect.origin;
-    NSSize s = rect.size;
-    NSLog(@"self bound: x: w: %0.4f, h: %0.4f", s.width, s.height);
-    NSLog(@"super frame: x: w: %0.4f, h: %0.4f", svFrame.size.width, svFrame.size.height);
-    NSLog(@"self bound: x: w: %0.4f, h: %0.4f", svBound.size.width, svBound.size.height);
-    NSLog(@"dirtyRect: x: %0.4f, y: %0.4f, w: %0.4f, h: %0.4f", dirtyRect.origin.x, dirtyRect.origin.y, dirtyRect.size.width, dirtyRect.size.height);
+    /*
+    [[NSColor redColor] set];
+    NSRectFill([self bounds]);
+     */
 
     if (_tronPDFView->GetDoc()) {
-        NSRect oldRect = [self frame];
-        oldRect.size.width = svBound.size.width;
-        [self setFrame: oldRect];
-        [self setBounds: oldRect];
+        /*
+        double width = _tronPDFView->GetCanvasWidth();
+        double height = _tronPDFView->GetCanvasHeight();
         
-        _tronPDFView->OnSize((int) [self bounds].size.width, (int) [self bounds].size.height);
+        [self setFrame:NSMakeRect(0, 0, width, height)];
+        [self setBounds:NSMakeRect(0, 0, width, height)];
+        */
+        
+        //_tronPDFView->OnSize((int) svFrame.size.width, (int) svFrame.size.height);
+
         
         const char* bgra = _tronPDFView->GetBuffer();
         if (bgra) {
             
             NSRect imageRect;
             imageRect.origin = NSZeroPoint;
-            imageRect.size.width = s.width;
-            imageRect.size.height = s.height;
+            imageRect.size.width = [[self superview] bounds].size.width;
+            imageRect.size.height = [[self superview] bounds].size.height;
             CGRect	zCgRect	= NSRectToCGRect(imageRect);
 
             CGContextDrawImage(zCgContextRef, zCgRect, cgImage);
     }
 
 }
+
 /*
 -(BOOL)isFlipped {
     return YES;
 }
 */
 
+- (BOOL)acceptsFirstResponder 
+{
+    return YES;
+}
+
 - (void)dealloc {
-    [super dealloc];
     if (_tronPDFView) {
         free(_tronPDFView);
     }
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+    [super dealloc];
 }
 
-
-
 - (void)setDocument:(MyPDFDoc*) myDoc {
     if (_tronPDFView) {
         _tronPDFView->SetDoc(*(myDoc.tronPDFDoc));
         _tronPDFView->SetRenderBeginProc(beginRendering, NULL);
         _tronPDFView->SetRenderFinishProc(endRendering, NULL);
         _tronPDFView->SetPageSpacing(10, 10, 20, 10);
-        [self setFrame: [myDoc makeDocRect]];
+        [self windowResized:nil];
+      /*
+        double w = _tronPDFView->GetCanvasWidth();
+        double h = _tronPDFView->GetCanvasHeight();
+        NSLog(@"setFrame width: %d, height: %d", w, h);
+        [self setFrame:NSMakeRect(0.0, 0.0, w, h)];
+       */
+    }
+}
+
+- (void)viewDidMoveToWindow
+{
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:NSWindowDidResizeNotification object:[self window]];
+}
+
+- (void)windowResized:(NSNotification *)notification;
+{
+    NSSize win_size = [[self window] frame].size;
+    
+    NSLog(@"window width = %f, window height = %f", win_size.width, win_size.height);
+    
+    NSSize size = [self bounds].size;
+    
+    NSRect svFrame = [[self superview] frame];
+    NSRect svBound = [[self superview] bounds];
+    NSRect rect = [self bounds];
+    NSPoint p = rect.origin;
+    NSSize s = rect.size;
+    NSLog(@"self bound: w: %0.4f, h: %0.4f", s.width, s.height);
+    NSLog(@"self frame: w: %0.4f, h: %0.4f", [self frame].size.width, [self frame].size.height);
+    NSLog(@"super frame: x: w: %0.4f, h: %0.4f", svFrame.size.width, svFrame.size.height);
+    NSLog(@"super bound: x: w: %0.4f, h: %0.4f", svBound.size.width, svBound.size.height);
+    
+    
+    if (_tronPDFView)
+    {
+        _tronPDFView->OnSize((int) svBound.size.width, (int) svBound.size.height);
+    
+        double w = _tronPDFView->GetCanvasWidth();
+        double h = _tronPDFView->GetCanvasHeight();
+        NSLog(@"setFrame width: %d, height: %d", w, h);
+        NSLog(@"setFrame width: %0.4f, height: %0.4f", w, h);
+        [self setFrame:NSMakeRect(0.0, 0.0, w, h)];
+        NSLog(@"result frame: w: %d, h: %d", [self frame].size.width, [self frame].size.height);
+        NSLog(@"result frame: w: %0.4f, h: %0.4f", [self frame].size.width, [self frame].size.height);        
     }
 }
 

cocoapdf.xcodeproj/quincy.mode1v3

 						<key>_historyCapacity</key>
 						<integer>0</integer>
 						<key>bookmark</key>
-						<string>2472670C1207ADAE001BF4F9</string>
+						<string>24A9C833120D555300A86D24</string>
 						<key>history</key>
 						<array>
-							<string>24E4BEB81207A0B600CA10EA</string>
 							<string>247266D51207A845001BF4F9</string>
-							<string>247266D61207A845001BF4F9</string>
-							<string>247266D71207A845001BF4F9</string>
-							<string>247266D81207A845001BF4F9</string>
+							<string>24A9C708120D0D4600A86D24</string>
+							<string>24A9C709120D0D4600A86D24</string>
+							<string>24A9C78B120D343400A86D24</string>
+							<string>24A9C803120D529100A86D24</string>
+							<string>24A9C805120D529100A86D24</string>
+							<string>24A9C82C120D552B00A86D24</string>
+							<string>24A9C82D120D552B00A86D24</string>
 						</array>
 					</dict>
 					<key>SplitCount</key>
 				<key>PBXModuleWindowStatusBarHidden2</key>
 				<false/>
 				<key>RubberWindowFrame</key>
-				<string>237 231 808 543 0 0 1280 778 </string>
+				<string>253 196 808 543 0 0 1280 778 </string>
 			</dict>
 		</dict>
 	</array>
 										<key>_historyCapacity</key>
 										<integer>0</integer>
 										<key>bookmark</key>
-										<string>2472670B1207ADAE001BF4F9</string>
+										<string>24A9C832120D555300A86D24</string>
 										<key>history</key>
 										<array>
 											<string>241D2A8211FBCBED0067260B</string>
 											<string>246738851206E1F400157160</string>
 											<string>24E4BEA71207A02F00CA10EA</string>
 											<string>24E4BECC1207A25400CA10EA</string>
-											<string>24E9E6881207A6ED00CCA218</string>
+											<string>24A9C75D120D2D0A00A86D24</string>
 										</array>
 									</dict>
 									<key>SplitCount</key>
 							<key>GeometryConfiguration</key>
 							<dict>
 								<key>Frame</key>
-								<string>{{0, 0}, {414, 178}}</string>
+								<string>{{0, 0}, {414, 165}}</string>
 								<key>RubberWindowFrame</key>
 								<string>190 177 788 504 0 0 1280 778 </string>
 							</dict>
 							<key>Module</key>
 							<string>PBXNavigatorGroup</string>
 							<key>Proportion</key>
-							<string>178pt</string>
+							<string>165pt</string>
 						</dict>
 						<dict>
 							<key>ContentConfiguration</key>
 							<key>GeometryConfiguration</key>
 							<dict>
 								<key>Frame</key>
-								<string>{{0, 183}, {414, 280}}</string>
+								<string>{{0, 170}, {414, 293}}</string>
 								<key>RubberWindowFrame</key>
 								<string>190 177 788 504 0 0 1280 778 </string>
 							</dict>
 							<key>Module</key>
 							<string>XCDetailModule</string>
 							<key>Proportion</key>
-							<string>280pt</string>
+							<string>293pt</string>
 						</dict>
 					</array>
 					<key>Proportion</key>
 			</array>
 			<key>TableOfContents</key>
 			<array>
-				<string>247266BB1207A70A001BF4F9</string>
+				<string>24A9C6FF120D0B5F00A86D24</string>
 				<string>1CE0B1FE06471DED0097A5F4</string>
-				<string>247266BC1207A70A001BF4F9</string>
+				<string>24A9C700120D0B5F00A86D24</string>
 				<string>1CE0B20306471E060097A5F4</string>
 				<string>1CE0B20506471E060097A5F4</string>
 			</array>
 	<integer>5</integer>
 	<key>WindowOrderList</key>
 	<array>
-		<string>2472670D1207ADAE001BF4F9</string>
-		<string>247266C71207A70A001BF4F9</string>
-		<string>247266C81207A70A001BF4F9</string>
+		<string>24A9C834120D555300A86D24</string>
+		<string>24A9C71A120D0E1200A86D24</string>
+		<string>24A9C71B120D0E1200A86D24</string>
+		<string>1CD10A99069EF8BA00B06720</string>
+		<string>/Users/quincy/Repositories/CocoaPDF/cocoapdf.xcodeproj</string>
+		<string>2492503F11CB2A5D0076F523</string>
 		<string>1C78EAAD065D492600B07095</string>
-		<string>1CD10A99069EF8BA00B06720</string>
-		<string>2492503F11CB2A5D0076F523</string>
-		<string>/Users/quincy/Repositories/CocoaPDF/cocoapdf.xcodeproj</string>
 		<string>24E4BEA112079F7600CA10EA</string>
 	</array>
 	<key>WindowString</key>
 								<key>PBXProjectModuleGUID</key>
 								<string>1CD0528F0623707200166675</string>
 								<key>PBXProjectModuleLabel</key>
-								<string></string>
+								<string>TronPDFView.mm</string>
 								<key>StatusBarVisibility</key>
 								<true/>
 							</dict>
 							<string>218pt</string>
 						</dict>
 						<dict>
+							<key>BecomeActive</key>
+							<true/>
 							<key>ContentConfiguration</key>
 							<dict>
 								<key>PBXProjectModuleGUID</key>
 			<key>TableOfContents</key>
 			<array>
 				<string>2492503F11CB2A5D0076F523</string>
-				<string>247266BE1207A70A001BF4F9</string>
+				<string>24A9C702120D0B5F00A86D24</string>
 				<string>1CD0528F0623707200166675</string>
 				<string>XCMainBuildResultsModuleGUID</string>
 			</array>
 			<key>WindowToolGUID</key>
 			<string>2492503F11CB2A5D0076F523</string>
 			<key>WindowToolIsVisible</key>
-			<false/>
+			<true/>
 		</dict>
 		<dict>
 			<key>FirstTimeWindowDisplayed</key>
 			<key>TableOfContents</key>
 			<array>
 				<string>1CD10A99069EF8BA00B06720</string>
-				<string>247266BF1207A70A001BF4F9</string>
+				<string>24A9C712120D0E1200A86D24</string>
 				<string>1C162984064C10D400B95A72</string>
-				<string>247266C01207A70A001BF4F9</string>
-				<string>247266C11207A70A001BF4F9</string>
-				<string>247266C21207A70A001BF4F9</string>
-				<string>247266C31207A70A001BF4F9</string>
-				<string>247266C41207A70A001BF4F9</string>
+				<string>24A9C713120D0E1200A86D24</string>
+				<string>24A9C714120D0E1200A86D24</string>
+				<string>24A9C715120D0E1200A86D24</string>
+				<string>24A9C716120D0E1200A86D24</string>
+				<string>24A9C717120D0E1200A86D24</string>
 			</array>
 			<key>ToolbarConfiguration</key>
 			<string>xcode.toolbar.config.debugV3</string>
 			<key>TableOfContents</key>
 			<array>
 				<string>1C78EAAD065D492600B07095</string>
-				<string>247266C51207A70A001BF4F9</string>
+				<string>24A9C718120D0E1200A86D24</string>
 				<string>1C78EAAC065D492600B07095</string>
 			</array>
 			<key>ToolbarConfiguration</key>
 			<key>WindowToolGUID</key>
 			<string>1C78EAAD065D492600B07095</string>
 			<key>WindowToolIsVisible</key>
-			<false/>
+			<true/>
 		</dict>
 		<dict>
 			<key>Identifier</key>