| 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_FXFA_APP_XFA_TEXTLAYOUT_H_ | 7 #ifndef XFA_FXFA_APP_XFA_TEXTLAYOUT_H_ |
| 8 #define XFA_FXFA_APP_XFA_TEXTLAYOUT_H_ | 8 #define XFA_FXFA_APP_XFA_TEXTLAYOUT_H_ |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "xfa/fde/css/fde_css.h" | 13 #include "xfa/fde/css/fde_css.h" |
| 14 #include "xfa/fde/fde_gedevice.h" | 14 #include "xfa/fde/fde_gedevice.h" |
| 15 #include "xfa/fxfa/include/xfa_ffdoc.h" |
| 15 #include "xfa/fgas/layout/fgas_rtfbreak.h" | 16 #include "xfa/fgas/layout/fgas_rtfbreak.h" |
| 16 #include "xfa/fxfa/include/xfa_ffdoc.h" | |
| 17 #include "xfa/fxfa/parser/xfa_object.h" | 17 #include "xfa/fxfa/parser/xfa_object.h" |
| 18 | 18 |
| 19 #define XFA_LOADERCNTXTFLG_FILTERSPACE 0x001 | 19 #define XFA_LOADERCNTXTFLG_FILTERSPACE 0x001 |
| 20 | 20 |
| 21 class CFDE_CSSStyleSelector; | 21 class CFDE_CSSStyleSelector; |
| 22 class CXFA_Para; | 22 class CXFA_Para; |
| 23 class CXFA_Font; | 23 class CXFA_Font; |
| 24 class CXFA_TextProvider; | 24 class CXFA_TextProvider; |
| 25 class CXFA_TextTabstopsContext; | 25 class CXFA_TextTabstopsContext; |
| 26 | 26 |
| 27 class CXFA_CSSTagProvider { | 27 class CXFA_CSSTagProvider { |
| 28 public: | 28 public: |
| 29 CXFA_CSSTagProvider() : m_bTagAvailable(FALSE), m_bContent(FALSE) {} | 29 using AttributeMap = std::map<CFX_WideString, CFX_WideString>; |
| 30 ~CXFA_CSSTagProvider() {} | 30 |
| 31 CXFA_CSSTagProvider(); |
| 32 ~CXFA_CSSTagProvider(); |
| 31 | 33 |
| 32 CFX_WideString GetTagName() { return m_wsTagName; } | 34 CFX_WideString GetTagName() { return m_wsTagName; } |
| 33 | 35 |
| 34 using AttributeMap = std::map<CFX_WideString, CFX_WideString>; | |
| 35 AttributeMap::iterator begin() { return m_Attributes.begin(); } | 36 AttributeMap::iterator begin() { return m_Attributes.begin(); } |
| 36 AttributeMap::iterator end() { return m_Attributes.end(); } | 37 AttributeMap::iterator end() { return m_Attributes.end(); } |
| 37 | 38 |
| 38 bool empty() const { return m_Attributes.empty(); } | 39 bool empty() const { return m_Attributes.empty(); } |
| 39 | 40 |
| 40 void SetTagNameObj(const CFX_WideString& wsName) { m_wsTagName = wsName; } | 41 void SetTagNameObj(const CFX_WideString& wsName) { m_wsTagName = wsName; } |
| 41 void SetAttribute(const CFX_WideString& wsAttr, | 42 void SetAttribute(const CFX_WideString& wsAttr, |
| 42 const CFX_WideString& wsValue) { | 43 const CFX_WideString& wsValue) { |
| 43 m_Attributes.insert({wsAttr, wsValue}); | 44 m_Attributes.insert({wsAttr, wsValue}); |
| 44 } | 45 } |
| 45 | 46 |
| 46 FX_BOOL m_bTagAvailable; | 47 FX_BOOL m_bTagAvailable; |
| 47 FX_BOOL m_bContent; | 48 FX_BOOL m_bContent; |
| 48 | 49 |
| 49 protected: | 50 protected: |
| 50 CFX_WideString m_wsTagName; | 51 CFX_WideString m_wsTagName; |
| 51 AttributeMap m_Attributes; | 52 AttributeMap m_Attributes; |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 class CXFA_TextParseContext : public CFX_Target { | 55 class CXFA_TextParseContext : public CFX_Target { |
| 55 public: | 56 public: |
| 56 CXFA_TextParseContext() | 57 CXFA_TextParseContext(); |
| 57 : m_pParentStyle(nullptr), | 58 ~CXFA_TextParseContext() override; |
| 58 m_ppMatchedDecls(nullptr), | 59 |
| 59 m_dwMatchedDecls(0), | |
| 60 m_eDisplay(FDE_CSSDISPLAY_None) {} | |
| 61 ~CXFA_TextParseContext() { | |
| 62 if (m_pParentStyle) | |
| 63 m_pParentStyle->Release(); | |
| 64 FX_Free(m_ppMatchedDecls); | |
| 65 } | |
| 66 void SetDisplay(FDE_CSSDISPLAY eDisplay) { m_eDisplay = eDisplay; } | 60 void SetDisplay(FDE_CSSDISPLAY eDisplay) { m_eDisplay = eDisplay; } |
| 67 FDE_CSSDISPLAY GetDisplay() const { return m_eDisplay; } | 61 FDE_CSSDISPLAY GetDisplay() const { return m_eDisplay; } |
| 68 void SetDecls(const CFDE_CSSDeclaration** ppDeclArray, int32_t iDeclCount); | 62 void SetDecls(const CFDE_CSSDeclaration** ppDeclArray, int32_t iDeclCount); |
| 69 const CFDE_CSSDeclaration** GetDecls() { | 63 const CFDE_CSSDeclaration** GetDecls() { |
| 70 return const_cast<const CFDE_CSSDeclaration**>(m_ppMatchedDecls); | 64 return const_cast<const CFDE_CSSDeclaration**>(m_ppMatchedDecls); |
| 71 } | 65 } |
| 72 uint32_t CountDecls() const { return m_dwMatchedDecls; } | 66 uint32_t CountDecls() const { return m_dwMatchedDecls; } |
| 67 |
| 73 IFDE_CSSComputedStyle* m_pParentStyle; | 68 IFDE_CSSComputedStyle* m_pParentStyle; |
| 74 | 69 |
| 75 protected: | 70 protected: |
| 76 CFDE_CSSDeclaration** m_ppMatchedDecls; | 71 CFDE_CSSDeclaration** m_ppMatchedDecls; |
| 77 uint32_t m_dwMatchedDecls; | 72 uint32_t m_dwMatchedDecls; |
| 78 FDE_CSSDISPLAY m_eDisplay; | 73 FDE_CSSDISPLAY m_eDisplay; |
| 79 }; | 74 }; |
| 80 | 75 |
| 81 class CXFA_TextParser { | 76 class CXFA_TextParser { |
| 82 public: | 77 public: |
| 83 CXFA_TextParser(); | 78 CXFA_TextParser(); |
| 84 virtual ~CXFA_TextParser(); | 79 virtual ~CXFA_TextParser(); |
| 80 |
| 85 void Reset(); | 81 void Reset(); |
| 86 void DoParse(CFDE_XMLNode* pXMLContainer, CXFA_TextProvider* pTextProvider); | 82 void DoParse(CFDE_XMLNode* pXMLContainer, CXFA_TextProvider* pTextProvider); |
| 87 IFDE_CSSComputedStyle* CreateRootStyle(CXFA_TextProvider* pTextProvider); | 83 IFDE_CSSComputedStyle* CreateRootStyle(CXFA_TextProvider* pTextProvider); |
| 88 IFDE_CSSComputedStyle* ComputeStyle(CFDE_XMLNode* pXMLNode, | 84 IFDE_CSSComputedStyle* ComputeStyle(CFDE_XMLNode* pXMLNode, |
| 89 IFDE_CSSComputedStyle* pParentStyle); | 85 IFDE_CSSComputedStyle* pParentStyle); |
| 90 FX_BOOL IsParsed() const { return !!m_pAllocator; } | 86 FX_BOOL IsParsed() const { return !!m_pAllocator; } |
| 91 | 87 |
| 92 int32_t GetVAlign(CXFA_TextProvider* pTextProvider) const; | 88 int32_t GetVAlign(CXFA_TextProvider* pTextProvider) const; |
| 93 FX_FLOAT GetTabInterval(IFDE_CSSComputedStyle* pStyle) const; | 89 FX_FLOAT GetTabInterval(IFDE_CSSComputedStyle* pStyle) const; |
| 94 int32_t CountTabs(IFDE_CSSComputedStyle* pStyle) const; | 90 int32_t CountTabs(IFDE_CSSComputedStyle* pStyle) const; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 IFDE_CSSComputedStyle* CreateStyle(IFDE_CSSComputedStyle* pParentStyle); | 132 IFDE_CSSComputedStyle* CreateStyle(IFDE_CSSComputedStyle* pParentStyle); |
| 137 std::unique_ptr<IFX_MemoryAllocator> m_pAllocator; | 133 std::unique_ptr<IFX_MemoryAllocator> m_pAllocator; |
| 138 std::unique_ptr<CFDE_CSSStyleSelector> m_pSelector; | 134 std::unique_ptr<CFDE_CSSStyleSelector> m_pSelector; |
| 139 IFDE_CSSStyleSheet* m_pUASheet; | 135 IFDE_CSSStyleSheet* m_pUASheet; |
| 140 CFX_MapPtrTemplate<CFDE_XMLNode*, CXFA_TextParseContext*> | 136 CFX_MapPtrTemplate<CFDE_XMLNode*, CXFA_TextParseContext*> |
| 141 m_mapXMLNodeToParseContext; | 137 m_mapXMLNodeToParseContext; |
| 142 }; | 138 }; |
| 143 | 139 |
| 144 class CXFA_LoaderContext { | 140 class CXFA_LoaderContext { |
| 145 public: | 141 public: |
| 146 CXFA_LoaderContext() | 142 CXFA_LoaderContext(); |
| 147 : m_bSaveLineHeight(FALSE), | 143 ~CXFA_LoaderContext(); |
| 148 m_fWidth(0), | 144 |
| 149 m_fHeight(0), | |
| 150 m_fLastPos(0), | |
| 151 m_fStartLineOffset(0), | |
| 152 m_iChar(0), | |
| 153 m_iTotalLines(-1), | |
| 154 m_pXMLNode(NULL), | |
| 155 m_pNode(NULL), | |
| 156 m_pParentStyle(NULL), | |
| 157 m_dwFlags(0) {} | |
| 158 FX_BOOL m_bSaveLineHeight; | 145 FX_BOOL m_bSaveLineHeight; |
| 159 FX_FLOAT m_fWidth; | 146 FX_FLOAT m_fWidth; |
| 160 FX_FLOAT m_fHeight; | 147 FX_FLOAT m_fHeight; |
| 161 FX_FLOAT m_fLastPos; | 148 FX_FLOAT m_fLastPos; |
| 162 FX_FLOAT m_fStartLineOffset; | 149 FX_FLOAT m_fStartLineOffset; |
| 163 int32_t m_iChar; | 150 int32_t m_iChar; |
| 164 int32_t m_iLines; | 151 int32_t m_iLines; |
| 165 int32_t m_iTotalLines; | 152 int32_t m_iTotalLines; |
| 166 CFDE_XMLNode* m_pXMLNode; | 153 CFDE_XMLNode* m_pXMLNode; |
| 167 CXFA_Node* m_pNode; | 154 CXFA_Node* m_pNode; |
| 168 IFDE_CSSComputedStyle* m_pParentStyle; | 155 IFDE_CSSComputedStyle* m_pParentStyle; |
| 169 CFX_ArrayTemplate<FX_FLOAT> m_lineHeights; | 156 CFX_ArrayTemplate<FX_FLOAT> m_lineHeights; |
| 170 uint32_t m_dwFlags; | 157 uint32_t m_dwFlags; |
| 171 CFX_FloatArray m_BlocksHeight; | 158 CFX_FloatArray m_BlocksHeight; |
| 172 }; | 159 }; |
| 173 | 160 |
| 174 class CXFA_LinkUserData : public IFX_Retainable, public CFX_Target { | 161 class CXFA_LinkUserData : public IFX_Retainable, public CFX_Target { |
| 175 public: | 162 public: |
| 176 CXFA_LinkUserData(IFX_MemoryAllocator* pAllocator, FX_WCHAR* pszText) | 163 CXFA_LinkUserData(IFX_MemoryAllocator* pAllocator, FX_WCHAR* pszText); |
| 177 : m_pAllocator(pAllocator), m_dwRefCount(1), m_wsURLContent(pszText) {} | 164 ~CXFA_LinkUserData() override; |
| 178 | |
| 179 ~CXFA_LinkUserData() override {} | |
| 180 | 165 |
| 181 // IFX_Retainable: | 166 // IFX_Retainable: |
| 182 uint32_t Retain() override { return ++m_dwRefCount; } | 167 uint32_t Retain() override; |
| 183 uint32_t Release() override { | 168 uint32_t Release() override; |
| 184 uint32_t dwRefCount = --m_dwRefCount; | |
| 185 if (dwRefCount <= 0) | |
| 186 FXTARGET_DeleteWith(CXFA_LinkUserData, m_pAllocator, this); | |
| 187 return dwRefCount; | |
| 188 } | |
| 189 | 169 |
| 190 const FX_WCHAR* GetLinkURL() { return m_wsURLContent.c_str(); } | 170 const FX_WCHAR* GetLinkURL(); |
| 191 | 171 |
| 192 protected: | 172 protected: |
| 193 IFX_MemoryAllocator* m_pAllocator; | 173 IFX_MemoryAllocator* m_pAllocator; |
| 194 uint32_t m_dwRefCount; | 174 uint32_t m_dwRefCount; |
| 195 CFX_WideString m_wsURLContent; | 175 CFX_WideString m_wsURLContent; |
| 196 }; | 176 }; |
| 197 | 177 |
| 198 class CXFA_TextUserData : public IFX_Retainable, public CFX_Target { | 178 class CXFA_TextUserData : public IFX_Retainable, public CFX_Target { |
| 199 public: | 179 public: |
| 200 CXFA_TextUserData(IFX_MemoryAllocator* pAllocator, | 180 CXFA_TextUserData(IFX_MemoryAllocator* pAllocator, |
| 201 IFDE_CSSComputedStyle* pStyle) | 181 IFDE_CSSComputedStyle* pStyle); |
| 202 : m_pStyle(pStyle), | |
| 203 m_pLinkData(nullptr), | |
| 204 m_pAllocator(pAllocator), | |
| 205 m_dwRefCount(0) { | |
| 206 ASSERT(m_pAllocator); | |
| 207 if (m_pStyle) | |
| 208 m_pStyle->Retain(); | |
| 209 } | |
| 210 CXFA_TextUserData(IFX_MemoryAllocator* pAllocator, | 182 CXFA_TextUserData(IFX_MemoryAllocator* pAllocator, |
| 211 IFDE_CSSComputedStyle* pStyle, | 183 IFDE_CSSComputedStyle* pStyle, |
| 212 CXFA_LinkUserData* pLinkData) | 184 CXFA_LinkUserData* pLinkData); |
| 213 : m_pStyle(pStyle), | 185 ~CXFA_TextUserData() override; |
| 214 m_pLinkData(pLinkData), | |
| 215 m_pAllocator(pAllocator), | |
| 216 m_dwRefCount(0) { | |
| 217 ASSERT(m_pAllocator); | |
| 218 if (m_pStyle) | |
| 219 m_pStyle->Retain(); | |
| 220 } | |
| 221 ~CXFA_TextUserData() override { | |
| 222 if (m_pStyle) | |
| 223 m_pStyle->Release(); | |
| 224 if (m_pLinkData) | |
| 225 m_pLinkData->Release(); | |
| 226 } | |
| 227 | 186 |
| 228 // IFX_Retainable: | 187 // IFX_Retainable: |
| 229 uint32_t Retain() override { return ++m_dwRefCount; } | 188 uint32_t Retain() override; |
| 230 uint32_t Release() override { | 189 uint32_t Release() override; |
| 231 uint32_t dwRefCount = --m_dwRefCount; | |
| 232 if (dwRefCount == 0) | |
| 233 FXTARGET_DeleteWith(CXFA_TextUserData, m_pAllocator, this); | |
| 234 return dwRefCount; | |
| 235 } | |
| 236 | 190 |
| 237 IFDE_CSSComputedStyle* m_pStyle; | 191 IFDE_CSSComputedStyle* m_pStyle; |
| 238 CXFA_LinkUserData* m_pLinkData; | 192 CXFA_LinkUserData* m_pLinkData; |
| 239 | 193 |
| 240 protected: | 194 protected: |
| 241 IFX_MemoryAllocator* m_pAllocator; | 195 IFX_MemoryAllocator* m_pAllocator; |
| 242 uint32_t m_dwRefCount; | 196 uint32_t m_dwRefCount; |
| 243 }; | 197 }; |
| 244 | 198 |
| 245 class XFA_TextPiece : public CFX_Target { | 199 class XFA_TextPiece : public CFX_Target { |
| 246 public: | 200 public: |
| 247 XFA_TextPiece() : pszText(nullptr), pFont(nullptr), pLinkData(nullptr) {} | 201 XFA_TextPiece(); |
| 248 ~XFA_TextPiece() override { | 202 ~XFA_TextPiece() override; |
| 249 if (pLinkData) | |
| 250 pLinkData->Release(); | |
| 251 } | |
| 252 | 203 |
| 253 FX_WCHAR* pszText; | 204 FX_WCHAR* pszText; |
| 254 int32_t iChars; | 205 int32_t iChars; |
| 255 int32_t* pWidths; | 206 int32_t* pWidths; |
| 256 int32_t iHorScale; | 207 int32_t iHorScale; |
| 257 int32_t iVerScale; | 208 int32_t iVerScale; |
| 258 int32_t iBidiLevel; | 209 int32_t iBidiLevel; |
| 259 int32_t iUnderline; | 210 int32_t iUnderline; |
| 260 int32_t iPeriod; | 211 int32_t iPeriod; |
| 261 int32_t iLineThrough; | 212 int32_t iLineThrough; |
| 262 CFGAS_GEFont* pFont; | 213 CFGAS_GEFont* pFont; |
| 263 FX_ARGB dwColor; | 214 FX_ARGB dwColor; |
| 264 FX_FLOAT fFontSize; | 215 FX_FLOAT fFontSize; |
| 265 CFX_RectF rtPiece; | 216 CFX_RectF rtPiece; |
| 266 CXFA_LinkUserData* pLinkData; | 217 CXFA_LinkUserData* pLinkData; |
| 267 }; | 218 }; |
| 268 typedef CFX_ArrayTemplate<XFA_TextPiece*> CXFA_PieceArray; | 219 typedef CFX_ArrayTemplate<XFA_TextPiece*> CXFA_PieceArray; |
| 269 | 220 |
| 270 class CXFA_PieceLine : public CFX_Target { | 221 class CXFA_PieceLine : public CFX_Target { |
| 271 public: | 222 public: |
| 272 CXFA_PieceLine() {} | 223 CXFA_PieceLine(); |
| 224 ~CXFA_PieceLine() override; |
| 225 |
| 273 CXFA_PieceArray m_textPieces; | 226 CXFA_PieceArray m_textPieces; |
| 274 CFX_Int32Array m_charCounts; | 227 CFX_Int32Array m_charCounts; |
| 275 }; | 228 }; |
| 276 typedef CFX_ArrayTemplate<CXFA_PieceLine*> CXFA_PieceLineArray; | 229 typedef CFX_ArrayTemplate<CXFA_PieceLine*> CXFA_PieceLineArray; |
| 277 | 230 |
| 278 struct XFA_TABSTOPS { | 231 struct XFA_TABSTOPS { |
| 279 uint32_t dwAlign; | 232 uint32_t dwAlign; |
| 280 FX_FLOAT fTabstops; | 233 FX_FLOAT fTabstops; |
| 281 }; | 234 }; |
| 282 | 235 |
| 283 class CXFA_TextTabstopsContext { | 236 class CXFA_TextTabstopsContext { |
| 284 public: | 237 public: |
| 285 CXFA_TextTabstopsContext() | 238 CXFA_TextTabstopsContext(); |
| 286 : m_iTabCount(0), | 239 ~CXFA_TextTabstopsContext(); |
| 287 m_iTabIndex(-1), | 240 |
| 288 m_bTabstops(FALSE), | 241 void Append(uint32_t dwAlign, FX_FLOAT fTabstops); |
| 289 m_fTabWidth(0), | 242 void RemoveAll(); |
| 290 m_fLeft(0) {} | 243 void Reset(); |
| 291 void Append(uint32_t dwAlign, FX_FLOAT fTabstops) { | 244 |
| 292 int32_t i = 0; | |
| 293 for (i = 0; i < m_iTabCount; i++) { | |
| 294 XFA_TABSTOPS* pTabstop = m_tabstops.GetDataPtr(i); | |
| 295 if (fTabstops < pTabstop->fTabstops) { | |
| 296 break; | |
| 297 } | |
| 298 } | |
| 299 m_tabstops.InsertSpaceAt(i, 1); | |
| 300 XFA_TABSTOPS tabstop; | |
| 301 tabstop.dwAlign = dwAlign; | |
| 302 tabstop.fTabstops = fTabstops; | |
| 303 m_tabstops.SetAt(i, tabstop); | |
| 304 m_iTabCount++; | |
| 305 } | |
| 306 void RemoveAll() { | |
| 307 m_tabstops.RemoveAll(); | |
| 308 m_iTabCount = 0; | |
| 309 } | |
| 310 void Reset() { | |
| 311 m_iTabIndex = -1; | |
| 312 m_bTabstops = FALSE; | |
| 313 m_fTabWidth = 0; | |
| 314 m_fLeft = 0; | |
| 315 } | |
| 316 CFX_ArrayTemplate<XFA_TABSTOPS> m_tabstops; | 245 CFX_ArrayTemplate<XFA_TABSTOPS> m_tabstops; |
| 317 int32_t m_iTabCount; | 246 int32_t m_iTabCount; |
| 318 int32_t m_iTabIndex; | 247 int32_t m_iTabIndex; |
| 319 FX_BOOL m_bTabstops; | 248 FX_BOOL m_bTabstops; |
| 320 FX_FLOAT m_fTabWidth; | 249 FX_FLOAT m_fTabWidth; |
| 321 FX_FLOAT m_fLeft; | 250 FX_FLOAT m_fLeft; |
| 322 }; | 251 }; |
| 323 | 252 |
| 324 class CXFA_TextLayout { | 253 class CXFA_TextLayout { |
| 325 public: | 254 public: |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 std::unique_ptr<CXFA_LoaderContext> m_pLoader; | 345 std::unique_ptr<CXFA_LoaderContext> m_pLoader; |
| 417 int32_t m_iLines; | 346 int32_t m_iLines; |
| 418 FX_FLOAT m_fMaxWidth; | 347 FX_FLOAT m_fMaxWidth; |
| 419 CXFA_TextParser m_textParser; | 348 CXFA_TextParser m_textParser; |
| 420 CXFA_PieceLineArray m_pieceLines; | 349 CXFA_PieceLineArray m_pieceLines; |
| 421 std::unique_ptr<CXFA_TextTabstopsContext> m_pTabstopContext; | 350 std::unique_ptr<CXFA_TextTabstopsContext> m_pTabstopContext; |
| 422 FX_BOOL m_bBlockContinue; | 351 FX_BOOL m_bBlockContinue; |
| 423 }; | 352 }; |
| 424 | 353 |
| 425 #endif // XFA_FXFA_APP_XFA_TEXTLAYOUT_H_ | 354 #endif // XFA_FXFA_APP_XFA_TEXTLAYOUT_H_ |
| OLD | NEW |