Revision: 15339 http://sourceforge.net/p/skim-app/code/15339 Author: hofman Date: 2025-06-01 17:07:28 +0000 (Sun, 01 Jun 2025) Log Message: ----------- implement getting or setting PDF view settings in SKPDFView class
Modified Paths: -------------- trunk/SKMainDocument.m trunk/SKMainWindowController.h trunk/SKMainWindowController.m trunk/SKMainWindowController_FullScreen.m trunk/SKPDFView.h trunk/SKPDFView.m Modified: trunk/SKMainDocument.m =================================================================== --- trunk/SKMainDocument.m 2025-06-01 16:14:03 UTC (rev 15338) +++ trunk/SKMainDocument.m 2025-06-01 17:07:28 UTC (rev 15339) @@ -1818,11 +1818,11 @@ } - (NSDictionary *)pdfViewSettings { - return [[self mainWindowController] currentPDFSettings]; + return [[self pdfView] displaySettings]; } - (void)setPdfViewSettings:(NSDictionary *)pdfViewSettings { - [[self mainWindowController] applyPDFSettings:pdfViewSettings rewind:NO]; + [[self pdfView] setDisplaySettings:pdfViewSettings]; } - (NSInteger)toolMode { Modified: trunk/SKMainWindowController.h =================================================================== --- trunk/SKMainWindowController.h 2025-06-01 16:14:03 UTC (rev 15338) +++ trunk/SKMainWindowController.h 2025-06-01 17:07:28 UTC (rev 15339) @@ -320,8 +320,6 @@ - (void)applySetup:(NSDictionary<NSString *, id> *)setup; - (NSDictionary<NSString *, id> *)currentSetup; -- (void)applyPDFSettings:(NSDictionary<NSString *, id> *)setup rewind:(BOOL)rewind; -- (NSDictionary<NSString *, id> *)currentPDFSettings; - (void)applyOptions:(NSDictionary<NSString *, id> *)options; - (void)updateSubtitle; Modified: trunk/SKMainWindowController.m =================================================================== --- trunk/SKMainWindowController.m 2025-06-01 16:14:03 UTC (rev 15338) +++ trunk/SKMainWindowController.m 2025-06-01 17:07:28 UTC (rev 15339) @@ -395,7 +395,7 @@ [pdfView setInterpolationQuality:[sud integerForKey:SKInterpolationQualityKey]]; [pdfView setBackgroundColor:[PDFView defaultBackgroundColor]]; - [self applyPDFSettings:hasWindowSetup ? savedNormalSetup : [sud dictionaryForKey:SKDefaultPDFDisplaySettingsKey] rewind:NO]; + [pdfView setDisplaySettings:hasWindowSetup ? savedNormalSetup : [sud dictionaryForKey:SKDefaultPDFDisplaySettingsKey]]; [pdfView setDelegate:self]; @@ -430,7 +430,7 @@ if (hasWindowSetup == NO && [[NSUserDefaults standardUserDefaults] boolForKey:SKUseSettingsFromPDFKey]) { NSDictionary *initialSettings = [[self pdfDocument] initialSettings]; if (initialSettings) { - [self applyPDFSettings:initialSettings rewind:NO]; + [pdfView setDisplaySettings:initialSettings]; if ([initialSettings objectForKey:@"fitWindow"]) windowSizeOption = [[initialSettings objectForKey:@"fitWindow"] boolValue] ? SKWindowOptionFit : SKWindowOptionDefault; } @@ -583,7 +583,7 @@ [self showSnapshotsWithSetups:snapshotSetups]; if ([self interactionMode] == SKNormalMode) - [self applyPDFSettings:setup rewind:NO]; + [pdfView setDisplaySettings:setup]; else [savedNormalSetup addEntriesFromDictionary:setup]; @@ -618,7 +618,7 @@ if ([snapshots count]) [setup setObject:[snapshots valueForKey:SKSnapshotCurrentSetupKey] forKey:SNAPSHOTS_KEY]; if ([self interactionMode] != SKPresentationMode) - [setup addEntriesFromDictionary:[self currentPDFSettings]]; + [setup addEntriesFromDictionary:[pdfView displaySettings]]; if ([self interactionMode] != SKNormalMode || [[pdfView document] isLocked]) { [setup addEntriesFromDictionary:savedNormalSetup]; [setup removeObjectsForKeys:@[HASHORIZONTALSCROLLER_KEY, HASVERTICALSCROLLER_KEY, AUTOHIDESSCROLLERS_KEY, DRAWSBACKGROUND_KEY, TABGROUP_KEY, TABINDEX_KEY, USECUSTOMANIMATION_KEY, LOCKED_KEY]]; @@ -627,43 +627,6 @@ return setup; } -- (void)applyPDFSettings:(NSDictionary *)setup rewind:(BOOL)rewind { - if ([setup count] && rewind) - [pdfView setNeedsRewind:YES]; - NSNumber *number; - if ((number = [setup objectForKey:AUTOSCALES_KEY])) - [pdfView setAutoScales:[number boolValue]]; - if ([pdfView autoScales] == NO && (number = [setup objectForKey:SCALEFACTOR_KEY])) - [pdfView setScaleFactor:[number doubleValue]]; - if ((number = [setup objectForKey:DISPLAYSPAGEBREAKS_KEY])) - [pdfView setDisplaysPageBreaks:[number boolValue]]; - if ((number = [setup objectForKey:DISPLAYSASBOOK_KEY])) - [pdfView setDisplaysAsBook:[number boolValue]]; - if ((number = [setup objectForKey:DISPLAYMODE_KEY])) - [pdfView setExtendedDisplayMode:[number integerValue]]; - if ((number = [setup objectForKey:DISPLAYDIRECTION_KEY])) - [pdfView setDisplaysHorizontally:[number boolValue]]; - if ((number = [setup objectForKey:DISPLAYSRTL_KEY])) - [pdfView setDisplaysRTL:[number boolValue]]; - if ((number = [setup objectForKey:DISPLAYBOX_KEY])) - [pdfView setDisplayBox:[number integerValue]]; -} - -- (NSDictionary *)currentPDFSettings { - NSMutableDictionary *setup = [NSMutableDictionary dictionary]; - - [setup setObject:[NSNumber numberWithBool:[pdfView displaysPageBreaks]] forKey:DISPLAYSPAGEBREAKS_KEY]; - [setup setObject:[NSNumber numberWithBool:[pdfView displaysAsBook]] forKey:DISPLAYSASBOOK_KEY]; - [setup setObject:[NSNumber numberWithInteger:[pdfView displayBox]] forKey:DISPLAYBOX_KEY]; - [setup setObject:[NSNumber numberWithDouble:[pdfView scaleFactor]] forKey:SCALEFACTOR_KEY]; - [setup setObject:[NSNumber numberWithBool:[pdfView autoScales]] forKey:AUTOSCALES_KEY]; - [setup setObject:[NSNumber numberWithInteger:[pdfView displayMode]] forKey:DISPLAYMODE_KEY]; - [setup setObject:[NSNumber numberWithInteger:[pdfView displaysHorizontally] ? 1 : 0] forKey:DISPLAYDIRECTION_KEY]; - [setup setObject:[NSNumber numberWithBool:[pdfView displaysRTL]] forKey:DISPLAYSRTL_KEY]; - - return setup; -} - - (void)applyOptions:(NSDictionary *)options { NSInteger page = [[options objectForKey:@"page"] integerValue]; NSString *searchString = [options objectForKey:@"search"]; @@ -671,8 +634,12 @@ [settings removeObjectForKey:@"page"]; [settings removeObjectForKey:@"point"]; [settings removeObjectForKey:@"search"]; - if ([settings count]) - [self applyPDFSettings:settings rewind:page == 0 && [[pdfView currentPage] pageIndex] > 0]; + if ([settings count]) { + if (page == 0 && [[pdfView currentPage] pageIndex] > 0) + [pdfView setDisplaySettingsAndRewind:settings]; + else + [pdfView setDisplaySettings:settings]; + } if (page > 0) { page = MIN(page, (NSInteger)[[pdfView document] pageCount]); NSString *pointString = [options objectForKey:@"point"]; @@ -2073,7 +2040,7 @@ NSDictionary *settings = [self interactionMode] == SKFullScreenMode ? [[NSUserDefaults standardUserDefaults] dictionaryForKey:SKDefaultFullScreenPDFDisplaySettingsKey] : nil; if ([settings count] == 0) settings = [savedNormalSetup objectForKey:AUTOSCALES_KEY] ? savedNormalSetup : [[NSUserDefaults standardUserDefaults] dictionaryForKey:SKDefaultPDFDisplaySettingsKey]; - [self applyPDFSettings:settings rewind:NO]; + [pdfView setDisplaySettings:settings]; NSNumber *pageIndexNumber = [savedNormalSetup objectForKey:PAGEINDEX_KEY]; NSUInteger pageIndex = pageIndexNumber ? [pageIndexNumber unsignedIntegerValue] : NSNotFound; Modified: trunk/SKMainWindowController_FullScreen.m =================================================================== --- trunk/SKMainWindowController_FullScreen.m 2025-06-01 16:14:03 UTC (rev 15338) +++ trunk/SKMainWindowController_FullScreen.m 2025-06-01 17:07:28 UTC (rev 15339) @@ -231,7 +231,7 @@ [[SKImageToolTipWindow sharedToolTipWindow] orderOut:nil]; // remember normal setup to return to, we must do this before changing the interactionMode - [savedNormalSetup setDictionary:[self currentPDFSettings]]; + [savedNormalSetup setDictionary:[pdfView displaySettings]]; NSWindow *normalWindow = [self window]; savedNormalWindow = normalWindow; @@ -564,7 +564,7 @@ if ([[pdfView document] isLocked] == NO) { NSDictionary *fullScreenSetup = [[NSUserDefaults standardUserDefaults] dictionaryForKey:SKDefaultFullScreenPDFDisplaySettingsKey]; if ([fullScreenSetup count]) - [self applyPDFSettings:fullScreenSetup rewind:YES]; + [pdfView setDisplaySettingsAndRewind:fullScreenSetup]; } } } @@ -576,7 +576,7 @@ [pdfView setBackgroundColor:backgroundColor]; [secondaryPdfView setBackgroundColor:backgroundColor]; if ([[[NSUserDefaults standardUserDefaults] dictionaryForKey:SKDefaultFullScreenPDFDisplaySettingsKey] count]) - [self applyPDFSettings:savedNormalSetup rewind:YES]; + [pdfView setDisplaySettingsAndRewind:savedNormalSetup]; } } @@ -583,7 +583,7 @@ - (void)windowWillEnterFullScreen:(NSWindow *)window { mwcFlags.isSwitchingFullScreen = 1; if ([[pdfView document] isLocked] == NO || [savedNormalSetup count] == 0) - [savedNormalSetup setDictionary:[self currentPDFSettings]]; + [savedNormalSetup setDictionary:[pdfView displaySettings]]; NSString *frameString = NSStringFromRect([[self window] frame]); [savedNormalSetup setObject:frameString forKey:MAINWINDOWFRAME_KEY]; [self forceSubwindowsOnTop:YES]; Modified: trunk/SKPDFView.h =================================================================== --- trunk/SKPDFView.h 2025-06-01 16:14:03 UTC (rev 15338) +++ trunk/SKPDFView.h 2025-06-01 17:07:28 UTC (rev 15339) @@ -223,6 +223,9 @@ - (void)setDisplayBoxAndRewind:(PDFDisplayBox)box; - (void)setDisplaysAsBookAndRewind:(BOOL)asBook; +@property (nonatomic, copy) NSDictionary<NSString *, id> *displaySettings; +- (void)setDisplaySettingsAndRewind:(NSDictionary<NSString *, id> *)settings; + - (void)addAnnotationForContext:(nullable id)sender; - (void)addAnnotationWithType:(SKNoteType)annotationType; - (void)removeCurrentAnnotation:(nullable id)sender; Modified: trunk/SKPDFView.m =================================================================== --- trunk/SKPDFView.m 2025-06-01 16:14:03 UTC (rev 15338) +++ trunk/SKPDFView.m 2025-06-01 17:07:28 UTC (rev 15339) @@ -137,6 +137,15 @@ #define SKAnnotationKey @"SKAnnotation" +#define SCALEFACTOR_KEY @"scaleFactor" +#define AUTOSCALES_KEY @"autoScales" +#define DISPLAYSPAGEBREAKS_KEY @"displaysPageBreaks" +#define DISPLAYSASBOOK_KEY @"displaysAsBook" +#define DISPLAYMODE_KEY @"displayMode" +#define DISPLAYDIRECTION_KEY @"displayDirection" +#define DISPLAYSRTL_KEY @"displaysRTL" +#define DISPLAYBOX_KEY @"displayBox" + static char SKPDFViewDefaultsObservationContext; static NSUInteger moveReadingBarModifiers = NSEventModifierFlagCommand; @@ -240,7 +249,7 @@ @implementation SKPDFView @synthesize toolMode, annotationMode, temporaryToolMode, currentAnnotation, readingBar, pacerSpeed, typeSelectHelper, syncDot, hideNotes, zooming; -@dynamic extendedDisplayMode, displaysHorizontally, canSelectNote, hasReadingBar, hasPacer, currentSelectionPage, currentSelectionRect, currentMagnification, needsRewind, editing; +@dynamic extendedDisplayMode, displaysHorizontally, displaySettings, canSelectNote, hasReadingBar, hasPacer, currentSelectionPage, currentSelectionRect, currentMagnification, needsRewind, editing; + (void)initialize { SKINITIALIZE; @@ -936,6 +945,47 @@ return hideNotes == NO && (toolMode == SKToolModeText || toolMode == SKToolModeNote) && [[self document] allowsNotes]; } +- (NSDictionary *)displaySetting { + NSMutableDictionary *setup = [NSMutableDictionary dictionary]; + + [setup setObject:[NSNumber numberWithBool:[self displaysPageBreaks]] forKey:DISPLAYSPAGEBREAKS_KEY]; + [setup setObject:[NSNumber numberWithBool:[self displaysAsBook]] forKey:DISPLAYSASBOOK_KEY]; + [setup setObject:[NSNumber numberWithInteger:[self displayBox]] forKey:DISPLAYBOX_KEY]; + [setup setObject:[NSNumber numberWithDouble:[self scaleFactor]] forKey:SCALEFACTOR_KEY]; + [setup setObject:[NSNumber numberWithBool:[self autoScales]] forKey:AUTOSCALES_KEY]; + [setup setObject:[NSNumber numberWithInteger:[self displayMode]] forKey:DISPLAYMODE_KEY]; + [setup setObject:[NSNumber numberWithInteger:[self displaysHorizontally] ? 1 : 0] forKey:DISPLAYDIRECTION_KEY]; + [setup setObject:[NSNumber numberWithBool:[self displaysRTL]] forKey:DISPLAYSRTL_KEY]; + + return setup; +} + +- (void)setDisplaySettings:(NSDictionary *)setup { + NSNumber *number; + if ((number = [setup objectForKey:AUTOSCALES_KEY])) + [self setAutoScales:[number boolValue]]; + if ([self autoScales] == NO && (number = [setup objectForKey:SCALEFACTOR_KEY])) + [self setScaleFactor:[number doubleValue]]; + if ((number = [setup objectForKey:DISPLAYSPAGEBREAKS_KEY])) + [self setDisplaysPageBreaks:[number boolValue]]; + if ((number = [setup objectForKey:DISPLAYSASBOOK_KEY])) + [self setDisplaysAsBook:[number boolValue]]; + if ((number = [setup objectForKey:DISPLAYMODE_KEY])) + [self setExtendedDisplayMode:[number integerValue]]; + if ((number = [setup objectForKey:DISPLAYDIRECTION_KEY])) + [self setDisplaysHorizontally:[number boolValue]]; + if ((number = [setup objectForKey:DISPLAYSRTL_KEY])) + [self setDisplaysRTL:[number boolValue]]; + if ((number = [setup objectForKey:DISPLAYBOX_KEY])) + [self setDisplayBox:[number integerValue]]; +} + +- (void)setDisplaySettingsAndRewind:(NSDictionary *)setup { + if ([setup count] && rewind) + [self setNeedsRewind:YES]; + [self setDisplaySettings:setup]; +} + #pragma mark Reading bar - (BOOL)hasReadingBar { 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