Line data Source code
1 : /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : *
3 : * This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "nsBidi_ICU.h"
8 : #include "ICUUtils.h"
9 :
10 0 : nsBidi::nsBidi()
11 : {
12 0 : mBiDi = ubidi_open();
13 0 : }
14 :
15 0 : nsBidi::~nsBidi()
16 : {
17 0 : ubidi_close(mBiDi);
18 0 : }
19 :
20 0 : nsresult nsBidi::SetPara(const char16_t *aText, int32_t aLength,
21 : nsBidiLevel aParaLevel)
22 : {
23 0 : UErrorCode error = U_ZERO_ERROR;
24 0 : ubidi_setPara(mBiDi, reinterpret_cast<const UChar*>(aText), aLength,
25 0 : aParaLevel, nullptr, &error);
26 0 : return ICUUtils::UErrorToNsResult(error);
27 : }
28 :
29 0 : nsresult nsBidi::GetDirection(nsBidiDirection* aDirection)
30 : {
31 0 : *aDirection = nsBidiDirection(ubidi_getDirection(mBiDi));
32 0 : return NS_OK;
33 : }
34 :
35 0 : nsresult nsBidi::GetParaLevel(nsBidiLevel* aParaLevel)
36 : {
37 0 : *aParaLevel = ubidi_getParaLevel(mBiDi);
38 0 : return NS_OK;
39 : }
40 :
41 0 : nsresult nsBidi::GetLogicalRun(int32_t aLogicalStart, int32_t* aLogicalLimit,
42 : nsBidiLevel* aLevel)
43 : {
44 0 : ubidi_getLogicalRun(mBiDi, aLogicalStart, aLogicalLimit, aLevel);
45 0 : return NS_OK;
46 : }
47 :
48 0 : nsresult nsBidi::CountRuns(int32_t* aRunCount)
49 : {
50 0 : UErrorCode errorCode = U_ZERO_ERROR;
51 0 : *aRunCount = ubidi_countRuns(mBiDi, &errorCode);
52 0 : return ICUUtils::UErrorToNsResult(errorCode);
53 : }
54 :
55 0 : nsresult nsBidi::GetVisualRun(int32_t aRunIndex, int32_t* aLogicalStart,
56 : int32_t* aLength, nsBidiDirection* aDirection)
57 : {
58 0 : *aDirection = nsBidiDirection(ubidi_getVisualRun(mBiDi, aRunIndex,
59 : aLogicalStart, aLength));
60 0 : return NS_OK;
61 : }
62 :
63 0 : nsresult nsBidi::ReorderVisual(const nsBidiLevel* aLevels, int32_t aLength,
64 : int32_t* aIndexMap)
65 : {
66 0 : ubidi_reorderVisual(aLevels, aLength, aIndexMap);
67 0 : return NS_OK;
68 : }
|