summaryrefslogtreecommitdiff
path: root/xfa/fgas/layout/fgas_unicode.cpp
blob: 10fdbf08101e5f883c366d742d8e7b962e338b08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#include "xfa/fgas/layout/fgas_unicode.h"

void FX_TEXTLAYOUT_PieceSort(CFX_TPOArray& tpos, int32_t iStart, int32_t iEnd) {
  ASSERT(iStart > -1 && iStart < tpos.GetSize());
  ASSERT(iEnd > -1 && iEnd < tpos.GetSize());
  if (iStart >= iEnd) {
    return;
  }
  int32_t i = iStart, j = iEnd;
  FX_TPO *pCur = tpos.GetPtrAt(iStart), *pSort;
  int32_t v = pCur->pos;
  while (i < j) {
    while (j > i) {
      pSort = tpos.GetPtrAt(j);
      if (pSort->pos < v) {
        FX_TPO t = *pSort;
        *pSort = *pCur;
        *pCur = t;
        pCur = pSort;
        break;
      }
      j--;
    }
    while (i < j) {
      pSort = tpos.GetPtrAt(i);
      if (pSort->pos > v) {
        FX_TPO t = *pSort;
        *pSort = *pCur;
        *pCur = t;
        pCur = pSort;
        break;
      }
      i++;
    }
  }
  i--, j++;
  if (iStart < i) {
    FX_TEXTLAYOUT_PieceSort(tpos, iStart, i);
  }
  if (j < iEnd) {
    FX_TEXTLAYOUT_PieceSort(tpos, j, iEnd);
  }
}