From dc26cbe3cb8ddb2c0e85271704c53a124d713bb6 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Fri, 28 Nov 2025 19:20:00 +0300 Subject: [PATCH] For bug #71108 Improve the check when to use fontHint --- common/editorscommon.js | 9 ++++ .../paragraph/paragraph-lines.js | 41 ++++++++++++++++++- word/Editor/Paragraph/RunContent/Text.js | 12 +++--- word/Editor/Run.js | 4 +- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/common/editorscommon.js b/common/editorscommon.js index 25690b9fd5..55b977e5d9 100644 --- a/common/editorscommon.js +++ b/common/editorscommon.js @@ -11748,6 +11748,14 @@ "Meiryo", "MS Gothic", "MS PGothic", "MS UI Gothic", "Yu Gothic", "Dotum", "Gulim", "Malgun Gothic" ]; + + // Символы, на которых работает + function isAmbiguousCharacter(codePoint) + { + return (0x00D7 === codePoint + || (0x0370 <= codePoint && codePoint <= 0x03FF)); + } + function IsEastAsianFont(sName) { @@ -15610,6 +15618,7 @@ window["AscCommon"].getAscColorScheme = getAscColorScheme; window["AscCommon"].checkAddColorScheme = checkAddColorScheme; window["AscCommon"].getIndexColorSchemeInArray = getIndexColorSchemeInArray; + window["AscCommon"].isAmbiguousCharacter = isAmbiguousCharacter; window["AscCommon"].isEastAsianScript = isEastAsianScript; window["AscCommon"].IsEastAsianFont = IsEastAsianFont; window["AscCommon"].IsComplexScript = IsComplexScript; diff --git a/tests/word/document-calculation/paragraph/paragraph-lines.js b/tests/word/document-calculation/paragraph/paragraph-lines.js index 3cc99c3f1a..1fcb04f1c3 100644 --- a/tests/word/document-calculation/paragraph/paragraph-lines.js +++ b/tests/word/document-calculation/paragraph/paragraph-lines.js @@ -105,16 +105,53 @@ $(function () { "界! " ]); - // check non asian text with the eastAsian hint (71108) + setText("你好世界! HΩllo! 你好世界! 你好世界! "); + recalculate(charWidth * 8.5); + checkLines(assert, para, [ + "你好世界! ", + "HΩllo! 你", + "好世界! 你好世", + "界! " + ]); + + setText("你好世界! HeΩlo! 你好世界! 你好世界! "); + recalculate(charWidth * 8.5); + checkLines(assert, para, [ + "你好世界! ", + "HeΩlo! 你", + "好世界! 你好世", + "界! " + ]); + + // Check ambiguous characters with the eastAsian hint (71108) + // × Ω (whole greek script) + run.SetRFontsHint(AscWord.fonthint_EastAsia); setText("你好世界! Hello! 你好世界! 你好世界! "); recalculate(charWidth * 8.5); checkLines(assert, para, [ - "你好世界! He", + "你好世界! ", + "Hello! 你", + "好世界! 你好世", + "界! " + ]); + + setText("你好世界! HΩllo! 你好世界! 你好世界! "); + recalculate(charWidth * 8.5); + checkLines(assert, para, [ + "你好世界! HΩ", "llo! 你好世", "界! 你好世界! " ]); + setText("你好世界! HeΩlo! 你好世界! 你好世界! "); + recalculate(charWidth * 8.5); + checkLines(assert, para, [ + "你好世界! He", + "Ωlo! 你好世", + "界! 你好世界! " + ]); + run.SetRFontsHint(undefined); }); diff --git a/word/Editor/Paragraph/RunContent/Text.js b/word/Editor/Paragraph/RunContent/Text.js index e3784b08ae..7ad9bebd58 100644 --- a/word/Editor/Paragraph/RunContent/Text.js +++ b/word/Editor/Paragraph/RunContent/Text.js @@ -473,13 +473,15 @@ { return this.IsDigit(); }; - CRunText.prototype.IsSpaceAfter = function() + CRunText.prototype.IsSpaceAfter = function(fontHint) { - return !!(this.Flags & FLAGS_SPACEAFTER); + return ((this.Flags & FLAGS_SPACEAFTER) + || (AscWord.fonthint_EastAsia === fontHint && AscCommon.isAmbiguousCharacter(this.Value))); }; - CRunText.prototype.IsSpaceBefore = function() + CRunText.prototype.IsSpaceBefore = function(fontHint) { - return AscCommon.isEastAsianScript(this.Value); + return (AscCommon.isEastAsianScript(this.Value) + || (AscWord.fonthint_EastAsia === fontHint && AscCommon.isAmbiguousCharacter(this.Value))); }; CRunText.prototype.isHyphenAfter = function() { @@ -566,7 +568,7 @@ // Дефисы if (0x002D === this.Value || 0x2014 === this.Value) return true; - + if (AscCommon.isEastAsianScript(this.Value) && this.CanBeAtEndOfLine()) return true; diff --git a/word/Editor/Run.js b/word/Editor/Run.js index 42bb57b5ce..209f52de83 100644 --- a/word/Editor/Run.js +++ b/word/Editor/Run.js @@ -3816,7 +3816,7 @@ ParaRun.prototype.Recalculate_Range = function(PRS, ParaPr, Depth) } } - let isBreakBefore = Item.IsSpaceBefore(); + let isBreakBefore = Item.IsSpaceBefore(textPr.RFonts.Hint); if (isBreakBefore && Word && PRS.LastItem.CanBeAtEndOfLine() @@ -3838,7 +3838,7 @@ ParaRun.prototype.Recalculate_Range = function(PRS, ParaPr, Depth) let isLigature = Item.IsLigature(); let GraphemeLen = isLigature ? Item.GetLigatureWidth() : LetterLen; - let isBreakAfter = Item.IsSpaceAfter() || textPr.RFonts.Hint === AscWord.fonthint_EastAsia; + let isBreakAfter = Item.IsSpaceAfter(textPr.RFonts.Hint); if (FirstItemOnLine && (X + SpaceLen + WordLen + GraphemeLen > XEnd