1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsComplexBreaker.h"
12 #include "nsUTF8Utils.h"
16 #if defined(NIGHTLY_BUILD)
17 # include "mozilla/WindowsProcessMitigations.h"
22 void NS_GetComplexLineBreaks(const char16_t
* aText
, uint32_t aLength
,
23 uint8_t* aBreakBefore
) {
24 NS_ASSERTION(aText
, "aText shouldn't be null");
26 #if defined(NIGHTLY_BUILD)
27 // If win32k lockdown is enabled we can't use Uniscribe, so fall back to
28 // nsRuleBreaker code. This will lead to some regressions and the change is
29 // only to allow testing of win32k lockdown in content.
30 // Use of Uniscribe will be replaced in bug 1684927.
31 if (mozilla::IsWin32kLockedDown()) {
32 for (uint32_t i
= 0; i
< aLength
; i
++)
34 (0 == TrbWordBreakPos(aText
, i
, aText
+ i
, aLength
- i
));
41 AutoTArray
<SCRIPT_ITEM
, 64> items
;
42 char16ptr_t text
= aText
;
44 memset(aBreakBefore
, false, aLength
);
46 items
.AppendElements(64);
49 result
= ScriptItemize(text
, aLength
, items
.Length(), nullptr, nullptr,
50 items
.Elements(), &outItems
);
52 if (result
== E_OUTOFMEMORY
) {
53 // XXX(Bug 1631371) Check if this should use a fallible operation as it
55 items
.AppendElements(items
.Length());
57 } while (result
== E_OUTOFMEMORY
);
59 for (int iItem
= 0; iItem
< outItems
; ++iItem
) {
61 (iItem
+ 1 == outItems
? aLength
: items
[iItem
+ 1].iCharPos
);
62 uint32_t startOffset
= items
[iItem
].iCharPos
;
63 AutoTArray
<SCRIPT_LOGATTR
, 64> sla
;
65 // XXX(Bug 1631371) Check if this should use a fallible operation as it
67 sla
.AppendElements(endOffset
- startOffset
);
69 if (ScriptBreak(text
+ startOffset
, endOffset
- startOffset
,
70 &items
[iItem
].a
, sla
.Elements()) < 0)
73 // We don't want to set a potential break position at the start of text;
74 // that's the responsibility of a higher level.
75 for (uint32_t j
= startOffset
? 0 : 1; j
+ startOffset
< endOffset
; ++j
) {
76 aBreakBefore
[j
+ startOffset
] = sla
[j
].fSoftBreak
;