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 _AUTOREFLOW_H
8#define _AUTOREFLOW_H
9#include "../../include/reflow/reflowengine.h"
10#include "reflowedpage.h"
11class CPDF_AutoReflowElement;
12class CPDF_AutoReflowLayoutProvider;
13typedef CFX_ArrayTemplate<CPDF_AutoReflowElement*> CAR_ElmPtrArray;
14typedef CFX_ArrayTemplate<CPDF_PageObject*> CAR_ObjPtrArray;
15class CRF_CELL : public CFX_Object
16{
17public:
18    CRF_CELL() { };
19    ~CRF_CELL() { };
20    CFX_PtrList		m_ObjList;
21    int			m_CellWritingMode;
22    FX_RECT		m_BBox;
23};
24class CPDF_AutoReflowElement : public IPDF_LayoutElement, public CFX_Object
25{
26public:
27    CPDF_AutoReflowElement(LayoutType layoutType = LayoutUnknown , CPDF_AutoReflowElement* pParent = NULL) ;
28    ~CPDF_AutoReflowElement();
29    LayoutType GetType()
30    {
31        return m_ElmType;
32    }
33    void	GetRect(CFX_FloatRect& rcRect) {};
34
35    int  CountAttrValues(LayoutAttr attr_type);
36    LayoutEnum  GetEnumAttr(LayoutAttr attr_type, int index);
37    FX_FLOAT GetNumberAttr(LayoutAttr attr_type, int index);
38    FX_COLORREF GetColorAttr(LayoutAttr attr_type, int index);
39
40    int  CountChildren()
41    {
42        return m_ChildArray.GetSize();
43    }
44    IPDF_LayoutElement* GetChild(int index)
45    {
46        return m_ChildArray.GetAt(index);
47    }
48
49    IPDF_LayoutElement* GetParent()
50    {
51        return m_pParentElm;
52    }
53    int		CountObjects()
54    {
55        return m_ObjArray.GetSize();
56    }
57    CPDF_PageObject*	GetObject(int index)
58    {
59        return m_ObjArray.GetAt(index);
60    }
61    CPDF_AutoReflowElement* m_pParentElm;
62    LayoutType		m_ElmType;
63    CAR_ElmPtrArray m_ChildArray;
64    CAR_ObjPtrArray m_ObjArray;
65    FX_FLOAT		m_SpaceBefore;
66};
67#define AUTOREFLOW_STEP_GENERATELINE		1
68#define AUTOREFLOW_STEP_GENERATEParagraph	2
69#define AUTOREFLOW_STEP_CREATEELEMENT		3
70#define AUTOREFLOW_STEP_REMOVEDATA			4
71class CPDF_AutoReflowLayoutProvider : public IPDF_LayoutProvider, public CFX_Object
72{
73public:
74    CPDF_AutoReflowLayoutProvider(CPDF_PageObjects* pPage, FX_BOOL bReadOrder);
75    ~CPDF_AutoReflowLayoutProvider();
76    void	SetLayoutProviderStyle(LAYOUTPROVIDER_STYLE Style)
77    {
78        m_Style = Style;
79    }
80    LayoutStatus StartLoad(IFX_Pause* pPause = NULL);
81    LayoutStatus Continue();
82    int	 		GetPosition();
83    IPDF_LayoutElement* GetRoot()
84    {
85        return m_pRoot;
86    }
87    FX_FLOAT GetObjMinCell(CPDF_PageObject* pObj);
88    void Conver2AppreceOrder(const CPDF_PageObjects* pStreamOrderObjs, CPDF_PageObjects* pAppraceOrderObjs);
89    void	ReleaseElm(CPDF_AutoReflowElement*& pElm, FX_BOOL bReleaseChildren = TRUE);
90    void GenerateCell();
91    void GenerateStructTree();
92    void GenerateLine(CFX_PtrArray& cellArray);
93    void GenerateParagraph(CFX_PtrArray& cellArray);
94    void CreateElement();
95    void AddObjectArray(CPDF_AutoReflowElement* pElm, CFX_PtrList& ObjList);
96    FX_FLOAT GetLayoutOrderHeight(CPDF_PageObject* pCurObj);
97    FX_FLOAT GetLayoutOrderWidth(CPDF_PageObject* pCurObj);
98    int GetWritingMode(CPDF_PageObject* pPreObj, CPDF_PageObject* pCurObj);
99    int GetRectStart(FX_RECT rect);
100    int GetRectEnd(FX_RECT rect);
101    int GetRectTop(FX_RECT rect);
102    int GetRectBottom(FX_RECT rect);
103    int GetRectHeight(FX_RECT rect);
104    int GetRectWidth(FX_RECT rect);
105    void ProcessObj(CFX_PtrArray& cellArray, CPDF_PageObject* pObj, CFX_AffineMatrix matrix);
106    FX_INT32 LogicPreObj(CPDF_PageObject* pObj);
107
108    CPDF_AutoReflowElement* m_pRoot;
109    CPDF_AutoReflowElement* m_pCurrElm;
110    CPDF_Page*	m_pPDFPage;
111    IFX_Pause*	m_pPause;
112    CFX_AffineMatrix m_PDFDisplayMatrix;
113    CPDF_PageObject* m_pPreObj;
114    LayoutStatus m_Status;
115    int m_WritingMode;
116    CFX_PtrArray m_CellArray;
117    FX_BOOL		 m_bReadOrder;
118    LAYOUTPROVIDER_STYLE m_Style;
119    CFX_PtrArray m_cellArray;
120    int			m_Step;
121};
122#endif
123