1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:17:35 +00:00

MacPDF: Add a "Debug" menu with a "Show Clipping Paths" entry

...and hook it up.

I opened MainMenu.xib in Xcode, added a new "Submenu Menu Item"
from the Library (cmd-shift-l), added a User Defined
"toggleShowClippingPaths:" action on First Responder and connected
the menu item's action to that action.

(I first tried duplicating the existing Window menu and editing that,
but the Window menu is marked as `systemMenu="window"` in the xib and
I couldn't find a way to undo that in Xcode. So the Debug menu first
acted as a second Window menu.)

I made "Debug" a toplevel menu to make it consistent with Ladybird.app
for now, but I'll probably make it a submenu of "View" in the future.
This commit is contained in:
Nico Weber 2024-01-15 10:50:48 -05:00 committed by Tim Flynn
parent 64a48065b0
commit 2650e64bd4
3 changed files with 50 additions and 17 deletions

View file

@ -26,4 +26,6 @@
- (IBAction)goToNextPage:(id)sender; - (IBAction)goToNextPage:(id)sender;
- (IBAction)goToPreviousPage:(id)sender; - (IBAction)goToPreviousPage:(id)sender;
- (IBAction)toggleShowClippingPaths:(id)sender;
@end @end

View file

@ -16,10 +16,11 @@
NSBitmapImageRep* _cachedBitmap; NSBitmapImageRep* _cachedBitmap;
int _page_index; int _page_index;
__weak id<MacPDFViewDelegate> _delegate; __weak id<MacPDFViewDelegate> _delegate;
PDF::RenderingPreferences _preferences;
} }
@end @end
static PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> render(PDF::Document& document, int page_index, NSSize size) static PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> render(PDF::Document& document, int page_index, NSSize size, PDF::RenderingPreferences const& preferences)
{ {
auto page = TRY(document.get_page(page_index)); auto page = TRY(document.get_page(page_index));
@ -29,7 +30,7 @@ static PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> render(PDF::Document& documen
auto bitmap = TRY(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, page_size)); auto bitmap = TRY(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, page_size));
auto errors = PDF::Renderer::render(document, page, bitmap, Color::White, PDF::RenderingPreferences {}); auto errors = PDF::Renderer::render(document, page, bitmap, Color::White, preferences);
if (errors.is_error()) { if (errors.is_error()) {
for (auto const& error : errors.error().errors()) for (auto const& error : errors.error().errors())
NSLog(@"warning: %@", @(error.message().characters())); NSLog(@"warning: %@", @(error.message().characters()));
@ -129,7 +130,7 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr<Gfx::Bitmap> bitmap_p)
if (NSEqualSizes([_cachedBitmap size], pixel_size)) if (NSEqualSizes([_cachedBitmap size], pixel_size))
return; return;
if (auto bitmap_or = render(*_doc, _page_index, pixel_size); !bitmap_or.is_error()) if (auto bitmap_or = render(*_doc, _page_index, pixel_size, _preferences); !bitmap_or.is_error())
_cachedBitmap = ns_from_gfx(bitmap_or.value()); _cachedBitmap = ns_from_gfx(bitmap_or.value());
} }
@ -158,6 +159,23 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr<Gfx::Bitmap> bitmap_p)
[self goToPage:current_page - 1]; [self goToPage:current_page - 1];
} }
- (BOOL)validateMenuItem:(NSMenuItem*)item
{
if ([item action] == @selector(toggleShowClippingPaths:)) {
[item setState:_preferences.show_clipping_paths ? NSControlStateValueOn : NSControlStateValueOff];
return _doc ? YES : NO;
}
return NO;
}
- (IBAction)toggleShowClippingPaths:(id)sender
{
if (_doc) {
_preferences.show_clipping_paths = !_preferences.show_clipping_paths;
[self invalidateCachedBitmap];
}
}
- (void)keyDown:(NSEvent*)event - (void)keyDown:(NSEvent*)event
{ {
// Calls moveLeft: or moveRight: below. // Calls moveLeft: or moveRight: below.

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22154" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22155" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies> <dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22154"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22155"/>
</dependencies> </dependencies>
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication"> <customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
@ -660,26 +660,39 @@
</items> </items>
</menu> </menu>
</menuItem> </menuItem>
<menuItem title="Window" id="aUF-d1-5bR"> <menuItem title="Debug" id="jWy-In-lcG">
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo"> <menu key="submenu" title="Debug" id="9JC-3n-6oc">
<items> <items>
<menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV"> <menuItem title="Show Clipping Paths" id="mNt-xL-mVw">
<connections>
<action selector="performMiniaturize:" target="-1" id="VwT-WD-YPe"/>
</connections>
</menuItem>
<menuItem title="Zoom" id="R4o-n2-Eq4">
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>
<connections> <connections>
<action selector="performZoom:" target="-1" id="DIl-cC-cCs"/> <action selector="toggleShowClippingPaths:" target="-1" id="ZXz-gM-52n"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/> </items>
<menuItem title="Bring All to Front" id="LE2-aR-0XJ"> </menu>
</menuItem>
<menuItem title="Window" id="rRF-Br-Pu3">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Window" systemMenu="window" id="ipJ-MA-vaP">
<items>
<menuItem title="Minimize" keyEquivalent="m" id="iQm-go-526">
<connections>
<action selector="performMiniaturize:" target="-1" id="ysV-jh-lhh"/>
</connections>
</menuItem>
<menuItem title="Zoom" id="3fA-VK-sIE">
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>
<connections> <connections>
<action selector="arrangeInFront:" target="-1" id="DRN-fu-gQh"/> <action selector="performZoom:" target="-1" id="3eR-Yk-WOl"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="fk3-NL-Gg9"/>
<menuItem title="Bring All to Front" id="q3x-yl-EEv">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="arrangeInFront:" target="-1" id="9GN-Lx-lIK"/>
</connections> </connections>
</menuItem> </menuItem>
</items> </items>