Home | History | Annotate | Download | only in include
      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
      8 #define _FX_RTFBREAK
      9 class IFX_Unknown;
     10 class IFX_Font;
     11 class CFX_Char;
     12 class CFX_RTFChar;
     13 class CFX_RTFBreakPiece;
     14 class IFX_RTFBreak;
     15 #define FX_RTFBREAKPOLICY_None 0x00
     16 #define FX_RTFBREAKPOLICY_SpaceBreak 0x01
     17 #define FX_RTFBREAKPOLICY_NumberBreak 0x02
     18 #define FX_RTFBREAKPOLICY_InfixBreak 0x04
     19 #define FX_RTFBREAKPOLICY_TabBreak 0x08
     20 #define FX_RTFBREAKPOLICY_OrphanPositionedTab 0x10
     21 #define FX_RTFBREAK_None 0x00
     22 #define FX_RTFBREAK_PieceBreak 0x01
     23 #define FX_RTFBREAK_LineBreak 0x02
     24 #define FX_RTFBREAK_ParagraphBreak 0x03
     25 #define FX_RTFBREAK_PageBreak 0x04
     26 #define FX_RTFLAYOUTSTYLE_Pagination 0x01
     27 #define FX_RTFLAYOUTSTYLE_VerticalLayout 0x02
     28 #define FX_RTFLAYOUTSTYLE_VerticalChars 0x04
     29 #define FX_RTFLAYOUTSTYLE_LineDirection 0x08
     30 #define FX_RTFLAYOUTSTYLE_ExpandTab 0x10
     31 #define FX_RTFLAYOUTSTYLE_ArabicNumber 0x20
     32 #define FX_RTFLAYOUTSTYLE_SingleLine 0x40
     33 #define FX_RTFLAYOUTSTYLE_MBCSCode 0x80
     34 #define FX_RTFCHARSTYLE_Alignment 0x000F
     35 #define FX_RTFCHARSTYLE_ArabicNumber 0x0010
     36 #define FX_RTFCHARSTYLE_ArabicShadda 0x0020
     37 #define FX_RTFCHARSTYLE_OddBidiLevel 0x0040
     38 #define FX_RTFCHARSTYLE_RTLReadingOrder 0x0080
     39 #define FX_RTFCHARSTYLE_ArabicContext 0x0300
     40 #define FX_RTFCHARSTYLE_ArabicIndic 0x0400
     41 #define FX_RTFCHARSTYLE_ArabicComma 0x0800
     42 #define FX_RTFLINEALIGNMENT_Left 0
     43 #define FX_RTFLINEALIGNMENT_Center 1
     44 #define FX_RTFLINEALIGNMENT_Right 2
     45 #define FX_RTFLINEALIGNMENT_Justified (1 << 2)
     46 #define FX_RTFLINEALIGNMENT_Distributed (2 << 2)
     47 #define FX_RTFLINEALIGNMENT_JustifiedLeft \
     48   (FX_RTFLINEALIGNMENT_Left | FX_RTFLINEALIGNMENT_Justified)
     49 #define FX_RTFLINEALIGNMENT_JustifiedCenter \
     50   (FX_RTFLINEALIGNMENT_Center | FX_RTFLINEALIGNMENT_Justified)
     51 #define FX_RTFLINEALIGNMENT_JustifiedRight \
     52   (FX_RTFLINEALIGNMENT_Right | FX_RTFLINEALIGNMENT_Justified)
     53 #define FX_RTFLINEALIGNMENT_DistributedLeft \
     54   (FX_RTFLINEALIGNMENT_Left | FX_RTFLINEALIGNMENT_Distributed)
     55 #define FX_RTFLINEALIGNMENT_DistributedCenter \
     56   (FX_RTFLINEALIGNMENT_Center | FX_RTFLINEALIGNMENT_Distributed)
     57 #define FX_RTFLINEALIGNMENT_DistributedRight \
     58   (FX_RTFLINEALIGNMENT_Right | FX_RTFLINEALIGNMENT_Distributed)
     59 #define FX_RTFLINEALIGNMENT_LowerMask 0x03
     60 #define FX_RTFLINEALIGNMENT_HigherMask 0x0C
     61 typedef struct _FX_RTFTEXTOBJ {
     62   _FX_RTFTEXTOBJ() {
     63     pStr = NULL;
     64     pWidths = NULL;
     65     iLength = 0;
     66     pFont = NULL;
     67     fFontSize = 12.0f;
     68     dwLayoutStyles = 0;
     69     iCharRotation = 0;
     70     iBidiLevel = 0;
     71     pRect = NULL;
     72     wLineBreakChar = L'\n';
     73     iHorizontalScale = 100;
     74     iVerticalScale = 100;
     75   }
     76   const FX_WCHAR* pStr;
     77   int32_t* pWidths;
     78   int32_t iLength;
     79   IFX_Font* pFont;
     80   FX_FLOAT fFontSize;
     81   FX_DWORD dwLayoutStyles;
     82   int32_t iCharRotation;
     83   int32_t iBidiLevel;
     84   FX_LPCRECTF pRect;
     85   FX_WCHAR wLineBreakChar;
     86   int32_t iHorizontalScale;
     87   int32_t iVerticalScale;
     88 } FX_RTFTEXTOBJ, *FX_LPRTFTEXTOBJ;
     89 typedef FX_RTFTEXTOBJ const* FX_LPCRTFTEXTOBJ;
     90 class CFX_RTFPiece : public CFX_Target {
     91  public:
     92   CFX_RTFPiece()
     93       : m_dwStatus(FX_RTFBREAK_PieceBreak),
     94         m_iStartPos(0),
     95         m_iWidth(-1),
     96         m_iStartChar(0),
     97         m_iChars(0),
     98         m_iBidiLevel(0),
     99         m_iBidiPos(0),
    100         m_iFontSize(0),
    101         m_iFontHeight(0),
    102         m_iHorizontalScale(100),
    103         m_iVerticalScale(100),
    104         m_dwLayoutStyles(0),
    105         m_dwIdentity(0),
    106         m_pChars(NULL),
    107         m_pUserData(NULL) {}
    108   ~CFX_RTFPiece() { Reset(); }
    109   void AppendChar(const CFX_RTFChar& tc) {
    110     FXSYS_assert(m_pChars != NULL);
    111     m_pChars->Add(tc);
    112     if (m_iWidth < 0) {
    113       m_iWidth = tc.m_iCharWidth;
    114     } else {
    115       m_iWidth += tc.m_iCharWidth;
    116     }
    117     m_iChars++;
    118   }
    119   int32_t GetEndPos() const {
    120     return m_iWidth < 0 ? m_iStartPos : m_iStartPos + m_iWidth;
    121   }
    122   int32_t GetLength() const { return m_iChars; }
    123   int32_t GetEndChar() const { return m_iStartChar + m_iChars; }
    124   CFX_RTFChar& GetChar(int32_t index) {
    125     FXSYS_assert(index > -1 && index < m_iChars && m_pChars != NULL);
    126     return *m_pChars->GetDataPtr(m_iStartChar + index);
    127   }
    128   CFX_RTFChar* GetCharPtr(int32_t index) const {
    129     FXSYS_assert(index > -1 && index < m_iChars && m_pChars != NULL);
    130     return m_pChars->GetDataPtr(m_iStartChar + index);
    131   }
    132   void GetString(FX_WCHAR* pText) const {
    133     FXSYS_assert(pText != NULL);
    134     int32_t iEndChar = m_iStartChar + m_iChars;
    135     CFX_RTFChar* pChar;
    136     for (int32_t i = m_iStartChar; i < iEndChar; i++) {
    137       pChar = m_pChars->GetDataPtr(i);
    138       *pText++ = (FX_WCHAR)pChar->m_wCharCode;
    139     }
    140   }
    141   void GetString(CFX_WideString& wsText) const {
    142     FX_WCHAR* pText = wsText.GetBuffer(m_iChars);
    143     GetString(pText);
    144     wsText.ReleaseBuffer(m_iChars);
    145   }
    146   void GetWidths(int32_t* pWidths) const {
    147     FXSYS_assert(pWidths != NULL);
    148     int32_t iEndChar = m_iStartChar + m_iChars;
    149     CFX_RTFChar* pChar;
    150     for (int32_t i = m_iStartChar; i < iEndChar; i++) {
    151       pChar = m_pChars->GetDataPtr(i);
    152       *pWidths++ = pChar->m_iCharWidth;
    153     }
    154   }
    155   void Reset() {
    156     m_dwStatus = FX_RTFBREAK_PieceBreak;
    157     if (m_iWidth > -1) {
    158       m_iStartPos += m_iWidth;
    159     }
    160     m_iWidth = -1;
    161     m_iStartChar += m_iChars;
    162     m_iChars = 0;
    163     m_iBidiLevel = 0;
    164     m_iBidiPos = 0;
    165     m_iHorizontalScale = 100;
    166     m_iVerticalScale = 100;
    167   }
    168   FX_DWORD m_dwStatus;
    169   int32_t m_iStartPos;
    170   int32_t m_iWidth;
    171   int32_t m_iStartChar;
    172   int32_t m_iChars;
    173   int32_t m_iBidiLevel;
    174   int32_t m_iBidiPos;
    175   int32_t m_iFontSize;
    176   int32_t m_iFontHeight;
    177   int32_t m_iHorizontalScale;
    178   int32_t m_iVerticalScale;
    179   FX_DWORD m_dwLayoutStyles;
    180   FX_DWORD m_dwIdentity;
    181   CFX_RTFCharArray* m_pChars;
    182   IFX_Unknown* m_pUserData;
    183 };
    184 typedef CFX_BaseArrayTemplate<CFX_RTFPiece> CFX_RTFPieceArray;
    185 class IFX_RTFBreak {
    186  public:
    187   static IFX_RTFBreak* Create(FX_DWORD dwPolicies);
    188   virtual ~IFX_RTFBreak() {}
    189   virtual void Release() = 0;
    190   virtual void SetLineBoundary(FX_FLOAT fLineStart, FX_FLOAT fLineEnd) = 0;
    191   virtual void SetLineStartPos(FX_FLOAT fLinePos) = 0;
    192   virtual FX_DWORD GetLayoutStyles() const = 0;
    193   virtual void SetLayoutStyles(FX_DWORD dwLayoutStyles) = 0;
    194   virtual void SetFont(IFX_Font* pFont) = 0;
    195   virtual void SetFontSize(FX_FLOAT fFontSize) = 0;
    196   virtual void SetTabWidth(FX_FLOAT fTabWidth) = 0;
    197   virtual void AddPositionedTab(FX_FLOAT fTabPos) = 0;
    198   virtual void SetPositionedTabs(const CFX_FloatArray& tabs) = 0;
    199   virtual void ClearPositionedTabs() = 0;
    200   virtual void SetDefaultChar(FX_WCHAR wch) = 0;
    201   virtual void SetLineBreakChar(FX_WCHAR wch) = 0;
    202   virtual void SetLineBreakTolerance(FX_FLOAT fTolerance) = 0;
    203   virtual void SetHorizontalScale(int32_t iScale) = 0;
    204   virtual void SetVerticalScale(int32_t iScale) = 0;
    205   virtual void SetCharRotation(int32_t iCharRotation) = 0;
    206   virtual void SetCharSpace(FX_FLOAT fCharSpace) = 0;
    207   virtual void SetWordSpace(FX_BOOL bDefault, FX_FLOAT fWordSpace) = 0;
    208   virtual void SetReadingOrder(FX_BOOL bRTL = FALSE) = 0;
    209   virtual void SetAlignment(int32_t iAlignment = FX_RTFLINEALIGNMENT_Left) = 0;
    210   virtual void SetUserData(IFX_Unknown* pUserData) = 0;
    211   virtual FX_DWORD AppendChar(FX_WCHAR wch) = 0;
    212   virtual FX_DWORD EndBreak(FX_DWORD dwStatus = FX_RTFBREAK_PieceBreak) = 0;
    213   virtual int32_t CountBreakPieces() const = 0;
    214   virtual const CFX_RTFPiece* GetBreakPiece(int32_t index) const = 0;
    215   virtual void GetLineRect(CFX_RectF& rect) const = 0;
    216   virtual void ClearBreakPieces() = 0;
    217   virtual void Reset() = 0;
    218   virtual int32_t GetDisplayPos(
    219       FX_LPCRTFTEXTOBJ pText,
    220       FXTEXT_CHARPOS* pCharPos,
    221       FX_BOOL bCharCode = FALSE,
    222       CFX_WideString* pWSForms = NULL,
    223       FX_AdjustCharDisplayPos pAdjustPos = NULL) const = 0;
    224   virtual int32_t GetCharRects(FX_LPCRTFTEXTOBJ pText,
    225                                CFX_RectFArray& rtArray,
    226                                FX_BOOL bCharBBox = FALSE) const = 0;
    227 };
    228 #endif
    229