Pergunta

Eu quero escrever a seguinte função

bool IsFontExistInSystem(const CString& fontStyle) const
{

}

Existe alguma API do Windows para fazer isso? Muito obrigado!

Foi útil?

Solução

Aqui está algum código antigo eu cavei fora, que vai verificar se a fonte está instalada. Ele pode fazer com sendo arrumado, mas você começa a idéia:

static int CALLBACK CFontHelper::EnumFontFamExProc(ENUMLOGFONTEX* /*lpelfe*/, NEWTEXTMETRICEX* /*lpntme*/, int /*FontType*/, LPARAM lParam)
{
    LPARAM* l = (LPARAM*)lParam;
    *l = TRUE;
    return TRUE;
}

bool Font::IsInstalled(LPCTSTR lpszFont)
{
    // Get the screen DC
    CDC dc;
    if (!dc.CreateCompatibleDC(NULL))
    {
        return false;
    }
    LOGFONT lf = { 0 };
    // Any character set will do
    lf.lfCharSet = DEFAULT_CHARSET;
    // Set the facename to check for
    _tcscpy(lf.lfFaceName, lpszFont);
    LPARAM lParam = 0;
    // Enumerate fonts
    ::EnumFontFamiliesEx(dc.GetSafeHdc(), &lf,  (FONTENUMPROC)EnumFontFamExProc, (LPARAM)&lParam, 0);
    return lParam ? true : false;
}

Outras dicas

Você pode usar EnumFontFamiliesEx para descobrir se existe fonte real.

UPD:. Acabei de saber que ele é recomendado por MS de usar EnumFontFamiliesEx vez de EnumFontFamilies

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top