Improve the check when to use fontHint
This commit is contained in:
Ilya Kirillov
2025-11-28 19:20:00 +03:00
parent 94d728dff1
commit dc26cbe3cb
4 changed files with 57 additions and 9 deletions

View File

@ -11748,6 +11748,14 @@
"Meiryo", "MS Gothic", "MS PGothic", "MS UI Gothic", "Yu Gothic",
"Dotum", "Gulim", "Malgun Gothic"
];
// Символы, на которых работает <w:rFonts w:hint="eastAsia"/>
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;

View File

@ -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);
});

View File

@ -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;

View File

@ -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