/*---------------------------------------------------------------------------------------------- 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; }
/*---------------------------------------------------------------------------------------------- Initialize the list of encodings from the writing system factory. ----------------------------------------------------------------------------------------------*/ void WpFormatWsDlg::InitEncList() { int cws; ILgWritingSystemFactoryPtr qwsf; qwsf.CreateInstance(CLSID_LgWritingSystemFactory); // Get the memory-based factory. CheckHr(qwsf->get_NumberOfWs(&cws)); int * prgenc = NewObj int[cws]; CheckHr(qwsf->GetWritingSystems(prgenc)); int wsUser; CheckHr(qwsf->get_UserWs(&wsUser)); for (int iws = 0; iws < cws; iws++) { if (prgenc[iws] == 0) continue; IWritingSystemPtr qws; CheckHr(qwsf->get_Engine(prgenc[iws], &qws)); if (!qws) continue; // Generate the name to use for the writing system. SmartBstr sbstr; CheckHr(qws->get_UiName(wsUser, &sbstr)); if (!sbstr) continue; StrUni stu(sbstr.Chars()); StrApp str = stu; m_vws.Push(prgenc[iws]); m_vstr.Push(str); } Assert(m_vws.Size() == m_vstr.Size()); // Sort the encodings by name. for (iws = 0; iws < m_vws.Size() - 1; iws++) { for (int iws2 = iws + 1; iws2 < m_vws.Size(); iws2++) { if (m_vstr[iws] > m_vstr[iws2]) { StrApp strTmp = m_vstr[iws]; int encTmp = m_vws[iws]; m_vstr[iws] = m_vstr[iws2]; m_vws[iws] = m_vws[iws2]; m_vstr[iws2] = strTmp; m_vws[iws2] = encTmp; } } if (m_vws[iws] == m_wsInit) m_iwsInit = iws; } delete[] prgenc; }