| 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 CORE_SRC_FPDFDOC_PDF_VT_H_ | 7 #ifndef CORE_SRC_FPDFDOC_PDF_VT_H_ |
| 8 #define CORE_SRC_FPDFDOC_PDF_VT_H_ | 8 #define CORE_SRC_FPDFDOC_PDF_VT_H_ |
| 9 | 9 |
| 10 class CPVT_Size; | 10 class CPVT_Size; |
| 11 class CPVT_FloatRect; | 11 class CPVT_FloatRect; |
| 12 struct CPVT_SectionInfo; | 12 struct CPVT_SectionInfo; |
| 13 struct CPVT_LineInfo; | 13 struct CPVT_LineInfo; |
| 14 struct CPVT_WordInfo; | 14 struct CPVT_WordInfo; |
| 15 class CLine; | 15 class CLine; |
| 16 class CLines; | 16 class CLines; |
| 17 class CSection; | 17 class CSection; |
| 18 class CTypeset; | 18 class CTypeset; |
| 19 class CPDF_EditContainer; | 19 class CPDF_EditContainer; |
| 20 class CPDF_VariableText; | 20 class CPDF_VariableText; |
| 21 class CPDF_VariableText_Iterator; | 21 class CPDF_VariableText_Iterator; |
| 22 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) | 22 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) |
| 23 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) | 23 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) |
| 24 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) | 24 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) |
| 25 template <class T> | 25 |
| 26 T FPDF_MIN(const T& i, const T& j) { | |
| 27 return ((i < j) ? i : j); | |
| 28 } | |
| 29 template <class T> | |
| 30 T FPDF_MAX(const T& i, const T& j) { | |
| 31 return ((i > j) ? i : j); | |
| 32 } | |
| 33 class CPVT_Size { | 26 class CPVT_Size { |
| 34 public: | 27 public: |
| 35 CPVT_Size() : x(0.0f), y(0.0f) {} | 28 CPVT_Size() : x(0.0f), y(0.0f) {} |
| 36 CPVT_Size(FX_FLOAT other_x, FX_FLOAT other_y) { | 29 CPVT_Size(FX_FLOAT other_x, FX_FLOAT other_y) { |
| 37 x = other_x; | 30 x = other_x; |
| 38 y = other_y; | 31 y = other_y; |
| 39 } | 32 } |
| 40 FX_FLOAT x, y; | 33 FX_FLOAT x, y; |
| 41 }; | 34 }; |
| 42 class CPVT_FloatRect : public CFX_FloatRect { | 35 class CPVT_FloatRect : public CFX_FloatRect { |
| 43 public: | 36 public: |
| 44 CPVT_FloatRect() { left = top = right = bottom = 0.0f; } | 37 CPVT_FloatRect() { left = top = right = bottom = 0.0f; } |
| 45 CPVT_FloatRect(FX_FLOAT other_left, | 38 CPVT_FloatRect(FX_FLOAT other_left, |
| 46 FX_FLOAT other_top, | 39 FX_FLOAT other_top, |
| 47 FX_FLOAT other_right, | 40 FX_FLOAT other_right, |
| 48 FX_FLOAT other_bottom) { | 41 FX_FLOAT other_bottom) { |
| 49 left = other_left; | 42 left = other_left; |
| 50 top = other_top; | 43 top = other_top; |
| 51 right = other_right; | 44 right = other_right; |
| 52 bottom = other_bottom; | 45 bottom = other_bottom; |
| 53 } | 46 } |
| 54 CPVT_FloatRect(const CPDF_Rect& rect) { | 47 explicit CPVT_FloatRect(const CPDF_Rect& rect) { |
| 55 left = rect.left; | 48 left = rect.left; |
| 56 top = rect.top; | 49 top = rect.top; |
| 57 right = rect.right; | 50 right = rect.right; |
| 58 bottom = rect.bottom; | 51 bottom = rect.bottom; |
| 59 } | 52 } |
| 60 void Default() { left = top = right = bottom = 0.0f; } | 53 void Default() { left = top = right = bottom = 0.0f; } |
| 61 FX_FLOAT Height() const { | 54 FX_FLOAT Height() const { |
| 62 if (top > bottom) | 55 if (top > bottom) |
| 63 return top - bottom; | 56 return top - bottom; |
| 64 return bottom - top; | 57 return bottom - top; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 } | 232 } |
| 240 | 233 |
| 241 private: | 234 private: |
| 242 CPVT_ArrayTemplate<CLine*> m_Lines; | 235 CPVT_ArrayTemplate<CLine*> m_Lines; |
| 243 int32_t m_nTotal; | 236 int32_t m_nTotal; |
| 244 }; | 237 }; |
| 245 class CSection { | 238 class CSection { |
| 246 friend class CTypeset; | 239 friend class CTypeset; |
| 247 | 240 |
| 248 public: | 241 public: |
| 249 CSection(CPDF_VariableText* pVT); | 242 explicit CSection(CPDF_VariableText* pVT); |
| 250 virtual ~CSection(); | 243 virtual ~CSection(); |
| 251 void ResetAll(); | 244 void ResetAll(); |
| 252 void ResetLineArray(); | 245 void ResetLineArray(); |
| 253 void ResetWordArray(); | 246 void ResetWordArray(); |
| 254 void ResetLinePlace(); | 247 void ResetLinePlace(); |
| 255 CPVT_WordPlace AddWord(const CPVT_WordPlace& place, | 248 CPVT_WordPlace AddWord(const CPVT_WordPlace& place, |
| 256 const CPVT_WordInfo& wordinfo); | 249 const CPVT_WordInfo& wordinfo); |
| 257 CPVT_WordPlace AddLine(const CPVT_LineInfo& lineinfo); | 250 CPVT_WordPlace AddLine(const CPVT_LineInfo& lineinfo); |
| 258 void ClearWords(const CPVT_WordRange& PlaceRange); | 251 void ClearWords(const CPVT_WordRange& PlaceRange); |
| 259 void ClearWord(const CPVT_WordPlace& place); | 252 void ClearWord(const CPVT_WordPlace& place); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 278 | 271 |
| 279 private: | 272 private: |
| 280 void ClearLeftWords(int32_t nWordIndex); | 273 void ClearLeftWords(int32_t nWordIndex); |
| 281 void ClearRightWords(int32_t nWordIndex); | 274 void ClearRightWords(int32_t nWordIndex); |
| 282 void ClearMidWords(int32_t nBeginIndex, int32_t nEndIndex); | 275 void ClearMidWords(int32_t nBeginIndex, int32_t nEndIndex); |
| 283 | 276 |
| 284 CPDF_VariableText* m_pVT; | 277 CPDF_VariableText* m_pVT; |
| 285 }; | 278 }; |
| 286 class CTypeset { | 279 class CTypeset { |
| 287 public: | 280 public: |
| 288 CTypeset(CSection* pSection); | 281 explicit CTypeset(CSection* pSection); |
| 289 virtual ~CTypeset(); | 282 virtual ~CTypeset(); |
| 290 CPVT_Size GetEditSize(FX_FLOAT fFontSize); | 283 CPVT_Size GetEditSize(FX_FLOAT fFontSize); |
| 291 CPVT_FloatRect Typeset(); | 284 CPVT_FloatRect Typeset(); |
| 292 CPVT_FloatRect CharArray(); | 285 CPVT_FloatRect CharArray(); |
| 293 | 286 |
| 294 private: | 287 private: |
| 295 void SplitLines(FX_BOOL bTypeset, FX_FLOAT fFontSize); | 288 void SplitLines(FX_BOOL bTypeset, FX_FLOAT fFontSize); |
| 296 void OutputLines(); | 289 void OutputLines(); |
| 297 | 290 |
| 298 CPVT_FloatRect m_rcRet; | 291 CPVT_FloatRect m_rcRet; |
| 299 CPDF_VariableText* m_pVT; | 292 CPDF_VariableText* m_pVT; |
| 300 CSection* m_pSection; | 293 CSection* m_pSection; |
| 301 }; | 294 }; |
| 302 class CPDF_EditContainer { | 295 class CPDF_EditContainer { |
| 303 public: | 296 public: |
| 304 CPDF_EditContainer() : m_rcPlate(0, 0, 0, 0), m_rcContent(0, 0, 0, 0) {} | 297 CPDF_EditContainer() : m_rcPlate(0, 0, 0, 0), m_rcContent(0, 0, 0, 0) {} |
| 305 virtual ~CPDF_EditContainer() {} | 298 virtual ~CPDF_EditContainer() {} |
| 306 virtual void SetPlateRect(const CPDF_Rect& rect) { m_rcPlate = rect; } | 299 virtual void SetPlateRect(const CPDF_Rect& rect) { m_rcPlate = rect; } |
| 307 virtual const CPDF_Rect& GetPlateRect() const { return m_rcPlate; } | 300 virtual const CPDF_Rect& GetPlateRect() const { return m_rcPlate; } |
| 308 virtual void SetContentRect(const CPVT_FloatRect& rect) { | 301 virtual void SetContentRect(const CPVT_FloatRect& rect) { |
| 309 m_rcContent = rect; | 302 m_rcContent = rect; |
| 310 }; | 303 } |
| 311 virtual CPDF_Rect GetContentRect() const { return m_rcContent; } | 304 virtual CPDF_Rect GetContentRect() const { return m_rcContent; } |
| 312 FX_FLOAT GetPlateWidth() const { return m_rcPlate.right - m_rcPlate.left; } | 305 FX_FLOAT GetPlateWidth() const { return m_rcPlate.right - m_rcPlate.left; } |
| 313 FX_FLOAT GetPlateHeight() const { return m_rcPlate.top - m_rcPlate.bottom; } | 306 FX_FLOAT GetPlateHeight() const { return m_rcPlate.top - m_rcPlate.bottom; } |
| 314 CPVT_Size GetPlateSize() const { | 307 CPVT_Size GetPlateSize() const { |
| 315 return CPVT_Size(GetPlateWidth(), GetPlateHeight()); | 308 return CPVT_Size(GetPlateWidth(), GetPlateHeight()); |
| 316 }; | 309 } |
| 317 CPDF_Point GetBTPoint() const { | 310 CPDF_Point GetBTPoint() const { |
| 318 return CPDF_Point(m_rcPlate.left, m_rcPlate.top); | 311 return CPDF_Point(m_rcPlate.left, m_rcPlate.top); |
| 319 }; | 312 } |
| 320 CPDF_Point GetETPoint() const { | 313 CPDF_Point GetETPoint() const { |
| 321 return CPDF_Point(m_rcPlate.right, m_rcPlate.bottom); | 314 return CPDF_Point(m_rcPlate.right, m_rcPlate.bottom); |
| 322 }; | 315 } |
| 323 inline CPDF_Point InToOut(const CPDF_Point& point) const { | 316 inline CPDF_Point InToOut(const CPDF_Point& point) const { |
| 324 return CPDF_Point(point.x + GetBTPoint().x, GetBTPoint().y - point.y); | 317 return CPDF_Point(point.x + GetBTPoint().x, GetBTPoint().y - point.y); |
| 325 }; | 318 } |
| 326 inline CPDF_Point OutToIn(const CPDF_Point& point) const { | 319 inline CPDF_Point OutToIn(const CPDF_Point& point) const { |
| 327 return CPDF_Point(point.x - GetBTPoint().x, GetBTPoint().y - point.y); | 320 return CPDF_Point(point.x - GetBTPoint().x, GetBTPoint().y - point.y); |
| 328 }; | 321 } |
| 329 inline CPDF_Rect InToOut(const CPVT_FloatRect& rect) const { | 322 inline CPDF_Rect InToOut(const CPVT_FloatRect& rect) const { |
| 330 CPDF_Point ptLeftTop = InToOut(CPDF_Point(rect.left, rect.top)); | 323 CPDF_Point ptLeftTop = InToOut(CPDF_Point(rect.left, rect.top)); |
| 331 CPDF_Point ptRightBottom = InToOut(CPDF_Point(rect.right, rect.bottom)); | 324 CPDF_Point ptRightBottom = InToOut(CPDF_Point(rect.right, rect.bottom)); |
| 332 return CPDF_Rect(ptLeftTop.x, ptRightBottom.y, ptRightBottom.x, | 325 return CPDF_Rect(ptLeftTop.x, ptRightBottom.y, ptRightBottom.x, |
| 333 ptLeftTop.y); | 326 ptLeftTop.y); |
| 334 }; | 327 } |
| 335 inline CPVT_FloatRect OutToIn(const CPDF_Rect& rect) const { | 328 inline CPVT_FloatRect OutToIn(const CPDF_Rect& rect) const { |
| 336 CPDF_Point ptLeftTop = OutToIn(CPDF_Point(rect.left, rect.top)); | 329 CPDF_Point ptLeftTop = OutToIn(CPDF_Point(rect.left, rect.top)); |
| 337 CPDF_Point ptRightBottom = OutToIn(CPDF_Point(rect.right, rect.bottom)); | 330 CPDF_Point ptRightBottom = OutToIn(CPDF_Point(rect.right, rect.bottom)); |
| 338 return CPVT_FloatRect(ptLeftTop.x, ptLeftTop.y, ptRightBottom.x, | 331 return CPVT_FloatRect(ptLeftTop.x, ptLeftTop.y, ptRightBottom.x, |
| 339 ptRightBottom.y); | 332 ptRightBottom.y); |
| 340 }; | 333 } |
| 341 | 334 |
| 342 private: | 335 private: |
| 343 CPDF_Rect m_rcPlate; | 336 CPDF_Rect m_rcPlate; |
| 344 CPVT_FloatRect m_rcContent; | 337 CPVT_FloatRect m_rcContent; |
| 345 }; | 338 }; |
| 346 | 339 |
| 347 class CPDF_VariableText : public IPDF_VariableText, private CPDF_EditContainer { | 340 class CPDF_VariableText : public IPDF_VariableText, private CPDF_EditContainer { |
| 348 friend class CTypeset; | 341 friend class CTypeset; |
| 349 friend class CSection; | 342 friend class CSection; |
| 350 friend class CPDF_VariableText_Iterator; | 343 friend class CPDF_VariableText_Iterator; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 | 525 |
| 533 private: | 526 private: |
| 534 FX_BOOL m_bInitial; | 527 FX_BOOL m_bInitial; |
| 535 FX_BOOL m_bRichText; | 528 FX_BOOL m_bRichText; |
| 536 IPDF_VariableText_Provider* m_pVTProvider; | 529 IPDF_VariableText_Provider* m_pVTProvider; |
| 537 CPDF_VariableText_Iterator* m_pVTIterator; | 530 CPDF_VariableText_Iterator* m_pVTIterator; |
| 538 }; | 531 }; |
| 539 | 532 |
| 540 class CPDF_VariableText_Iterator : public IPDF_VariableText_Iterator { | 533 class CPDF_VariableText_Iterator : public IPDF_VariableText_Iterator { |
| 541 public: | 534 public: |
| 542 CPDF_VariableText_Iterator(CPDF_VariableText* pVT); | 535 explicit CPDF_VariableText_Iterator(CPDF_VariableText* pVT); |
| 543 ~CPDF_VariableText_Iterator() override; | 536 ~CPDF_VariableText_Iterator() override; |
| 544 | 537 |
| 545 // IPDF_VariableText_Iterator | 538 // IPDF_VariableText_Iterator |
| 546 FX_BOOL NextWord() override; | 539 FX_BOOL NextWord() override; |
| 547 FX_BOOL PrevWord() override; | 540 FX_BOOL PrevWord() override; |
| 548 FX_BOOL NextLine() override; | 541 FX_BOOL NextLine() override; |
| 549 FX_BOOL PrevLine() override; | 542 FX_BOOL PrevLine() override; |
| 550 FX_BOOL NextSection() override; | 543 FX_BOOL NextSection() override; |
| 551 FX_BOOL PrevSection() override; | 544 FX_BOOL PrevSection() override; |
| 552 FX_BOOL SetWord(const CPVT_Word& word) override; | 545 FX_BOOL SetWord(const CPVT_Word& word) override; |
| 553 FX_BOOL GetWord(CPVT_Word& word) const override; | 546 FX_BOOL GetWord(CPVT_Word& word) const override; |
| 554 FX_BOOL GetLine(CPVT_Line& line) const override; | 547 FX_BOOL GetLine(CPVT_Line& line) const override; |
| 555 FX_BOOL GetSection(CPVT_Section& section) const override; | 548 FX_BOOL GetSection(CPVT_Section& section) const override; |
| 556 FX_BOOL SetSection(const CPVT_Section& section) override; | 549 FX_BOOL SetSection(const CPVT_Section& section) override; |
| 557 void SetAt(int32_t nWordIndex) override; | 550 void SetAt(int32_t nWordIndex) override; |
| 558 void SetAt(const CPVT_WordPlace& place) override; | 551 void SetAt(const CPVT_WordPlace& place) override; |
| 559 const CPVT_WordPlace& GetAt() const override { return m_CurPos; } | 552 const CPVT_WordPlace& GetAt() const override { return m_CurPos; } |
| 560 | 553 |
| 561 private: | 554 private: |
| 562 CPVT_WordPlace m_CurPos; | 555 CPVT_WordPlace m_CurPos; |
| 563 CPDF_VariableText* m_pVT; | 556 CPDF_VariableText* m_pVT; |
| 564 }; | 557 }; |
| 565 | 558 |
| 566 #endif // CORE_SRC_FPDFDOC_PDF_VT_H_ | 559 #endif // CORE_SRC_FPDFDOC_PDF_VT_H_ |
| OLD | NEW |