modify some files of bada project

This commit is contained in:
dumganhar 2011-09-20 02:19:26 +08:00
parent 81243eecdf
commit eb32cf9fe2
12 changed files with 673 additions and 201 deletions

View File

@ -68,6 +68,7 @@ bool AppDelegate::initInstance()
#if (CC_TARGET_PLATFORM == CC_PLATFORM_BADA)
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(this));
cocos2d::CCFileUtils::setResourcePath("/Res/");
#endif
bRet = true;
} while (0);

View File

@ -45,10 +45,11 @@
<tool id="cdt.managedbuild.tool.osp.gnu.simul.c.linker.exe.simul.1562949457" name="bada C Linker" superClass="cdt.managedbuild.tool.osp.gnu.simul.c.linker.exe.simul"/>
<tool id="cdt.managedbuild.tool.osp.gnu.simul.cpp.linker.exe.simul.1526380860" name="bada C++ Linker" superClass="cdt.managedbuild.tool.osp.gnu.simul.cpp.linker.exe.simul">
<option id="osp.gnu.cpp.link.simual.debug.option.libs.985039748" name="Libraries (-l)" superClass="osp.gnu.cpp.link.simual.debug.option.libs" valueType="libs">
<listOptionValue builtIn="false" value="cocos2dx"/>
<listOptionValue builtIn="false" value="png"/>
<listOptionValue builtIn="false" value="zlib"/>
<listOptionValue builtIn="false" value="osp_rt0"/>
<listOptionValue builtIn="false" value="cocos2dx"/>
<listOptionValue builtIn="false" value="jpeg"/>
<listOptionValue builtIn="false" value="zlib"/>
<listOptionValue builtIn="false" value="png"/>
<listOptionValue builtIn="false" value="libc-newlib"/>
<listOptionValue builtIn="false" value="FOsp"/>
<listOptionValue builtIn="false" value="FGraphicsOpengl"/>
@ -58,7 +59,6 @@
<listOptionValue builtIn="false" value="&quot;${SIMULATOR_LIB_PATH}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${SDKROOT}/Lib&quot;"/>
<listOptionValue builtIn="false" value="&quot;${PROJECT_ROOT}/lib&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/cocos2dx/.Simulator-Debug}&quot;"/>
</option>
<inputType id="cdt.managedbuild.tool.osp.gnu.cpp.linker.input.543292516" superClass="cdt.managedbuild.tool.osp.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>

View File

@ -146,7 +146,7 @@ bool CCImage::_initWithJpgData(void * data, int nSize)
jpeg_create_decompress( &cinfo );
/* this makes the library read from infile */
//cjh_must jpeg_mem_src( &cinfo, (unsigned char *) data, nSize );
jpeg_mem_src( &cinfo, (unsigned char *) data, nSize );
/* reading the image header which contains image information */
jpeg_read_header( &cinfo, true );
@ -221,8 +221,10 @@ bool CCImage::_initWithPngData(void * pData, int nDatalen)
// init png_info
info_ptr = png_create_info_struct(png_ptr);
//cjh_must CC_BREAK_IF(!info_ptr || setjmp(png_jmpbuf(png_ptr)));
CC_BREAK_IF(!info_ptr);
#if CC_TARGET_PLATFORM != CC_PLATFORM_BADA
CC_BREAK_IF(setjmp(png_jmpbuf(png_ptr)));
#endif
// set the read call back function
tImageSource imageSource;
imageSource.data = (unsigned char*)pData;
@ -246,7 +248,7 @@ bool CCImage::_initWithPngData(void * pData, int nDatalen)
// init image info
m_bPreMulti = true;
//cjh_must m_bHasAlpha = ( info_ptr->color_type & PNG_COLOR_MASK_ALPHA ) ? true : false;
m_bHasAlpha = ( info_ptr->color_type & PNG_COLOR_MASK_ALPHA ) ? true : false;
// allocate memory and read data
int bytesPerComponent = 3;
@ -390,12 +392,12 @@ bool CCImage::_saveImageToPNG(const char * pszFilePath, bool bIsToRGB)
break;
}
//cjh_must if (setjmp(png_jmpbuf(png_ptr)))
{
fclose(fp);
png_destroy_write_struct(&png_ptr, &info_ptr);
break;
}
//cjh if (setjmp(png_jmpbuf(png_ptr)))
// {
// fclose(fp);
// png_destroy_write_struct(&png_ptr, &info_ptr);
// break;
// }
png_init_io(png_ptr, fp);

View File

@ -60,16 +60,14 @@ void CCApplication::setAnimationInterval(double interval)
bool CCApplication::OnAppInitializing(AppRegistry& appRegistry)
{
InitGbkUnicodeTable("/Res/gbk_uni_tb.dat");
if (applicationDidFinishLaunching())
return true;
return false;
if (! initInstance() || !applicationDidFinishLaunching())
return false;
return true;
}
bool CCApplication::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
{
ReleaseGbkUnicodeTable();
return true;
}

View File

@ -42,7 +42,10 @@ class CC_DLL CCApplication :
public:
CCApplication();
virtual ~CCApplication();
/**
@brief Implement for initialize OpenGL instance, set source path, etc...
*/
virtual bool initInstance() = 0;
/**
@brief Implement Window create, CCDirector and CCScene init code here.
@return true Initialize success, app continue.

View File

@ -38,6 +38,7 @@ bool CCImage::initWithString(
result r = E_FAILURE;
do
{
CC_BREAK_IF(nWidth <= 0 || nHeight <= 0);
Canvas * pCanvas = new Canvas();
CC_BREAK_IF(! pCanvas);

View File

@ -4,9 +4,66 @@
#include <stdlib.h>
#include <stdarg.h>
#include <limits.h>
#include <ctype.h>
#include <malloc.h>
#include <errno.h>
#undef errno
static int errno = 0;
#define _U 01
#define _L 02
#define _N 04
#define _S 010
#define _P 020
#define _C 040
#define _X 0100
#define _B 0200
#define _CTYPE_DATA_0_127 \
_C, _C, _C, _C, _C, _C, _C, _C, \
_C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C, \
_C, _C, _C, _C, _C, _C, _C, _C, \
_C, _C, _C, _C, _C, _C, _C, _C, \
_S|_B, _P, _P, _P, _P, _P, _P, _P, \
_P, _P, _P, _P, _P, _P, _P, _P, \
_N, _N, _N, _N, _N, _N, _N, _N, \
_N, _N, _P, _P, _P, _P, _P, _P, \
_P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, \
_U, _U, _U, _U, _U, _U, _U, _U, \
_U, _U, _U, _U, _U, _U, _U, _U, \
_U, _U, _U, _P, _P, _P, _P, _P, \
_P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, \
_L, _L, _L, _L, _L, _L, _L, _L, \
_L, _L, _L, _L, _L, _L, _L, _L, \
_L, _L, _L, _P, _P, _P, _P, _C
#define _CTYPE_DATA_128_255 \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0
char _ctype_b[128 + 256] = {
_CTYPE_DATA_128_255,
_CTYPE_DATA_0_127,
_CTYPE_DATA_128_255
};
char *__ctype_ptr__ = (char *) _ctype_b + 127;
int sprintf(char* buf, const char *format, ...)
{
@ -1285,3 +1342,9 @@ int sscanf (const char *s,const char *format, ...)
return done;
}
void __assert_func(const char *file, int line, const char *a, const char *b)
{
}

View File

@ -0,0 +1,540 @@
/*
* Gbk_Unicode.h
*
* Created on: 2011-9-12
* Author: dumganhar
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Gbk_Unicode.h"
#define LOGI //printf
#define USE_MEMORY
#ifdef USE_MEMORY
#include "gbk_table.h"
#include "unicode_table.h"
#endif
#undef SAFE_FREE
#define SAFE_FREE(p) do \
{\
if ((p) != NULL) \
{ \
free((p)); \
(p) = NULL; \
} \
}while(0)
#define UNICODE1_BEGIN (0x3000)
#define UNICODE1_END (0x9FA5)
#define UNICODE1_TOTAL (UNICODE1_END-UNICODE1_BEGIN+1)
#define UNICODE2_BEGIN (0xFF00)
#define UNICODE2_END (0xFFEF)
#define UNICODE2_TOTAL (UNICODE2_END-UNICODE2_BEGIN+1)
#define UNICODE3_BEGIN (0x2000)
#define UNICODE3_END (0x206F)
#define UNICODE3_TOTAL (UNICODE3_END-UNICODE3_BEGIN+1)
#define FONT_ROW_BEGIN 129
#define FONT_ROW_END 254
#define FONT_COL_BEGIN 64
#define FONT_COL_END 254
#define FONT_TOTAL (((FONT_ROW_END)-(FONT_ROW_BEGIN)+1)*((FONT_COL_END)-(FONT_COL_BEGIN)+1))
static unsigned short* g_uni_table = NULL;
static unsigned short* g_gbk_table1 = NULL;
static unsigned short* g_gbk_table2 = NULL;
static unsigned short* g_gbk_table3 = NULL;
static int s_bInit = 0;
static int myWcslen(const unsigned short* str)
{
int i=0;
while(*str++) i++;
return i;
}
int InitGbkUnicodeTable(const char* szTablePath)
{
#ifndef USE_MEMORY
int ret = 0;
FILE* fp = NULL;
if (s_bInit)
return 0;
fp = fopen(szTablePath, "rb");
if (fp == NULL)
{
return 0;
}
g_uni_table = (unsigned short*)malloc(FONT_TOTAL*2);
memset((void*)g_uni_table, 0, FONT_TOTAL*2);
g_gbk_table1 = (unsigned short*)malloc(UNICODE1_TOTAL*2);
memset((void*)g_gbk_table1, 0, UNICODE1_TOTAL*2);
g_gbk_table2 = (unsigned short*)malloc(UNICODE2_TOTAL*2);
memset((void*)g_gbk_table2, 0, UNICODE2_TOTAL*2);
g_gbk_table3 = (unsigned short*)malloc(UNICODE3_TOTAL*2);
memset((void*)g_gbk_table3, 0, UNICODE3_TOTAL*2);
ret = fread((void*)g_uni_table, FONT_TOTAL*2, 1, fp);
ret = fread((void*)g_gbk_table1, UNICODE1_TOTAL*2, 1, fp);
ret = fread((void*)g_gbk_table2, UNICODE2_TOTAL*2, 1, fp);
ret = fread((void*)g_gbk_table3, UNICODE3_TOTAL*2, 1, fp);
fclose(fp);
s_bInit = 1;
#else
g_uni_table = g_uni_table_array;
g_gbk_table1 = g_gbk_table1_array;
g_gbk_table2 = g_gbk_table2_array;
g_gbk_table3 = g_gbk_table3_array;
s_bInit = 1;
#endif
return 1;
}
void ReleaseGbkUnicodeTable(void)
{
#ifndef USE_MEMORY
if (s_bInit) {
if (g_uni_table != NULL)
{
free((void*)g_uni_table);
g_uni_table = NULL;
}
if (g_gbk_table1 != NULL)
{
free((void*)g_gbk_table1);
g_gbk_table1 = NULL;
}
if (g_gbk_table2 != NULL)
{
free((void*)g_gbk_table2);
g_gbk_table2 = NULL;
}
if (g_gbk_table3 != NULL)
{
free((void*)g_gbk_table3);
g_gbk_table3 = NULL;
}
s_bInit = 0;
}
#endif
}
#define GET_GBK_WORD(table, s, e) \
if (pUnicodeIn[i] >= s && pUnicodeIn[i] <= e) \
{ \
iIndex = pUnicodeIn[i]-s; \
oneGbk = table[iIndex]; \
pGbk = (unsigned char*)&oneGbk; \
pGBKOut[j++] = *(pGbk+1); \
pGBKOut[j++] = *pGbk; \
continue; \
}
int MyUnicodeToGBK(char* pGBKOut, int iGbkBufSize, const unsigned short* pUnicodeIn)
{
unsigned char* pOneUnicode = NULL;
int len = 0;
int iIndex = 0;
int i = 0, j = 0;
if (!s_bInit)
return 0;
if (pUnicodeIn == NULL || pGBKOut == NULL || iGbkBufSize <= 2)
{
LOGI("pUnicodeIn == NULL || pGBKOut == NULL || iGbkBufSize <= 2");
return 0;
}
memset(pGBKOut, 0, iGbkBufSize);
len = myWcslen(pUnicodeIn);
for (i = 0, j = 0; i < len; i++)
{
unsigned char* pGbk = NULL;
unsigned short oneGbk = 0;
pOneUnicode = (unsigned char*)&pUnicodeIn[i];
if (j >= iGbkBufSize-1)
{
break;
}
if (pOneUnicode[1] == 0)
{// 半角字母符号
if (pOneUnicode[0] == 0xb7)
{
pGBKOut[j++] = 0xa1;
pGBKOut[j++] = 0xa4;
}
else if (pOneUnicode[0] == 0xB0)
{
pGBKOut[j++] = 0xA1;
pGBKOut[j++] = 0xE3;
}
else
{
pGBKOut[j++] = pOneUnicode[0];
}
}
else
{
GET_GBK_WORD(g_gbk_table1, UNICODE1_BEGIN, UNICODE1_END);// 汉字
GET_GBK_WORD(g_gbk_table2, UNICODE2_BEGIN, UNICODE2_END);// 全角字母符号
GET_GBK_WORD(g_gbk_table3, UNICODE3_BEGIN, UNICODE3_END);// 常用标点符号
}
}
j = j > iGbkBufSize-1 ? iGbkBufSize-1 : j;
pGBKOut[j] = '\0';
return 1;
}
int MyGBKToUnicode(unsigned short* pUnicodeOut, int iUniBufSize, const char* pGBKIn)
{
int i = 0;
int j = 0;
int len = 0;
int iIndex = 0;
unsigned char* pUnicode = NULL;
unsigned short oneGbkHanzi = 0;
unsigned char* pOneGbkHanzi = (unsigned char*)&oneGbkHanzi;
const unsigned char* pGBKInU = (const unsigned char*)pGBKIn;
if (!s_bInit)
return 0;
if (pUnicodeOut == NULL || pGBKIn == NULL || iUniBufSize <= 3)
{
LOGI("pUnicodeOut == NULL || pGBKIn == NULL || iUniBufSize <= 3");
return 0;
}
memset(pUnicodeOut, 0, iUniBufSize);
len = strlen(pGBKIn);
for (i = 0; i < len; i++)
{
if (j >= iUniBufSize/2-1)
{
break;
}
pUnicode = (unsigned char*)&pUnicodeOut[j];
if (pGBKInU[i] >= 0x00 && pGBKInU[i] <= 0x80)
{// 半角字母符号
*(pUnicode++) = pGBKInU[i];
*pUnicode = 0x00;
++j;
}
else if ((pGBKInU[i] >= 0x81 && pGBKInU[i] <= 0xFE)
&&(pGBKInU[i+1] >= 0x40 && pGBKInU[i+1] <= 0xFE)
&& (pGBKInU[i+1] != 0x7F)
)
{// 中文
pOneGbkHanzi[1] = pGBKInU[i];
pOneGbkHanzi[0] = pGBKInU[i+1];
iIndex = (pOneGbkHanzi[1]-0x81)*191+(pOneGbkHanzi[0]-0x40);
pUnicodeOut[j] = g_uni_table[iIndex];
++i;
++j;
}
}
// LOGI("unicode len = %d", j);
j = j > iUniBufSize/2-1 ? iUniBufSize/2-1 : j;
pUnicodeOut[j] = L'\0';
return 1;
}
static int GetUtf8Len(unsigned short* pUniStr)
{
int wideLen = 0;
int len = 0;
int i = 0;
if (pUniStr == NULL || (wideLen = myWcslen(pUniStr)) <= 0)
return 0;
for (i = 0; i < wideLen; i++)
{
unsigned short c = pUniStr[i];
if (c < 0x80)
{
len += 1;
}
else if (c < 0x800)
{
len += 2;
}
else if (c < 0x10000)
{
len += 3;
}
else if (c < 0x200000)
{
len += 4;
}
else if (c < 0x4000000)
{
len += 5;
}
else
{
len += 6;
}
}
return len;
}
static int unichar_to_utf8 (unsigned short c, char* outbuf)
{
/* If this gets modified, also update the copy in g_string_insert_unichar() */
size_t len = 0;
int first;
int i;
if (c < 0x80)
{
first = 0;
len = 1;
}
else if (c < 0x800)
{
first = 0xc0;
len = 2;
}
else if (c < 0x10000)
{
first = 0xe0;
len = 3;
}
else if (c < 0x200000)
{
first = 0xf0;
len = 4;
}
else if (c < 0x4000000)
{
first = 0xf8;
len = 5;
}
else
{
first = 0xfc;
len = 6;
}
if (outbuf)
{
for (i = len - 1; i > 0; --i)
{
outbuf[i] = (c & 0x3f) | 0x80;
c >>= 6;
}
outbuf[0] = c | first;
}
return len;
}
int MyGBKToUTF8_M(char** ppszOutUtf8, char* pszGbk)
{
int i = 0;
int iRet = 0;
int wideLenGuess = 0;
int wideLen = 0;
int utfLen = 0;
unsigned short* pUnicode = NULL;
if (ppszOutUtf8 == NULL || pszGbk == NULL || strlen(pszGbk) <= 0)
return 0;
wideLenGuess = (strlen(pszGbk)+1)*2;
pUnicode = (unsigned short*)malloc(wideLenGuess);
if (pUnicode == NULL)
{
LOGI("int MyGBKToUTF8_M malloc unicode buf fails!");
return 0;
}
memset(pUnicode, 0, wideLenGuess);
do {
if (0 == MyGBKToUnicode(pUnicode, wideLenGuess, pszGbk))
{
LOGI("MyGBKToUnicode fails in MyGBKToUTF8_M");
break;
}
wideLen = myWcslen(pUnicode);
utfLen = GetUtf8Len(pUnicode);
*ppszOutUtf8 = (char*)malloc(utfLen+1);
if (*ppszOutUtf8 == NULL)
{
break;
}
memset(*ppszOutUtf8, 0, utfLen+1);
for (i = 0; i < wideLen; i++)
{
char szTmpUtf8[7] = {0};
unichar_to_utf8(pUnicode[i], szTmpUtf8);
strcat(*ppszOutUtf8, szTmpUtf8);
}
iRet = 1;
}while (0);
SAFE_FREE(pUnicode);
return iRet;
}
/*************************************************************************************************
* UTF8编码转换成UnicodeUCS-2
*
* char* pInput '\0'
* char** ppOutput
*
* Unicode字符串的字节数-1
*
* 1. UTF8没有字节序问题Unicode字符有字节序
* Big EndianLittle Endian
* Intel处理器中采用小端法表示
* 2. *ppOutput
**************************************************************************************************/
static int utf8_to_unicode(char* pInput, char** ppOutput)
{
int outputSize = 0; //记录转换后的Unicode字符串的字节数
char *tmp = NULL;
if (pInput == NULL || strlen(pInput) <= 0)
return -1;
*ppOutput = (char *)malloc(strlen(pInput) * 2); //为输出字符串分配足够大的内存空间
memset(*ppOutput, 0, strlen(pInput) * 2);
tmp = *ppOutput; //临时变量,用于遍历输出字符串
while (*pInput)
{
if (*pInput > 0x00 && *pInput <= 0x7F) //处理单字节UTF8字符英文字母、数字
{
*tmp = *pInput;
tmp++;
*tmp = 0; //小端法表示在高地址填补0
}
else if (((*pInput) & 0xE0) == 0xC0) //处理双字节UTF8字符
{
char high = *pInput;
char low = 0;
pInput++;
low = *pInput;
if ((low & 0xC0) != 0x80) //检查是否为合法的UTF8字符表示
{
return -1; //如果不是则报错
}
*tmp = (high << 6) + (low & 0x3F);
tmp++;
*tmp = (high >> 2) & 0x07;
}
else if (((*pInput) & 0xF0) == 0xE0) //处理三字节UTF8字符
{
char high = *pInput;
char middle = 0;
char low = 0;
pInput++;
middle = *pInput;
pInput++;
low = *pInput;
if (((middle & 0xC0) != 0x80) || ((low & 0xC0) != 0x80))
{
return -1;
}
*tmp = (middle << 6) + (low & 0x7F);
tmp++;
*tmp = (high << 4) + ((middle >> 2) & 0x0F);
}
else //对于其他字节数的UTF8字符不进行处理
{
return -1;
}
pInput ++;
tmp ++;
outputSize += 2;
}
*tmp = 0;
tmp++;
*tmp = 0;
return outputSize;
}
int MyUTF8ToGBK_M(char** ppszOutGbk, char* pszUtf8)
{
int iRet = 0;
int unicodeBytes = 0;
unsigned short* pUnicodeStrChar = NULL;
if (ppszOutGbk == NULL || pszUtf8 == NULL || strlen(pszUtf8) <= 0)
return 0;
do {
unicodeBytes = utf8_to_unicode(pszUtf8, (char**)&pUnicodeStrChar);
if (unicodeBytes <= 0)
{
break;
}
*ppszOutGbk = (char*)malloc(unicodeBytes+1);
if (*ppszOutGbk == NULL)
{
break;
}
memset(*ppszOutGbk, 0, unicodeBytes+1);
if (0 == MyUnicodeToGBK(*ppszOutGbk, unicodeBytes+1, pUnicodeStrChar))
{
LOGI("MyUnicodeToGBK fails in MyUTF8ToGBK_M");
SAFE_FREE(*ppszOutGbk);
break;
}
iRet = 1;
} while(0);
SAFE_FREE(pUnicodeStrChar);
return iRet;
}

View File

@ -1,164 +0,0 @@
/*
* Gbk_Unicode.cpp
*
* Created on: 2010-7-7
* Author: Administrator
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include "Gbk_Unicode.h"
#define UNICODE_BEGIN (0x3001)
#define UNICODE_END (0x9FA5)
#define UNICODE_TOTAL (UNICODE_END-UNICODE_BEGIN+1)
#define UNICODE2_BEGIN (0xFF00)
#define UNICODE2_END (0xFFEF)
#define UNICODE2_TOTAL (UNICODE2_END-UNICODE2_BEGIN+1)
#define FONT_ROW_BEGIN 129
#define FONT_ROW_END 254
#define FONT_COL_BEGIN 64
#define FONT_COL_END 254
#define FONT_TOTAL (((FONT_ROW_END)-(FONT_ROW_BEGIN)+1)*((FONT_COL_END)-(FONT_COL_BEGIN)+1))
const unsigned short* gbk_table = NULL;
const unsigned short* gbk_table2 = NULL;
const unsigned short* uni_table = NULL;
int InitGbkUnicodeTable(char* szTablePath)
{
int ret = 0;
FILE* fp = NULL;
fp = fopen(szTablePath, "rb");
if (fp == NULL)
{
return 0;
}
gbk_table = (unsigned short*)malloc(UNICODE_TOTAL*2);
memset((void*)gbk_table, 0, UNICODE_TOTAL*2);
gbk_table2 = (unsigned short*)malloc(UNICODE2_TOTAL*2);
memset((void*)gbk_table2, 0, UNICODE2_TOTAL*2);
uni_table = (unsigned short*)malloc(FONT_TOTAL*2);
memset((void*)uni_table, 0, FONT_TOTAL*2);
ret = fread((void*)uni_table, FONT_TOTAL*2, 1, fp);
ret = fread((void*)gbk_table, UNICODE_TOTAL*2, 1, fp);
ret = fread((void*)gbk_table2, UNICODE2_TOTAL*2, 1, fp);
fclose(fp);
return 1;
}
void ReleaseGbkUnicodeTable(void)
{
if (gbk_table != NULL)
{
free((void*)gbk_table);
gbk_table = NULL;
}
if (gbk_table2 != NULL)
{
free((void*)gbk_table2);
gbk_table2 = NULL;
}
if (uni_table != NULL)
{
free((void*)uni_table);
uni_table = NULL;
}
}
void MyUnicodeToGBK(char* pGBKOut, wchar_t* pUnicodeIn)
{
char* pOneUnicode = NULL;
int len = wcslen(pUnicodeIn);
int iIndex = 0;
int i = 0, j = 0;
if (pUnicodeIn == NULL|| pGBKOut == NULL)
{
return;
}
for (i = 0, j = 0; i < len; i++)
{
unsigned char* pGbk = NULL;
unsigned short oneGbk = 0;
pOneUnicode = (char*)&pUnicodeIn[i];
if (pOneUnicode[1] == 0)
{// 半角字母符号
pGBKOut[j++] = pOneUnicode[0];
}
else
{
if (pUnicodeIn[i] >= UNICODE_BEGIN && pUnicodeIn[i] <= UNICODE_END)
{// 汉字
iIndex = pUnicodeIn[i]-UNICODE_BEGIN;
oneGbk = gbk_table[iIndex];
pGbk = (unsigned char*)&oneGbk;
pGBKOut[j++] = *(pGbk+1);
pGBKOut[j++] = *pGbk;
}
else if (pUnicodeIn[i] >=UNICODE2_BEGIN && pUnicodeIn[i] <= UNICODE2_END)
{// 全角字母符号
iIndex = pUnicodeIn[i]-UNICODE2_BEGIN;
oneGbk = gbk_table2[iIndex];
pGbk = (unsigned char*)&oneGbk;
pGBKOut[j++] = *(pGbk+1);
pGBKOut[j++] = *pGbk;
}
}
}
pGBKOut[j] = '\0';
}
void MyGBKToUnicode(wchar_t* pUnicodeOut, char* pGBKIn)
{
int i = 0;
int j = 0;
int len = 0;
int iIndex = 0;
unsigned char* pUnicode = NULL;
unsigned short oneGbkHanzi = 0;
unsigned char* pOneGbkHanzi = (unsigned char*)&oneGbkHanzi;
unsigned char* pGBKInU = (unsigned char*)pGBKIn;
if (pUnicodeOut == NULL || pGBKIn == NULL)
{
return;
}
len = strlen(pGBKIn);
for (i = 0; i < len; i++)
{
pUnicode = (unsigned char*)&pUnicodeOut[j];
if (pGBKInU[i] >= 0x00 && pGBKInU[i] <= 0x80)
{// 半角字母符号
*(pUnicode++) = pGBKInU[i];
*pUnicode = 0x00;;
++j;
}
else if ((pGBKInU[i] >= 0x81 && pGBKInU[i] <= 0xFE)
&&(pGBKInU[i+1] >= 0x40 && pGBKInU[i+1] <= 0xFE)
&& (pGBKInU[i+1] != 0x7F)
)
{// 中文
pOneGbkHanzi[1] = pGBKInU[i];
pOneGbkHanzi[0] = pGBKInU[i+1];
iIndex = (pOneGbkHanzi[1]-0x81)*191+(pOneGbkHanzi[0]-0x40);
pUnicodeOut[j] = uni_table[iIndex];
++i;
++j;
}
}
pUnicodeOut[j] = L'\0';
}

View File

@ -1,16 +1,42 @@
/*
* Gbk_Unicode.h
*
* Created on: 2010-7-7
* Author: Administrator
* Created on: 2011-9-12
* Author: dumganhar
*/
#ifndef GBK_UNICODE_H_
#define GBK_UNICODE_H_
int InitGbkUnicodeTable(char* szTablePath);
void ReleaseGbkUnicodeTable(void);
void MyUnicodeToGBK(char* pGBKOut, wchar_t* pUnicodeIn);
void MyGBKToUnicode(wchar_t* pUnicodeOut, char* pGBKIn);
#ifdef __cplusplus
extern "C" {
#endif
/*
* param:
* pGbkOut[out]:Gbk的缓冲
* iGbkBufSize[in]:Gbk的缓冲的大小, pGbkOut为数组, 使sizeof()
* pUnicodeIn[in]:unicode缓冲
* return: 0:, 1:
*/
int MyUnicodeToGBK(char* pGBKOut, int iGbkBufSize, const unsigned short* pUnicodeIn);
/*
* param:
* pUnicodeOut[out]:unicode的缓冲
* iUniBufSize[in]:unicode的缓冲的大小, pUnicodeOut为数组, 使sizeof()
* pGBKIn[in]:gbk缓冲
* return: 0:, 1:
*/
int MyGBKToUnicode(unsigned short* pUnicodeOut, int iUniBufSize, const char* pGBKIn);
// ppszOutUtf8为空指针的地址传入函数内部对其赋值_M结束的函数需要用free释放
int MyGBKToUTF8_M(char** ppszOutUtf8, char* pszGbk);
// ppszOutGbk为空指针的地址传入函数内部对其赋值_M结束的函数需要用free释放
int MyUTF8ToGBK_M(char** ppszOutGbk, char* pszUtf8);
#ifdef __cplusplus
}
#endif
#endif /* GBK_UNICODE_H_ */

View File

@ -0,0 +1 @@
91648ccc87a82401632a6369a47382bb438d3160

View File

@ -0,0 +1 @@
9260a2c16edf31510bf8a9205b1058140666ef81