2007-08-15 20:52:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-08-15 20:52:13 +04:00
|
|
|
|
|
|
|
#include "nsComplexBreaker.h"
|
|
|
|
|
2008-12-03 16:42:03 +03:00
|
|
|
#include <windows.h>
|
|
|
|
|
2008-03-14 19:22:25 +03:00
|
|
|
#include <usp10.h>
|
2008-12-03 16:42:03 +03:00
|
|
|
|
2007-08-15 20:52:13 +04:00
|
|
|
#include "nsUTF8Utils.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
void
|
2014-01-04 19:02:17 +04:00
|
|
|
NS_GetComplexLineBreaks(const char16_t* aText, uint32_t aLength,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t* aBreakBefore)
|
2007-08-15 20:52:13 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aText, "aText shouldn't be null");
|
2008-12-03 16:42:03 +03:00
|
|
|
|
2007-08-15 20:52:13 +04:00
|
|
|
int outItems = 0;
|
|
|
|
HRESULT result;
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<SCRIPT_ITEM, 64> items;
|
2013-12-03 19:09:50 +04:00
|
|
|
char16ptr_t text = aText;
|
2007-08-15 20:52:13 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
memset(aBreakBefore, false, aLength);
|
2007-08-15 20:52:13 +04:00
|
|
|
|
|
|
|
if (!items.AppendElements(64))
|
|
|
|
return;
|
|
|
|
|
|
|
|
do {
|
2013-12-03 19:09:50 +04:00
|
|
|
result = ScriptItemize(text, aLength, items.Length(), nullptr, nullptr,
|
2013-08-23 23:51:30 +04:00
|
|
|
items.Elements(), &outItems);
|
2007-08-15 20:52:13 +04:00
|
|
|
|
|
|
|
if (result == E_OUTOFMEMORY) {
|
|
|
|
if (!items.AppendElements(items.Length()))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} while (result == E_OUTOFMEMORY);
|
|
|
|
|
|
|
|
for (int iItem = 0; iItem < outItems; ++iItem) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t endOffset = (iItem + 1 == outItems ? aLength : items[iItem + 1].iCharPos);
|
|
|
|
uint32_t startOffset = items[iItem].iCharPos;
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<SCRIPT_LOGATTR, 64> sla;
|
2007-08-15 20:52:13 +04:00
|
|
|
|
|
|
|
if (!sla.AppendElements(endOffset - startOffset))
|
|
|
|
return;
|
|
|
|
|
2013-12-03 19:09:50 +04:00
|
|
|
if (ScriptBreak(text + startOffset, endOffset - startOffset,
|
2008-02-11 19:46:55 +03:00
|
|
|
&items[iItem].a, sla.Elements()) < 0)
|
2007-08-15 20:52:13 +04:00
|
|
|
return;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t j=0; j+startOffset < endOffset; ++j) {
|
2007-08-15 20:52:13 +04:00
|
|
|
aBreakBefore[j+startOffset] = sla[j].fSoftBreak;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|