X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fencoding.C;h=9c7b07d8184dc512e13990d559d54767caa9dbfc;hb=ce7c45bb437c44dae15f96148cb9b793ab0b895c;hp=129a29a03678ee249e4d04fd8dc07da9ddbd9101;hpb=2984f46a036bed8994ab43a386b4860985a15659;p=lyx.git diff --git a/src/encoding.C b/src/encoding.C index 129a29a036..9c7b07d818 100644 --- a/src/encoding.C +++ b/src/encoding.C @@ -1,322 +1,74 @@ -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor - * - * Copyright 1995 Matthias Ettrich - * Copyright 1995-2000 The LyX Team. +/** + * \file encoding.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * ====================================================== */ + * \author Lars Gullik Bjønnes + * \author Jean-Marc Lasgouttes + * \author Dekel Tsur + * + * Full author contact details are available in file CREDITS. + */ #include #include "encoding.h" -Uchar tab_iso8859_1[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, - 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff -}; +#include "debug.h" +#include "LaTeXFeatures.h" +#include "lyxlex.h" +#include "lyxrc.h" -Uchar tab_iso8859_2[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7, - 0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b, - 0x00b0, 0x0105, 0x02db, 0x0142, 0x00b4, 0x013e, 0x015b, 0x02c7, - 0x00b8, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c, - 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, - 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, - 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, - 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, - 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, - 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, - 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, - 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9 -}; - -Uchar tab_iso8859_3[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0x00a0, 0x0126, 0x02d8, 0x00a3, 0x00a4, 0xffff, 0x0124, 0x00a7, - 0x00a8, 0x0130, 0x015e, 0x011e, 0x0134, 0x00ad, 0xffff, 0x017b, - 0x00b0, 0x0127, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x0125, 0x00b7, - 0x00b8, 0x0131, 0x015f, 0x011f, 0x0135, 0x00bd, 0xffff, 0x017c, - 0x00c0, 0x00c1, 0x00c2, 0xffff, 0x00c4, 0x010a, 0x0108, 0x00c7, - 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, - 0xffff, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x0120, 0x00d6, 0x00d7, - 0x011c, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x016c, 0x015c, 0x00df, - 0x00e0, 0x00e1, 0x00e2, 0xffff, 0x00e4, 0x010b, 0x0109, 0x00e7, - 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, - 0xffff, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x0121, 0x00f6, 0x00f7, - 0x011d, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x016d, 0x015d, 0x02d9, -}; - -Uchar tab_iso8859_4[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0x00a0, 0x0104, 0x0138, 0x0156, 0x00a4, 0x0128, 0x013b, 0x00a7, - 0x00a8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00ad, 0x017d, 0x00af, - 0x00b0, 0x0105, 0x02db, 0x0157, 0x00b4, 0x0129, 0x013c, 0x02c7, - 0x00b8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014a, 0x017e, 0x014b, - 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, - 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x012a, - 0x0110, 0x0145, 0x014c, 0x0136, 0x00d4, 0x00d5, 0x00d6, 0x00d7, - 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x0168, 0x016a, 0x00df, - 0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f, - 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x012b, - 0x0111, 0x0146, 0x014d, 0x0137, 0x00f4, 0x00f5, 0x00f6, 0x00f7, - 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x0169, 0x016b, 0x02d9 -}; - -Uchar tab_iso8859_6_16[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666, 0x0667, - 0x0668, 0x0669, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x061f, - 0x0040, 0xfe80, 0xfe81, 0xfe83, 0xfe85, 0xfe87, 0xfe89, 0xfe8d, - 0xfe8f, 0xfe93, 0xfe95, 0xfe99, 0xfe9d, 0xfea1, 0xfea5, 0xfea9, - 0xfeab, 0xfead, 0xfeaf, 0xfeb1, 0xfeb5, 0xfeb9, 0xfebd, 0xfec1, - 0xfec5, 0xfec9, 0xfecd, 0x005d, 0x005c, 0x005b, 0x005e, 0x005f, - 0x0640, 0xfed1, 0xfed5, 0xfed9, 0xfedd, 0xfee1, 0xfee5, 0xfee9, - 0xfeed, 0xfeef, 0xfef1, 0x065b, 0x065c, 0x064d, 0x064e, 0x064f, - 0x0650, 0x0651, 0x0652, 0x0073, 0x0074, 0x0075, 0xfef5, 0xfef7, - 0xfef9, 0xfefb, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0xfe71, 0x0091, 0x0092, 0xfe77, 0xfe79, 0xfe7b, 0xfe7f, 0xfe7d, - 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, - 0xfe8c, 0xfe82, 0xfe84, 0xfe86, 0xfe88, 0xfe8e, 0xfeaa, 0xfeac, - 0xfeae, 0xfeb0, 0xfeee, 0xfef0, 0xfe91, 0xfe92, 0xfe90, 0xfe97, - 0xfe98, 0xfe94, 0xfe97, 0xfe98, 0xfe96, 0xfe9b, 0xfe9c, 0xfe9a, - 0xfe9f, 0xfea0, 0xfe9e, 0xfea3, 0xfea4, 0xfea2, 0xfea7, 0xfea8, - 0xfea6, 0xfeb3, 0xfeb4, 0xfeb2, 0xfeb7, 0xfeb8, 0xfeb6, 0xfebb, - 0xfebc, 0xfeba, 0xfebf, 0xfec0, 0xfebe, 0xfec3, 0xfec4, 0xfec2, - 0xfec7, 0xfec8, 0xfec6, 0xfecb, 0xfecc, 0xfeca, 0xfecf, 0xfed0, - 0xfece, 0xfed3, 0xfed4, 0xfed2, 0xfed7, 0xfed8, 0xfed6, 0xfedb, - 0xfedc, 0xfeda, 0xfedf, 0xfee0, 0xfede, 0xfee3, 0xfee4, 0xfee2, - 0xfee7, 0xfee8, 0xfee6, 0xfeeb, 0xfeec, 0xfeea, 0xfef3, 0xfef4, - 0xfef2, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, - 0xfe8b, 0xfe8a, 0xfef6, 0xfefa, 0xfef8, 0xfefc, 0x00fe, 0x00ff -}; - -Uchar tab_iso8859_7[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0x00a0, 0x0371, 0x0372, 0x00a3, 0xffff, 0xffff, 0x00a6, 0x00a7, - 0x00a8, 0x00a9, 0xffff, 0x00ab, 0x00ac, 0x00ad, 0xffff, 0x2015, - 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x03f3, 0x03f4, 0x0386, 0x00b7, - 0x0388, 0x0389, 0x038a, 0x00bb, 0x038c, 0x00bd, 0x038e, 0x038f, - 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, - 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, - 0x03a0, 0x03a1, 0xffff, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7, - 0x03a8, 0x03a9, 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af, - 0x03b0, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, - 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, - 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, - 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce, 0xffff -}; - -Uchar tab_iso8859_9[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, - 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, - 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, - 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, - 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, - 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, - 0x011e, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, - 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x0130, 0x015e, 0x00df, - 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, - 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, - 0x011f, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, - 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0131, 0x015f, 0x00ff, -}; - -Uchar tab_cp1255[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0x00a0, 0xffff, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, - 0x00a8, 0x00a9, 0x00d7, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x203e, - 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, - 0x00b8, 0x00b9, 0x00f7, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, - 0x05b0, 0x05b1, 0x05b2, 0x05b3, 0x05b4, 0x05b5, 0x05b6, 0x05b7, - 0x05b8, 0x05b9, 0xffff, 0x05bb, 0x05bc, 0x05bd, 0x05be, 0x05bf, - 0x05c0, 0x05c1, 0x05c2, 0x05c3, 0x05f0, 0x05f1, 0x05f2, 0x05f3, - 0x05f4, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0x05d0, 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, 0x05d6, 0x05d7, - 0x05d8, 0x05d9, 0x05da, 0x05db, 0x05dc, 0x05dd, 0x05de, 0x05df, - 0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, 0x05e6, 0x05e7, - 0x05e8, 0x05e9, 0x05ea, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff -}; - -Uchar tab_koi8[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x2500, 0x2502, 0x250c, 0x2510, 0x2514, 0x2518, 0x251c, 0x2524, - 0x252c, 0x2534, 0x253c, 0x2580, 0x2584, 0x2588, 0x258c, 0x2590, - 0x2591, 0x2592, 0x2593, 0x2320, 0x25a0, 0x2219, 0x221a, 0x2248, - 0x2264, 0x2265, 0x00a0, 0x2321, 0x00b0, 0x00b2, 0x00b7, 0x00f7, - 0x2550, 0x2551, 0x2552, 0x0451, 0x2553, 0x2554, 0x2555, 0x2556, - 0x2557, 0x2558, 0x2559, 0x255a, 0x255b, 0x255c, 0x255d, 0x255e, - 0x255f, 0x2560, 0x2561, 0x0401, 0x2562, 0x2563, 0x2564, 0x2565, - 0x2566, 0x2567, 0x2568, 0x2569, 0x256a, 0x256b, 0x256c, 0x00a9, - 0x044e, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, - 0x0445, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, - 0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, - 0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447, 0x044a, - 0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, - 0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, - 0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, - 0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a -}; +#include "support/filename.h" +#include "support/lstrings.h" +#include "support/unicode.h" -Uchar tab_symbol[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, +#include - 0x0020, 0x0021, 0x2200, 0x0023, 0x2203, 0x0025, 0x0026, 0x220b, - 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, +namespace lyx { -// 0x2245, 0x0391, 0x0392, 0x03a7, 0x0394, 0x0395, 0x03a6, 0x0393, -// 0x0397, 0x0399, 0x03d1, 0x039a, 0x039b, 0x039c, 0x039d, 0x039f, +using support::FileName; -// 0x03a0, 0x0398, 0x03a1, 0x03a3, 0x03a4, 0x03a5, 0x03c2, 0x03a9, -// 0x039e, 0x03a8, 0x0396, 0x005b, 0x2234, 0x005d, 0x22a5, 0xffff, - 0x2245, 0x0041, 0x0042, 0x0058, 0x0394, 0x0045, 0x03c2, 0x03a9, - 0x0048, 0x0049, 0x03d1, 0x004b, 0x039b, 0x004d, 0x004e, 0x004f, - - 0x03a0, 0x0398, 0x0050, 0x03a3, 0x0054, 0x0059, 0x03c2, 0x03a9, - 0x039e, 0x03a8, 0x005a, 0x005b, 0x2234, 0x005d, 0x22a5, 0xffff, - - 0xffff, 0x03b1, 0x03b2, 0x03c7, 0x03b4, 0x03b5, 0x03d5, 0x03b3, - 0x03b7, 0x03b9, 0x03c6, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03bf, - - 0x03c0, 0x03b8, 0x03c1, 0x03c3, 0x03c4, 0x03c5, 0x03d6, 0x03c9, - 0x03be, 0x03c8, 0x03b6, 0x007b, 0x007c, 0x007d, 0x007e, 0xffff, - - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - - 0xffff, 0x03d2, 0x2032, 0x2264, 0x2215, 0x221e, 0xffff, 0x2663, - 0x2666, 0x2665, 0x2660, 0x2194, 0x2190, 0x2191, 0x2192, 0x2193, - - 0x00b0, 0x00b1, 0x2033, 0x2265, 0x00d7, 0x221d, 0x2202, 0x2022, - 0x00f7, 0x2260, 0x2261, 0x2248, 0x22ef, 0xffff, 0xffff, 0x21b5, +#ifndef CXX_GLOBAL_CSTD +using std::strtol; +#endif - 0x2135, 0x2111, 0x211c, 0x2118, 0x2297, 0x2295, 0x2205, 0x2229, - 0x222a, 0x2283, 0x2287, 0x2284, 0x2282, 0x2286, 0x2208, 0x2209, +using std::endl; +using std::string; - 0x2220, 0x2207, 0x00ae, 0x00a9, 0x2122, 0x220f, 0x221a, 0x22c5, - 0x00ac, 0x2227, 0x2228, 0x21d4, 0x21d0, 0x21d1, 0x21d2, 0x21d3, - 0x2662, 0x2329, 0x00ae, 0x00a9, 0x2122, 0x2211, 0xffff, 0xffff, - 0xffff, 0x2308, 0xffff, 0x230a, 0xffff, 0xffff, 0xffff, 0xffff, +Encodings encodings; - 0xffff, 0x232a, 0x222b, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, - 0xffff, 0x2309, 0xffff, 0x230b, 0xffff, 0xffff, 0xffff, 0xffff -}; +namespace { -unsigned char arabic_table2[63][4] = { +char_type arabic_table2[63][4] = { {0x41, 0x41, 0x41, 0x41}, // 0xc1 = hamza - {0x42, 0xa1, 0x42, 0x42}, // 0xc2 = ligature madda on alef - {0x43, 0xa2, 0x43, 0x43}, // 0xc3 = ligature hamza on alef - {0x44, 0xa3, 0x44, 0x44}, // 0xc4 = ligature hamza on waw - {0x45, 0xa4, 0x45, 0x45}, // 0xc5 = ligature hamza under alef - {0xf9, 0xf9, 0xf8, 0xa0}, // 0xc6 = ligature hamza on ya - {0x47, 0xa5, 0xa5, 0xa5}, // 0xc7 = alef + {0x42, 0xa1, 0x42, 0xa1}, // 0xc2 = ligature madda on alef + {0x43, 0xa2, 0x43, 0xa2}, // 0xc3 = ligature hamza on alef + {0x44, 0xa3, 0x44, 0xa3}, // 0xc4 = ligature hamza on waw + {0x45, 0xa4, 0x45, 0xa4}, // 0xc5 = ligature hamza under alef + {0x46, 0xf9, 0xf8, 0xa0}, // 0xc6 = ligature hamza on ya + {0x47, 0xa5, 0x47, 0xa5}, // 0xc7 = alef {0x48, 0xae, 0xac, 0xad}, // 0xc8 = baa - {0x49, 0xb1, 0xaf, 0xb0}, // 0xc9 = taa marbuta + {0x49, 0xb1, 0x49, 0xb1}, // 0xc9 = taa marbuta {0x4a, 0xb4, 0xb2, 0xb3}, // 0xca = taa {0x4b, 0xb7, 0xb5, 0xb6}, // 0xcb = thaa {0x4c, 0xba, 0xb8, 0xb9}, // 0xcc = jeem {0x4d, 0xbd, 0xbb, 0xbc}, // 0xcd = haa {0x4e, 0xc0, 0xbe, 0xbf}, // 0xce = khaa - {0x4f, 0xa6, 0xa6, 0xa6}, // 0xcf = dal + {0x4f, 0xa6, 0x4f, 0xa6}, // 0xcf = dal - {0x50, 0xa7, 0xa7, 0xa7}, // 0xd0 = thal - {0x51, 0xa8, 0xa8, 0xa8}, // 0xd1 = ra - {0x52, 0xa9, 0xa9, 0xa9}, // 0xd2 = zain - {0x53, 0xc3, 0xc1, 0xc2}, // 0xd3 = seen + {0x50, 0xa7, 0x50, 0xa7}, // 0xd0 = thal + {0x51, 0xa8, 0x51, 0xa8}, // 0xd1 = ra + {0x52, 0xa9, 0x52, 0xa9}, // 0xd2 = zain + {0x53, 0xc3, 0xc1, 0xc2}, // 0xd3 = seen {0x54, 0xc6, 0xc4, 0xc5}, // 0xd4 = sheen - {0x55, 0xc9, 0xc7, 0xc8}, // 0xd5 = sad - {0x56, 0xcc, 0xca, 0xcb}, // 0xd6 = dad - {0x57, 0xcf, 0xcd, 0xce}, // 0xd7 = tah - {0x58, 0xd2, 0xd0, 0xd1}, // 0xd8 = zah - {0x59, 0xd5, 0xd3, 0xd4}, // 0xd9 = ain + {0x55, 0xc9, 0xc7, 0xc8}, // 0xd5 = sad + {0x56, 0xcc, 0xca, 0xcb}, // 0xd6 = dad + {0x57, 0xcf, 0xcd, 0xce}, // 0xd7 = tah + {0x58, 0xd2, 0xd0, 0xd1}, // 0xd8 = zah + {0x59, 0xd5, 0xd3, 0xd4}, // 0xd9 = ain {0x5a, 0xd8, 0xd6, 0xd7}, // 0xda = ghain {0,0,0,0}, // 0xdb {0,0,0,0}, // 0xdc @@ -324,17 +76,17 @@ unsigned char arabic_table2[63][4] = { {0,0,0,0}, // 0xde {0,0,0,0}, // 0xdf - {0,0,0,0}, // 0xe0 - {0x61, 0xdb, 0xd9, 0xda}, // 0xe1 = fa - {0x62, 0xde, 0xdc, 0xdd}, // 0xe2 = qaf - {0x63, 0xe1, 0xdf, 0xe0}, // 0xe3 = kaf - {0x64, 0xe4, 0xe2, 0xe3}, // 0xe4 = lam - {0x65, 0xe7, 0xe5, 0xe6}, // 0xe5 = meem - {0x66, 0xea, 0xe8, 0xe9}, // 0xe6 = noon - {0x67, 0xed, 0xeb, 0xec}, // 0xe7 = ha - {0x68, 0xaa, 0xaa, 0xaa}, // 0xe8 = waw - {0x69, 0xab, 0xab, 0xab}, // 0xe9 = alef maksura - {0x6a, 0xf0, 0xee, 0xef}, // 0xea = ya + {0,0,0,0}, // 0xe0 + {0x61, 0xdb, 0xd9, 0xda}, // 0xe1 = fa + {0x62, 0xde, 0xdc, 0xdd}, // 0xe2 = qaf + {0x63, 0xe1, 0xdf, 0xe0}, // 0xe3 = kaf + {0x64, 0xe4, 0xe2, 0xe3}, // 0xe4 = lam + {0x65, 0xe7, 0xe5, 0xe6}, // 0xe5 = meem + {0x66, 0xea, 0xe8, 0xe9}, // 0xe6 = noon + {0x67, 0xed, 0xeb, 0xec}, // 0xe7 = ha + {0x68, 0xaa, 0x68, 0xaa}, // 0xe8 = waw + {0x69, 0xab, 0x69, 0xab}, // 0xe9 = alef maksura + {0x6a, 0xf0, 0xee, 0xef}, // 0xea = ya {0x6b, 0x6b, 0x6b, 0x6b}, // 0xeb = fathatan {0x6c, 0x6c, 0x6c, 0x6c}, // 0xec = dammatan {0x6d, 0x6d, 0x6d, 0x6d}, // 0xed = kasratan @@ -359,7 +111,8 @@ unsigned char arabic_table2[63][4] = { {0,0,0,0}, // 0xff }; -unsigned char arabic_table[63][2] = { + +char_type arabic_table[63][2] = { {0xc1, 0xc1}, // 0xc1 = hamza {0xc2, 0xc2}, // 0xc2 = ligature madda on alef {0xc3, 0xc3}, // 0xc3 = ligature hamza on alef @@ -428,19 +181,288 @@ unsigned char arabic_table[63][2] = { {0,0} // 0xff }; -Encoding iso8859_1("latin1",tab_iso8859_1); -Encoding iso8859_2("latin2",tab_iso8859_2); -Encoding iso8859_3("latin3",tab_iso8859_3); -Encoding iso8859_4("latin4",tab_iso8859_4); -Encoding iso8859_6("unknown",tab_iso8859_6_16); -Encoding iso8859_7("unknown",tab_iso8859_7); -Encoding iso8859_9("latin5",tab_iso8859_9); -Encoding cp1255("cp1255",tab_cp1255); -Encoding koi8("koi8-r",tab_koi8); - - -#ifdef USE_UNICODE_FOR_SYMBOLS -Encoding symbol_encoding("",tab_symbol); -#else -Encoding symbol_encoding("",tab_iso8859_1); -#endif + +char_type const arabic_start = 0xc1; + + +/// Information about a single UCS4 character +struct CharInfo { + /// LaTeX command for this character + docstring command; + /// Needed LaTeX preamble (or feature) + string preamble; + /// Is this a combining character? + bool combining; + /// Is \c preamble a feature known by LaTeXFeatures, or a raw LaTeX + /// command? + bool feature; + /// Always force the LaTeX command, even if the encoding contains + /// this character? + bool force; +}; + + +typedef std::map CharInfoMap; +CharInfoMap unicodesymbols; + +} // namespace anon + + +Encoding::Encoding(string const & n, string const & l, string const & i) + : Name_(n), LatexName_(l), iconvName_(i) +{ + if (n == "utf8") + // UTF8 can encode all 1<<20 + 1<<16 UCS4 code points + start_encodable_ = 0x110000; + else { + start_encodable_ = 0; + // temporarily switch off lyxerr, since we will generate iconv errors + lyxerr.disable(); + for (unsigned short j = 0; j < 256; ++j) { + char const c = j; + std::vector const ucs4 = eightbit_to_ucs4(&c, 1, i); + if (ucs4.size() == 1) { + char_type const c = ucs4[0]; + CharInfoMap::const_iterator const it = unicodesymbols.find(c); + if (it == unicodesymbols.end() || !it->second.force) + encodable_.insert(c); + } + } + lyxerr.enable(); + CharSet::iterator it = encodable_.find(start_encodable_); + while (it != encodable_.end()) { + encodable_.erase(it); + ++start_encodable_; + it = encodable_.find(start_encodable_); + } + } +} + + +docstring const Encoding::latexChar(char_type c) const +{ + if (c < start_encodable_) + return docstring(1, c); + if (encodable_.find(c) == encodable_.end()) { + // c cannot be encoded in this encoding + CharInfoMap::const_iterator const it = unicodesymbols.find(c); + if (it == unicodesymbols.end()) + lyxerr << "Could not find LaTeX command for character 0x" + << std::hex << c << ".\nLaTeX export will fail." + << endl; + else + return it->second.command; + } + return docstring(1, c); +} + + +void Encoding::validate(char_type c, LaTeXFeatures & features) const +{ + if (c < start_encodable_) + return; + + if (encodable_.find(c) != encodable_.end()) + return; + + // c cannot be encoded in this encoding + CharInfoMap::const_iterator const it = unicodesymbols.find(c); + if (it != unicodesymbols.end() && !it->second.preamble.empty()) { + if (it->second.feature) + features.require(it->second.preamble); + else + features.addPreambleSnippet(it->second.preamble); + } +} + + +bool Encodings::isComposeChar_hebrew(char_type c) +{ + return c <= 0xd2 && c >= 0xc0 && + c != 0xce && c != 0xd0; +} + + +// Special Arabic letters are ones that do not get connected from left +// they are hamza, alef_madda, alef_hamza, waw_hamza, alef_hamza_under, +// alef, tah_marbota, dal, thal, rah, zai, wow, alef_maksoura + +bool Encodings::is_arabic_special(char_type c) +{ + return (c >= 0xc1 && c <= 0xc5) || + c == 0xc7 || c == 0xc9 || + c == 0xcf || c == 0xe8 || + (c >= 0xd0 && c <= 0xd2) || + c == 0xe9; +} + +bool Encodings::isComposeChar_arabic(char_type c) +{ + return c >= 0xeb && c <= 0xf2; +} + + +bool Encodings::is_arabic(char_type c) +{ + return c >= arabic_start && arabic_table[c-arabic_start][0]; +} + + +char_type Encodings::transformChar(char_type c, + Encodings::Letter_Form form) +{ + if (!is_arabic(c)) + return c; + + if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) + return arabic_table2[c-arabic_start][form]; + else + return arabic_table[c-arabic_start][form >> 1]; +} + + +bool Encodings::isCombiningChar(char_type c) +{ + CharInfoMap::const_iterator const it = unicodesymbols.find(c); + if (it != unicodesymbols.end()) + return it->second.combining; + return false; +} + + +Encoding const * Encodings::getFromLyXName(string const & name) const +{ + EncodingList::const_iterator it = encodinglist.find(name); + if (it != encodinglist.end()) + return &it->second; + else + return 0; +} + + +Encoding const * Encodings::getFromLaTeXName(string const & name) const +{ + // We don't use std::find_if because it makes copies of the pairs in + // the map. + // This linear search is OK since we don't have many encodings. + // Users could even optimize it by putting the encodings they use + // most at the top of lib/encodings. + EncodingList::const_iterator const end = encodinglist.end(); + for (EncodingList::const_iterator it = encodinglist.begin(); it != end; ++it) + if (it->second.latexName() == name) + return &it->second; + return 0; +} + + +Encodings::Encodings() +{ +} + + +void Encodings::read(FileName const & encfile, FileName const & symbolsfile) +{ + // We must read the symbolsfile first, because the Encoding + // constructor depends on it. + LyXLex symbolslex(0, 0); + symbolslex.setFile(symbolsfile); + while (symbolslex.isOK()) { + char_type symbol; + CharInfo info; + string flags; + + if (symbolslex.next(true)) { + std::istringstream is(symbolslex.getString()); + // reading symbol directly does not work if + // char_type == std::wchar_t. + boost::uint32_t tmp; + if(!(is >> std::hex >> tmp)) + break; + symbol = tmp; + } else + break; + if (symbolslex.next(true)) + info.command = symbolslex.getDocString(); + else + break; + if (symbolslex.next(true)) + info.preamble = symbolslex.getString(); + else + break; + if (symbolslex.next(true)) + flags = symbolslex.getString(); + else + break; + + info.combining = false; + info.force = false; + while (!flags.empty()) { + string flag; + flags = support::split(flags, flag, ','); + if (flag == "combining") + info.combining = true; + else if (flag == "force") + info.force = true; + else + lyxerr << "Ignoring unknown flag `" << flag + << "' for symbol `0x" << std::hex + << symbol << "'." << endl; + } + + if (!info.preamble.empty()) + info.feature = info.preamble[0] != '\\'; + + lyxerr[Debug::INFO] + << "Read unicode symbol " << symbol << " '" + << to_utf8(info.command) << "' '" << info.preamble + << "' " << info.combining << ' ' << info.feature + << endl; + unicodesymbols[symbol] = info; + } + + // Now read the encodings + enum Encodingtags { + et_encoding = 1, + et_end, + et_last + }; + + struct keyword_item encodingtags[et_last - 1] = { + { "encoding", et_encoding }, + { "end", et_end } + }; + + LyXLex lex(encodingtags, et_last - 1); + lex.setFile(encfile); + while (lex.isOK()) { + switch (lex.lex()) { + case et_encoding: + { + lex.next(); + string const name = lex.getString(); + lex.next(); + string const latexname = lex.getString(); + lex.next(); + string const iconvname = lex.getString(); + lyxerr[Debug::INFO] << "Reading encoding " << name << endl; + encodinglist[name] = Encoding(name, latexname, iconvname); + if (lex.lex() != et_end) + lex.printError("Encodings::read: " + "missing end"); + break; + } + case et_end: + lex.printError("Encodings::read: Misplaced end"); + break; + case LyXLex::LEX_FEOF: + break; + default: + lex.printError("Encodings::read: " + "Unknown tag: `$$Token'"); + break; + } + } +} + + +} // namespace lyx