diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_compose.cxx | 16 | ||||
| -rw-r--r-- | src/Makefile | 4 | ||||
| -rw-r--r-- | src/fl_encoding_latin1.cxx | 136 | ||||
| -rw-r--r-- | src/fl_encoding_mac_roman.cxx | 133 | ||||
| -rw-r--r-- | src/fl_font_mac.cxx | 57 | ||||
| -rw-r--r-- | src/gl_draw.cxx | 9 | ||||
| -rw-r--r-- | src/makefile.wat | 2 |
7 files changed, 290 insertions, 67 deletions
diff --git a/src/Fl_compose.cxx b/src/Fl_compose.cxx index f05e6bc1f..29a820d12 100644 --- a/src/Fl_compose.cxx +++ b/src/Fl_compose.cxx @@ -26,6 +26,7 @@ // #include <FL/Fl.H> +#include <stdio.h> // // MRS: Uncomment the following define to get the original (pre-1.1.2) @@ -37,6 +38,7 @@ static const char* const compose_pairs = +"=E _'f _\"..+ ++^ %%^S< OE ^Z ^''^^\"\"^-*- --~ TM^s> oe ^z:Y" " ! % # $ y=| & : c a <<~ - r _ * +-2 3 ' u p . , 1 o >>141234? " "`A'A^A~A:A*AAE,C`E'E^E:E`I'I^I:I-D~N`O'O^O~O:Ox O/`U'U^U:U'YTHss" "`a'a^a~a:a*aae,c`e'e^e:e`i'i^i:i-d~n`o'o^o~o:o-:o/`u'u^u:u'yth:y"; @@ -90,7 +92,11 @@ int Fl::compose(int& del) { if (compose_state == 1) { // after the compose key if (ascii == ' ') { // space turns into nbsp +#ifdef __APPLE__ + e_text[0] = char(0xCA); +#else e_text[0] = char(0xA0); +#endif compose_state = 0; return 1; } else if (ascii < ' ' || ascii == 127) { @@ -101,7 +107,7 @@ int Fl::compose(int& del) { // see if it is either character of any pair: for (const char *p = compose_pairs; *p; p += 2) if (p[0] == ascii || p[1] == ascii) { - if (p[1] == ' ') e_text[0] = (p-compose_pairs)/2+0xA0; + if (p[1] == ' ') e_text[0] = (p-compose_pairs)/2+0x80; compose_state = ascii; return 1; } @@ -117,7 +123,7 @@ int Fl::compose(int& del) { // now search for the pair in either order: for (const char *p = compose_pairs; *p; p += 2) { if (p[0] == ascii && p[1] == c1 || p[1] == ascii && p[0] == c1) { - e_text[0] = (p-compose_pairs)/2+0xA0; + e_text[0] = (p-compose_pairs)/2+0x80; del = 1; // delete the old character and insert new one compose_state = 0; return 1; @@ -134,7 +140,9 @@ int Fl::compose(int& del) { return 1; } -#ifndef WIN32 // X only +#ifdef WIN32 +//#elif (defined __APPLE__) +#else // See if they typed a dead key. This gets it into the same state as // typing prefix+accent: if (i >= 0xfe50 && i <= 0xfe5b) { @@ -149,7 +157,7 @@ int Fl::compose(int& del) { ascii = e_text[0]; for (const char *p = compose_pairs; *p; p += 2) if (p[0] == ascii || - (p[1] == ' ' && (p - compose_pairs) / 2 + 0xA0 == ascii)) { + (p[1] == ' ' && (p - compose_pairs) / 2 + 0x80 == ascii)) { compose_state = p[0]; return 1; } diff --git a/src/Makefile b/src/Makefile index 52af2cd07..8a1e331c7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -128,6 +128,8 @@ CPPFILES = \ fl_draw.cxx \ fl_draw_image.cxx \ fl_draw_pixmap.cxx \ + fl_encoding_latin1.cxx \ + fl_encoding_mac_roman.cxx \ fl_engraved_label.cxx \ fl_file_dir.cxx \ fl_font.cxx \ @@ -427,6 +429,8 @@ fl_draw_image.o: ../FL/mac.H ../FL/win32.H fl_draw_image_mac.o: ../FL/mac.H ../FL/win32.H fl_draw_image_win32.o: ../FL/mac.H ../FL/win32.H fl_draw_pixmap.o: ../FL/mac.H ../FL/win32.H +fl_encoding_latin1.o: ../FL/mac.H ../FL/win32.H +fl_encoding_mac_roman.o: ../FL/mac.H ../FL/win32.H Fl_File_Chooser2.o: ../FL/mac.H ../FL/win32.H fl_font.o: ../FL/mac.H ../FL/win32.H Fl_get_key.o: ../FL/mac.H ../FL/win32.H diff --git a/src/fl_encoding_latin1.cxx b/src/fl_encoding_latin1.cxx new file mode 100644 index 000000000..a0115199d --- /dev/null +++ b/src/fl_encoding_latin1.cxx @@ -0,0 +1,136 @@ +// +// "$Id: $" +// +// Convert MSWindows-1252 (Latin-1) encoded text to the local encoding. +// +// Copyright 1998-2006 by Bill Spitzak and others. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +#include <FL/fl_draw.h> +#include <stdlib.h> +#include "flstring.h" + +// These function assume a western code page. If you need to support +// scripts that are not part of this code page, you might want to +// take a look at FLTK2, which uses utf8 for text encoding. +// +// By keeping these conversion tables in their own module, they will not +// be statically linked (by a smart linker) unless actually used. +// +// On MS-Windows, nothing need to be converted. We simply return the +// original pointer. +// +// Most X11 implementations seem to default to Latin-1 as a code since it +// is a superset of ISO 8859-1, the original wetsern codepage on X11. +// +// Apple's OS X however renders text in MacRoman for western settings. The +// lookup tables below will convert all common character codes and replace +// unknown characters with an upsidedown question mark. + +// This table converts MSWindows-1252/Latin 1 into MacRoman encoding +static uchar latin2roman[256] = { +0xdb, 0xc0, 0xe2, 0xc4, 0xe3, 0xc9, 0xa0, 0xe0, 0xf6, 0xe4, 0xc0, 0xdc, 0xce, 0xc0, 0xc0, 0xc0, +0xc0, 0xd4, 0xd5, 0xd2, 0xd3, 0xa5, 0xd0, 0xd1, 0xf7, 0xaa, 0xc0, 0xdd, 0xcf, 0xc0, 0xc0, 0xd9, +0xca, 0xc1, 0xa2, 0xa3, 0xc0, 0xb4, 0xc0, 0xa4, 0xac, 0xa9, 0xbb, 0xc7, 0xc2, 0xc0, 0xa8, 0xf8, +0xa1, 0xb1, 0xc0, 0xc0, 0xab, 0xb5, 0xa6, 0xe1, 0xfc, 0xc0, 0xbc, 0xc8, 0xc0, 0xc0, 0xc0, 0xc0, +0xcb, 0xe7, 0xe5, 0xcc, 0x80, 0x81, 0xae, 0x82, 0xe9, 0x83, 0xe6, 0xe8, 0xed, 0xea, 0xeb, 0xec, +0xc0, 0x84, 0xf1, 0xee, 0xef, 0xcd, 0x85, 0xc0, 0xaf, 0xf4, 0xf2, 0xf3, 0x86, 0xc0, 0xc0, 0xa7, +0x88, 0x87, 0x89, 0x8b, 0x8a, 0x8c, 0xbe, 0x8d, 0x8f, 0x8e, 0x90, 0x91, 0x93, 0x92, 0x94, 0x95, +0xc0, 0x96, 0x98, 0x97, 0x99, 0x9b, 0x9a, 0xd6, 0xbf, 0x9d, 0x9c, 0x9e, 0x9f, 0xc0, 0xc0, 0xd8 +}; + +// This table converts MacRoman into MSWindows-1252/Latin 1 +static uchar roman2latin[256] = { +0xc4, 0xc5, 0xc7, 0xc9, 0xd1, 0xd6, 0xdc, 0xe1, 0xe0, 0xe2, 0xe4, 0xe3, 0xe5, 0xe7, 0xe9, 0xe8, +0xea, 0xeb, 0xed, 0xec, 0xee, 0xef, 0xf1, 0xf3, 0xf2, 0xf4, 0xf6, 0xf5, 0xfa, 0xf9, 0xfb, 0xfc, +0x86, 0xb0, 0xa2, 0xa3, 0xa7, 0x95, 0xb6, 0xdf, 0xae, 0xa9, 0x99, 0xb4, 0xa8, 0xbf, 0xc6, 0xd8, +0xbf, 0xb1, 0xbf, 0xbf, 0xa5, 0xb5, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xaa, 0xba, 0xbf, 0xe6, 0xf8, +0xbf, 0xa1, 0xac, 0xbf, 0x83, 0xbf, 0xbf, 0xab, 0xbb, 0x85, 0xa0, 0xc0, 0xc3, 0xd5, 0x8c, 0x9c, +0x96, 0x97, 0x93, 0x94, 0x91, 0x92, 0xf7, 0xbf, 0xff, 0x9f, 0xbf, 0x80, 0x8b, 0x9b, 0xbf, 0xbf, +0x87, 0xb7, 0x82, 0x84, 0x89, 0xc2, 0xca, 0xc1, 0xcb, 0xc8, 0xcd, 0xce, 0xcf, 0xcc, 0xd3, 0xd4, +0xbf, 0xd2, 0xda, 0xdb, 0xd9, 0xbf, 0x88, 0x98, 0xaf, 0xbf, 0xbf, 0xbf, 0xb8, 0xbf, 0xbf, 0xbf +}; + +static char *buf = 0; +static int n_buf = 0; + +#ifdef __APPLE__ + +const char *fl_latin1_to_local(const char *t, int n) +{ + if (n==-1) n = strlen(t); + if (n<=n_buf) { + n_buf = (n + 257) & 0x7fffff00; + if (buf) free(buf); + buf = (char*)malloc(n_buf); + } + const uchar *src = (const uchar*)t; + uchar *dst = (uchar*)buf; + for ( ; n>0; n--) { + uchar c = *src; + if (c>127) + *dst = latin2roman[c-128]; + else + *dst = c; + } + //*dst = 0; // this would be wrong! + return buf; +} + +const char *fl_local_to_latin1(const char *t, int n) +{ + if (n==-1) n = strlen(t); + if (n<=n_buf) { + n_buf = (n + 257) & 0x7fffff00; + if (buf) free(buf); + buf = (char*)malloc(n_buf); + } + const uchar *src = (const uchar*)t; + uchar *dst = (uchar*)buf; + for ( ; n>0; n--) { + uchar c = *src++; + if (c>127) + *dst++ = roman2latin[c-128]; + else + *dst++ = c; + } + //*dst = 0; // this would be wrong + return buf; +} + +#else + +const char *fl_latin1_to_local(const char *t, int) +{ + return t; +} + +const char *fl_local_to_latin1(const char *t, int) +{ + return t; +} + +#endif + +// +// End of "$Id: $". +// diff --git a/src/fl_encoding_mac_roman.cxx b/src/fl_encoding_mac_roman.cxx new file mode 100644 index 000000000..bc176e93e --- /dev/null +++ b/src/fl_encoding_mac_roman.cxx @@ -0,0 +1,133 @@ +// +// "$Id: $" +// +// Convert Mac Roman encoded text to the local encoding. +// +// Copyright 1998-2006 by Bill Spitzak and others. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +#include <FL/fl_draw.h> +#include <stdlib.h> +#include "flstring.h" + +// These function assume a western code page. If you need to support +// scripts that are not part of this code page, you might want to +// take a look at FLTK2, which uses utf8 for text encoding. +// +// By keeping these conversion tables in their own module, they will not +// be statically linked (by a smart linker) unless actually used. +// +// On Mac OS X, nothing need to be converted. We simply return the +// original pointer. +// +// MSWindows and X11 render text in ISO or Latin-1 for western settings. The +// lookup tables below will convert all common character codes and replace +// unknown characters with an upsidedown question mark. + +#ifdef __APPLE__ + +const char *fl_mac_roman_to_local(const char *t, int) +{ + return t; +} + +const char *fl_local_to_mac_roman(const char *t, int) +{ + return t; +} + +#else + +// This table converts MSWindows-1252/Latin 1 into MacRoman encoding +static uchar latin2roman[256] = { +0xdb, 0xc0, 0xe2, 0xc4, 0xe3, 0xc9, 0xa0, 0xe0, 0xf6, 0xe4, 0xc0, 0xdc, 0xce, 0xc0, 0xc0, 0xc0, +0xc0, 0xd4, 0xd5, 0xd2, 0xd3, 0xa5, 0xd0, 0xd1, 0xf7, 0xaa, 0xc0, 0xdd, 0xcf, 0xc0, 0xc0, 0xd9, +0xca, 0xc1, 0xa2, 0xa3, 0xc0, 0xb4, 0xc0, 0xa4, 0xac, 0xa9, 0xbb, 0xc7, 0xc2, 0xc0, 0xa8, 0xf8, +0xa1, 0xb1, 0xc0, 0xc0, 0xab, 0xb5, 0xa6, 0xe1, 0xfc, 0xc0, 0xbc, 0xc8, 0xc0, 0xc0, 0xc0, 0xc0, +0xcb, 0xe7, 0xe5, 0xcc, 0x80, 0x81, 0xae, 0x82, 0xe9, 0x83, 0xe6, 0xe8, 0xed, 0xea, 0xeb, 0xec, +0xc0, 0x84, 0xf1, 0xee, 0xef, 0xcd, 0x85, 0xc0, 0xaf, 0xf4, 0xf2, 0xf3, 0x86, 0xc0, 0xc0, 0xa7, +0x88, 0x87, 0x89, 0x8b, 0x8a, 0x8c, 0xbe, 0x8d, 0x8f, 0x8e, 0x90, 0x91, 0x93, 0x92, 0x94, 0x95, +0xc0, 0x96, 0x98, 0x97, 0x99, 0x9b, 0x9a, 0xd6, 0xbf, 0x9d, 0x9c, 0x9e, 0x9f, 0xc0, 0xc0, 0xd8 +}; + +// This table converts MacRoman into MSWindows-1252/Latin 1 +static uchar roman2latin[256] = { +0xc4, 0xc5, 0xc7, 0xc9, 0xd1, 0xd6, 0xdc, 0xe1, 0xe0, 0xe2, 0xe4, 0xe3, 0xe5, 0xe7, 0xe9, 0xe8, +0xea, 0xeb, 0xed, 0xec, 0xee, 0xef, 0xf1, 0xf3, 0xf2, 0xf4, 0xf6, 0xf5, 0xfa, 0xf9, 0xfb, 0xfc, +0x86, 0xb0, 0xa2, 0xa3, 0xa7, 0x95, 0xb6, 0xdf, 0xae, 0xa9, 0x99, 0xb4, 0xa8, 0xbf, 0xc6, 0xd8, +0xbf, 0xb1, 0xbf, 0xbf, 0xa5, 0xb5, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xaa, 0xba, 0xbf, 0xe6, 0xf8, +0xbf, 0xa1, 0xac, 0xbf, 0x83, 0xbf, 0xbf, 0xab, 0xbb, 0x85, 0xa0, 0xc0, 0xc3, 0xd5, 0x8c, 0x9c, +0x96, 0x97, 0x93, 0x94, 0x91, 0x92, 0xf7, 0xbf, 0xff, 0x9f, 0xbf, 0x80, 0x8b, 0x9b, 0xbf, 0xbf, +0x87, 0xb7, 0x82, 0x84, 0x89, 0xc2, 0xca, 0xc1, 0xcb, 0xc8, 0xcd, 0xce, 0xcf, 0xcc, 0xd3, 0xd4, +0xbf, 0xd2, 0xda, 0xdb, 0xd9, 0xbf, 0x88, 0x98, 0xaf, 0xbf, 0xbf, 0xbf, 0xb8, 0xbf, 0xbf, 0xbf +}; + +static char *buf = 0; +static int n_buf = 0; + +const char *fl_local_to_mac_roman(const char *t, int n) +{ + if (n==-1) n = strlen(t); + if (n<=n_buf) { + n_buf = (n + 257) & 0x7fffff00; + if (buf) free(buf); + buf = (char*)malloc(n_buf); + } + const uchar *src = (const uchar*)t; + uchar *dst = (uchar*)buf; + for ( ; n>0; n--) { + uchar c = *src; + if (c>127) + *dst = latin2roman[c-128]; + else + *dst = c; + } + //*dst = 0; // this would be wrong! + return buf; +} + +const char *fl_mac_roman_to_local(const char *t, int n) +{ + if (n==-1) n = strlen(t); + if (n<=n_buf) { + n_buf = (n + 257) & 0x7fffff00; + if (buf) free(buf); + buf = (char*)malloc(n_buf); + } + const uchar *src = (const uchar*)t; + uchar *dst = (uchar*)buf; + for ( ; n>0; n--) { + uchar c = *src++; + if (c>127) + *dst++ = roman2latin[c-128]; + else + *dst++ = c; + } + //*dst = 0; // this would be wrong + return buf; +} + +#endif + +// +// End of "$Id: $". +// diff --git a/src/fl_font_mac.cxx b/src/fl_font_mac.cxx index f37500ce9..b9a5f5bbb 100644 --- a/src/fl_font_mac.cxx +++ b/src/fl_font_mac.cxx @@ -203,52 +203,7 @@ int fl_descent() { else return -1; } -// MRS: The default character set is MacRoman, which is different from -// ISO-8859-1; in FLTK 2.0 we'll use UTF-8 with Quartz... - -static uchar macroman_lut[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, - 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, - 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, - 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, - 202, 193, 162, 163, 164, 180, 166, 164, 172, 169, 187, 199, 194, 173, 168, 248, - 161, 177, 178, 179, 171, 181, 166, 225, 252, 185, 188, 200, 188, 189, 190, 192, - 203, 231, 229, 204, 128, 129, 174, 130, 233, 131, 230, 232, 237, 234, 235, 236, - 208, 132, 241, 238, 239, 205, 133, 215, 175, 244, 242, 243, 134, 221, 222, 167, - 136, 135, 137, 139, 138, 140, 190, 141, 143, 142, 144, 145, 147, 146, 148, 149, - 240, 150, 152, 151, 153, 155, 154, 214, 191, 157, 156, 158, 159, 253, 254, 216 -}; - -static char *iso_buf = 0; -static int n_iso_buf = 0; - -// this function must be available for OpenGL character drawing as well -const char *fl_iso2macRoman(const char *s, int n) { - // do not do a text lookup for 'Symbol' or 'WebDings'. This fails - // if the user assigns a new font to these numbers though. - if (fl_font_ == 12 || fl_font_ == 15) - return s; - if (n>n_iso_buf) { - if (iso_buf) free(iso_buf); - iso_buf = (char*)malloc(n+500); - n_iso_buf = n; - } - uchar *src = (uchar*)s; - uchar *dst = (uchar*)iso_buf; - for (;n--;) { - *dst++ = macroman_lut[*src++]; - } - return iso_buf; -} - -double fl_width(const char* c, int n) { - const char *txt = fl_iso2macRoman(c, n); +double fl_width(const char* txt, int n) { #ifdef __APPLE_QD__ return (double)TextWidth( txt, 0, n ); #else @@ -269,20 +224,15 @@ double fl_width(const char* c, int n) { } double fl_width(uchar c) { -#ifdef __APPLE_QD__ - return (double)TextWidth((const char*)(macroman_lut + c), 0, 1 ); -#else return fl_width((const char*)(&c), 1); -#endif } void fl_draw(const char *str, int n, float x, float y); void fl_draw(const char* str, int n, int x, int y) { #ifdef __APPLE_QD__ - const char *txt = fl_iso2macRoman(str, n); MoveTo(x, y); - DrawText((const char *)txt, 0, n); + DrawText((const char *)str, 0, n); #elif defined(__APPLE_QUARTZ__) fl_draw(str, n, (float)x, (float)y); #else @@ -294,8 +244,7 @@ void fl_draw(const char *str, int n, float x, float y) { #ifdef __APPLE_QD__ fl_draw(str, n, (int)x, (int)y); #elif defined(__APPLE_QUARTZ__) - const char *txt = fl_iso2macRoman(str, n); - CGContextShowTextAtPoint(fl_gc, x, y, txt, n); + CGContextShowTextAtPoint(fl_gc, x, y, str, n); #else # error : neither Quartz no Quickdraw chosen #endif diff --git a/src/gl_draw.cxx b/src/gl_draw.cxx index 6eac7a7ed..4b5555e7b 100644 --- a/src/gl_draw.cxx +++ b/src/gl_draw.cxx @@ -127,17 +127,8 @@ void gl_remove_displaylist_fonts() #endif } -#ifdef __APPLE__ -const char *fl_iso2macRoman(const char*, int); -#endif - void gl_draw(const char* str, int n) { -#ifdef __APPLE__ - const char *txt = fl_iso2macRoman(str, n); - glCallLists(n, GL_UNSIGNED_BYTE, txt); -#else glCallLists(n, GL_UNSIGNED_BYTE, str); -#endif } void gl_draw(const char* str, int n, int x, int y) { diff --git a/src/makefile.wat b/src/makefile.wat index abf34e941..4fcc3cff2 100644 --- a/src/makefile.wat +++ b/src/makefile.wat @@ -126,6 +126,8 @@ CPPFILES = & fl_draw.obj &
fl_draw_image.obj &
fl_draw_pixmap.obj &
+ fl_encoding_latin1.obj &
+ fl_encoding_mac_roman.obj &
fl_engraved_label.obj &
fl_file_dir.obj &
fl_font.obj &
|
