Initial commit.
[pdfium.git] / core / src / fpdfdoc / doc_annot.cpp
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 #include "../../include/fpdfdoc/fpdf_doc.h"\r
8 #include "../../include/fpdfapi/fpdf_pageobj.h"\r
9 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage)\r
10 {\r
11     ASSERT(pPage != NULL);\r
12     m_pPageDict = pPage->m_pFormDict;\r
13     if (m_pPageDict == NULL) {\r
14         return;\r
15     }\r
16     m_pDocument = pPage->m_pDocument;\r
17     CPDF_Array* pAnnots = m_pPageDict->GetArray("Annots");\r
18     if (pAnnots == NULL) {\r
19         return;\r
20     }\r
21     CPDF_Dictionary* pRoot = m_pDocument->GetRoot();\r
22     CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm");\r
23     FX_BOOL bRegenerateAP = pAcroForm && pAcroForm->GetBoolean("NeedAppearances");\r
24     for (FX_DWORD i = 0; i < pAnnots->GetCount(); i ++) {\r
25         CPDF_Dictionary* pDict = (CPDF_Dictionary*)pAnnots->GetElementValue(i);\r
26         if (pDict == NULL || pDict->GetType() != PDFOBJ_DICTIONARY) {\r
27             continue;\r
28         }\r
29         FX_DWORD dwObjNum = pDict->GetObjNum();\r
30         if (dwObjNum == 0) {\r
31             dwObjNum = m_pDocument->AddIndirectObject(pDict);\r
32             CPDF_Reference* pAction = CPDF_Reference::Create(m_pDocument, dwObjNum);\r
33             if (pAction == NULL) {\r
34                 break;\r
35             }\r
36             pAnnots->InsertAt(i, pAction);\r
37             pAnnots->RemoveAt(i + 1);\r
38             pDict = pAnnots->GetDict(i);\r
39         }\r
40         CPDF_Annot* pAnnot = FX_NEW CPDF_Annot(pDict);\r
41         if (pAnnot == NULL) {\r
42             break;\r
43         }\r
44         pAnnot->m_pList = this;\r
45         m_AnnotList.Add(pAnnot);\r
46         if (bRegenerateAP && pDict->GetConstString(FX_BSTRC("Subtype")) == FX_BSTRC("Widget"))\r
47             if (CPDF_InterForm::UpdatingAPEnabled()) {\r
48                 FPDF_GenerateAP(m_pDocument, pDict);\r
49             }\r
50     }\r
51 }\r
52 CPDF_AnnotList::~CPDF_AnnotList()\r
53 {\r
54     int i = 0;\r
55     for (i = 0; i < m_AnnotList.GetSize(); i ++) {\r
56         delete (CPDF_Annot*)m_AnnotList[i];\r
57     }\r
58     for (i = 0; i < m_Borders.GetSize(); ++i) {\r
59         delete (CPDF_PageObjects*)m_Borders[i];\r
60     }\r
61 }\r
62 void CPDF_AnnotList::DisplayPass(const CPDF_Page* pPage, CFX_RenderDevice* pDevice,\r
63                                  CPDF_RenderContext* pContext, FX_BOOL bPrinting, CFX_AffineMatrix* pMatrix,\r
64                                  FX_BOOL bWidgetPass, CPDF_RenderOptions* pOptions, FX_RECT* clip_rect)\r
65 {\r
66     for (int i = 0; i < m_AnnotList.GetSize(); i ++) {\r
67         CPDF_Annot* pAnnot = (CPDF_Annot*)m_AnnotList[i];\r
68         FX_BOOL bWidget = pAnnot->GetSubType() == "Widget";\r
69         if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget)) {\r
70             continue;\r
71         }\r
72         FX_DWORD annot_flags = pAnnot->GetFlags();\r
73         if (annot_flags & ANNOTFLAG_HIDDEN) {\r
74             continue;\r
75         }\r
76         if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) {\r
77             continue;\r
78         }\r
79         if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) {\r
80             continue;\r
81         }\r
82         if (pOptions != NULL) {\r
83             IPDF_OCContext* pOCContext = pOptions->m_pOCContext;\r
84             CPDF_Dictionary* pAnnotDict = pAnnot->m_pAnnotDict;\r
85             if (pOCContext != NULL && pAnnotDict != NULL &&\r
86                     !pOCContext->CheckOCGVisible(pAnnotDict->GetDict(FX_BSTRC("OC")))) {\r
87                 continue;\r
88             }\r
89         }\r
90         CPDF_Rect annot_rect_f;\r
91         pAnnot->GetRect(annot_rect_f);\r
92         CFX_Matrix matrix;\r
93         matrix = *pMatrix;\r
94         if (clip_rect) {\r
95             annot_rect_f.Transform(&matrix);\r
96             FX_RECT annot_rect = annot_rect_f.GetOutterRect();\r
97             annot_rect.Intersect(*clip_rect);\r
98             if (annot_rect.IsEmpty()) {\r
99                 continue;\r
100             }\r
101         }\r
102         if (pContext) {\r
103             pAnnot->DrawInContext(pPage, pContext, &matrix, CPDF_Annot::Normal);\r
104         } else if (!pAnnot->DrawAppearance(pPage, pDevice, &matrix, CPDF_Annot::Normal, pOptions)) {\r
105             pAnnot->DrawBorder(pDevice, &matrix, pOptions);\r
106         }\r
107     }\r
108 }\r
109 void CPDF_AnnotList::DisplayAnnots(const CPDF_Page* pPage, CFX_RenderDevice* pDevice,\r
110                                    CFX_AffineMatrix* pUser2Device,\r
111                                    FX_BOOL bShowWidget, CPDF_RenderOptions* pOptions)\r
112 {\r
113     FX_RECT clip_rect;\r
114     if (pDevice) {\r
115         clip_rect = pDevice->GetClipBox();\r
116     }\r
117     FX_BOOL bPrinting = pDevice->GetDeviceClass() == FXDC_PRINTER || (pOptions && (pOptions->m_Flags & RENDER_PRINTPREVIEW));\r
118     DisplayAnnots(pPage, pDevice, NULL, bPrinting, pUser2Device, bShowWidget ? 3 : 1, pOptions, &clip_rect);\r
119 }\r
120 void CPDF_AnnotList::DisplayAnnots(const CPDF_Page* pPage, CFX_RenderDevice* pDevice, CPDF_RenderContext* pContext,\r
121                                    FX_BOOL bPrinting, CFX_AffineMatrix* pUser2Device, FX_DWORD dwAnnotFlags,\r
122                                    CPDF_RenderOptions* pOptions, FX_RECT* pClipRect)\r
123 {\r
124     if (dwAnnotFlags & 0x01) {\r
125         DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, FALSE, pOptions, pClipRect);\r
126     }\r
127     if (dwAnnotFlags & 0x02) {\r
128         DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, TRUE, pOptions, pClipRect);\r
129     }\r
130 }\r
131 int CPDF_AnnotList::GetIndex(CPDF_Annot* pAnnot)\r
132 {\r
133     for (int i = 0; i < m_AnnotList.GetSize(); i ++)\r
134         if (m_AnnotList[i] == (FX_LPVOID)pAnnot) {\r
135             return i;\r
136         }\r
137     return -1;\r
138 }\r
139 CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict)\r
140 {\r
141     m_pList = NULL;\r
142     m_pAnnotDict = pDict;\r
143 }\r
144 CPDF_Annot::~CPDF_Annot()\r
145 {\r
146     ClearCachedAP();\r
147 }\r
148 CPDF_Reference* CPDF_Annot::NewAnnotRef()\r
149 {\r
150     if (m_pAnnotDict->GetObjNum() == 0) {\r
151         m_pList->m_pDocument->AddIndirectObject(m_pAnnotDict);\r
152     }\r
153     return CPDF_Reference::Create(m_pList->m_pDocument, m_pAnnotDict->GetObjNum());\r
154 }\r
155 void CPDF_Annot::ClearCachedAP()\r
156 {\r
157     FX_POSITION pos = m_APMap.GetStartPosition();\r
158     while (pos) {\r
159         void* pForm;\r
160         void* pObjects;\r
161         m_APMap.GetNextAssoc(pos, pForm, pObjects);\r
162         delete (CPDF_PageObjects*)pObjects;\r
163     }\r
164     m_APMap.RemoveAll();\r
165 }\r
166 CFX_ByteString CPDF_Annot::GetSubType() const\r
167 {\r
168     return m_pAnnotDict->GetConstString(FX_BSTRC("Subtype"));\r
169 }\r
170 void CPDF_Annot::GetRect(CPDF_Rect& rect) const\r
171 {\r
172     if (m_pAnnotDict == NULL) {\r
173         return;\r
174     }\r
175     rect = m_pAnnotDict->GetRect("Rect");\r
176     rect.Normalize();\r
177 }\r
178 CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, CPDF_Annot::AppearanceMode mode)\r
179 {\r
180     CPDF_Dictionary* pAP = pAnnotDict->GetDict("AP");\r
181     if (pAP == NULL) {\r
182         return NULL;\r
183     }\r
184     const FX_CHAR* ap_entry = "N";\r
185     if (mode == CPDF_Annot::Down) {\r
186         ap_entry = "D";\r
187     } else if (mode == CPDF_Annot::Rollover) {\r
188         ap_entry = "R";\r
189     }\r
190     if (!pAP->KeyExist(ap_entry)) {\r
191         ap_entry = "N";\r
192     }\r
193     CPDF_Object* psub = pAP->GetElementValue(ap_entry);\r
194     if (psub == NULL) {\r
195         return NULL;\r
196     }\r
197     CPDF_Stream* pStream = NULL;\r
198     if (psub->GetType() == PDFOBJ_STREAM) {\r
199         pStream = (CPDF_Stream*)psub;\r
200     } else if (psub->GetType() == PDFOBJ_DICTIONARY) {\r
201         CFX_ByteString as = pAnnotDict->GetString("AS");\r
202         if (as.IsEmpty()) {\r
203             CFX_ByteString value = pAnnotDict->GetString(FX_BSTRC("V"));\r
204             if (value.IsEmpty()) {\r
205                 value = pAnnotDict->GetDict(FX_BSTRC("Parent"))->GetString(FX_BSTRC("V"));\r
206             }\r
207             if (value.IsEmpty() || !((CPDF_Dictionary*)psub)->KeyExist(value)) {\r
208                 as = FX_BSTRC("Off");\r
209             } else {\r
210                 as = value;\r
211             }\r
212         }\r
213         pStream = ((CPDF_Dictionary*)psub)->GetStream(as);\r
214     }\r
215     return pStream;\r
216 }\r
217 CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode)\r
218 {\r
219     CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pAnnotDict, mode);\r
220     if (pStream == NULL) {\r
221         return NULL;\r
222     }\r
223     CPDF_Form* pForm;\r
224     if (m_APMap.Lookup(pStream, (void*&)pForm)) {\r
225         return pForm;\r
226     }\r
227     pForm = FX_NEW CPDF_Form(m_pList->m_pDocument, pPage->m_pResources, pStream);\r
228     if (pForm == NULL) {\r
229         return NULL;\r
230     }\r
231     pForm->ParseContent(NULL, NULL, NULL, NULL);\r
232     m_APMap.SetAt(pStream, pForm);\r
233     return pForm;\r
234 }\r
235 static CPDF_Form* FPDFDOC_Annot_GetMatrix(const CPDF_Page* pPage, CPDF_Annot* pAnnot, CPDF_Annot::AppearanceMode mode, const CFX_AffineMatrix* pUser2Device, CFX_Matrix &matrix)\r
236 {\r
237     CPDF_Form* pForm = pAnnot->GetAPForm(pPage, mode);\r
238     if (!pForm) {\r
239         return NULL;\r
240     }\r
241     CFX_FloatRect form_bbox = pForm->m_pFormDict->GetRect(FX_BSTRC("BBox"));\r
242     CFX_Matrix form_matrix = pForm->m_pFormDict->GetMatrix(FX_BSTRC("Matrix"));\r
243     form_matrix.TransformRect(form_bbox);\r
244     CPDF_Rect arect;\r
245     pAnnot->GetRect(arect);\r
246     matrix.MatchRect(arect, form_bbox);\r
247     matrix.Concat(*pUser2Device);\r
248     return pForm;\r
249 }\r
250 FX_BOOL CPDF_Annot::DrawAppearance(const CPDF_Page* pPage, CFX_RenderDevice* pDevice, const CFX_AffineMatrix* pUser2Device,\r
251                                    AppearanceMode mode, const CPDF_RenderOptions* pOptions)\r
252 {\r
253     CFX_Matrix matrix;\r
254     CPDF_Form* pForm = FPDFDOC_Annot_GetMatrix(pPage, this, mode, pUser2Device, matrix);\r
255     if (!pForm) {\r
256         return FALSE;\r
257     }\r
258     CPDF_RenderContext context;\r
259     context.Create((CPDF_Page*)pPage);\r
260     context.DrawObjectList(pDevice, pForm, &matrix, pOptions);\r
261     return TRUE;\r
262 }\r
263 FX_BOOL CPDF_Annot::DrawInContext(const CPDF_Page* pPage, const CPDF_RenderContext* pContext, const CFX_AffineMatrix* pUser2Device, AppearanceMode mode)\r
264 {\r
265     CFX_Matrix matrix;\r
266     CPDF_Form* pForm = FPDFDOC_Annot_GetMatrix(pPage, this, mode, pUser2Device, matrix);\r
267     if (!pForm) {\r
268         return FALSE;\r
269     }\r
270     ((CPDF_RenderContext*)pContext)->AppendObjectList(pForm, &matrix);\r
271     return TRUE;\r
272 }\r
273 CPDF_PageObject* CPDF_Annot::GetBorder(FX_BOOL bPrint, const CPDF_RenderOptions* pOptions)\r
274 {\r
275     if (GetSubType() == "Popup") {\r
276         return NULL;\r
277     }\r
278     FX_DWORD annot_flags = GetFlags();\r
279     if (annot_flags & ANNOTFLAG_HIDDEN) {\r
280         return NULL;\r
281     }\r
282     FX_BOOL bPrinting = bPrint || (pOptions && (pOptions->m_Flags & RENDER_PRINTPREVIEW));\r
283     if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) {\r
284         return NULL;\r
285     }\r
286     if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) {\r
287         return NULL;\r
288     }\r
289     CPDF_Dictionary* pBS = m_pAnnotDict->GetDict("BS");\r
290     char style_char;\r
291     FX_FLOAT width;\r
292     CPDF_Array* pDashArray = NULL;\r
293     if (pBS == NULL) {\r
294         CPDF_Array* pBorderArray = m_pAnnotDict->GetArray("Border");\r
295         style_char = 'S';\r
296         if (pBorderArray) {\r
297             width = pBorderArray->GetNumber(2);\r
298             if (pBorderArray->GetCount() == 4) {\r
299                 pDashArray = pBorderArray->GetArray(3);\r
300                 if (pDashArray == NULL) {\r
301                     return NULL;\r
302                 }\r
303                 style_char = 'D';\r
304             }\r
305         } else {\r
306             width = 1;\r
307         }\r
308     } else {\r
309         CFX_ByteString style = pBS->GetString("S");\r
310         pDashArray = pBS->GetArray("D");\r
311         style_char = style[1];\r
312         width = pBS->GetNumber("W");\r
313     }\r
314     if (width <= 0) {\r
315         return NULL;\r
316     }\r
317     CPDF_Array* pColor = m_pAnnotDict->GetArray("C");\r
318     FX_DWORD argb = 0xff000000;\r
319     if (pColor != NULL) {\r
320         int R = (FX_INT32)(pColor->GetNumber(0) * 255);\r
321         int G = (FX_INT32)(pColor->GetNumber(1) * 255);\r
322         int B = (FX_INT32)(pColor->GetNumber(2) * 255);\r
323         argb = ArgbEncode(0xff, R, G, B);\r
324     }\r
325     CPDF_PathObject *pPathObject = FX_NEW CPDF_PathObject();\r
326     if (!pPathObject) {\r
327         return NULL;\r
328     }\r
329     CPDF_GraphStateData *pGraphState = pPathObject->m_GraphState.GetModify();\r
330     if (!pGraphState) {\r
331         pPathObject->Release();\r
332         return NULL;\r
333     }\r
334     pGraphState->m_LineWidth = width;\r
335     CPDF_ColorStateData *pColorData = pPathObject->m_ColorState.GetModify();\r
336     if (!pColorData) {\r
337         pPathObject->Release();\r
338         return NULL;\r
339     }\r
340     pColorData->m_StrokeRGB = argb;\r
341     pPathObject->m_bStroke = TRUE;\r
342     pPathObject->m_FillType = 0;\r
343     if (style_char == 'D') {\r
344         if (pDashArray) {\r
345             FX_DWORD dash_count = pDashArray->GetCount();\r
346             if (dash_count % 2) {\r
347                 dash_count ++;\r
348             }\r
349             pGraphState->m_DashArray = FX_Alloc(FX_FLOAT, dash_count);\r
350             if (pGraphState->m_DashArray == NULL) {\r
351                 pPathObject->Release();\r
352                 return NULL;\r
353             }\r
354             pGraphState->m_DashCount = dash_count;\r
355             FX_DWORD i;\r
356             for (i = 0; i < pDashArray->GetCount(); i ++) {\r
357                 pGraphState->m_DashArray[i] = pDashArray->GetNumber(i);\r
358             }\r
359             if (i < dash_count) {\r
360                 pGraphState->m_DashArray[i] = pGraphState->m_DashArray[i - 1];\r
361             }\r
362         } else {\r
363             pGraphState->m_DashArray = FX_Alloc(FX_FLOAT, 2);\r
364             if (pGraphState->m_DashArray == NULL) {\r
365                 pPathObject->Release();\r
366                 return NULL;\r
367             }\r
368             pGraphState->m_DashCount = 2;\r
369             pGraphState->m_DashArray[0] = pGraphState->m_DashArray[1] = 3 * 1.0f;\r
370         }\r
371     }\r
372     CFX_FloatRect rect;\r
373     GetRect(rect);\r
374     width /= 2;\r
375     CPDF_PathData *pPathData = pPathObject->m_Path.GetModify();\r
376     if (pPathData) {\r
377         pPathData->AppendRect(rect.left + width, rect.bottom + width, rect.right - width, rect.top - width);\r
378     }\r
379     pPathObject->CalcBoundingBox();\r
380     return pPathObject;\r
381 }\r
382 void CPDF_Annot::DrawBorder(CFX_RenderDevice* pDevice, const CFX_AffineMatrix* pUser2Device, const CPDF_RenderOptions* pOptions)\r
383 {\r
384     if (GetSubType() == "Popup") {\r
385         return;\r
386     }\r
387     FX_DWORD annot_flags = GetFlags();\r
388     if (annot_flags & ANNOTFLAG_HIDDEN) {\r
389         return;\r
390     }\r
391     FX_BOOL bPrinting = pDevice->GetDeviceClass() == FXDC_PRINTER || (pOptions && (pOptions->m_Flags & RENDER_PRINTPREVIEW));\r
392     if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) {\r
393         return;\r
394     }\r
395     if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) {\r
396         return;\r
397     }\r
398     CPDF_Dictionary* pBS = m_pAnnotDict->GetDict("BS");\r
399     char style_char;\r
400     FX_FLOAT width;\r
401     CPDF_Array* pDashArray = NULL;\r
402     if (pBS == NULL) {\r
403         CPDF_Array* pBorderArray = m_pAnnotDict->GetArray("Border");\r
404         style_char = 'S';\r
405         if (pBorderArray) {\r
406             width = pBorderArray->GetNumber(2);\r
407             if (pBorderArray->GetCount() == 4) {\r
408                 pDashArray = pBorderArray->GetArray(3);\r
409                 if (pDashArray == NULL) {\r
410                     return;\r
411                 }\r
412                 int nLen = pDashArray->GetCount();\r
413                 int i = 0;\r
414                 for (; i < nLen; ++i) {\r
415                     CPDF_Object*pObj = pDashArray->GetElementValue(i);\r
416                     if (pObj && pObj->GetInteger()) {\r
417                         break;\r
418                     }\r
419                 }\r
420                 if (i == nLen) {\r
421                     return;\r
422                 }\r
423                 style_char = 'D';\r
424             }\r
425         } else {\r
426             width = 1;\r
427         }\r
428     } else {\r
429         CFX_ByteString style = pBS->GetString("S");\r
430         pDashArray = pBS->GetArray("D");\r
431         style_char = style[1];\r
432         width = pBS->GetNumber("W");\r
433     }\r
434     if (width <= 0) {\r
435         return;\r
436     }\r
437     CPDF_Array* pColor = m_pAnnotDict->GetArray("C");\r
438     FX_DWORD argb = 0xff000000;\r
439     if (pColor != NULL) {\r
440         int R = (FX_INT32)(pColor->GetNumber(0) * 255);\r
441         int G = (FX_INT32)(pColor->GetNumber(1) * 255);\r
442         int B = (FX_INT32)(pColor->GetNumber(2) * 255);\r
443         argb = ArgbEncode(0xff, R, G, B);\r
444     }\r
445     CPDF_GraphStateData graph_state;\r
446     graph_state.m_LineWidth = width;\r
447     if (style_char == 'D') {\r
448         if (pDashArray) {\r
449             FX_DWORD dash_count = pDashArray->GetCount();\r
450             if (dash_count % 2) {\r
451                 dash_count ++;\r
452             }\r
453             graph_state.m_DashArray = FX_Alloc(FX_FLOAT, dash_count);\r
454             if (graph_state.m_DashArray == NULL) {\r
455                 return ;\r
456             }\r
457             graph_state.m_DashCount = dash_count;\r
458             FX_DWORD i;\r
459             for (i = 0; i < pDashArray->GetCount(); i ++) {\r
460                 graph_state.m_DashArray[i] = pDashArray->GetNumber(i);\r
461             }\r
462             if (i < dash_count) {\r
463                 graph_state.m_DashArray[i] = graph_state.m_DashArray[i - 1];\r
464             }\r
465         } else {\r
466             graph_state.m_DashArray = FX_Alloc(FX_FLOAT, 2);\r
467             if (graph_state.m_DashArray == NULL) {\r
468                 return ;\r
469             }\r
470             graph_state.m_DashCount = 2;\r
471             graph_state.m_DashArray[0] = graph_state.m_DashArray[1] = 3 * 1.0f;\r
472         }\r
473     }\r
474     CFX_FloatRect rect;\r
475     GetRect(rect);\r
476     CPDF_PathData path;\r
477     width /= 2;\r
478     path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, rect.top - width);\r
479     int fill_type = 0;\r
480     if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) {\r
481         fill_type |= FXFILL_NOPATHSMOOTH;\r
482     }\r
483     pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type);\r
484 }\r
485 int CPDF_Annot::CountIRTNotes()\r
486 {\r
487     int count = 0;\r
488     for (int i = 0; i < m_pList->Count(); i ++) {\r
489         CPDF_Annot* pAnnot = m_pList->GetAt(i);\r
490         if (pAnnot == NULL) {\r
491             continue;\r
492         }\r
493         CPDF_Dictionary* pIRT = pAnnot->m_pAnnotDict->GetDict("IRT");\r
494         if (pIRT != m_pAnnotDict) {\r
495             continue;\r
496         }\r
497         count ++;\r
498     }\r
499     return count;\r
500 }\r
501 CPDF_Annot* CPDF_Annot::GetIRTNote(int index)\r
502 {\r
503     int count = 0;\r
504     for (int i = 0; i < m_pList->Count(); i ++) {\r
505         CPDF_Annot* pAnnot = m_pList->GetAt(i);\r
506         if (pAnnot == NULL) {\r
507             continue;\r
508         }\r
509         CPDF_Dictionary* pIRT = pAnnot->m_pAnnotDict->GetDict("IRT");\r
510         if (pIRT != m_pAnnotDict) {\r
511             continue;\r
512         }\r
513         if (count == index) {\r
514             return pAnnot;\r
515         }\r
516         count ++;\r
517     }\r
518     return NULL;\r
519 }\r