diff --git a/backend/emf.c b/backend/emf.c index 47834efd..bd6f6a29 100644 --- a/backend/emf.c +++ b/backend/emf.c @@ -248,7 +248,6 @@ INTERNAL int emf_plot(struct zint_symbol *symbol) { } rect = symbol->vector->rectangles; - this_rectangle = 0; while (rect) { if (rectangle_count_bycolour[rect->colour] == 0) { colours_used++; @@ -634,11 +633,11 @@ INTERNAL int emf_plot(struct zint_symbol *symbol) { if (string_count > 0) { fwrite(&emr_selectobject_font, sizeof (emr_selectobject_t), 1, emf_file); } - + for (i = 0; i < string_count; i++) { spacing = 8 * symbol->scale; fwrite(&text[i], sizeof (emr_exttextoutw_t), 1, emf_file); - fwrite(this_string[i], bump_up(text[i].w_emr_text.chars + 1) * 2, 1, emf_file); + fwrite(this_string[i], bump_up(text[i].w_emr_text.chars + 1) * 2, 1, emf_file); // NOLINT text set 0..(string_count - 1) free(this_string[i]); for (j = 0; j < bump_up(text[i].w_emr_text.chars + 1); j++) { fwrite(&spacing, 4, 1, emf_file); diff --git a/backend/tests/CMakeLists.txt b/backend/tests/CMakeLists.txt index 42efd9be..bbe1d3ee 100644 --- a/backend/tests/CMakeLists.txt +++ b/backend/tests/CMakeLists.txt @@ -61,6 +61,7 @@ zint_add_test(composite, test_composite) zint_add_test(dmatrix, test_dmatrix) zint_add_test(dotcode, test_dotcode) zint_add_test(eci, test_eci) +zint_add_test(emf, test_emf) zint_add_test(gb18030, test_gb18030) zint_add_test(gb2312, test_gb2312) zint_add_test(gridmtx, test_gridmtx) diff --git a/backend/tests/test_emf.c b/backend/tests/test_emf.c new file mode 100644 index 00000000..bb391a38 --- /dev/null +++ b/backend/tests/test_emf.c @@ -0,0 +1,117 @@ +/* + libzint - the open source barcode library + Copyright (C) 2020 Robin Stuart + + 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. + */ +/* vim: set ts=4 sw=4 et : */ + +#include "testcommon.h" + +static void test_emf(int index, int debug) { + + testStart(""); + + if (!testUtilHaveInkscape()) { + testSkip("Inkscape not available"); + return; + } + + int ret; + struct item { + int symbology; + int option_1; + int option_2; + char *fgcolour; + char *bgcolour; + float scale; + unsigned char *data; + }; + // s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) + struct item data[] = { + /* 0*/ { BARCODE_EANX, -1, -1, NULL, NULL, 0, "210987654321+54321" }, // #185 Byte count, font data, HeaderExtension1/2 + /* 1*/ { BARCODE_MAXICODE, -1, 20, "E0E0E0", "700070", 0, "THIS IS A 93 CHARACTER CODE SET A MESSAGE THAT FILLS A MODE 4, UNAPPENDED, MAXICODE SYMBOL..." }, // #185 Maxicode scaling + }; + int data_size = ARRAY_SIZE(data); + + for (int i = 0; i < data_size; i++) { + + if (index != -1 && i != index) continue; + + struct zint_symbol *symbol = ZBarcode_Create(); + assert_nonnull(symbol, "Symbol not created\n"); + + symbol->symbology = data[i].symbology; + if (data[i].option_1 != -1) { + symbol->option_1 = data[i].option_1; + } + if (data[i].option_2 != -1) { + symbol->option_2 = data[i].option_2; + } + if (data[i].fgcolour != NULL) { + strcpy(symbol->fgcolour, data[i].fgcolour); + } + if (data[i].bgcolour != NULL) { + strcpy(symbol->bgcolour, data[i].bgcolour); + } + if (data[i].scale != 0) { + symbol->scale = data[i].scale; + } + symbol->debug | debug; + + int length = strlen(data[i].data); + + ret = ZBarcode_Encode(symbol, data[i].data, length); + assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); + + char *filename = "out.emf"; + strcpy(symbol->outfile, filename); + ret = ZBarcode_Print(symbol, 0); + assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret); + + ret = testUtilVerifyInkscape(symbol->outfile, debug); // Slow + assert_zero(ret, "i:%d %s inkscape %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret); + + assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile); + + ZBarcode_Delete(symbol); + } + + testFinish(); +} + +int main(int argc, char *argv[]) { + + testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ + { "test_emf", test_emf, 1, 0, 1 }, + }; + + testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); + + testReport(); + + return 0; +}