From 7d6bfcc3a927028e8202f0afe55bce366c0d6dca Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 4 Jul 2019 11:09:47 +0200 Subject: [PATCH] + fix: encoding detection failure fallback: current code-page or default encoding on new (if fallback forced) + chg: to force UTF-8 as preffered encoding: activate encoding detection failure fallback for default encoding + chg: allow Fixedsys font for GDI rendering + chg: for new "Text File" scheme: use regular Segoe UI font --- Versions/build.txt | 2 +- res/Notepad3.exe.manifest.conf | 2 +- src/ChooseFont/ChooseFont.cpp | 10 +++++----- src/Config/Config.cpp | 2 +- src/Edit.c | 26 +++++++++++++++++++------- src/StyleLexers/styleLexStandard.c | 4 ++-- src/Styles.c | 2 +- src/Version.h | 2 +- src/VersionEx.h | 4 ++-- 9 files changed, 33 insertions(+), 21 deletions(-) diff --git a/Versions/build.txt b/Versions/build.txt index 76bfd63d0..febba2821 100644 --- a/Versions/build.txt +++ b/Versions/build.txt @@ -1 +1 @@ -2382 +2383 diff --git a/res/Notepad3.exe.manifest.conf b/res/Notepad3.exe.manifest.conf index 325beede9..044dc2fbd 100644 --- a/res/Notepad3.exe.manifest.conf +++ b/res/Notepad3.exe.manifest.conf @@ -3,7 +3,7 @@ Notepad3 Oniguruma diff --git a/src/ChooseFont/ChooseFont.cpp b/src/ChooseFont/ChooseFont.cpp index 6407a2165..01b347930 100644 --- a/src/ChooseFont/ChooseFont.cpp +++ b/src/ChooseFont/ChooseFont.cpp @@ -49,8 +49,8 @@ class ChooseFontDialog { public: - explicit ChooseFontDialog(HWND hParent, const WCHAR* localeName, DPI_T dpi, LPCHOOSEFONT lpCFGDI); - virtual ~ChooseFontDialog(); + ChooseFontDialog(HWND hParent, const WCHAR* localeName, DPI_T dpi, LPCHOOSEFONT lpCFGDI); + ~ChooseFontDialog(); ChooseFontDialog() = delete; HRESULT GetTextFormat(IDWriteTextFormat** textFormat); @@ -131,7 +131,7 @@ ChooseFontDialog::~ChooseFontDialog() /****************************************************************** * * -* ChooseFontDialog::ChooseFontDialog * +* ChooseFontDialog::GetTextFormat * * * * Create and display the dialog initialized to default attributes * * * @@ -696,7 +696,7 @@ BOOL ChooseFontDialog::OnInitDialog(HWND dialog, HWND hwndFocus, LPARAM lParam) } // Select the current size - FLOAT fCurFontSize = static_cast(round(m_currentTextFormat->GetFontSize() * 10.0f) / 10.0f); + FLOAT fCurFontSize = static_cast(roundf(m_currentTextFormat->GetFontSize() * 10.0f) / 10.0f); StringCchPrintf(sizeName, _ARRAYSIZE(sizeName), L"%.3G", fCurFontSize); SetWindowText(hwndSizes, sizeName); @@ -791,7 +791,7 @@ static void SetChosenFontFromTextFormat( StringCchCopy(lpCF->lpLogFont->lfFaceName, LF_FACESIZE, fontFamilyName); lpCF->lpLogFont->lfHeight = -MulDiv(static_cast(lround(pointSize)), GetDeviceCaps(lpCF->hDC, LOGPIXELSY), 72); - lpCF->iPointSize = static_cast(lround(pointSize * 10.0f)); + lpCF->iPointSize = static_cast(lroundf(pointSize * 10.0f)); lpCF->lpLogFont->lfWeight = static_cast(fontWeight); lpCF->lpLogFont->lfItalic = static_cast((((fontStyle == DWRITE_FONT_STYLE_ITALIC) || (fontStyle == DWRITE_FONT_STYLE_OBLIQUE)) ? TRUE : FALSE)); diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index 9a016602a..8c6568c6c 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -829,7 +829,7 @@ void LoadSettings() cpi_enc_t const iPrefEncIniSetting = (cpi_enc_t)Encoding_MapIniSetting(false, (int)CPI_UTF8); GET_ENC_VALUE_FROM_INISECTION(DefaultEncoding, iPrefEncIniSetting, CPI_NONE, INT_MAX); Settings.DefaultEncoding = ((Settings.DefaultEncoding == CPI_NONE) ? CPI_UTF8 : (cpi_enc_t)Encoding_MapIniSetting(true, (int)Settings.DefaultEncoding)); - GET_BOOL_VALUE_FROM_INISECTION(UseDefaultForFileEncoding, false); + GET_BOOL_VALUE_FROM_INISECTION(UseDefaultForFileEncoding, true); GET_BOOL_VALUE_FROM_INISECTION(LoadASCIIasUTF8, true); GET_BOOL_VALUE_FROM_INISECTION(UseReliableCEDonly, true); GET_BOOL_VALUE_FROM_INISECTION(LoadNFOasOEM, true); diff --git a/src/Edit.c b/src/Edit.c index 0f3e1bd45..652e533c7 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -1014,7 +1014,8 @@ bool EditLoadFile( // Encoding Detection // -------------------------------------------------------------------------- - cpi_enc_t iPreferredEncoding = Settings.LoadASCIIasUTF8 ? CPI_UTF8 : CPI_ANSI_DEFAULT; + // assume current code-page or default encoding (if forced) + cpi_enc_t const iAnalyzeFallback = Settings.UseDefaultForFileEncoding ? Settings.DefaultEncoding : CPI_ANSI_DEFAULT; // --- 1st check for force encodings --- LPCWSTR lpszExt = PathFindExtension(pszFile); @@ -1033,7 +1034,7 @@ bool EditLoadFile( if (Encoding_IsNONE(iForcedEncoding) || bForceEncDetection) { - iAnalyzedEncoding = Encoding_AnalyzeText(lpData, cbNbytes4Analysis, &confidence, iPreferredEncoding); + iAnalyzedEncoding = Encoding_AnalyzeText(lpData, cbNbytes4Analysis, &confidence, iAnalyzeFallback); if (Flags.bDevDebugMode) { #if 1 @@ -1048,7 +1049,6 @@ bool EditLoadFile( #endif } } - bool const bIsReliable = (confidence >= Settings2.AnalyzeReliableConfidenceLevel); // ------------------------------------------------------ @@ -1056,18 +1056,29 @@ bool EditLoadFile( { bool const bIsUnicode = Encoding_IsUTF8(iAnalyzedEncoding) || Encoding_IsUNICODE(iAnalyzedEncoding); - if (iAnalyzedEncoding == CPI_ASCII_7BIT) { - iAnalyzedEncoding = Settings.LoadASCIIasUTF8 ? CPI_UTF8 : iPreferredEncoding; // stay on preferred + if (iAnalyzedEncoding == CPI_NONE) + { + iAnalyzedEncoding = iAnalyzeFallback; + confidence = Settings2.AnalyzeReliableConfidenceLevel; + } + else if (iAnalyzedEncoding == CPI_ASCII_7BIT) { + iAnalyzedEncoding = Settings.LoadASCIIasUTF8 ? CPI_UTF8 : CPI_ANSI_DEFAULT; + confidence = Settings2.AnalyzeReliableConfidenceLevel; } else { if ((bSkipUTFDetection && bIsUnicode) || (bSkipANSICPDetection && !bIsUnicode)) { iAnalyzedEncoding = CPI_NONE; + confidence = 0.0; } } } + + bool const bIsReliable = (confidence >= Settings2.AnalyzeReliableConfidenceLevel); + // -------------------------------------------------------------------------- - if (bForceEncDetection && !Encoding_IsNONE(iAnalyzedEncoding)) { + if (bForceEncDetection && !Encoding_IsNONE(iAnalyzedEncoding)) + { iForcedEncoding = iAnalyzedEncoding; // no bIsReliable check (forced unreliable detection) } // -------------------------------------------------------------------------- @@ -1080,7 +1091,8 @@ bool EditLoadFile( // choose best encoding guess cpi_enc_t const iFileEncWeak = Encoding_SrcWeak(CPI_GET); - // remap Preferred Encoding + // set Preferred Encoding + cpi_enc_t iPreferredEncoding = Settings.LoadASCIIasUTF8 ? CPI_UTF8 : CPI_ANSI_DEFAULT; if (bIsForced) { iPreferredEncoding = iForcedEncoding; diff --git a/src/StyleLexers/styleLexStandard.c b/src/StyleLexers/styleLexStandard.c index a0ae56d60..d677f38a9 100644 --- a/src/StyleLexers/styleLexStandard.c +++ b/src/StyleLexers/styleLexStandard.c @@ -20,7 +20,7 @@ SCLEX_NULL, IDS_LEX_DEF_TXT, L"Default Text", L"", L"", /* 10 */ { {_STYLE_GETSTYLEID(STY_LONG_LN_MRK)}, IDS_LEX_STD_LONG_LN, L"Long Line Marker (Colors)", L"fore:#FFC000", L"" }, /* 11 */ { {_STYLE_GETSTYLEID(STY_X_LN_SPACE)}, IDS_LEX_STD_X_SPC, L"Extra Line Spacing (Size)", L"size:2", L"" }, /* 12 */ { {_STYLE_GETSTYLEID(STY_BOOK_MARK)}, IDS_LEX_STD_BKMRK, L"Bookmarks and Folding (Colors, Size)", L"size:+2; fore:#000000; back:#00DC00; alpha:100", L"" }, - /* 13 */ { {_STYLE_GETSTYLEID(STY_MARK_OCC)}, IDS_LEX_STR_63262, L"Mark Occurrences (Indicator)", L"alpha:60; alpha2:60; indic_roundbox", L"" }, + /* 13 */ { {_STYLE_GETSTYLEID(STY_MARK_OCC)}, IDS_LEX_STR_63262, L"Mark Occurrences (Indicator)", L"fore:#3399FF; alpha:60; alpha2:60; indic_roundbox", L"" }, /* 14 */ { {_STYLE_GETSTYLEID(STY_URL_HOTSPOT)}, IDS_LEX_STR_63264, L"Hyperlink Hotspots", L"fore:#0000FF; back:#0000BF; indic_plain", L"" }, /* 15 */ { {_STYLE_GETSTYLEID(STY_MULTI_EDIT)}, IDS_LEX_STR_63354, L"Multi Edit Indicator", L"fore:#FFA000; alpha:60; alpha2:180; indic_roundbox", L"" }, /* 16 */ { {_STYLE_GETSTYLEID(STY_IME_COLOR)}, IDS_LEX_STR_63352, L"Inline-IME Color", L"fore:#00AA00", L"" }, @@ -53,7 +53,7 @@ SCLEX_NULL, IDS_LEX_STR_63266, L"2nd Default Text", L"", L"", EDITLEXER lexTEXT = { SCLEX_NULL, IDS_LEX_TEXT_FILES, L"Text Files", L"txt; text; tmp; log; asc; doc; wtx", L"", &KeyWords_NULL,{ - { {STYLE_DEFAULT}, IDS_LEX_STR_63126, L"Default", L"font:Segoe UI Semibold; size:11; semibold; smoothing:cleartype", L"" }, + { {STYLE_DEFAULT}, IDS_LEX_STR_63126, L"Default", L"font:Segoe UI; size:11; smoothing:cleartype", L"" }, { {STYLE_LINENUMBER}, IDS_LEX_STD_MARGIN, L"Margins and Line Numbers", L"font:Lucida Console; size:-2", L"" }, { {SCI_SETEXTRAASCENT + SCI_SETEXTRADESCENT}, IDS_LEX_STD_X_SPC, L"Extra Line Spacing (Size)", L"size:-1", L"" }, EDITLEXER_SENTINEL } }; diff --git a/src/Styles.c b/src/Styles.c index ad59550a4..4bd1d89ce 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -3013,7 +3013,7 @@ bool Style_SelectFont(HWND hwnd,LPWSTR lpszStyle,int cchStyle, LPCWSTR sLexerNam cf.lCustData = (LPARAM)FontSelTitle; //cf.Flags = CF_INITTOLOGFONTSTRUCT /*| CF_EFFECTS | CF_NOSCRIPTSEL*/ | CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_ENABLEHOOK; //cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_USESTYLE | CF_SCALABLEONLY | CF_FORCEFONTEXIST | CF_ENABLEHOOK; - cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCALABLEONLY | CF_FORCEFONTEXIST | CF_ENABLEHOOK; + cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS | CF_INACTIVEFONTS | CF_FORCEFONTEXIST | CF_ENABLEHOOK; if (bGlobalDefaultStyle) { if (bRelFontSize) diff --git a/src/Version.h b/src/Version.h index efb85e09c..fa2608e61 100644 --- a/src/Version.h +++ b/src/Version.h @@ -68,7 +68,7 @@ #if defined(_MSC_VER) #if (_MSC_VER >= 1920) #if(_MSC_FULL_VER >= 192127702) - #define VER_CPL MS Visual C++ 2019 v16.1.(0-4) + #define VER_CPL MS Visual C++ 2019 v16.1.(0-5) #elif(_MSC_FULL_VER >= 192027508) #define VER_CPL MS Visual C++ 2019 v16.0.(0-4) #elif(_MSC_FULL_VER >= 192027027) diff --git a/src/VersionEx.h b/src/VersionEx.h index b43ee6e27..737966af5 100644 --- a/src/VersionEx.h +++ b/src/VersionEx.h @@ -7,8 +7,8 @@ #define SAPPNAME "Notepad3" #define VERSION_MAJOR 5 #define VERSION_MINOR 19 -#define VERSION_REV 702 -#define VERSION_BUILD 2382 +#define VERSION_REV 704 +#define VERSION_BUILD 2383 #define SCINTILLA_VER 417 #define ONIGURUMA_REGEX_VER 6.9.2 #define VERSION_PATCH Oniguruma