Ejemplo n.º 1
0
int IsGBK(UC zi)
{
	int pos_offset;
	byte pos_mask,*pos;
	extern int GenGBKMapResource();

	if(!gbk_map)
	{
		gbk_map = GetReadOnlySharedMemory(gbkmap_share_name);

		//可能存在其他进程已经装载了,但是退出后共享内存被释放的问题
		if (!gbk_map && share_segment->gbkmap_loaded)
		{
			share_segment->gbkmap_loaded = 0;
			GenGBKMapResource();
		}
	}
	if(!gbk_map)
		return 1;

	if (zi > 0xFFFFF)
		return 0;

	////PUA
	//if ( !_tcscmp(pim_config->chinese_font_name,TEXT("微软雅黑")) && zi >= 0xE000 && zi <= 0xF8FF )
	//	return 0;

	pos_offset = zi >> 3;
	pos_mask = 1 << (zi % 8);

	pos = (byte*)(gbk_map + pos_offset);

	return (*pos) & pos_mask;
}
Ejemplo n.º 2
0
/**	获得汉字笔划的拼音串,用于显示笔划候选
 */
void GetZiBHPinyin(UC zi, TCHAR *buffer, int length)
{
	int  i, first;
	TCHAR s_str[0x30];
	int  s_len;
	SYLLABLE s;

	if (!buffer || !length || length < sizeof(HZ) + 1)
		return;

	if (!share_segment->hz_data_loaded)
		LoadHZDataResource();

	if (!hz_data)
	{
		hz_data = GetReadOnlySharedMemory(hz_data_share_name);

		//可能存在其他进程已经装载了,但是退出后共享内存被释放的问题
		if (!hz_data && share_segment->hz_data_loaded)
		{
			share_segment->hz_data_loaded = 0;
			LoadHZDataResource();
		}
	}

	if (!hz_data)
	{
		buffer[0] = 0;
		return;
	}

	UCS32ToUCS16(zi, buffer);

	first = 1;
	for (i = 0; i < hz_data->hz_count; i++)
	{
		if (hz_data->hz_item[i].hz != zi)
			continue;

		s	   = hz_data->hz_item[i].syllable;
		s_len  = GetSyllableString(s, s_str, _SizeOf(s_str),/* 0,*/ 1);

		if (s_len + (int)_tcslen(buffer) + 2 >= length - 1)
			return;

		if (first)
			_tcscat_s(buffer, length, TEXT("("));
		else
			_tcscat_s(buffer, length, TEXT(","));

		_tcscat_s(buffer, length, s_str);

		first = 0;
	}

	if (!first)
		_tcscat_s(buffer, length, TEXT(")"));
}
Ejemplo n.º 3
0
int FontCanSupport(UC zi)
{
	int pos_offset;
	byte pos_mask,*pos;
	TCHAR *fontname,*pos1,*pos2;
	extern int LoadFontMapResource();

	if(!share_segment->fontmap_loaded)
		return 1;
	//if font map data isn't loaded,return 1(support)
	if(!fontmap)
	{
		fontmap = GetReadOnlySharedMemory(fontmap_share_name);

		//可能存在其他进程已经装载了,但是退出后共享内存被释放的问题
		if (!fontmap && share_segment->fontmap_loaded)
		{
			share_segment->fontmap_loaded = 0;
			LoadFontMapResource();
		}
	}
	if(!fontmap)
		return 1;

	fontname = (TCHAR *)(fontmap + 0x6000);
	if (!fontname)
		return 1;
	pos1 = _tcsstr( fontname, pim_config->chinese_font_name );
	pos2 = _tcsstr( fontname, TEXT("{") );
	if (!pos1 || pos1 > pos2)
		return 1;

	if (!fontmap || zi > 0x2FFFF)
		return 1;

	//PUA
	if ( !_tcscmp(pim_config->chinese_font_name,TEXT("微软雅黑")) && zi >= 0xE000 && zi <= 0xF8FF )
		return 0;

	pos_offset = zi >> 3;
	pos_mask = 1 << (zi % 8);

	pos = (byte*)(fontmap + pos_offset);

	return (*pos) & pos_mask;
}
Ejemplo n.º 4
0
/*	获得汉字候选。
 *	参数:
 *		syllable		音节
 *		candidate_array	候选数组
 *		array_length	候选数组长度
 *		fuzzy_mode		模糊设置
 *		set_mode		汉字集合选项:常用(进化)、全集
 *		output_mode		字输出选项:繁体、简体
 *		注:如果为繁体,则肯定是全集汉字集合。
 *	返回:
 *		候选汉字数目。
 */
int GetZiCandidates(SYLLABLE syllable, CANDIDATE *candidate_array, int array_length, int fuzzy_mode, int set_mode, int output_mode)
{
	int i, j, count;		//候选计数器
	int topzi_count;		//置顶字数目
	HZ  top_zi[MAX_TOPZI];	//置顶字
	int check_top_zcs_fuzzy = 0;	//置顶字zcs模糊
	extern int LoadHZDataResource();

	if (!array_length)
		return 0;

	if (!share_segment->hz_data_loaded)
		LoadHZDataResource();

	if (!hz_data)
	{
		hz_data = GetReadOnlySharedMemory(hz_data_share_name);

		//可能存在其他进程已经装载了,但是退出后共享内存被释放的问题
		if (!hz_data && share_segment->hz_data_loaded)
		{
			share_segment->hz_data_loaded = 0;
			LoadHZDataResource();
		}
	}

	if (!hz_data)
		return 0;

	topzi_count = GetTopZi(syllable, top_zi);

	//由于s=是,c=出,z=中重 的设置,所以必须对zcs的模糊进行处理,找出
	//带有固定字的候选
	if (topzi_count && syllable.vow == VOW_NULL &&
		(syllable.con == CON_Z || syllable.con == CON_C || syllable.con == CON_S))
		check_top_zcs_fuzzy = 1;

	count = 0;
	//检索汉字
	for (i = 0; i < hz_data->hz_count; i++)
	{
		//判断简繁体是否符合
		if (!(
			((output_mode & HZ_OUTPUT_HANZI_ALL)) ||								//输出全集汉字
			((output_mode & HZ_OUTPUT_ICW_ZI) && hz_data->hz_item[i].icw_hz) ||			//输出ICW使用的汉字
			((output_mode & HZ_OUTPUT_SIMPLIFIED) && hz_data->hz_item[i].simplified) ||	//输出简体字,字是简体
			((output_mode & HZ_OUTPUT_TRADITIONAL) && (hz_data->hz_item[i].traditional || hz_data->hz_item[i].other))	//输出繁体字,字是繁体或该字未分类
			))
			continue;

		if (check_top_zcs_fuzzy)
		{
			if (!ContainSyllableWithTone(syllable, hz_data->hz_item[i].syllable, fuzzy_mode | FUZZY_Z_ZH | FUZZY_C_CH | FUZZY_S_SH))
				continue;

			//判断是否为置顶字
			for (j = 0; j < topzi_count; j++)
				if (top_zi[j] == LOWORD(hz_data->hz_item[i].hz))
					break;

			//不是置顶字的话,需要重新进行音调的判断
			if (j == topzi_count)
				if (!ContainSyllableWithTone(syllable, hz_data->hz_item[i].syllable, fuzzy_mode))
					continue;			//拼音不相符
		}
		else if (!ContainSyllableWithTone(syllable, hz_data->hz_item[i].syllable, fuzzy_mode))
			continue;			//拼音不相符

		candidate_array[count].type		  = CAND_TYPE_ZI;
		candidate_array[count].hz.is_word = 0;
		candidate_array[count].hz.item	  = &hz_data->hz_item[i];
		candidate_array[count].hz.hz_type = ZI_TYPE_NORMAL;

		//判断是否为置顶字
		for (j = 0; j < topzi_count; j++)
			if (top_zi[j] == LOWORD(hz_data->hz_item[i].hz))
				break;

		//设置置顶字序号,如果没有,则设为最大值
		if (j == topzi_count)
			j = DEFAULT_TOP_POS;

		candidate_array[count].hz.top_pos = j;

		count++;
		if (count >= array_length)			//数组过长
			break;
	}

	return count;
}