📄 hpijs.cpp
字号:
return snprintf(value_buf, value_size, "%.4fx%.4f", pSS->pPC->PrintableWidth(), pSS->pPC->PrintableHeight()); } else if (!strcmp (key, "PrintableTopLeft")) { /* If duplexing, adjust printable top to 1/2 inch top margin, except laserjets. */ if ((pSS->pPC->QueryDuplexMode() != DUPLEXMODE_NONE) && pSS->pPC->RotateImageForBackPage()) return snprintf(value_buf, value_size, "%.4fx%.4f", pSS->pPC->PrintableStartX(), 0.5); else return snprintf(value_buf, value_size, "%.4fx%.4f", pSS->pPC->PrintableStartX(), pSS->pPC->PrintableStartY()); } else if ((!strcmp (key, "Duplex")) || (!strcmp (key, "PS:Duplex"))) { if (pSS->pPC->QueryDuplexMode() == DUPLEXMODE_NONE) return snprintf(value_buf, value_size, "false"); else return snprintf(value_buf, value_size, "true"); } else if ((!strcmp (key, "Tumble")) || (!strcmp (key, "PS:Tumble"))) { if (pSS->pPC->QueryDuplexMode() == DUPLEXMODE_TABLET) return snprintf(value_buf, value_size, "true"); else return snprintf(value_buf, value_size, "false"); } else if (!strcmp (key, "PaperSize")) { return snprintf(value_buf, value_size, "%.4fx%.4f", pSS->pPC->PhysicalPageSizeX(), pSS->pPC->PhysicalPageSizeY()); } else if (!strcmp (key, "Dpi")) { return snprintf(value_buf, value_size, "%dx%d", pSS->pPC->EffectiveResolutionX(), pSS->pPC->EffectiveResolutionY()); } else if (!strcmp (key, "DeviceModel")) { return snprintf(value_buf, value_size, "%s", pSS->pPC->PrinterModel()); } else if (!strcmp (key, "Quality:Quality")) { return snprintf(value_buf, value_size, "%d", pSS->Quality); } else if (!strcmp (key, "Quality:ColorMode")) { return snprintf(value_buf, value_size, "%d", pSS->ColorMode); } else if (!strcmp (key, "Quality:MediaType")) { return snprintf(value_buf, value_size, "%d", pSS->MediaType); } else if (!strcmp (key, "ColorSpace")) { return snprintf(value_buf, value_size, pSS->ph.cs); } else if (!strcmp (key, "PageImageFormat")) { return snprintf(value_buf, value_size, "Raster"); } else if (!strcmp (key, "BitsPerSample")) { return snprintf(value_buf, value_size, "8"); } else if (!strcmp (key, "PS:MediaPosition")) { return snprintf(value_buf, value_size, "%d", pSS->MediaPosition); } else bug("unable to get key=%s\n", key); return IJS_EUNKPARAM;}/* Get raster from the client. */int hpijs_get_client_raster(IjsServerCtx *ctx, char *buf, int size, char white){ int status, clean=1, i; status = ijs_server_get_data(ctx, (char *)buf, size); if (status < 0) return status; /* error */ /* Check for blank raster. */ for (i = 0; i < size; i++) { if (buf[i] != white) { clean = 0; break; } } if (clean) return 0; return size;}int main(int argc, char *argv[]){ UXServices *pSS = NULL; IjsServerCtx *ctx = NULL; char *raster = NULL, *k_raster = NULL; int status = EXIT_FAILURE; int ret, n, i, kn=0, width, k_width; if (argc > 1) { const char *arg = argv[1]; if ((arg[0] == '-') && (arg[1] == 'h')) { fprintf(stdout, "\nHewlett-Packard Co. Inkjet Server %s\n", VERSION); fprintf(stdout, "Copyright (c) 2001-2004, Hewlett-Packard Co.\n"); exit(0); } } ctx = ijs_server_init(); if (ctx == NULL) { bug("unable to init hpijs server\n"); goto BUGOUT; } pSS = new UXServices(); if (pSS->constructor_error != NO_ERROR) { bug("unable to open Services object err=%d\n", pSS->constructor_error); goto BUGOUT; }#ifdef CAPTURE if ((pSS->InitScript("/tmp/capout", TRUE)) != NO_ERROR) bug("unable to init capture");#endif pSS->pPC = new PrintContext(pSS, 0, 0); if (pSS->pPC->constructor_error > 0) { bug("unable to open PrintContext object err=%d\n", pSS->pPC->constructor_error); goto BUGOUT; } if (pSS->pPC->constructor_error < 0) bug("WARNING: %s\n", pSS->GetDriverMessage(pSS->pPC->constructor_error)); /* Turn off any bi-di support. Allow bi-di for printer capabilities only. */ pSS->IOMode.bDevID = pSS->IOMode.bStatus = FALSE;#if 0 bug("device model=%s\n", pSS->pPC->PrinterModel()); bug("device class=%s\n", pSS->pPC->PrintertypeToString(pSS->pPC->SelectedDevice())); bug("default pen=%d\n", pSS->pPC->GetDefaultPenSet()); bug("installed pen=%d\n", pSS->pPC->GetInstalledPens());#endif ijs_server_install_status_cb (ctx, hpijs_status_cb, pSS); ijs_server_install_list_cb (ctx, hpijs_list_cb, pSS); ijs_server_install_enum_cb (ctx, hpijs_enum_cb, pSS); ijs_server_install_set_cb (ctx, hpijs_set_cb, pSS); ijs_server_install_get_cb (ctx, hpijs_get_cb, pSS); while (1) { if ((ret = ijs_server_get_page_header(ctx, &pSS->ph)) < 0) { bug("unable to read client data err=%d\n", ret); goto BUGOUT; } if (pSS->Model == -1) goto BUGOUT; /* no device selected */ if (ret) { status = 0; /* normal exit */ break; } if (pSS->FirstRaster) { pSS->FirstRaster = 0; width = (int)(pSS->ph.xres * pSS->pPC->PrintableWidth() + 0.5); /* Desensitize input width, may be off by one due to paper size conversions. */ if (pSS->ph.width < width) width = pSS->ph.width; if ((ret = pSS->pPC->SetPixelsPerRow(width, width)) != NO_ERROR) { bug("unable to SetPixelsPerRow width=%d, err=%d\n", pSS->ph.width, ret); } if (pSS->pJob != NULL) delete pSS->pJob; pSS->pJob = new Job(pSS->pPC); if (pSS->pJob->constructor_error != NO_ERROR) { bug("unable to create Job object err=%d\n", pSS->pJob->constructor_error); goto BUGOUT; } if (pSS->pPC->QueryDuplexMode() != DUPLEXMODE_NONE) { if ((pSS->pPC->QueryDuplexMode() == DUPLEXMODE_BOOK) && pSS->pPC->RotateImageForBackPage()) pSS->InitDuplexBuffer(); pSS->BackPage = FALSE; } pSS->KRGB=0; if (strcmp(pSS->ph.cs, "KRGB") == 0) pSS->KRGB=1; #if 0 bug("papersize=%d\n", pSS->pPC->GetPaperSize()); bug("width=%d, height=%d\n", pSS->ph.width, pSS->ph.height); bug("EffResX=%d, EffResY=%d, InPixelsPerRow=%d, OutPixelsPerRow=%d\n", pSS->pPC->EffectiveResolutionX(), pSS->pPC->EffectiveResolutionY(), pSS->pPC->InputPixelsPerRow(), pSS->pPC->OutputPixelsPerRow()); bug("device=%s\n", pSS->pPC->PrinterModel());#endif } // pSS->FirstRaster if ((raster = (char *)malloc(pSS->ph.width*3)) == NULL) { bug("unable to allocate raster buffer size=%d: %m\n", pSS->ph.width*3); goto BUGOUT; } k_width = (pSS->ph.width + 7) >> 3; /* width of k plane in bytes, byte aligned */ if ((k_raster = (char *)malloc(k_width)) == NULL) { bug("unable to allocate black raster buffer size=%d: %m\n", k_width); goto BUGOUT; } memset(k_raster, 0, k_width); for (i=0; i < pSS->ph.height; i++) { if ((n = hpijs_get_client_raster(ctx, raster, pSS->ph.width*3, 0xff)) < 0) break; /* error */ if (pSS->KRGB) { if ((kn = hpijs_get_client_raster(ctx, k_raster, k_width, 0)) < 0) break; /* error */ } if (n == 0 && kn == 0) pSS->ProcessRaster((char *)0, (char *)0); /* blank raster */ else if (kn == 0) pSS->ProcessRaster(raster, (char *)0); else if (n == 0) pSS->ProcessRaster((char *)0, k_raster); else pSS->ProcessRaster(raster, k_raster); } free(raster); raster = NULL; free(k_raster); k_raster = NULL; if (pSS->pPC->QueryDuplexMode() != DUPLEXMODE_NONE) { if ((pSS->pPC->QueryDuplexMode() == DUPLEXMODE_BOOK) && pSS->pPC->RotateImageForBackPage() && pSS->BackPage) { pSS->SendBackPage(); } pSS->BackPage = (BOOL)((int)pSS->BackPage + 1) % 2; } pSS->pJob->NewPage(); } /* end while (1) */ if (pSS->pPC->QueryDuplexMode() != DUPLEXMODE_NONE) { if (pSS->BackPage) { /* Send extra blank line & newpage to eject the page. (for VIP printers). */ /* For malibu send enough blank lines to cause at least two blank rasters in Job::sendrasters(). 5/1/03, des */ // for (int i = 0; i < 201; i++) for (int i = 0; i < 401; i++) pSS->pJob->SendRasters((unsigned char *)0); pSS->pJob->NewPage(); } }BUGOUT: if (pSS != NULL) { if (pSS->pJob != NULL) delete pSS->pJob; if (pSS->pPC != NULL) delete pSS->pPC;#ifdef CAPTURE pSS->EndScript();#endif delete pSS; } if (raster != NULL) free(raster); if (k_raster != NULL) free(k_raster); if (ctx != NULL) ijs_server_done(ctx); exit(status);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -