diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 09716f9a5..92ea9dd4d 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -1511,6 +1511,18 @@ void NppParameters::setFontList(HWND hWnd) ::EnumFontFamiliesEx(hDC, &lf, EnumFontFamExProc, (LPARAM)&_fontlist, 0); } +bool NppParameters::isInFontList(const generic_string fontName2Search) const +{ + if (fontName2Search.empty()) + return false; + + for (size_t i = 0, len = _fontlist.size(); i < len; i++) + { + if (_fontlist[i] == fontName2Search) + return true; + } + return false; +} void NppParameters::getLangKeywordsFromXmlTree() { diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 282cf51d7..852f27f21 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1366,6 +1366,7 @@ public: void setCurLineHilitingColour(COLORREF colour2Set); void setFontList(HWND hWnd); + bool isInFontList(const generic_string fontName2Search) const; const std::vector& getFontList() const { return _fontlist; } int getNbUserLang() const {return _nbUserLang;} diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 2263370bf..9afd51545 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -428,6 +428,7 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa return _callWindowProc(_scintillaDefaultProc, hwnd, Message, wParam, lParam); } +#define DEFAULT_FONT_NAME "Courier New" void ScintillaEditView::setSpecialStyle(const Style & styleToSet) { @@ -441,8 +442,16 @@ void ScintillaEditView::setSpecialStyle(const Style & styleToSet) if (styleToSet._fontName && lstrcmp(styleToSet._fontName, TEXT("")) != 0) { WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); - const char * fontNameA = wmc->wchar2char(styleToSet._fontName, CP_UTF8); - execute(SCI_STYLESETFONT, (WPARAM)styleID, (LPARAM)fontNameA); + + if (not _pParameter->isInFontList(styleToSet._fontName)) + { + execute(SCI_STYLESETFONT, (WPARAM)styleID, (LPARAM)DEFAULT_FONT_NAME); + } + else + { + const char * fontNameA = wmc->wchar2char(styleToSet._fontName, CP_UTF8); + execute(SCI_STYLESETFONT, (WPARAM)styleID, (LPARAM)fontNameA); + } } int fontStyle = styleToSet._fontStyle; if (fontStyle != STYLE_NOT_USED)