Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/Content.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Content
SymbologyIdentifier symbology;
CharacterSet defaultCharset = CharacterSet::Unknown;
bool hasECI = false;
std::vector<size_t> fncPositions;

Content();
Content(ByteArray&& bytes, SymbologyIdentifier si);
Expand Down
18 changes: 18 additions & 0 deletions core/src/Result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ const ByteArray& Result::bytes() const
return _content.bytes;
}

ByteArray Result::bytesFNCFix() const
{
auto& fncPos = _content.fncPositions;
if(fncPos.empty()) {
return ByteArray(_content.bytes);
}
ByteArray newBytes(_content.bytes.size() - fncPos.size() * 5);
size_t a = 0, i = 0;
for(size_t b : fncPos){
std::copy(&_content.bytes[a], &_content.bytes[b], &newBytes[i]);
i+=b-a;
newBytes[i++] = 232;
a = b + 6;
}
std::copy(&_content.bytes[a], &_content.bytes[_content.bytes.size()], &newBytes[i]);
return newBytes;
}

ByteArray Result::bytesECI() const
{
return _content.bytesECI();
Expand Down
5 changes: 5 additions & 0 deletions core/src/Result.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class Result
*/
const ByteArray& bytes() const;

/**
* @brief bytes is the raw / standard content without any modifications like character set conversions
*/
ByteArray bytesFNCFix() const;

/**
* @brief bytesECI is the raw / standard content following the ECI protocol
*/
Expand Down
34 changes: 16 additions & 18 deletions core/src/datamatrix/DMDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ static void DecodeC40OrTextSegment(BitSource& bits, Content& result, Mode mode)
case 2:
if (cValue < 28) // Size(SHIFT_SET_CHARS))
if (SHIFT_SET_CHARS[cValue] == (char)29) {
// result.push_back(232);
result.fncPositions.push_back(result.bytes.size());
result.push_back((char)'{');
result.push_back((char)'F');
result.push_back((char)'N');
Expand Down Expand Up @@ -295,7 +297,7 @@ DecoderResult Decode(ByteArray&& bytes, const bool isDMRE)
bool readerInit = false;
bool firstCodeword = true;
bool done = false;
int firstFNC1Position = 1;
// int firstFNC1Position = 1;
Shift128 upperShift;

// See ISO 16022:2006, 5.2.3 and Annex C, Table C.2
Expand All @@ -314,25 +316,21 @@ DecoderResult Decode(ByteArray&& bytes, const bool isDMRE)
// Only recognizing an FNC1 as first/second by codeword position (aka symbol character position), not
// by decoded character position, i.e. not recognizing a C40/Text encoded FNC1 (which requires a latch
// and a shift)
if (bits.byteOffset() == firstFNC1Position)
{
result.push_back((char)'{');
result.push_back((char)'F');
result.push_back((char)'N');
result.push_back((char)'C');
result.push_back((char)'1');
result.push_back((char)'}');
break;
}
//result.symbology.modifier = '2'; // GS1
// if (bits.byteOffset() == firstFNC1Position)
// result.symbology.modifier = '2'; // GS1
// else if (bits.byteOffset() == firstFNC1Position + 1)
// result.symbology.modifier = '3'; // AIM, note no AIM Application Indicator format defined, ISO 16022:2006 11.2
else
{
result.push_back((char)29); // translate as ASCII 29 <GS>
break;
}

// else
// result.push_back((char)29); // translate as ASCII 29 <GS>
// result.push_back(232);
result.fncPositions.push_back(result.bytes.size());
result.push_back((char)'{');
result.push_back((char)'F');
result.push_back((char)'N');
result.push_back((char)'C');
result.push_back((char)'1');
result.push_back((char)'}');
break;
case 233: // Structured Append
if (!firstCodeword) // Must be first ISO 16022:2006 5.6.1
throw FormatError("structured append tag must be first code word");
Expand Down