Debian Codegraph @

src/main/escp2-resolutions.c

raw symbols SCIP
1 /*
2 *
3 * Print plug-in EPSON ESC/P2 driver for the GIMP.
4 *
5 * Copyright 1997-2000 Michael Sweet ([email protected]) and
6 * Robert Krawitz ([email protected])
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 #include <gutenprint/gutenprint.h>
26 #include "gutenprint-internal.h"
27 #include <gutenprint/gutenprint-intl-internal.h>
28 #include "print-escp2.h"
29
30
31 static printer_weave_list_t *
32 stpi_escp2_load_printer_weaves_from_xml(stp_mxml_node_t *node)
33 {
34 printer_weave_list_t *xpw = stp_malloc(sizeof(printer_weave_list_t));
35 int count = 0;
36 stp_mxml_node_t *child = node->child;
37 while (child)
38 {
39 if (child->type == STP_MXML_ELEMENT &&
40 !strcmp(child->value.element.name, "weave"))
41 count++;
42 child = child->next;
43 }
44 if (stp_mxmlElementGetAttr(node, "name"))
45 xpw->name = stp_strdup(stp_mxmlElementGetAttr(node, "name"));
46 xpw->n_printer_weaves = count;
47 xpw->printer_weaves = stp_zalloc(sizeof(printer_weave_t) * count);
48 child = node->child;
49 count = 0;
50 while (child)
51 {
52 if (child->type == STP_MXML_ELEMENT &&
53 !strcmp(child->value.element.name, "weave"))
54 {
55 const char *wname = stp_mxmlElementGetAttr(child, "name");
56 const char *wtext = stp_mxmlElementGetAttr(child, "text");
57 const char *cmd = stp_mxmlElementGetAttr(child, "command");
58 if (wname)
59 xpw->printer_weaves[count].name = stp_strdup(wname);
60 if (wtext)
61 xpw->printer_weaves[count].text = stp_strdup(wtext);
62 if (cmd)
63 xpw->printer_weaves[count].command = stp_xmlstrtoraw(cmd);
64 count++;
65 }
66 child = child->next;
67 }
68 return xpw;
69 }
70
71 int
72 stpi_escp2_load_printer_weaves(const stp_vars_t *v, const char *name)
73 {
74 static const char *weave_cache = "escp2PrinterWeaves";
75 stpi_escp2_printer_t *printdef = stpi_escp2_get_printer(v);
76 printer_weave_list_t *pw =
77 (printer_weave_list_t *) stp_refcache_find_item(weave_cache, name);
78 if(! pw)
79 {
80 stp_mxml_node_t *node =
81 stp_xml_parse_file_from_path_uncached_safe(name, "escp2PrinterWeaves", NULL);
82 stp_dprintf(STP_DBG_ESCP2_XML, v,
83 ">>>Loading printer weave data from %s (%p)...", name, (void *) node);
84 stp_xml_init();
85 pw = stpi_escp2_load_printer_weaves_from_xml(node);
86 stp_xml_exit();
87 stp_refcache_add_item(weave_cache, name, pw);
88 stp_xml_free_parsed_file(node);
89 }
90 printdef->printer_weaves = pw;
91 return 1;
92 }
93
94 static resolution_list_t *
95 stpi_escp2_load_resolutions_from_xml(stp_mxml_node_t *node)
96 {
97 resolution_list_t *xrs = stp_malloc(sizeof(resolution_list_t));
98 int count = 0;
99 stp_mxml_node_t *child = node->child;
100 while (child)
101 {
102 if (child->type == STP_MXML_ELEMENT &&
103 !strcmp(child->value.element.name, "resolution"))
104 {
105 count++;
106 }
107 child = child->next;
108 }
109 if (stp_mxmlElementGetAttr(node, "name"))
110 xrs->name = stp_strdup(stp_mxmlElementGetAttr(node, "name"));
111 xrs->n_resolutions = count;
112 xrs->resolutions = stp_zalloc(sizeof(res_t) * count);
113 child = node->child;
114 count = 0;
115 while (child)
116 {
117 if (child->type == STP_MXML_ELEMENT &&
118 !strcmp(child->value.element.name, "resolution"))
119 {
120 res_t *res = &(xrs->resolutions[count]);
121 stp_mxml_node_t *cchild = child->child;
122 const char *wname = stp_mxmlElementGetAttr(child, "name");
123 const char *wtext = stp_mxmlElementGetAttr(child, "text");
124 res->v = stp_vars_create();
125 res->vertical_passes = 1;
126 if (wname)
127 res->name = stp_strdup(wname);
128 if (wtext)
129 res->text = stp_strdup(wtext);
130 stp_vars_fill_from_xmltree_ref(cchild, node, res->v);
131 while (cchild)
132 {
133 if (cchild->type == STP_MXML_ELEMENT)
134 {
135 const char *elt = cchild->value.element.name;
136 if (cchild->type == STP_MXML_ELEMENT &&
137 (!strcmp(elt, "physicalResolution") ||
138 !strcmp(elt, "printedResolution")))
139 {
140 long data[2] = { 0, 0 };
141 stp_mxml_node_t *ccchild = cchild->child;
142 data[0] = stp_xmlstrtol(ccchild->value.text.string);
143 ccchild = ccchild->next;
144 data[1] = stp_xmlstrtol(ccchild->value.text.string);
145 if (!strcmp(elt, "physicalResolution"))
146 {
147 res->hres = data[0];
148 res->vres = data[1];
149 }
150 else if (!strcmp(elt, "printedResolution"))
151 {
152 res->printed_hres = data[0];
153 res->printed_vres = data[1];
154 }
155 }
156 else if (!strcmp(elt, "verticalPasses") &&
157 cchild->child &&
158 cchild->child->type == STP_MXML_TEXT)
159 res->vertical_passes = stp_xmlstrtol(cchild->child->value.text.string);
160 else if (!strcmp(elt, "printerWeave") &&
161 stp_mxmlElementGetAttr(cchild, "command"))
162 res->command = stp_xmlstrtoraw(stp_mxmlElementGetAttr(cchild, "command"));
163 }
164 cchild = cchild->next;
165 }
166 if (!res->printed_hres)
167 res->printed_hres = res->hres;
168 if (!res->printed_vres)
169 res->printed_vres = res->vres;
170 count++;
171 }
172 child = child->next;
173 }
174 return xrs;
175 }
176
177 int
178 stpi_escp2_load_resolutions(const stp_vars_t *v, const char *name,
179 stp_mxml_node_t *node)
180 {
181 stp_dprintf(STP_DBG_ESCP2_XML, v,
182 ">>>Loading resolutions from %s (%p)...", name, (void *) node);
183 static const char *res_cache = "escp2Resolutions";
184 stpi_escp2_printer_t *printdef = stpi_escp2_get_printer(v);
185 resolution_list_t *pr =
186 (resolution_list_t *) stp_refcache_find_item(res_cache, name);
187 int found = 0;
188 if (pr)
189 stp_dprintf(STP_DBG_ESCP2_XML, v, "cached!");
190 if(! pr)
191 {
192 stp_mxml_node_t *parent = NULL;
193 if (! node)
194 {
195 parent = stp_xml_parse_file_from_path_uncached_safe(name, "escp2Resolutions", NULL);
196 node = parent->child;
197 }
198 while (node)
199 {
200 if (node->type == STP_MXML_ELEMENT &&
201 !strcmp(node->value.element.name, "resolutions"))
202 {
203 stp_xml_init();
204 pr = stpi_escp2_load_resolutions_from_xml(node);
205 stp_refcache_add_item(res_cache, name, pr);
206 stp_xml_exit();
207 found = 1;
208 break;
209 }
210 node = node->next;
211 }
212 stp_xml_free_parsed_file(parent);
213 }
214 printdef->resolutions = pr;
215 stp_dprintf(STP_DBG_ESCP2_XML, v, "(%p) done!", (void *) pr);
216 return found;
217 }
218
219 static quality_list_t *
220 stpi_escp2_load_quality_presets_from_xml(stp_mxml_node_t *node)
221 {
222 quality_list_t *qpw = stp_malloc(sizeof(quality_list_t));
223 int count = 0;
224 stp_mxml_node_t *child = node->child;
225 while (child)
226 {
227 if (child->type == STP_MXML_ELEMENT &&
228 !strcmp(child->value.element.name, "quality"))
229 count++;
230 child = child->next;
231 }
232 if (stp_mxmlElementGetAttr(node, "name"))
233 qpw->name = stp_strdup(stp_mxmlElementGetAttr(node, "name"));
234 qpw->n_quals = count;
235 qpw->qualities = stp_zalloc(sizeof(quality_t) * count);
236 child = node->child;
237 count = 0;
238 while (child)
239 {
240 if (child->type == STP_MXML_ELEMENT &&
241 !strcmp(child->value.element.name, "quality"))
242 {
243 stp_mxml_node_t *cchild = child->child;
244 const char *wname = stp_mxmlElementGetAttr(child, "name");
245 const char *wtext = stp_mxmlElementGetAttr(child, "text");
246 if (wname)
247 qpw->qualities[count].name = stp_strdup(wname);
248 if (wtext)
249 qpw->qualities[count].text = stp_strdup(wtext);
250 while (cchild)
251 {
252 if (cchild->type == STP_MXML_ELEMENT &&
253 (!strcmp(cchild->value.element.name, "minimumResolution") ||
254 !strcmp(cchild->value.element.name, "maximumResolution") ||
255 !strcmp(cchild->value.element.name, "desiredResolution")))
256 {
257 long data[2] = { 0, 0 };
258 stp_mxml_node_t *ccchild = cchild->child;
259 data[0] = stp_xmlstrtol(ccchild->value.text.string);
260 ccchild = ccchild->next;
261 data[1] = stp_xmlstrtol(ccchild->value.text.string);
262 if (!strcmp(cchild->value.element.name, "minimumResolution"))
263 {
264 qpw->qualities[count].min_hres = data[0];
265 qpw->qualities[count].min_vres = data[1];
266 }
267 else if (!strcmp(cchild->value.element.name, "maximumResolution"))
268 {
269 qpw->qualities[count].max_hres = data[0];
270 qpw->qualities[count].max_vres = data[1];
271 }
272 else if (!strcmp(cchild->value.element.name, "desiredResolution"))
273 {
274 qpw->qualities[count].desired_hres = data[0];
275 qpw->qualities[count].desired_vres = data[1];
276 }
277 }
278 cchild = cchild->next;
279 }
280 count++;
281 }
282 child = child->next;
283 }
284 return qpw;
285 }
286
287 int
288 stpi_escp2_load_quality_presets(const stp_vars_t *v, const char *name)
289 {
290 stp_dprintf(STP_DBG_ESCP2_XML, v,
291 ">>>Loading quality presets from %s...", name);
292 static const char *quality_cache = "escp2QualityPresets";
293 stpi_escp2_printer_t *printdef = stpi_escp2_get_printer(v);
294 quality_list_t *qpw =
295 (quality_list_t *) stp_refcache_find_item(quality_cache, name);
296 if (qpw)
297 stp_dprintf(STP_DBG_ESCP2_XML, v, "cached!");
298 if(! qpw)
299 {
300 stp_mxml_node_t *node =
301 stp_xml_parse_file_from_path_uncached_safe(name, "escp2QualityPresets", NULL);
302 stp_xml_init();
303 qpw = stpi_escp2_load_quality_presets_from_xml(node);
304 stp_refcache_add_item(quality_cache, name, qpw);
305 stp_xml_free_parsed_file(node);
306 stp_xml_exit();
307 }
308 printdef->quality_list = qpw;
309 stp_dprintf(STP_DBG_ESCP2_XML, v, "(%p) done!", (void *) qpw);
310 return 1;
311 }