Revision: 14757
http://sourceforge.net/p/skim-app/code/14757
Author: hofman
Date: 2024-11-27 23:48:33 +0000 (Wed, 27 Nov 2024)
Log Message:
-----------
Allow writing and svaing PDF data when printing is not allowed on newer system.
For now allow on 12.0+ as I know it works there, not sure whether it can work
on 10.13+ for earlier versions.
Modified Paths:
--------------
trunk/PDFDocument_SKExtensions.h
trunk/PDFDocument_SKExtensions.m
trunk/PDFPage_SKExtensions.m
trunk/SKMainDocument.m
trunk/SKMainWindowController.m
trunk/SKPDFView.m
Modified: trunk/PDFDocument_SKExtensions.h
===================================================================
--- trunk/PDFDocument_SKExtensions.h 2024-11-27 10:41:44 UTC (rev 14756)
+++ trunk/PDFDocument_SKExtensions.h 2024-11-27 23:48:33 UTC (rev 14757)
@@ -61,6 +61,7 @@
@property (nonatomic, nullable, readonly) NSArray<NSString *> *fileIDStrings;
@property (nonatomic, nullable, readonly) NSDictionary<NSString *, id>
*initialSettings;
@property (nonatomic, readonly) SKLanguageDirectionAngles
languageDirectionAngles;
+@property (nonatomic, readonly) BOOL allowsSaving;
@property (nonatomic, readonly) BOOL allowsNotes;
@property (nonatomic, readonly) BOOL realAllowsCommenting;
@property (nonatomic, nullable, readonly) NSArray<PDFAnnotation *>
*detectedWidgets;
Modified: trunk/PDFDocument_SKExtensions.m
===================================================================
--- trunk/PDFDocument_SKExtensions.m 2024-11-27 10:41:44 UTC (rev 14756)
+++ trunk/PDFDocument_SKExtensions.m 2024-11-27 23:48:33 UTC (rev 14757)
@@ -269,6 +269,13 @@
return angles;
}
+- (BOOL)allowsSaving {
+ if (@available(macOS 12.0, *))
+ return [self isLocked] == NO;
+ else
+ return [self allowsPrinting];
+}
+
- (BOOL)allowsNotes {
return [self isLocked] == NO && [self allowsCommenting];
}
Modified: trunk/PDFPage_SKExtensions.m
===================================================================
--- trunk/PDFPage_SKExtensions.m 2024-11-27 10:41:44 UTC (rev 14756)
+++ trunk/PDFPage_SKExtensions.m 2024-11-27 23:48:33 UTC (rev 14757)
@@ -317,7 +317,7 @@
- (NSString *)filePromiseProvider:(NSFilePromiseProvider *)filePromiseProvider
fileNameForType:(NSString *)fileType {
NSString *label = [self displayLabel];
NSIndexSet *pageIndexes = [filePromiseProvider userInfo];
- if (pageIndexes && [[self document] allowsPrinting]) {
+ if (pageIndexes && [[self document] allowsSaving]) {
NSMutableArray *labels = [NSMutableArray array];
[pageIndexes enumerateIndexesUsingBlock:^(NSUInteger i, BOOL *stop){
[labels addObject:[[[self document] pageAtIndex:i] displayLabel]];
@@ -325,7 +325,7 @@
label = [labels componentsJoinedByString:@", "];
}
NSString *filename = [([[[self containingDocument] displayName]
stringByDeletingPathExtension] ?: @"PDF")
stringByAppendingDashAndString:[NSString
stringWithFormat:NSLocalizedString(@"Page %@", @""), label]];
- NSString *pathExt = [[self document] allowsPrinting] ? @"pdf" : @"tiff";
+ NSString *pathExt = [[self document] allowsSaving] ? @"pdf" : @"tiff";
return [filename stringByAppendingPathExtension:pathExt];
}
@@ -332,7 +332,7 @@
- (void)filePromiseProvider:(NSFilePromiseProvider *)filePromiseProvider
writePromiseToURL:(NSURL *)fileURL completionHandler:(void (^)(NSError
*))completionHandler {
NSData *data = nil;
NSError *error = nil;
- if ([[self document] allowsPrinting]) {
+ if ([[self document] allowsSaving]) {
NSIndexSet *pageIndexes = [filePromiseProvider userInfo];
data = [self dataRepresentationForPageIndexes:pageIndexes];
} else
@@ -343,7 +343,7 @@
- (id<NSPasteboardWriting>)filePromiseForPageIndexes:(NSIndexSet *)pageIndexes
{
if ([[self document] isLocked] == NO) {
- NSString *fileUTI = [[self document] allowsPrinting] ? (__bridge
NSString *)kUTTypePDF : (__bridge NSString *)kUTTypeTIFF;
+ NSString *fileUTI = [[self document] allowsSaving] ? (__bridge
NSString *)kUTTypePDF : (__bridge NSString *)kUTTypeTIFF;
NSFilePromiseProvider *item = [[NSFilePromiseProvider alloc]
initWithFileType:fileUTI delegate:self];
if (pageIndexes)
[item setUserInfo:pageIndexes];
@@ -356,7 +356,7 @@
if ([[self document] isLocked] == NO) {
NSData *tiffData = [self TIFFDataForRect:[self
boundsForBox:kPDFDisplayBoxCropBox]];
NSPasteboardItem *pboardItem = [[NSPasteboardItem alloc] init];
- if ([[self document] allowsPrinting])
+ if ([[self document] allowsSaving])
[pboardItem setData:[self
dataRepresentationForPageIndexes:pageIndexes] forType:NSPasteboardTypePDF];
[pboardItem setData:tiffData forType:NSPasteboardTypeTIFF];
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m 2024-11-27 10:41:44 UTC (rev 14756)
+++ trunk/SKMainDocument.m 2024-11-27 23:48:33 UTC (rev 14757)
@@ -190,7 +190,7 @@
- (void)setDataFromTmpData {
PDFDocument *pdfDoc = [tmpData pdfDocument];
- mdFlags.needsPasswordToConvert = [pdfDoc allowsPrinting] == NO || [pdfDoc
allowsNotes] == NO;
+ mdFlags.needsPasswordToConvert = [pdfDoc allowsSaving] == NO || [pdfDoc
allowsNotes] == NO;
[self tryToUnlockDocument:pdfDoc];
@@ -320,7 +320,7 @@
[exportAccessoryController setHasExportOptions:NO];
} else {
[exportAccessoryController setHasExportOptions:YES];
- if ([[NSWorkspace sharedWorkspace] type:type
conformsToType:SKDocumentTypePDF] && ([[self pdfDocument] isLocked] == NO &&
[[self pdfDocument] allowsPrinting])) {
+ if ([[NSWorkspace sharedWorkspace] type:type
conformsToType:SKDocumentTypePDF] && ([[self pdfDocument] isLocked] == NO &&
[[self pdfDocument] allowsSaving])) {
[exportAccessoryController setAllowsEmbeddedOption:YES];
} else {
[exportAccessoryController setAllowsEmbeddedOption:NO];
@@ -1191,8 +1191,8 @@
if (result == NSModalResponseOK) {
[[passwordSheetController window] orderOut:nil];
- if (pdfDoc && ([pdfDoc allowsNotes] == NO || [pdfDoc
allowsPrinting] == NO) &&
- ([pdfDoc unlockWithPassword:[passwordSheetController
stringValue]] == NO || [pdfDoc allowsNotes] == NO || [pdfDoc allowsPrinting] ==
NO)) {
+ if (pdfDoc && ([pdfDoc allowsNotes] == NO || [pdfDoc
allowsSaving] == NO) &&
+ ([pdfDoc unlockWithPassword:[passwordSheetController
stringValue]] == NO || [pdfDoc allowsNotes] == NO || [pdfDoc allowsSaving] ==
NO)) {
[self beginConvertNotesPasswordSheetForPDFDocument:pdfDoc];
} else {
[self convertNotesUsingPDFDocument:pdfDoc];
@@ -1211,7 +1211,7 @@
if (mdFlags.needsPasswordToConvert) {
pdfDocWithoutNotes = [[PDFDocument alloc] initWithData:pdfData];
[self tryToUnlockDocument:pdfDocWithoutNotes];
- if ([pdfDocWithoutNotes allowsNotes] == NO || [pdfDocWithoutNotes
allowsPrinting] == NO) {
+ if ([pdfDocWithoutNotes allowsNotes] == NO || [pdfDocWithoutNotes
allowsSaving] == NO) {
[self
beginConvertNotesPasswordSheetForPDFDocument:pdfDocWithoutNotes];
return;
}
Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m 2024-11-27 10:41:44 UTC (rev 14756)
+++ trunk/SKMainWindowController.m 2024-11-27 23:48:33 UTC (rev 14757)
@@ -1568,7 +1568,7 @@
[overviewContentView setFrame:[oldView frame]];
[overviewView scrollRectToVisible:[overviewView
frameForItemAtIndex:[[pdfView currentPage] pageIndex]]];
[overviewView setSelectionIndexes:[NSIndexSet indexSetWithIndex:[[pdfView
currentPage] pageIndex]]];
- [overviewView setAllowsMultipleSelection:isPresentation == NO && [[self
pdfDocument] allowsPrinting]];
+ [overviewView setAllowsMultipleSelection:isPresentation == NO && [[self
pdfDocument] allowsSaving]];
if (@available(macOS 10.14, *)) {
if (isPresentation) {
Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m 2024-11-27 10:41:44 UTC (rev 14756)
+++ trunk/SKPDFView.m 2024-11-27 23:48:33 UTC (rev 14757)
@@ -1133,7 +1133,7 @@
imageItem = [[NSPasteboardItem alloc] init];
- if ([[self document] allowsPrinting] && (pdfData = [page
PDFDataForRect:selRect]))
+ if ([[self document] allowsSaving] && (pdfData = [page
PDFDataForRect:selRect]))
[imageItem setData:pdfData forType:NSPasteboardTypePDF];
if ((tiffData = [page TIFFDataForRect:selRect]))
[imageItem setData:tiffData forType:NSPasteboardTypeTIFF];
@@ -2276,7 +2276,7 @@
NSRect selRect = NSIntegralRect(selectionRect);
// Unfortunately only old PboardTypes are requested rather than
preferred UTIs, even if we only validate and the Service only requests UTIs, so
we need to support both
- if ([[self document] allowsPrinting] && [[self document] isLocked] ==
NO) {
+ if ([[self document] allowsSaving] && [[self document] isLocked] ==
NO) {
if ([types containsObject:NSPasteboardTypePDF])
pdfType = NSPasteboardTypePDF;
else if ([types containsObject:NSPDFPboardType])
@@ -2317,7 +2317,7 @@
- (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString
*)returnType {
if ([self toolMode] == SKToolModeSelect && NSIsEmptyRect(selectionRect) ==
NO && selectionPageIndex != NSNotFound && returnType == nil &&
- (([[self document] allowsPrinting] && [[self document] isLocked] == NO
&& [sendType isEqualToString:NSPasteboardTypePDF]) || [sendType
isEqualToString:NSPasteboardTypeTIFF])) {
+ (([[self document] allowsSaving] && [[self document] isLocked] == NO
&& [sendType isEqualToString:NSPasteboardTypePDF]) || [sendType
isEqualToString:NSPasteboardTypeTIFF])) {
return self;
}
if ([[self currentSelection] hasCharacters] && returnType == nil &&
([sendType isEqualToString:NSPasteboardTypeString] || [sendType
isEqualToString:NSPasteboardTypeRTF])) {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit