📄 eprnparm.c
字号:
our colour mapping functions. According to Drivers.htm, a value of at least 31 for max_gray or max_color (actually, the documentation says "max_rgb") leads to ghostscript using the colour returned by the device if valid instead of using the dither parameters for halftoning. The actual values for the max_* parameters should then be irrelevant. */ if (eprn->non_black_levels > 0) dev->color_info.max_color = 255; else dev->color_info.max_color = 0; dev->color_info.max_gray = 255; /* As long as our colour mapping functions return valid color indices, the following parameters should be irrelevant. */ dev->color_info.dither_grays = 256; if (dev->color_info.num_components == 1) dev->color_info.dither_colors = 0; else dev->color_info.dither_colors = dev->color_info.max_color + 1; } else { /* Let ghostscript do halftoning */ if (eprn->non_black_levels > 0) dev->color_info.max_color = eprn->non_black_levels - 1; else dev->color_info.max_color = 0; if (eprn->black_levels > 0) dev->color_info.max_gray = eprn->black_levels - 1; else dev->color_info.max_gray = dev->color_info.max_color; /* The dither parameters */ if (eprn->black_levels > 0) dev->color_info.dither_grays = eprn->black_levels; else dev->color_info.dither_grays = eprn->non_black_levels; if (eprn->non_black_levels > 0) dev->color_info.dither_colors = eprn->non_black_levels; else dev->color_info.dither_colors = 0; } return;}/****************************************************************************** Function: eprn_put_params This function reads a parameter list, extracts the parameters known to the 'eprn' device, and configures the device appropriately. This includes parameters defined by base devices. If an error occurs in the processing of parameters, the function will return a negative value, otherwise zero. This function does *not* exhibit transactional behaviour as requested in gsparam.h, i.e. on error the parameter values in the device structure might have changed. However, all values will be individually valid. For most of the parameters an attempt to set them closes the device if it is open.******************************************************************************/int eprn_put_params(gx_device *dev, gs_param_list *plist){ bool colour_mode_given_and_valid = false; gs_param_name pname; gs_param_string string_value; eprn_Eprn *eprn = &((eprn_Device *)dev)->eprn; const char *epref = eprn->CUPS_messages? CUPS_ERRPREF: "", *wpref = eprn->CUPS_messages? CUPS_WARNPREF: ""; float mediasize[2]; int height = dev->height, last_error = 0, temp, rc, width = dev->width;#ifdef EPRN_TRACE if (gs_debug_c(EPRN_TRACE_CHAR)) { dlprintf( "! eprn_put_params() called with the following device parameters:\n"); eprn_dump_parameter_list(plist); }#endif /* EPRN_TRACE */ /* Remember initial page size */ for (temp = 0; temp < 2; temp++) mediasize[temp] = dev->MediaSize[temp]; /* CUPS message format. This should be the first parameter to be set which is a problem because it should happen even before the put_params methods of derived devices are called. However, note that in a CUPS filter "CUPSMessages" will usually be set from the command line while most remaining parameters will be set via setpagedevice. Hence this will come first anyway except for problems for which the print administrator is responsible, not the ordinary user. */ if ((rc = param_read_bool(plist, "CUPSMessages", &eprn->CUPS_messages)) == 0) { epref = eprn->CUPS_messages? CUPS_ERRPREF: ""; wpref = eprn->CUPS_messages? CUPS_WARNPREF: ""; } else if (rc < 0) last_error = rc; /* Read colour model into 'temp'. For those colonials across the pond we also accept the barbarized spelling variant. */#define colour_model(option) \ if ((rc = param_read_string(plist, (pname = option), &string_value)) == 0) { \ rc = eprn_get_int(&string_value, eprn_colour_model_list, &temp); \ if (rc != 0) { \ if (rc != gs_error_VMerror) { \ eprintf1("%s" ERRPREF "Unknown colour model: `", epref); \ errwrite(string_value.data, sizeof(char)*string_value.size); \ eprintf("'.\n"); \ } \ last_error = rc; \ param_signal_error(plist, pname, last_error); \ } \ else colour_mode_given_and_valid = true; \ } \ else if (rc < 0) last_error = rc; colour_model("ColorModel") colour_model("ColourModel") /* overrides if both are given */#undef colour_model if (colour_mode_given_and_valid) { if (eprn->colour_model != temp && dev->is_open) gs_closedevice(dev); /* The close_device method can fail, but what should I do then? */ eprn->colour_model = temp; /* Set the native colour space */ switch(eprn->colour_model) { case eprn_DeviceGray: dev->color_info.num_components = 1; break; case eprn_DeviceRGB: /*FALLTHROUGH*/ case eprn_DeviceCMY: /*FALLTHROUGH*/ case eprn_DeviceCMY_plus_K: dev->color_info.num_components = 3; break; case eprn_DeviceCMYK: dev->color_info.num_components = 4; break; default: assert(0); } dev->color_info.polarity = dci_std_polarity(dev->color_info.num_components); /* Adjust black levels */ if (eprn->colour_model == eprn_DeviceCMY || eprn->colour_model == eprn_DeviceRGB) { if (eprn->black_levels != 0) eprn->black_levels = 0; } else if (eprn->black_levels == 0) eprn->black_levels = 2; /* Adjust non-black levels if they are too small for colour */ if (dev->color_info.num_components > 1 && eprn->non_black_levels <= 0) eprn->non_black_levels = 2; /* Adjustments to pixel depth, 'max_gray', 'max_color' and dither levels will occur near the end of this routine */ } /* BlackLevels. Various depending values will be adjusted below. */ if ((rc = param_read_int(plist, (pname = "BlackLevels"), &temp)) == 0) { if (temp == 0 && (eprn->colour_model == eprn_DeviceRGB || eprn->colour_model == eprn_DeviceCMY) || 2 <= temp && temp <= 256 && eprn->colour_model != eprn_DeviceRGB && eprn->colour_model != eprn_DeviceCMY) { if (eprn->black_levels != temp && dev->is_open) gs_closedevice(dev); eprn->black_levels = temp; } else { eprintf2("%s" ERRPREF "The value for BlackLevels is outside the range permitted: %d.\n", epref, temp); last_error = gs_error_rangecheck; param_signal_error(plist, pname, last_error); } } else if (rc < 0) last_error = rc; /* CMYLevels */ if ((rc = param_read_int(plist, (pname = "CMYLevels"), &temp)) == 0) { if (temp == 0 && eprn->colour_model == eprn_DeviceGray || 2 <= temp && temp <= 256 && eprn->colour_model != eprn_DeviceGray) { if (eprn->non_black_levels != temp && dev->is_open) gs_closedevice(dev); eprn->non_black_levels = temp; } else { eprintf2("%s" ERRPREF "The value for CMYLevels is outside the range permitted: %d.\n", epref, temp); last_error = gs_error_rangecheck; param_signal_error(plist, pname, last_error); } } else if (rc < 0) last_error = rc; /* CUPS page accounting messages */ { bool temp; if ((rc = param_read_bool(plist, "CUPSAccounting", &temp)) == 0) { if (eprn->CUPS_accounting && !temp) eprintf(CUPS_WARNPREF WARNPREF "Attempt to set CUPSAccounting from true to false.\n"); else eprn->CUPS_accounting = temp; } else if (rc < 0) last_error = rc; } /* Intensity rendering */ if ((rc = param_read_string(plist, (pname = "IntensityRendering"), &string_value)) == 0) { rc = eprn_get_int(&string_value, intensity_rendering_list, &temp); if (rc == 0) { if (temp != eprn->intensity_rendering && dev->is_open) gs_closedevice(dev); eprn->intensity_rendering = temp; } else { eprintf1("%s" ERRPREF "Invalid method for IntensityRendering: `", epref); errwrite(string_value.data, sizeof(char)*string_value.size); eprintf("'.\n"); last_error = gs_error_rangecheck; param_signal_error(plist, pname, last_error); } } else if (rc < 0) last_error = rc; /* Leading edge */ if ((rc = param_read_null(plist, (pname = "LeadingEdge"))) == 0) { if (eprn->leading_edge_set && dev->is_open) gs_closedevice(dev); eprn->leading_edge_set = false; } else if (rc < 0 && rc != gs_error_typecheck) last_error = rc; else if ((rc = param_read_int(plist, (pname = "LeadingEdge"), &temp)) == 0) { if (0 <= temp && temp <= 3) { if ((!eprn->leading_edge_set || eprn->default_orientation != temp) && dev->is_open) gs_closedevice(dev); eprn->leading_edge_set = true; eprn->default_orientation = temp; } else { eprintf2( "%s" ERRPREF "LeadingEdge may only have values 0 to 3, not %d.\n", epref, temp); last_error = gs_error_rangecheck; param_signal_error(plist, pname, last_error); } } else if (rc < 0) last_error = rc; /* Media configuration file */ if ((rc = param_read_null(plist, (pname = "MediaConfigurationFile"))) == 0) { if (eprn->media_file != NULL && dev->is_open) gs_closedevice(dev); rc = eprn_set_media_data((eprn_Device *)dev, NULL, 0); } else if (rc < 0 && rc != gs_error_typecheck) last_error = rc; else if ((rc = param_read_string(plist, pname, &string_value)) == 0) { if (string_value.size > 0) { if ((eprn->media_file == NULL || strncmp(eprn->media_file, (const char *)string_value.data, string_value.size) != 0 || eprn->media_file[string_value.size] != '\0') && dev->is_open) gs_closedevice(dev); rc = eprn_set_media_data((eprn_Device *)dev, (const char *)string_value.data, string_value.size); } else { if (eprn->media_file != NULL && dev->is_open) gs_closedevice(dev); rc = eprn_set_media_data((eprn_Device *)dev, NULL, 0); } if (rc != 0) { last_error = rc; param_signal_error(plist, pname, last_error); } } else if (rc < 0) last_error = rc;#ifndef EPRN_GS_HAS_MEDIAPOSITION if ((rc = param_read_null(plist, (pname = "MediaPosition"))) == 0) eprn->media_position_set = false; else if (rc < 0 && (rc = param_read_int(plist, pname, &eprn->media_position)) == 0) { /* Current (up to at least gs 6.50) ghostscript versions do not accept negative MediaPosition values. */ if (eprn->media_position < 0) eprintf3("%s" WARNPREF "Ghostscript does not accept negative values (%d) for the\n" "%s `MediaPosition' parameter.\n", wpref, eprn->media_position, wpref); /* The error message is left for ghostscript to generate during input media selection, should such an entry be a match. */ eprn->media_position_set = true; } else if (rc < 0) last_error = rc;#endif /* EPRN_GS_HAS_MEDIAPOSITION */#ifndef EPRN_NO_PAGECOUNTFILE /* Page count file */ if ((rc = param_read_null(plist, (pname = "PageCountFile"))) == 0) { if (eprn->pagecount_file != NULL) { gs_free(gs_lib_ctx_get_non_gc_memory_t(), eprn->pagecount_file, strlen(eprn->pagecount_file) + 1, sizeof(char), "eprn_put_params"); eprn->pagecount_file = NULL; } } else if (rc < 0 && rc != gs_error_typecheck) last_error = rc; else if ((rc = param_read_string(plist, pname, &string_value)) == 0) { /* Free old storage */ if (eprn->pagecount_file != NULL) { gs_free(gs_lib_ctx_get_non_gc_memory_t(), eprn->pagecount_file, strlen(eprn->pagecount_file) + 1, sizeof(char), "eprn_put_params"); eprn->pagecount_file = NULL; } /* Store file name unless it is the empty string */ if (string_value.size > 0) { eprn->pagecount_file = (char *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), string_value.size + 1, sizeof(char), "eprn_put_params"); if (eprn->pagecount_file == NULL) { eprintf1( "%s" ERRPREF "Memory allocation failure from gs_malloc() in eprn_put_params().\n", epref); last_error = gs_error_VMerror; param_signal_error(plist, pname, last_error); } else { strncpy(eprn->pagecount_file, (const char *)string_value.data, string_value.size); eprn->pagecount_file[string_value.size] = '\0'; } } }#endif /* EPRN_NO_PAGECOUNTFILE */ /* RGBLevels */ if ((rc = param_read_int(plist, (pname = "RGBLevels"), &temp)) == 0) { if (temp == 0 || 2 <= temp && temp <= 256) { if (eprn->non_black_levels != temp && dev->is_open) gs_closedevice(dev); eprn->non_black_levels = temp; } else { eprintf2("%s" ERRPREF "The value for RGBLevels is outside the range permitted: %d.\n", epref, temp); last_error = gs_error_rangecheck; param_signal_error(plist, pname, last_error); } } else if (rc < 0) last_error = rc; /* Determine various derived colour parameters */ set_derived_colour_data((eprn_Device *)dev); /* Catch a specification of BitsPerPixel --- otherwise a wrong value gives just a rangecheck error from gs without any readily understandable information (see gx_default_put_params()). This confused one hpdj user so much that he wrote in a newsgroup that gs was dumping core in this case :-). */ if ((rc = param_read_int(plist, (pname = "BitsPerPixel"), &temp)) == 0) { if (temp != dev->color_info.depth) { eprintf3("%s" ERRPREF "Attempt to set `BitsPerPixel' to a value (%d)\n" "%s other than the one selected by the driver.\n", epref, temp, epref); last_error = gs_error_rangecheck; param_signal_error(plist, pname, last_error); } } else if (rc < 0) last_error = rc; /* Check whether ".HWMargins" is specified and, if it is, refrain from overwriting it. */ { gs_param_typed_value temp; if (param_read_typed(plist, ".HWMargins", &temp) == 0) { /* ".HWMargins" is specified */#ifdef EPRN_TRACE if_debug1(EPRN_TRACE_CHAR, "! .HWMargins is specified: type is %d.\n", (int)temp.type);#endif eprn->keep_margins = true; } } /* Process parameters defined by base classes (should occur after treating parameters defined for the derived class, see gsparam.h) */ if ((rc = gdev_prn_put_params(dev, plist)) < 0 || rc > 0 && last_error >= 0) last_error = rc; if (last_error < 0) return_error(last_error); /* If the page size was modified, close the device */ if (dev->is_open && (dev->width != width || dev->height != height || mediasize[0] != dev->MediaSize[0] || mediasize[1] != dev->MediaSize[1])) { gs_closedevice(dev);#ifdef EPRN_TRACE if_debug0(EPRN_TRACE_CHAR, "! Closing device because of page size modification.\n");#endif } return last_error;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -