📄 hpijs.cpp
字号:
/*****************************************************************************\ hpijs.cpp : HP Inkjet Server Copyright (c) 2001 - 2004, Hewlett-Packard Co. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the Hewlett-Packard nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\*****************************************************************************/#include <sys/stat.h>#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <syslog.h>#include <string.h>#include <unistd.h>#include <fcntl.h>#include "header.h"#include "ijs.h"#include "ijs_server.h"#include "services.h"#include "hpijs.h"extern int hpijs97();int bug(const char *fmt, ...){ char buf[256]; va_list args; int n; va_start(args, fmt); if ((n = vsnprintf(buf, 256, fmt, args)) == -1) buf[255] = 0; /* output was truncated */ fprintf(stderr, buf); syslog(LOG_WARNING, buf); fflush(stderr); va_end(args); return n;}/* Set Print Context. */int hpijs_set_context(UXServices *pSS){ int r; if (pSS->PenSet != DUMMY_PEN) { if ((r = pSS->pPC->SetPenSet((PEN_TYPE)pSS->PenSet)) != NO_ERROR) bug("unable to SetPenSet set=%d, err=%d\n", pSS->PenSet, r); } if ((r = pSS->pPC->SelectPrintMode((QUALITY_MODE)pSS->Quality, (MEDIATYPE)pSS->MediaType, (COLORMODE)pSS->ColorMode)) != NO_ERROR) { BOOL bDevText; bug("unable to set Quality=%d, ColorMode=%d, MediaType=%d, err=%d\n", pSS->Quality, pSS->ColorMode, pSS->MediaType, r); pSS->pPC->GetPrintModeSettings((QUALITY_MODE &)pSS->Quality, (MEDIATYPE &)pSS->MediaType, (COLORMODE &)pSS->ColorMode, bDevText); bug("following will be used Quality=%d, ColorMode=%d, MediaType=%d\n", pSS->Quality, pSS->ColorMode, pSS->MediaType); } /* Map ghostscript paper size to APDK paper size. */ pSS->MapPaperSize(pSS->PaperWidth, pSS->PaperHeight); /* Do duplex stuff now, since we have a valid print mode. */ if (pSS->Duplex && !pSS->Tumble) { if (pSS->pPC->SelectDuplexPrinting(DUPLEXMODE_BOOK) != TRUE) bug("unable to set duplex mode=book\n"); } else if (pSS->Duplex && pSS->Tumble) { if (pSS->pPC->SelectDuplexPrinting(DUPLEXMODE_TABLET) != TRUE) bug("unable to set duplex mode=tablet\n"); } else { pSS->pPC->SelectDuplexPrinting(DUPLEXMODE_NONE); } if (pSS->MediaPosition != sourceTrayAuto) { if (pSS->pPC->SetMediaSource((MediaSource)pSS->MediaPosition) != NO_ERROR) bug("unable to set MediaPosition=%d\n", pSS->MediaPosition); } return 0;}int hpijs_status_cb(void *status_cb_data, IjsServerCtx *ctx, IjsJobId job_id){ return 0;}int hpijs_list_cb(void *list_cb_data, IjsServerCtx *ctx, IjsJobId job_id, char *val_buf, int val_size){ return snprintf(val_buf, val_size, "OutputFD,DeviceManufacturer,DeviceModel,PageImageFormat,Dpi,Width,Height,BitsPerSample,ColorSpace,PaperSize,PrintableArea,PrintableTopLeft,PS:Duplex,PS:Tumble,Quality:Quality,Quality:MediaType,Quality:ColorMode,Quality:PenSet,Quality:FullBleed,PS:MediaPosition");}int hpijs_enum_cb(void *enum_cb_data, IjsServerCtx *ctx, IjsJobId job_id, const char *key, char *val_buf, int val_size){ UXServices *pSS = (UXServices*)enum_cb_data; if (!strcmp (key, "ColorSpace")) { if (pSS->pPC->SupportSeparateBlack()) return snprintf(val_buf, val_size, "sRGB,KRGB"); else return snprintf(val_buf, val_size, "sRGB"); } else if (!strcmp (key, "DeviceManufacturer")) return snprintf(val_buf, val_size, "HEWLETT-PACKARD,APOLLO,HP"); else if (!strcmp (key, "PageImageFormat")) return snprintf(val_buf, val_size, "Raster"); else if (!strcmp (key, "BitsPerSample")) return snprintf(val_buf, val_size, "8"); else if (!strcmp (key, "PS:Duplex")) { if (pSS->pPC->SelectDuplexPrinting(DUPLEXMODE_BOOK) == TRUE) return snprintf(val_buf, val_size, "true"); else return snprintf(val_buf, val_size, "false"); pSS->pPC->SelectDuplexPrinting(DUPLEXMODE_NONE); } else if (!strcmp (key, "PS:Tumble")) { if (pSS->pPC->SelectDuplexPrinting(DUPLEXMODE_TABLET) == TRUE) return snprintf(val_buf, val_size, "true"); else return snprintf(val_buf, val_size, "false"); pSS->pPC->SelectDuplexPrinting(DUPLEXMODE_NONE); } else bug("unable to enum key=%s\n", key); return IJS_ERANGE;}/* * Set parameter (in the server) call back. Note, OutputFD is the only call that can be * preceded by set DeviceManufacturer and DeviceModel. */int hpijs_set_cb (void *set_cb_data, IjsServerCtx *ctx, IjsJobId job_id, const char *key, const char *value, int value_size){ UXServices *pSS = (UXServices*)set_cb_data; int fd, r; char *tail; int status = 0; char svalue[IJS_MAX_PARAM+1]; float w, h; /* Sanity check input value. */ if (value_size > IJS_MAX_PARAM) { memcpy(svalue, value, IJS_MAX_PARAM); svalue[IJS_MAX_PARAM] = 0; } else { memcpy(svalue, value, value_size); svalue[value_size] = 0; } if (!strcmp (key, "OutputFD")) { fd = strtol(svalue, &tail, 10); pSS->OutputPath = fd; /* set prn_stream as output of SS::ToDevice */ } else if (!strcmp (key, "DeviceManufacturer")) { if ((strncasecmp(svalue, "HEWLETT-PACKARD", 15) != 0) && (strncasecmp(svalue, "APOLLO", 6) != 0) && (strncasecmp(svalue, "HP", 2) != 0)) { bug("unable to set DeviceManufacturer=%s\n", svalue); status = -1; } } else if (!strcmp (key, "DeviceModel")) { if ((r = pSS->pPC->SelectDevice(svalue)) != NO_ERROR) { /* OfficeJet LX is not very unique, do separate check here. */ if (!strncmp(svalue,"OfficeJet", 10)) r = pSS->pPC->SelectDevice("DESKJET 540"); } if (r == NO_ERROR) { pSS->Model = 1; /* Got a valid device class, let's set some print mode defaults. */ BOOL bDevText; pSS->pPC->GetPrintModeSettings((QUALITY_MODE &)pSS->Quality, (MEDIATYPE &)pSS->MediaType, (COLORMODE &)pSS->ColorMode, bDevText); } else { bug("unable to set device=%s, err=%d\n", svalue, r); status = -1; } } else if ((strcmp (key, "PS:Duplex") == 0) || (strcmp (key, "Duplex") == 0)) { if (strncmp(svalue, "true", 4) == 0) pSS->Duplex = 1; else pSS->Duplex = 0; } else if ((strcmp (key, "PS:Tumble") == 0) || (strcmp (key, "Tumble") == 0)) { if (strncmp(svalue, "true", 4) == 0) pSS->Tumble = 1; else pSS->Tumble = 0; } else if (!strcmp (key, "PaperSize")) { w = (float)strtod(svalue, &tail); h = (float)strtod(tail+1, &tail); if (pSS->FirstRaster) { /* Normal start of print Job. */ pSS->PaperWidth = w; pSS->PaperHeight = h; hpijs_set_context(pSS); } else { /* Middle of print Job, ignore paper size if same. */ if (!(w == pSS->PaperWidth && h == pSS->PaperHeight)) { pSS->FirstRaster = 1; /* force new Job */ pSS->PaperWidth = w; /* set new paper size */ pSS->PaperHeight = h; hpijs_set_context(pSS); } } } else if (!strcmp (key, "TopLeft")) { /* not currently used */ } else if (!strcmp (key, "Quality:Quality")) { pSS->Quality = strtol(svalue, &tail, 10); } else if (!strcmp (key, "Quality:MediaType")) { pSS->MediaType = strtol(svalue, &tail, 10); } else if (!strcmp (key, "Quality:ColorMode")) { pSS->ColorMode = strtol(svalue, &tail, 10); } else if (!strcmp (key, "Quality:PenSet")) { pSS->PenSet = strtol(svalue, &tail, 10); } else if (!strcmp (key, "Quality:FullBleed")) { pSS->FullBleed = strtol(svalue, &tail, 10); } else if (!strcmp (key, "PS:MediaPosition")) { pSS->MediaPosition = strtol(svalue, &tail, 10); } else bug("unable to set key=%s, value=%s\n", key, svalue); return status;}/* Get parameter (from the server) call back. Note, all calls must be preceded by set DeviceName. */int hpijs_get_cb(void *get_cb_data, IjsServerCtx *ctx, IjsJobId job_id, const char *key, char *value_buf, int value_size){ UXServices *pSS = (UXServices*)get_cb_data; if (!strcmp (key, "PrintableArea")) { /* If duplexing, adjust printable height to 1/2 inch top/bottom margins, except laserjets. */ if ((pSS->pPC->QueryDuplexMode() != DUPLEXMODE_NONE) && pSS->pPC->RotateImageForBackPage()) return snprintf(value_buf, value_size, "%.4fx%.4f", pSS->pPC->PrintableWidth(), pSS->pPC->PhysicalPageSizeY()-1); else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -