| 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 #include "xfa/fgas/layout/fgas_rtfbreak.h" | 7 #include "xfa/fgas/layout/fgas_rtfbreak.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "core/fxcrt/include/fx_arabic.h" |
| 11 #include "core/fxcrt/include/fx_arb.h" | 12 #include "core/fxcrt/include/fx_arb.h" |
| 12 #include "xfa/fgas/layout/fgas_linebreak.h" | 13 #include "xfa/fgas/layout/fgas_linebreak.h" |
| 13 #include "xfa/fgas/layout/fgas_unicode.h" | 14 #include "xfa/fgas/layout/fgas_unicode.h" |
| 14 | 15 |
| 15 namespace { | |
| 16 | |
| 17 class CFX_RTFLine { | |
| 18 public: | |
| 19 CFX_RTFLine() | |
| 20 : m_LinePieces(16), | |
| 21 m_iStart(0), | |
| 22 m_iWidth(0), | |
| 23 m_iArabicChars(0), | |
| 24 m_iMBCSChars(0) {} | |
| 25 ~CFX_RTFLine() { RemoveAll(); } | |
| 26 int32_t CountChars() const { return m_LineChars.GetSize(); } | |
| 27 CFX_RTFChar& GetChar(int32_t index) { | |
| 28 FXSYS_assert(index > -1 && index < m_LineChars.GetSize()); | |
| 29 return *m_LineChars.GetDataPtr(index); | |
| 30 } | |
| 31 CFX_RTFChar* GetCharPtr(int32_t index) { | |
| 32 FXSYS_assert(index > -1 && index < m_LineChars.GetSize()); | |
| 33 return m_LineChars.GetDataPtr(index); | |
| 34 } | |
| 35 int32_t CountPieces() const { return m_LinePieces.GetSize(); } | |
| 36 CFX_RTFPiece& GetPiece(int32_t index) const { | |
| 37 FXSYS_assert(index > -1 && index < m_LinePieces.GetSize()); | |
| 38 return m_LinePieces.GetAt(index); | |
| 39 } | |
| 40 CFX_RTFPiece* GetPiecePtr(int32_t index) const { | |
| 41 FXSYS_assert(index > -1 && index < m_LinePieces.GetSize()); | |
| 42 return m_LinePieces.GetPtrAt(index); | |
| 43 } | |
| 44 int32_t GetLineEnd() const { return m_iStart + m_iWidth; } | |
| 45 void RemoveAll(FX_BOOL bLeaveMemory = FALSE) { | |
| 46 CFX_RTFChar* pChar; | |
| 47 IFX_Unknown* pUnknown; | |
| 48 int32_t iCount = m_LineChars.GetSize(); | |
| 49 for (int32_t i = 0; i < iCount; i++) { | |
| 50 pChar = m_LineChars.GetDataPtr(i); | |
| 51 if ((pUnknown = pChar->m_pUserData) != NULL) { | |
| 52 pUnknown->Release(); | |
| 53 } | |
| 54 } | |
| 55 m_LineChars.RemoveAll(); | |
| 56 m_LinePieces.RemoveAll(bLeaveMemory); | |
| 57 m_iWidth = 0; | |
| 58 m_iArabicChars = 0; | |
| 59 m_iMBCSChars = 0; | |
| 60 } | |
| 61 CFX_RTFCharArray m_LineChars; | |
| 62 CFX_RTFPieceArray m_LinePieces; | |
| 63 int32_t m_iStart; | |
| 64 int32_t m_iWidth; | |
| 65 int32_t m_iArabicChars; | |
| 66 int32_t m_iMBCSChars; | |
| 67 }; | |
| 68 | |
| 69 class CFX_RTFBreak : public IFX_RTFBreak { | |
| 70 public: | |
| 71 CFX_RTFBreak(uint32_t dwPolicies); | |
| 72 ~CFX_RTFBreak(); | |
| 73 void Release() override { delete this; } | |
| 74 void SetLineBoundary(FX_FLOAT fLineStart, FX_FLOAT fLineEnd) override; | |
| 75 void SetLineStartPos(FX_FLOAT fLinePos) override; | |
| 76 uint32_t GetLayoutStyles() const override { return m_dwLayoutStyles; } | |
| 77 void SetLayoutStyles(uint32_t dwLayoutStyles) override; | |
| 78 void SetFont(IFX_Font* pFont) override; | |
| 79 void SetFontSize(FX_FLOAT fFontSize) override; | |
| 80 void SetTabWidth(FX_FLOAT fTabWidth) override; | |
| 81 void AddPositionedTab(FX_FLOAT fTabPos) override; | |
| 82 void SetPositionedTabs(const CFX_FloatArray& tabs) override; | |
| 83 void ClearPositionedTabs() override; | |
| 84 void SetDefaultChar(FX_WCHAR wch) override; | |
| 85 void SetLineBreakChar(FX_WCHAR wch) override; | |
| 86 void SetLineBreakTolerance(FX_FLOAT fTolerance) override; | |
| 87 void SetHorizontalScale(int32_t iScale) override; | |
| 88 void SetVerticalScale(int32_t iScale) override; | |
| 89 void SetCharRotation(int32_t iCharRotation) override; | |
| 90 void SetCharSpace(FX_FLOAT fCharSpace) override; | |
| 91 void SetWordSpace(FX_BOOL bDefault, FX_FLOAT fWordSpace) override; | |
| 92 void SetReadingOrder(FX_BOOL bRTL = FALSE) override; | |
| 93 void SetAlignment(int32_t iAlignment = FX_RTFLINEALIGNMENT_Left) override; | |
| 94 void SetUserData(IFX_Unknown* pUserData) override; | |
| 95 uint32_t AppendChar(FX_WCHAR wch) override; | |
| 96 uint32_t EndBreak(uint32_t dwStatus = FX_RTFBREAK_PieceBreak) override; | |
| 97 int32_t CountBreakPieces() const override; | |
| 98 const CFX_RTFPiece* GetBreakPiece(int32_t index) const override; | |
| 99 void GetLineRect(CFX_RectF& rect) const override; | |
| 100 void ClearBreakPieces() override; | |
| 101 void Reset() override; | |
| 102 int32_t GetDisplayPos( | |
| 103 const FX_RTFTEXTOBJ* pText, | |
| 104 FXTEXT_CHARPOS* pCharPos, | |
| 105 FX_BOOL bCharCode = FALSE, | |
| 106 CFX_WideString* pWSForms = NULL, | |
| 107 FX_AdjustCharDisplayPos pAdjustPos = NULL) const override; | |
| 108 int32_t GetCharRects(const FX_RTFTEXTOBJ* pText, | |
| 109 CFX_RectFArray& rtArray, | |
| 110 FX_BOOL bCharBBox = FALSE) const override; | |
| 111 uint32_t AppendChar_CharCode(FX_WCHAR wch); | |
| 112 uint32_t AppendChar_Combination(CFX_RTFChar* pCurChar, int32_t iRotation); | |
| 113 uint32_t AppendChar_Tab(CFX_RTFChar* pCurChar, int32_t iRotation); | |
| 114 uint32_t AppendChar_Control(CFX_RTFChar* pCurChar, int32_t iRotation); | |
| 115 uint32_t AppendChar_Arabic(CFX_RTFChar* pCurChar, int32_t iRotation); | |
| 116 uint32_t AppendChar_Others(CFX_RTFChar* pCurChar, int32_t iRotation); | |
| 117 | |
| 118 protected: | |
| 119 uint32_t m_dwPolicies; | |
| 120 IFX_ArabicChar* m_pArabicChar; | |
| 121 int32_t m_iBoundaryStart; | |
| 122 int32_t m_iBoundaryEnd; | |
| 123 uint32_t m_dwLayoutStyles; | |
| 124 FX_BOOL m_bPagination; | |
| 125 FX_BOOL m_bVertical; | |
| 126 FX_BOOL m_bSingleLine; | |
| 127 FX_BOOL m_bCharCode; | |
| 128 IFX_Font* m_pFont; | |
| 129 int32_t m_iFontHeight; | |
| 130 int32_t m_iFontSize; | |
| 131 int32_t m_iTabWidth; | |
| 132 CFX_Int32Array m_PositionedTabs; | |
| 133 FX_BOOL m_bOrphanLine; | |
| 134 FX_WCHAR m_wDefChar; | |
| 135 int32_t m_iDefChar; | |
| 136 FX_WCHAR m_wLineBreakChar; | |
| 137 int32_t m_iHorizontalScale; | |
| 138 int32_t m_iVerticalScale; | |
| 139 int32_t m_iLineRotation; | |
| 140 int32_t m_iCharRotation; | |
| 141 int32_t m_iRotation; | |
| 142 int32_t m_iCharSpace; | |
| 143 FX_BOOL m_bWordSpace; | |
| 144 int32_t m_iWordSpace; | |
| 145 FX_BOOL m_bRTL; | |
| 146 int32_t m_iAlignment; | |
| 147 IFX_Unknown* m_pUserData; | |
| 148 uint32_t m_dwCharType; | |
| 149 uint32_t m_dwIdentity; | |
| 150 CFX_RTFLine m_RTFLine1; | |
| 151 CFX_RTFLine m_RTFLine2; | |
| 152 CFX_RTFLine* m_pCurLine; | |
| 153 int32_t m_iReady; | |
| 154 int32_t m_iTolerance; | |
| 155 int32_t GetLineRotation(uint32_t dwStyles) const; | |
| 156 void SetBreakStatus(); | |
| 157 CFX_RTFChar* GetLastChar(int32_t index) const; | |
| 158 CFX_RTFLine* GetRTFLine(FX_BOOL bReady) const; | |
| 159 CFX_RTFPieceArray* GetRTFPieces(FX_BOOL bReady) const; | |
| 160 uint32_t GetUnifiedCharType(uint32_t dwType) const; | |
| 161 int32_t GetLastPositionedTab() const; | |
| 162 FX_BOOL GetPositionedTab(int32_t& iTabPos) const; | |
| 163 int32_t GetBreakPos(CFX_RTFCharArray& tca, | |
| 164 int32_t& iEndPos, | |
| 165 FX_BOOL bAllChars = FALSE, | |
| 166 FX_BOOL bOnlyBrk = FALSE); | |
| 167 void SplitTextLine(CFX_RTFLine* pCurLine, | |
| 168 CFX_RTFLine* pNextLine, | |
| 169 FX_BOOL bAllChars = FALSE); | |
| 170 FX_BOOL EndBreak_SplitLine(CFX_RTFLine* pNextLine, | |
| 171 FX_BOOL bAllChars, | |
| 172 uint32_t dwStatus); | |
| 173 void EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus); | |
| 174 void EndBreak_Alignment(CFX_TPOArray& tpos, | |
| 175 FX_BOOL bAllChars, | |
| 176 uint32_t dwStatus); | |
| 177 }; | |
| 178 | |
| 179 } // namespace | |
| 180 | |
| 181 IFX_RTFBreak* IFX_RTFBreak::Create(uint32_t dwPolicies) { | |
| 182 return new CFX_RTFBreak(dwPolicies); | |
| 183 } | |
| 184 CFX_RTFBreak::CFX_RTFBreak(uint32_t dwPolicies) | 16 CFX_RTFBreak::CFX_RTFBreak(uint32_t dwPolicies) |
| 185 : m_dwPolicies(dwPolicies), | 17 : m_dwPolicies(dwPolicies), |
| 186 m_pArabicChar(NULL), | 18 m_pArabicChar(NULL), |
| 187 m_iBoundaryStart(0), | 19 m_iBoundaryStart(0), |
| 188 m_iBoundaryEnd(2000000), | 20 m_iBoundaryEnd(2000000), |
| 189 m_dwLayoutStyles(0), | 21 m_dwLayoutStyles(0), |
| 190 m_bPagination(FALSE), | 22 m_bPagination(FALSE), |
| 191 m_bVertical(FALSE), | 23 m_bVertical(FALSE), |
| 192 m_bSingleLine(FALSE), | 24 m_bSingleLine(FALSE), |
| 193 m_bCharCode(FALSE), | 25 m_bCharCode(FALSE), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 211 m_bRTL(FALSE), | 43 m_bRTL(FALSE), |
| 212 m_iAlignment(FX_RTFLINEALIGNMENT_Left), | 44 m_iAlignment(FX_RTFLINEALIGNMENT_Left), |
| 213 m_pUserData(NULL), | 45 m_pUserData(NULL), |
| 214 m_dwCharType(0), | 46 m_dwCharType(0), |
| 215 m_dwIdentity(0), | 47 m_dwIdentity(0), |
| 216 m_RTFLine1(), | 48 m_RTFLine1(), |
| 217 m_RTFLine2(), | 49 m_RTFLine2(), |
| 218 m_pCurLine(NULL), | 50 m_pCurLine(NULL), |
| 219 m_iReady(0), | 51 m_iReady(0), |
| 220 m_iTolerance(0) { | 52 m_iTolerance(0) { |
| 221 m_pArabicChar = IFX_ArabicChar::Create(); | 53 m_pArabicChar = new CFX_ArabicChar; |
| 222 m_pCurLine = &m_RTFLine1; | 54 m_pCurLine = &m_RTFLine1; |
| 223 } | 55 } |
| 224 CFX_RTFBreak::~CFX_RTFBreak() { | 56 CFX_RTFBreak::~CFX_RTFBreak() { |
| 225 Reset(); | 57 Reset(); |
| 226 m_PositionedTabs.RemoveAll(); | 58 m_PositionedTabs.RemoveAll(); |
| 227 m_pArabicChar->Release(); | 59 m_pArabicChar->Release(); |
| 228 if (m_pUserData != NULL) { | 60 if (m_pUserData != NULL) { |
| 229 m_pUserData->Release(); | 61 m_pUserData->Release(); |
| 230 } | 62 } |
| 231 } | 63 } |
| (...skipping 1450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1682 rtBBoxF.height = fHeight; | 1514 rtBBoxF.height = fHeight; |
| 1683 rtBBoxF.top = std::max(rtBBoxF.top, 0.0f); | 1515 rtBBoxF.top = std::max(rtBBoxF.top, 0.0f); |
| 1684 } | 1516 } |
| 1685 rtArray.SetAt(i, rtBBoxF); | 1517 rtArray.SetAt(i, rtBBoxF); |
| 1686 continue; | 1518 continue; |
| 1687 } | 1519 } |
| 1688 rtArray.SetAt(i, rect); | 1520 rtArray.SetAt(i, rect); |
| 1689 } | 1521 } |
| 1690 return iLength; | 1522 return iLength; |
| 1691 } | 1523 } |
| OLD | NEW |