1/* 2 * "$Id: escp2-resolutions.c,v 1.52 2010/08/04 00:33:56 rlk Exp $" 3 * 4 * Print plug-in EPSON ESC/P2 driver for the GIMP. 5 * 6 * Copyright 1997-2000 Michael Sweet (mike@easysw.com) and 7 * Robert Krawitz (rlk@alum.mit.edu) 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 <gutenprint/gutenprint.h> 28#include "gutenprint-internal.h" 29#include <gutenprint/gutenprint-intl-internal.h> 30#include "print-escp2.h" 31 32 33int 34stp_escp2_load_printer_weaves_from_xml(const stp_vars_t *v, 35 stp_mxml_node_t *node) 36{ 37 stpi_escp2_printer_t *printdef = stp_escp2_get_printer(v); 38 printer_weave_list_t *xpw = stp_malloc(sizeof(printer_weave_list_t)); 39 int count = 0; 40 stp_mxml_node_t *child = node->child; 41 while (child) 42 { 43 if (child->type == STP_MXML_ELEMENT && 44 !strcmp(child->value.element.name, "weave")) 45 count++; 46 child = child->next; 47 } 48 printdef->printer_weaves = xpw; 49 if (stp_mxmlElementGetAttr(node, "name")) 50 xpw->name = stp_strdup(stp_mxmlElementGetAttr(node, "name")); 51 xpw->n_printer_weaves = count; 52 xpw->printer_weaves = stp_zalloc(sizeof(printer_weave_t) * count); 53 child = node->child; 54 count = 0; 55 while (child) 56 { 57 if (child->type == STP_MXML_ELEMENT && 58 !strcmp(child->value.element.name, "weave")) 59 { 60 const char *wname = stp_mxmlElementGetAttr(child, "name"); 61 const char *wtext = stp_mxmlElementGetAttr(child, "text"); 62 const char *cmd = stp_mxmlElementGetAttr(child, "command"); 63 if (wname) 64 xpw->printer_weaves[count].name = stp_strdup(wname); 65 if (wtext) 66 xpw->printer_weaves[count].text = stp_strdup(wtext); 67 if (cmd) 68 xpw->printer_weaves[count].command = stp_xmlstrtoraw(cmd); 69 count++; 70 } 71 child = child->next; 72 } 73 return 1; 74} 75 76int 77stp_escp2_load_printer_weaves(const stp_vars_t *v, const char *name) 78{ 79 stp_list_t *dirlist = stpi_data_path(); 80 stp_list_item_t *item; 81 int found = 0; 82 item = stp_list_get_start(dirlist); 83 while (item) 84 { 85 const char *dn = (const char *) stp_list_item_get_data(item); 86 char *ffn = stpi_path_merge(dn, name); 87 stp_mxml_node_t *weaves = 88 stp_mxmlLoadFromFile(NULL, ffn, STP_MXML_NO_CALLBACK); 89 stp_free(ffn); 90 if (weaves) 91 { 92 stp_mxml_node_t *node = stp_mxmlFindElement(weaves, weaves, 93 "escp2:PrinterWeaves", NULL, 94 NULL, STP_MXML_DESCEND); 95 if (node) 96 stp_escp2_load_printer_weaves_from_xml(v, node); 97 stp_mxmlDelete(weaves); 98 found = 1; 99 break; 100 } 101 item = stp_list_item_next(item); 102 } 103 stp_list_destroy(dirlist); 104 STPI_ASSERT(found, v); 105 return found; 106} 107 108int 109stp_escp2_load_resolutions_from_xml(const stp_vars_t *v, stp_mxml_node_t *node) 110{ 111 stpi_escp2_printer_t *printdef = stp_escp2_get_printer(v); 112 resolution_list_t *xrs = stp_malloc(sizeof(resolution_list_t)); 113 int count = 0; 114 stp_mxml_node_t *child = node->child; 115 while (child) 116 { 117 if (child->type == STP_MXML_ELEMENT && 118 !strcmp(child->value.element.name, "resolution")) 119 count++; 120 child = child->next; 121 } 122 printdef->resolutions = xrs; 123 if (stp_mxmlElementGetAttr(node, "name")) 124 xrs->name = stp_strdup(stp_mxmlElementGetAttr(node, "name")); 125 xrs->n_resolutions = count; 126 xrs->resolutions = stp_zalloc(sizeof(res_t) * count); 127 child = node->child; 128 count = 0; 129 while (child) 130 { 131 if (child->type == STP_MXML_ELEMENT && 132 !strcmp(child->value.element.name, "resolution")) 133 { 134 res_t *res = &(xrs->resolutions[count]); 135 stp_mxml_node_t *cchild = child->child; 136 const char *wname = stp_mxmlElementGetAttr(child, "name"); 137 const char *wtext = stp_mxmlElementGetAttr(child, "text"); 138 res->v = stp_vars_create(); 139 res->vertical_passes = 1; 140 if (wname) 141 res->name = stp_strdup(wname); 142 if (wtext) 143 res->text = stp_strdup(wtext); 144 stp_vars_fill_from_xmltree_ref(cchild, node, res->v); 145 while (cchild) 146 { 147 if (cchild->type == STP_MXML_ELEMENT) 148 { 149 const char *elt = cchild->value.element.name; 150 if (cchild->type == STP_MXML_ELEMENT && 151 (!strcmp(elt, "physicalResolution") || 152 !strcmp(elt, "printedResolution"))) 153 { 154 long data[2] = { 0, 0 }; 155 stp_mxml_node_t *ccchild = cchild->child; 156 data[0] = stp_xmlstrtol(ccchild->value.text.string); 157 ccchild = ccchild->next; 158 data[1] = stp_xmlstrtol(ccchild->value.text.string); 159 if (!strcmp(elt, "physicalResolution")) 160 { 161 res->hres = data[0]; 162 res->vres = data[1]; 163 } 164 else if (!strcmp(elt, "printedResolution")) 165 { 166 res->printed_hres = data[0]; 167 res->printed_vres = data[1]; 168 } 169 } 170 else if (!strcmp(elt, "verticalPasses") && 171 cchild->child && 172 cchild->child->type == STP_MXML_TEXT) 173 res->vertical_passes = stp_xmlstrtol(cchild->child->value.text.string); 174 else if (!strcmp(elt, "printerWeave") && 175 stp_mxmlElementGetAttr(cchild, "command")) 176 res->command = stp_xmlstrtoraw(stp_mxmlElementGetAttr(cchild, "command")); 177 } 178 cchild = cchild->next; 179 } 180 if (!res->printed_hres) 181 res->printed_hres = res->hres; 182 if (!res->printed_vres) 183 res->printed_vres = res->vres; 184 count++; 185 } 186 child = child->next; 187 } 188 return 1; 189} 190 191int 192stp_escp2_load_resolutions(const stp_vars_t *v, const char *name) 193{ 194 stp_list_t *dirlist = stpi_data_path(); 195 stp_list_item_t *item; 196 int found = 0; 197 item = stp_list_get_start(dirlist); 198 while (item) 199 { 200 const char *dn = (const char *) stp_list_item_get_data(item); 201 char *ffn = stpi_path_merge(dn, name); 202 stp_mxml_node_t *resolutions = 203 stp_mxmlLoadFromFile(NULL, ffn, STP_MXML_NO_CALLBACK); 204 stp_free(ffn); 205 if (resolutions) 206 { 207 stp_mxml_node_t *node = stp_mxmlFindElement(resolutions, resolutions, 208 "escp2:resolutions", NULL, 209 NULL, STP_MXML_DESCEND); 210 if (node) 211 stp_escp2_load_resolutions_from_xml(v, node); 212 stp_mxmlDelete(resolutions); 213 found = 1; 214 break; 215 } 216 item = stp_list_item_next(item); 217 } 218 stp_list_destroy(dirlist); 219 STPI_ASSERT(found, v); 220 return found; 221} 222 223int 224stp_escp2_load_quality_presets_from_xml(const stp_vars_t *v, stp_mxml_node_t *node) 225{ 226 stpi_escp2_printer_t *printdef = stp_escp2_get_printer(v); 227 quality_list_t *qpw = stp_malloc(sizeof(quality_list_t)); 228 int count = 0; 229 stp_mxml_node_t *child = node->child; 230 while (child) 231 { 232 if (child->type == STP_MXML_ELEMENT && 233 !strcmp(child->value.element.name, "quality")) 234 count++; 235 child = child->next; 236 } 237 printdef->quality_list = qpw; 238 if (stp_mxmlElementGetAttr(node, "name")) 239 qpw->name = stp_strdup(stp_mxmlElementGetAttr(node, "name")); 240 qpw->n_quals = count; 241 qpw->qualities = stp_zalloc(sizeof(quality_t) * count); 242 child = node->child; 243 count = 0; 244 while (child) 245 { 246 if (child->type == STP_MXML_ELEMENT && 247 !strcmp(child->value.element.name, "quality")) 248 { 249 stp_mxml_node_t *cchild = child->child; 250 const char *wname = stp_mxmlElementGetAttr(child, "name"); 251 const char *wtext = stp_mxmlElementGetAttr(child, "text"); 252 if (wname) 253 qpw->qualities[count].name = stp_strdup(wname); 254 if (wtext) 255 qpw->qualities[count].text = stp_strdup(wtext); 256 while (cchild) 257 { 258 if (cchild->type == STP_MXML_ELEMENT && 259 (!strcmp(cchild->value.element.name, "minimumResolution") || 260 !strcmp(cchild->value.element.name, "maximumResolution") || 261 !strcmp(cchild->value.element.name, "desiredResolution"))) 262 { 263 long data[2] = { 0, 0 }; 264 stp_mxml_node_t *ccchild = cchild->child; 265 data[0] = stp_xmlstrtol(ccchild->value.text.string); 266 ccchild = ccchild->next; 267 data[1] = stp_xmlstrtol(ccchild->value.text.string); 268 if (!strcmp(cchild->value.element.name, "minimumResolution")) 269 { 270 qpw->qualities[count].min_hres = data[0]; 271 qpw->qualities[count].min_vres = data[1]; 272 } 273 else if (!strcmp(cchild->value.element.name, "maximumResolution")) 274 { 275 qpw->qualities[count].max_hres = data[0]; 276 qpw->qualities[count].max_vres = data[1]; 277 } 278 else if (!strcmp(cchild->value.element.name, "desiredResolution")) 279 { 280 qpw->qualities[count].desired_hres = data[0]; 281 qpw->qualities[count].desired_vres = data[1]; 282 } 283 } 284 cchild = cchild->next; 285 } 286 count++; 287 } 288 child = child->next; 289 } 290 return 1; 291} 292 293int 294stp_escp2_load_quality_presets(const stp_vars_t *v, const char *name) 295{ 296 stp_list_t *dirlist = stpi_data_path(); 297 stp_list_item_t *item; 298 int found = 0; 299 item = stp_list_get_start(dirlist); 300 while (item) 301 { 302 const char *dn = (const char *) stp_list_item_get_data(item); 303 char *ffn = stpi_path_merge(dn, name); 304 stp_mxml_node_t *qualities = 305 stp_mxmlLoadFromFile(NULL, ffn, STP_MXML_NO_CALLBACK); 306 stp_free(ffn); 307 if (qualities) 308 { 309 stp_mxml_node_t *node = stp_mxmlFindElement(qualities, qualities, 310 "escp2:QualityPresets", NULL, 311 NULL, STP_MXML_DESCEND); 312 if (node) 313 stp_escp2_load_quality_presets_from_xml(v, node); 314 stp_mxmlDelete(qualities); 315 found = 1; 316 break; 317 } 318 item = stp_list_item_next(item); 319 } 320 stp_list_destroy(dirlist); 321 STPI_ASSERT(found, v); 322 return found; 323} 324