From 4d9e5057564863922cb14cef096e18e93b9d2509 Mon Sep 17 00:00:00 2001 From: Adam Kisiel Date: Thu, 16 Aug 2001 13:33:43 +0000 Subject: [PATCH] displaying ISO characters in TTFs - needed for Polish translation of documentation SVN revision: 5180 --- dox/dox.h | 7 +++ dox/ttfont.c | 119 +++++++++++++++++++++++++++++++++++++++++++++------ src/E.h | 7 +++ src/ttfont.c | 119 +++++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 226 insertions(+), 26 deletions(-) diff --git a/dox/dox.h b/dox/dox.h index 691fe6a3..0f7f2f97 100644 --- a/dox/dox.h +++ b/dox/dox.h @@ -71,6 +71,12 @@ #define MAX(a,b) ((a)>(b)?(a):(b)) #endif +/* ISO encodings */ +#define ENCOING_ISO_8859_1 0 +#define ENCOING_ISO_8859_2 1 +#define ENCOING_ISO_8859_3 2 +#define ENCOING_ISO_8859_4 3 + #define Esetenv(var, val, overwrite) \ { \ static char envvar[1024]; \ @@ -87,6 +93,7 @@ typedef struct _efont int num_glyph; TT_Glyph *glyphs; TT_Raster_Map **glyphs_cached; + TT_CharMap char_map; int max_descent; int max_ascent; } diff --git a/dox/ttfont.c b/dox/ttfont.c index a7749d8f..be285a1a 100644 --- a/dox/ttfont.c +++ b/dox/ttfont.c @@ -39,6 +39,96 @@ static unsigned char alpha_lut[5] = static unsigned char bounded_palette[9] = {0, 1, 2, 3, 4, 4, 4, 4, 4}; +struct _imlib_encoding_map { + unsigned short char_map[96]; +}; + +typedef struct _imlib_encoding_map ImlibEncodingMap ; + +/* Encoding maps */ +static const ImlibEncodingMap iso1 = +{ + /* ISO-8859-1 encoding (conversion to UTF-8) */ + 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, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7, 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF +}; + +static const ImlibEncodingMap iso2 = +{ + /* ISO-8859-2 encoding (conversion to UTF-8) */ + 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 +}; + +static const ImlibEncodingMap iso3 = +{ + /* ISO-8859-3 encoding (conversion to UTF-8) */ + 0x00A0, 0x0126, 0x02D8, 0x00A3, 0x00A4, 0x0124, 0x00A7, 0x00A8, 0x0130, 0x015E, 0x011E, 0x0134, 0x00AD, 0x017B, 0x00B0, 0x0127, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x0125, 0x00B7, 0x00B8, 0x0131, 0x015F, 0x011F, 0x0135, 0x00BD, 0x017C, 0x00C0, 0x00C1, 0x00C2, 0x00C4, 0x010A, 0x0108, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x0120, 0x00D6, 0x00D7, 0x011C, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x016C, 0x015C, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E4, 0x010B, 0x0109, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x0121, 0x00F6, 0x00F7, 0x011D, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x016D, 0x015D, 0x02D9 +}; + +static const ImlibEncodingMap iso4 = +{ + /* ISO-8859-4 encoding (conversion to UTF-8) */ + 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 +}; + +static const ImlibEncodingMap iso5 = +{ + /* ISO-8859-5 encoding (conversion to UTF-8) */ + 0x00A0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040A, 0x040B, 0x040C, 0x00AD, 0x040E, 0x040F, 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F, 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F, 0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, 0x0458, 0x0459, 0x045A, 0x045B, 0x045C, 0x00A7, 0x045E, 0x045F +}; + +static const ImlibEncodingMap* _imlib_encodings[5] = { &iso1, &iso2, &iso3, &iso4, &iso5 }; +int IsoEncoding = ENCOING_ISO_8859_1; +char encoding_initialized = 0; + +void +__init_iso_encoding() +{ + /* Set the current ISO encoding based on (in that order): + * the "IMLIB_ENCODING" environment variable, + * the "LANG" variable, + * the ISO-8859-1 default */ + + char *s, *enc_num, *lang; + char iso2lang[21] = "cs hu pl ro hr sk sl"; + char iso3lang[6] = "eo mt"; + char iso4lang[12] = "et lv lt kl"; + char iso5lang[18] = "bg be mk ru sr uk"; + + /* Check if we already initialized the encoding */ + if (!encoding_initialized) + { + IsoEncoding = 255; + /* First check if we have IMLIB_ENCODING variable set */ + if ((s = getenv("IMLIB_ENCODING")) != NULL) + { + if ((enc_num = strstr(s, "8859-")) != NULL) + { + if (!strcmp((enc_num+5), "1")) IsoEncoding = 0; + else if (!strcmp((enc_num+5), "2")) IsoEncoding = 1; + else if (!strcmp((enc_num+5), "3")) IsoEncoding = 2; + else if (!strcmp((enc_num+5), "4")) IsoEncoding = 3; + else if (!strcmp((enc_num+5), "5")) IsoEncoding = 4; + } + } + if (IsoEncoding == 255) + { + /* Still not initialized - try to guess from LANG variable */ + if ((lang = getenv("LANG")) != NULL) + { + if (strstr(iso2lang, lang) != NULL) IsoEncoding = 1; + else if (strstr(iso3lang, lang) != NULL) IsoEncoding = 2; + else if (strstr(iso4lang, lang) != NULL) IsoEncoding = 3; + else if (strstr(iso5lang, lang) != NULL) IsoEncoding = 4; + } + } + if (IsoEncoding == 255) { + /* Still not initialized - default to ISO8859-1 */ + IsoEncoding = 0; + } + encoding_initialized = 1; + } +} + static TT_Raster_Map * create_font_raster(int width, int height) { @@ -99,7 +189,7 @@ calc_size(Efont * f, int *width, int *height, char *text) for (i = 0; text[i]; i++) { - unsigned char j = text[i]; + unsigned char j = text[i]; if (!TT_VALID(f->glyphs[j])) continue; @@ -133,7 +223,7 @@ render_text(TT_Raster_Map * rmap, TT_Raster_Map * rchr, Efont * f, char *text, int i, ioff, iread; char *off, *read, *_off, *_read; int x_offset, y_offset; - unsigned char j; + unsigned char j; TT_Raster_Map *rtmp; TT_Get_Instance_Metrics(f->instance, &imetrics); @@ -150,8 +240,7 @@ render_text(TT_Raster_Map * rmap, TT_Raster_Map * rchr, Efont * f, char *text, rtmp = NULL; for (i = 0; text[i]; i++) { - j = text[i]; - + j = text[i]; if (!TT_VALID(f->glyphs[j])) continue; @@ -712,16 +801,16 @@ Efont * Efont_load(char *file, int size) { TT_Error error; - TT_CharMap char_map; TT_Glyph_Metrics metrics; static TT_Engine engine; static char have_engine = 0; int dpi = 96; Efont *f; - unsigned short i, n, code, load_flags; + unsigned short i, n, index, load_flags; unsigned short num_glyphs = 0, no_cmap = 0; unsigned short platform, encoding; + __init_iso_encoding(); if (!have_engine) { error = TT_Init_FreeType(&engine); @@ -765,7 +854,8 @@ Efont_load(char *file, int size) if ((platform == 3 && encoding == 1) || (platform == 0 && encoding == 0)) { - TT_Get_CharMap(f->face, i, &char_map); + // TT_Get_CharMap(f->face, i, &char_map); + TT_Get_CharMap(f->face, i, &(f->char_map)); break; } } @@ -797,15 +887,18 @@ Efont_load(char *file, int size) if (no_cmap) { - code = (i - ' ' + 1) < 0 ? 0 : (i - ' ' + 1); - if (code >= num_glyphs) - code = 0; + index = (i - ' ' + 1) < 0 ? 0 : (i - ' ' + 1); + if (index >= num_glyphs) + index = 0; } else - code = TT_Char_Index(char_map, i); + if (i < 0xA0 ) + index = TT_Char_Index(f->char_map, i); + else + index = TT_Char_Index(f->char_map, _imlib_encodings[IsoEncoding]->char_map[(i - 0xA0)]); TT_New_Glyph(f->face, &f->glyphs[i]); - TT_Load_Glyph(f->instance, f->glyphs[i], code, load_flags); + TT_Load_Glyph(f->instance, f->glyphs[i], index, load_flags); TT_Get_Glyph_Metrics(f->glyphs[i], &metrics); if ((metrics.bbox.yMin & -64) < f->max_descent) @@ -841,7 +934,7 @@ Efont_extents(Efont * f, char *text, int *font_ascent_return, for (i = 0; text[i]; i++) { - unsigned char j = text[i]; + unsigned char j = text[i]; if (!TT_VALID(f->glyphs[j])) continue; diff --git a/src/E.h b/src/E.h index ab564a6c..9cbd4916 100644 --- a/src/E.h +++ b/src/E.h @@ -540,6 +540,12 @@ int Esnprintf(va_alist); #define SET_ON 1 #define SET_TOGGLE 2 +/* ISO encodings */ +#define ENCOING_ISO_8859_1 0 +#define ENCOING_ISO_8859_2 1 +#define ENCOING_ISO_8859_3 2 +#define ENCOING_ISO_8859_4 3 + typedef struct _menu Menu; typedef struct _dialog Dialog; typedef struct _pager Pager; @@ -678,6 +684,7 @@ typedef struct _efont int num_glyph; TT_Glyph *glyphs; TT_Raster_Map **glyphs_cached; + TT_CharMap char_map; int max_descent; int max_ascent; } diff --git a/src/ttfont.c b/src/ttfont.c index 6a92379c..adf56741 100644 --- a/src/ttfont.c +++ b/src/ttfont.c @@ -36,6 +36,96 @@ struct _efont_color_tab static unsigned char alpha_lut[5] = { 0, 64, 128, 192, 255 }; static unsigned char bounded_palette[9] = { 0, 1, 2, 3, 4, 4, 4, 4, 4 }; +struct _imlib_encoding_map { + unsigned short char_map[96]; +}; + +typedef struct _imlib_encoding_map ImlibEncodingMap ; + +/* Encoding maps */ +static const ImlibEncodingMap iso1 = +{ + /* ISO-8859-1 encoding (conversion to UTF-8) */ + 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, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7, 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF +}; + +static const ImlibEncodingMap iso2 = +{ + /* ISO-8859-2 encoding (conversion to UTF-8) */ + 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 +}; + +static const ImlibEncodingMap iso3 = +{ + /* ISO-8859-3 encoding (conversion to UTF-8) */ + 0x00A0, 0x0126, 0x02D8, 0x00A3, 0x00A4, 0x0124, 0x00A7, 0x00A8, 0x0130, 0x015E, 0x011E, 0x0134, 0x00AD, 0x017B, 0x00B0, 0x0127, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x0125, 0x00B7, 0x00B8, 0x0131, 0x015F, 0x011F, 0x0135, 0x00BD, 0x017C, 0x00C0, 0x00C1, 0x00C2, 0x00C4, 0x010A, 0x0108, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x0120, 0x00D6, 0x00D7, 0x011C, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x016C, 0x015C, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E4, 0x010B, 0x0109, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x0121, 0x00F6, 0x00F7, 0x011D, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x016D, 0x015D, 0x02D9 +}; + +static const ImlibEncodingMap iso4 = +{ + /* ISO-8859-4 encoding (conversion to UTF-8) */ + 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 +}; + +static const ImlibEncodingMap iso5 = +{ + /* ISO-8859-5 encoding (conversion to UTF-8) */ + 0x00A0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040A, 0x040B, 0x040C, 0x00AD, 0x040E, 0x040F, 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F, 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F, 0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, 0x0458, 0x0459, 0x045A, 0x045B, 0x045C, 0x00A7, 0x045E, 0x045F +}; + +static const ImlibEncodingMap* _imlib_encodings[5] = { &iso1, &iso2, &iso3, &iso4, &iso5 }; +int IsoEncoding = ENCOING_ISO_8859_1; +char encoding_initialized = 0; + +void +__init_iso_encoding() +{ + /* Set the current ISO encoding based on (in that order): + * the "IMLIB_ENCODING" environment variable, + * the "LANG" variable, + * the ISO-8859-1 default */ + + char *s, *enc_num, *lang; + char iso2lang[21] = "cs hu pl ro hr sk sl"; + char iso3lang[6] = "eo mt"; + char iso4lang[12] = "et lv lt kl"; + char iso5lang[18] = "bg be mk ru sr uk"; + + /* Check if we already initialized the encoding */ + if (!encoding_initialized) + { + IsoEncoding = 255; + /* First check if we have IMLIB_ENCODING variable set */ + if ((s = getenv("IMLIB_ENCODING")) != NULL) + { + if ((enc_num = strstr(s, "8859-")) != NULL) + { + if (!strcmp((enc_num+5), "1")) IsoEncoding = 0; + else if (!strcmp((enc_num+5), "2")) IsoEncoding = 1; + else if (!strcmp((enc_num+5), "3")) IsoEncoding = 2; + else if (!strcmp((enc_num+5), "4")) IsoEncoding = 3; + else if (!strcmp((enc_num+5), "5")) IsoEncoding = 4; + } + } + if (IsoEncoding == 255) + { + /* Still not initialized - try to guess from LANG variable */ + if ((lang = getenv("LANG")) != NULL) + { + if (strstr(iso2lang, lang) != NULL) IsoEncoding = 1; + else if (strstr(iso3lang, lang) != NULL) IsoEncoding = 2; + else if (strstr(iso4lang, lang) != NULL) IsoEncoding = 3; + else if (strstr(iso5lang, lang) != NULL) IsoEncoding = 4; + } + } + if (IsoEncoding == 255) { + /* Still not initialized - default to ISO8859-1 */ + IsoEncoding = 0; + } + encoding_initialized = 1; + } +} + static TT_Raster_Map * create_font_raster(int width, int height) { @@ -109,7 +199,7 @@ calc_size(Efont * f, int *width, int *height, char *text) for (i = 0; text[i]; i++) { - unsigned char j = text[i]; + unsigned char j = text[i]; if (!TT_VALID(f->glyphs[j])) continue; @@ -143,7 +233,7 @@ render_text(TT_Raster_Map * rmap, TT_Raster_Map * rchr, Efont * f, char *text, int i, ioff, iread; char *off, *read, *_off, *_read; int x_offset, y_offset; - unsigned char j; + unsigned char j; TT_Raster_Map *rtmp; TT_Get_Instance_Metrics(f->instance, &imetrics); @@ -160,8 +250,7 @@ render_text(TT_Raster_Map * rmap, TT_Raster_Map * rchr, Efont * f, char *text, rtmp = NULL; for (i = 0; text[i]; i++) { - j = text[i]; - + j = text[i]; if (!TT_VALID(f->glyphs[j])) continue; @@ -761,16 +850,16 @@ Efont * Efont_load(char *file, int size) { TT_Error error; - TT_CharMap char_map; TT_Glyph_Metrics metrics; static TT_Engine engine; static char have_engine = 0; int dpi = 96; Efont *f; - unsigned short i, n, code, load_flags; + unsigned short i, n, index, load_flags; unsigned short num_glyphs = 0, no_cmap = 0; unsigned short platform, encoding; + __init_iso_encoding(); if (!have_engine) { error = TT_Init_FreeType(&engine); @@ -814,7 +903,8 @@ Efont_load(char *file, int size) if ((platform == 3 && encoding == 1) || (platform == 0 && encoding == 0)) { - TT_Get_CharMap(f->face, i, &char_map); + // TT_Get_CharMap(f->face, i, &char_map); + TT_Get_CharMap(f->face, i, &(f->char_map)); break; } } @@ -846,15 +936,18 @@ Efont_load(char *file, int size) if (no_cmap) { - code = (i - ' ' + 1) < 0 ? 0 : (i - ' ' + 1); - if (code >= num_glyphs) - code = 0; + index = (i - ' ' + 1) < 0 ? 0 : (i - ' ' + 1); + if (index >= num_glyphs) + index = 0; } else - code = TT_Char_Index(char_map, i); + if (i < 0xA0 ) + index = TT_Char_Index(f->char_map, i); + else + index = TT_Char_Index(f->char_map, _imlib_encodings[IsoEncoding]->char_map[(i - 0xA0)]); TT_New_Glyph(f->face, &f->glyphs[i]); - TT_Load_Glyph(f->instance, f->glyphs[i], code, load_flags); + TT_Load_Glyph(f->instance, f->glyphs[i], index, load_flags); TT_Get_Glyph_Metrics(f->glyphs[i], &metrics); if ((metrics.bbox.yMin & -64) < f->max_descent) @@ -890,7 +983,7 @@ Efont_extents(Efont * f, char *text, int *font_ascent_return, for (i = 0; text[i]; i++) { - unsigned char j = text[i]; + unsigned char j = text[i]; if (!TT_VALID(f->glyphs[j])) continue;