mirror of
https://github.com/fltk/fltk.git
synced 2026-06-05 16:12:13 +08:00
Rewrite Fl_Copy_Surface::complete_copy_pdf_and_tiff() using cocoa APIs.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10442 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -155,7 +155,6 @@ public:
|
|||||||
int set_cursor(const Fl_RGB_Image*, int, int);
|
int set_cursor(const Fl_RGB_Image*, int, int);
|
||||||
static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
|
static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
|
||||||
static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
|
static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
|
||||||
static CFDataRef CGBitmapContextToTIFF(CGContextRef c);
|
|
||||||
static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h);
|
static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h);
|
||||||
static CGContextRef watch_cursor_image(void);
|
static CGContextRef watch_cursor_image(void);
|
||||||
static CGContextRef help_cursor_image(void);
|
static CGContextRef help_cursor_image(void);
|
||||||
|
|||||||
@@ -212,49 +212,6 @@ void Fl_Copy_Surface::prepare_copy_pdf_and_tiff(int w, int h)
|
|||||||
CGContextSaveGState(gc);
|
CGContextSaveGState(gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Fl_Copy_Surface::complete_copy_pdf_and_tiff()
|
|
||||||
{
|
|
||||||
CGContextRestoreGState(gc);
|
|
||||||
CGContextEndPage(gc);
|
|
||||||
CGContextRelease(gc);
|
|
||||||
PasteboardRef clipboard = NULL;
|
|
||||||
PasteboardCreate(kPasteboardClipboard, &clipboard);
|
|
||||||
PasteboardClear(clipboard); // first, copy PDF to clipboard
|
|
||||||
PasteboardPutItemFlavor (clipboard, (PasteboardItemID)1,
|
|
||||||
CFSTR("com.adobe.pdf"), // kUTTypePDF
|
|
||||||
pdfdata, kPasteboardFlavorNoFlags);
|
|
||||||
//second, transform this PDF to a bitmap image and put it as tiff in clipboard
|
|
||||||
CGDataProviderRef prov;
|
|
||||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
|
|
||||||
if(fl_mac_os_version >= 100400)
|
|
||||||
prov = CGDataProviderCreateWithCFData(pdfdata); // 10.4
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
prov = CGDataProviderCreateWithData(NULL, CFDataGetBytePtr(pdfdata), CFDataGetLength(pdfdata), NULL);
|
|
||||||
CGPDFDocumentRef pdfdoc = CGPDFDocumentCreateWithProvider(prov);
|
|
||||||
CGPDFPageRef pdfpage = CGPDFDocumentGetPage(pdfdoc, 1);
|
|
||||||
CGDataProviderRelease(prov);
|
|
||||||
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
|
|
||||||
void *mem = ( fl_mac_os_version >= 100600 ? NULL : malloc(width * height * 4) );
|
|
||||||
gc = CGBitmapContextCreate(mem, width, height, 8, width * 4, space, kCGImageAlphaNoneSkipLast);
|
|
||||||
CFRelease(space);
|
|
||||||
if (gc == NULL) { if (mem) free(mem); return; }
|
|
||||||
CGRect rect = CGRectMake(0, 0, width, height);
|
|
||||||
CGContextSetRGBFillColor(gc, 1,1,1,1);//need to clear background
|
|
||||||
CGContextFillRect(gc, rect);
|
|
||||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
|
|
||||||
CGContextDrawPDFPage(gc, pdfpage); // requires 10.3
|
|
||||||
#endif
|
|
||||||
CGPDFDocumentRelease(pdfdoc);
|
|
||||||
CFRelease(pdfdata);
|
|
||||||
PasteboardPutItemFlavor(clipboard, (PasteboardItemID)1, CFSTR("public.tiff"),
|
|
||||||
Fl_X::CGBitmapContextToTIFF(gc), kPasteboardFlavorNoFlags);
|
|
||||||
CFRelease(clipboard);
|
|
||||||
CGContextRelease(gc);
|
|
||||||
if (mem) free(mem);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // __APPLE__
|
#endif // __APPLE__
|
||||||
|
|
||||||
#if !(defined(__APPLE__) || defined(WIN32) || defined(FL_DOXYGEN))
|
#if !(defined(__APPLE__) || defined(WIN32) || defined(FL_DOXYGEN))
|
||||||
|
|||||||
+33
-19
@@ -44,6 +44,7 @@ extern "C" {
|
|||||||
#include <FL/Fl_Printer.H>
|
#include <FL/Fl_Printer.H>
|
||||||
#include <FL/Fl_Input_.H>
|
#include <FL/Fl_Input_.H>
|
||||||
#include <FL/Fl_Text_Display.H>
|
#include <FL/Fl_Text_Display.H>
|
||||||
|
#include <FL/Fl_Copy_Surface.H>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "flstring.h"
|
#include "flstring.h"
|
||||||
@@ -3031,6 +3032,38 @@ void Fl_X::q_end_image() {
|
|||||||
CGContextRestoreGState(fl_gc);
|
CGContextRestoreGState(fl_gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Fl_Copy_Surface::complete_copy_pdf_and_tiff()
|
||||||
|
{
|
||||||
|
CGContextRestoreGState(gc);
|
||||||
|
CGContextEndPage(gc);
|
||||||
|
CGContextRelease(gc);
|
||||||
|
NSPasteboard *clip = [NSPasteboard generalPasteboard];
|
||||||
|
[clip declareTypes:[NSArray arrayWithObjects:@"com.adobe.pdf", @"public.tiff", nil] owner:nil];
|
||||||
|
[clip setData:(NSData*)pdfdata forType:@"com.adobe.pdf"];
|
||||||
|
//second, transform this PDF to a bitmap image and put it as tiff in clipboard
|
||||||
|
NSPDFImageRep *vectorial = [[NSPDFImageRep alloc] initWithData:(NSData*)pdfdata];
|
||||||
|
CFRelease(pdfdata);
|
||||||
|
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
|
||||||
|
pixelsWide:width
|
||||||
|
pixelsHigh:height
|
||||||
|
bitsPerSample:8
|
||||||
|
samplesPerPixel:3
|
||||||
|
hasAlpha:NO
|
||||||
|
isPlanar:NO
|
||||||
|
colorSpaceName:NSDeviceRGBColorSpace
|
||||||
|
bytesPerRow:width*4
|
||||||
|
bitsPerPixel:32];
|
||||||
|
memset([bitmap bitmapData], -1, [bitmap bytesPerRow] * [bitmap pixelsHigh]);
|
||||||
|
NSDictionary *dict = [NSDictionary dictionaryWithObject:bitmap
|
||||||
|
forKey:NSGraphicsContextDestinationAttributeName];
|
||||||
|
NSGraphicsContext *oldgc = [NSGraphicsContext currentContext];
|
||||||
|
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithAttributes:dict]];
|
||||||
|
[vectorial draw];
|
||||||
|
[vectorial release];
|
||||||
|
[NSGraphicsContext setCurrentContext:oldgc];
|
||||||
|
[clip setData:[bitmap TIFFRepresentation] forType:@"public.tiff"];
|
||||||
|
[bitmap release];
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
// Copy & Paste fltk implementation.
|
// Copy & Paste fltk implementation.
|
||||||
@@ -3438,25 +3471,6 @@ static NSImage *CGBitmapContextToNSImage(CGContextRef c)
|
|||||||
return [image autorelease];
|
return [image autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CFDataRef Fl_X::CGBitmapContextToTIFF(CGContextRef c)
|
|
||||||
{ // the returned value is autoreleased
|
|
||||||
unsigned char *pdata = (unsigned char *)CGBitmapContextGetData(c);
|
|
||||||
NSBitmapImageRep *imagerep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&pdata
|
|
||||||
pixelsWide:CGBitmapContextGetWidth(c)
|
|
||||||
pixelsHigh:CGBitmapContextGetHeight(c)
|
|
||||||
bitsPerSample:8
|
|
||||||
samplesPerPixel:3
|
|
||||||
hasAlpha:NO
|
|
||||||
isPlanar:NO
|
|
||||||
colorSpaceName:NSDeviceRGBColorSpace
|
|
||||||
bytesPerRow:CGBitmapContextGetBytesPerRow(c)
|
|
||||||
bitsPerPixel:CGBitmapContextGetBitsPerPixel(c)];
|
|
||||||
NSData* tiff = [imagerep TIFFRepresentation];
|
|
||||||
[imagerep release];
|
|
||||||
return (CFDataRef)tiff;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Fl_X::set_cursor(Fl_Cursor c)
|
int Fl_X::set_cursor(Fl_Cursor c)
|
||||||
{
|
{
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
|
|||||||
Reference in New Issue
Block a user