diff --git a/src/include/espeak-ng/espeak_ng.h b/src/include/espeak-ng/espeak_ng.h index 7cb5db09..e6e6cb38 100644 --- a/src/include/espeak-ng/espeak_ng.h +++ b/src/include/espeak-ng/espeak_ng.h @@ -207,6 +207,7 @@ typedef enum ESPEAKNG_ENCODING_ISO_8859_15, ESPEAKNG_ENCODING_ISO_8859_16, ESPEAKNG_ENCODING_KOI8_R, + ESPEAKNG_ENCODING_ISCII, } espeak_ng_ENCODING; ESPEAK_NG_API espeak_ng_ENCODING diff --git a/src/libespeak-ng/encoding.c b/src/libespeak-ng/encoding.c index 8d18d1b7..8967404f 100644 --- a/src/libespeak-ng/encoding.c +++ b/src/libespeak-ng/encoding.c @@ -35,6 +35,7 @@ MNEM_TAB mnem_encoding[] = { { "ELOT_928", ESPEAKNG_ENCODING_ISO_8859_7 }, { "IBM367", ESPEAKNG_ENCODING_US_ASCII }, { "IBM819", ESPEAKNG_ENCODING_ISO_8859_1 }, + { "ISCII", ESPEAKNG_ENCODING_ISCII }, { "ISO_646.irv:1991", ESPEAKNG_ENCODING_US_ASCII }, { "ISO_8859-1", ESPEAKNG_ENCODING_ISO_8859_1 }, { "ISO_8859-1:1987", ESPEAKNG_ENCODING_ISO_8859_1 }, @@ -468,6 +469,26 @@ static const uint32_t KOI8_R[0x80] = { 0x0171, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0119, 0x021b, 0x00ff, // f8 }; +// Reference: http://varamozhi.sourceforge.net/iscii91.pdf +static const uint32_t ISCII[0x80] = { + 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // 80 + 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // 88 + 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // 90 + 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // 98 + 0xfffd, 0x0901, 0x0902, 0x0903, 0x0905, 0x0906, 0x0907, 0x0908, // a0 + 0x0909, 0x090a, 0x090b, 0x090e, 0x090f, 0x0910, 0x090d, 0x0912, // a8 + 0x0913, 0x0914, 0x0911, 0x0915, 0x0916, 0x0917, 0x0918, 0x0919, // b0 + 0x091a, 0x091b, 0x091c, 0x091d, 0x091e, 0x091f, 0x0920, 0x0921, // b8 + 0x0922, 0x0923, 0x0924, 0x0925, 0x0926, 0x0927, 0x0928, 0x0929, // c0 + 0x092a, 0x092b, 0x092c, 0x092d, 0x092e, 0x092f, 0x095f, 0x0930, // c8 + 0x0931, 0x0932, 0x0933, 0x0934, 0x0935, 0x0936, 0x0937, 0x0938, // d0 + 0x0939, 0x0020, 0x093e, 0x093f, 0x0940, 0x0941, 0x0942, 0x0943, // d8 + 0x0946, 0x0947, 0x0948, 0x0945, 0x094a, 0x094b, 0x094c, 0x0949, // e0 + 0x094d, 0x093c, 0x0964, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // e8 + 0x0020, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, // f0 + 0x0037, 0x0038, 0x0039, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // f8 +}; + static uint32_t string_decoder_getc_us_ascii(espeak_ng_TEXT_DECODER *decoder) { @@ -516,6 +537,7 @@ static const encoding_t string_decoders[] = { { string_decoder_getc_codepage, ISO_8859_15 }, { string_decoder_getc_codepage, ISO_8859_16 }, { string_decoder_getc_codepage, KOI8_R }, + { string_decoder_getc_codepage, ISCII }, }; espeak_ng_TEXT_DECODER * @@ -543,7 +565,7 @@ text_decoder_decode_string(espeak_ng_TEXT_DECODER *decoder, int length, espeak_ng_ENCODING encoding) { - if (encoding > ESPEAKNG_ENCODING_KOI8_R) + if (encoding > ESPEAKNG_ENCODING_ISCII) return ENS_UNKNOWN_TEXT_ENCODING; const encoding_t *enc = string_decoders + encoding; diff --git a/tests/encoding.c b/tests/encoding.c index a949551b..d896533e 100644 --- a/tests/encoding.c +++ b/tests/encoding.c @@ -117,6 +117,31 @@ test_koi8_r_encoding() destroy_text_decoder(decoder); } +void +test_iscii_encoding() +{ + printf("testing ISCII encoding\n"); + + assert(espeak_ng_EncodingFromName("ISCII") == ESPEAKNG_ENCODING_ISCII); + + espeak_ng_TEXT_DECODER *decoder = create_text_decoder(); + + assert(text_decoder_decode_string(decoder, "aG\x92\xA0\xE6", 5, ESPEAKNG_ENCODING_ISCII) == ENS_OK); + assert(text_decoder_eof(decoder) == 0); + assert(text_decoder_getc(decoder) == 'a'); + assert(text_decoder_eof(decoder) == 0); + assert(text_decoder_getc(decoder) == 'G'); + assert(text_decoder_eof(decoder) == 0); + assert(text_decoder_getc(decoder) == 0xfffd); + assert(text_decoder_eof(decoder) == 0); + assert(text_decoder_getc(decoder) == 0xfffd); + assert(text_decoder_eof(decoder) == 0); + assert(text_decoder_getc(decoder) == 0x094c); + assert(text_decoder_eof(decoder) == 1); + + destroy_text_decoder(decoder); +} + void test_iso_8859_1_encoding() { @@ -582,6 +607,7 @@ main(int argc, char **argv) test_us_ascii_encoding(); test_koi8_r_encoding(); + test_iscii_encoding(); test_iso_8859_1_encoding(); test_iso_8859_2_encoding();