Added hand-crafted example of kanji mode text encoding to C++, Java, Python demo programs.

This commit is contained in:
Project Nayuki 2017-04-21 16:59:13 +00:00
parent cfb4caa377
commit 88ad854fd3
3 changed files with 73 additions and 0 deletions

View File

@ -133,6 +133,23 @@ static void doSegmentDemo() {
segs.push_back(QrSegment::makeAlphanumeric(golden2));
const QrCode qr3 = QrCode::encodeSegments(segs, QrCode::Ecc::LOW);
printQr(qr3);
// Illustration "Madoka": kanji, kana, Greek, Cyrillic, full-width Latin characters
const char *madoka = "\xE3\x80\x8C\xE9\xAD\x94\xE6\xB3\x95\xE5\xB0\x91\xE5\xA5\xB3\xE3\x81\xBE\xE3\x81\xA9\xE3\x81\x8B\xE2\x98\x86\xE3\x83\x9E\xE3\x82\xAE\xE3\x82\xAB\xE3\x80\x8D\xE3\x81\xA3\xE3\x81\xA6\xE3\x80\x81\xE3\x80\x80\xD0\x98\xD0\x90\xD0\x98\xE3\x80\x80\xEF\xBD\x84\xEF\xBD\x85\xEF\xBD\x93\xEF\xBD\x95\xE3\x80\x80\xCE\xBA\xCE\xB1\xEF\xBC\x9F";
const QrCode qr4 = QrCode::encodeText(madoka, QrCode::Ecc::LOW);
printQr(qr4);
const std::vector<uint8_t> packedKanjiData{ // Kanji mode encoding (13 bits per character)
0x01, 0xAC, 0x00, 0x9F, 0x80, 0xAE, 0xD5, 0x6B, 0x85, 0x70,
0x28, 0xE1, 0x29, 0x02, 0xC8, 0x6F, 0x43, 0x1A, 0x18, 0xA0,
0x1B, 0x05, 0x04, 0x28, 0x80, 0x01, 0x00, 0x00, 0x92, 0x44,
0x80, 0x24, 0x90, 0x00, 0x04, 0x10, 0x20, 0xA1, 0x13, 0x08,
0xA8, 0x00, 0x04, 0x10, 0x1F, 0xF0, 0x04, 0x00,
};
segs.clear();
segs.push_back(QrSegment(QrSegment::Mode::KANJI, 29, packedKanjiData, 377));
const QrCode qr5 = QrCode::encodeSegments(segs, QrCode::Ecc::LOW);
printQr(qr5);
}

View File

@ -136,6 +136,22 @@ public final class QrCodeGeneratorDemo {
QrSegment.makeAlphanumeric(golden2));
qr = QrCode.encodeSegments(segs, QrCode.Ecc.LOW);
writePng(qr.toImage(8, 5), "phi-segmented-QR.png");
// Illustration "Madoka": kanji, kana, Greek, Cyrillic, full-width Latin characters
String madoka = "「魔法少女まどか☆マギカ」って、 ИАИ desu κα?";
qr = QrCode.encodeText(madoka, QrCode.Ecc.LOW);
writePng(qr.toImage(9, 4), "madoka-utf8-QR.png");
byte[] packedKanjiData = new byte[] { // Kanji mode encoding (13 bits per character)
(byte)0x01, (byte)0xAC, (byte)0x00, (byte)0x9F, (byte)0x80, (byte)0xAE, (byte)0xD5, (byte)0x6B, (byte)0x85, (byte)0x70,
(byte)0x28, (byte)0xE1, (byte)0x29, (byte)0x02, (byte)0xC8, (byte)0x6F, (byte)0x43, (byte)0x1A, (byte)0x18, (byte)0xA0,
(byte)0x1B, (byte)0x05, (byte)0x04, (byte)0x28, (byte)0x80, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x92, (byte)0x44,
(byte)0x80, (byte)0x24, (byte)0x90, (byte)0x00, (byte)0x04, (byte)0x10, (byte)0x20, (byte)0xA1, (byte)0x13, (byte)0x08,
(byte)0xA8, (byte)0x00, (byte)0x04, (byte)0x10, (byte)0x1F, (byte)0xF0, (byte)0x04, (byte)0x00,
};
segs = Arrays.asList(new QrSegment(QrSegment.Mode.KANJI, 29, packedKanjiData, 377));
qr = QrCode.encodeSegments(segs, QrCode.Ecc.LOW);
writePng(qr.toImage(9, 4), "madoka-kanji-QR.png");
}

View File

@ -106,6 +106,46 @@ def do_segment_demo():
qrcodegen.QrSegment.make_alphanumeric(golden2)]
qr = qrcodegen.QrCode.encode_segments(segs, qrcodegen.QrCode.Ecc.LOW)
print_qr(qr)
# Illustration "Madoka": kanji, kana, Greek, Cyrillic, full-width Latin characters
madoka = u"\u300C\u9B54\u6CD5\u5C11\u5973\u307E\u3069\u304B\u2606\u30DE\u30AE\u30AB\u300D\u3063\u3066\u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