Bug 1710182 [wpt PR 28911] - [GridNG] Update test expectations of legacy grid failure...
[gecko.git] / intl / lwbrk / nsUniscribeBreaker.cpp
blob5a6c071de77bb5694f0621081511ebf888f4c707
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"
8 #include <windows.h>
10 #include <usp10.h>
12 #include "nsUTF8Utils.h"
13 #include "nsString.h"
14 #include "nsTArray.h"
16 #if defined(NIGHTLY_BUILD)
17 # include "mozilla/WindowsProcessMitigations.h"
18 # define TH_UNICODE
19 # include "rulebrk.h"
20 #endif
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++)
33 aBreakBefore[i] =
34 (0 == TrbWordBreakPos(aText, i, aText + i, aLength - i));
35 return;
37 #endif
39 int outItems = 0;
40 HRESULT result;
41 AutoTArray<SCRIPT_ITEM, 64> items;
42 char16ptr_t text = aText;
44 memset(aBreakBefore, false, aLength);
46 items.AppendElements(64);
48 do {
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
54 // pretended earlier.
55 items.AppendElements(items.Length());
57 } while (result == E_OUTOFMEMORY);
59 for (int iItem = 0; iItem < outItems; ++iItem) {
60 uint32_t endOffset =
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
66 // pretended earlier.
67 sla.AppendElements(endOffset - startOffset);
69 if (ScriptBreak(text + startOffset, endOffset - startOffset,
70 &items[iItem].a, sla.Elements()) < 0)
71 return;
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;