5

很少有 QR 编码器/解码器(显式)支持所谓的 GS1 编码。Zint是例外之一(在 QR 下选择 GS-1 数据模式),但它的许可证阻止我使用它。主要来自 Tec-It 的商业报价非常昂贵,特别是因为我对他们支持的所有其他类型的条形码不感兴趣。

有没有办法在不更改其源的情况下将 GS1 支持添加到任何 QR 编码器/解码器?例如,我可以应用一些算法将文本 GTIN AI 数据转换为兼容的二进制文件吗?我觉得应该是可以的,因为毕竟还是二维码。请注意,我不是数据编码专家——我只是在寻找一种方法来处理这个标准,而不用花一大笔钱。到目前为止,我发现确实支持它的postscriptbarcode,并且似乎使用它自己的 QR 引擎,但输出质量一般,而且我的 PostScript 技能太有限,无法弄清楚算法。

4

1 回答 1

6

只要库支持 FNC1 特殊字符的解码,就可以用来读取 GS1 码。FNC1 字符不是数据流中的一个字节,而更像是一个格式化符号。

规范说,前导 FNC1 字符用于识别 GS1 条码,应解码为"]d2"(GS1 DataMatrix)、"]C1"(GS1-128)、"]e0"(GS1 DataBar Omnidirectional) 或"]Q3"(GS1 QR Code)。任何其他 FNC1 字符都应解码为 ASCII GS 字符(字节值 29)。

根据库,前导 FNC1 可能丢失,或解码为GS(非关键),或者嵌入的 FNC1 字符可能丢失(关键)。嵌入的 FNC1 字符用于分隔可变长度字段。

您可以在此处阅读完整的规范(pdf)。解码数据的算法可在标题7.9 使用 GS1 应用标识符处理来自 GS1 符号系统的数据(第 426 页)下找到。

算法是这样的:

Peek at the first character.
If it is ']',
    If string does not start with ']C1' or ']e0' or ']d2' or ']Q3',
        Not a GS1 barcode.
        Stop.
    Consume the caracters.
Else if it is <GS>,
    Consume character.
Else,
    No symbology identifier, assume GS1.
While not end of input,
    Read the first two digits.
    If they are in the table of valid codes,
        Look up the length of the AI-code.
        Read the rest of the code.
        Look up the length of the field.
        If it is variable-length,
            Read until the next <FNC1> or <GS>.
        Else,
            Read the rest if the field.
        Peek at the next character.
        If it is <FNC1> or <GS>, consume it.
        Save the read field.
    Else,
        Error: Invalid AI

QR 码中的二进制数据被编码为 4 位令牌,并带有嵌入数据。

0111 -> Start Extended Channel Interpretation (ECI) Mode (special encodings).
0001, 0010, 0100, 1000 -> start numeric, alphanumeric, raw 8-bit, kanji encoded data.
0011 -> structured append (combine two or more QR Codes to one data-stream).
0101 -> FNC1 initial position.
1001 -> FNC1 other positions.
0000 -> End of stream (can be omitted if not enough space).

在编码规范之后是数据长度,然后是实际数据。数据位的含义取决于所使用的编码。在数据块之间,您可以压缩 FNC1 字符。

不幸的是,二维码规范 ( ISO/IEC 18004 ) 需要花钱 (210 法郎)。不过,您可能会在网上找到一些盗版版本。

要创建 GS1 二维码,您需要能够在数据中指定 FNC1 字符。该库应该识别“]Q3”前缀和 GS 字符,或者允许您通过其他方法编写 FNC1 令牌。

如果你有办法编写 FNC1 字符,你可以对 GS1 数据进行如下编码:

Write initial FNC1.
For each field,
    Write the AI-code as decimal digits.
    Write field data.
    If the code is a variable-length field,
        If not the last field,
            Write FNC1 to terminate the field.

如果可能,您应该对字段进行排序,使可变长度字段排在最后。


正如特里伯顿在评论中指出的那样;GS1 QR 码中的 FNC1 符号可以编码为%字母数字数据,也可以编码为 GS 字节模式。要编码一个实际的百分号,你可以把它写成%%.

要进行编码(01) 04912345123459 (15) 970331 (30) 128 (10) ABC123,首先将其组合到数据字符串中01049123451234591597033130128%10ABC123%指示符是编码的 FNC1 符号)。然后这个字符串写成

0101 - Initial FNC1, GS1 mode indicator
0001 - QR numeric mode
0000011101 - Data length (29)
<data bits for "01049123451234591597033130128">
0010 - QR alphanumeric mode
000001001 - Data length (9)
<data bits for "%10ABC123">

(来自 ISO 18004:2006 规范的示例)

于 2012-11-29T20:00:02.767 回答