Exemplo n.º 1
0
BOOL CFontPropPage::GetFontProps(CDataExchange* /* pDX */,
	FONTOBJECT* pfobj, LPCTSTR pszPropName, MERGEOBJECT* pmobj)
{
	USES_CONVERSION;
	BOOL bStatus = FALSE;

	COleDispatchDriver PropDispDriver;

	ULONG nObjects;
	LPDISPATCH* ppDisp = GetObjectArray(&nObjects);

	for (ULONG i = 0; i < nObjects; i++)
	{
		DISPID dwDispID;

		// Get the Dispatch ID for the property and if successful get the value
		LPCOLESTR lpOleStr = T2COLE(pszPropName);
		if (SUCCEEDED(ppDisp[i]->GetIDsOfNames(IID_NULL, (LPOLESTR*)&lpOleStr,
			1, m_lcid, &dwDispID)))
		{
			LPDISPATCH pFontDisp;

			// Get property
			PropDispDriver.AttachDispatch(ppDisp[i], FALSE);
			PropDispDriver.GetProperty(dwDispID, VT_DISPATCH, &pFontDisp);
			PropDispDriver.DetachDispatch();

			if (pFontDisp == NULL)
				continue;

			// Get font interface
			IFont * pFont;
			HRESULT hresult = pFontDisp->QueryInterface(IID_IFont, (void**)&pFont);
			if (hresult == S_OK)
			{
				BOOL bTemp;

				// Set font characteristics
				OLECHAR *pszName;
				pFont->get_Name(&pszName);
				if (lstrcmp(OLE2CT(pszName), pfobj->strName) != 0 && i != 0)
					pmobj->bNameOK = FALSE;
				pfobj->strName = pszName;
				SysFreeString(pszName);

				CY cyTemp;
				pFont->get_Size(&cyTemp);
				if ((cyTemp.Lo != pfobj->cySize.Lo || cyTemp.Hi != pfobj->cySize.Hi) && i != 0)
					pmobj->bSizeOK = FALSE;
				pfobj->cySize = cyTemp;

				pFont->get_Bold(&bTemp);
				if (pfobj->bBold != bTemp && i != 0)
					pmobj->bStyleOK = FALSE;
				pfobj->bBold = bTemp;

				pFont->get_Italic(&bTemp);
				if (pfobj->bItalic != bTemp && i != 0)
					pmobj->bStyleOK = FALSE;
				pfobj->bItalic = bTemp;

				pFont->get_Underline(&bTemp);
				if (pfobj->bUnderline != bTemp && i != 0)
					pmobj->bUnderlineOK = FALSE;
				pfobj->bUnderline = bTemp;

				pFont->get_Strikethrough(&bTemp);
				if (pfobj->bStrikethrough != bTemp && i != 0)
					pmobj->bStrikethroughOK = FALSE;
				pfobj->bStrikethrough = bTemp;

				short sTemp;

				pFont->get_Weight(&sTemp);
				if (pfobj->sWeight != sTemp && i != 0)
					pmobj->bStyleOK = FALSE;
				pfobj->sWeight = sTemp;

				// Release the font interface
				RELEASE(pFont);
				bStatus = TRUE;
			}

			// Release font interface
			RELEASE(pFontDisp);
		}
	}
	return bStatus;
}
Exemplo n.º 2
0
void C_DictionaryClient::LanguageChange()
{
    C_STLException::install();

    try {

        if (m_dic) {

            IFontDisp *fontdisp = NULL;

            m_dic->get_TranslationFont(&fontdisp);

            if (fontdisp) {

                IFont *font = NULL;
                fontdisp->QueryInterface(IID_IFont, reinterpret_cast<void**>(&font));

                if (font) {

                    BSTR bs = NULL;
                    CY cy;
                    BOOL bold = FALSE;
                    BOOL italic = FALSE;
                    short weight = FW_NORMAL;

                    font->get_Name(&bs);
                    font->get_Size(&cy);
                    font->get_Bold(&bold);
                    font->get_Italic(&italic);
                    font->get_Weight(&weight);

                    String name(bs);
                    String::FreeBSTR(&bs);

                    font->Release();

                    static C_NullDC null;
                    static int ppi = GetDeviceCaps(null.GetHandle(), LOGPIXELSY);

                    LOGFONT lf = {
                        cy.Lo * ppi / 560000,
                        0,
                        0,
                        0,
                        weight,
                        italic,
                        FALSE,
                        FALSE,
                        ANSI_CHARSET,
                        OUT_DEFAULT_PRECIS,
                        CLIP_DEFAULT_PRECIS,
                        DEFAULT_QUALITY | ANTIALIASED_QUALITY,
                        DEFAULT_PITCH | FF_DECORATIVE,
                        _T("Arial")
                    };

                    _stprintf(lf.lfFaceName, name.toLPCTSTR());

                    m_lFont = lf;
                }

                fontdisp->Release();
            }
        }
    }
    catch (C_STLNonStackException const &exception) {
        exception.Log(_T("Exception in C_DictionaryClient::LanguageChange"));
    }
}