summaryrefslogtreecommitdiff
path: root/src/macos/Sources/PardesView.swift
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-16 14:46:16 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:14 -0300
commit717afaf3177a2e0925b18ae3445119efe808b129 (patch)
tree45a2196711de78d8d1e2db6cb5e5c51271676c2f /src/macos/Sources/PardesView.swift
parent7cbd44dd1cfe97126e7fc996214e458525d2980c (diff)
downloadpardes-717afaf3177a2e0925b18ae3445119efe808b129.tar.gz
pardes-717afaf3177a2e0925b18ae3445119efe808b129.zip
Add macOS backdrop blur and preserve PDF ink opacity
Diffstat (limited to 'src/macos/Sources/PardesView.swift')
-rw-r--r--src/macos/Sources/PardesView.swift16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/macos/Sources/PardesView.swift b/src/macos/Sources/PardesView.swift
index 7c537055..7981cf46 100644
--- a/src/macos/Sources/PardesView.swift
+++ b/src/macos/Sources/PardesView.swift
@@ -1446,6 +1446,7 @@ final class PardesView: NSView {
let source: CGRect
let body: CGRect
let destination: CGRect
+ let paperBG: UInt32
}
/// Rasterized attachments, decoded once each. The bytes the core lends are
@@ -1496,7 +1497,7 @@ final class PardesView: NSView {
height: CGFloat(place.dst_h) / scale)
let frozen = FrozenImage(
key: key, image: crop, source: source,
- body: body, destination: dst)
+ body: body, destination: dst, paperBG: place.paper_bg)
frameImages.append(frozen)
drawFrozenImage(ctx, frozen)
}
@@ -1545,11 +1546,24 @@ final class PardesView: NSView {
ctx.clip(to: placed.body)
// isFlipped gives us a y-down CTM and CGImage draws +y up, so flip
// about this destination rather than changing the grid arithmetic.
+ let isPDF = placed.paperBG != UInt32(PARDES_COLOR_DEFAULT)
+ if isPDF {
+ fillBackground(ctx, placed.destination, placed.paperBG, backgroundAlpha)
+ }
ctx.translateBy(x: placed.destination.minX, y: placed.destination.maxY)
ctx.scaleBy(x: 1, y: -1)
ctx.interpolationQuality = .high
let rect = CGRect(x: 0, y: 0,
width: placed.destination.width, height: placed.destination.height)
+ if isPDF {
+ // Paper was painted at WindowOpacity. Content keeps the PDF's own
+ // coverage, so glyphs, photos and paths stay legible at zero opacity.
+ ctx.setAlpha(1)
+ ctx.setBlendMode(.normal)
+ ctx.draw(placed.image, in: rect)
+ ctx.restoreGState()
+ return
+ }
// Match image.frag.glsl/backgroundLayerBlend: source coverage removes
// the destination independently of WindowOpacity, then the source is
// added at that opacity. Ordinary source-over would compound alpha;