From 4f4057b82ad4dd1cae091ba0f9c6ee17fd7103c7 Mon Sep 17 00:00:00 2001 From: Martin Mares <mj@ucw.cz> Date: Mon, 13 Jun 2016 18:54:36 +0200 Subject: [PATCH] Implemented most useful options --- xcpt.c | 116 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 31 deletions(-) diff --git a/xcpt.c b/xcpt.c index 4dac725..4c4c9b4 100644 --- a/xcpt.c +++ b/xcpt.c @@ -77,7 +77,19 @@ static char *xstrdup(const char *x) O(JOB_TITLE, "?") \ O(COPIES, "1") \ O(LANGUAGE, "?") \ - O(MEDIASIZE, "A4") + O(COLOR, "color") \ + O(ORIENTATION, "") \ + O(PRIVATE, "") \ + O(OFFSET, "none") \ + O(SIDES, "one-sided") \ + O(COLLATE, "uncollated") \ + O(OUTPUT, "automatic") \ + O(MEDIACOLOR, "white") \ + O(INPUTTRAY, "automatic") \ + O(TRAYFEED, "stack") \ + O(MEDIATYPE, "system-default") \ + O(MEDIAXSIZE, "21000") \ + O(MEDIAYSIZE, "29700") enum option { #define O(name, val) OPT_##name, @@ -98,6 +110,11 @@ char *opt[] = { #undef O }; +#define OPT(name) opt[OPT_##name] +#define OPT_IS(name, val) !strcasecmp(OPT(name), val) +#define OPT_IS_SET(name) *OPT(name) +#define OPT_IS_TRUE(name) OPT_IS(name, "yes") + static void set_option(char *key, char *val) { for (int i=0; i<OPT_MAX; i++) @@ -352,59 +369,84 @@ static void xcpt_name(const char *name, const char *text) static void gen_job_template(void) { - xcpt_integer("adjust-contrast", 0); + // Color adjustments + xcpt_integer("adjust-contrast", 0); // FIXME: all of them xcpt_integer("adjust-cyan-red", 0); xcpt_integer("adjust-lightness", 0); xcpt_integer("adjust-magenta-green", 0); xcpt_integer("adjust-saturation", 0); xcpt_integer("adjust-yellow-blue", 0); - xcpt_keyword("color-adjustment-set", "automatic"); - xcpt_keyword("color-effects-type", "color"); - xcpt_integer("copies", 1); - xcpt_keyword("document-reading-orientation", "portrait"); - xcpt_keyword("embedded-profiles", "automatic"); + if (OPT_IS(COLOR, "color")) + { + xcpt_keyword("color-adjustment-set", "automatic"); + xcpt_keyword("color-effects-type", "color"); + } + else + { + xcpt_keyword("color-adjustment-set", "monochrome-grayscale"); + xcpt_keyword("color-effects-type", "monochrome-grayscale"); + } + + xcpt_integer("copies", atoi(OPT(COPIES))); + if (OPT_IS_SET(ORIENTATION)) + xcpt_keyword("document-reading-orientation", OPT(ORIENTATION)); + + // FIXME xcpt_set_open("finishings"); xcpt_enum("value", 3); xcpt_close(); xcpt_keyword("halftone-text", "ignore-pdl"); - xcpt_keyword("hold-for-authentication", "none"); + xcpt_keyword("halftone-graphics", "ignore-pdl"); + xcpt_keyword("halftone-images", "ignore-pdl"); + if (OPT_IS_SET(PRIVATE)) + xcpt_keyword("hold-for-authentication", "user-id"); + else + xcpt_keyword("hold-for-authentication", "none"); + + // Interleaving not supported at the moment xcpt_collection_open("interleaved-sheets-col"); xcpt_keyword("interleaved-sheets-type", "none"); xcpt_close(); xcpt_set_open("job-offset"); - xcpt_keyword("value", "offset-set"); + xcpt_keyword("value", OPT(OFFSET)); xcpt_close(); + // Saved jobs are not supported at the moment xcpt_collection_open("job-save-disposition"); xcpt_keyword("save", "none"); xcpt_close(); - xcpt_keyword("job-sheets", "job-start-sheet"); + // We leave printing of banner sheets to CUPS itself + xcpt_keyword("job-sheets", "none"); xcpt_collection_open("client-default-attributes-col"); xcpt_collection_open("media-col"); - xcpt_keyword("input-tray", "automatic"); - xcpt_keyword("media-color", "white"); + xcpt_keyword("input-tray", OPT(INPUTTRAY)); + xcpt_keyword("tray-feed", OPT(TRAYFEED)); + xcpt_keyword("media-color", OPT(MEDIACOLOR)); xcpt_collection_open("media-size"); - xcpt_integer("x-dimension", 21000); - xcpt_integer("y-dimension", 29700); + xcpt_integer("x-dimension", atoi(OPT(MEDIAXSIZE))); + xcpt_integer("y-dimension", atoi(OPT(MEDIAYSIZE))); xcpt_close(); - xcpt_keyword("media-type", "system-default"); + xcpt_keyword("media-type", OPT(MEDIATYPE)); xcpt_close(); - xcpt_keyword("print-quality-level", "standard"); - xcpt_keyword("sides", "two-sided-long-edge"); + xcpt_keyword("print-quality-level", "standard"); // FIXME + xcpt_keyword("sides", OPT(SIDES)); xcpt_close(); - xcpt_keyword("output-bin", "automatic"); + xcpt_keyword("output-bin", OPT(OUTPUT)); + xcpt_keyword("sheet-collate", OPT(COLLATE)); + + // Rendering intents and color sources: so far, nothing can be set + xcpt_keyword("embedded-profiles", "automatic"); xcpt_keyword("print-settings", "none"); xcpt_keyword("rendering-intent-graphics", "automatic"); xcpt_keyword("rendering-intent-images", "automatic"); xcpt_keyword("rendering-intent-text", "automatic"); - xcpt_keyword("sheet-collate", "collated"); xcpt_keyword("spot-color-mapping", "use-local-printer-values"); xcpt_keyword("undefined-source-cmyk-images", "automatic"); xcpt_keyword("undefined-source-cmyk-text", "automatic"); @@ -418,16 +460,21 @@ static void gen_job_template(void) static void gen_job_operation(void) { - xcpt_keyword("creator-name-attributes", "windows-ps-driver"); - xcpt_keyword("creator-name-pdl", "explorer"); - xcpt_text("creator-version-attributes", "cups-xcpt"); - xcpt_text("creator-version-pdl", "6.1.7601.17567"); // FIXME - xcpt_media_type("document-format", "application/postscript"); // FIXME - xcpt_name("job-id-from-client", "TOP SECRET JOB #1"); - xcpt_name("job-name", "Test Page"); - xcpt_name("job-originating-user-domain", "KAM"); - xcpt_name("job-originating-user-name", "nobody"); - xcpt_name("requesting-user-name", "nobody"); + xcpt_keyword("creator-name-attributes", "cups-xcpt"); + xcpt_keyword("creator-name-pdl", "unknown"); + xcpt_text("creator-version-attributes", "0.1"); // FIXME + xcpt_text("creator-version-pdl", "0.0"); + if (OPT_IS(LANGUAGE, "PDF")) + xcpt_media_type("document-format", "application/pdf"); + else + xcpt_media_type("document-format", "application/postscript"); + xcpt_name("job-id-from-client", OPT(JOB_ID)); + xcpt_name("job-name", OPT(JOB_TITLE)); + xcpt_name("job-originating-user-domain", "KAM"); // FIXME + + const char *user = OPT(USERNAME); + xcpt_name("job-originating-user-name", user); + xcpt_name("requesting-user-name", user); } static void gen_xcpt(void) @@ -448,12 +495,19 @@ static void gen_xcpt(void) xcpt_close(); ASSERT(!xcpt_level); - printf("@PJL ENTER LANGUAGE = %s\n", opt[OPT_LANGUAGE]); + printf("@PJL ENTER LANGUAGE = %s\n", OPT(LANGUAGE)); } static void copy_body(void) { - // FIXME + char buf[1024]; + size_t n; + + while (n = fread(buf, 1, sizeof(buf), stdin)) + { + if (fwrite(buf, 1, n, stdout) != n) + bug("Write error"); + } } /*** Main ***/ -- GitLab