From 0fb1a614c58103bf480d0ebbff9da4714738e0f7 Mon Sep 17 00:00:00 2001 From: Gauthier Quesnel Date: Tue, 2 Jul 2024 15:13:57 +0200 Subject: [PATCH] dexi: adds new FONTNAME and INTERVAL tokens --- lib/src/model.cpp | 36 ++++++++++++++++++++++++++++++++++++ lib/src/model.hpp | 12 ++++++------ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/lib/src/model.cpp b/lib/src/model.cpp index 874e163..536084f 100644 --- a/lib/src/model.cpp +++ b/lib/src/model.cpp @@ -114,12 +114,14 @@ struct Model_reader OPTION, SETTINGS, FONTSIZE, + FONTNAME, PAGEBREAK, REPORTS, ATTRIBUTE, NAME, DESCRIPTION, SCALE, + INTERVAL, ORDER, SCALEVALUE, GROUP, @@ -153,12 +155,14 @@ struct Model_reader { "OPTION", stack_identifier::OPTION }, { "SETTINGS", stack_identifier::SETTINGS }, { "FONTSIZE", stack_identifier::FONTSIZE }, + { "FONTNAME", stack_identifier::FONTNAME }, { "PAGEBREAK", stack_identifier::PAGEBREAK }, { "REPORTS", stack_identifier::REPORTS }, { "ATTRIBUTE", stack_identifier::ATTRIBUTE }, { "NAME", stack_identifier::NAME }, { "DESCRIPTION", stack_identifier::DESCRIPTION }, { "SCALE", stack_identifier::SCALE }, + { "INTERVAL", stack_identifier::INTERVAL }, { "ORDER", stack_identifier::ORDER }, { "SCALEVALUE", stack_identifier::SCALEVALUE }, { "GROUP", stack_identifier::GROUP }, @@ -289,6 +293,14 @@ struct Model_reader pd->stack.push(id); break; + case stack_identifier::FONTNAME: + if (!pd->is_parent({ stack_identifier::SETTINGS })) { + pd->stop_parser(status::dexi_parser_file_format_error); + break; + } + pd->stack.push(id); + break; + case stack_identifier::PAGEBREAK: if (!pd->is_parent({ stack_identifier::SETTINGS })) { pd->stop_parser(status::dexi_parser_file_format_error); @@ -381,6 +393,13 @@ struct Model_reader } break; + case stack_identifier::INTERVAL: + if (!pd->is_parent({ stack_identifier::SCALE })) { + pd->stop_parser(status::dexi_parser_file_format_error); + break; + } + break; + case stack_identifier::SCALEVALUE: if (!pd->is_parent({ stack_identifier::SCALE })) { pd->stop_parser(status::dexi_parser_file_format_error); @@ -491,6 +510,11 @@ struct Model_reader pd->stack.pop(); break; + case stack_identifier::FONTNAME: + pd->model.fontname.assign(pd->char_data); + pd->stack.pop(); + break; + case stack_identifier::PAGEBREAK: pd->model.pagebreak.assign(pd->char_data); pd->stack.pop(); @@ -567,7 +591,11 @@ struct Model_reader case stack_identifier::ORDER: if (pd->char_data == "NONE") pd->model.attributes.back().scale.order = false; + break; + case stack_identifier::INTERVAL: + pd->model.attributes.back().scale.interval = + (pd->char_data != "False"); break; case stack_identifier::SCALEVALUE: @@ -742,6 +770,9 @@ struct Model_writer if (!dex.fontsize.empty()) os.print(" {}\n", escape(dex.fontsize)); + if (!dex.fontname.empty()) + os.print(" {}\n", escape(dex.fontname)); + if (!dex.optdatatype.empty()) os.print(" {}\n", escape(dex.optdatatype)); @@ -860,6 +891,11 @@ struct Model_writer os.print("NONE\n"); } + if (!att.scale.interval) { + make_space(); + os.print("False\n"); + } + for (const auto& sv : att.scale.scale) { make_space(); os.print("\n"); diff --git a/lib/src/model.hpp b/lib/src/model.hpp index cbf7b73..a05daac 100644 --- a/lib/src/model.hpp +++ b/lib/src/model.hpp @@ -87,12 +87,10 @@ struct function struct scales { - scales() - : order(true) - { - } + scales() = default; - bool order; + bool order = true; + bool interval = false; std::vector scale; std::optional find_scale_value(const std::string& name) const @@ -163,6 +161,7 @@ struct Model std::string created; std::string pagebreak = "True"; std::string fontsize; + std::string fontname; std::string reports = "6"; std::string optdatatype; std::string optlevels; @@ -270,7 +269,8 @@ operator==(const scalevalue& lhs, const scalevalue& rhs) inline bool operator==(const scales& lhs, const scales& rhs) { - return lhs.order == rhs.order && lhs.scale == rhs.scale; + return lhs.order == rhs.order && lhs.interval == rhs.interval && + lhs.scale == rhs.scale; } inline bool