intl/lwbrk/src/nsUniscribeBreaker.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/lwbrk/src/nsUniscribeBreaker.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsComplexBreaker.h"
    1.10 +
    1.11 +#include <windows.h>
    1.12 +
    1.13 +#include <usp10.h>
    1.14 +
    1.15 +#include "nsUTF8Utils.h"
    1.16 +#include "nsString.h"
    1.17 +#include "nsTArray.h"
    1.18 +
    1.19 +void
    1.20 +NS_GetComplexLineBreaks(const char16_t* aText, uint32_t aLength,
    1.21 +                        uint8_t* aBreakBefore)
    1.22 +{
    1.23 +  NS_ASSERTION(aText, "aText shouldn't be null"); 
    1.24 +
    1.25 +  int outItems = 0;
    1.26 +  HRESULT result;
    1.27 +  nsAutoTArray<SCRIPT_ITEM, 64> items;
    1.28 +  char16ptr_t text = aText;
    1.29 +
    1.30 +  memset(aBreakBefore, false, aLength);
    1.31 +
    1.32 +  if (!items.AppendElements(64))
    1.33 +    return;
    1.34 +
    1.35 +  do {
    1.36 +    result = ScriptItemize(text, aLength, items.Length(), nullptr, nullptr,
    1.37 +                           items.Elements(), &outItems);
    1.38 +
    1.39 +    if (result == E_OUTOFMEMORY) {
    1.40 +      if (!items.AppendElements(items.Length()))
    1.41 +        return;
    1.42 +    }
    1.43 +  } while (result == E_OUTOFMEMORY);
    1.44 +
    1.45 +  for (int iItem = 0; iItem < outItems; ++iItem)  {
    1.46 +    uint32_t endOffset = (iItem + 1 == outItems ? aLength : items[iItem + 1].iCharPos);
    1.47 +    uint32_t startOffset = items[iItem].iCharPos;
    1.48 +    nsAutoTArray<SCRIPT_LOGATTR, 64> sla;
    1.49 +    
    1.50 +    if (!sla.AppendElements(endOffset - startOffset))
    1.51 +      return;
    1.52 +
    1.53 +    if (ScriptBreak(text + startOffset, endOffset - startOffset,
    1.54 +                    &items[iItem].a,  sla.Elements()) < 0) 
    1.55 +      return;
    1.56 +
    1.57 +    for (uint32_t j=0; j+startOffset < endOffset; ++j) {
    1.58 +       aBreakBefore[j+startOffset] = sla[j].fSoftBreak;
    1.59 +    }
    1.60 +  }
    1.61 +}

mercurial