📄 print_pic.c
字号:
#include <stdio.h>#include <stdlib.h>#include <Pt.h>PtWidget_t *pane, *window;PpPrintContext_t *pc;int quit_cb ( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo){ PpReleasePC (pc); fflush( stdout ); exit (EXIT_SUCCESS); return (Pt_CONTINUE);}int print_cb ( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo){ int action; /* You could make these calls to PpSetPC() right after creating the print context. Having it here lets you reuse the print context. */ PhDim_t size = { 850, 1100 }; PhDim_t size2 = { 200, 150 }; /* Set the source resolution to be proportional to the size of a page. */ fflush( stdout ); PpSetPC(pc, Pp_PC_SOURCE_SIZE, &size, 0); fflush( stdout ); /* Uncomment this to set the source size to be the size of the widget. The widget will be scaled when printed. */ /* PpSetPC(pc, Pp_PC_SOURCE_SIZE, &size2, 0); */ action = PtPrintSelection(window, NULL, "Demo Print Selector", pc, Pt_PRINTSEL_DFLT_LOOK); if (action != Pt_PRINTSEL_CANCEL) { /* Start printing the pane. Note that we're using the same print context for all print jobs. */ PpStartJob(pc); fflush( stdout ); PpContinueJob(pc); fflush( stdout ); /* Print the widget. */ PpPrintWidget(pc, pane, NULL, NULL, 0); fflush( stdout ); /* Close the print context. */ PpSuspendJob(pc); PpEndJob(pc); } return (Pt_CONTINUE);}int main(int argc, char *argv[]){ PtArg_t args[4]; PtWidget_t *print, *quit; PhDim_t win_dim = { 200, 200 }; PhArea_t pane_area = { {0, 0}, {200, 150} }; PhArea_t print_area = { {30, 170}, {60, 20} }; PhArea_t quit_area = { {110, 170}, {60, 20} }; PhArea_t cir_area = { {35, 20}, {130, 110} }; PhArea_t cir2_area = { {67, 40}, {20, 20} }; PhArea_t cir3_area = { {110, 40}, {20, 20} }; PhArea_t cir4_area = { {85, 80}, {30, 30} }; PtCallback_t callbacks[2] = { {print_cb, NULL}, {quit_cb, NULL} }; if (PtInit(NULL) == -1) PtExit(EXIT_FAILURE); /* Create the main window. */ PtSetArg (&args[0], Pt_ARG_DIM, &win_dim, 0); PtSetArg (&args[1], Pt_ARG_WINDOW_TITLE, "Print Example", 0); if ((window = PtCreateWidget(PtWindow, Pt_NO_PARENT, 2, args)) == NULL) PtExit(EXIT_FAILURE); /* Create a print context. */ pc = PpCreatePC(); fflush( stdout ); /* Create the pane to be printed. */ PtSetArg (&args[0], Pt_ARG_AREA, &pane_area, 0); pane = PtCreateWidget (PtPane, window, 1, args); /* put some stuff in the pane to be printed. */ PtSetArg (&args[0], Pt_ARG_AREA, &cir_area, 0); PtCreateWidget (PtEllipse, pane, 1, args); PtSetArg (&args[0], Pt_ARG_AREA, &cir2_area, 0); PtSetArg (&args[1], Pt_ARG_FILL_COLOR, Pg_BLACK, 0); PtCreateWidget (PtEllipse, pane, 2, args); PtSetArg (&args[0], Pt_ARG_AREA, &cir3_area, 0); PtSetArg (&args[1], Pt_ARG_FILL_COLOR, Pg_BLACK, 0); PtCreateWidget (PtEllipse, pane, 2, args); PtSetArg (&args[0], Pt_ARG_AREA, &cir4_area, 0); PtCreateWidget (PtEllipse, pane, 1, args); /* Create the print button. */ PtSetArg(&args[0], Pt_ARG_AREA, &print_area, 0); PtSetArg(&args[1], Pt_ARG_TEXT_STRING, "Print", 0); PtSetArg(&args[2], Pt_CB_ACTIVATE, &callbacks[0], 0); print = PtCreateWidget (PtButton, window, 3, args); /* Create the quit button. */ PtSetArg(&args[0], Pt_ARG_AREA, &quit_area, 0); fflush( stdout ); PtSetArg(&args[1], Pt_ARG_TEXT_STRING, "Quit", 0); PtSetArg(&args[2], Pt_CB_ACTIVATE, &callbacks[1], 0); quit = PtCreateWidget (PtButton, window, 3, args); PtRealizeWidget(window); PtMainLoop(); return (EXIT_SUCCESS);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -