intl/lwbrk/src/nsUniscribeBreaker.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsComplexBreaker.h"
michael@0 7
michael@0 8 #include <windows.h>
michael@0 9
michael@0 10 #include <usp10.h>
michael@0 11
michael@0 12 #include "nsUTF8Utils.h"
michael@0 13 #include "nsString.h"
michael@0 14 #include "nsTArray.h"
michael@0 15
michael@0 16 void
michael@0 17 NS_GetComplexLineBreaks(const char16_t* aText, uint32_t aLength,
michael@0 18 uint8_t* aBreakBefore)
michael@0 19 {
michael@0 20 NS_ASSERTION(aText, "aText shouldn't be null");
michael@0 21
michael@0 22 int outItems = 0;
michael@0 23 HRESULT result;
michael@0 24 nsAutoTArray<SCRIPT_ITEM, 64> items;
michael@0 25 char16ptr_t text = aText;
michael@0 26
michael@0 27 memset(aBreakBefore, false, aLength);
michael@0 28
michael@0 29 if (!items.AppendElements(64))
michael@0 30 return;
michael@0 31
michael@0 32 do {
michael@0 33 result = ScriptItemize(text, aLength, items.Length(), nullptr, nullptr,
michael@0 34 items.Elements(), &outItems);
michael@0 35
michael@0 36 if (result == E_OUTOFMEMORY) {
michael@0 37 if (!items.AppendElements(items.Length()))
michael@0 38 return;
michael@0 39 }
michael@0 40 } while (result == E_OUTOFMEMORY);
michael@0 41
michael@0 42 for (int iItem = 0; iItem < outItems; ++iItem) {
michael@0 43 uint32_t endOffset = (iItem + 1 == outItems ? aLength : items[iItem + 1].iCharPos);
michael@0 44 uint32_t startOffset = items[iItem].iCharPos;
michael@0 45 nsAutoTArray<SCRIPT_LOGATTR, 64> sla;
michael@0 46
michael@0 47 if (!sla.AppendElements(endOffset - startOffset))
michael@0 48 return;
michael@0 49
michael@0 50 if (ScriptBreak(text + startOffset, endOffset - startOffset,
michael@0 51 &items[iItem].a, sla.Elements()) < 0)
michael@0 52 return;
michael@0 53
michael@0 54 for (uint32_t j=0; j+startOffset < endOffset; ++j) {
michael@0 55 aBreakBefore[j+startOffset] = sla[j].fSoftBreak;
michael@0 56 }
michael@0 57 }
michael@0 58 }

mercurial