--- a/src/QRCommand.h Wed Apr 14 20:56:18 2021 +0200
+++ b/src/QRCommand.h Wed Apr 14 22:02:23 2021 +0200
@@ -32,6 +32,7 @@
namespace qr {
class QRCommand {
+private:
std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: use platform encoding as default / check zbar encoding
@@ -55,15 +56,10 @@
// {L"addon_name", relpipe::writer::TypeId::STRING},
{L"value", relpipe::writer::TypeId::STRING},
// {L"xml", relpipe::writer::TypeId::STRING},
- {L"location_size", relpipe::writer::TypeId::INTEGER},
- {L"x_1", relpipe::writer::TypeId::INTEGER},
- {L"y_1", relpipe::writer::TypeId::INTEGER},
- {L"x_2", relpipe::writer::TypeId::INTEGER},
- {L"y_2", relpipe::writer::TypeId::INTEGER},
- {L"x_3", relpipe::writer::TypeId::INTEGER},
- {L"y_3", relpipe::writer::TypeId::INTEGER},
- {L"x_4", relpipe::writer::TypeId::INTEGER},
- {L"y_4", relpipe::writer::TypeId::INTEGER},
+ {L"x", relpipe::writer::TypeId::INTEGER},
+ {L"y", relpipe::writer::TypeId::INTEGER},
+ {L"width", relpipe::writer::TypeId::INTEGER},
+ {L"height", relpipe::writer::TypeId::INTEGER},
}, true);
int n = scanner.scan(image);
@@ -74,21 +70,28 @@
writer->writeAttribute(convertor.from_bytes(symbol->get_data()));
// writer->writeAttribute(convertor.from_bytes(symbol->xml()));
- relpipe::common::type::Integer locationSize = symbol->get_location_size();
- writer->writeAttribute(&locationSize, typeid (locationSize));
-
- for (int i = 0; i < 4; i++) {
- relpipe::common::type::Integer x = -5;
- relpipe::common::type::Integer y = -6;
- if (i < locationSize) {
- x = symbol->get_location_x(i);
- y = symbol->get_location_y(i);
- }
- writer->writeAttribute(&x, typeid (x));
- writer->writeAttribute(&y, typeid (y));
+ relpipe::common::type::Integer minX = 0;
+ relpipe::common::type::Integer minY = 0;
+ relpipe::common::type::Integer maxX = 0;
+ relpipe::common::type::Integer maxY = 0;
+
+ // TODO: return original polygon in XML
+ for (int i = 0, locationSize = symbol->get_location_size(); i < locationSize; i++) {
+ relpipe::common::type::Integer x = symbol->get_location_x(i);
+ relpipe::common::type::Integer y = symbol->get_location_y(i);
+ minX = minX ? std::min(minX, x) : x;
+ minY = minY ? std::min(minY, y) : y;
+ maxX = std::max(maxX, x);
+ maxY = std::max(maxY, y);
}
+ relpipe::common::type::Integer width = maxX - minX;
+ relpipe::common::type::Integer height = maxY - minY;
+ writer->writeAttribute(&minX, typeid (minX));
+ writer->writeAttribute(&minY, typeid (minY));
+ writer->writeAttribute(&width, typeid (width));
+ writer->writeAttribute(&height, typeid (height));
}
image.set_data(nullptr, 0);