zxing-cpp 0.5.2

A rust wrapper for the zxing-cpp barcode library.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
/* ps.c - Post Script output */
/*
    libzint - the open source barcode library
    Copyright (C) 2009-2025 Robin Stuart <rstuart114@gmail.com>

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

    1. Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.
    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.
    3. Neither the name of the project nor the names of its contributors
       may be used to endorse or promote products derived from this software
       without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    SUCH DAMAGE.
 */
/* SPDX-License-Identifier: BSD-3-Clause */

#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include "common.h"
#include "filemem.h"
#include "output.h"

/* Output Ultracode rectangle colour as PostScript setrgbcolor/setcmykcolor */
static void ps_put_colour(const int is_rgb, const int colour, struct filemem *const fmp) {
    const int idx = colour >= 1 && colour <= 8 ? colour - 1 : 6 /*black*/;
    if (is_rgb) {
        /* Use RGB colour space */
        static const char ps_rgbs[8][6] = {
            "0 1 1", /* 0: Cyan (1) */
            "0 0 1", /* 1: Blue (2) */
            "1 0 1", /* 2: Magenta (3) */
            "1 0 0", /* 3: Red (4) */
            "1 1 0", /* 4: Yellow (5) */
            "0 1 0", /* 5: Green (6) */
            "0 0 0", /* 6: Black (7) */
            "1 1 1", /* 7: White (8) */
        };
        zint_fm_puts(ps_rgbs[idx], fmp);
        zint_fm_puts(" setrgbcolor\n", fmp);
    } else {
        static const char ps_cmyks[8][8] = {
            "1 0 0 0", /* 0: Cyan (1) */
            "1 1 0 0", /* 1: Blue (2) */
            "0 1 0 0", /* 2: Magenta (3) */
            "0 1 1 0", /* 3: Red (4) */
            "0 0 1 0", /* 4: Yellow (5) */
            "1 0 1 0", /* 5: Green (6) */
            "0 0 0 1", /* 6: Black (7) */
            "0 0 0 0", /* 7: White (8) */
        };
        zint_fm_puts(ps_cmyks[idx], fmp);
        zint_fm_puts(" setcmykcolor\n", fmp);
    }
}

/* Escape special PostScript chars. Assumes valid UTF-8-encoded ISO/IEC 8859-1 */
static void ps_convert(const unsigned char *string, unsigned char *ps_string) {
    const unsigned char *s;
    unsigned char *p = ps_string;

    /* `NOLINT` required due to disconnect between `symbol->text` and vector `string`s which are always <= */
    /* NOLINTBEGIN(clang-analyzer-security.ArrayBound) clang-tidy-21 false positive */
    for (s = string; *s; s++) {
        switch (*s) {
            case '(':
            case ')':
            case '\\':
                *p++ = '\\';
                *p++ = *s;
                break;
            case 0xC2:
                *p++ = *++s; /* C2 80-BF -> 80-BF */
                break;
            case 0xC3:
                *p++ = *++s + 0x40; /* C3 80-BF -> C0-FF */
                break;
            default:
                if (*s < 0x80) { /* ASCII - all other Unicode points > U+00FF ignored */
                    *p++ = *s;
                }
                break;
        }
    }
    *p = '\0';
    /* NOLINTEND(clang-analyzer-security.ArrayBound) */
}

#ifdef ZINT_TEST /* Wrapper for direct testing */
INTERNAL void zint_test_ps_convert(const unsigned char *string, unsigned char *ps_string) {
    ps_convert(string, ps_string);
}
#endif

/* Helper to output RGB colour */
static void ps_put_rgbcolor(const float red, const float green, const float blue,
                struct filemem *const fmp) {
    zint_fm_putsf("", 2, red, fmp);
    zint_fm_putsf(" ", 2, green, fmp);
    zint_fm_putsf(" ", 2, blue, fmp);
    zint_fm_puts(" setrgbcolor\n", fmp);
}

/* Helper to output CMYK colour */
static void ps_put_cmykcolor(const float cyan, const float magenta, const float yellow, const float black,
                struct filemem *const fmp) {
    zint_fm_putsf("", 2, cyan, fmp);
    zint_fm_putsf(" ", 2, magenta, fmp);
    zint_fm_putsf(" ", 2, yellow, fmp);
    zint_fm_putsf(" ", 2, black, fmp);
    zint_fm_puts(" setcmykcolor\n", fmp);
}

/* Helper to output rectangle */
static void ps_put_rect(const struct zint_symbol *symbol, const struct zint_vector_rect *rect, const int type,
                struct filemem *const fmp) {
    if (type == 0 || type == 1) {
        zint_fm_putsf("", 2, rect->height, fmp);
        zint_fm_putsf(" ", 2, (symbol->vector->height - rect->y) - rect->height, fmp);
    }
    zint_fm_putsf(type == 0 ? " " : type == 1 ? " I " : type == 2 ? "I " : "", 2, rect->x, fmp);
    zint_fm_putsf(" ", 2, rect->width, fmp);
    zint_fm_puts(" R\n", fmp);
}

/* Helper to output circle/disc */
static void ps_put_circle(const struct zint_symbol *symbol, const struct zint_vector_circle *circle,
                const float radius, const int type, struct filemem *const fmp) {
    if (circle->width) {
        zint_fm_putsf("", 2, circle->x, fmp);
        zint_fm_putsf(" ", 2, symbol->vector->height - circle->y, fmp);
        zint_fm_putsf(" ", 4, radius, fmp);
        zint_fm_putsf(" ", 4, circle->width, fmp);
        zint_fm_puts(" C\n", fmp);
    } else {
        if (type == 0 || type == 1) {
            zint_fm_putsf("", 2, symbol->vector->height - circle->y, fmp);
            zint_fm_putsf(" ", 4, radius, fmp);
        }
        zint_fm_putsf(type == 0 ? " " : type == 1 ? " I " : type == 2 ? "I " : "", 2, circle->x, fmp);
        zint_fm_puts(" D\n", fmp);
    }
}

/* Helper to count rectangles */
static int ps_count_rectangles(const struct zint_symbol *symbol) {
    int rectangles = 0;
    const struct zint_vector_rect *rect;

    for (rect = symbol->vector->rectangles; rect; rect = rect->next) {
        rectangles++;
    }

    return rectangles;
}

INTERNAL int zint_ps_plot(struct zint_symbol *symbol) {
    struct filemem fm;
    struct filemem *const fmp = &fm;
    unsigned char fgred, fggrn, fgblu, bgred, bggrn, bgblu, bgalpha;
    int fgcyan, fgmagenta, fgyellow, fgblack, bgcyan, bgmagenta, bgyellow, bgblack;
    float red_ink = 0.0f, green_ink = 0.0f, blue_ink = 0.0f; /* Suppress `-Wmaybe-uninitialized` */
    float red_paper = 0.0f, green_paper = 0.0f, blue_paper = 0.0f;
    float cyan_ink = 0.0f, magenta_ink = 0.0f, yellow_ink = 0.0f, black_ink = 0.0f;
    float cyan_paper = 0.0f, magenta_paper = 0.0f, yellow_paper = 0.0f, black_paper = 0.0f;
    float previous_diameter;
    float radius;
    int colour_rect_flag;
    int type_latch;
    int draw_background = 1;
    struct zint_vector_rect *rect;
    struct zint_vector_hexagon *hex;
    struct zint_vector_circle *circle;
    struct zint_vector_string *string;
    int i;
    int ps_len = 0;
    int iso_latin1 = 0;
    int have_circles_with_width = 0, have_circles_without_width = 0;
    const int is_upcean = z_is_upcean(symbol->symbology);
    const int is_rgb = (symbol->output_options & CMYK_COLOUR) == 0;

    if (symbol->vector == NULL) {
        return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 646, "Vector header NULL");
    }
    if (!zint_fm_open(fmp, symbol, "w")) {
        return ZEXT z_errtxtf(ZINT_ERROR_FILE_ACCESS, symbol, 645, "Could not open EPS output file (%1$d: %2$s)",
                                fmp->err, strerror(fmp->err));
    }

    if (is_rgb) {
        (void) zint_out_colour_get_rgb(symbol->fgcolour, &fgred, &fggrn, &fgblu, NULL /*alpha*/);
        red_ink = fgred / 255.0f;
        green_ink = fggrn / 255.0f;
        blue_ink = fgblu / 255.0f;

        (void) zint_out_colour_get_rgb(symbol->bgcolour, &bgred, &bggrn, &bgblu, &bgalpha);
        red_paper = bgred / 255.0f;
        green_paper = bggrn / 255.0f;
        blue_paper = bgblu / 255.0f;
    } else {
        (void) zint_out_colour_get_cmyk(symbol->fgcolour, &fgcyan, &fgmagenta, &fgyellow, &fgblack,
                                        NULL /*rgb_alpha*/);
        cyan_ink = fgcyan / 100.0f;
        magenta_ink = fgmagenta / 100.0f;
        yellow_ink = fgyellow / 100.0f;
        black_ink = fgblack / 100.0f;

        (void) zint_out_colour_get_cmyk(symbol->bgcolour, &bgcyan, &bgmagenta, &bgyellow, &bgblack, &bgalpha);
        cyan_paper = bgcyan / 100.0f;
        magenta_paper = bgmagenta / 100.0f;
        yellow_paper = bgyellow / 100.0f;
        black_paper = bgblack / 100.0f;
    }
    if (bgalpha == 0) {
        draw_background = 0;
    }

    for (i = 0; i < symbol->text_length; i++) {
        switch (symbol->text[i]) {
            case '(':
            case ')':
            case '\\':
                ps_len += 2;
                break;
            default:
                if (!iso_latin1 && symbol->text[i] >= 0x80) {
                    iso_latin1 = 1;
                }
                ps_len++; /* Will overcount 2 byte UTF-8 chars */
                break;
        }
    }

    /* Check for circle widths */
    for (circle = symbol->vector->circles; circle; circle = circle->next) {
        if (circle->width) {
            have_circles_with_width = 1;
            if (have_circles_without_width) {
                break;
            }
        } else {
            have_circles_without_width = 1;
            if (have_circles_with_width) {
                break;
            }
        }
    }

    /* Start writing the header */
    zint_fm_puts("%!PS-Adobe-3.0 EPSF-3.0\n"
                "%%Creator: Zint ", fmp);
#if ZINT_VERSION_BUILD
    zint_fm_printf(fmp, "%d.%d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE,
                    ZINT_VERSION_BUILD);
#else
    zint_fm_printf(fmp, "%d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE);
#endif
    zint_fm_puts("%%Title: Zint Generated Symbol\n"
                "%%Pages: 0\n"
                "%%BoundingBox: 0 0 ", fmp);
    zint_fm_printf(fmp, "%d %d\n", (int) ceilf(symbol->vector->width), (int) ceilf(symbol->vector->height));
    zint_fm_puts("%%EndComments\n", fmp);

    /* Definitions */
    if (have_circles_without_width) {
        /* Disc: y radius x D */
        zint_fm_puts("/D { newpath 3 1 roll 0 360 arc fill } bind def\n", fmp);
    }
    if (have_circles_with_width) {
        /* Circle (ring): x y radius width C (adapted from BWIPP renmaxicode.ps) */
        zint_fm_puts("/C { newpath 4 1 roll 3 copy 0 360 arc closepath 4 -1 roll add 360 0 arcn closepath fill }"
                    " bind def\n", fmp);
    }
    if (symbol->vector->hexagons) {
        /* Hexagon: radius half_radius half_sqrt3_radius x y */
        if (symbol->vector->hexagons->rotation == 0 || symbol->vector->hexagons->rotation == 180) {
            zint_fm_puts("/H { newpath moveto 2 copy exch neg exch rmoveto 2 index neg 0 exch rlineto"
                        " 2 copy neg rlineto 2 copy rlineto 3 -1 roll 0 exch rlineto exch neg exch rlineto"
                        " closepath fill } bind def\n", fmp);
        } else {
            zint_fm_puts("/H { newpath moveto 2 copy neg exch neg rmoveto 2 index 0 rlineto 2 copy exch rlineto"
                        " 2 copy neg exch rlineto 3 -1 roll neg 0 rlineto neg exch neg rlineto"
                        " closepath fill } bind def\n", fmp);
        }
        /* Copy r hr hsr for repeat use without having to specify them subsequently */
        zint_fm_puts("/J { 3 copy } bind def\n", fmp);
        /* TODO: Save repeating x also */
    }
    if (symbol->vector->rectangles || draw_background) {
        /* Rectangle: h y x w */
        zint_fm_puts("/R { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto"
                    " closepath fill } bind def\n", fmp);
    }
    if (symbol->vector->rectangles || have_circles_without_width) {
        /* Copy h y (rect) or y r (disc) for repeat use without having to specify them subsequently */
        zint_fm_puts("/I { 2 copy } bind def\n", fmp);
    }

    /* Now the actual representation */

    /* Background */
    if (draw_background) {
        if (is_rgb) {
            ps_put_rgbcolor(red_paper, green_paper, blue_paper, fmp);
        } else {
            ps_put_cmykcolor(cyan_paper, magenta_paper, yellow_paper, black_paper, fmp);
        }

        zint_fm_putsf("", 2, symbol->vector->height, fmp);
        zint_fm_putsf(" 0 0 ", 2, symbol->vector->width, fmp); /* y x w */
        zint_fm_puts(" R\n", fmp);
    }

    if (symbol->symbology != BARCODE_ULTRA) {
        if (is_rgb) {
            ps_put_rgbcolor(red_ink, green_ink, blue_ink, fmp);
        } else {
            ps_put_cmykcolor(cyan_ink, magenta_ink, yellow_ink, black_ink, fmp);
        }
    }

    /* Rectangles */
    if (symbol->symbology == BARCODE_ULTRA) {
        /* Group rectangles by colour */
        const int rect_cnt = ps_count_rectangles(symbol);
        struct zint_vector_rect **ultra_rects
            = (struct zint_vector_rect **) z_alloca(sizeof(struct zint_vector_rect *) * (rect_cnt ? rect_cnt : 1));
        int u_i = 0;
        for (i = 0; i <= 8; i++) {
            for (rect = symbol->vector->rectangles; rect; rect = rect->next) {
                if ((i == 0 && rect->colour == -1) || rect->colour == i) {
                    assert(u_i < rect_cnt); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
                    ultra_rects[u_i++] = rect;
                }
            }
        }
        assert(u_i == ps_count_rectangles(symbol));

        colour_rect_flag = 0;
        type_latch = 0;
        for (i = 0; i < u_i; i++) {
            rect = ultra_rects[i];
            if (i == 0 || rect->colour != ultra_rects[i - 1]->colour) {
                if (rect->colour == -1) {
                    if (colour_rect_flag == 0) {
                        /* Set foreground colour */
                        if (is_rgb) {
                            ps_put_rgbcolor(red_ink, green_ink, blue_ink, fmp);
                        } else {
                            ps_put_cmykcolor(cyan_ink, magenta_ink, yellow_ink, black_ink, fmp);
                        }
                        colour_rect_flag = 1;
                    }
                } else {
                    /* Set new colour */
                    ps_put_colour(is_rgb, rect->colour, fmp);
                }
            }
            if (i + 1 < u_i && rect->height == ultra_rects[i + 1]->height && rect->y == ultra_rects[i + 1]->y) {
                ps_put_rect(symbol, rect, type_latch ? 2 : 1, fmp);
                type_latch = 1;
            } else {
                ps_put_rect(symbol, rect, type_latch ? 3 : 0, fmp);
                type_latch = 0;
            }
        }
    } else {
        type_latch = 0;
        for (rect = symbol->vector->rectangles; rect; rect = rect->next) {
            if (rect->next && rect->height == rect->next->height && rect->y == rect->next->y) {
                ps_put_rect(symbol, rect, type_latch ? 2 : 1, fmp);
                type_latch = 1;
            } else {
                ps_put_rect(symbol, rect, type_latch ? 3 : 0, fmp);
                type_latch = 0;
            }
        }
    }

    /* Hexagons */
    previous_diameter = 0.0f;
    for (hex = symbol->vector->hexagons; hex; hex = hex->next) {
        float hy = symbol->vector->height - hex->y;
        if (previous_diameter != hex->diameter) {
            previous_diameter = hex->diameter;
            zint_fm_putsf("", 4, 0.5f * previous_diameter /*radius*/, fmp);
            zint_fm_putsf(" ", 4, 0.43301270189221932338f * previous_diameter /*half_sqrt3_radius*/, fmp);
            zint_fm_putsf(" ", 4, 0.25f * previous_diameter /*half_radius*/, fmp);
            zint_fm_putc('\n', fmp);
        }
        if (hex->next) {
            zint_fm_putsf("J ", 2, hex->x, fmp);
        } else {
            zint_fm_putsf("", 2, hex->x, fmp);
        }
        zint_fm_putsf(" ", 2, hy, fmp);
        zint_fm_puts(" H\n", fmp);
    }

    /* Circles */
    previous_diameter = radius = 0.0f;
    type_latch = 0;
    for (circle = symbol->vector->circles; circle; circle = circle->next) {
        if (previous_diameter != circle->diameter - circle->width) {
            previous_diameter = circle->diameter - circle->width;
            radius = 0.5f * previous_diameter;
        }
        if (circle->colour) { /* Legacy - no longer used */
            /* A 'white' circle */
            if (is_rgb) {
                ps_put_rgbcolor(red_paper, green_paper, blue_paper, fmp);
            } else {
                ps_put_cmykcolor(cyan_paper, magenta_paper, yellow_paper, black_paper, fmp);
            }
            ps_put_circle(symbol, circle, radius, 0 /*type*/, fmp);
            if (circle->next) {
                if (is_rgb) {
                    ps_put_rgbcolor(red_ink, green_ink, blue_ink, fmp);
                } else {
                    ps_put_cmykcolor(cyan_ink, magenta_ink, yellow_ink, black_ink, fmp);
                }
            }
        } else {
            /* A 'black' circle */
            if (circle->next && circle->y == circle->next->y && circle->diameter == circle->next->diameter) {
                ps_put_circle(symbol, circle, radius, type_latch ? 2 : 1, fmp);
                type_latch = 1;
            } else {
                ps_put_circle(symbol, circle, radius, type_latch ? 3 : 0, fmp);
                type_latch = 0;
            }
        }
    }

    /* Text */

    string = symbol->vector->strings;

    if (string) {
        float previous_fsize = 0.0f;
        const char *font;
        unsigned char *ps_string = (unsigned char *) z_alloca(ps_len + 1);

        if ((symbol->output_options & BOLD_TEXT) && !is_upcean) {
            font = "Helvetica-Bold";
        } else {
            font = "Helvetica";
        }
        if (iso_latin1) {
            /* Change encoding to ISO 8859-1, see Postscript Language Reference Manual 2nd Edition Example 5.6 */
            zint_fm_printf(fmp, "/%s findfont\n", font);
            zint_fm_puts("dup length dict begin\n"
                          "{1 index /FID ne {def} {pop pop} ifelse} forall\n"
                          "/Encoding ISOLatin1Encoding def\n"
                          "currentdict\n"
                          "end\n"
                          "/Helvetica-ISOLatin1 exch definefont pop\n", fmp);
            font = "Helvetica-ISOLatin1";
        }
        do {
            ps_convert(string->text, ps_string);
            if (string->fsize != previous_fsize) {
                zint_fm_printf(fmp, "/%s findfont", font);
                /* Compensate for Helvetica being smaller than Zint's OCR-B */
                zint_fm_putsf( " ", 2, is_upcean ? string->fsize * 1.07f : string->fsize, fmp);
                zint_fm_puts(" scalefont setfont\n", fmp);
                previous_fsize = string->fsize;
            }
            /* Unhack the guard whitespace `gws_left_fudge`/`gws_right_fudge` hack */
            if (is_upcean && string->halign == 1 && string->text[0] == '<') {
                const float gws_left_fudge = symbol->scale < 0.1f ? 0.1f : symbol->scale; /* 0.5 * 2 * scale */
                zint_fm_putsf(" ", 2, string->x + gws_left_fudge, fmp);
            } else if (is_upcean && string->halign == 2 && string->text[0] == '>') {
                const float gws_right_fudge = symbol->scale < 0.1f ? 0.1f : symbol->scale; /* 0.5 * 2 * scale */
                zint_fm_putsf(" ", 2, string->x - gws_right_fudge, fmp);
            } else {
                zint_fm_putsf(" ", 2, string->x, fmp);
            }
            zint_fm_putsf(" ", 2, symbol->vector->height - string->y, fmp);
            zint_fm_puts(" moveto\n", fmp);
            if (string->rotation != 0) {
                zint_fm_puts(" gsave\n", fmp);
                zint_fm_printf(fmp, " %d rotate\n", 360 - string->rotation);
            }
            if (string->halign == 0 || string->halign == 2) { /* Need width for middle or right align */
                zint_fm_printf(fmp, " (%s) stringwidth pop" /* Returns "width height" - discard "height" */
                                " %s 0 rmoveto\n", ps_string, string->halign == 2 ? "neg" : "-2 div");
            }
            zint_fm_printf(fmp, " (%s) show\n", ps_string);
            if (string->rotation != 0) {
                zint_fm_puts(" grestore\n", fmp);
            }
            string = string->next;
        } while (string);
    }

    if (zint_fm_error(fmp)) {
        ZEXT z_errtxtf(0, symbol, 647, "Incomplete write of EPS output (%1$d: %2$s)", fmp->err, strerror(fmp->err));
        (void) zint_fm_close(fmp, symbol);
        return ZINT_ERROR_FILE_WRITE;
    }

    if (!zint_fm_close(fmp, symbol)) {
        return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 649, "Failure on closing EPS output file (%1$d: %2$s)",
                                fmp->err, strerror(fmp->err));
    }

    return 0;
}

/* vim: set ts=4 sw=4 et : */