コード例 #1
0
/*----------------------------------------------------------------------------------------------
	Return the ISO-639-3 language code, cast to an unsigned int.
----------------------------------------------------------------------------------------------*/
isocode FwGrTxtSrc::getLanguage(toffset ich)
{
	LgCharRenderProps lgchrp;
	int ichMinBogus, ichLimBogus;
	GrResult res = (GrResult)m_qts->GetCharProps(GrToVwOffset(ich), &lgchrp, &ichMinBogus, &ichLimBogus);

	int ws = lgchrp.ws;

	ILgWritingSystemFactoryPtr qwsf;
	IWritingSystemPtr qws;
	CheckHr(m_qts->GetWsFactory(&qwsf));
	if (qwsf)
	{
		CheckHr(qwsf->get_EngineOrNull(ws, &qws));
	}
	else
	{
		qwsf.CreateInstance(CLSID_LgWritingSystemFactory);	// Get the memory-based factory.
		CheckHr(qwsf->get_EngineOrNull(ws, &qws));
	}

	isocode code;
	if (!qws)
	{
		memset(code.rgch, 0, sizeof(char) * 4);
		return code;
	}

	SmartBstr bstrLang, bstrScript, bstrCountry, bstrVariant;
	CheckHr(qws->GetIcuLocaleParts(&bstrLang, &bstrScript, &bstrCountry, &bstrVariant));

	for (int i = 0; i < 4; i++)
		code.rgch[i] = (char)(i >= bstrLang.Length() ? 0 : bstrLang[i]);
	return code;
}