diff --git a/program/country/default.cpp b/program/country/default.cpp new file mode 100644 index 0000000..2f6211d --- /dev/null +++ b/program/country/default.cpp @@ -0,0 +1,96 @@ +#include +#include "default.h" + +namespace default { + + /** + * @brief 必要とされる文字列 + */ + tstring _neededString; + + /** + * Charsetに対するEnumFontFamiliesExのコールバック + * + * @param lpelfe 論理的なフォントデータ + * @param lpntme 物理的なフォントデータ + * @param FontType フォントの種類 + * @param lParam アプリケーション定義のデータ + * @return 0:列挙を中止する 1:次のフォントを列挙する。 + */ + int CALLBACK EnumFontCharsetProc( + ENUMLOGFONTEX *lpelfe, // 論理的なフォントデータ + NEWTEXTMETRICEX *lpntme, // 物理的なフォントデータ + DWORD FontType, // フォントの種類 + LPARAM lParam // アプリケーション定義のデータ + ) + { + if (_neededString == lpelfe->elfFullName) { + return 0; + } + + return 1; + + } + + /** + * Charsetに対するフォントを取得する + * + * @return 0:フォントが存在する 1:フォントは存在しない + */ + int findCharsetFont() + { + LOGFONT lf; + + lf.lfPitchAndFamily = 0; + lf.lfCharSet = DEFAULT_CHARSET; + + HDC hDC; + hDC = GetDC(GetDesktopWindow()); + + int found = 1; + found = ::EnumFontFamiliesEx( + hDC, + &lf, + (FONTENUMPROC)EnumFontCharsetProc, + (LPARAM)0, + 0 + ); + + return found; + } + + /** + * Write fallback font when font specified in language file is not found. + * For example in Japanese, use Yu Gothic -> MS UI Gothic + * Use this routine, unfortunately system font selection is too ugly such as Japan. + * If you want to use language and Windows version specific fallback, copy this source for your country + * and modify font name in language specific font name which is installed all Windows in your country. + * + * @brief Determine exist font for default languages. + * @param settingString Preferred font name + * @return Choiced font name + */ + tstring getDefaultFontFallback(tstring &settingString) + { + int result = 1; + + _neededString = settingString; + + result = findCharsetFont(); + if (result == 0) { + return settingString; + } + + _neededString = _T("MS Shell Dlg"); + result = findCharsetFont(); + if (result == 0) { + return _neededString; + } + + _neededString = _T("Arial"); + + return _neededString; + + } + +} diff --git a/program/country/default.h b/program/country/default.h new file mode 100644 index 0000000..66c07a8 --- /dev/null +++ b/program/country/default.h @@ -0,0 +1,16 @@ +/* +noMeiryoUI (C) 2005,2012-2023 Tatsuhiko Shoji +The sources for noMeiryoUI are distributed under the MIT open source license +*/ + +#pragma once + +#include +#include +#include + +namespace default { + + extern tstring getDefaultFontFallback(tstring &settingString); + +}; diff --git a/program/noMeiryoUI.cpp b/program/noMeiryoUI.cpp index 2a3ba3f..ec5b066 100644 --- a/program/noMeiryoUI.cpp +++ b/program/noMeiryoUI.cpp @@ -21,7 +21,8 @@ The sources for noMeiryoUI are distributed under the MIT open source license #include "NCFileDialog.h" #include "util.h" -// #include "country\japan.h" +#include "country\default.h" +#include "country\japan.h" #include "country\korea.h" // @@ -95,6 +96,7 @@ void initializeLocale(void) if (!readResult) { has11Preset = false; } + } /** @@ -137,12 +139,7 @@ void setResourceFileName(TCHAR * langFileName, TCHAR * helpFileName, char*system } // Language detection - if (wcsstr(langWork, L"ja-JP") != NULL) { - runningCountry = Japan; - } - if (wcsstr(langWork, L"ko-KR") != NULL) { - runningCountry = Korea; - } + setLocationInternalCode(langWork); _tcscpy(findPath, iniPath); TCHAR *p = _tcsrchr(langWork, _T('.')); @@ -188,6 +185,23 @@ void setResourceFileName(TCHAR * langFileName, TCHAR * helpFileName, char*system } } +/** + * @brief Set internal lanuguage enumeration + * @param langWork Locale name +*/ +void setLocationInternalCode(TCHAR langWork[85]) +{ + if (wcsstr(langWork, L"ja-JP") != NULL) { + runningCountry = Japan; + return; + } + if (wcsstr(langWork, L"ko-KR") != NULL) { + runningCountry = Korea; + return; + } + runningCountry = NoCountry; +} + /** * _CAOv[VW * @@ -818,12 +832,9 @@ void NoMeiryoUI::applyResource() tstring font = langResource[0]; -#if 0 - // Under construction - if (runningCountry == Japan) { - font = japan::getJapaneseFontFallback(langResource[0]); - } -#endif + // Get fallback font + font = getLanguageFallbackForCountry(langResource[0]); + HFONT displayFont = CreateFont( -MulDiv(APP_FONTSIZE, GetDeviceCaps(hDC, LOGPIXELSY), 72), @@ -919,6 +930,26 @@ void NoMeiryoUI::applyResource() //DeleteObject(newFont); } +/** + * @brief Get fallback font when font settings in language file didn't exist in Windows(For example older Windows) + * @param settingString Application display font name in language file. + * @return Font name adjusted by font installed in Windows. +*/ +tstring NoMeiryoUI::getLanguageFallbackForCountry(tstring &settingString) +{ + tstring font; + + switch (runningCountry) { + case Japan: + font = japan::getJapaneseFontFallback(langResource[0]); + break; + default: + font = default::getDefaultFontFallback(langResource[0]); + break; + } + + return font; +} /** * tHg\XVB diff --git a/program/noMeiryoUI.h b/program/noMeiryoUI.h index 2aa06d1..88c99e5 100644 --- a/program/noMeiryoUI.h +++ b/program/noMeiryoUI.h @@ -24,6 +24,8 @@ BOOL CALLBACK MonitorNearWindowCallback( BOOL CALLBACK setWindowSize(HWND hWnd, LPARAM lparam); void setResourceFileName(TCHAR* langFileName, TCHAR* helpFileName, char* localeName, TCHAR *iniPath); +void setLocationInternalCode(TCHAR langWork[85]); + /** tHg̃|Cgۑ\ */ struct FontPoints { /** ^Cgo[tHgTCY(Point) */ @@ -134,6 +136,7 @@ class NoMeiryoUI : public DialogAppliBase { void getOption(TCHAR *lpCmdLine); void parseOption(TCHAR *param, int argCount); void applyResource(); + tstring getLanguageFallbackForCountry(tstring &settingString); void showVersion(void); void adjustWindowSize(void); diff --git a/program/noMeiryoUI.vcxproj b/program/noMeiryoUI.vcxproj index 6ca5d66..d78cc9c 100644 --- a/program/noMeiryoUI.vcxproj +++ b/program/noMeiryoUI.vcxproj @@ -183,6 +183,7 @@ + @@ -206,6 +207,7 @@ + diff --git a/program/noMeiryoUI.vcxproj.filters b/program/noMeiryoUI.vcxproj.filters index 7e17d45..a42322f 100644 --- a/program/noMeiryoUI.vcxproj.filters +++ b/program/noMeiryoUI.vcxproj.filters @@ -75,6 +75,9 @@ ソース ファイル\country + + ソース ファイル\country + @@ -140,6 +143,9 @@ ヘッダー ファイル\country + + ヘッダー ファイル\country + diff --git a/program/util.h b/program/util.h index 6153d67..1841505 100644 --- a/program/util.h +++ b/program/util.h @@ -105,8 +105,8 @@ void readResourceFile(TCHAR *file); int readFontResource8(TCHAR *file); int readFontResource10(TCHAR *file); int readFontResource11(TCHAR* file); +void setLocationInternalCode(TCHAR langWork[85]); void adjustCenter(RECT parentRect, HWND parentHWnd, HWND myHWnd); -void getKoreanFontName(TCHAR *dispBuf); void strreplace(TCHAR* buf, const TCHAR* source, const TCHAR* oldWord, const TCHAR* newWord, int bufLen); BOOL isWin11OrLater(DWORD& buildNumber); DWORD GetVersionForApp(DWORD &majorVersion, DWORD &minorVersion, DWORD& buildNumber);