f910dfd3720ed1ed4db692bea0f19e39a4173d51
[pdfium.git] / core / src / fpdfdoc / pdf_vt.h
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 _PDF_VT_H_
8 #define _PDF_VT_H_
9
10 class CPVT_Size;
11 class CPVT_FloatRect;
12 struct CPVT_SectionInfo;
13 struct CPVT_LineInfo;
14 struct CPVT_WordInfo;
15 class CLine;
16 class CLines;
17 class CSection;
18 class CTypeset;
19 class CPDF_EditContainer;
20 class CPDF_VariableText;
21 class CPDF_VariableText_Iterator;
22 #define IsFloatZero(f)                                          ((f) < 0.0001 && (f) > -0.0001)
23 #define IsFloatBigger(fa,fb)                            ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
24 #define IsFloatSmaller(fa,fb)                           ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
25 template<class T> T FPDF_MIN (const T & i, const T & j)
26 {
27     return ((i < j) ? i : j);
28 }
29 template<class T> T FPDF_MAX (const T & i, const T & j)
30 {
31     return ((i > j) ? i : j);
32 }
33 class CPVT_Size
34 {
35 public:
36     CPVT_Size() : x(0.0f), y(0.0f)
37     {
38     }
39     CPVT_Size(FX_FLOAT x, FX_FLOAT y)
40     {
41         this->x = x;
42         this->y = y;
43     }
44     FX_FLOAT x, y;
45 };
46 class CPVT_FloatRect : public CFX_FloatRect
47 {
48 public:
49     CPVT_FloatRect()
50     {
51         left = top = right = bottom = 0.0f;
52     }
53     CPVT_FloatRect(FX_FLOAT left, FX_FLOAT top,
54                    FX_FLOAT right, FX_FLOAT bottom)
55     {
56         this->left = left;
57         this->top = top;
58         this->right = right;
59         this->bottom = bottom;
60     }
61     CPVT_FloatRect(const CPDF_Rect & rect)
62     {
63         this->left = rect.left;
64         this->top = rect.top;
65         this->right = rect.right;
66         this->bottom = rect.bottom;
67     }
68     void Default()
69     {
70         left = top = right = bottom = 0.0f;
71     }
72     FX_FLOAT Height() const
73     {
74         if(this->top > this->bottom) {
75             return this->top - this->bottom;
76         } else {
77             return this->bottom - this->top;
78         }
79     }
80 };
81 struct CPVT_SectionInfo {
82     CPVT_SectionInfo() : rcSection(), nTotalLine(0), pSecProps(NULL), pWordProps(NULL)
83     {
84     }
85     virtual ~CPVT_SectionInfo()
86     {
87         if (pSecProps) {
88             delete pSecProps;
89         }
90         if (pWordProps) {
91             delete pWordProps;
92         }
93     }
94     CPVT_SectionInfo(const CPVT_SectionInfo & other): rcSection(), nTotalLine(0), pSecProps(NULL), pWordProps(NULL)
95     {
96         operator = (other);
97     }
98     void operator = (const CPVT_SectionInfo & other)
99     {
100         if (this == &other) {
101             return;
102         }
103         this->rcSection = other.rcSection;
104         this->nTotalLine = other.nTotalLine;
105         if (other.pSecProps) {
106             if (pSecProps) {
107                 *pSecProps = *other.pSecProps;
108             } else {
109                 pSecProps = FX_NEW CPVT_SecProps(*other.pSecProps);
110             }
111         }
112         if (other.pWordProps) {
113             if (pWordProps) {
114                 *pWordProps = *other.pWordProps;
115             } else {
116                 pWordProps = FX_NEW CPVT_WordProps(*other.pWordProps);
117             }
118         }
119     }
120     CPVT_FloatRect                              rcSection;
121     FX_INT32                                    nTotalLine;
122     CPVT_SecProps*                              pSecProps;
123     CPVT_WordProps*                             pWordProps;
124 };
125 struct CPVT_LineInfo {
126     CPVT_LineInfo() : nTotalWord(0), nBeginWordIndex(-1), nEndWordIndex(-1),
127         fLineX(0.0f), fLineY(0.0f), fLineWidth(0.0f), fLineAscent(0.0f), fLineDescent(0.0f)
128     {
129     }
130     FX_INT32                                    nTotalWord;
131     FX_INT32                                    nBeginWordIndex;
132     FX_INT32                                    nEndWordIndex;
133     FX_FLOAT                                    fLineX;
134     FX_FLOAT                                    fLineY;
135     FX_FLOAT                                    fLineWidth;
136     FX_FLOAT                                    fLineAscent;
137     FX_FLOAT                                    fLineDescent;
138 };
139 struct CPVT_WordInfo  {
140     CPVT_WordInfo() : Word(0), nCharset(0),
141         fWordX(0.0f), fWordY(0.0f), fWordTail(0.0f), nFontIndex(-1), pWordProps(NULL)
142     {
143     }
144     CPVT_WordInfo(FX_WORD word, FX_INT32 charset, FX_INT32 fontIndex, CPVT_WordProps * pProps):
145         Word(word), nCharset(charset), fWordX(0.0f), fWordY(0.0f), fWordTail(0.0f),
146         nFontIndex(fontIndex), pWordProps(pProps)
147     {
148     }
149     virtual ~CPVT_WordInfo()
150     {
151         if (pWordProps) {
152             delete pWordProps;
153         }
154     }
155     CPVT_WordInfo(const CPVT_WordInfo & word): Word(0), nCharset(0),
156         fWordX(0.0f), fWordY(0.0f), fWordTail(0.0f), nFontIndex(-1), pWordProps(NULL)
157     {
158         operator = (word);
159     }
160     void operator = (const CPVT_WordInfo & word)
161     {
162         if (this == &word) {
163             return;
164         }
165         this->Word = word.Word;
166         this->nCharset = word.nCharset;
167         this->nFontIndex = word.nFontIndex;
168         if (word.pWordProps) {
169             if (pWordProps) {
170                 *pWordProps = *word.pWordProps;
171             } else {
172                 pWordProps = FX_NEW CPVT_WordProps(*word.pWordProps);
173             }
174         }
175     }
176     FX_WORD                                             Word;
177     FX_INT32                                    nCharset;
178     FX_FLOAT                                    fWordX;
179     FX_FLOAT                                    fWordY;
180     FX_FLOAT                                    fWordTail;
181     FX_INT32                                    nFontIndex;
182     CPVT_WordProps*                             pWordProps;
183 };
184 struct CPVT_FloatRange {
185     CPVT_FloatRange() : fMin(0.0f), fMax(0.0f)
186     {
187     }
188     CPVT_FloatRange(FX_FLOAT min, FX_FLOAT max) : fMin(min), fMax(max)
189     {
190     }
191     FX_FLOAT Range() const
192     {
193         return fMax - fMin;
194     }
195     FX_FLOAT fMin, fMax;
196 };
197 template<class TYPE> class CPVT_ArrayTemplate : public CFX_ArrayTemplate<TYPE>
198 {
199 public:
200     FX_BOOL IsEmpty()
201     {
202         return CFX_ArrayTemplate<TYPE>::GetSize() <= 0;
203     }
204     TYPE GetAt(int nIndex) const
205     {
206         if (nIndex >= 0 && nIndex < CFX_ArrayTemplate<TYPE>::GetSize()) {
207             return CFX_ArrayTemplate<TYPE>::GetAt(nIndex);
208         }
209         return NULL;
210     }
211     void RemoveAt(int nIndex)
212     {
213         if (nIndex >= 0 && nIndex < CFX_ArrayTemplate<TYPE>::GetSize()) {
214             CFX_ArrayTemplate<TYPE>::RemoveAt(nIndex);
215         }
216     }
217 };
218 class CLine 
219 {
220 public:
221     CLine();
222     virtual ~CLine();
223     CPVT_WordPlace                                                      GetBeginWordPlace() const;
224     CPVT_WordPlace                                                      GetEndWordPlace() const;
225     CPVT_WordPlace                                                      GetPrevWordPlace(const CPVT_WordPlace & place) const;
226     CPVT_WordPlace                                                      GetNextWordPlace(const CPVT_WordPlace & place) const;
227     CPVT_WordPlace                                                      LinePlace;
228     CPVT_LineInfo                                                       m_LineInfo;
229 };
230 class CLines
231 {
232 public:
233     CLines() : m_nTotal(0) {}
234     virtual ~CLines()
235     {
236         RemoveAll();
237     }
238     FX_INT32                                                            GetSize() const
239     {
240         return m_Lines.GetSize();
241     }
242     CLine *                                                                     GetAt(FX_INT32 nIndex) const
243     {
244         return m_Lines.GetAt(nIndex);
245     }
246     void                                                                        Empty()
247     {
248         m_nTotal = 0;
249     }
250     void                                                                        RemoveAll()
251     {
252         for (FX_INT32 i = 0, sz = GetSize(); i < sz; i++) {
253             delete GetAt(i);
254         }
255         m_Lines.RemoveAll();
256         m_nTotal = 0;
257     }
258     FX_INT32                                                            Add(const CPVT_LineInfo & lineinfo)
259     {
260         if (m_nTotal >= GetSize()) {
261             if (CLine * pLine = FX_NEW CLine) {
262                 pLine->m_LineInfo = lineinfo;
263                 m_Lines.Add(pLine);
264                 return m_nTotal++;
265             }
266             return m_nTotal;
267         } else {
268             if (CLine * pLine = GetAt(m_nTotal)) {
269                 pLine->m_LineInfo = lineinfo;
270             }
271             return m_nTotal++;
272         }
273     }
274     void                                                                        Clear()
275     {
276         for (FX_INT32 i = GetSize() - 1; i >= m_nTotal; i--) {
277             delete GetAt(i);
278             m_Lines.RemoveAt(i);
279         }
280     }
281 private:
282     CPVT_ArrayTemplate<CLine*>                          m_Lines;
283     FX_INT32                                                            m_nTotal;
284 };
285 class CSection 
286 {
287     friend class CTypeset;
288 public:
289     CSection(CPDF_VariableText * pVT);
290     virtual ~CSection();
291     void                                                                        ResetAll();
292     void                                                                        ResetLineArray();
293     void                                                                        ResetWordArray();
294     void                                                                        ResetLinePlace();
295     CPVT_WordPlace                                                      AddWord(const CPVT_WordPlace & place, const CPVT_WordInfo & wordinfo);
296     CPVT_WordPlace                                                      AddLine(const CPVT_LineInfo & lineinfo);
297     void                                                                        ClearWords(const CPVT_WordRange & PlaceRange);
298     void                                                                        ClearWord(const CPVT_WordPlace & place);
299     CPVT_FloatRect                                                      Rearrange();
300     CPVT_Size                                                           GetSectionSize(FX_FLOAT fFontSize);
301     CPVT_WordPlace                                                      GetBeginWordPlace() const;
302     CPVT_WordPlace                                                      GetEndWordPlace() const;
303     CPVT_WordPlace                                                      GetPrevWordPlace(const CPVT_WordPlace & place) const;
304     CPVT_WordPlace                                                      GetNextWordPlace(const CPVT_WordPlace & place) const;
305     void                                                                        UpdateWordPlace(CPVT_WordPlace & place) const;
306     CPVT_WordPlace                                                      SearchWordPlace(const CPDF_Point & point) const;
307     CPVT_WordPlace                                                      SearchWordPlace(FX_FLOAT fx, const CPVT_WordPlace & lineplace) const;
308     CPVT_WordPlace                                                      SearchWordPlace(FX_FLOAT fx, const CPVT_WordRange & range) const;
309 public:
310     CPVT_WordPlace                                                      SecPlace;
311     CPVT_SectionInfo                                            m_SecInfo;
312     CLines                                                                      m_LineArray;
313     CPVT_ArrayTemplate<CPVT_WordInfo*>          m_WordArray;
314 private:
315     void                                                                        ClearLeftWords(FX_INT32 nWordIndex);
316     void                                                                        ClearRightWords(FX_INT32 nWordIndex);
317     void                                                                        ClearMidWords(FX_INT32 nBeginIndex, FX_INT32 nEndIndex);
318
319     CPDF_VariableText                                           *m_pVT;
320 };
321 class CTypeset
322 {
323 public:
324     CTypeset(CSection * pSection);
325     virtual ~CTypeset();
326     CPVT_Size                                                           GetEditSize(FX_FLOAT fFontSize);
327     CPVT_FloatRect                                                      Typeset();
328     CPVT_FloatRect                                                      CharArray();
329 private:
330     void                                                                        SplitLines(FX_BOOL bTypeset, FX_FLOAT fFontSize);
331     void                                                                        OutputLines();
332
333     CPVT_FloatRect                                                      m_rcRet;
334     CPDF_VariableText                                           * m_pVT;
335     CSection                                                            * m_pSection;
336 };
337 class CPDF_EditContainer
338 {
339 public:
340     CPDF_EditContainer(): m_rcPlate(0, 0, 0, 0), m_rcContent(0, 0, 0, 0) {};
341     virtual ~CPDF_EditContainer() {};
342     virtual void                                                        SetPlateRect(const CPDF_Rect & rect)
343     {
344         m_rcPlate = rect;
345     };
346     virtual const CPDF_Rect &                           GetPlateRect() const
347     {
348         return m_rcPlate;
349     };
350     virtual void                                                        SetContentRect(const CPVT_FloatRect & rect)
351     {
352         m_rcContent = rect;
353     };
354     virtual CPDF_Rect                                           GetContentRect() const
355     {
356         return m_rcContent;
357     };
358     FX_FLOAT                                                            GetPlateWidth() const
359     {
360         return m_rcPlate.right - m_rcPlate.left;
361     };
362     FX_FLOAT                                                            GetPlateHeight() const
363     {
364         return m_rcPlate.top - m_rcPlate.bottom;
365     };
366     CPVT_Size                                                           GetPlateSize() const
367     {
368         return CPVT_Size(GetPlateWidth(), GetPlateHeight());
369     };
370     CPDF_Point                                                          GetBTPoint() const
371     {
372         return CPDF_Point(m_rcPlate.left, m_rcPlate.top);
373     };
374     CPDF_Point                                                          GetETPoint() const
375     {
376         return CPDF_Point(m_rcPlate.right, m_rcPlate.bottom);
377     };
378     inline CPDF_Point                                           InToOut(const CPDF_Point & point) const
379     {
380         return CPDF_Point(point.x + GetBTPoint().x, GetBTPoint().y - point.y);
381     };
382     inline CPDF_Point                                           OutToIn(const CPDF_Point & point) const
383     {
384         return CPDF_Point(point.x - GetBTPoint().x, GetBTPoint().y - point.y);
385     };
386     inline CPDF_Rect                                            InToOut(const CPVT_FloatRect & rect) const
387     {
388         CPDF_Point ptLeftTop = InToOut(CPDF_Point(rect.left, rect.top));
389         CPDF_Point ptRightBottom = InToOut(CPDF_Point(rect.right, rect.bottom));
390         return CPDF_Rect(ptLeftTop.x, ptRightBottom.y, ptRightBottom.x, ptLeftTop.y);
391     };
392     inline CPVT_FloatRect                                       OutToIn(const CPDF_Rect & rect) const
393     {
394         CPDF_Point ptLeftTop = OutToIn(CPDF_Point(rect.left, rect.top));
395         CPDF_Point ptRightBottom = OutToIn(CPDF_Point(rect.right, rect.bottom));
396         return CPVT_FloatRect(ptLeftTop.x, ptLeftTop.y, ptRightBottom.x, ptRightBottom.y);
397     };
398
399 private:
400     CPDF_Rect                                                           m_rcPlate;
401     CPVT_FloatRect                                                      m_rcContent;
402 };
403 class CPDF_VariableText : public IPDF_VariableText, private CPDF_EditContainer
404 {
405     friend class CTypeset;
406     friend class CSection;
407     friend class CPDF_VariableText_Iterator;
408 public:
409     CPDF_VariableText();
410     virtual ~CPDF_VariableText();
411     IPDF_VariableText_Provider*                         SetProvider(IPDF_VariableText_Provider * pProvider);
412     IPDF_VariableText_Iterator*                         GetIterator();
413     void                                                                        SetPlateRect(const CPDF_Rect & rect)
414     {
415         CPDF_EditContainer::SetPlateRect(rect);
416     }
417     void                                                                        SetAlignment(FX_INT32 nFormat = 0)
418     {
419         m_nAlignment = nFormat;
420     }
421     void                                                                        SetPasswordChar(FX_WORD wSubWord = '*')
422     {
423         m_wSubWord = wSubWord;
424     }
425     void                                                                        SetLimitChar(FX_INT32 nLimitChar = 0)
426     {
427         m_nLimitChar = nLimitChar;
428     }
429     void                                                                        SetCharSpace(FX_FLOAT fCharSpace = 0.0f)
430     {
431         m_fCharSpace = fCharSpace;
432     }
433     void                                                                        SetHorzScale(FX_INT32 nHorzScale = 100)
434     {
435         m_nHorzScale = nHorzScale;
436     }
437     void                                                                        SetMultiLine(FX_BOOL bMultiLine = TRUE)
438     {
439         m_bMultiLine = bMultiLine;
440     }
441     void                                                                        SetAutoReturn(FX_BOOL bAuto = TRUE)
442     {
443         m_bLimitWidth = bAuto;
444     }
445     void                                                                        SetFontSize(FX_FLOAT fFontSize)
446     {
447         m_fFontSize = fFontSize;
448     }
449     void                                                                        SetCharArray(FX_INT32 nCharArray = 0)
450     {
451         m_nCharArray = nCharArray;
452     }
453     void                                                                        SetAutoFontSize(FX_BOOL bAuto = TRUE)
454     {
455         m_bAutoFontSize = bAuto;
456     }
457     void                                                                        SetRichText(FX_BOOL bRichText)
458     {
459         m_bRichText = bRichText;
460     }
461     void                                                                        SetLineLeading(FX_FLOAT fLineLeading)
462     {
463         m_fLineLeading = fLineLeading;
464     }
465     void                                                                        Initialize();
466     FX_BOOL                                                                     IsValid() const
467     {
468         return m_bInitial;
469     }
470     FX_BOOL                                                                     IsRichText() const
471     {
472         return m_bRichText;
473     }
474     void                                                                        RearrangeAll();
475     void                                                                        RearrangePart(const CPVT_WordRange & PlaceRange);
476     void                                                                        ResetAll();
477     void                                                                        SetText(FX_LPCWSTR text, FX_INT32 charset = 1, const CPVT_SecProps * pSecProps = NULL,
478             const CPVT_WordProps * pWordProps = NULL);
479     CPVT_WordPlace                                                      InsertWord(const CPVT_WordPlace & place, FX_WORD word, FX_INT32 charset = 1,
480             const CPVT_WordProps * pWordProps = NULL);
481     CPVT_WordPlace                                                      InsertSection(const CPVT_WordPlace & place, const CPVT_SecProps * pSecProps = NULL,
482             const CPVT_WordProps * pWordProps = NULL);
483     CPVT_WordPlace                                                      InsertText(const CPVT_WordPlace & place, FX_LPCWSTR text, FX_INT32 charset = 1,
484             const CPVT_SecProps * pSecProps = NULL,     const CPVT_WordProps * pWordProps = NULL);
485     CPVT_WordPlace                                                      DeleteWords(const CPVT_WordRange & PlaceRange);
486     CPVT_WordPlace                                                      DeleteWord(const CPVT_WordPlace & place);
487     CPVT_WordPlace                                                      BackSpaceWord(const CPVT_WordPlace & place);
488     const CPDF_Rect &                                           GetPlateRect() const
489     {
490         return CPDF_EditContainer::GetPlateRect();
491     }
492     CPDF_Rect                                                           GetContentRect() const;
493     FX_INT32                                                            GetTotalWords() const;
494     FX_FLOAT                                                            GetFontSize() const
495     {
496         return m_fFontSize;
497     }
498     FX_INT32                                                            GetAlignment() const
499     {
500         return m_nAlignment;
501     }
502     FX_INT32                                                            GetCharArray() const
503     {
504         return m_nCharArray;
505     }
506     FX_INT32                                                            GetLimitChar() const
507     {
508         return m_nLimitChar;
509     }
510     FX_BOOL                                                                     IsMultiLine() const
511     {
512         return m_bMultiLine;
513     }
514     FX_INT32                                                            GetHorzScale() const
515     {
516         return m_nHorzScale;
517     }
518     FX_FLOAT                                                            GetCharSpace() const
519     {
520         return m_fCharSpace;
521     }
522
523     CPVT_WordPlace                                                      GetBeginWordPlace() const;
524     CPVT_WordPlace                                                      GetEndWordPlace() const;
525     CPVT_WordPlace                                                      GetPrevWordPlace(const CPVT_WordPlace & place) const;
526     CPVT_WordPlace                                                      GetNextWordPlace(const CPVT_WordPlace & place) const;
527     CPVT_WordPlace                                                      SearchWordPlace(const CPDF_Point & point) const;
528     CPVT_WordPlace                                                      GetUpWordPlace(const CPVT_WordPlace & place, const CPDF_Point & point) const;
529     CPVT_WordPlace                                                      GetDownWordPlace(const CPVT_WordPlace & place, const CPDF_Point & point) const;
530     CPVT_WordPlace                                                      GetLineBeginPlace(const CPVT_WordPlace & place) const;
531     CPVT_WordPlace                                                      GetLineEndPlace(const CPVT_WordPlace & place) const;
532     CPVT_WordPlace                                                      GetSectionBeginPlace(const CPVT_WordPlace & place) const;
533     CPVT_WordPlace                                                      GetSectionEndPlace(const CPVT_WordPlace & place) const;
534     void                                                                        UpdateWordPlace(CPVT_WordPlace & place) const;
535     FX_INT32                                                            WordPlaceToWordIndex(const CPVT_WordPlace & place) const;
536     CPVT_WordPlace                                                      WordIndexToWordPlace(FX_INT32 index) const;
537     FX_WORD                                                                     GetPasswordChar() const
538     {
539         return GetSubWord();
540     }
541     FX_WORD                                                                     GetSubWord() const
542     {
543         return m_wSubWord;
544     }
545 private:
546     FX_INT32                                                            GetCharWidth(FX_INT32 nFontIndex, FX_WORD Word, FX_WORD SubWord, FX_INT32 nWordStyle);
547     FX_INT32                                                            GetTypeAscent(FX_INT32 nFontIndex);
548     FX_INT32                                                            GetTypeDescent(FX_INT32 nFontIndex);
549     FX_INT32                                                            GetWordFontIndex(FX_WORD word, FX_INT32 charset, FX_INT32 nFontIndex);
550     FX_INT32                                                            GetDefaultFontIndex();
551     FX_BOOL                                                                     IsLatinWord(FX_WORD word);
552 private:
553
554     CPVT_WordPlace                                                      AddSection(const CPVT_WordPlace & place, const CPVT_SectionInfo & secinfo);
555     CPVT_WordPlace                                                      AddLine(const CPVT_WordPlace & place, const CPVT_LineInfo & lineinfo);
556     CPVT_WordPlace                                                      AddWord(const CPVT_WordPlace & place, const CPVT_WordInfo & wordinfo);
557     FX_BOOL                                                                     GetWordInfo(const CPVT_WordPlace & place, CPVT_WordInfo & wordinfo);
558     FX_BOOL                                                                     SetWordInfo(const CPVT_WordPlace & place, const CPVT_WordInfo & wordinfo);
559     FX_BOOL                                                                     GetLineInfo(const CPVT_WordPlace & place, CPVT_LineInfo & lineinfo);
560     FX_BOOL                                                                     GetSectionInfo(const CPVT_WordPlace & place, CPVT_SectionInfo & secinfo);
561     FX_FLOAT                                                            GetWordFontSize(const CPVT_WordInfo & WordInfo, FX_BOOL bFactFontSize = FALSE);
562     FX_FLOAT                                                            GetWordWidth(FX_INT32 nFontIndex, FX_WORD Word, FX_WORD SubWord,
563             FX_FLOAT fCharSpace, FX_INT32 nHorzScale,
564             FX_FLOAT fFontSize, FX_FLOAT fWordTail, FX_INT32 nWordStyle);
565     FX_FLOAT                                                            GetWordWidth(const CPVT_WordInfo & WordInfo);
566     FX_FLOAT                                                            GetWordAscent(const CPVT_WordInfo & WordInfo, FX_FLOAT fFontSize);
567     FX_FLOAT                                                            GetWordDescent(const CPVT_WordInfo & WordInfo, FX_FLOAT fFontSize);
568     FX_FLOAT                                                            GetWordAscent(const CPVT_WordInfo & WordInfo, FX_BOOL bFactFontSize = FALSE);
569     FX_FLOAT                                                            GetWordDescent(const CPVT_WordInfo & WordInfo, FX_BOOL bFactFontSize = FALSE);
570     FX_FLOAT                                                            GetLineAscent(const CPVT_SectionInfo & SecInfo);
571     FX_FLOAT                                                            GetLineDescent(const CPVT_SectionInfo & SecInfo);
572     FX_FLOAT                                                            GetFontAscent(FX_INT32 nFontIndex, FX_FLOAT fFontSize);
573     FX_FLOAT                                                            GetFontDescent(FX_INT32 nFontIndex, FX_FLOAT fFontSize);
574     FX_INT32                                                            GetWordFontIndex(const CPVT_WordInfo & WordInfo);
575     FX_FLOAT                                                            GetCharSpace(const CPVT_WordInfo & WordInfo);
576     FX_INT32                                                            GetHorzScale(const CPVT_WordInfo & WordInfo);
577     FX_FLOAT                                                            GetLineLeading(const CPVT_SectionInfo & SecInfo);
578     FX_FLOAT                                                            GetLineIndent(const CPVT_SectionInfo & SecInfo);
579     FX_INT32                                                            GetAlignment(const CPVT_SectionInfo& SecInfo);
580
581     void                                                                        ClearSectionRightWords(const CPVT_WordPlace & place);
582     CPVT_WordPlace                                                      AjustLineHeader(const CPVT_WordPlace & place, FX_BOOL bPrevOrNext) const;
583     FX_BOOL                                                                     ClearEmptySection(const CPVT_WordPlace & place);
584     void                                                                        ClearEmptySections(const CPVT_WordRange & PlaceRange);
585     void                                                                        LinkLatterSection(const CPVT_WordPlace & place);
586     void                                                                        ClearWords(const CPVT_WordRange & PlaceRange);
587     CPVT_WordPlace                                                      ClearLeftWord(const CPVT_WordPlace & place);
588     CPVT_WordPlace                                                      ClearRightWord(const CPVT_WordPlace & place);
589 private:
590     CPVT_FloatRect                                                      Rearrange(const CPVT_WordRange & PlaceRange);
591     FX_FLOAT                                                            GetAutoFontSize();
592     FX_BOOL                                                                     IsBigger(FX_FLOAT fFontSize);
593     CPVT_FloatRect                                                      RearrangeSections(const CPVT_WordRange & PlaceRange);
594 private:
595     void                                                                        ResetSectionArray();
596 private:
597     CPVT_ArrayTemplate<CSection*>                       m_SectionArray;
598     FX_INT32                                                            m_nLimitChar;
599     FX_INT32                                                            m_nCharArray;
600     FX_BOOL                                                                     m_bMultiLine;
601     FX_BOOL                                                                     m_bLimitWidth;
602     FX_BOOL                                                                     m_bAutoFontSize;
603     FX_INT32                                                            m_nAlignment;
604     FX_FLOAT                                                            m_fLineLeading;
605     FX_FLOAT                                                            m_fCharSpace;
606     FX_INT32                                                            m_nHorzScale;
607     FX_WORD                                                                     m_wSubWord;
608     FX_FLOAT                                                            m_fFontSize;
609
610 private:
611     FX_BOOL                                                                     m_bInitial;
612     FX_BOOL                                                                     m_bRichText;
613     IPDF_VariableText_Provider *                        m_pVTProvider;
614     CPDF_VariableText_Iterator *                        m_pVTIterator;
615 };
616 class CPDF_VariableText_Iterator : public IPDF_VariableText_Iterator
617 {
618 public:
619     CPDF_VariableText_Iterator(CPDF_VariableText * pVT);
620     virtual ~CPDF_VariableText_Iterator();
621     FX_BOOL                                                                     NextWord();
622     FX_BOOL                                                                     PrevWord();
623     FX_BOOL                                                                     NextLine();
624     FX_BOOL                                                                     PrevLine();
625     FX_BOOL                                                                     NextSection();
626     FX_BOOL                                                                     PrevSection();
627     FX_BOOL                                                                     SetWord(const CPVT_Word & word);
628     FX_BOOL                                                                     GetWord(CPVT_Word & word) const;
629     FX_BOOL                                                                     GetLine(CPVT_Line & line) const;
630     FX_BOOL                                                                     GetSection(CPVT_Section & section) const;
631     FX_BOOL                                                                     SetSection(const CPVT_Section & section);
632     void                                                                        SetAt(FX_INT32 nWordIndex);
633     void                                                                        SetAt(const CPVT_WordPlace & place);
634     const CPVT_WordPlace &                                      GetAt() const
635     {
636         return m_CurPos;
637     };
638 private:
639     CPVT_WordPlace                                                      m_CurPos;
640     CPDF_VariableText *                                         m_pVT;
641 };
642
643 #endif  // _PDF_VT_H_