Skip to content

Commit

Permalink
[de] Implement DoNotHyphenateCaps parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillovIlya committed Aug 11, 2023
1 parent 861bd43 commit 4a56e0a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{
BUFFER_STRING += String.fromCodePoint(codePoint);
};
AscHyphenation.HyphenateBuffer = function()
AscHyphenation.Hyphenate = function()
{
let checkString = BUFFER_STRING.toLowerCase();

Expand All @@ -58,11 +58,9 @@

return [];
};
AscHyphenation.Hyphenate = function()
AscHyphenation.Clear = function()
{
let result = AscHyphenation.HyphenateBuffer();
BUFFER_STRING = "";
return result;
};

})(window);
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ $(function ()
{
return autoHyphenation;
};
AscWord.CParagraph.prototype.IsHyphenateCaps = function()
AscWord.CTextHyphenator.prototype.IsHyphenateCaps = function()
{
return hyphenateCaps;
};
Expand Down Expand Up @@ -139,17 +139,17 @@ $(function ()
{
SetText("abcde AAABBB aaabbb");

CheckLines(assert, false, charWidth * 10.5, ["abcde ", "AAABBB ", "aaabbb"]);
CheckLines(assert, false, charWidth * 11.5, ["abcde ", "AAABBB ", "aaabbb"]);
CheckAutoHyphenAfter(assert, 8, false);
CheckAutoHyphenAfter(assert, 15, false);

SetHyphenateCaps(true);
CheckLines(assert, true, charWidth * 10.5, ["abcde AAA", "BBB aaabbb"]);
CheckLines(assert, true, charWidth * 11.5, ["abcde AAA", "BBB aaabbb"]);
CheckAutoHyphenAfter(assert, 8, true);
CheckAutoHyphenAfter(assert, 15, false);

SetHyphenateCaps(false);
CheckLines(assert, true, charWidth * 10.5, ["abcde ", "AAABBB aaa", "bbb"]);
CheckLines(assert, true, charWidth * 11.5, ["abcde ", "AAABBB aaa", "bbb"]);
CheckAutoHyphenAfter(assert, 8, false);
CheckAutoHyphenAfter(assert, 15, true);

Expand Down
52 changes: 44 additions & 8 deletions word/Editor/Paragraph/TextHyphenator.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var AscHyphenation = AscHyphenation || {};
{
BUFFER_STRING += String.fromCodePoint(codePoint);
};
AscHyphenation.HyphenateBuffer = function()
AscHyphenation.Hyphenate = function()
{
if ("reenter" === BUFFER_STRING)
return [1];
Expand All @@ -55,11 +55,9 @@ var AscHyphenation = AscHyphenation || {};

return [];
};
AscHyphenation.Hyphenate = function()
AscHyphenation.Clear = function()
{
let result = AscHyphenation.HyphenateBuffer();
BUFFER_STRING = "";
return result;
};
})();

Expand All @@ -77,9 +75,13 @@ var AscHyphenation = AscHyphenation || {};
this.FontSlot = fontslot_Unknown;
this.Lang = lcid_enUS;
this.Buffer = [];

this.HyphenateCaps = true;
}
CTextHyphenator.prototype.Hyphenate = function(paragraph)
{
this.CheckHyphenateCaps(paragraph);

let self = this;
paragraph.CheckRunContent(function(run, startPos, endPos)
{
Expand Down Expand Up @@ -112,6 +114,14 @@ var AscHyphenation = AscHyphenation || {};
}
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Private area
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CTextHyphenator.prototype.ResetBuffer = function()
{
this.Buffer.length = 0;
AscHyphenation.Clear();
};
CTextHyphenator.prototype.GetLang = function(run, fontSlot)
{
let textPr = run.Get_CompiledPr(false);
Expand Down Expand Up @@ -152,19 +162,45 @@ var AscHyphenation = AscHyphenation || {};
if (!this.Word)
return;

this.Word = false;

if (!this.IsHyphenateCaps() && this.IsAllCaps())
return this.ResetBuffer();

let result = AscHyphenation.Hyphenate();
for (let i = 0, len = result.length; i < len; ++i)
{
this.Buffer[result[i]].SetHyphenAfter(true);
}

this.Buffer.length = 0;
this.Word = false;
this.ResetBuffer();
};
CTextHyphenator.prototype.IsAllCaps = function()
{
for (let i = 0, len = this.Buffer.length; i < len; ++i)
{
let char = String.fromCodePoint(this.Buffer[i].GetCodePoint());
if (char.toUpperCase() !== char)
return false;
}

return true;
};
CTextHyphenator.prototype.CheckHyphenateCaps = function(paragraph)
{
this.HyphenateCaps = true;

let logicDocument = paragraph.GetLogicDocument();
if (logicDocument && logicDocument.IsDocumentEditor())
this.HyphenateCaps = logicDocument.GetDocumentSettings().IsHyphenateCaps();
};
CTextHyphenator.prototype.IsHyphenateCaps = function()
{
return this.HyphenateCaps;
};

//--------------------------------------------------------export----------------------------------------------------
window['AscWord'].CTextHyphenator = CTextHyphenator;
window['AscWord'].TextHyphenator = new CTextHyphenator();
window['AscWord'].TextHyphenator = new CTextHyphenator();

})(window);

0 comments on commit 4a56e0a

Please sign in to comment.