Community
    • Login

    Fix npp displays Chinese characters in traditional characters in DirectWrite render mode since version 8.6

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    2 Posts 2 Posters 47 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Yan SerenadeY
      Yan Serenade
      last edited by

      Since Notepad++ 8.6 added DirectWrite as the default rendering method, the program displays Chinese characters in traditional characters, and modifying to GBK font cannot fix the issue; reverting to GDI rendering resolves the problem.
      1.jpg
      I tracked the issue:
      According to Scintilla’s description, DirectWrite determines which set of glyph variants to use for CJK characters based on localeName (locale name).
      The default values for Scintilla (see Platform.h) are:

      constexpr const char *localeNameDefault = "en-us";
      

      The repair method is as follows:
      After enabling DirectWrite, the correct font locale will be automatically set according to the system locale in the init method:
      Taking the notepad-plus-plus-8.9.2 source code as an example, modify the if statement starting from ScintillaEditView.cpp:482 to the following:
      3.jpg

      		// === New: Automatically set font locale based on system locale, and fix the issue with CJK font selection ===
      		wchar_t sysLocaleName[LOCALE_NAME_MAX_LENGTH] = { 0 };
      		if (GetUserDefaultLocaleName(sysLocaleName, LOCALE_NAME_MAX_LENGTH) > 0)
      		{
      			int len = WideCharToMultiByte(CP_UTF8, 0, sysLocaleName, -1, nullptr, 0, nullptr, nullptr);
      			if (len > 0)
      			{
      				std::string localeUtf8(len, '\0');
      				WideCharToMultiByte(CP_UTF8, 0, sysLocaleName, -1, &localeUtf8[0], len, nullptr, nullptr);
      				localeUtf8.resize(len - 1);
      				execute(SCI_SETFONTLOCALE, 0, reinterpret_cast<LPARAM>(localeUtf8.c_str()));
      			}
      		}
      		// === New end ===
      

      After DirectWrite initialization, this code reads the user’s system language (such as zh-CN) and notifies Scintilla to use the corresponding font variant through SCI_SETFONTLOCALE. This ensures that the Simplified Chinese system (zh-CN) correctly selects the Simplified Chinese font, while the Traditional Chinese system (zh-TW) selects the Traditional Chinese font.
      Finally result:
      2.jpg

      1 Reply Last reply Reply Quote 2
      • rdipardoR
        rdipardo
        last edited by

        Bravo!

        You may also be interested in this issue: “ANSI auto-completion shows garbled text when typing Chinese characters (since v8.8)”

        1 Reply Last reply Reply Quote 1
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors