Проблемы со шрифтами Roboto в приложении на основе MFC

У меня есть старое приложение на основе MFC. Недавно мы перешли от Trébuchent к шрифту Roboto. С тех пор на некоторых машинах мы находим странные символы в приложении.

Я использую CreateFontIndirect функция для создания шрифта. Я использую среду разработки Visual Studio 2008.

Эта проблема не влияет на все приложение. Это влияет только на несколько мест.

Я заметил закономерность в этих барахлах. Похоже, что это добавляет 2 к каждому значению ASCII. Например: если я хочу отобразить ABCD, он показывает CDEF.

Пожалуйста, помогите мне найти это. Заранее спасибо.

Вот мой пример кода:

void Render (CDC *pDC)
{
CString strText;
    CFont *pFont = GetLocalFontStore()->LoadFont(_T("Roboto"), (int)(26 *fSizeFactor) , FW_EXTRABOLD, false, false);
COLORREF txtColor =RGB(255,0,0);
CRect rcTobeDrawn = CRect( (CPoint(177,172)), (CPoint(636,215)));
    strText = _T(“This is my string”);

CFont *pOldfont = pDC->SelectObject(pFont); 
    COLORREF oldTxtColor = pDC->SetTextColor(txtColor);
    int oldBkMode = pDC->SetBkMode(TRANSPARENT);

    pDC->DrawText(strText, rcTobeDrawn, DT_CENTER|DT_NOCLIP|DT_VCENTER);

    pDC->SelectObject(pOldfont);
    pDC->SetBkMode(oldBkMode);
    pDC->SetTextColor(oldTxtColor);

}

CFont* CLocalFontStore::LoadFont(CString strFaceName,int height,int weight/*=FW_REGULAR*/,
    bool bUnderLine/*=false*/,bool bItalics/* = false*/, BYTE charSet /*= DEFAULT_CHARSET*/,bool bHeightFlag/* = false*/)
{
    if(m_nCharSet == -1)
        m_nCharSet = GetCharset();

    LOGFONT lf;
    CFont* pFont = NULL;
    CString strFontText;
    memset(&lf, 0, sizeof(LOGFONT));
    swprintf_s(lf.lfFaceName,GetCommonLobby()->GetSupportedFontName(strFaceName));
    double d72DPIHeight = (STANDARD_DPI * (float)height) / 72.0;
    lf.lfHeight = (long) (d72DPIHeight < 0.0 ? ceil(d72DPIHeight - 0.5) : floor(d72DPIHeight + 0.5));
    lf.lfWeight = weight >0 ? weight : FW_DONTCARE;
    lf.lfUnderline = bUnderLine ? true :false;
    lf.lfItalic = bItalics;
    lf.lfCharSet = m_nCharSet;

    strFontText.Format(_T("%s~%d~%d~%d~%d~%d"), lf.lfFaceName, lf.lfHeight, lf.lfWeight, lf.lfUnderline, lf.lfItalic, m_nCharSet);

    if(m_FontMap.size() != 0)
        pFont = GetFont(strFontText);
    if(pFont == NULL)
    {
        HFONT hFont = GetIFontStore()->LoadFont(strFaceName, height, weight, bUnderLine, bItalics, charSet,bHeightFlag);
        if(hFont != NULL)
        {
            pFont = new CFont;
            pFont->Attach(hFont);
            m_FontMap[strFontText] = pFont;
        }
    }
    return pFont;
}

CFont* CLocalFontStore::LoadFont(CString strFaceName,int height,int weight/*=FW_REGULAR*/,
    bool bUnderLine/*=false*/,bool bItalics/* = false*/, BYTE charSet /*= DEFAULT_CHARSET*/,bool bHeightFlag/* = false*/)
{
    if(m_nCharSet == -1)
        m_nCharSet = GetCharset();

    LOGFONT lf;
    CFont* pFont = NULL;
    CString strFontText;
    memset(&lf, 0, sizeof(LOGFONT));
    swprintf_s(lf.lfFaceName,GetCommonLobby()->GetSupportedFontName(strFaceName));
    double d72DPIHeight = (STANDARD_DPI * (float)height) / 72.0;
    lf.lfHeight = (long) (d72DPIHeight < 0.0 ? ceil(d72DPIHeight - 0.5) : floor(d72DPIHeight + 0.5));
    lf.lfWeight = weight >0 ? weight : FW_DONTCARE;
    lf.lfUnderline = bUnderLine ? true :false;
    lf.lfItalic = bItalics;
    lf.lfCharSet = m_nCharSet;

    strFontText.Format(_T("%s~%d~%d~%d~%d~%d"), lf.lfFaceName, lf.lfHeight, lf.lfWeight, lf.lfUnderline, lf.lfItalic, m_nCharSet);

    if(m_FontMap.size() != 0)
        pFont = GetFont(strFontText);
    if(pFont == NULL)
    {
        HFONT hFont = GetIFontStore()->LoadFont(strFaceName, height, weight, bUnderLine, bItalics, charSet,bHeightFlag);
        if(hFont != NULL)
        {
            pFont = new CFont;
            pFont->Attach(hFont);
            m_FontMap[strFontText] = pFont;
        }
    }
    return pFont;
}

HFONT CFontStore::LoadPointFont(CString strFaceName,int height,int weight/*=FW_REGULAR*/,
    bool bUnderLine/*=false*/,bool bItalics/* = false*/, BYTE charSet /*= DEFAULT_CHARSET*/,bool bHeightFlag/* = false*/, bool bIsEnglish/* = false*/)
{
    LOGFONT lf;
    CString strFontText;
    memset(&lf, 0, sizeof(LOGFONT));
    if (!_tcsicmp(strFaceName, _T("Small Fonts")))
    {
        _stprintf(lf.lfFaceName, strFaceName);
    }
    else
    {
        _stprintf(lf.lfFaceName,GetCommonLobby()->GetSupportedFontName(strFaceName));
    }

    double d72DPIHeight = (STANDARD_DPI * (float)height) / 72.0;
    lf.lfHeight = (long) (d72DPIHeight < 0.0 ? ceil(d72DPIHeight - 0.5) : floor(d72DPIHeight + 0.5));
    lf.lfWeight = weight >0 ? weight : FW_DONTCARE;
    lf.lfUnderline = bUnderLine ? true :false;
    lf.lfItalic = bItalics;
    lf.lfCharSet = GetCharset();

    if(!bIsEnglish)
    {
        ChangeFont(lf, 10);
    }

    strFontText.Format(_T("%s~%d~%d~%d~%d~%d"),lf.lfFaceName,lf.lfHeight,lf.lfWeight,lf.lfUnderline,lf.lfItalic, GetCharset());

    HFONT hFont = NULL;
    if(m_FontMap.size() != 0)
    {
        hFont = GetFont(strFontText);
    }

    if(hFont == NULL)
    {
        lf.lfHeight = -lf.lfHeight;
        HFONT hf = CreateFontIndirect(&lf);
        if(NULL != hf)
        {
            hFont = hf;
            m_FontMap[strFontText] = hFont;
        }
    }

    return hFont;
}

0 ответов

Другие вопросы по тегам