Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
fx_bidi.cpp
Go to the documentation of this file.
1
// Copyright 2014 The PDFium Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7
#
include
"core/fxcrt/fx_bidi.h"
8
9
#
include
<
algorithm
>
10
11
#
include
"core/fxcrt/check_op.h"
12
#
include
"core/fxcrt/fx_unicode.h"
13
14
CFX_BidiChar
::
CFX_BidiChar
()
15
: m_CurrentSegment({0, 0,
Direction
::
kNeutral
}),
16
m_LastSegment({0, 0,
Direction
::
kNeutral
}) {}
17
18
bool
CFX_BidiChar
::
AppendChar
(
wchar_t
wch) {
19
Direction
direction;
20
switch
(
pdfium
::
unicode
::
GetBidiClass
(
wch
)
) {
21
case
FX_BIDICLASS
::
kL
:
22
direction =
Direction
::
kLeft
;
23
break
;
24
case
FX_BIDICLASS
::
kAN
:
25
case
FX_BIDICLASS
::
kEN
:
26
case
FX_BIDICLASS
::
kNSM
:
27
case
FX_BIDICLASS
::
kCS
:
28
case
FX_BIDICLASS
::
kES
:
29
case
FX_BIDICLASS
::
kET
:
30
case
FX_BIDICLASS
::
kBN
:
31
direction =
Direction
::
kLeftWeak
;
32
break
;
33
case
FX_BIDICLASS
::
kR
:
34
case
FX_BIDICLASS
::
kAL
:
35
direction =
Direction
::
kRight
;
36
break
;
37
default
:
38
direction =
Direction
::
kNeutral
;
39
break
;
40
}
41
42
bool
bChangeDirection = (direction != m_CurrentSegment
.
direction
);
43
if
(bChangeDirection)
44
StartNewSegment(direction);
45
46
m_CurrentSegment
.
count
++;
47
return
bChangeDirection;
48
}
49
50
bool
CFX_BidiChar
::
EndChar
() {
51
StartNewSegment(
Direction
::
kNeutral
);
52
return
m_LastSegment
.
count
> 0;
53
}
54
55
void
CFX_BidiChar
::StartNewSegment(
CFX_BidiChar
::
Direction
direction) {
56
m_LastSegment = m_CurrentSegment;
57
m_CurrentSegment
.
start
+= m_CurrentSegment
.
count
;
58
m_CurrentSegment
.
count
= 0;
59
m_CurrentSegment
.
direction
= direction;
60
}
61
62
CFX_BidiString
::
CFX_BidiString
(
const
WideString
& str) : m_Str(str) {
63
CFX_BidiChar
bidi;
64
for
(
wchar_t
c : m_Str) {
65
if
(bidi.AppendChar(c))
66
m_Order.push_back(bidi.GetSegmentInfo());
67
}
68
if
(bidi.EndChar())
69
m_Order.push_back(bidi.GetSegmentInfo());
70
71
size_t nR2L =
std
::count_if(
72
m_Order.begin(), m_Order.end(), [](
const
CFX_BidiChar
::
Segment
& seg) {
73
return
seg
.
direction
==
CFX_BidiChar
::
Direction
::
kRight
;
74
});
75
76
size_t nL2R =
std
::count_if(
77
m_Order.begin(), m_Order.end(), [](
const
CFX_BidiChar
::
Segment
& seg) {
78
return
seg
.
direction
==
CFX_BidiChar
::
Direction
::
kLeft
;
79
});
80
81
if
(nR2L > 0 && nR2L >= nL2R)
82
SetOverallDirectionRight
(
)
;
83
}
84
85
CFX_BidiString
::~
CFX_BidiString
() =
default
;
86
87
CFX_BidiChar
::
Direction
CFX_BidiString
::
OverallDirection
()
const
{
88
DCHECK_NE
(m_eOverallDirection,
CFX_BidiChar
::
Direction
::
kNeutral
);
89
DCHECK_NE
(m_eOverallDirection,
CFX_BidiChar
::
Direction
::
kLeftWeak
);
90
return
m_eOverallDirection;
91
}
92
93
void
CFX_BidiString
::
SetOverallDirectionRight
() {
94
if
(m_eOverallDirection !=
CFX_BidiChar
::
Direction
::
kRight
) {
95
std
::reverse(m_Order.begin(), m_Order.end());
96
m_eOverallDirection =
CFX_BidiChar
::
Direction
::
kRight
;
97
}
98
}
DCHECK_NE
#define DCHECK_NE(x, y)
Definition
check_op.h:18
CFX_BidiChar
Definition
fx_bidi.h:17
CFX_BidiChar::AppendChar
bool AppendChar(wchar_t wch)
Definition
fx_bidi.cpp:18
CFX_BidiChar::Direction
Direction
Definition
fx_bidi.h:19
CFX_BidiChar::Direction::kLeftWeak
@ kLeftWeak
Definition
fx_bidi.h:19
CFX_BidiChar::Direction::kLeft
@ kLeft
Definition
fx_bidi.h:19
CFX_BidiChar::Direction::kRight
@ kRight
Definition
fx_bidi.h:19
CFX_BidiChar::Direction::kNeutral
@ kNeutral
Definition
fx_bidi.h:19
CFX_BidiChar::CFX_BidiChar
CFX_BidiChar()
Definition
fx_bidi.cpp:14
CFX_BidiChar::EndChar
bool EndChar()
Definition
fx_bidi.cpp:50
CFX_BidiString
Definition
fx_bidi.h:49
CFX_BidiString::SetOverallDirectionRight
void SetOverallDirectionRight()
Definition
fx_bidi.cpp:93
CFX_BidiString::~CFX_BidiString
~CFX_BidiString()
CFX_BidiString::CFX_BidiString
CFX_BidiString(const WideString &str)
Definition
fx_bidi.cpp:62
CFX_BidiString::OverallDirection
CFX_BidiChar::Direction OverallDirection() const
Definition
fx_bidi.cpp:87
pdfium::CFDETextOutLargeBitmapTest
Definition
cfde_textout_unittest.cpp:117
FX_BIDICLASS
FX_BIDICLASS
Definition
fx_unicode.h:13
FX_BIDICLASS::kAL
@ kAL
Definition
fx_unicode.h:19
FX_BIDICLASS::kET
@ kET
Definition
fx_unicode.h:23
FX_BIDICLASS::kES
@ kES
Definition
fx_unicode.h:22
FX_BIDICLASS::kL
@ kL
Definition
fx_unicode.h:15
FX_BIDICLASS::kCS
@ kCS
Definition
fx_unicode.h:21
FX_BIDICLASS::kAN
@ kAN
Definition
fx_unicode.h:17
FX_BIDICLASS::kNSM
@ kNSM
Definition
fx_unicode.h:20
FX_BIDICLASS::kEN
@ kEN
Definition
fx_unicode.h:18
FX_BIDICLASS::kR
@ kR
Definition
fx_unicode.h:16
FX_BIDICLASS::kBN
@ kBN
Definition
fx_unicode.h:24
pdfium::unicode
Definition
fx_unicode.h:97
pdfium::unicode::GetBidiClass
FX_BIDICLASS GetBidiClass(wchar_t wch)
Definition
fx_unicode.cpp:156
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
CFX_BidiChar::Segment
Definition
fx_bidi.h:20
CFX_BidiChar::Segment::start
int32_t start
Definition
fx_bidi.h:21
CFX_BidiChar::Segment::count
int32_t count
Definition
fx_bidi.h:22
CFX_BidiChar::Segment::direction
Direction direction
Definition
fx_bidi.h:23
WideString
fxcrt::WideString WideString
Definition
widestring.h:207
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fxcrt
fx_bidi.cpp
Generated on
for Qt by
1.16.1