diff options
Diffstat (limited to 'src/main/print-ps.c')
-rw-r--r-- | src/main/print-ps.c | 104 |
1 files changed, 86 insertions, 18 deletions
diff --git a/src/main/print-ps.c b/src/main/print-ps.c index 5a8ab9c..751424d 100644 --- a/src/main/print-ps.c +++ b/src/main/print-ps.c @@ -16,8 +16,7 @@ * for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * along with this program. If not, see <https://www.gnu.org/licenses/>. */ /* @@ -94,7 +93,8 @@ static const int the_parameter_count = sizeof(the_parameters) / sizeof(const stp_parameter_t); static int -ps_option_to_param(stp_parameter_t *param, stp_mxml_node_t *option) +ps_option_to_param(const stp_vars_t *v, stp_parameter_t *param, + stp_mxml_node_t *option) { const char *group_text = stp_mxmlElementGetAttr(option, "grouptext"); @@ -120,7 +120,7 @@ ps_option_to_param(stp_parameter_t *param, stp_mxml_node_t *option) param->is_active = 1; param->verify_this_parameter = 1; param->name = stp_mxmlElementGetAttr(option, "stpname"); - stp_deprintf(STP_DBG_PS, + stp_dprintf(STP_DBG_PS, v, "Gutenprint parameter %s type %d mandatory %d class %d level %d channel %d default %s %f", param->name, param->p_type, param->is_mandatory, param->p_class, param->p_level, param->channel, @@ -131,7 +131,7 @@ ps_option_to_param(stp_parameter_t *param, stp_mxml_node_t *option) param->deflt.dbl = stp_default_value; param->bounds.dbl.upper = upper_bound; param->bounds.dbl.lower = lower_bound; - stp_deprintf(STP_DBG_PS, " %.3f %.3f %.3f\n", + stp_dprintf(STP_DBG_PS, v, " %.3f %.3f %.3f\n", param->deflt.dbl, param->bounds.dbl.upper, param->bounds.dbl.lower); break; @@ -139,7 +139,7 @@ ps_option_to_param(stp_parameter_t *param, stp_mxml_node_t *option) param->deflt.dimension = atoi(default_value); param->bounds.dimension.upper = (stp_dimension_t) upper_bound; param->bounds.dimension.lower = (stp_dimension_t) lower_bound; - stp_deprintf(STP_DBG_PS, " %f %f %f\n", + stp_dprintf(STP_DBG_PS, v, " %f %f %f\n", param->deflt.dimension, param->bounds.dimension.upper, param->bounds.dimension.lower); break; @@ -147,16 +147,16 @@ ps_option_to_param(stp_parameter_t *param, stp_mxml_node_t *option) param->deflt.integer = atoi(default_value); param->bounds.integer.upper = (int) upper_bound; param->bounds.integer.lower = (int) lower_bound; - stp_deprintf(STP_DBG_PS, " %d %d %d\n", + stp_dprintf(STP_DBG_PS, v, " %d %d %d\n", param->deflt.integer, param->bounds.integer.upper, param->bounds.integer.lower); break; case STP_PARAMETER_TYPE_BOOLEAN: param->deflt.boolean = strcasecmp(default_value, "true") == 0 ? 1 : 0; - stp_deprintf(STP_DBG_PS, " %d\n", param->deflt.boolean); + stp_dprintf(STP_DBG_PS, v, " %d\n", param->deflt.boolean); break; default: - stp_deprintf(STP_DBG_PS, "\n"); + stp_dprintf(STP_DBG_PS, v, "\n"); break; } } @@ -263,7 +263,7 @@ ps_list_parameters(const stp_vars_t *v) option = stpi_xmlppd_find_option_index(m_ppd, i); if (option) { - ps_option_to_param(param, option); + ps_option_to_param(v, param, option); if (param->p_type != STP_PARAMETER_TYPE_INVALID && strcmp(param->name, "PageRegion") != 0 && strcmp(param->name, "PageSize") != 0) @@ -314,8 +314,8 @@ ps_parameters_internal(const stp_vars_t *v, const char *name, nickname = stp_mxmlElementGetAttr(m_ppd, "nickname"); else nickname = _("None; please provide a PPD file"); - stp_string_list_add_string(description->bounds.str, - nickname, nickname); + stp_string_list_add_string_unsafe(description->bounds.str, + nickname, nickname); description->deflt.str = nickname; description->is_active = 1; return; @@ -374,7 +374,7 @@ ps_parameters_internal(const stp_vars_t *v, const char *name, } } - ps_option_to_param(description, option); + ps_option_to_param(v, description, option); if (description->p_type != STP_PARAMETER_TYPE_STRING_LIST) return; num_choices = atoi(stp_mxmlElementGetAttr(option, "num_choices")); @@ -470,6 +470,74 @@ ps_media_size_internal(const stp_vars_t *v, /* I */ return; } +static const stp_papersize_t * +ps_describe_papersize(const stp_vars_t *v, const char *name) +{ + int status = check_ppd_file(v); + if (status) + { + stp_mxml_node_t *paper = stpi_xmlppd_find_page_size(m_ppd, name); + if (paper) + { + const char *papersize_list_name = m_ppd_file ? m_ppd_file : "NOPPD"; + stp_papersize_list_t *ourlist = + stpi_find_papersize_list_named(papersize_list_name); + const stp_papersize_t *papersize; + const stp_papersize_t *standard_papersize = + stpi_get_listed_papersize(name, "standard"); + + if (! ourlist) + ourlist = stpi_new_papersize_list(papersize_list_name); + + papersize = stpi_get_papersize_by_name(ourlist, name); + if (! papersize) + { + stp_papersize_t *npapersize = stp_malloc(sizeof(stp_papersize_t)); + npapersize->name = stp_strdup(name); + npapersize->text = stp_strdup(name); + npapersize->comment = NULL; + /* + * Note that we used the width and height from the PPD file, + * not from the standard definition. This is so that if the + * PPD file is for another driver that uses slightly different + * dimensions than we do that our description matches that of + * driver in use. + */ + npapersize->width = atof(stp_mxmlElementGetAttr(paper, "width")); + npapersize->height = atof(stp_mxmlElementGetAttr(paper, "height")); + /* + * Only use auxiliary information from our list if our paper size + * really is substantially the same as what the PPD file says! + */ + if (standard_papersize && + fabs(npapersize->width - standard_papersize->width) < 1 && + fabs(npapersize->height - standard_papersize->height) < 1) + { + npapersize->paper_unit = standard_papersize->paper_unit; + npapersize->paper_size_type = standard_papersize->paper_size_type; + npapersize->top = standard_papersize->top; + npapersize->left = standard_papersize->left; + npapersize->bottom = standard_papersize->bottom; + npapersize->right = standard_papersize->right; + } + else + { + npapersize->top = 0; + npapersize->left = 0; + npapersize->bottom = 0; + npapersize->right = 0; + npapersize->paper_unit = PAPERSIZE_ENGLISH_STANDARD; + npapersize->paper_size_type = PAPERSIZE_TYPE_STANDARD; + } + if (stpi_papersize_create(ourlist, npapersize)) + return npapersize; + } + return papersize; + } + } + return NULL; +} + static void ps_media_size(const stp_vars_t *v, stp_dimension_t *width, stp_dimension_t *height) { @@ -954,7 +1022,7 @@ ps_print_internal(stp_vars_t *v, stp_image_t *image) * Output a standard PostScript header with DSC comments... */ - curtime = time(NULL); + curtime = stpi_time(NULL); top = paper_height - top; @@ -1175,7 +1243,6 @@ ps_print(const stp_vars_t *v, stp_image_t *image) char *locale; #endif stp_vars_t *nv = stp_vars_create_copy(v); - stp_prune_inactive_options(nv); if (!stp_verify(nv)) { stp_eprintf(nv, "Print options not verified; cannot print.\n"); @@ -1341,7 +1408,8 @@ static const stp_printfuncs_t print_ps_printfuncs = stp_verify_printer_params, NULL, NULL, - ps_external_options + ps_external_options, + ps_describe_papersize }; @@ -1355,14 +1423,14 @@ static stp_family_t print_ps_module_data = static int print_ps_module_init(void) { - return stp_family_register(print_ps_module_data.printer_list); + return stpi_family_register(print_ps_module_data.printer_list); } static int print_ps_module_exit(void) { - return stp_family_unregister(print_ps_module_data.printer_list); + return stpi_family_unregister(print_ps_module_data.printer_list); } |