diff options
author | scuri <scuri> | 2010-06-13 05:26:57 +0000 |
---|---|---|
committer | scuri <scuri> | 2010-06-13 05:26:57 +0000 |
commit | 62d214b0afe2afe4d2a39bcba4ccff5595ef4593 (patch) | |
tree | a099d7889d04cd05c2690fe5444114eec007ae7d /src | |
parent | 6cc4fd9f87137f98096cb53c6fbccd9e45b06d03 (diff) |
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r-- | src/cairo/cdcairoctx.h | 5 | ||||
-rw-r--r-- | src/cairo/cdcairoimg.c | 1 | ||||
-rw-r--r-- | src/cairo/cdcairoplus.c | 4 | ||||
-rw-r--r-- | src/cairo/cdcairoprn.c | 144 | ||||
-rw-r--r-- | src/config.mak | 5 | ||||
-rw-r--r-- | src/drv/cd0prn.c | 8 |
6 files changed, 162 insertions, 5 deletions
diff --git a/src/cairo/cdcairoctx.h b/src/cairo/cdcairoctx.h index 03a719c..776e8a8 100644 --- a/src/cairo/cdcairoctx.h +++ b/src/cairo/cdcairoctx.h @@ -13,6 +13,9 @@ #include "cd.h" #include "cd_private.h" +#ifndef __GTK_PRINT_UNIX_DIALOG_H__ +typedef struct _GtkPrintJob GtkPrintJob; +#endif struct _cdCtxImage { unsigned int w, h; @@ -68,6 +71,8 @@ struct _cdCtxCanvas cdImage* image_dbuffer; /* Used by double buffer driver */ cdCanvas* canvas_dbuffer; + + GtkPrintJob* job; /* used in Printer */ }; #define cdCairoGetRed(_) (((double)cdRed(_))/255.) diff --git a/src/cairo/cdcairoimg.c b/src/cairo/cdcairoimg.c index 04b3f46..bc39129 100644 --- a/src/cairo/cdcairoimg.c +++ b/src/cairo/cdcairoimg.c @@ -45,7 +45,6 @@ static cdContext cdImageContext = NULL }; - cdContext* cdContextCairoImage(void) { return &cdImageContext; diff --git a/src/cairo/cdcairoplus.c b/src/cairo/cdcairoplus.c index c50f1ec..5da7546 100644 --- a/src/cairo/cdcairoplus.c +++ b/src/cairo/cdcairoplus.c @@ -18,8 +18,8 @@ void cdInitContextPlus(void) ctx_list[CD_CTX_NATIVEWINDOW] = cdContextCairoNativeWindow(); ctx_list[CD_CTX_IMAGE] = cdContextCairoImage(); ctx_list[CD_CTX_DBUFFER] = cdContextCairoDBuffer(); -#ifdef WIN32 -// ctx_list[CD_CTX_PRINTER] = cdContextCairoPrinter(); +#ifndef WIN32 + ctx_list[CD_CTX_PRINTER] = cdContextCairoPrinter(); #endif cdInitContextPlusList(ctx_list); diff --git a/src/cairo/cdcairoprn.c b/src/cairo/cdcairoprn.c new file mode 100644 index 0000000..924b1a2 --- /dev/null +++ b/src/cairo/cdcairoprn.c @@ -0,0 +1,144 @@ +/** \file + * \brief Cairo/GTK Printer Driver (UNIX Only) + * + * See Copyright Notice in cd.h + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <gtk/gtkprintunixdialog.h> + +#include "cdcairoctx.h" +#include "cdprint.h" + + + +static void cdkillcanvas(cdCtxCanvas *ctxcanvas) +{ + //if(ctxcanvas->settings) + // g_object_unref(ctxcanvas->settings); + + gtk_print_job_send(ctxcanvas->job, NULL, NULL, NULL); + + cdcairoKillCanvas(ctxcanvas); +} + +static char* get_printername_attrib(cdCtxCanvas* ctxcanvas) +{ + return (char*)gtk_printer_get_name(gtk_print_job_get_printer(ctxcanvas->job)); +} + +static cdAttribute printername_attrib = +{ + "PRINTERNAME", + NULL, + get_printername_attrib +}; + +static void cdcreatecanvas(cdCanvas* canvas, void *data) +{ + cdCtxCanvas* ctxcanvas; + char *data_str = (char*) data; + char docname[256] = "CD - Canvas Draw Document"; + GtkPrintUnixDialog* dialog; + GtkPrinter* printer; + GtkPrintSettings* settings; + GtkPageSetup* page_setup; + GtkPrintJob* job; + int show_dialog = 0; + + /* Starting parameters */ + if (data_str == NULL) + return; + + if (data_str[0] != 0) + { + char *ptr = strstr(data_str, "-d"); + + if (ptr != NULL) + show_dialog = 1; + + if (data_str[0] != '-') + { + strcpy(docname, data_str); + + if (show_dialog) + docname[ptr - data_str - 1] = 0; + } + } + + dialog = (GtkPrintUnixDialog*)gtk_print_unix_dialog_new(NULL, NULL); + + //GTK_PRINT_CAPABILITY_PAGE_SET = 1 << 0, + //GTK_PRINT_CAPABILITY_COPIES = 1 << 1, + //GTK_PRINT_CAPABILITY_COLLATE = 1 << 2, + //GTK_PRINT_CAPABILITY_REVERSE = 1 << 3, + //GTK_PRINT_CAPABILITY_SCALE = 1 << 4, + //GTK_PRINT_CAPABILITY_GENERATE_PDF = 1 << 5, + //GTK_PRINT_CAPABILITY_GENERATE_PS = 1 << 6, + //GTK_PRINT_CAPABILITY_PREVIEW = 1 << 7, + //GTK_PRINT_CAPABILITY_NUMBER_UP = 1 << 8, + //GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT = 1 << 9 + + gtk_print_unix_dialog_set_manual_capabilities(dialog, GTK_PRINT_CAPABILITY_GENERATE_PDF|GTK_PRINT_CAPABILITY_GENERATE_PS); + + gtk_widget_realize(GTK_WIDGET(dialog)); + + if (show_dialog) + { + int response = gtk_dialog_run(GTK_DIALOG(dialog)); + + if (response == GTK_RESPONSE_CANCEL) + { + gtk_widget_destroy(GTK_WIDGET(dialog)); + return; + } + } + + printer = gtk_print_unix_dialog_get_selected_printer(dialog); + settings = gtk_print_unix_dialog_get_settings(dialog); + page_setup = gtk_print_unix_dialog_get_page_setup(dialog); + + job = gtk_print_job_new(docname, printer, settings, page_setup); + + canvas->w = (int)gtk_page_setup_get_page_width(page_setup, GTK_UNIT_PIXEL); + canvas->h = (int)gtk_page_setup_get_page_height(page_setup, GTK_UNIT_PIXEL); + canvas->w_mm = (int)gtk_page_setup_get_page_width(page_setup, GTK_UNIT_MM); + canvas->h_mm = (int)gtk_page_setup_get_page_height(page_setup, GTK_UNIT_MM); + canvas->bpp = 24; + canvas->xres = (double)canvas->w / canvas->w_mm; + canvas->yres = (double)canvas->h / canvas->h_mm; + + ctxcanvas = cdcairoCreateCanvas(canvas, cairo_create(gtk_print_job_get_surface(job, NULL))); + ctxcanvas->job = job; + + cdRegisterAttribute(canvas, &printername_attrib); + +// gtk_widget_destroy(GTK_WIDGET(dialog)); + //g_object_unref(settings); +} + +static void cdinittable(cdCanvas* canvas) +{ + cdcairoInitTable(canvas); + + canvas->cxKillCanvas = cdkillcanvas; +} + +static cdContext cdPrinterCairoContext = +{ + CD_CAP_ALL & ~(CD_CAP_PLAY | CD_CAP_YAXIS | CD_CAP_REGION | CD_CAP_GETIMAGERGB | + CD_CAP_WRITEMODE | CD_CAP_PALETTE | CD_CAP_IMAGESRV), + 0, + cdcreatecanvas, + cdinittable, + NULL, + NULL, +}; + +cdContext* cdContextCairoPrinter(void) +{ + return &cdPrinterCairoContext; +} diff --git a/src/config.mak b/src/config.mak index d9af743..a972968 100644 --- a/src/config.mak +++ b/src/config.mak @@ -37,6 +37,7 @@ SRCCOMM = cd.c wd.c wdhdcpy.c rgb2map.c cd_vectortext.c cd_active.c \ cd_attributes.c cd_bitmap.c cd_image.c cd_primitives.c cd_text.c cd_util.c SRC = $(SRCCOMM) $(SRCSVG) $(SRCINTCGM) $(SRCDRV) $(SRCSIM) +INCLUDES = . drv x11 win32 intcgm freetype2 sim cairo ../include ifneq ($(findstring Win, $(TEC_SYSNAME)), ) ifdef USE_GDK @@ -50,7 +51,8 @@ ifneq ($(findstring Win, $(TEC_SYSNAME)), ) LIBS = freetype6 else ifdef USE_GDK - SRC += $(SRCGDK) $(SRCCAIRO) + SRC += $(SRCGDK) $(SRCCAIRO) cairo/cdcairoprn.c + INCLUDES += /usr/include/gtk-unix-print-2.0 USE_GTK = Yes LIBS += cairo ifndef GTK_DEFAULT @@ -75,4 +77,3 @@ endif LDIR = ../lib/$(TEC_UNAME) -INCLUDES = . drv x11 win32 intcgm freetype2 sim cairo ../include diff --git a/src/drv/cd0prn.c b/src/drv/cd0prn.c index 429a392..fa313d8 100644 --- a/src/drv/cd0prn.c +++ b/src/drv/cd0prn.c @@ -6,12 +6,20 @@ #include <stdlib.h> #include "cd.h" +#include "cd_private.h" #include "cdprint.h" cdContext* cdContextPrinter(void) { + if (cdUseContextPlus(CD_QUERY)) + { + cdContext* ctx = cdGetContextPlus(CD_CTX_PRINTER); + if (ctx != NULL) + return ctx; + } + return NULL; } |