Mercurial > dwindows
comparison mac/dw.m @ 1175:eb4589ddff3e
Added some test code to save what we are trying to print as a PNG on Mac.
Realized the internal representation is flipped so it may be trying to
print upside down.... so added code to flip it... now the exported
PNG looks perfect but the print preview is still just a purple box.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 19 Sep 2011 19:37:35 +0000 |
parents | 924c8087a755 |
children | 408ea33b19cf |
comparison
equal
deleted
inserted
replaced
1174:f1cb493f97fd | 1175:eb4589ddff3e |
---|---|
9387 * DW_ERROR_UNKNOWN on error or DW_ERROR_NONE on success. | 9387 * DW_ERROR_UNKNOWN on error or DW_ERROR_NONE on success. |
9388 */ | 9388 */ |
9389 int API dw_print_run(HPRINT print, unsigned long flags) | 9389 int API dw_print_run(HPRINT print, unsigned long flags) |
9390 { | 9390 { |
9391 DWPrint *p = print; | 9391 DWPrint *p = print; |
9392 NSBitmapImageRep *rep; | 9392 NSBitmapImageRep *rep, *rep2; |
9393 NSPrintInfo *pi; | 9393 NSPrintInfo *pi; |
9394 NSPrintOperation *po; | 9394 NSPrintOperation *po; |
9395 HPIXMAP pixmap; | 9395 HPIXMAP pixmap, pixmap2; |
9396 NSImage *image; | 9396 NSImage *image, *flipped; |
9397 NSImageView *iv; | 9397 NSImageView *iv; |
9398 NSSize size; | 9398 NSSize size; |
9399 PMPrintSettings settings; | 9399 PMPrintSettings settings; |
9400 int x, result = DW_ERROR_UNKNOWN; | 9400 int x, result = DW_ERROR_UNKNOWN; |
9401 UInt32 start, end; | 9401 UInt32 start, end; |
9408 size = [pi paperSize]; | 9408 size = [pi paperSize]; |
9409 /* Create an image view to print and a pixmap to draw into */ | 9409 /* Create an image view to print and a pixmap to draw into */ |
9410 iv = [[NSImageView alloc] init]; | 9410 iv = [[NSImageView alloc] init]; |
9411 pixmap = dw_pixmap_new(iv, (int)size.width, (int)size.height, 8); | 9411 pixmap = dw_pixmap_new(iv, (int)size.width, (int)size.height, 8); |
9412 rep = pixmap->image; | 9412 rep = pixmap->image; |
9413 pixmap2 = dw_pixmap_new(iv, (int)size.width, (int)size.height, 8); | |
9414 rep2 = pixmap2->image; | |
9413 | 9415 |
9414 /* Create an image with the data from the pixmap | 9416 /* Create an image with the data from the pixmap |
9415 * to go into the image view. | 9417 * to go into the image view. |
9416 */ | 9418 */ |
9417 image = [[NSImage alloc] initWithSize:[rep size]]; | 9419 image = [[NSImage alloc] initWithSize:[rep size]]; |
9420 flipped = [[NSImage alloc] initWithSize:[rep size]]; | |
9418 [image addRepresentation:rep]; | 9421 [image addRepresentation:rep]; |
9419 [iv setImage:image]; | 9422 [flipped addRepresentation:pixmap->image]; |
9423 [iv setImage:flipped]; | |
9420 [iv setImageScaling:NSScaleProportionally]; | 9424 [iv setImageScaling:NSScaleProportionally]; |
9421 [iv setFrameOrigin:NSMakePoint(0,0)]; | 9425 [iv setFrameOrigin:NSMakePoint(0,0)]; |
9422 [iv setFrameSize:size]; | 9426 [iv setFrameSize:size]; |
9423 | 9427 |
9424 /* Create the print operation using the image view and | 9428 /* Create the print operation using the image view and |
9441 /* Cycle through each page */ | 9445 /* Cycle through each page */ |
9442 for(x=start; x<end && p->drawfunc; x++) | 9446 for(x=start; x<end && p->drawfunc; x++) |
9443 { | 9447 { |
9444 /* Call the application's draw function */ | 9448 /* Call the application's draw function */ |
9445 p->drawfunc(print, pixmap, x, p->drawdata); | 9449 p->drawfunc(print, pixmap, x, p->drawdata); |
9450 /* Internal representation is flipped... so flip again so we can print */ | |
9451 _flip_image(image, rep2, size); | |
9452 /* Save it to file to see what we have */ | |
9453 NSData *data = [rep2 representationUsingType: NSPNGFileType properties: nil]; | |
9454 [data writeToFile: @"print.png" atomically: NO]; | |
9446 /* Print the image view */ | 9455 /* Print the image view */ |
9447 [po runOperation]; | 9456 [po runOperation]; |
9448 /* Fill the pixmap with white in case we are printing more pages */ | 9457 /* Fill the pixmap with white in case we are printing more pages */ |
9449 dw_color_foreground_set(DW_CLR_WHITE); | 9458 dw_color_foreground_set(DW_CLR_WHITE); |
9450 dw_draw_rect(0, pixmap, TRUE, 0, 0, (int)size.width, (int)size.height); | 9459 dw_draw_rect(0, pixmap, TRUE, 0, 0, (int)size.width, (int)size.height); |
9451 } | 9460 } |
9452 if(p->drawfunc) | 9461 if(p->drawfunc) |
9453 result = DW_ERROR_NONE; | 9462 result = DW_ERROR_NONE; |
9454 /* Free memory */ | 9463 /* Free memory */ |
9455 [image release]; | 9464 [image release]; |
9465 [flipped release]; | |
9456 dw_pixmap_destroy(pixmap); | 9466 dw_pixmap_destroy(pixmap); |
9467 dw_pixmap_destroy(pixmap2); | |
9457 free(p); | 9468 free(p); |
9458 [iv release]; | 9469 [iv release]; |
9459 return result; | 9470 return result; |
9460 } | 9471 } |
9461 | 9472 |