Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 void
17 NS_GetComplexLineBreaks(const char16_t* aText, uint32_t aLength,
18 uint8_t* aBreakBefore)
19 {
20 NS_ASSERTION(aText, "aText shouldn't be null");
22 int outItems = 0;
23 HRESULT result;
24 nsAutoTArray<SCRIPT_ITEM, 64> items;
25 char16ptr_t text = aText;
27 memset(aBreakBefore, false, aLength);
29 if (!items.AppendElements(64))
30 return;
32 do {
33 result = ScriptItemize(text, aLength, items.Length(), nullptr, nullptr,
34 items.Elements(), &outItems);
36 if (result == E_OUTOFMEMORY) {
37 if (!items.AppendElements(items.Length()))
38 return;
39 }
40 } while (result == E_OUTOFMEMORY);
42 for (int iItem = 0; iItem < outItems; ++iItem) {
43 uint32_t endOffset = (iItem + 1 == outItems ? aLength : items[iItem + 1].iCharPos);
44 uint32_t startOffset = items[iItem].iCharPos;
45 nsAutoTArray<SCRIPT_LOGATTR, 64> sla;
47 if (!sla.AppendElements(endOffset - startOffset))
48 return;
50 if (ScriptBreak(text + startOffset, endOffset - startOffset,
51 &items[iItem].a, sla.Elements()) < 0)
52 return;
54 for (uint32_t j=0; j+startOffset < endOffset; ++j) {
55 aBreakBefore[j+startOffset] = sla[j].fSoftBreak;
56 }
57 }
58 }