intl/lwbrk/src/nsUniscribeBreaker.cpp

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:8816668bcb2f
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/. */
5
6 #include "nsComplexBreaker.h"
7
8 #include <windows.h>
9
10 #include <usp10.h>
11
12 #include "nsUTF8Utils.h"
13 #include "nsString.h"
14 #include "nsTArray.h"
15
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");
21
22 int outItems = 0;
23 HRESULT result;
24 nsAutoTArray<SCRIPT_ITEM, 64> items;
25 char16ptr_t text = aText;
26
27 memset(aBreakBefore, false, aLength);
28
29 if (!items.AppendElements(64))
30 return;
31
32 do {
33 result = ScriptItemize(text, aLength, items.Length(), nullptr, nullptr,
34 items.Elements(), &outItems);
35
36 if (result == E_OUTOFMEMORY) {
37 if (!items.AppendElements(items.Length()))
38 return;
39 }
40 } while (result == E_OUTOFMEMORY);
41
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;
46
47 if (!sla.AppendElements(endOffset - startOffset))
48 return;
49
50 if (ScriptBreak(text + startOffset, endOffset - startOffset,
51 &items[iItem].a, sla.Elements()) < 0)
52 return;
53
54 for (uint32_t j=0; j+startOffset < endOffset; ++j) {
55 aBreakBefore[j+startOffset] = sla[j].fSoftBreak;
56 }
57 }
58 }

mercurial