summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXImage.c
diff options
context:
space:
mode:
authorKevin Walzer <kw@codebykevin.com>2023-09-28 13:21:16 (GMT)
committerKevin Walzer <kw@codebykevin.com>2023-09-28 13:21:16 (GMT)
commit1c5c40e220e700f37c72ac520aca7de1cff6f52b (patch)
treef2b95f99b76e184f58a1c634654c50ef1815e4b7 /macosx/tkMacOSXImage.c
parentd01c74bb7b184652bc40874b4fb1812d6cc19ba7 (diff)
downloadtk-1c5c40e220e700f37c72ac520aca7de1cff6f52b.zip
tk-1c5c40e220e700f37c72ac520aca7de1cff6f52b.tar.gz
tk-1c5c40e220e700f37c72ac520aca7de1cff6f52b.tar.bz2
Replace CGImageRef data with PDF data
Diffstat (limited to 'macosx/tkMacOSXImage.c')
-rw-r--r--macosx/tkMacOSXImage.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c
index ebbe323..b0c199c 100644
--- a/macosx/tkMacOSXImage.c
+++ b/macosx/tkMacOSXImage.c
@@ -670,6 +670,57 @@ CreateCGImageFromDrawableRect(
}
return result;
}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * CreatePDFFromDrawableRect
+ *
+ * Extract PDF data from a MacOSX drawable.
+ *
+ * Results:
+ * Returns a CFDataRef that can be written to a file.
+ *
+ * NOTE: The x,y coordinates should be relative to a coordinate system
+ * with origin at the top left, as used by XImage and CGImage, not bottom
+ * left as used by NSView.
+ *
+ * Side effects:
+ * None
+ *
+ *----------------------------------------------------------------------
+ */
+
+CFDataRef
+CreatePDFFromDrawableRect(
+ Drawable drawable,
+ int x,
+ int y,
+ unsigned int width,
+ unsigned int height)
+{
+ MacDrawable *mac_drawable = (MacDrawable *)drawable;
+ NSView *view = TkMacOSXGetNSViewForDrawable(mac_drawable);
+ if (view == nil) {
+ TkMacOSXDbgMsg("Invalid source drawable");
+ return NULL;
+ }
+ NSRect bounds, viewSrcRect;
+
+ /*
+ * Get the child window area in NSView coordinates
+ * (origin at bottom left).
+ */
+
+ bounds = [view bounds];
+ viewSrcRect = NSMakeRect(mac_drawable->xOff + x,
+ bounds.size.height - height - (mac_drawable->yOff + y),
+ width, height);
+ NSData *viewData = [view dataWithPDFInsideRect:viewSrcRect];
+ CFDataRef result = (CFDataRef)viewData;
+ return result;
+}
+
/*
*----------------------------------------------------------------------