Home | History | Annotate | Download | only in layout
      1 // Copyright 2014 PDFium Authors. All rights reserved.
      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 #ifndef _FX_RTFBREAK_IMP
      8 #define _FX_RTFBREAK_IMP
      9 
     10 #include "core/include/fxcrt/fx_arb.h"
     11 
     12 class CFX_RTFLine;
     13 class CFX_RTFBreak;
     14 class CFX_RTFLine {
     15  public:
     16   CFX_RTFLine()
     17       : m_LinePieces(16),
     18         m_iStart(0),
     19         m_iWidth(0),
     20         m_iArabicChars(0),
     21         m_iMBCSChars(0) {}
     22   ~CFX_RTFLine() { RemoveAll(); }
     23   int32_t CountChars() const { return m_LineChars.GetSize(); }
     24   CFX_RTFChar& GetChar(int32_t index) {
     25     FXSYS_assert(index > -1 && index < m_LineChars.GetSize());
     26     return *m_LineChars.GetDataPtr(index);
     27   }
     28   CFX_RTFChar* GetCharPtr(int32_t index) {
     29     FXSYS_assert(index > -1 && index < m_LineChars.GetSize());
     30     return m_LineChars.GetDataPtr(index);
     31   }
     32   int32_t CountPieces() const { return m_LinePieces.GetSize(); }
     33   CFX_RTFPiece& GetPiece(int32_t index) const {
     34     FXSYS_assert(index > -1 && index < m_LinePieces.GetSize());
     35     return m_LinePieces.GetAt(index);
     36   }
     37   CFX_RTFPiece* GetPiecePtr(int32_t index) const {
     38     FXSYS_assert(index > -1 && index < m_LinePieces.GetSize());
     39     return m_LinePieces.GetPtrAt(index);
     40   }
     41   int32_t GetLineEnd() const { return m_iStart + m_iWidth; }
     42   void RemoveAll(FX_BOOL bLeaveMemory = FALSE) {
     43     CFX_RTFChar* pChar;
     44     IFX_Unknown* pUnknown;
     45     int32_t iCount = m_LineChars.GetSize();
     46     for (int32_t i = 0; i < iCount; i++) {
     47       pChar = m_LineChars.GetDataPtr(i);
     48       if ((pUnknown = pChar->m_pUserData) != NULL) {
     49         pUnknown->Release();
     50       }
     51     }
     52     m_LineChars.RemoveAll();
     53     m_LinePieces.RemoveAll(bLeaveMemory);
     54     m_iWidth = 0;
     55     m_iArabicChars = 0;
     56     m_iMBCSChars = 0;
     57   }
     58   CFX_RTFCharArray m_LineChars;
     59   CFX_RTFPieceArray m_LinePieces;
     60   int32_t m_iStart;
     61   int32_t m_iWidth;
     62   int32_t m_iArabicChars;
     63   int32_t m_iMBCSChars;
     64 };
     65 class CFX_RTFBreak : public IFX_RTFBreak {
     66  public:
     67   CFX_RTFBreak(FX_DWORD dwPolicies);
     68   ~CFX_RTFBreak();
     69   void Release() override { delete this; }
     70   void SetLineBoundary(FX_FLOAT fLineStart, FX_FLOAT fLineEnd) override final;
     71   void SetLineStartPos(FX_FLOAT fLinePos) override final;
     72   FX_DWORD GetLayoutStyles() const override { return m_dwLayoutStyles; }
     73   void SetLayoutStyles(FX_DWORD dwLayoutStyles) override;
     74   void SetFont(IFX_Font* pFont) override;
     75   void SetFontSize(FX_FLOAT fFontSize) override;
     76   void SetTabWidth(FX_FLOAT fTabWidth) override;
     77   void AddPositionedTab(FX_FLOAT fTabPos) override;
     78   void SetPositionedTabs(const CFX_FloatArray& tabs) override;
     79   void ClearPositionedTabs() override;
     80   void SetDefaultChar(FX_WCHAR wch) override;
     81   void SetLineBreakChar(FX_WCHAR wch) override;
     82   void SetLineBreakTolerance(FX_FLOAT fTolerance) override;
     83   void SetHorizontalScale(int32_t iScale) override;
     84   void SetVerticalScale(int32_t iScale) override;
     85   void SetCharRotation(int32_t iCharRotation) override;
     86   void SetCharSpace(FX_FLOAT fCharSpace) override;
     87   void SetWordSpace(FX_BOOL bDefault, FX_FLOAT fWordSpace) override;
     88   void SetReadingOrder(FX_BOOL bRTL = FALSE) override;
     89   void SetAlignment(int32_t iAlignment = FX_RTFLINEALIGNMENT_Left) override;
     90   void SetUserData(IFX_Unknown* pUserData) override;
     91   FX_DWORD AppendChar(FX_WCHAR wch) override;
     92   FX_DWORD EndBreak(FX_DWORD dwStatus = FX_RTFBREAK_PieceBreak) override;
     93   int32_t CountBreakPieces() const override;
     94   const CFX_RTFPiece* GetBreakPiece(int32_t index) const override;
     95   void GetLineRect(CFX_RectF& rect) const override;
     96   void ClearBreakPieces() override;
     97   void Reset() override;
     98   int32_t GetDisplayPos(
     99       FX_LPCRTFTEXTOBJ pText,
    100       FXTEXT_CHARPOS* pCharPos,
    101       FX_BOOL bCharCode = FALSE,
    102       CFX_WideString* pWSForms = NULL,
    103       FX_AdjustCharDisplayPos pAdjustPos = NULL) const override;
    104   int32_t GetCharRects(FX_LPCRTFTEXTOBJ pText,
    105                        CFX_RectFArray& rtArray,
    106                        FX_BOOL bCharBBox = FALSE) const override;
    107   FX_DWORD AppendChar_CharCode(FX_WCHAR wch);
    108   FX_DWORD AppendChar_Combination(CFX_RTFChar* pCurChar, int32_t iRotation);
    109   FX_DWORD AppendChar_Tab(CFX_RTFChar* pCurChar, int32_t iRotation);
    110   FX_DWORD AppendChar_Control(CFX_RTFChar* pCurChar, int32_t iRotation);
    111   FX_DWORD AppendChar_Arabic(CFX_RTFChar* pCurChar, int32_t iRotation);
    112   FX_DWORD AppendChar_Others(CFX_RTFChar* pCurChar, int32_t iRotation);
    113 
    114  protected:
    115   FX_DWORD m_dwPolicies;
    116   IFX_ArabicChar* m_pArabicChar;
    117   int32_t m_iBoundaryStart;
    118   int32_t m_iBoundaryEnd;
    119   FX_DWORD m_dwLayoutStyles;
    120   FX_BOOL m_bPagination;
    121   FX_BOOL m_bVertical;
    122   FX_BOOL m_bSingleLine;
    123   FX_BOOL m_bCharCode;
    124   IFX_Font* m_pFont;
    125   int32_t m_iFontHeight;
    126   int32_t m_iFontSize;
    127   int32_t m_iTabWidth;
    128   CFX_Int32Array m_PositionedTabs;
    129   FX_BOOL m_bOrphanLine;
    130   FX_WCHAR m_wDefChar;
    131   int32_t m_iDefChar;
    132   FX_WCHAR m_wLineBreakChar;
    133   int32_t m_iHorizontalScale;
    134   int32_t m_iVerticalScale;
    135   int32_t m_iLineRotation;
    136   int32_t m_iCharRotation;
    137   int32_t m_iRotation;
    138   int32_t m_iCharSpace;
    139   FX_BOOL m_bWordSpace;
    140   int32_t m_iWordSpace;
    141   FX_BOOL m_bRTL;
    142   int32_t m_iAlignment;
    143   IFX_Unknown* m_pUserData;
    144   FX_DWORD m_dwCharType;
    145   FX_DWORD m_dwIdentity;
    146   CFX_RTFLine m_RTFLine1;
    147   CFX_RTFLine m_RTFLine2;
    148   CFX_RTFLine* m_pCurLine;
    149   int32_t m_iReady;
    150   int32_t m_iTolerance;
    151   int32_t GetLineRotation(FX_DWORD dwStyles) const;
    152   void SetBreakStatus();
    153   CFX_RTFChar* GetLastChar(int32_t index) const;
    154   CFX_RTFLine* GetRTFLine(FX_BOOL bReady) const;
    155   CFX_RTFPieceArray* GetRTFPieces(FX_BOOL bReady) const;
    156   FX_DWORD GetUnifiedCharType(FX_DWORD dwType) const;
    157   int32_t GetLastPositionedTab() const;
    158   FX_BOOL GetPositionedTab(int32_t& iTabPos) const;
    159   int32_t GetBreakPos(CFX_RTFCharArray& tca,
    160                       int32_t& iEndPos,
    161                       FX_BOOL bAllChars = FALSE,
    162                       FX_BOOL bOnlyBrk = FALSE);
    163   void SplitTextLine(CFX_RTFLine* pCurLine,
    164                      CFX_RTFLine* pNextLine,
    165                      FX_BOOL bAllChars = FALSE);
    166   FX_BOOL EndBreak_SplitLine(CFX_RTFLine* pNextLine,
    167                              FX_BOOL bAllChars,
    168                              FX_DWORD dwStatus);
    169   void EndBreak_BidiLine(CFX_TPOArray& tpos, FX_DWORD dwStatus);
    170   void EndBreak_Alignment(CFX_TPOArray& tpos,
    171                           FX_BOOL bAllChars,
    172                           FX_DWORD dwStatus);
    173 };
    174 #endif
    175