| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #ifndef XFA_FGAS_LAYOUT_FGAS_TEXTBREAK_H_ | 7 #ifndef XFA_FGAS_LAYOUT_FGAS_TEXTBREAK_H_ |
| 8 #define XFA_FGAS_LAYOUT_FGAS_TEXTBREAK_H_ | 8 #define XFA_FGAS_LAYOUT_FGAS_TEXTBREAK_H_ |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "core/fxcrt/fx_ucd.h" | 13 #include "core/fxcrt/fx_ucd.h" |
| 14 #include "core/fxge/cfx_renderdevice.h" | 14 #include "core/fxge/cfx_renderdevice.h" |
| 15 #include "third_party/base/stl_util.h" |
| 15 #include "xfa/fgas/crt/fgas_utils.h" | 16 #include "xfa/fgas/crt/fgas_utils.h" |
| 16 #include "xfa/fgas/layout/fgas_unicode.h" | 17 #include "xfa/fgas/layout/fgas_unicode.h" |
| 17 | 18 |
| 18 class CFX_Char; | 19 class CFX_Char; |
| 19 class CFGAS_GEFont; | 20 class CFGAS_GEFont; |
| 20 class CFX_TxtChar; | 21 class CFX_TxtChar; |
| 21 class CFX_TxtPiece; | 22 class CFX_TxtPiece; |
| 22 class IFX_TxtAccess; | 23 class IFX_TxtAccess; |
| 23 | 24 |
| 24 #define FX_TXTBREAKPOLICY_None 0x00 | 25 #define FX_TXTBREAKPOLICY_None 0x00 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 public: | 111 public: |
| 111 CFX_TxtPiece(); | 112 CFX_TxtPiece(); |
| 112 | 113 |
| 113 int32_t GetEndPos() const { | 114 int32_t GetEndPos() const { |
| 114 return m_iWidth < 0 ? m_iStartPos : m_iStartPos + m_iWidth; | 115 return m_iWidth < 0 ? m_iStartPos : m_iStartPos + m_iWidth; |
| 115 } | 116 } |
| 116 int32_t GetLength() const { return m_iChars; } | 117 int32_t GetLength() const { return m_iChars; } |
| 117 int32_t GetEndChar() const { return m_iStartChar + m_iChars; } | 118 int32_t GetEndChar() const { return m_iStartChar + m_iChars; } |
| 118 CFX_TxtChar* GetCharPtr(int32_t index) const { | 119 CFX_TxtChar* GetCharPtr(int32_t index) const { |
| 119 ASSERT(index > -1 && index < m_iChars && m_pChars); | 120 ASSERT(index > -1 && index < m_iChars && m_pChars); |
| 120 return m_pChars->GetDataPtr(m_iStartChar + index); | 121 return &(*m_pChars)[m_iStartChar + index]; |
| 121 } | 122 } |
| 122 void GetString(FX_WCHAR* pText) const { | 123 void GetString(FX_WCHAR* pText) const { |
| 123 ASSERT(pText); | 124 ASSERT(pText); |
| 124 int32_t iEndChar = m_iStartChar + m_iChars; | 125 int32_t iEndChar = m_iStartChar + m_iChars; |
| 125 CFX_Char* pChar; | 126 for (int32_t i = m_iStartChar; i < iEndChar; i++) |
| 126 for (int32_t i = m_iStartChar; i < iEndChar; i++) { | 127 *pText++ = static_cast<FX_WCHAR>((*m_pChars)[i].m_wCharCode); |
| 127 pChar = m_pChars->GetDataPtr(i); | |
| 128 *pText++ = (FX_WCHAR)pChar->m_wCharCode; | |
| 129 } | |
| 130 } | 128 } |
| 131 void GetString(CFX_WideString& wsText) const { | 129 void GetString(CFX_WideString& wsText) const { |
| 132 FX_WCHAR* pText = wsText.GetBuffer(m_iChars); | 130 FX_WCHAR* pText = wsText.GetBuffer(m_iChars); |
| 133 GetString(pText); | 131 GetString(pText); |
| 134 wsText.ReleaseBuffer(m_iChars); | 132 wsText.ReleaseBuffer(m_iChars); |
| 135 } | 133 } |
| 136 void GetWidths(int32_t* pWidths) const { | 134 void GetWidths(int32_t* pWidths) const { |
| 137 ASSERT(pWidths); | 135 ASSERT(pWidths); |
| 138 int32_t iEndChar = m_iStartChar + m_iChars; | 136 int32_t iEndChar = m_iStartChar + m_iChars; |
| 139 CFX_Char* pChar; | 137 for (int32_t i = m_iStartChar; i < iEndChar; i++) |
| 140 for (int32_t i = m_iStartChar; i < iEndChar; i++) { | 138 *pWidths++ = (*m_pChars)[i].m_iCharWidth; |
| 141 pChar = m_pChars->GetDataPtr(i); | |
| 142 *pWidths++ = pChar->m_iCharWidth; | |
| 143 } | |
| 144 } | 139 } |
| 145 | 140 |
| 146 uint32_t m_dwStatus; | 141 uint32_t m_dwStatus; |
| 147 int32_t m_iStartPos; | 142 int32_t m_iStartPos; |
| 148 int32_t m_iWidth; | 143 int32_t m_iWidth; |
| 149 int32_t m_iStartChar; | 144 int32_t m_iStartChar; |
| 150 int32_t m_iChars; | 145 int32_t m_iChars; |
| 151 int32_t m_iBidiLevel; | 146 int32_t m_iBidiLevel; |
| 152 int32_t m_iBidiPos; | 147 int32_t m_iBidiPos; |
| 153 int32_t m_iHorizontalScale; | 148 int32_t m_iHorizontalScale; |
| 154 int32_t m_iVerticalScale; | 149 int32_t m_iVerticalScale; |
| 155 uint32_t m_dwCharStyles; | 150 uint32_t m_dwCharStyles; |
| 156 CFX_TxtCharArray* m_pChars; | 151 std::vector<CFX_TxtChar>* m_pChars; |
| 157 void* m_pUserData; | 152 void* m_pUserData; |
| 158 }; | 153 }; |
| 159 | 154 |
| 160 typedef CFX_BaseArrayTemplate<CFX_TxtPiece> CFX_TxtPieceArray; | 155 typedef CFX_BaseArrayTemplate<CFX_TxtPiece> CFX_TxtPieceArray; |
| 161 | 156 |
| 162 class CFX_TxtLine { | 157 class CFX_TxtLine { |
| 163 public: | 158 public: |
| 164 explicit CFX_TxtLine(int32_t iBlockSize); | 159 explicit CFX_TxtLine(int32_t iBlockSize); |
| 165 ~CFX_TxtLine(); | 160 ~CFX_TxtLine(); |
| 166 | 161 |
| 167 int32_t CountChars() const { return m_pLineChars->GetSize(); } | 162 int32_t CountChars() const { |
| 163 return pdfium::CollectionSize<int32_t>(*m_pLineChars); |
| 164 } |
| 165 |
| 168 CFX_TxtChar* GetCharPtr(int32_t index) const { | 166 CFX_TxtChar* GetCharPtr(int32_t index) const { |
| 169 ASSERT(index > -1 && index < m_pLineChars->GetSize()); | 167 ASSERT(index >= 0 && |
| 170 return m_pLineChars->GetDataPtr(index); | 168 index < pdfium::CollectionSize<int32_t>(*m_pLineChars)); |
| 169 return &(*m_pLineChars)[index]; |
| 171 } | 170 } |
| 171 |
| 172 int32_t CountPieces() const { return m_pLinePieces->GetSize(); } | 172 int32_t CountPieces() const { return m_pLinePieces->GetSize(); } |
| 173 CFX_TxtPiece* GetPiecePtr(int32_t index) const { | 173 CFX_TxtPiece* GetPiecePtr(int32_t index) const { |
| 174 ASSERT(index > -1 && index < m_pLinePieces->GetSize()); | 174 ASSERT(index > -1 && index < m_pLinePieces->GetSize()); |
| 175 return m_pLinePieces->GetPtrAt(index); | 175 return m_pLinePieces->GetPtrAt(index); |
| 176 } | 176 } |
| 177 |
| 177 void GetString(CFX_WideString& wsStr) const { | 178 void GetString(CFX_WideString& wsStr) const { |
| 178 int32_t iCount = m_pLineChars->GetSize(); | 179 int32_t iCount = pdfium::CollectionSize<int32_t>(*m_pLineChars); |
| 179 FX_WCHAR* pBuf = wsStr.GetBuffer(iCount); | 180 FX_WCHAR* pBuf = wsStr.GetBuffer(iCount); |
| 180 CFX_Char* pChar; | 181 for (int32_t i = 0; i < iCount; i++) |
| 181 for (int32_t i = 0; i < iCount; i++) { | 182 *pBuf++ = static_cast<FX_WCHAR>((*m_pLineChars)[i].m_wCharCode); |
| 182 pChar = m_pLineChars->GetDataPtr(i); | |
| 183 *pBuf++ = (FX_WCHAR)pChar->m_wCharCode; | |
| 184 } | |
| 185 wsStr.ReleaseBuffer(iCount); | 183 wsStr.ReleaseBuffer(iCount); |
| 186 } | 184 } |
| 185 |
| 187 void RemoveAll(bool bLeaveMemory = false) { | 186 void RemoveAll(bool bLeaveMemory = false) { |
| 188 m_pLineChars->RemoveAll(); | 187 m_pLineChars->clear(); |
| 189 m_pLinePieces->RemoveAll(bLeaveMemory); | 188 m_pLinePieces->RemoveAll(bLeaveMemory); |
| 190 m_iWidth = 0; | 189 m_iWidth = 0; |
| 191 m_iArabicChars = 0; | 190 m_iArabicChars = 0; |
| 192 } | 191 } |
| 193 | 192 |
| 194 std::unique_ptr<CFX_TxtCharArray> m_pLineChars; | 193 std::unique_ptr<std::vector<CFX_TxtChar>> m_pLineChars; |
| 195 std::unique_ptr<CFX_TxtPieceArray> m_pLinePieces; | 194 std::unique_ptr<CFX_TxtPieceArray> m_pLinePieces; |
| 196 int32_t m_iStart; | 195 int32_t m_iStart; |
| 197 int32_t m_iWidth; | 196 int32_t m_iWidth; |
| 198 int32_t m_iArabicChars; | 197 int32_t m_iArabicChars; |
| 199 }; | 198 }; |
| 200 | 199 |
| 201 class CFX_TxtBreak { | 200 class CFX_TxtBreak { |
| 202 public: | 201 public: |
| 203 explicit CFX_TxtBreak(uint32_t dwPolicies); | 202 explicit CFX_TxtBreak(uint32_t dwPolicies); |
| 204 ~CFX_TxtBreak(); | 203 ~CFX_TxtBreak(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 void ResetArabicContext(); | 253 void ResetArabicContext(); |
| 255 void ResetContextCharStyles(); | 254 void ResetContextCharStyles(); |
| 256 void EndBreak_UpdateArabicShapes(); | 255 void EndBreak_UpdateArabicShapes(); |
| 257 bool EndBreak_SplitLine(CFX_TxtLine* pNextLine, | 256 bool EndBreak_SplitLine(CFX_TxtLine* pNextLine, |
| 258 bool bAllChars, | 257 bool bAllChars, |
| 259 uint32_t dwStatus); | 258 uint32_t dwStatus); |
| 260 void EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus); | 259 void EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus); |
| 261 void EndBreak_Alignment(CFX_TPOArray& tpos, | 260 void EndBreak_Alignment(CFX_TPOArray& tpos, |
| 262 bool bAllChars, | 261 bool bAllChars, |
| 263 uint32_t dwStatus); | 262 uint32_t dwStatus); |
| 264 int32_t GetBreakPos(CFX_TxtCharArray& ca, | 263 int32_t GetBreakPos(std::vector<CFX_TxtChar>& ca, |
| 265 int32_t& iEndPos, | 264 int32_t& iEndPos, |
| 266 bool bAllChars = false, | 265 bool bAllChars = false, |
| 267 bool bOnlyBrk = false); | 266 bool bOnlyBrk = false); |
| 268 void SplitTextLine(CFX_TxtLine* pCurLine, | 267 void SplitTextLine(CFX_TxtLine* pCurLine, |
| 269 CFX_TxtLine* pNextLine, | 268 CFX_TxtLine* pNextLine, |
| 270 bool bAllChars = false); | 269 bool bAllChars = false); |
| 271 | 270 |
| 272 uint32_t m_dwPolicies; | 271 uint32_t m_dwPolicies; |
| 273 bool m_bPagination; | 272 bool m_bPagination; |
| 274 int32_t m_iLineWidth; | 273 int32_t m_iLineWidth; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 304 std::unique_ptr<CFX_TxtLine> m_pTxtLine2; | 303 std::unique_ptr<CFX_TxtLine> m_pTxtLine2; |
| 305 CFX_TxtLine* m_pCurLine; | 304 CFX_TxtLine* m_pCurLine; |
| 306 int32_t m_iReady; | 305 int32_t m_iReady; |
| 307 int32_t m_iTolerance; | 306 int32_t m_iTolerance; |
| 308 int32_t m_iHorScale; | 307 int32_t m_iHorScale; |
| 309 int32_t m_iVerScale; | 308 int32_t m_iVerScale; |
| 310 int32_t m_iCharSpace; | 309 int32_t m_iCharSpace; |
| 311 }; | 310 }; |
| 312 | 311 |
| 313 #endif // XFA_FGAS_LAYOUT_FGAS_TEXTBREAK_H_ | 312 #endif // XFA_FGAS_LAYOUT_FGAS_TEXTBREAK_H_ |
| OLD | NEW |