Add cyrillic font auto selection for x frontend.

Thanks for Serge Orlov (sorlov@con.mcst.ru) from the net.
This commit is contained in:
ftang 1998-05-01 20:23:44 +00:00
Родитель 6a5f58df68
Коммит 05747ce5ad
5 изменённых файлов: 82 добавлений и 383 удалений

Просмотреть файл

@ -1,363 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* cvchcode.c */
#include "intlpriv.h"
#include "xp.h"
#include "libi18n.h"
extern cscvt_t cscvt_tbl[];
extern int haveBig5;
struct RealCCCDataObject {
struct INTL_CCCFuncs *funcs_pointer;
CCCRADFunc report_autodetect;
void *autodetect_closure;
CCCFunc cvtfunc;
int32 jismode;
int32 cvtflag; /* cvt func dependent flag */
unsigned char uncvtbuf[UNCVTBUF_SIZE];
uint16 default_doc_csid;
int16 from_csid;
int16 to_csid;
int retval; /* error value for return */
int32 len; /* byte len of converted buf */
};
/*
* report_autodetect
*/
PRIVATE void
CallCCCReportAutoDetect(CCCDataObject obj, uint16 detected_doc_csid)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
if (c->report_autodetect)
(c->report_autodetect)(c->autodetect_closure, obj, detected_doc_csid);
}
PRIVATE void
SetCCCReportAutoDetect(CCCDataObject obj,
CCCRADFunc report_autodetect,
void *autodetect_closure)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
c->report_autodetect = report_autodetect;
c->autodetect_closure = autodetect_closure;
}
/*
* cvtfunc
*/
PRIVATE CCCFunc
GetCCCCvtfunc(CCCDataObject obj)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
return c->cvtfunc;
}
PRIVATE void
SetCCCCvtfunc(CCCDataObject obj, CCCFunc cvtfunc)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
c->cvtfunc = cvtfunc;
}
/*
* jismode
*/
PRIVATE int32
GetCCCJismode(CCCDataObject obj)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
return c->jismode;
}
PRIVATE void
SetCCCJismode(CCCDataObject obj, int32 jismode)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
c->jismode = jismode;
}
/*
* cvtflag
*/
PRIVATE int32
GetCCCCvtflag(CCCDataObject obj)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
return c->cvtflag;
}
PRIVATE void
SetCCCCvtflag(CCCDataObject obj, int32 cvtflag)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
c->cvtflag = cvtflag;
}
/*
* uncvtbuf
*/
PRIVATE unsigned char*
GetCCCUncvtbuf(CCCDataObject obj)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
return c->uncvtbuf;
}
/*
* len
*/
PRIVATE int32
GetCCCLen(CCCDataObject obj)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
return c->len;
}
PRIVATE void
SetCCCLen(CCCDataObject obj, int32 len)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
c->len = len;
}
/*
* retval
*/
PRIVATE int
GetCCCRetval(CCCDataObject obj)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
return c->retval;
}
PRIVATE void
SetCCCRetval(CCCDataObject obj, int retval)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
c->retval = retval;
}
/*
* default_doc_csid
*/
PRIVATE void
SetCCCDefaultCSID(CCCDataObject obj, uint16 default_doc_csid)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
c->default_doc_csid = default_doc_csid;
}
PRIVATE uint16
GetCCCDefaultCSID(CCCDataObject obj)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
return c->default_doc_csid;
}
/*
* from_csid
*/
PRIVATE uint16
GetCCCFromCSID(CCCDataObject obj)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
return c->from_csid;
}
PRIVATE void
SetCCCFromCSID(CCCDataObject obj, uint16 from_csid)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
c->from_csid = from_csid;
}
/*
* to_csid
*/
PRIVATE uint16
GetCCCToCSID(CCCDataObject obj)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
return c->to_csid;
}
PRIVATE void
SetCCCToCSID(CCCDataObject obj, uint16 to_csid)
{
struct RealCCCDataObject *c = (struct RealCCCDataObject *)obj;
c->to_csid = to_csid;
}
PUBLIC unsigned char *
INTL_CallCharCodeConverter(CCCDataObject obj, const unsigned char *buf,
int32 bufsz)
{
return (INTL_GetCCCCvtfunc(obj))(obj, buf, bufsz);
}
/* INTL_GetCharCodeConverter:
* RETURN: 1 if converter found, else 0
* Also, sets:
* obj->cvtfunc: function handle for chararcter
* code set streams converter
* obj->cvtflag: (Optional) flag to converter
* function
* obj->from_csid: Code set converting from
* obj->to_csid: Code set converting to
* If the arg to_csid==0, then use the the conversion for the
* first conversion entry that matches the from_csid.
*/
PUBLIC int
INTL_GetCharCodeConverter( register int16 from_csid,
register int16 to_csid,
CCCDataObject obj)
{
register cscvt_t *cscvtp;
if (from_csid == CS_DEFAULT)
INTL_SetCCCFromCSID(obj, INTL_GetCCCDefaultCSID(obj));
else
INTL_SetCCCFromCSID(obj, from_csid);
if(to_csid == 0) /* unknown TO codeset */
to_csid = INTL_DocToWinCharSetID(from_csid);
INTL_SetCCCToCSID(obj, to_csid);
/* Look-up conversion method given FROM and TO char. code sets */
cscvtp = cscvt_tbl;
while (cscvtp->from_csid) {
if ((cscvtp->from_csid == from_csid) && (cscvtp->to_csid == to_csid))
break;
cscvtp++;
}
INTL_SetCCCCvtflag(obj, cscvtp->cvtflag);
INTL_SetCCCCvtfunc(obj, cscvtp->cvtmethod);
return (INTL_GetCCCCvtfunc(obj)) ? 1 : 0;
}
/* WARNING: THIS TABLE AND THE STRUCT MUST BE IN SYNC WITH EACH OTHER */
PRIVATE struct INTL_CCCFuncs ccc_funcs = {
/* set_report_autodetect */ SetCCCReportAutoDetect,
/* call_report_autodetect */ CallCCCReportAutoDetect,
/* set_cvtfunc */ SetCCCCvtfunc,
/* get_cvtfunc */ GetCCCCvtfunc,
/* set_jismode */ SetCCCJismode,
/* get_jismode */ GetCCCJismode,
/* set_cvtflag */ SetCCCCvtflag,
/* get_cvtflag */ GetCCCCvtflag,
/* get_uncvtbuf */ GetCCCUncvtbuf,
/* set_default_doc_csid */ SetCCCDefaultCSID,
/* get_default_doc_csid */ GetCCCDefaultCSID,
/* set_from_csid */ SetCCCFromCSID,
/* get_from_csid */ GetCCCFromCSID,
/* set_to_csid */ SetCCCToCSID,
/* get_to_csid */ GetCCCToCSID,
/* set_retval */ SetCCCRetval,
/* get_retval */ GetCCCRetval,
/* set_len */ SetCCCLen,
/* get_len */ GetCCCLen
};
PUBLIC CCCDataObject
INTL_CreateCharCodeConverter()
{
struct RealCCCDataObject *obj;
obj = XP_NEW_ZAP(struct RealCCCDataObject);
obj->funcs_pointer = &ccc_funcs;
obj->default_doc_csid = INTL_DefaultDocCharSetID(0);
return (CCCDataObject) obj;
}
PUBLIC void
INTL_DestroyCharCodeConverter(CCCDataObject obj)
{
XP_FREE(obj);
}
PRIVATE unsigned char *intl_conv (int16 fromcsid, int16 tocsid, unsigned char *pSrc, uint32 block_size);
PRIVATE
unsigned char *intl_conv(int16 fromcsid, int16 tocsid, unsigned char *pSrc, uint32 block_size)
{
CCCDataObject obj;
unsigned char *pDest = NULL;
if (NULL != (obj = INTL_CreateCharCodeConverter()))
{
if(0 != INTL_GetCharCodeConverter(fromcsid, tocsid, obj))
{
CCCFunc cvtfunc;
if (NULL != (cvtfunc = INTL_GetCCCCvtfunc(obj)))
{
if(pSrc == (pDest = (unsigned char *)cvtfunc(obj, pSrc, block_size)) )
{
/* if it use the same buffer to do conversion, we return NULL */
pDest = NULL;
}
}
}
INTL_DestroyCharCodeConverter(obj);
}
return pDest ;
}
PUBLIC unsigned char *
INTL_ConvertLineWithoutAutoDetect (int16 fromcsid, int16 tocsid, unsigned char *pSrc, uint32 block_size)
{
#ifdef XP_OS2
if (fromcsid != tocsid)
{
return intl_conv(fromcsid, tocsid, pSrc, block_size);
else
{
return XP_STRDUP(pSrc);
}
#else
return intl_conv(fromcsid, tocsid, pSrc, block_size);
#endif /* XP_OS2 */
}

Просмотреть файл

@ -86,7 +86,13 @@ PRIVATE intl_CharLenFunc intl_char_len_func[]=
intl_CharLen_SingleByte,
};
int haveBig5 = 0;
#ifdef XP_UNIX
PRIVATE XP_Bool haveBig5 = FALSE;
PRIVATE XP_Bool have88595 = FALSE;
PRIVATE XP_Bool have1251 = FALSE;
PRIVATE XP_Bool haveKOI8R = FALSE;
#endif
PRIVATE int16 *availableFontCharSets = NULL;
@ -436,15 +442,21 @@ MODULE_PRIVATE cscvt_t cscvt_tbl[] = {
/* CYRILLIC */
{CS_KOI8_R, CS_KOI8_R, 0, NULL, 0},
{CS_8859_5, CS_8859_5, 0, NULL, 0},
{CS_CP_1251, CS_CP_1251, 0, NULL, 0},
{CS_8859_5, CS_KOI8_R, 0, (CCCFunc)One2OneCCC, 0},
{CS_KOI8_R, CS_8859_5, 0, (CCCFunc)One2OneCCC, 0},
{CS_CP_1251, CS_8859_5, 0, (CCCFunc)One2OneCCC, 0},
{CS_CP_1251, CS_8859_5, 0, (CCCFunc)One2OneCCC, 0},
{CS_8859_5, CS_CP_1251, 0, (CCCFunc)One2OneCCC, 0},
{CS_CP_1251, CS_KOI8_R, 0, (CCCFunc)One2OneCCC, 0},
{CS_KOI8_R, CS_CP_1251, 0, (CCCFunc)One2OneCCC, 0},
/* GREEK */
{CS_8859_7, CS_8859_7, 0, NULL, 0},
{CS_8859_7, CS_CP_1253, 0, (CCCFunc)One2OneCCC, 0},
{CS_CP_1253, CS_8859_7, 0, (CCCFunc)One2OneCCC, 0},
{CS_CP_1253, CS_8859_7, 0, (CCCFunc)One2OneCCC, 0},
/* TURKISH */
{CS_8859_9, CS_8859_9, 0, NULL, 0},
@ -868,7 +880,11 @@ PUBLIC int16 INTL_DocToWinCharSetID(int16 csid)
* disgusting hack...
*/
#ifdef XP_UNIX
if ((cscvtp->to_csid == CS_CNS_8BIT) && haveBig5) {
if (((cscvtp->to_csid == CS_CNS_8BIT) && (TRUE == haveBig5)) ||
((cscvtp->to_csid == CS_8859_5) && (FALSE == have88595)) ||
((cscvtp->to_csid == CS_KOI8_R) && (FALSE == haveKOI8R)) ||
((cscvtp->to_csid == CS_CP_1251) && (FALSE == have1251)) )
{
cscvtp++;
continue;
}
@ -930,10 +946,23 @@ INTL_ReportFontCharSets(int16 *charsets)
while (*charsets)
{
if (*charsets == CS_X_BIG5)
#ifdef XP_UNIX
switch(*charsets)
{
haveBig5 = 1;
case CS_X_BIG5:
haveBig5 = TRUE;
break;
case CS_8859_5:
have88595 = TRUE;
break;
case CS_CP_1251:
have1251 = TRUE;
break;
case CS_KOI8_R:
haveKOI8R = TRUE;
break;
}
#endif
charsets++;
}
len = (charsets - availableFontCharSets);

Просмотреть файл

@ -206,6 +206,32 @@ PRIVATE unsigned char iso8859_7_to_cp1253[] = {
};
PRIVATE char *iso8859_7_to_cp1253_p = (char*)iso8859_7_to_cp1253;
/* Translation cp1251.txt -> koi8r.txt */
PRIVATE unsigned char cp1251_to_koi8r[] = {
/*8x*/ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
/*9x*/ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
/*Ax*/ '?', '?', '?', '?', '?', '?', '?', '?',0xB3, '?', '?', '?', '?', '?', '?', '?',
/*Bx*/ '?', '?', '?', '?', '?', '?', '?', '?',0xA3, '?', '?', '?', '?', '?', '?', '?',
/*Cx*/ 0xE1,0xE2,0xF7,0xE7,0xE4,0xE5,0xF6,0xFA,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,
/*Dx*/ 0xF2,0xF3,0xF4,0xF5,0xE6,0xE8,0xE3,0xFE,0xFB,0xFD,0xFF,0xF9,0xF8,0xFC,0xE0,0xF1,
/*Ex*/ 0xC1,0xC2,0xD7,0xC7,0xC4,0xC5,0xD6,0xDA,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,
/*Fx*/ 0xD2,0xD3,0xD4,0xD5,0xC6,0xC8,0xC3,0xDE,0xDB,0xDD,0xDF,0xD9,0xD8,0xDC,0xC0,0xD1,
};
PRIVATE char *cp1251_to_koi8r_p = (char*)cp1251_to_koi8r;
/* Translation koi8r.txt -> cp1251.txt */
PRIVATE unsigned char koi8r_to_cp1251[] = {
/*8x*/ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
/*9x*/ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
/*Ax*/ '?', '?', '?',0xB8, '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
/*Bx*/ '?', '?', '?',0xA8, '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
/*Cx*/ 0xFE,0xE0,0xE1,0xF6,0xE4,0xE5,0xF4,0xE3,0xF5,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,
/*Dx*/ 0xEF,0xFF,0xF0,0xF1,0xF2,0xF3,0xE6,0xE2,0xFC,0xFB,0xE7,0xF8,0xFD,0xF9,0xF7,0xFA,
/*Ex*/ 0xDE,0xC0,0xC1,0xD6,0xC4,0xC5,0xD4,0xC3,0xD5,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,
/*Fx*/ 0xCF,0xDF,0xD0,0xD1,0xD2,0xD3,0xC6,0xC2,0xDC,0xDB,0xC7,0xD8,0xDD,0xD9,0xD7,0xDA,
};
PRIVATE char *koi8r_to_cp1251_p = (char*)koi8r_to_cp1251;
PUBLIC char **
INTL_GetSingleByteTable(int16 from_csid, int16 to_csid, int32 resourceid)
{
@ -235,6 +261,12 @@ INTL_GetSingleByteTable(int16 from_csid, int16 to_csid, int32 resourceid)
else if ((from_csid == CS_CP_1251) && (to_csid == CS_8859_5)) {
return &cp1251_to_iso8859_5_p;
}
else if ((from_csid == CS_CP_1251) && (to_csid == CS_KOI8_R)) {
return &cp1251_to_koi8r_p;
}
else if ((from_csid == CS_KOI8_R) && (to_csid == CS_CP_1251)) {
return &koi8r_to_cp1251_p;
}
/* GREEK */
else if ((from_csid == CS_8859_7) && (to_csid == CS_CP_1253)) {

Просмотреть файл

@ -247,7 +247,7 @@ PRIVATE unsigned char lower_lookup_8859_5[128]={
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
#endif
#if defined(XP_WIN) || defined(XP_OS2)
#if defined(XP_WIN) || defined(XP_OS2) || defined(XP_UNIX)
/*
lower_lookup_cp1251 map
0x80 0x90
@ -636,6 +636,8 @@ MODULE_PRIVATE unsigned char *INTL_GetSingleByteToLowerMap(int16 csid)
return lower_lookup_8859_7;
case CS_8859_9:
return lower_lookup_8859_9;
case CS_CP_1251:
return lower_lookup_cp1251;
#endif
case CS_KOI8_R:
return lower_lookup_koi8_r;

Просмотреть файл

@ -132,6 +132,12 @@ PRIVATE uint16 koi8rFromTbl[] = {
PRIVATE uint16 koi8rToTbl[] = {
#include "koi8r.ut"
};
PRIVATE uint16 cp1251FromTbl[] = {
#include "cp1251.uf"
};
PRIVATE uint16 cp1251ToTbl[] = {
#include "cp1251.ut"
};
/*--------------------------------------------------------------------------*/
/* Japanese stuff */
PRIVATE uint16 JIS0208FromTbl[] = {
@ -197,17 +203,6 @@ PRIVATE uint16 GB2312ToTbl[] = {
};
/*--------------------------------------------------------------------------*/
/* Korean Stuff */
#ifdef UNICODE_1_1_BASE_KOREAN
PRIVATE uint16 KSC5601FromTbl[] = {
#include "ksc5601.uf"
};
PRIVATE uint16 KSC5601ToTbl[] = {
#include "ksc5601.ut"
};
#else /* UNICODE_1_1_BASE_KOREAN */
/*
For UNIX the Korean UNICODE 2.0 table is u20kscgl.u[tf]
They are GL base table that contains minimun set of Korean table that
@ -220,8 +215,6 @@ PRIVATE uint16 KSC5601ToTbl[] = {
#include "u20kscgl.ut"
};
#endif /* UNICODE_1_1_BASE_KOREAN */
/*--------------------------------------------------------------------------*/
/* Symbol Stuff */
@ -262,6 +255,9 @@ PRIVATE uTable* LoadToUCS2Table(uint16 csid)
case CS_KOI8_R:
return (uTable*) koi8rToTbl;
case CS_CP_1251:
return (uTable*) cp1251ToTbl;
/* Japanese */
case CS_JISX0208:
@ -338,6 +334,9 @@ PRIVATE uTable* LoadFromUCS2Table(uint16 csid)
case CS_KOI8_R:
return (uTable*) koi8rFromTbl;
case CS_CP_1251:
return (uTable*) cp1251FromTbl;
/* Japanese */
case CS_JISX0208: