LibPDF+MacPDF: Clip text, and add a debug option for disabling it

This commit is contained in:
Nico Weber 2024-01-19 20:01:23 -08:00 committed by Andreas Kling
parent 90fdf738a1
commit a0462f495c
Notes: sideshowbarker 2024-07-17 05:05:51 +09:00
7 changed files with 30 additions and 0 deletions

View File

@ -29,5 +29,6 @@
- (IBAction)toggleShowClippingPaths:(id)sender;
- (IBAction)toggleClipImages:(id)sender;
- (IBAction)toggleClipPaths:(id)sender;
- (IBAction)toggleClipText:(id)sender;
@end

View File

@ -177,6 +177,10 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr<Gfx::Bitmap> bitmap_p)
[item setState:_preferences.clip_paths ? NSControlStateValueOn : NSControlStateValueOff];
return _doc ? YES : NO;
}
if ([item action] == @selector(toggleClipText:)) {
[item setState:_preferences.clip_text ? NSControlStateValueOn : NSControlStateValueOff];
return _doc ? YES : NO;
}
return NO;
}
@ -204,6 +208,14 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr<Gfx::Bitmap> bitmap_p)
}
}
- (IBAction)toggleClipText:(id)sender
{
if (_doc) {
_preferences.clip_text = !_preferences.clip_text;
[self invalidateCachedBitmap];
}
}
- (void)keyDown:(NSEvent*)event
{
// Calls moveLeft: or moveRight: below.

View File

@ -24,6 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
- (IBAction)toggleShowClippingPaths:(id)sender;
- (IBAction)toggleClipImages:(id)sender;
- (IBAction)toggleClipPaths:(id)sender;
- (IBAction)toggleClipText:(id)sender;
- (IBAction)showGoToPageDialog:(id)sender;
- (void)pdfDidInitialize;

View File

@ -154,6 +154,11 @@
[_pdfView toggleClipPaths:sender];
}
- (IBAction)toggleClipText:(id)sender
{
[_pdfView toggleClipText:sender];
}
- (IBAction)showGoToPageDialog:(id)sender
{
auto alert = [[NSAlert alloc] init];

View File

@ -682,6 +682,12 @@
<action selector="toggleClipPaths:" target="-1" id="pZu-tJ-RFh"/>
</connections>
</menuItem>
<menuItem title="Clip Text" state="on" id="u58-eB-op8">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleClipText:" target="-1" id="qxg-tH-KXd"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>

View File

@ -1011,6 +1011,10 @@ PDFErrorOr<void> Renderer::show_text(ByteString const& string)
if (!text_state().font)
return Error::rendering_unsupported_error("Can't draw text because an invalid font was in use");
OwnPtr<ClipRAII> clip_raii;
if (m_rendering_preferences.clip_text)
clip_raii = make<ClipRAII>(*this);
auto start_position = Gfx::FloatPoint { 0.0f, 0.0f };
auto end_position = TRY(text_state().font->draw_string(m_painter, start_position, string, *this));

View File

@ -92,6 +92,7 @@ struct RenderingPreferences {
bool clip_images { true };
bool clip_paths { true };
bool clip_text { true };
unsigned hash() const
{