From d15785ccccf916d5a18bbaba70219dd7445e5d48 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 14 Mar 2024 07:52:10 -0400 Subject: [PATCH] MacPDF: Add "Show Images" debug menu entry PDFViewer has this, and it's useful for PDFs that have the same text both as a scanned bitmap in the background as well as using vector text in the foreground. xib changes: Added a new menu entry connected to `toggleShowImages:`, and also toggled the initial state of two menu entries. (The latter part has no effect when the program runs since we dynamically update this state, but it makes the menu entries show their initial state in Xcode's menu editor.) --- Meta/Lagom/Contrib/MacPDF/MacPDFView.h | 1 + Meta/Lagom/Contrib/MacPDF/MacPDFView.mm | 12 ++++++++++++ Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h | 1 + .../Lagom/Contrib/MacPDF/MacPDFWindowController.mm | 5 +++++ Meta/Lagom/Contrib/MacPDF/MainMenu.xib | 14 ++++++++++---- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFView.h b/Meta/Lagom/Contrib/MacPDF/MacPDFView.h index dd0ed1065e..a207895119 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFView.h +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFView.h @@ -30,5 +30,6 @@ - (IBAction)toggleClipImages:(id)sender; - (IBAction)toggleClipPaths:(id)sender; - (IBAction)toggleClipText:(id)sender; +- (IBAction)toggleShowImages:(id)sender; @end diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFView.mm b/Meta/Lagom/Contrib/MacPDF/MacPDFView.mm index 268b2c1f00..d3206e238d 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFView.mm +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFView.mm @@ -181,6 +181,10 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr bitmap_p) [item setState:_preferences.clip_text ? NSControlStateValueOn : NSControlStateValueOff]; return _doc ? YES : NO; } + if ([item action] == @selector(toggleShowImages:)) { + [item setState:_preferences.show_images ? NSControlStateValueOn : NSControlStateValueOff]; + return _doc ? YES : NO; + } return NO; } @@ -216,6 +220,14 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr bitmap_p) } } +- (IBAction)toggleShowImages:(id)sender +{ + if (_doc) { + _preferences.show_images = !_preferences.show_images; + [self invalidateCachedBitmap]; + } +} + - (void)keyDown:(NSEvent*)event { // Calls moveLeft: or moveRight: below. diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h index 7b11f0a58f..b4e2cda134 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h @@ -25,6 +25,7 @@ NS_ASSUME_NONNULL_BEGIN - (IBAction)toggleClipImages:(id)sender; - (IBAction)toggleClipPaths:(id)sender; - (IBAction)toggleClipText:(id)sender; +- (IBAction)toggleShowImages:(id)sender; - (IBAction)showGoToPageDialog:(id)sender; - (void)pdfDidInitialize; diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm index bf00df6513..595c3c590c 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm @@ -159,6 +159,11 @@ [_pdfView toggleClipText:sender]; } +- (IBAction)toggleShowImages:(id)sender +{ + [_pdfView toggleShowImages:sender]; +} + - (IBAction)showGoToPageDialog:(id)sender { auto alert = [[NSAlert alloc] init]; diff --git a/Meta/Lagom/Contrib/MacPDF/MainMenu.xib b/Meta/Lagom/Contrib/MacPDF/MainMenu.xib index f36878cef6..bb6ab08353 100644 --- a/Meta/Lagom/Contrib/MacPDF/MainMenu.xib +++ b/Meta/Lagom/Contrib/MacPDF/MainMenu.xib @@ -1,7 +1,7 @@ - + - + @@ -670,13 +670,13 @@ - + - + @@ -688,6 +688,12 @@ + + + + + +