1/* 2 * "$Id: printer_margins.c,v 1.21 2007/05/06 19:38:10 rlk Exp $" 3 * 4 * Dump the per-printer margins for the OpenPrinting database 5 * 6 * Copyright 2000, 2003 Robert Krawitz (rlk@alum.mit.edu) and 7 * Till Kamppeter (till.kamppeter@gmail.com) 8 * 9 * This program is free software; you can redistribute it and/or modify it 10 * under the terms of the GNU General Public License as published by the Free 11 * Software Foundation; either version 2 of the License, or (at your option) 12 * any later version. 13 * 14 * This program is distributed in the hope that it will be useful, but 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17 * for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 */ 23 24#ifdef HAVE_CONFIG_H 25#include <config.h> 26#endif 27#include <stdio.h> 28#include <string.h> 29#include <gutenprint/gutenprint.h> 30 31int 32main(int argc, char **argv) { 33 int i, k; 34 int use_all_page_sizes = 1; 35 if (argc > 1 && !strcmp(argv[1], "-s")) 36 use_all_page_sizes = 0; 37 38 stp_init(); 39 for (i = 0; i < stp_printer_model_count(); i++) { 40 const stp_printer_t *p = stp_get_printer_by_index(i); 41 const char *driver = stp_printer_get_driver(p); 42 const char *family = stp_printer_get_family(p); 43 stp_vars_t *pv = 44 stp_vars_create_copy(stp_printer_get_defaults(p)); 45 stp_parameter_t desc; 46 int num_opts; 47 int printer_is_color = 0; 48 const stp_param_string_t *opt; 49 int width, height, bottom, left, top, right; 50 if (strcmp(family, "ps") == 0 || strcmp(family, "raw") == 0) 51 continue; 52 stp_describe_parameter(pv, "PrintingMode", &desc); 53 if (stp_string_list_is_present(desc.bounds.str, "Color")) 54 printer_is_color = 1; 55 stp_parameter_description_destroy(&desc); 56 if (printer_is_color) 57 stp_set_string_parameter(pv, "PrintingMode", "Color"); 58 else 59 stp_set_string_parameter(pv, "PrintingMode", "BW"); 60 stp_set_string_parameter(pv, "ChannelBitDepth", "8"); 61 printf("# Printer model %s, long name `%s'\n", driver, 62 stp_printer_get_long_name(p)); 63 stp_describe_parameter(pv, "PageSize", &desc); 64 printf("$defaults{'%s'}{'PageSize'} = '%s';\n", 65 driver, desc.deflt.str); 66 num_opts = stp_string_list_count(desc.bounds.str); 67 68 for (k = 0; k < num_opts; k++) { 69 const stp_papersize_t *papersize; 70 opt = stp_string_list_param(desc.bounds.str, k); 71 papersize = stp_get_papersize_by_name(opt->name); 72 73 if (!papersize) { 74 printf("Unable to lookup size %s!\n", opt->name); 75 continue; 76 } 77 if (!use_all_page_sizes && num_opts >= 10 && 78 (papersize->paper_unit == PAPERSIZE_ENGLISH_EXTENDED || 79 papersize->paper_unit == PAPERSIZE_METRIC_EXTENDED)) 80 continue; 81 82 width = papersize->width; 83 height = papersize->height; 84 85 stp_set_string_parameter(pv, "PageSize", opt->name); 86 87 stp_get_media_size(pv, &width, &height); 88 stp_get_maximum_imageable_area(pv, &left, &right, &bottom, &top); 89 90 if (left < 0) 91 left = 0; 92 if (right > width) 93 right = width; 94 if (bottom > height) 95 bottom = height; 96 if (top < 0) 97 top = 0; 98 99 bottom = height - bottom; 100 top = height - top; 101 102 if (strcmp(opt->name, "Custom") == 0) { 103 /* Use relative values for the custom size */ 104 right = width - right; 105 top = height - top; 106 width = 0; 107 height = 0; 108 } 109 110 printf("$stpdata{'%s'}{'PageSize'}{'%s'} = '%s';", 111 driver, opt->name, opt->text); 112 printf("$imageableareas{'%s'}{'%s'} = {", 113 driver, opt->name); 114 printf(" 'left' => '%d',", left); 115 printf(" 'right' => '%d',", right); 116 printf(" 'top' => '%d',", top); 117 printf(" 'bottom' => '%d',", bottom); 118 printf(" 'width' => '%d',", width); 119 printf(" 'height' => '%d'", height); 120 printf("};\n"); 121 } 122 stp_parameter_description_destroy(&desc); 123 stp_vars_destroy(pv); 124 } 125 return 0; 126} 127