Revision: 12948
          http://sourceforge.net/p/skim-app/code/12948
Author:   hofman
Date:     2022-06-25 18:12:38 +0000 (Sat, 25 Jun 2022)
Log Message:
-----------
convenience method to move the reading bar to a line on a page or move to the 
next page

Modified Paths:
--------------
    trunk/SKPDFView.m
    trunk/SKReadingBar.h
    trunk/SKReadingBar.m

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2022-06-25 17:53:47 UTC (rev 12947)
+++ trunk/SKPDFView.m   2022-06-25 18:12:38 UTC (rev 12948)
@@ -566,10 +566,7 @@
         }
         if (page) {
             SKReadingBar *aReadingBar = [[SKReadingBar alloc] 
initWithPage:page];
-            if ([aReadingBar maxLine] != -1)
-                [aReadingBar setCurrentLine:MIN(readingBarLine, [aReadingBar 
maxLine])];
-            else
-                [aReadingBar goToNextLine];
+            [aReadingBar goToLine:readingBarLine onPage:page];
             [self setReadingBar:aReadingBar];
             [aReadingBar release];
         }
@@ -2942,10 +2939,7 @@
                 NSInteger line = [page indexOfLineRectAtPoint:point lower:YES];
                 if ([self hasReadingBar] == NO) {
                     SKReadingBar *aReadingBar = [[SKReadingBar alloc] 
initWithPage:page];
-                    if (line == -1)
-                        [aReadingBar goToNextPage];
-                    else
-                        [aReadingBar setCurrentLine:MIN([aReadingBar maxLine], 
line)];
+                    [aReadingBar goToLine:line onPage:page];
                     [self setReadingBar:aReadingBar];
                     [aReadingBar release];
                     if (invert)
@@ -2955,11 +2949,7 @@
                 } else {
                     oldPage = [readingBar page];
                     oldRect = [readingBar currentBoundsForBox:[self 
displayBox]];
-                    [readingBar setPage:page];
-                    if (line == -1)
-                        [readingBar goToNextPage];
-                    else
-                        [readingBar setCurrentLine:MIN([readingBar maxLine], 
line)];
+                    [readingBar goToLine:line onPage:page];
                     [self setNeedsDisplayInRect:oldRect ofPage:oldPage];
                     [self setNeedsDisplayInRect:[readingBar 
currentBoundsForBox:[self displayBox]] ofPage:[readingBar page]];
                 }
@@ -4568,8 +4558,7 @@
         if ([page isEqual:readingBarPage] == NO || currentLine != [readingBar 
currentLine]) {
             NSRect newRect, oldRect = [readingBar currentBoundsForBox:[self 
displayBox]];
             [self setNeedsDisplayInRect:[readingBar currentBoundsForBox:[self 
displayBox]] ofPage:readingBarPage];
-            [readingBar setPage:page];
-            [readingBar setCurrentLine:currentLine];
+            [readingBar goToLine:currentLine onPage:page];
             newRect = [readingBar currentBoundsForBox:[self displayBox]];
             if ([page isEqual:readingBarPage]) {
                 [self setNeedsDisplayInRect:NSUnionRect(oldRect, newRect) 
ofPage:page];

Modified: trunk/SKReadingBar.h
===================================================================
--- trunk/SKReadingBar.h        2022-06-25 17:53:47 UTC (rev 12947)
+++ trunk/SKReadingBar.h        2022-06-25 18:12:38 UTC (rev 12948)
@@ -63,6 +63,8 @@
 - (BOOL)goToNextPage;
 - (BOOL)goToPreviousPage;
 
+- (void)goToLine:(NSInteger)line onPage:(PDFPage *)page;
+
 - (void)drawForPage:(PDFPage *)pdfPage withBox:(PDFDisplayBox)box 
inContext:(CGContextRef)context;
 - (void)drawForPage:(PDFPage *)pdfPage withBox:(PDFDisplayBox)box 
active:(BOOL)active;
 

Modified: trunk/SKReadingBar.m
===================================================================
--- trunk/SKReadingBar.m        2022-06-25 17:53:47 UTC (rev 12947)
+++ trunk/SKReadingBar.m        2022-06-25 18:12:38 UTC (rev 12948)
@@ -232,6 +232,15 @@
     return [self goToPreviousPageAtTop:YES];
 }
 
+- (void)goToLine:(NSInteger)line onPage:(PDFPage *)aPage {
+    if (page != aPage)
+        [self setPage:aPage];
+    if ([lineRects count] == 0)
+        [self goToNextPageAtTop:YES];
+    else
+        [self setCurrentLine:MAX(0, MIN([self maxLine], line))];
+}
+
 - (void)drawForPage:(PDFPage *)pdfPage withBox:(PDFDisplayBox)box 
inContext:(CGContextRef)context {
     BOOL invert = [[NSUserDefaults standardUserDefaults] 
boolForKey:SKReadingBarInvertKey];
     

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to