Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
cfgas_break.cpp
Go to the documentation of this file.
1
// Copyright 2017 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
"xfa/fgas/layout/cfgas_break.h"
8
9
#
include
<
algorithm
>
10
#
include
<
utility
>
11
#
include
<
vector
>
12
13
#
include
"core/fxcrt/fx_safe_types.h"
14
#
include
"core/fxcrt/stl_util.h"
15
#
include
"xfa/fgas/font/cfgas_gefont.h"
16
17
const
float
CFGAS_Break
::
kConversionFactor
= 20000.0f;
18
const
int
CFGAS_Break
::
kMinimumTabWidth
= 160000;
19
20
CFGAS_Break
::
CFGAS_Break
(
Mask
<
LayoutStyle
> dwLayoutStyles)
21
:
m_dwLayoutStyles
(
dwLayoutStyles
),
m_pCurLine
(&
m_Lines
[0]) {}
22
23
CFGAS_Break
::~
CFGAS_Break
() =
default
;
24
25
void
CFGAS_Break
::
Reset
() {
26
m_eCharType = FX_CHARTYPE::kUnknown;
27
for
(CFGAS_BreakLine& line : m_Lines)
28
line.Clear();
29
}
30
31
void
CFGAS_Break
::
SetLayoutStyles
(
Mask
<
LayoutStyle
> dwLayoutStyles) {
32
m_dwLayoutStyles = dwLayoutStyles;
33
m_bSingleLine
= !!(m_dwLayoutStyles & LayoutStyle::kSingleLine);
34
m_bCombText
= !!(m_dwLayoutStyles & LayoutStyle::kCombText);
35
}
36
37
void
CFGAS_Break
::
SetHorizontalScale
(int32_t iScale) {
38
iScale =
std
::max(iScale, 0);
39
if
(
m_iHorizontalScale
== iScale)
40
return
;
41
42
SetBreakStatus
(
)
;
43
m_iHorizontalScale
= iScale;
44
}
45
46
void
CFGAS_Break
::
SetVerticalScale
(int32_t iScale) {
47
if
(iScale < 0)
48
iScale = 0;
49
if
(
m_iVerticalScale
== iScale)
50
return
;
51
52
SetBreakStatus
(
)
;
53
m_iVerticalScale
= iScale;
54
}
55
56
void
CFGAS_Break
::
SetFont
(
RetainPtr
<CFGAS_GEFont> pFont) {
57
if
(!pFont || pFont == m_pFont)
58
return
;
59
60
SetBreakStatus
(
)
;
61
m_pFont = std::move(pFont);
62
}
63
64
void
CFGAS_Break
::
SetFontSize
(
float
fFontSize) {
65
int32_t iFontSize =
FXSYS_roundf
(
fFontSize * 20.0f
)
;
66
if
(
m_iFontSize
== iFontSize)
67
return
;
68
69
SetBreakStatus
(
)
;
70
m_iFontSize
= iFontSize;
71
}
72
73
void
CFGAS_Break
::
SetBreakStatus
() {
74
++
m_dwIdentity
;
75
76
CFGAS_Char
* tc = m_pCurLine->LastChar();
77
if
(tc && tc
->
m_dwStatus
==
CFGAS_Char
::
BreakType
::
kNone
)
78
tc
->
m_dwStatus
=
CFGAS_Char
::
BreakType
::
kPiece
;
79
}
80
81
bool
CFGAS_Break
::
IsGreaterThanLineWidth
(int32_t width)
const
{
82
FX_SAFE_INT32
line_width = m_iLineWidth;
83
line_width +=
m_iTolerance
;
84
return
line_width.IsValid() && width > line_width.ValueOrDie();
85
}
86
87
FX_CHARTYPE
CFGAS_Break
::
GetUnifiedCharType
(FX_CHARTYPE chartype)
const
{
88
return
chartype >= FX_CHARTYPE::kArabicAlef ? FX_CHARTYPE::kArabic : chartype;
89
}
90
91
void
CFGAS_Break
::
SetTabWidth
(
float
fTabWidth) {
92
// Note, the use of max here was only done in the TxtBreak code. Leaving this
93
// in for the RTFBreak code for consistency. If we see issues with tab widths
94
// we may need to fix this.
95
m_iTabWidth
=
96
std
::max(
FXSYS_roundf
(
fTabWidth *
kConversionFactor
)
,
kMinimumTabWidth
);
97
}
98
99
void
CFGAS_Break
::
SetParagraphBreakChar
(
wchar_t
wch) {
100
if
(wch != L'\r' && wch != L'\n')
101
return
;
102
m_wParagraphBreakChar
= wch;
103
}
104
105
void
CFGAS_Break
::
SetLineBreakTolerance
(
float
fTolerance) {
106
m_iTolerance
=
FXSYS_roundf
(
fTolerance *
kConversionFactor
)
;
107
}
108
109
void
CFGAS_Break
::
SetCharSpace
(
float
fCharSpace) {
110
m_iCharSpace
=
FXSYS_roundf
(
fCharSpace *
kConversionFactor
)
;
111
}
112
113
void
CFGAS_Break
::
SetLineBoundary
(
float
fLineStart,
float
fLineEnd) {
114
if
(fLineStart > fLineEnd)
115
return
;
116
117
m_iLineStart
=
FXSYS_roundf
(
fLineStart *
kConversionFactor
)
;
118
m_iLineWidth
=
FXSYS_roundf
(
fLineEnd *
kConversionFactor
)
;
119
m_pCurLine->m_iStart = std::min(m_pCurLine->m_iStart, m_iLineWidth);
120
m_pCurLine->m_iStart = std::max(m_pCurLine->m_iStart, m_iLineStart);
121
}
122
123
CFGAS_Char
*
CFGAS_Break
::
GetLastChar
(int32_t index,
124
bool
bOmitChar,
125
bool
bRichText)
const
{
126
std::vector<CFGAS_Char>& tca = m_pCurLine->m_LineChars;
127
if
(!
fxcrt
::IndexInBounds(tca, index))
128
return
nullptr
;
129
130
int32_t iStart =
fxcrt
::CollectionSize<int32_t>(tca) - 1;
131
while
(iStart > -1) {
132
CFGAS_Char
* pTC = &tca[iStart--];
133
if
(((bRichText && pTC->m_iCharWidth < 0) || bOmitChar) &&
134
pTC->GetCharType() == FX_CHARTYPE::kCombination) {
135
continue
;
136
}
137
if
(--index < 0)
138
return
pTC;
139
}
140
return
nullptr
;
141
}
142
143
int32_t
CFGAS_Break
::
CountBreakPieces
()
const
{
144
return
HasLine
(
)
?
fxcrt
::CollectionSize<int32_t>(
145
m_Lines[m_iReadyLineIndex].m_LinePieces)
146
: 0;
147
}
148
149
const
CFGAS_BreakPiece
*
CFGAS_Break
::
GetBreakPieceUnstable
(
150
int32_t index)
const
{
151
if
(!
HasLine
(
)
)
152
return
nullptr
;
153
if
(!
fxcrt
::IndexInBounds(m_Lines[m_iReadyLineIndex].m_LinePieces, index))
154
return
nullptr
;
155
return
&m_Lines[m_iReadyLineIndex].m_LinePieces[index];
156
}
157
158
void
CFGAS_Break
::
ClearBreakPieces
() {
159
if
(HasLine())
160
m_Lines[m_iReadyLineIndex].Clear();
161
m_iReadyLineIndex
= -1;
162
}
CFGAS_BreakPiece
Definition
cfgas_breakpiece.h:19
CFGAS_Break
Definition
cfgas_break.h:21
CFGAS_Break::m_bCombText
bool m_bCombText
Definition
cfgas_break.h:78
CFGAS_Break::Reset
void Reset()
Definition
cfgas_break.cpp:25
CFGAS_Break::SetBreakStatus
void SetBreakStatus()
Definition
cfgas_break.cpp:73
CFGAS_Break::CFGAS_Break
CFGAS_Break(Mask< LayoutStyle > dwLayoutStyles)
Definition
cfgas_break.cpp:20
CFGAS_Break::SetCharSpace
void SetCharSpace(float fCharSpace)
Definition
cfgas_break.cpp:109
CFGAS_Break::~CFGAS_Break
virtual ~CFGAS_Break()
CFGAS_Break::m_iTabWidth
int32_t m_iTabWidth
Definition
cfgas_break.h:85
CFGAS_Break::m_iHorizontalScale
int32_t m_iHorizontalScale
Definition
cfgas_break.h:86
CFGAS_Break::SetVerticalScale
void SetVerticalScale(int32_t iScale)
Definition
cfgas_break.cpp:46
CFGAS_Break::SetFontSize
void SetFontSize(float fFontSize)
Definition
cfgas_break.cpp:64
CFGAS_Break::GetLastChar
CFGAS_Char * GetLastChar(int32_t index, bool bOmitChar, bool bRichText) const
Definition
cfgas_break.cpp:123
CFGAS_Break::m_iVerticalScale
int32_t m_iVerticalScale
Definition
cfgas_break.h:87
CFGAS_Break::LayoutStyle
LayoutStyle
Definition
cfgas_break.h:23
CFGAS_Break::m_iReadyLineIndex
int8_t m_iReadyLineIndex
Definition
cfgas_break.h:91
CFGAS_Break::m_dwIdentity
uint32_t m_dwIdentity
Definition
cfgas_break.h:80
CFGAS_Break::m_bSingleLine
bool m_bSingleLine
Definition
cfgas_break.h:77
CFGAS_Break::ClearBreakPieces
void ClearBreakPieces()
Definition
cfgas_break.cpp:158
CFGAS_Break::SetHorizontalScale
void SetHorizontalScale(int32_t iScale)
Definition
cfgas_break.cpp:37
CFGAS_Break::m_iCharSpace
int32_t m_iCharSpace
Definition
cfgas_break.h:89
CFGAS_Break::m_wParagraphBreakChar
wchar_t m_wParagraphBreakChar
Definition
cfgas_break.h:83
CFGAS_Break::GetBreakPieceUnstable
const CFGAS_BreakPiece * GetBreakPieceUnstable(int32_t index) const
Definition
cfgas_break.cpp:149
CFGAS_Break::HasLine
bool HasLine() const
Definition
cfgas_break.h:72
CFGAS_Break::SetLineBreakTolerance
void SetLineBreakTolerance(float fTolerance)
Definition
cfgas_break.cpp:105
CFGAS_Break::m_iFontSize
int32_t m_iFontSize
Definition
cfgas_break.h:84
CFGAS_Break::SetLineBoundary
void SetLineBoundary(float fLineStart, float fLineEnd)
Definition
cfgas_break.cpp:113
CFGAS_Break::SetFont
void SetFont(RetainPtr< CFGAS_GEFont > pFont)
Definition
cfgas_break.cpp:56
CFGAS_Break::CountBreakPieces
int32_t CountBreakPieces() const
Definition
cfgas_break.cpp:143
CFGAS_Break::m_iLineStart
int32_t m_iLineStart
Definition
cfgas_break.h:81
CFGAS_Break::SetLayoutStyles
void SetLayoutStyles(Mask< LayoutStyle > dwLayoutStyles)
Definition
cfgas_break.cpp:31
CFGAS_Break::IsGreaterThanLineWidth
bool IsGreaterThanLineWidth(int32_t width) const
Definition
cfgas_break.cpp:81
CFGAS_Break::SetParagraphBreakChar
void SetParagraphBreakChar(wchar_t wch)
Definition
cfgas_break.cpp:99
CFGAS_Break::m_iTolerance
int32_t m_iTolerance
Definition
cfgas_break.h:88
CFGAS_Break::kConversionFactor
static const float kConversionFactor
Definition
cfgas_break.h:67
CFGAS_Break::SetTabWidth
void SetTabWidth(float fTabWidth)
Definition
cfgas_break.cpp:91
CFGAS_Break::m_iLineWidth
int32_t m_iLineWidth
Definition
cfgas_break.h:82
CFGAS_Break::kMinimumTabWidth
static const int kMinimumTabWidth
Definition
cfgas_break.h:66
CFGAS_Break::GetUnifiedCharType
FX_CHARTYPE GetUnifiedCharType(FX_CHARTYPE dwType) const
Definition
cfgas_break.cpp:87
CFGAS_Char
Definition
cfgas_char.h:19
CFGAS_Char::BreakType
BreakType
Definition
cfgas_char.h:21
CFGAS_Char::BreakType::kNone
@ kNone
Definition
cfgas_char.h:22
CFGAS_Char::BreakType::kPiece
@ kPiece
Definition
cfgas_char.h:23
CFGAS_Char::m_dwStatus
BreakType m_dwStatus
Definition
cfgas_char.h:43
fxcrt::Mask
Definition
mask.h:15
fxcrt::RetainPtr
Definition
retain_ptr.h:28
FX_SAFE_INT32
pdfium::CheckedNumeric< int32_t > FX_SAFE_INT32
Definition
fx_safe_types.h:15
FXSYS_roundf
int FXSYS_roundf(float f)
Definition
fx_system.cpp:100
fxcrt
Definition
stl_util.h:17
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtwebengine
src
3rdparty
chromium
third_party
pdfium
xfa
fgas
layout
cfgas_break.cpp
Generated on
for Qt by
1.18.0