From e1b6f4a79bf9756a128a0141990fe0450d563b38 Mon Sep 17 00:00:00 2001 From: Libor Pechacek Date: Tue, 28 Dec 2021 18:08:32 +0100 Subject: [PATCH 1/2] OcdFileExport: Export objects with undefined symbols This commit fixes multiple issues with .ocd export. Line and point objects were exported with symbol number 0 while the typical value for such objects is -1. Text object export routines didn't recognize the undefined text symbol and choke on it, failing to export previously imported objects. Closes GH-2012. --- src/fileformats/ocd_file_export.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/fileformats/ocd_file_export.cpp b/src/fileformats/ocd_file_export.cpp index b0fdbd273..d8dc694ce 100644 --- a/src/fileformats/ocd_file_export.cpp +++ b/src/fileformats/ocd_file_export.cpp @@ -2507,7 +2507,9 @@ QByteArray OcdFileExport::exportPointObject(const PointObject* point, typename O { OcdObject ocd_object = {}; ocd_object.type = 1; - ocd_object.symbol = entry.symbol = decltype(entry.symbol)(symbol_numbers[point->getSymbol()]); + auto const symbol_number_it = symbol_numbers.find(point->getSymbol()); + decltype(entry.symbol) const symbol_number = symbol_number_it != symbol_numbers.end() ? symbol_number_it->second : -1; + ocd_object.symbol = entry.symbol = symbol_number; ocd_object.angle = decltype(ocd_object.angle)(convertRotation(point->getRotation())); return exportObjectCommon(point, ocd_object, entry); } @@ -2543,7 +2545,9 @@ void OcdFileExport::exportPathObject(OcdFile& file, const PathObject* pa if (!need_split_lines) { - ocd_object.symbol = entry.symbol = decltype(entry.symbol)(symbol_numbers[symbol]); + auto const symbol_number_it = symbol_numbers.find(symbol); + decltype(entry.symbol) const symbol_number = symbol_number_it != symbol_numbers.end() ? symbol_number_it->second : -1; + ocd_object.symbol = entry.symbol = symbol_number; auto data = exportObjectCommon(path, ocd_object, entry); FILEFORMAT_ASSERT(!data.isEmpty()); @@ -2619,11 +2623,16 @@ QByteArray OcdFileExport::exportTextObject(const TextObject* text, typename OcdO auto text_format = std::find_if(begin(text_format_mapping), end(text_format_mapping), [symbol, alignment](const auto& m) { return m.symbol == symbol && m.alignment == alignment; }); - FILEFORMAT_ASSERT(text_format != end(text_format_mapping)); + + decltype(entry.symbol) symbol_number = -1; + if (text_format != end(text_format_mapping)) + symbol_number = text_format->symbol_number; + else + FILEFORMAT_ASSERT(map->findSymbolIndex(symbol) < -1); // -2 and below indicate objects with undefined symbols OcdObject ocd_object = {}; ocd_object.type = text->hasSingleAnchor() ? 4 : 5; - ocd_object.symbol = entry.symbol = decltype(entry.symbol)(text_format->symbol_number); + ocd_object.symbol = entry.symbol = symbol_number; ocd_object.angle = decltype(ocd_object.angle)(convertRotation(text->getRotation())); return exportObjectCommon(text, ocd_object, entry); } From 40b005cfcca9d5a2f3f316168e6ba6dbecd5aa48 Mon Sep 17 00:00:00 2001 From: Libor Pechacek Date: Tue, 28 Dec 2021 18:24:54 +0100 Subject: [PATCH 2/2] OcdFileExport: Add tests for objects with undefined symbols --- test/data/undefined-objects.omap | 27 +++++++++++++++++++++++++++ test/file_format_t.cpp | 1 + 2 files changed, 28 insertions(+) create mode 100644 test/data/undefined-objects.omap diff --git a/test/data/undefined-objects.omap b/test/data/undefined-objects.omap new file mode 100644 index 000000000..20f6b00c5 --- /dev/null +++ b/test/data/undefined-objects.omap @@ -0,0 +1,27 @@ + + + + + + + + + + + +4792 1790; +3222 1770;-2778 1770; +1212 0;B +6137 72;C +-3667 0;A + + + + + + + + + + + diff --git a/test/file_format_t.cpp b/test/file_format_t.cpp index b7155cc86..04309402c 100644 --- a/test/file_format_t.cpp +++ b/test/file_format_t.cpp @@ -504,6 +504,7 @@ namespace "data:/examples/forest sample.omap", "data:/examples/overprinting.omap", "testdata:templates/world-file.xmap", + "data:undefined-objects.omap", }; auto const xml_test_files = {