Revision: 4377
http://skim-app.svn.sourceforge.net/skim-app/?rev=4377&view=rev
Author: hofman
Date: 2008-08-11 20:11:06 +0000 (Mon, 11 Aug 2008)
Log Message:
-----------
Fix synctex support. Apparently synctex uses an inverted coordinate system
(top-down) with the same scale as the PDF, and moreover a shifted line number.
Modified Paths:
--------------
trunk/SKPDFDocument.m
trunk/SKPDFSynchronizer.h
trunk/SKPDFSynchronizer.m
trunk/SKPDFView.m
Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m 2008-08-11 18:50:14 UTC (rev 4376)
+++ trunk/SKPDFDocument.m 2008-08-11 20:11:06 UTC (rev 4377)
@@ -1494,9 +1494,12 @@
}
}
-- (void)synchronizer:(SKPDFSynchronizer *)synchronizer
foundLocation:(NSPoint)point atPageIndex:(unsigned int)pageIndex {
+- (void)synchronizer:(SKPDFSynchronizer *)synchronizer
foundLocation:(NSPoint)point atPageIndex:(unsigned int)pageIndex
isSyncTeX:(BOOL)isSyncTeX {
+ PDFPage *page = [[self pdfDocument] pageAtIndex:pageIndex];
+ if (isSyncTeX)
+ point.y = NSMaxY([page boundsForBox:kPDFDisplayBoxMediaBox]) - point.y;
if ([[NSUserDefaults standardUserDefaults]
boolForKey:SKShouldHighlightSearchResultsKey])
- [[self mainWindowController] addTemporaryAnnotationForPoint:point
onPage:[[self pdfDocument] pageAtIndex:pageIndex]];
+ [[self mainWindowController] addTemporaryAnnotationForPoint:point
onPage:page];
[[self pdfView] displayLineAtPoint:point inPageAtIndex:pageIndex];
}
@@ -2007,7 +2010,7 @@
PDFSelection *sel = [page selectionForLineAtPoint:point];
NSRect rect = sel ? [sel boundsForPage:page] : NSMakeRect(point.x -
20.0, point.y - 5.0, 40.0, 10.0);
- [[self synchronizer] findFileAndLineForLocation:point inRect:rect
atPageIndex:pageIndex];
+ [[self synchronizer] findFileAndLineForLocation:point inRect:rect
pageBounds:[page boundsForBox:kPDFDisplayBoxMediaBox] atPageIndex:pageIndex];
}
}
Modified: trunk/SKPDFSynchronizer.h
===================================================================
--- trunk/SKPDFSynchronizer.h 2008-08-11 18:50:14 UTC (rev 4376)
+++ trunk/SKPDFSynchronizer.h 2008-08-11 20:11:06 UTC (rev 4377)
@@ -68,7 +68,7 @@
- (NSString *)fileName;
- (void)setFileName:(NSString *)newFileName;
-- (void)findFileAndLineForLocation:(NSPoint)point inRect:(NSRect)rect
atPageIndex:(unsigned int)pageIndex;
+- (void)findFileAndLineForLocation:(NSPoint)point inRect:(NSRect)rect
pageBounds:(NSRect)bounds atPageIndex:(unsigned int)pageIndex;
- (void)findPageAndLocationForLine:(int)line inFile:(NSString *)file;
- (void)stopDOServer;
@@ -78,5 +78,5 @@
@interface NSObject (SKPDFSynchronizerDelegate)
- (void)synchronizer:(SKPDFSynchronizer *)synchronizer foundLine:(int)line
inFile:(NSString *)file;
-- (void)synchronizer:(SKPDFSynchronizer *)synchronizer
foundLocation:(NSPoint)point atPageIndex:(unsigned int)pageIndex;
+- (void)synchronizer:(SKPDFSynchronizer *)synchronizer
foundLocation:(NSPoint)point atPageIndex:(unsigned int)pageIndex
isSyncTeX:(BOOL)isSyncTeX;
@end
Modified: trunk/SKPDFSynchronizer.m
===================================================================
--- trunk/SKPDFSynchronizer.m 2008-08-11 18:50:14 UTC (rev 4376)
+++ trunk/SKPDFSynchronizer.m 2008-08-11 20:11:06 UTC (rev 4377)
@@ -69,14 +69,14 @@
@protocol SKPDFSynchronizerServerThread
- (oneway void)stopRunning;
-- (oneway void)serverFindFileAndLineForLocation:(NSPoint)point
inRect:(NSRect)rect atPageIndex:(unsigned int)pageIndex;
+- (oneway void)serverFindFileAndLineForLocation:(NSPoint)point
inRect:(NSRect)rect pageBounds:(NSRect)bounds atPageIndex:(unsigned
int)pageIndex;
- (oneway void)serverFindPageAndLocationForLine:(int)line inFile:(bycopy
NSString *)file;
@end
@protocol SKPDFSynchronizerMainThread
- (void)setLocalServer:(byref id)anObject;
- (oneway void)serverFoundLine:(int)line inFile:(bycopy NSString *)file;
-- (oneway void)serverFoundLocation:(NSPoint)point atPageIndex:(unsigned
int)pageIndex;
+- (oneway void)serverFoundLocation:(NSPoint)point atPageIndex:(unsigned
int)pageIndex isSyncTeX:(BOOL)isSyncTeX;
@end
#pragma mark -
@@ -311,8 +311,8 @@
#pragma mark | API
-- (void)findFileAndLineForLocation:(NSPoint)point inRect:(NSRect)rect
atPageIndex:(unsigned int)pageIndex {
- [serverOnServerThread serverFindFileAndLineForLocation:point inRect:rect
atPageIndex:pageIndex];
+- (void)findFileAndLineForLocation:(NSPoint)point inRect:(NSRect)rect
pageBounds:(NSRect)bounds atPageIndex:(unsigned int)pageIndex {
+ [serverOnServerThread serverFindFileAndLineForLocation:point inRect:rect
pageBounds:bounds atPageIndex:pageIndex];
}
- (void)findPageAndLocationForLine:(int)line inFile:(NSString *)file {
@@ -326,9 +326,9 @@
[delegate synchronizer:self foundLine:line inFile:file];
}
-- (oneway void)serverFoundLocation:(NSPoint)point atPageIndex:(unsigned
int)pageIndex {
- if ([self shouldKeepRunning] && [delegate
respondsToSelector:@selector(synchronizer:foundLocation:atPageIndex:)])
- [delegate synchronizer:self foundLocation:point atPageIndex:pageIndex];
+- (oneway void)serverFoundLocation:(NSPoint)point atPageIndex:(unsigned
int)pageIndex isSyncTeX:(BOOL)isSyncTeX {
+ if ([self shouldKeepRunning] && [delegate
respondsToSelector:@selector(synchronizer:foundLocation:atPageIndex:isSyncTeX:)])
+ [delegate synchronizer:self foundLocation:point atPageIndex:pageIndex
isSyncTeX:isSyncTeX];
}
#pragma mark | Server thread
@@ -448,7 +448,7 @@
return rv;
}
-- (BOOL)pdfsyncFindFileLine:(int *)line file:(NSString **)file
forLocation:(NSPoint)point inRect:(NSRect)rect atPageIndex:(unsigned
int)pageIndex {
+- (BOOL)pdfsyncFindFileLine:(int *)line file:(NSString **)file
forLocation:(NSPoint)point inRect:(NSRect)rect pageBounds:(NSRect)bounds
atPageIndex:(unsigned int)pageIndex {
BOOL rv = NO;
if (pageIndex < [pages count]) {
@@ -581,12 +581,12 @@
return rv;
}
-- (BOOL)synctexFindFileLine:(int *)line file:(NSString **)file
forLocation:(NSPoint)point inRect:(NSRect)rect atPageIndex:(unsigned
int)pageIndex {
+- (BOOL)synctexFindFileLine:(int *)line file:(NSString **)file
forLocation:(NSPoint)point inRect:(NSRect)rect pageBounds:(NSRect)bounds
atPageIndex:(unsigned int)pageIndex {
BOOL rv = NO;
- if (synctex_edit_query(scanner, (int)pageIndex + 1, PDF_TO_SYNC(point.x),
PDF_TO_SYNC(point.y)) > 0) {
+ if (synctex_edit_query(scanner, (int)pageIndex + 1, point.x,
NSMaxY(bounds) - point.y) > 0) {
synctex_node_t node = synctex_next_result(scanner);
if (node) {
- *line = synctex_node_line(node);
+ *line = synctex_node_line(node) - 1;
*file =
SKTeXSourceFile(SKPathFromFileSystemRepresentation(synctex_scanner_get_name(scanner,
synctex_node_tag(node))), [[self fileName] stringByDeletingLastPathComponent]);
rv = YES;
}
@@ -597,12 +597,12 @@
- (BOOL)synctexFindPage:(unsigned int *)pageIndex location:(NSPoint *)point
forLine:(int)line inFile:(NSString *)file {
BOOL rv = NO;
NSString *filename = [filenames objectForKey:file] ?: [file
lastPathComponent];
- if (synctex_display_query(scanner, [filename fileSystemRepresentation],
line, 0) > 0) {
+ if (synctex_display_query(scanner, [filename fileSystemRepresentation],
line + 1, 0) > 0) {
synctex_node_t node = synctex_next_result(scanner);
if (node) {
unsigned int page = synctex_node_page(node);
*pageIndex = page > 0 ? page - 1 : page;
- *point = NSMakePoint(SYNC_TO_PDF(synctex_node_h(node)),
SYNC_TO_PDF(synctex_node_v(node)));
+ *point = NSMakePoint(synctex_node_visible_h(node),
synctex_node_visible_v(node));
rv = YES;
}
}
@@ -640,16 +640,16 @@
return rv;
}
-- (oneway void)serverFindFileAndLineForLocation:(NSPoint)point
inRect:(NSRect)rect atPageIndex:(unsigned int)pageIndex {
+- (oneway void)serverFindFileAndLineForLocation:(NSPoint)point
inRect:(NSRect)rect pageBounds:(NSRect)bounds atPageIndex:(unsigned
int)pageIndex {
if ([self shouldKeepRunning] && [self parseSyncFileIfNeeded]) {
int foundLine = -1;
NSString *foundFile = nil;
BOOL success = NO;
if (isPdfsync)
- success = [self pdfsyncFindFileLine:&foundLine file:&foundFile
forLocation:point inRect:rect atPageIndex:pageIndex];
+ success = [self pdfsyncFindFileLine:&foundLine file:&foundFile
forLocation:point inRect:rect pageBounds:bounds atPageIndex:pageIndex];
else
- success = [self synctexFindFileLine:&foundLine file:&foundFile
forLocation:point inRect:rect atPageIndex:pageIndex];
+ success = [self synctexFindFileLine:&foundLine file:&foundFile
forLocation:point inRect:rect pageBounds:bounds atPageIndex:pageIndex];
if (success && [self shouldKeepRunning])
[serverOnMainThread serverFoundLine:foundLine inFile:foundFile];
@@ -670,7 +670,7 @@
success = [self synctexFindPage:&foundPageIndex
location:&foundPoint forLine:line inFile:file];
if (success && [self shouldKeepRunning])
- [serverOnMainThread serverFoundLocation:foundPoint
atPageIndex:foundPageIndex];
+ [serverOnMainThread serverFoundLocation:foundPoint
atPageIndex:foundPageIndex isSyncTeX:isPdfsync == NO];
}
}
Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m 2008-08-11 18:50:14 UTC (rev 4376)
+++ trunk/SKPDFView.m 2008-08-11 20:11:06 UTC (rev 4377)
@@ -3881,7 +3881,7 @@
PDFSelection *sel = [page selectionForLineAtPoint:location];
NSRect rect = sel ? [sel boundsForPage:page] : NSMakeRect(location.x -
20.0, location.y - 5.0, 40.0, 10.0);
- [[document synchronizer] findFileAndLineForLocation:location
inRect:rect atPageIndex:pageIndex];
+ [[document synchronizer] findFileAndLineForLocation:location
inRect:rect pageBounds:[page boundsForBox:kPDFDisplayBoxMediaBox]
atPageIndex:pageIndex];
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit