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