Пример #1
0
static IFontDisp *QFontToIFont(const QFont &font)
{
#if defined(Q_OS_WINCE)
    Q_UNUSED(font);
    return 0;
#else
    FONTDESC fdesc;
    memset(&fdesc, 0, sizeof(fdesc));
    fdesc.cbSizeofstruct = sizeof(FONTDESC);
    fdesc.cySize.Lo = font.pointSize() * 10000;
    fdesc.fItalic = font.italic();
    fdesc.fStrikethrough = font.strikeOut();
    fdesc.fUnderline = font.underline();
    fdesc.lpstrName = QStringToBSTR(font.family());
    fdesc.sWeight = font.weight() * 10;
    
    IFontDisp *f;
    HRESULT res = OleCreateFontIndirect(&fdesc, IID_IFontDisp, (void**)&f);
    if (res != S_OK) {
        if (f) f->Release();
        f = 0;
#if defined(QT_CHECK_STATE)
        qWarning("QFontToIFont: Failed to create IFont");
#endif
    }
    return f;
#endif
}
Пример #2
0
void CMyAxCtrl::OnFontChanged()
{
   // Always set it to the container's font
   if (m_MyEdit.m_hWnd != NULL)
   {
      IFontDisp* pFontDisp = NULL;
      IFont *pFont = NULL;
      HRESULT hr;

      // Get the container's FontDisp interface
      pFontDisp = AmbientFont();
      if (pFontDisp)
      {
         hr = pFontDisp->QueryInterface(IID_IFont, (LPVOID *) &pFont);
         if (FAILED(hr))
         {
            pFontDisp->Release();
            return;
         }
      }

      HFONT hFont = NULL;
      if (pFont)
      {
         pFont->get_hFont(&hFont);
         m_MyEdit.SendMessage(WM_SETFONT, (WPARAM)hFont, 0L);
      }

      pFontDisp->Release();
   }

   // Invalidate the control
   m_MyEdit.Invalidate();
   m_MyEdit.UpdateWindow();
   
   COleControl::OnFontChanged();
}
Пример #3
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"));
    }
}