diff --git a/scintilla/src/ViewStyle.cxx b/scintilla/src/ViewStyle.cxx index 7d1bdcfa2..de7f816a7 100644 --- a/scintilla/src/ViewStyle.cxx +++ b/scintilla/src/ViewStyle.cxx @@ -338,10 +338,9 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) { someStylesForceCase = std::any_of(styles.cbegin(), styles.cend(), [](const Style &style) noexcept { return style.caseForce != Style::CaseForce::mixed; }); - // >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> - //~tabWidth = spaceWidth * tabInChars; - tabWidth = aveCharWidth * tabInChars; - // <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< + aveCharWidth = styles[STYLE_DEFAULT].aveCharWidth; + spaceWidth = styles[STYLE_DEFAULT].spaceWidth; + tabWidth = spaceWidth * tabInChars; controlCharWidth = 0.0; if (controlCharSymbol >= 32) { diff --git a/src/Edit.c b/src/Edit.c index 8f8a574d4..dc75d6ebf 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -395,6 +395,34 @@ void EditSetNewText(HWND hwnd, const char* lpstrText, DocPosU lenText, bool bCle } +//============================================================================= +// +// EditReInterpretText() +// memory ownership transfered to caller +// +static LPCH EditReInterpretText(LPCCH pchSource, const int szSrc, cpi_enc_t fromCP, cpi_enc_t asCP, int *plen_out) { + + int cmbch = 0; + LPCH pchConvText = NULL; + + int cwch = MultiByteToWideChar(Encoding_GetCodePage(fromCP), 0, pchSource, szSrc, NULL, 0); + WCHAR *pwchText = (WCHAR *)AllocMem((cwch + 1) * sizeof(WCHAR), HEAP_ZERO_MEMORY); + if (pwchText) { + cwch = MultiByteToWideChar(Encoding_GetCodePage(fromCP), 0, pchSource, szSrc, pwchText, cwch); + cmbch = WideCharToMultiByte(Encoding_GetCodePage(asCP), 0, pwchText, cwch, NULL, 0, NULL, NULL); + pchConvText = (LPCH)AllocMem(cmbch + 1, HEAP_ZERO_MEMORY); + if (pchConvText) { + cmbch = WideCharToMultiByte(Encoding_GetCodePage(asCP), 0, pwchText, cwch, pchConvText, cmbch, NULL, NULL); + } else { + cmbch = 0; + } + FreeMem(pwchText); + } + if (plen_out) { + *plen_out = cmbch; + } + return pchConvText; +} //============================================================================= // @@ -416,25 +444,20 @@ bool EditConvertText(HWND hwnd, cpi_enc_t encSource, cpi_enc_t encDest) return false; } - const DocPos chBufSize = length * 5 + 2; - char* pchText = AllocMem(chBufSize, HEAP_ZERO_MEMORY); + WCHAR *pwchText = AllocMem((length + 1) * sizeof(WCHAR), HEAP_ZERO_MEMORY); - struct Sci_TextRange tr = {{0, -1}, NULL}; - tr.lpstrText = pchText; - DocPos const rlength = SciCall_GetTextRange(&tr); - - const DocPos wchBufSize = rlength * 3 + 2; - WCHAR* pwchText = AllocMem(wchBufSize, HEAP_ZERO_MEMORY); + DocPos const chBufSize = length * 5 + 2; + char *pchText = AllocMem(chBufSize, HEAP_ZERO_MEMORY); // MultiBytes(Sci) -> WideChar(destination) -> Sci(MultiByte) const UINT cpDst = Encoding_GetCodePage(encDest); // get text as wide char - ptrdiff_t cbwText = MultiByteToWideCharEx(Encoding_SciCP, 0, pchText, length, pwchText, wchBufSize); + ptrdiff_t cbwText = MultiByteToWideCharEx(Encoding_SciCP, 0, SciCall_GetCharacterPointer(), length, pwchText, length); // convert wide char to destination multibyte ptrdiff_t cbText = WideCharToMultiByteEx(cpDst, 0, pwchText, cbwText, pchText, chBufSize, NULL, NULL); // re-code to wide char - cbwText = MultiByteToWideCharEx(cpDst, 0, pchText, cbText, pwchText, wchBufSize); + cbwText = MultiByteToWideCharEx(cpDst, 0, pchText, cbText, pwchText, length); // convert to Scintilla format cbText = WideCharToMultiByteEx(Encoding_SciCP, 0, pwchText, cbwText, pchText, chBufSize, NULL, NULL); @@ -2002,27 +2025,14 @@ void EditBase64Code(HWND hwnd, const bool bEncode, cpi_enc_t cpi) { bool const bStraightSel = (SciCall_GetAnchor() <= SciCall_GetCurrentPos()); size_t iSelSize = SciCall_GetSelText(NULL) - 1; // w/o terminating zero - unsigned char * pchText = (unsigned char *)SciCall_GetRangePointer(iSelStart, (DocPos)iSelSize); + char * pchText = (char *)SciCall_GetRangePointer(iSelStart, (DocPos)iSelSize); bool bAllocatedText = false; if (bEncode && (codePage != Encoding_SciCP)) { - // TODO: convert to WCHAR, convert to cpi encoding, encode base64 - WCHAR * wchText = (WCHAR *)AllocMem((iSelSize + 1) * sizeof(WCHAR), HEAP_ZERO_MEMORY); // should be large enough - if (wchText) { - int const cwchTxt = MultiByteToWideChar(Encoding_SciCP, 0, (LPCCH)pchText, (int)iSelSize, wchText, (int)iSelSize); - // allocate conversion buffer for desired encoding - int const cmbchTxt = WideCharToMultiByte(codePage, 0, wchText, cwchTxt, NULL, 0, NULL, NULL); - pchText = (unsigned char *)AllocMem(cmbchTxt + 1, HEAP_ZERO_MEMORY); - if (pchText) { - iSelSize = (size_t)WideCharToMultiByte(codePage, 0, wchText, cwchTxt, (LPCH)pchText, cmbchTxt, NULL, NULL); - bAllocatedText = true; - } else { - iSelSize = 0ULL; - } - FreeMem(wchText); - } else { - iSelSize = 0ULL; - } + int new_size = 0; + pchText = (char *)EditReInterpretText(pchText, (int)iSelSize, Enc_SciCPI, cpi, &new_size); + bAllocatedText = true; + iSelSize = (size_t)new_size; } if (iSelSize == 0) { if (bAllocatedText) { @@ -2032,8 +2042,8 @@ void EditBase64Code(HWND hwnd, const bool bEncode, cpi_enc_t cpi) { } size_t base64Size = 0; - char * pBase64CodedTxt = (char *)(bEncode ? Encoding_Base64Encode(pchText, iSelSize, &base64Size) : - Encoding_Base64Decode(pchText, iSelSize, &base64Size)); + char * pBase64CodedTxt = (char *)(bEncode ? Encoding_Base64Encode((unsigned char *)pchText, iSelSize, &base64Size) : + Encoding_Base64Decode((unsigned char *)pchText, iSelSize, &base64Size)); if (bAllocatedText) { FreeMem(pchText); @@ -2041,22 +2051,11 @@ void EditBase64Code(HWND hwnd, const bool bEncode, cpi_enc_t cpi) { if (bDecode && (codePage != Encoding_SciCP)) { // don't care if input is really a valid Base64 encoded byte-stream - WCHAR *wchText = (WCHAR *)AllocMem((base64Size + 1) * sizeof(WCHAR), HEAP_ZERO_MEMORY); // should be large enough - if (wchText) { - int const cwchTxt = MultiByteToWideChar(codePage, 0, pBase64CodedTxt, (int)base64Size, wchText, (int)base64Size); - // convert to SCI Encoding (UTF-8) - int const cmbchTxt = WideCharToMultiByte(Encoding_SciCP, 0, wchText, cwchTxt, NULL, 0, NULL, NULL); - FreeMem(pBase64CodedTxt); - pBase64CodedTxt = (char *)AllocMem(cmbchTxt + 1, HEAP_ZERO_MEMORY); - if (pBase64CodedTxt) { - base64Size = (size_t)WideCharToMultiByte(Encoding_SciCP, 0, wchText, cwchTxt, pBase64CodedTxt, cmbchTxt, NULL, NULL); - } else { - base64Size = 0ULL; - } - FreeMem(wchText); - } else { - base64Size = 0ULL; - } + int new_size = 0; + char * const pReInterpret = (char *)EditReInterpretText(pBase64CodedTxt, (int)base64Size, cpi, Enc_SciCPI, &new_size); + FreeMem(pBase64CodedTxt); + pBase64CodedTxt = pReInterpret; + base64Size = (size_t)new_size; } _SAVE_TARGET_RANGE_; diff --git a/src/Encoding.h b/src/Encoding.h index d5754c166..146214358 100644 --- a/src/Encoding.h +++ b/src/Encoding.h @@ -112,7 +112,8 @@ bool Encoding_IsEXTERNAL_8BIT(const cpi_enc_t iEncoding); bool Encoding_IsRECODE(const cpi_enc_t iEncoding); // Scintilla related -#define Encoding_SciCP CP_UTF8 +#define Encoding_SciCP CP_UTF8 +#define Enc_SciCPI CPI_UTF8 void Encoding_SetDefaultFlag(const cpi_enc_t iEncoding); const WCHAR* Encoding_GetLabel(const cpi_enc_t iEncoding); diff --git a/src/Notepad3.c b/src/Notepad3.c index 90017b2c1..8ac268932 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -9074,7 +9074,7 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) // ------------------------------------------------------ if (g_iStatusbarVisible[STATUS_2ND_DEF]) { - static bool s_bUse2ndDefault = -1; + static bool s_bUse2ndDefault = true; bool const bUse2ndDefault = Style_GetUse2ndDefault(); if (bForceRedraw || (s_bUse2ndDefault != bUse2ndDefault)) { if (bUse2ndDefault) diff --git a/src/StyleLexers/styleLexStandard.c b/src/StyleLexers/styleLexStandard.c index 733490c99..46e5d8172 100644 --- a/src/StyleLexers/styleLexStandard.c +++ b/src/StyleLexers/styleLexStandard.c @@ -47,7 +47,7 @@ EDITLEXER lexStandard2nd = /* 9 */ { {_STYLE_GETSTYLEID(STY_CARET)}, IDS_LEX_2ND_CARET, L"2nd Caret (Color, Size 1-3)", L"", L"" }, /* 10 */ { {_STYLE_GETSTYLEID(STY_LONG_LN_MRK)}, IDS_LEX_2ND_LONG_LN, L"2nd Long Line Marker (Colors)", L"fore:#FFC000", L"" }, /* 11 */ { {_STYLE_GETSTYLEID(STY_X_LN_SPACE)}, IDS_LEX_2ND_X_SPC, L"2nd Extra Line Spacing (Size)", L"", L"" }, - /* 12 */ { {_STYLE_GETSTYLEID(STY_BOOK_MARK)}, IDS_LEX_2ND_BKMRK, L"2nd Bookmarks and Folding (Colors, Size)", L"size:+2; fore:#000000; back:#00DC00; charset:2; case:U; alpha:100", L"" }, + /* 12 */ { {_STYLE_GETSTYLEID(STY_BOOK_MARK)}, IDS_LEX_2ND_BKMRK, L"2nd Bookmarks and Folding (Colors, Size)", L"size:+2; charset:2; fore:#000000; back:#00DC00; case:U; alpha:100", L"" }, /* 13 */ { {_STYLE_GETSTYLEID(STY_MARK_OCC)}, IDS_LEX_STR_63263, L"2nd Mark Occurrences (Indicator)", L"fore:#0000FF; alpha:60; alpha2:60; indic_box", L"" }, /* 14 */ { {_STYLE_GETSTYLEID(STY_URL_HOTSPOT)}, IDS_LEX_STR_63265, L"2nd Hyperlink Hotspots", L"fore:#00D000; back:#009C00; alpha:180; indic_compositionthin", L"" }, /* 15 */ {{_STYLE_GETSTYLEID(STY_UNICODE_HOTSPOT)}, IDS_LEX_STR_63368, L"2nd Unicode-Point Hover", L"fore:#0000FA; alpha:60; alpha2:180; indic_compositionthick", L""}, @@ -74,7 +74,7 @@ EDITLEXER lexANSI = { SCLEX_NULL, "null", IDS_LEX_ANSI_ART, L"ANSI Art", L"nfo; diz; \\^Readme$", L"", &KeyWords_NULL,{ - { {STYLE_DEFAULT}, IDS_LEX_STR_63126, L"Default", L"font:Lucida Console; size:11; thin; smoothing:none", L"" }, + { {STYLE_DEFAULT}, IDS_LEX_STR_63126, L"Default", L"font:Lucida Console; thin; size:11; smoothing:aliased", L"" }, { {STYLE_LINENUMBER}, IDS_LEX_STD_MARGIN, L"Margins and Line Numbers", L"font:Lucida Console; size:-2", L"" }, { {STYLE_BRACELIGHT}, IDS_LEX_STD_BRACE, L"Matching Braces", L"", L"" }, { {STYLE_BRACEBAD}, IDS_LEX_STD_BRACE_FAIL, L"Matching Braces Error", L"", L"" }, diff --git a/src/Styles.c b/src/Styles.c index fb685b0dd..dcad98390 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -53,7 +53,7 @@ static PEDITLEXER g_pLexArray[NUMLEXERS] = { &lexStandard, // Default Text &lexStandard2nd, // 2nd Default Text &lexTEXT, // Pure Text Files (Constants.StdDefaultLexerID = 2) - &lexANSI, // ANSI Files + &lexANSI, // ANSI Files (ASCII Art) &lexCONF, // Apache Config Files &lexASM, // Assembly Script &lexAHKL, // AutoHotkey L Script @@ -938,8 +938,7 @@ void Style_ToIniSection(bool bForceAll) const WCHAR* const IniSecStyles = Constants.Styles_Section; // auto select - bool const bUse2ndSty = Style_GetUse2ndDefault(); - SAVE_STYLE_IF_NOT_EQ_DEFAULT(Bool, Use2ndDefaultStyle, bUse2ndSty, false); + SAVE_STYLE_IF_NOT_EQ_DEFAULT(Bool, Use2ndDefaultStyle, Style_GetUse2ndDefault(), false); // default scheme SAVE_STYLE_IF_NOT_EQ_DEFAULT(Int, DefaultScheme, s_iDefaultLexer, Constants.StdDefaultLexerID); @@ -1111,8 +1110,6 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) // first set standard lexer's default values const PEDITLEXER pCurrentStandard = (IsLexerStandard(pLexNew)) ? pLexNew : GetCurrentStdLexer(); - Style_SetUse2ndDefault(pCurrentStandard == &lexStandard2nd); // sync if forced - // Set Lexer SciCall_SetILexer(CreateLexer(pLexNew->lexerName)); @@ -2451,7 +2448,7 @@ void Style_SetLexerFromID(HWND hwnd,int id) void Style_ToggleUse2ndDefault(HWND hwnd) { bool const use2ndDefStyle = Style_GetUse2ndDefault(); - Style_SetUse2ndDefault(use2ndDefStyle ? false : true); // swap + Style_SetUse2ndDefault(!use2ndDefStyle); // swap if (IsLexerStandard(s_pLexCurrent)) { s_pLexCurrent = GetCurrentStdLexer(); // sync } @@ -3202,17 +3199,17 @@ void Style_CopyStyles_IfNotDefined(LPCWSTR lpszStyleSrc, LPWSTR lpszStyleDest, i StringCchCat(szTmpStyle, COUNTOF(szTmpStyle), tch); } - // --------- Special Styles --------- - int iFontQuality = Settings2.SciFontQuality; if (Style_StrGetFontQuality(lpszStyleDest, tch, COUNTOF(tch), &iFontQuality)) { AppendStyle(szTmpStyle, COUNTOF(szTmpStyle), L"smoothing:"); StringCchCat(szTmpStyle, COUNTOF(szTmpStyle), tch); - } else if (Style_StrGetFontQuality(lpszStyleSrc, tch, COUNTOF(tch), &iFontQuality)) { + } else if (!bIsFontDefInDestination && Style_StrGetFontQuality(lpszStyleSrc, tch, COUNTOF(tch), &iFontQuality)) { AppendStyle(szTmpStyle, COUNTOF(szTmpStyle), L"smoothing:"); StringCchCat(szTmpStyle, COUNTOF(szTmpStyle), tch); } + // --------- Special Styles --------- + if (Style_StrHasAttribute(lpszStyleDest, FontEffects[FE_EOLFILLED])) { AppendStyle(szTmpStyle, COUNTOF(szTmpStyle), FontEffects[FE_EOLFILLED]); } else if (Style_StrHasAttribute(lpszStyleSrc, FontEffects[FE_EOLFILLED])) { diff --git a/src/Styles.h b/src/Styles.h index 9d8d2ebee..27249bb2a 100644 --- a/src/Styles.h +++ b/src/Styles.h @@ -86,8 +86,8 @@ bool Style_StrGetStrokeWidth(HWND hwnd, int indicID, LPCWSTR lpszStyle, int *p bool Style_StrGetCase(LPCWSTR lpszStyle, int *i); bool Style_StrGetAlpha(LPCWSTR lpszStyle, int* iOutValue, bool bAlpha1st); bool Style_GetIndicatorType(LPWSTR lpszStyle,int cchSize,int* idx); -void Style_CopyStyles_IfNotDefined(LPCWSTR lpszStyleSrc,LPWSTR lpszStyleDest,int cchSizeDest); -bool Style_SelectFont(HWND hwnd,LPWSTR lpszStyle,int cchStyle,LPCWSTR sLexerName,LPCWSTR sStyleName,bool,bool); +void Style_CopyStyles_IfNotDefined(LPCWSTR lpszStyleSrc, LPWSTR lpszStyleDest, int cchSizeDest); +bool Style_SelectFont(HWND hwnd, LPWSTR lpszStyle, int cchStyle, LPCWSTR sLexerName, LPCWSTR sStyleName, bool bGlobalDefaultStyle, bool bCurrentDefaultStyle); bool Style_SelectColor(HWND hwnd,bool,LPWSTR lpszStyle,int cchStyle,bool); void Style_SetStyles(HWND hwnd,const int iStyle,LPCWSTR lpszStyle); bool Style_IsCurLexerStandard();