|
fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) ![]() |
00001 // 00002 // "$Id: fl_encoding_latin1.cxx 7903 2010-11-28 21:06:39Z matt $" 00003 // 00004 // Convert MSWindows-1252 (Latin-1) encoded text to the local encoding. 00005 // 00006 // Copyright 1998-2010 by Bill Spitzak and others. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 // USA. 00022 // 00023 // Please report all bugs and problems on the following page: 00024 // 00025 // http://www.fltk.org/str.php 00026 // 00027 00028 #include <FL/fl_draw.H> 00029 #include <FL/Enumerations.H> 00030 #include <stdlib.h> 00031 #include "flstring.h" 00032 00033 #ifdef __APPLE__ 00034 00035 // These function assume a western code page. If you need to support 00036 // scripts that are not part of this code page, you might want to 00037 // take a look at FLTK2, which uses utf8 for text encoding. 00038 // 00039 // By keeping these conversion tables in their own module, they will not 00040 // be statically linked (by a smart linker) unless actually used. 00041 // 00042 // On MS-Windows, nothing need to be converted. We simply return the 00043 // original pointer. 00044 // 00045 // Most X11 implementations seem to default to Latin-1 as a code since it 00046 // is a superset of ISO 8859-1, the original wetsern codepage on X11. 00047 // 00048 // Apple's OS X however renders text in MacRoman for western settings. The 00049 // lookup tables below will convert all common character codes and replace 00050 // unknown characters with an upsidedown question mark. 00051 00052 // This table converts MSWindows-1252/Latin 1 into MacRoman encoding 00053 static uchar latin2roman[128] = { 00054 0xdb, 0xc0, 0xe2, 0xc4, 0xe3, 0xc9, 0xa0, 0xe0, 0xf6, 0xe4, 0xc0, 0xdc, 0xce, 0xc0, 0xc0, 0xc0, 00055 0xc0, 0xd4, 0xd5, 0xd2, 0xd3, 0xa5, 0xd0, 0xd1, 0xf7, 0xaa, 0xc0, 0xdd, 0xcf, 0xc0, 0xc0, 0xd9, 00056 0xca, 0xc1, 0xa2, 0xa3, 0xc0, 0xb4, 0xc0, 0xa4, 0xac, 0xa9, 0xbb, 0xc7, 0xc2, 0xc0, 0xa8, 0xf8, 00057 0xa1, 0xb1, 0xc0, 0xc0, 0xab, 0xb5, 0xa6, 0xe1, 0xfc, 0xc0, 0xbc, 0xc8, 0xc0, 0xc0, 0xc0, 0xc0, 00058 0xcb, 0xe7, 0xe5, 0xcc, 0x80, 0x81, 0xae, 0x82, 0xe9, 0x83, 0xe6, 0xe8, 0xed, 0xea, 0xeb, 0xec, 00059 0xc0, 0x84, 0xf1, 0xee, 0xef, 0xcd, 0x85, 0xc0, 0xaf, 0xf4, 0xf2, 0xf3, 0x86, 0xc0, 0xc0, 0xa7, 00060 0x88, 0x87, 0x89, 0x8b, 0x8a, 0x8c, 0xbe, 0x8d, 0x8f, 0x8e, 0x90, 0x91, 0x93, 0x92, 0x94, 0x95, 00061 0xc0, 0x96, 0x98, 0x97, 0x99, 0x9b, 0x9a, 0xd6, 0xbf, 0x9d, 0x9c, 0x9e, 0x9f, 0xc0, 0xc0, 0xd8 00062 }; 00063 00064 // This table converts MacRoman into MSWindows-1252/Latin 1 00065 static uchar roman2latin[128] = { 00066 0xc4, 0xc5, 0xc7, 0xc9, 0xd1, 0xd6, 0xdc, 0xe1, 0xe0, 0xe2, 0xe4, 0xe3, 0xe5, 0xe7, 0xe9, 0xe8, 00067 0xea, 0xeb, 0xed, 0xec, 0xee, 0xef, 0xf1, 0xf3, 0xf2, 0xf4, 0xf6, 0xf5, 0xfa, 0xf9, 0xfb, 0xfc, 00068 0x86, 0xb0, 0xa2, 0xa3, 0xa7, 0x95, 0xb6, 0xdf, 0xae, 0xa9, 0x99, 0xb4, 0xa8, 0xbf, 0xc6, 0xd8, 00069 0xbf, 0xb1, 0xbf, 0xbf, 0xa5, 0xb5, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xaa, 0xba, 0xbf, 0xe6, 0xf8, 00070 0xbf, 0xa1, 0xac, 0xbf, 0x83, 0xbf, 0xbf, 0xab, 0xbb, 0x85, 0xa0, 0xc0, 0xc3, 0xd5, 0x8c, 0x9c, 00071 0x96, 0x97, 0x93, 0x94, 0x91, 0x92, 0xf7, 0xbf, 0xff, 0x9f, 0xbf, 0x80, 0x8b, 0x9b, 0xbf, 0xbf, 00072 0x87, 0xb7, 0x82, 0x84, 0x89, 0xc2, 0xca, 0xc1, 0xcb, 0xc8, 0xcd, 0xce, 0xcf, 0xcc, 0xd3, 0xd4, 00073 0xbf, 0xd2, 0xda, 0xdb, 0xd9, 0xbf, 0x88, 0x98, 0xaf, 0xbf, 0xbf, 0xbf, 0xb8, 0xbf, 0xbf, 0xbf 00074 }; 00075 00076 static char *buf = 0; 00077 static int n_buf = 0; 00078 00079 const char *fl_latin1_to_local(const char *t, int n) 00080 { 00081 if (n==-1) n = strlen(t); 00082 if (n<=n_buf) { 00083 n_buf = (n + 257) & 0x7fffff00; 00084 if (buf) free(buf); 00085 buf = (char*)malloc(n_buf); 00086 } 00087 const uchar *src = (const uchar*)t; 00088 uchar *dst = (uchar*)buf; 00089 for ( ; n>0; n--) { 00090 uchar c = *src++; 00091 if (c>127) 00092 *dst = latin2roman[c-128]; 00093 else 00094 *dst = c; 00095 } 00096 //*dst = 0; // this would be wrong! 00097 return buf; 00098 } 00099 00100 const char *fl_local_to_latin1(const char *t, int n) 00101 { 00102 if (n==-1) n = strlen(t); 00103 if (n<=n_buf) { 00104 n_buf = (n + 257) & 0x7fffff00; 00105 if (buf) free(buf); 00106 buf = (char*)malloc(n_buf); 00107 } 00108 const uchar *src = (const uchar*)t; 00109 uchar *dst = (uchar*)buf; 00110 for ( ; n>0; n--) { 00111 uchar c = *src++; 00112 if (c>127) 00113 *dst++ = roman2latin[c-128]; 00114 else 00115 *dst++ = c; 00116 } 00117 //*dst = 0; // this would be wrong 00118 return buf; 00119 } 00120 00121 #else 00122 00123 const char *fl_latin1_to_local(const char *t, int) 00124 { 00125 return t; 00126 } 00127 00128 const char *fl_local_to_latin1(const char *t, int) 00129 { 00130 return t; 00131 } 00132 00133 #endif 00134 00135 // 00136 // End of "$Id: fl_encoding_latin1.cxx 7903 2010-11-28 21:06:39Z matt $". 00137 //