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
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
17const float CFGAS_Break::kConversionFactor = 20000.0f;
18const int CFGAS_Break::kMinimumTabWidth = 160000;
19
22
23CFGAS_Break::~CFGAS_Break() = default;
24
26 m_eCharType = FX_CHARTYPE::kUnknown;
27 for (CFGAS_BreakLine& line : m_Lines)
28 line.Clear();
29}
30
32 m_dwLayoutStyles = dwLayoutStyles;
33 m_bSingleLine = !!(m_dwLayoutStyles & LayoutStyle::kSingleLine);
34 m_bCombText = !!(m_dwLayoutStyles & LayoutStyle::kCombText);
35}
36
37void CFGAS_Break::SetHorizontalScale(int32_t iScale) {
38 iScale = std::max(iScale, 0);
39 if (m_iHorizontalScale == iScale)
40 return;
41
43 m_iHorizontalScale = iScale;
44}
45
46void CFGAS_Break::SetVerticalScale(int32_t iScale) {
47 if (iScale < 0)
48 iScale = 0;
49 if (m_iVerticalScale == iScale)
50 return;
51
53 m_iVerticalScale = iScale;
54}
55
56void CFGAS_Break::SetFont(RetainPtr<CFGAS_GEFont> pFont) {
57 if (!pFont || pFont == m_pFont)
58 return;
59
61 m_pFont = std::move(pFont);
62}
63
64void CFGAS_Break::SetFontSize(float fFontSize) {
65 int32_t iFontSize = FXSYS_roundf(fFontSize * 20.0f);
66 if (m_iFontSize == iFontSize)
67 return;
68
70 m_iFontSize = iFontSize;
71}
72
75
76 CFGAS_Char* tc = m_pCurLine->LastChar();
79}
80
81bool 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
87FX_CHARTYPE CFGAS_Break::GetUnifiedCharType(FX_CHARTYPE chartype) const {
88 return chartype >= FX_CHARTYPE::kArabicAlef ? FX_CHARTYPE::kArabic : chartype;
89}
90
91void 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.
97}
98
100 if (wch != L'\r' && wch != L'\n')
101 return;
103}
104
105void CFGAS_Break::SetLineBreakTolerance(float fTolerance) {
107}
108
109void CFGAS_Break::SetCharSpace(float fCharSpace) {
111}
112
113void CFGAS_Break::SetLineBoundary(float fLineStart, float fLineEnd) {
114 if (fLineStart > fLineEnd)
115 return;
116
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
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
144 return HasLine() ? fxcrt::CollectionSize<int32_t>(
145 m_Lines[m_iReadyLineIndex].m_LinePieces)
146 : 0;
147}
148
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
159 if (HasLine())
160 m_Lines[m_iReadyLineIndex].Clear();
162}
void SetBreakStatus()
CFGAS_Break(Mask< LayoutStyle > dwLayoutStyles)
void SetCharSpace(float fCharSpace)
virtual ~CFGAS_Break()
int32_t m_iTabWidth
Definition cfgas_break.h:83
int32_t m_iHorizontalScale
Definition cfgas_break.h:84
void SetVerticalScale(int32_t iScale)
void SetFontSize(float fFontSize)
CFGAS_Char * GetLastChar(int32_t index, bool bOmitChar, bool bRichText) const
int32_t m_iVerticalScale
Definition cfgas_break.h:85
int8_t m_iReadyLineIndex
Definition cfgas_break.h:90
uint32_t m_dwIdentity
Definition cfgas_break.h:78
void ClearBreakPieces()
void SetHorizontalScale(int32_t iScale)
int32_t m_iCharSpace
Definition cfgas_break.h:87
wchar_t m_wParagraphBreakChar
Definition cfgas_break.h:81
const CFGAS_BreakPiece * GetBreakPieceUnstable(int32_t index) const
bool HasLine() const
Definition cfgas_break.h:70
void SetLineBreakTolerance(float fTolerance)
int32_t m_iFontSize
Definition cfgas_break.h:82
void SetLineBoundary(float fLineStart, float fLineEnd)
void SetFont(RetainPtr< CFGAS_GEFont > pFont)
int32_t CountBreakPieces() const
int32_t m_iLineStart
Definition cfgas_break.h:79
void SetLayoutStyles(Mask< LayoutStyle > dwLayoutStyles)
bool IsGreaterThanLineWidth(int32_t width) const
void SetParagraphBreakChar(wchar_t wch)
int32_t m_iTolerance
Definition cfgas_break.h:86
static const float kConversionFactor
Definition cfgas_break.h:65
void SetTabWidth(float fTabWidth)
int32_t m_iLineWidth
Definition cfgas_break.h:80
static const int kMinimumTabWidth
Definition cfgas_break.h:64
FX_CHARTYPE GetUnifiedCharType(FX_CHARTYPE dwType) const
BreakType m_dwStatus
Definition cfgas_char.h:43
int FXSYS_roundf(float f)
Definition fx_system.cpp:92