blob: 91fd3ef0b269bcc3d3698f9a92e539b011884060 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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#include "../include/fsdk_define.h"
Bo Xufdc00a72014-10-28 23:03:33 -07008#include "../include/fpdfxfa/fpdfxfa_doc.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009#include "../include/fsdk_mgr.h"
10#include "../include/fsdk_baseannot.h"
11
12
13//---------------------------------------------------------------------------
14// CPDFSDK_DateTime
15//---------------------------------------------------------------------------
Tom Sepezbfa9a822015-06-09 13:24:12 -070016int _gAfxGetTimeZoneInSeconds(FX_CHAR tzhour, uint8_t tzminute)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017{
18 return (int)tzhour * 3600 + (int)tzminute * (tzhour >= 0 ? 60 : -60);
19}
20
Tom Sepezbfa9a822015-06-09 13:24:12 -070021FX_BOOL _gAfxIsLeapYear(int16_t year)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070022{
23 return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)));
24}
25
Tom Sepezbfa9a822015-06-09 13:24:12 -070026FX_WORD _gAfxGetYearDays(int16_t year)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027{
28 return (_gAfxIsLeapYear(year) == TRUE ? 366 : 365);
29}
30
Tom Sepezbfa9a822015-06-09 13:24:12 -070031uint8_t _gAfxGetMonthDays(int16_t year, uint8_t month)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032{
Tom Sepezbfa9a822015-06-09 13:24:12 -070033 uint8_t mDays;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034 switch (month)
35 {
36 case 1:
37 case 3:
38 case 5:
39 case 7:
40 case 8:
41 case 10:
42 case 12:
43 mDays = 31;
44 break;
45
46 case 4:
47 case 6:
48 case 9:
49 case 11:
50 mDays = 30;
51 break;
52
53 case 2:
54 if (_gAfxIsLeapYear(year) == TRUE)
55 mDays = 29;
56 else
57 mDays = 28;
58 break;
59
60 default:
61 mDays = 0;
62 break;
63 }
64
65 return mDays;
66}
67
68CPDFSDK_DateTime::CPDFSDK_DateTime()
69{
70 ResetDateTime();
71}
72
73CPDFSDK_DateTime::CPDFSDK_DateTime(const CFX_ByteString& dtStr)
74{
75 ResetDateTime();
76
77 FromPDFDateTimeString(dtStr);
78}
79
80CPDFSDK_DateTime::CPDFSDK_DateTime(const CPDFSDK_DateTime& datetime)
81{
82 operator = (datetime);
83}
84
85CPDFSDK_DateTime::CPDFSDK_DateTime(const FX_SYSTEMTIME& st)
86{
87 operator = (st) ;
88}
89
90
91void CPDFSDK_DateTime::ResetDateTime()
92{
93 tzset();
94
95 time_t curTime;
96 time(&curTime);
97 struct tm* newtime;
98 //newtime = gmtime(&curTime);
99 newtime = localtime(&curTime);
100
101 dt.year = newtime->tm_year + 1900;
102 dt.month = newtime->tm_mon + 1;
103 dt.day = newtime->tm_mday;
104 dt.hour = newtime->tm_hour;
105 dt.minute = newtime->tm_min;
106 dt.second = newtime->tm_sec;
107// dt.tzHour = _timezone / 3600 * -1;
108// dt.tzMinute = (abs(_timezone) % 3600) / 60;
109}
110
111CPDFSDK_DateTime& CPDFSDK_DateTime::operator = (const CPDFSDK_DateTime& datetime)
112{
113 FXSYS_memcpy(&dt, &datetime.dt, sizeof(FX_DATETIME));
114 return *this;
115}
116
117CPDFSDK_DateTime& CPDFSDK_DateTime::operator = (const FX_SYSTEMTIME& st)
118{
119 tzset();
120
Tom Sepezbfa9a822015-06-09 13:24:12 -0700121 dt.year = (int16_t)st.wYear;
122 dt.month = (uint8_t)st.wMonth;
123 dt.day = (uint8_t)st.wDay;
124 dt.hour = (uint8_t)st.wHour;
125 dt.minute = (uint8_t)st.wMinute;
126 dt.second = (uint8_t)st.wSecond;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700127// dt.tzHour = _timezone / 3600 * -1;
128// dt.tzMinute = (abs(_timezone) % 3600) / 60;
129 return *this;
130}
131
132FX_BOOL CPDFSDK_DateTime::operator == (CPDFSDK_DateTime& datetime)
133{
134 return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) == 0);
135}
136
137FX_BOOL CPDFSDK_DateTime::operator != (CPDFSDK_DateTime& datetime)
138{
139 return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) != 0);
140}
141
142FX_BOOL CPDFSDK_DateTime::operator > (CPDFSDK_DateTime& datetime)
143{
144 CPDFSDK_DateTime dt1 = ToGMT();
145 CPDFSDK_DateTime dt2 = datetime.ToGMT();
146 int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
147 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
148 int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
149 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int)dt2.dt.second;
150
151 if (d1 > d3) return TRUE;
152 if (d2 > d4) return TRUE;
153 return FALSE;
154}
155
156FX_BOOL CPDFSDK_DateTime::operator >= (CPDFSDK_DateTime& datetime)
157{
158 CPDFSDK_DateTime dt1 = ToGMT();
159 CPDFSDK_DateTime dt2 = datetime.ToGMT();
160 int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
161 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
162 int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
163 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int)dt2.dt.second;
164
165 if (d1 >= d3) return TRUE;
166 if (d2 >= d4) return TRUE;
167 return FALSE;
168}
169
170FX_BOOL CPDFSDK_DateTime::operator < (CPDFSDK_DateTime& datetime)
171{
172 CPDFSDK_DateTime dt1 = ToGMT();
173 CPDFSDK_DateTime dt2 = datetime.ToGMT();
174 int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
175 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
176 int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
177 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int)dt2.dt.second;
178
179 if (d1 < d3) return TRUE;
180 if (d2 < d4) return TRUE;
181 return FALSE;
182}
183
184FX_BOOL CPDFSDK_DateTime::operator <= (CPDFSDK_DateTime& datetime)
185{
186 CPDFSDK_DateTime dt1 = ToGMT();
187 CPDFSDK_DateTime dt2 = datetime.ToGMT();
188 int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
189 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
190 int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
191 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int)dt2.dt.second;
192
193 if (d1 <= d3) return TRUE;
194 if (d2 <= d4) return TRUE;
195 return FALSE;
196}
197
198CPDFSDK_DateTime::operator time_t()
199{
200 struct tm newtime;
201
202 newtime.tm_year = dt.year - 1900;
203 newtime.tm_mon = dt.month - 1;
204 newtime.tm_mday = dt.day;
205 newtime.tm_hour = dt.hour;
206 newtime.tm_min = dt.minute;
207 newtime.tm_sec = dt.second;
208
209 return mktime(&newtime);
210}
211
212CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(const CFX_ByteString& dtStr)
213{
214 int strLength = dtStr.GetLength();
215 if (strLength > 0)
216 {
217 int i = 0;
218 int j, k;
219 FX_CHAR ch;
220 while (i < strLength)
221 {
222 ch = dtStr[i];
223 if (ch >= '0' && ch <= '9') break;
224 i ++;
225 }
226 if (i >= strLength) return *this;
227
228 j = 0;
229 k = 0;
230 while (i < strLength && j < 4)
231 {
232 ch = dtStr[i];
233 k = k * 10 + ch - '0';
234 j ++;
235 if (ch < '0' || ch > '9') break;
236 i ++;
237 }
Tom Sepezbfa9a822015-06-09 13:24:12 -0700238 dt.year = (int16_t)k;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239 if (i >= strLength || j < 4) return *this;
240
241 j = 0;
242 k = 0;
243 while (i < strLength && j < 2)
244 {
245 ch = dtStr[i];
246 k = k * 10 + ch - '0';
247 j ++;
248 if (ch < '0' || ch > '9') break;
249 i ++;
250 }
Tom Sepezbfa9a822015-06-09 13:24:12 -0700251 dt.month = (uint8_t)k;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700252 if (i >= strLength || j < 2) return *this;
253
254 j = 0;
255 k = 0;
256 while (i < strLength && j < 2)
257 {
258 ch = dtStr[i];
259 k = k * 10 + ch - '0';
260 j ++;
261 if (ch < '0' || ch > '9') break;
262 i ++;
263 }
Tom Sepezbfa9a822015-06-09 13:24:12 -0700264 dt.day = (uint8_t)k;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700265 if (i >= strLength || j < 2) return *this;
266
267 j = 0;
268 k = 0;
269 while (i < strLength && j < 2)
270 {
271 ch = dtStr[i];
272 k = k * 10 + ch - '0';
273 j ++;
274 if (ch < '0' || ch > '9') break;
275 i ++;
276 }
Tom Sepezbfa9a822015-06-09 13:24:12 -0700277 dt.hour = (uint8_t)k;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700278 if (i >= strLength || j < 2) return *this;
279
280 j = 0;
281 k = 0;
282 while (i < strLength && j < 2)
283 {
284 ch = dtStr[i];
285 k = k * 10 + ch - '0';
286 j ++;
287 if (ch < '0' || ch > '9') break;
288 i ++;
289 }
Tom Sepezbfa9a822015-06-09 13:24:12 -0700290 dt.minute = (uint8_t)k;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700291 if (i >= strLength || j < 2) return *this;
292
293 j = 0;
294 k = 0;
295 while (i < strLength && j < 2)
296 {
297 ch = dtStr[i];
298 k = k * 10 + ch - '0';
299 j ++;
300 if (ch < '0' || ch > '9') break;
301 i ++;
302 }
Tom Sepezbfa9a822015-06-09 13:24:12 -0700303 dt.second = (uint8_t)k;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700304 if (i >= strLength || j < 2) return *this;
305
306 ch = dtStr[i ++];
307 if (ch != '-' && ch != '+') return *this;
308 if (ch == '-')
309 dt.tzHour = -1;
310 else
311 dt.tzHour = 1;
312 j = 0;
313 k = 0;
314 while (i < strLength && j < 2)
315 {
316 ch = dtStr[i];
317 k = k * 10 + ch - '0';
318 j ++;
319 if (ch < '0' || ch > '9') break;
320 i ++;
321 }
322 dt.tzHour *= (FX_CHAR)k;
323 if (i >= strLength || j < 2) return *this;
324
325 ch = dtStr[i ++];
326 if (ch != '\'') return *this;
327 j = 0;
328 k = 0;
329 while (i < strLength && j < 2)
330 {
331 ch = dtStr[i];
332 k = k * 10 + ch - '0';
333 j ++;
334 if (ch < '0' || ch > '9') break;
335 i ++;
336 }
Tom Sepezbfa9a822015-06-09 13:24:12 -0700337 dt.tzMinute = (uint8_t)k;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700338 if (i >= strLength || j < 2) return *this;
339 }
340
341 return *this;
342}
343
344CFX_ByteString CPDFSDK_DateTime::ToCommonDateTimeString()
345{
346 CFX_ByteString str1;
347 str1.Format("%04d-%02d-%02d %02d:%02d:%02d ", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
348 if (dt.tzHour < 0)
349 str1 += "-";
350 else
351 str1 += "+";
352 CFX_ByteString str2;
353 str2.Format("%02d:%02d", abs(dt.tzHour), dt.tzMinute);
354 return str1 + str2;
355}
356
357CFX_ByteString CPDFSDK_DateTime::ToPDFDateTimeString()
358{
359 CFX_ByteString dtStr;
360 char tempStr[32];
Tom Sepez2080b3e2015-03-11 14:25:05 -0700361 memset(tempStr, 0, sizeof(tempStr));
362 FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "D:%04d%02d%02d%02d%02d%02d",
363 dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700364 dtStr = CFX_ByteString(tempStr);
365 if (dt.tzHour < 0)
366 dtStr += CFX_ByteString("-");
367 else
368 dtStr += CFX_ByteString("+");
Tom Sepez2080b3e2015-03-11 14:25:05 -0700369 memset(tempStr, 0, sizeof(tempStr));
370 FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "%02d'%02d'", abs(dt.tzHour), dt.tzMinute);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700371 dtStr += CFX_ByteString(tempStr);
372 return dtStr;
373}
374
375void CPDFSDK_DateTime::ToSystemTime(FX_SYSTEMTIME& st)
376{
377 CPDFSDK_DateTime dt = *this;
378 time_t t = (time_t)dt;
379 struct tm* pTime = localtime(&t);
380 if(pTime){
381 st.wYear = (FX_WORD)pTime->tm_year + 1900;
382 st.wMonth = (FX_WORD)pTime->tm_mon + 1;
383 st.wDay = (FX_WORD)pTime->tm_mday;
384 st.wDayOfWeek = (FX_WORD)pTime->tm_wday;
385 st.wHour = (FX_WORD)pTime->tm_hour;
386 st.wMinute = (FX_WORD)pTime->tm_min;
387 st.wSecond = (FX_WORD)pTime->tm_sec;
388 st.wMilliseconds = 0;
389 }
390}
391
392CPDFSDK_DateTime CPDFSDK_DateTime::ToGMT()
393{
394 CPDFSDK_DateTime dt = *this;
395 dt.AddSeconds(-_gAfxGetTimeZoneInSeconds(dt.dt.tzHour, dt.dt.tzMinute));
396 dt.dt.tzHour = 0;
397 dt.dt.tzMinute = 0;
398 return dt;
399}
400
401CPDFSDK_DateTime& CPDFSDK_DateTime::AddDays(short days)
402{
403 if (days == 0) return *this;
404
Tom Sepezbfa9a822015-06-09 13:24:12 -0700405 int16_t y = dt.year, yy;
406 uint8_t m = dt.month;
407 uint8_t d = dt.day;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700408 int mdays, ydays, ldays;
409
410 ldays = days;
411 if (ldays > 0)
412 {
413 yy = y;
414 if (((FX_WORD)m * 100 + d) > 300) yy ++;
415 ydays = _gAfxGetYearDays(yy);
416 while (ldays >= ydays)
417 {
418 y ++;
419 ldays -= ydays;
420 yy ++;
421 mdays = _gAfxGetMonthDays(y, m);
422 if (d > mdays)
423 {
424 m ++;
425 d -= mdays;
426 }
427 ydays = _gAfxGetYearDays(yy);
428 }
429 mdays = _gAfxGetMonthDays(y, m) - d + 1;
430 while (ldays >= mdays)
431 {
432 ldays -= mdays;
433 m ++;
434 d = 1;
435 mdays = _gAfxGetMonthDays(y, m);
436 }
437 d += ldays;
438 }
439 else
440 {
441 ldays *= -1;
442 yy = y;
443 if (((FX_WORD)m * 100 + d) < 300) yy --;
444 ydays = _gAfxGetYearDays(yy);
445 while (ldays >= ydays)
446 {
447 y --;
448 ldays -= ydays;
449 yy --;
450 mdays = _gAfxGetMonthDays(y, m);
451 if (d > mdays)
452 {
453 m ++;
454 d -= mdays;
455 }
456 ydays = _gAfxGetYearDays(yy);
457 }
458 while (ldays >= d)
459 {
460 ldays -= d;
461 m --;
462 mdays = _gAfxGetMonthDays(y, m);
463 d = mdays;
464 }
465 d -= ldays;
466 }
467
468 dt.year = y;
469 dt.month = m;
470 dt.day = d;
471
472 return *this;
473}
474
475CPDFSDK_DateTime& CPDFSDK_DateTime::AddSeconds(int seconds)
476{
477 if (seconds == 0) return *this;
478
479 int n;
480 int days;
481
482 n = dt.hour * 3600 + dt.minute * 60 + dt.second + seconds;
483 if (n < 0)
484 {
485 days = (n - 86399) / 86400;
486 n -= days * 86400;
487 }
488 else
489 {
490 days = n / 86400;
491 n %= 86400;
492 }
Tom Sepezbfa9a822015-06-09 13:24:12 -0700493 dt.hour = (uint8_t)(n / 3600);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700494 dt.hour %= 24;
495 n %= 3600;
Tom Sepezbfa9a822015-06-09 13:24:12 -0700496 dt.minute = (uint8_t)(n / 60);
497 dt.second = (uint8_t)(n % 60);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700498 if (days != 0) AddDays(days);
499
500 return *this;
501}
502
503
504//---------------------------------------------------------------------------
505// CPDFSDK_Annot
506//---------------------------------------------------------------------------
Bo Xufdc00a72014-10-28 23:03:33 -0700507CPDFSDK_Annot::CPDFSDK_Annot(CPDFSDK_PageView* pPageView) :
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700508m_pPageView(pPageView),
509m_bSelected(FALSE),
510m_nTabOrder(-1)
511{
512}
513
Bo Xufdc00a72014-10-28 23:03:33 -0700514
515//CPDFSDK_BAAnnot
516CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView) :
517 CPDFSDK_Annot(pPageView),
518 m_pAnnot(pAnnot)
519{
520
521}
522
523CPDFSDK_BAAnnot::~CPDFSDK_BAAnnot()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700524{
525 m_pAnnot = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700526}
527
Bo Xufdc00a72014-10-28 23:03:33 -0700528CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700529{
530 return m_pAnnot;
531}
532
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700533FX_BOOL CPDFSDK_Annot::IsSelected()
534{
535 return m_bSelected;
536}
537
538void CPDFSDK_Annot::SetSelected(FX_BOOL bSelected)
539{
540 m_bSelected = bSelected;
541}
542
543// Tab Order
544int CPDFSDK_Annot::GetTabOrder()
545{
546 return m_nTabOrder;
547}
548
549void CPDFSDK_Annot::SetTabOrder(int iTabOrder)
550{
551 m_nTabOrder = iTabOrder;
552}
553
Bo Xufdc00a72014-10-28 23:03:33 -0700554CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700555{
556 ASSERT(m_pAnnot != NULL);
557
Lei Zhang64adf192015-06-05 15:50:32 -0700558 return m_pAnnot->GetAnnotDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700559}
560
Bo Xufdc00a72014-10-28 23:03:33 -0700561void CPDFSDK_BAAnnot::SetRect(const CPDF_Rect& rect)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700562{
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700563 ASSERT(rect.right - rect.left >= GetMinWidth());
564 ASSERT(rect.top - rect.bottom >= GetMinHeight());
565
Lei Zhang64adf192015-06-05 15:50:32 -0700566 m_pAnnot->GetAnnotDict()->SetAtRect("Rect", rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700567}
568
Bo Xufdc00a72014-10-28 23:03:33 -0700569CPDF_Rect CPDFSDK_BAAnnot::GetRect() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700570{
571 ASSERT(m_pAnnot != NULL);
572
573 CPDF_Rect rect;
574 m_pAnnot->GetRect(rect);
575
576 return rect;
577}
578
Bo Xufdc00a72014-10-28 23:03:33 -0700579CFX_ByteString CPDFSDK_BAAnnot::GetType() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700580{
581 ASSERT(m_pAnnot != NULL);
582
583 return m_pAnnot->GetSubType();
584}
585
Bo Xufdc00a72014-10-28 23:03:33 -0700586CFX_ByteString CPDFSDK_BAAnnot::GetSubType() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700587{
588 return "";
589}
590
Bo Xufdc00a72014-10-28 23:03:33 -0700591void CPDFSDK_BAAnnot::ResetAppearance()
592{
593 ASSERT(FALSE);
594}
595
596void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700597 CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions)
598{
599 ASSERT(m_pPageView != NULL);
600 ASSERT(m_pAnnot != NULL);
601
602 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, mode, pOptions);
603}
604
Bo Xufdc00a72014-10-28 23:03:33 -0700605FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700606{
Lei Zhang64adf192015-06-05 15:50:32 -0700607 return m_pAnnot->GetAnnotDict()->GetDict("AP") != NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700608}
609
Bo Xufdc00a72014-10-28 23:03:33 -0700610FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700611{
Lei Zhang64adf192015-06-05 15:50:32 -0700612 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700613 if (pAP == NULL) return FALSE;
614
615 // Choose the right sub-ap
616 const FX_CHAR* ap_entry = "N";
617 if (mode == CPDF_Annot::Down)
618 ap_entry = "D";
619 else if (mode == CPDF_Annot::Rollover)
620 ap_entry = "R";
621 if (!pAP->KeyExist(ap_entry))
622 ap_entry = "N";
623
624 // Get the AP stream or subdirectory
625 CPDF_Object* psub = pAP->GetElementValue(ap_entry);
626 if (psub == NULL) return FALSE;
627
628 return TRUE;
629}
630
Bo Xufdc00a72014-10-28 23:03:33 -0700631void CPDFSDK_BAAnnot::DrawBorder(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700632 const CPDF_RenderOptions* pOptions)
633{
634 ASSERT(m_pAnnot != NULL);
635 m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions);
636}
637
Bo Xufdc00a72014-10-28 23:03:33 -0700638void CPDFSDK_BAAnnot::ClearCachedAP()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700639{
640 ASSERT(m_pAnnot != NULL);
641 m_pAnnot->ClearCachedAP();
642}
643
Bo Xufdc00a72014-10-28 23:03:33 -0700644void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700645{
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700646 if (sContents.IsEmpty())
Lei Zhang64adf192015-06-05 15:50:32 -0700647 m_pAnnot->GetAnnotDict()->RemoveAt("Contents");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700648 else
Lei Zhang64adf192015-06-05 15:50:32 -0700649 m_pAnnot->GetAnnotDict()->SetAtString("Contents", PDF_EncodeText(sContents));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700650}
651
Bo Xufdc00a72014-10-28 23:03:33 -0700652CFX_WideString CPDFSDK_BAAnnot::GetContents() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700653{
Lei Zhang64adf192015-06-05 15:50:32 -0700654 return m_pAnnot->GetAnnotDict()->GetUnicodeText("Contents");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700655}
656
Bo Xufdc00a72014-10-28 23:03:33 -0700657void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700658{
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700659 if (sName.IsEmpty())
Lei Zhang64adf192015-06-05 15:50:32 -0700660 m_pAnnot->GetAnnotDict()->RemoveAt("NM");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700661 else
Lei Zhang64adf192015-06-05 15:50:32 -0700662 m_pAnnot->GetAnnotDict()->SetAtString("NM", PDF_EncodeText(sName));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700663}
664
Bo Xufdc00a72014-10-28 23:03:33 -0700665CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700666{
Lei Zhang64adf192015-06-05 15:50:32 -0700667 return m_pAnnot->GetAnnotDict()->GetUnicodeText("NM");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700668}
669
Bo Xufdc00a72014-10-28 23:03:33 -0700670void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700671{
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700672 CPDFSDK_DateTime dt(st);
673 CFX_ByteString str = dt.ToPDFDateTimeString();
674
675 if (str.IsEmpty())
Lei Zhang64adf192015-06-05 15:50:32 -0700676 m_pAnnot->GetAnnotDict()->RemoveAt("M");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700677 else
Lei Zhang64adf192015-06-05 15:50:32 -0700678 m_pAnnot->GetAnnotDict()->SetAtString("M", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700679}
680
Bo Xufdc00a72014-10-28 23:03:33 -0700681FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700682{
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700683 FX_SYSTEMTIME systime;
Lei Zhang64adf192015-06-05 15:50:32 -0700684 CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetString("M");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700685
686 CPDFSDK_DateTime dt(str);
687 dt.ToSystemTime(systime);
688
689 return systime;
690}
691
Bo Xufdc00a72014-10-28 23:03:33 -0700692void CPDFSDK_BAAnnot::SetFlags(int nFlags)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700693{
Lei Zhang64adf192015-06-05 15:50:32 -0700694 m_pAnnot->GetAnnotDict()->SetAtInteger("F", nFlags);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700695}
696
Bo Xufdc00a72014-10-28 23:03:33 -0700697int CPDFSDK_BAAnnot::GetFlags() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700698{
Lei Zhang64adf192015-06-05 15:50:32 -0700699 return m_pAnnot->GetAnnotDict()->GetInteger("F");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700700}
701
Bo Xufdc00a72014-10-28 23:03:33 -0700702void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700703{
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700704 if (str.IsEmpty())
Lei Zhang64adf192015-06-05 15:50:32 -0700705 m_pAnnot->GetAnnotDict()->RemoveAt("AS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700706 else
Lei Zhang64adf192015-06-05 15:50:32 -0700707 m_pAnnot->GetAnnotDict()->SetAtString("AS", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700708}
709
Bo Xufdc00a72014-10-28 23:03:33 -0700710CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700711{
Lei Zhang64adf192015-06-05 15:50:32 -0700712 return m_pAnnot->GetAnnotDict()->GetString("AS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700713}
714
Bo Xufdc00a72014-10-28 23:03:33 -0700715void CPDFSDK_BAAnnot::SetStructParent(int key)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700716{
Lei Zhang64adf192015-06-05 15:50:32 -0700717 m_pAnnot->GetAnnotDict()->SetAtInteger("StructParent", key);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700718}
719
Bo Xufdc00a72014-10-28 23:03:33 -0700720int CPDFSDK_BAAnnot::GetStructParent() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700721{
Lei Zhang64adf192015-06-05 15:50:32 -0700722 return m_pAnnot->GetAnnotDict()->GetInteger("StructParent");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700723}
724
725//border
Bo Xufdc00a72014-10-28 23:03:33 -0700726void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700727{
Lei Zhang64adf192015-06-05 15:50:32 -0700728 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700729
730 if (pBorder)
731 {
732 pBorder->SetAt(2, FX_NEW CPDF_Number(nWidth));
733 }
734 else
735 {
Lei Zhang64adf192015-06-05 15:50:32 -0700736 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700737
738 if (!pBSDict)
739 {
740 pBSDict = FX_NEW CPDF_Dictionary;
Lei Zhang64adf192015-06-05 15:50:32 -0700741 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700742 }
743
744 pBSDict->SetAtInteger("W", nWidth);
745 }
746}
747
Bo Xufdc00a72014-10-28 23:03:33 -0700748int CPDFSDK_BAAnnot::GetBorderWidth() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700749{
Lei Zhang64adf192015-06-05 15:50:32 -0700750 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700751
752 if (pBorder)
753 {
754 return pBorder->GetInteger(2);
755 }
756 else
757 {
Lei Zhang64adf192015-06-05 15:50:32 -0700758 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700759
760 if (pBSDict)
761 {
762 return pBSDict->GetInteger("W", 1);
763 }
764 }
765 return 1;
766}
767
Bo Xufdc00a72014-10-28 23:03:33 -0700768void CPDFSDK_BAAnnot::SetBorderStyle(int nStyle)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700769{
Lei Zhang64adf192015-06-05 15:50:32 -0700770 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700771 if (!pBSDict)
772 {
Lei Zhang64adf192015-06-05 15:50:32 -0700773 pBSDict = new CPDF_Dictionary;
774 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700775 }
776
777 switch (nStyle)
778 {
779 case BBS_SOLID:
780 pBSDict->SetAtName("S", "S");
781 break;
782 case BBS_DASH:
783 pBSDict->SetAtName("S", "D");
784 break;
785 case BBS_BEVELED:
786 pBSDict->SetAtName("S", "B");
787 break;
788 case BBS_INSET:
789 pBSDict->SetAtName("S", "I");
790 break;
791 case BBS_UNDERLINE:
792 pBSDict->SetAtName("S", "U");
793 break;
794 }
795}
796
Bo Xufdc00a72014-10-28 23:03:33 -0700797int CPDFSDK_BAAnnot::GetBorderStyle() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700798{
Lei Zhang64adf192015-06-05 15:50:32 -0700799 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700800 if (pBSDict)
801 {
802 CFX_ByteString sBorderStyle = pBSDict->GetString("S", "S");
803 if (sBorderStyle == "S") return BBS_SOLID;
804 if (sBorderStyle == "D") return BBS_DASH;
805 if (sBorderStyle == "B") return BBS_BEVELED;
806 if (sBorderStyle == "I") return BBS_INSET;
807 if (sBorderStyle == "U") return BBS_UNDERLINE;
808 }
809
Lei Zhang64adf192015-06-05 15:50:32 -0700810 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700811 if (pBorder)
812 {
813 if (pBorder->GetCount() >= 4)
814 {
815 CPDF_Array *pDP = pBorder->GetArray(3);
816 if (pDP && pDP->GetCount() > 0)
817 return BBS_DASH;
818 }
819 }
820
821 return BBS_SOLID;
822}
823
Bo Xufdc00a72014-10-28 23:03:33 -0700824void CPDFSDK_BAAnnot::SetBorderDash(const CFX_IntArray& array)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700825{
Lei Zhang64adf192015-06-05 15:50:32 -0700826 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700827 if (!pBSDict)
828 {
Lei Zhang64adf192015-06-05 15:50:32 -0700829 pBSDict = new CPDF_Dictionary;
830 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700831 }
832
833 CPDF_Array* pArray = FX_NEW CPDF_Array;
834 for (int i=0,sz=array.GetSize(); i<sz; i++)
835 {
836 pArray->AddInteger(array[i]);
837 }
838
839 pBSDict->SetAt("D", pArray);
840}
841
Bo Xufdc00a72014-10-28 23:03:33 -0700842void CPDFSDK_BAAnnot::GetBorderDash(CFX_IntArray& array) const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700843{
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700844 CPDF_Array* pDash = NULL;
845
Lei Zhang64adf192015-06-05 15:50:32 -0700846 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700847 if (pBorder)
848 {
849 pDash = pBorder->GetArray(3);
850 }
851 else
852 {
Lei Zhang64adf192015-06-05 15:50:32 -0700853 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700854 if (pBSDict)
855 {
856 pDash = pBSDict->GetArray("D");
857 }
858 }
859
860 if (pDash)
861 {
862 for (int i=0,sz=pDash->GetCount(); i<sz; i++)
863 {
864 array.Add(pDash->GetInteger(i));
865 }
866 }
867}
868
Bo Xufdc00a72014-10-28 23:03:33 -0700869void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700870{
Lei Zhang64adf192015-06-05 15:50:32 -0700871 CPDF_Array* pArray = new CPDF_Array;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700872 pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f);
873 pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f);
874 pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f);
Lei Zhang64adf192015-06-05 15:50:32 -0700875 m_pAnnot->GetAnnotDict()->SetAt("C", pArray);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700876}
877
Bo Xufdc00a72014-10-28 23:03:33 -0700878void CPDFSDK_BAAnnot::RemoveColor()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700879{
Lei Zhang64adf192015-06-05 15:50:32 -0700880 m_pAnnot->GetAnnotDict()->RemoveAt("C");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700881}
882
Bo Xufdc00a72014-10-28 23:03:33 -0700883FX_BOOL CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700884{
Lei Zhang64adf192015-06-05 15:50:32 -0700885 if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArray("C"))
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700886 {
887 int nCount = pEntry->GetCount();
888 if (nCount == 1)
889 {
890 FX_FLOAT g = pEntry->GetNumber(0) * 255;
891
892 color = FXSYS_RGB((int)g, (int)g, (int)g);
893
894 return TRUE;
895 }
896 else if (nCount == 3)
897 {
898 FX_FLOAT r = pEntry->GetNumber(0) * 255;
899 FX_FLOAT g = pEntry->GetNumber(1) * 255;
900 FX_FLOAT b = pEntry->GetNumber(2) * 255;
901
902 color = FXSYS_RGB((int)r, (int)g, (int)b);
903
904 return TRUE;
905 }
906 else if (nCount == 4)
907 {
908 FX_FLOAT c = pEntry->GetNumber(0);
909 FX_FLOAT m = pEntry->GetNumber(1);
910 FX_FLOAT y = pEntry->GetNumber(2);
911 FX_FLOAT k = pEntry->GetNumber(3);
912
913 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
914 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
915 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
916
917 color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255));
918
919 return TRUE;
920 }
921 }
922
923 return FALSE;
924}
925
926
Bo Xufdc00a72014-10-28 23:03:33 -0700927void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, const CPDF_Rect& rcBBox,
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700928 const CPDF_Matrix& matrix, const CFX_ByteString& sContents,
929 const CFX_ByteString& sAPState)
930{
Lei Zhang64adf192015-06-05 15:50:32 -0700931 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700932
933 if (!pAPDict)
934 {
Lei Zhang64adf192015-06-05 15:50:32 -0700935 pAPDict = new CPDF_Dictionary;
936 m_pAnnot->GetAnnotDict()->SetAt("AP", pAPDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700937 }
938
939 CPDF_Stream* pStream = NULL;
940 CPDF_Dictionary* pParentDict = NULL;
941
942 if (sAPState.IsEmpty())
943 {
944 pParentDict = pAPDict;
945 pStream = pAPDict->GetStream(sAPType);
946 }
947 else
948 {
949 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDict(sAPType);
950 if (!pAPTypeDict)
951 {
952 pAPTypeDict = FX_NEW CPDF_Dictionary;
953 pAPDict->SetAt(sAPType, pAPTypeDict);
954 }
955
956 pParentDict = pAPTypeDict;
957 pStream = pAPTypeDict->GetStream(sAPState);
958 }
959
960 if (!pStream)
961 {
962 ASSERT(m_pPageView != NULL);
963 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
964 ASSERT(pDoc != NULL);
Tom Sepezbfa9a822015-06-09 13:24:12 -0700965
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700966 pStream = FX_NEW CPDF_Stream(NULL, 0, NULL);
Tom Sepezbfa9a822015-06-09 13:24:12 -0700967 int32_t objnum = pDoc->AddIndirectObject(pStream);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700968 //pAPDict->SetAtReference(sAPType, pDoc, objnum);
969 ASSERT(pParentDict != NULL);
970 pParentDict->SetAtReference(sAPType, pDoc, objnum);
971 }
Tom Sepezbfa9a822015-06-09 13:24:12 -0700972
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700973 CPDF_Dictionary * pStreamDict = pStream->GetDict();
974
975 if (!pStreamDict)
976 {
977 pStreamDict = FX_NEW CPDF_Dictionary;
978 pStreamDict->SetAtName("Type", "XObject");
979 pStreamDict->SetAtName("Subtype", "Form");
980 pStreamDict->SetAtInteger("FormType", 1);
981 pStream->InitStream(NULL,0,pStreamDict);
982 }
983
984 if (pStreamDict)
985 {
986 pStreamDict->SetAtMatrix("Matrix",matrix);
987 pStreamDict->SetAtRect("BBox", rcBBox);
988 }
989
Tom Sepezbfa9a822015-06-09 13:24:12 -0700990 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength(), FALSE, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700991}
992
993#define BA_ANNOT_MINWIDTH 1
994#define BA_ANNOT_MINHEIGHT 1
995
996FX_FLOAT CPDFSDK_Annot::GetMinWidth() const
997{
998 return BA_ANNOT_MINWIDTH;
999}
1000
1001FX_FLOAT CPDFSDK_Annot::GetMinHeight() const
1002{
1003 return BA_ANNOT_MINHEIGHT;
1004}
1005
Bo Xufdc00a72014-10-28 23:03:33 -07001006FX_BOOL CPDFSDK_BAAnnot::CreateFormFiller()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001007{
1008 return TRUE;
1009}
Bo Xufdc00a72014-10-28 23:03:33 -07001010FX_BOOL CPDFSDK_BAAnnot::IsVisible() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001011{
1012 int nFlags = GetFlags();
1013 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || (nFlags & ANNOTFLAG_NOVIEW));
1014}
1015
Bo Xufdc00a72014-10-28 23:03:33 -07001016CPDF_Action CPDFSDK_BAAnnot::GetAction() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001017{
Lei Zhang64adf192015-06-05 15:50:32 -07001018 return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001019}
1020
Bo Xufdc00a72014-10-28 23:03:33 -07001021void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001022{
Tom Sepez7b5bc262015-03-05 16:44:22 -08001023 ASSERT(action);
Lei Zhang64adf192015-06-05 15:50:32 -07001024 if ((CPDF_Action&)action != CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A")))
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001025 {
1026 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
Tom Sepez7b5bc262015-03-05 16:44:22 -08001027 CPDF_Dictionary* pDict = action.GetDict();
1028 if (pDict && pDict->GetObjNum() == 0) {
1029 pDoc->AddIndirectObject(pDict);
1030 }
Lei Zhang64adf192015-06-05 15:50:32 -07001031 m_pAnnot->GetAnnotDict()->SetAtReference("A", pDoc, pDict->GetObjNum());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001032 }
1033}
1034
Bo Xufdc00a72014-10-28 23:03:33 -07001035void CPDFSDK_BAAnnot::RemoveAction()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001036{
Lei Zhang64adf192015-06-05 15:50:32 -07001037 m_pAnnot->GetAnnotDict()->RemoveAt("A");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001038}
1039
Bo Xufdc00a72014-10-28 23:03:33 -07001040CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001041{
Lei Zhang64adf192015-06-05 15:50:32 -07001042 return m_pAnnot->GetAnnotDict()->GetDict("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001043}
1044
Bo Xufdc00a72014-10-28 23:03:33 -07001045void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001046{
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001047 ASSERT(aa != NULL);
1048
Lei Zhang64adf192015-06-05 15:50:32 -07001049 if ((CPDF_AAction&)aa != m_pAnnot->GetAnnotDict()->GetDict("AA"))
1050 m_pAnnot->GetAnnotDict()->SetAt("AA", (CPDF_AAction&)aa);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001051}
1052
Bo Xufdc00a72014-10-28 23:03:33 -07001053void CPDFSDK_BAAnnot::RemoveAAction()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001054{
Lei Zhang64adf192015-06-05 15:50:32 -07001055 m_pAnnot->GetAnnotDict()->RemoveAt("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001056}
1057
Bo Xufdc00a72014-10-28 23:03:33 -07001058CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001059{
1060 CPDF_AAction AAction = GetAAction();
Tom Sepez7b5bc262015-03-05 16:44:22 -08001061
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001062 if (AAction.ActionExist(eAAT))
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001063 return AAction.GetAction(eAAT);
Tom Sepez7b5bc262015-03-05 16:44:22 -08001064
1065 if (eAAT == CPDF_AAction::ButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001066 return GetAction();
Tom Sepez7b5bc262015-03-05 16:44:22 -08001067
1068 return CPDF_Action();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001069}
1070
Bo Xufdc00a72014-10-28 23:03:33 -07001071FX_BOOL CPDFSDK_BAAnnot::IsXFAField()
1072{
1073 return FALSE;
1074}
1075
1076void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, CPDF_RenderOptions* pOptions)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001077{
1078
1079 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal);
1080 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
1081
1082 return ;
1083}
1084
1085CPDF_Page* CPDFSDK_Annot::GetPDFPage()
1086{
1087 if(m_pPageView)
1088 return m_pPageView->GetPDFPage();
1089 return NULL;
1090}
1091
Bo Xufdc00a72014-10-28 23:03:33 -07001092CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage()
1093{
1094 if (m_pPageView)
1095 return m_pPageView->GetPDFXFAPage();
1096 return NULL;
1097}
1098