DataFlex Requires Chilkat v11.7.0+
DataFlex
QR Code with Non-English Text (UTF-8 and ECI)
See more QR Code Examples
Demonstrates text outside ASCII. QrCode always stores text as UTF-8 bytes, which is what phones expect. A QR code can also say so explicitly with an ECI header: setting encoding.eci to 26 declares the bytes to be UTF-8, for readers that would otherwise assume another character set. The header costs a little space, and a few older readers do not understand it, so it is off by default.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Variant vSbText
Handle hoSbText
Variant vJson
Handle hoJson
Handle hoFmt
Variant vJsonOut
Handle hoJsonOut
String sTemp1
Integer iTemp1
Boolean bTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The text is "Gruesse aus Muenchen" written with u-umlaut and sharp s. It is given here with
// JSON escapes only so that this source is plain ASCII. Decode turns the escapes into characters.
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbText
If (Not(IsComObjectCreated(hoSbText))) Begin
Send CreateComObject of hoSbText
End
Get ComAppend Of hoSbText "Gr\u00fc\u00dfe aus M\u00fcnchen" To iSuccess
Get ComDecode Of hoSbText "json" "utf-8" To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get pvComObject of hoSbText to vSbText
Get ComUpdateSb Of hoJson "payload.text" vSbText To iSuccess
Get ComUpdateString Of hoJson "output.path" "qa_output/qr_utf8.png" To iSuccess
Get ComUpdateBool Of hoJson "output.overwrite" True To iSuccess
Get ComUpdateString Of hoJson "output.return" "none" To iSuccess
Get Create (RefClass(cComChilkatFormats)) To hoFmt
If (Not(IsComObjectCreated(hoFmt))) Begin
Send CreateComObject of hoFmt
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOut
If (Not(IsComObjectCreated(hoJsonOut))) Begin
Send CreateComObject of hoJsonOut
End
Get pvComObject of hoJson to vJson
Get pvComObject of hoJsonOut to vJsonOut
Get ComQrCode Of hoFmt "generate" vJson vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFmt To sTemp1
Showln sTemp1
Procedure_Return
End
// 17 characters, three of which take two bytes in UTF-8.
Get ComLength Of hoSbText To iTemp1
Showln "characters: " iTemp1
Get ComIntOf Of hoJsonOut "symbols[0].payloadBytes" To iTemp1
Showln "bytes encoded: " iTemp1
Get ComHasMember Of hoJsonOut "symbols[0].selectedEncoding.eci" To bTemp1
Showln "ECI header: " bTemp1
// Without an ECI header (qa_output/qr_utf8.png):
//
// The same text with an ECI header declaring UTF-8.
Get ComUpdateInt Of hoJson "encoding.eci" 26 To iSuccess
Get ComUpdateString Of hoJson "output.path" "qa_output/qr_utf8_eci.png" To iSuccess
Get pvComObject of hoJson to vJson
Get pvComObject of hoJsonOut to vJsonOut
Get ComQrCode Of hoFmt "generate" vJson vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFmt To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComHasMember Of hoJsonOut "symbols[0].selectedEncoding.eci" To bTemp1
Get ComIntOf Of hoJsonOut "symbols[0].selectedEncoding.eci" To iTemp1
Showln "with encoding.eci = 26, ECI header: " bTemp1 ", value " iTemp1
// With the ECI header (qa_output/qr_utf8_eci.png). Both scan as the same text:
//
// Sample output:
// characters: 17
// bytes encoded: 20
// ECI header: False
// with encoding.eci = 26, ECI header: True, value 26
End_Procedure