OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../include/fsdk_define.h" | 7 #include "../include/fsdk_define.h" |
8 #include "../include/fsdk_mgr.h" | 8 #include "../include/fsdk_mgr.h" |
9 #include "../include/fsdk_baseannot.h" | 9 #include "../include/fsdk_baseannot.h" |
10 | 10 |
11 | |
12 //--------------------------------------------------------------------------- | 11 //--------------------------------------------------------------------------- |
13 //» » » » » » » » CPDFSDK_DateTime
» | 12 //» » » » » » » » CPDFSDK_DateTime |
14 //--------------------------------------------------------------------------- | 13 //--------------------------------------------------------------------------- |
15 int _gAfxGetTimeZoneInSeconds(FX_CHAR tzhour, FX_BYTE tzminute) | 14 int _gAfxGetTimeZoneInSeconds(FX_CHAR tzhour, FX_BYTE tzminute) { |
16 { | 15 return (int)tzhour * 3600 + (int)tzminute * (tzhour >= 0 ? 60 : -60); |
17 return (int)tzhour * 3600 + (int)tzminute * (tzhour >= 0 ? 60 : -60); | 16 } |
18 } | 17 |
19 | 18 FX_BOOL _gAfxIsLeapYear(FX_SHORT year) { |
20 FX_BOOL _gAfxIsLeapYear(FX_SHORT year) | 19 return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))); |
21 { | 20 } |
22 return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))); | 21 |
23 } | 22 FX_WORD _gAfxGetYearDays(FX_SHORT year) { |
24 | 23 return (_gAfxIsLeapYear(year) == TRUE ? 366 : 365); |
25 FX_WORD _gAfxGetYearDays(FX_SHORT year) | 24 } |
26 { | 25 |
27 return (_gAfxIsLeapYear(year) == TRUE ? 366 : 365); | 26 FX_BYTE _gAfxGetMonthDays(FX_SHORT year, FX_BYTE month) { |
28 } | 27 FX_BYTE mDays; |
29 | 28 switch (month) { |
30 FX_BYTE _gAfxGetMonthDays(FX_SHORT year, FX_BYTE month) | 29 case 1: |
31 { | 30 case 3: |
32 FX_BYTE mDays; | 31 case 5: |
33 switch (month) | 32 case 7: |
34 { | 33 case 8: |
35 case 1: | 34 case 10: |
36 case 3: | 35 case 12: |
37 case 5: | 36 mDays = 31; |
38 case 7: | 37 break; |
39 case 8: | 38 |
40 case 10: | 39 case 4: |
41 case 12: | 40 case 6: |
42 mDays = 31; | 41 case 9: |
43 break; | 42 case 11: |
44 | 43 mDays = 30; |
45 case 4: | 44 break; |
46 case 6: | 45 |
47 case 9: | 46 case 2: |
48 case 11: | 47 if (_gAfxIsLeapYear(year) == TRUE) |
49 mDays = 30; | 48 mDays = 29; |
50 break; | 49 else |
51 | 50 mDays = 28; |
52 case 2: | 51 break; |
53 if (_gAfxIsLeapYear(year) == TRUE) | 52 |
54 mDays = 29; | 53 default: |
55 else | 54 mDays = 0; |
56 mDays = 28; | 55 break; |
57 break; | 56 } |
58 | 57 |
59 default: | 58 return mDays; |
60 mDays = 0; | 59 } |
61 break; | 60 |
62 } | 61 CPDFSDK_DateTime::CPDFSDK_DateTime() { |
63 | 62 ResetDateTime(); |
64 return mDays; | 63 } |
65 } | 64 |
66 | 65 CPDFSDK_DateTime::CPDFSDK_DateTime(const CFX_ByteString& dtStr) { |
67 CPDFSDK_DateTime::CPDFSDK_DateTime() | 66 ResetDateTime(); |
68 { | 67 |
69 ResetDateTime(); | 68 FromPDFDateTimeString(dtStr); |
70 } | 69 } |
71 | 70 |
72 CPDFSDK_DateTime::CPDFSDK_DateTime(const CFX_ByteString& dtStr) | 71 CPDFSDK_DateTime::CPDFSDK_DateTime(const CPDFSDK_DateTime& datetime) { |
73 { | 72 operator=(datetime); |
74 ResetDateTime(); | 73 } |
75 | 74 |
76 FromPDFDateTimeString(dtStr); | 75 CPDFSDK_DateTime::CPDFSDK_DateTime(const FX_SYSTEMTIME& st) { |
77 } | 76 operator=(st); |
78 | 77 } |
79 CPDFSDK_DateTime::CPDFSDK_DateTime(const CPDFSDK_DateTime& datetime) | 78 |
80 { | 79 void CPDFSDK_DateTime::ResetDateTime() { |
81 operator = (datetime); | 80 tzset(); |
82 } | 81 |
83 | 82 time_t curTime; |
84 CPDFSDK_DateTime::CPDFSDK_DateTime(const FX_SYSTEMTIME& st) | 83 time(&curTime); |
85 { | 84 struct tm* newtime; |
86 operator = (st) ; | 85 // newtime = gmtime(&curTime); |
87 } | 86 newtime = localtime(&curTime); |
88 | 87 |
89 | 88 dt.year = newtime->tm_year + 1900; |
90 void CPDFSDK_DateTime::ResetDateTime() | 89 dt.month = newtime->tm_mon + 1; |
91 { | 90 dt.day = newtime->tm_mday; |
92 tzset(); | 91 dt.hour = newtime->tm_hour; |
93 | 92 dt.minute = newtime->tm_min; |
94 time_t curTime; | 93 dt.second = newtime->tm_sec; |
95 time(&curTime); | 94 // dt.tzHour = _timezone / 3600 * -1; |
96 struct tm* newtime; | 95 // dt.tzMinute = (abs(_timezone) % 3600) / 60; |
97 //newtime = gmtime(&curTime); | 96 } |
98 newtime = localtime(&curTime); | 97 |
99 | 98 CPDFSDK_DateTime& CPDFSDK_DateTime::operator=( |
100 dt.year = newtime->tm_year + 1900; | 99 const CPDFSDK_DateTime& datetime) { |
101 dt.month = newtime->tm_mon + 1; | 100 FXSYS_memcpy(&dt, &datetime.dt, sizeof(FX_DATETIME)); |
102 dt.day = newtime->tm_mday; | 101 return *this; |
103 dt.hour = newtime->tm_hour; | 102 } |
104 dt.minute = newtime->tm_min; | 103 |
105 dt.second = newtime->tm_sec; | 104 CPDFSDK_DateTime& CPDFSDK_DateTime::operator=(const FX_SYSTEMTIME& st) { |
106 // dt.tzHour = _timezone / 3600 * -1; | 105 tzset(); |
107 // dt.tzMinute = (abs(_timezone) % 3600) / 60; | 106 |
108 } | 107 dt.year = (FX_SHORT)st.wYear; |
109 | 108 dt.month = (FX_BYTE)st.wMonth; |
110 CPDFSDK_DateTime& CPDFSDK_DateTime::operator = (const CPDFSDK_DateTime& datetime
) | 109 dt.day = (FX_BYTE)st.wDay; |
111 { | 110 dt.hour = (FX_BYTE)st.wHour; |
112 FXSYS_memcpy(&dt, &datetime.dt, sizeof(FX_DATETIME)); | 111 dt.minute = (FX_BYTE)st.wMinute; |
113 return *this; | 112 dt.second = (FX_BYTE)st.wSecond; |
114 } | 113 // dt.tzHour = _timezone / 3600 * -1; |
115 | 114 // dt.tzMinute = (abs(_timezone) % 3600) / 60; |
116 CPDFSDK_DateTime& CPDFSDK_DateTime::operator = (const FX_SYSTEMTIME& st) | 115 return *this; |
117 { | 116 } |
118 tzset(); | 117 |
119 | 118 FX_BOOL CPDFSDK_DateTime::operator==(CPDFSDK_DateTime& datetime) { |
120 dt.year = (FX_SHORT)st.wYear; | 119 return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) == 0); |
121 dt.month = (FX_BYTE)st.wMonth; | 120 } |
122 dt.day = (FX_BYTE)st.wDay; | 121 |
123 dt.hour = (FX_BYTE)st.wHour; | 122 FX_BOOL CPDFSDK_DateTime::operator!=(CPDFSDK_DateTime& datetime) { |
124 dt.minute = (FX_BYTE)st.wMinute; | 123 return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) != 0); |
125 dt.second = (FX_BYTE)st.wSecond; | 124 } |
126 // dt.tzHour = _timezone / 3600 * -1; | 125 |
127 // dt.tzMinute = (abs(_timezone) % 3600) / 60; | 126 FX_BOOL CPDFSDK_DateTime::operator>(CPDFSDK_DateTime& datetime) { |
128 return *this; | 127 CPDFSDK_DateTime dt1 = ToGMT(); |
129 } | 128 CPDFSDK_DateTime dt2 = datetime.ToGMT(); |
130 | 129 int d1 = |
131 FX_BOOL CPDFSDK_DateTime::operator == (CPDFSDK_DateTime& datetime) | 130 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day; |
132 { | 131 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | |
133 return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) == 0); | 132 (int)dt1.dt.second; |
134 } | 133 int d3 = |
135 | 134 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day; |
136 FX_BOOL CPDFSDK_DateTime::operator != (CPDFSDK_DateTime& datetime) | 135 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | |
137 { | 136 (int)dt2.dt.second; |
138 return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) != 0); | 137 |
139 } | 138 if (d1 > d3) |
140 | 139 return TRUE; |
141 FX_BOOL CPDFSDK_DateTime::operator > (CPDFSDK_DateTime& datetime) | 140 if (d2 > d4) |
142 { | 141 return TRUE; |
143 CPDFSDK_DateTime dt1 = ToGMT(); | 142 return FALSE; |
144 CPDFSDK_DateTime dt2 = datetime.ToGMT(); | 143 } |
145 int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)
dt1.dt.day; | 144 |
146 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int
)dt1.dt.second; | 145 FX_BOOL CPDFSDK_DateTime::operator>=(CPDFSDK_DateTime& datetime) { |
147 int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)
dt2.dt.day; | 146 CPDFSDK_DateTime dt1 = ToGMT(); |
148 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int
)dt2.dt.second; | 147 CPDFSDK_DateTime dt2 = datetime.ToGMT(); |
149 | 148 int d1 = |
150 if (d1 > d3) return TRUE; | 149 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day; |
151 if (d2 > d4) return TRUE; | 150 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | |
152 return FALSE; | 151 (int)dt1.dt.second; |
153 } | 152 int d3 = |
154 | 153 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day; |
155 FX_BOOL CPDFSDK_DateTime::operator >= (CPDFSDK_DateTime& datetime) | 154 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | |
156 { | 155 (int)dt2.dt.second; |
157 CPDFSDK_DateTime dt1 = ToGMT(); | 156 |
158 CPDFSDK_DateTime dt2 = datetime.ToGMT(); | 157 if (d1 >= d3) |
159 int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)
dt1.dt.day; | 158 return TRUE; |
160 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int
)dt1.dt.second; | 159 if (d2 >= d4) |
161 int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)
dt2.dt.day; | 160 return TRUE; |
162 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int
)dt2.dt.second; | 161 return FALSE; |
163 | 162 } |
164 if (d1 >= d3) return TRUE; | 163 |
165 if (d2 >= d4) return TRUE; | 164 FX_BOOL CPDFSDK_DateTime::operator<(CPDFSDK_DateTime& datetime) { |
166 return FALSE; | 165 CPDFSDK_DateTime dt1 = ToGMT(); |
167 } | 166 CPDFSDK_DateTime dt2 = datetime.ToGMT(); |
168 | 167 int d1 = |
169 FX_BOOL CPDFSDK_DateTime::operator < (CPDFSDK_DateTime& datetime) | 168 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day; |
170 { | 169 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | |
171 CPDFSDK_DateTime dt1 = ToGMT(); | 170 (int)dt1.dt.second; |
172 CPDFSDK_DateTime dt2 = datetime.ToGMT(); | 171 int d3 = |
173 int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)
dt1.dt.day; | 172 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day; |
174 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int
)dt1.dt.second; | 173 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | |
175 int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)
dt2.dt.day; | 174 (int)dt2.dt.second; |
176 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int
)dt2.dt.second; | 175 |
177 | 176 if (d1 < d3) |
178 if (d1 < d3) return TRUE; | 177 return TRUE; |
179 if (d2 < d4) return TRUE; | 178 if (d2 < d4) |
180 return FALSE; | 179 return TRUE; |
181 } | 180 return FALSE; |
182 | 181 } |
183 FX_BOOL CPDFSDK_DateTime::operator <= (CPDFSDK_DateTime& datetime) | 182 |
184 { | 183 FX_BOOL CPDFSDK_DateTime::operator<=(CPDFSDK_DateTime& datetime) { |
185 CPDFSDK_DateTime dt1 = ToGMT(); | 184 CPDFSDK_DateTime dt1 = ToGMT(); |
186 CPDFSDK_DateTime dt2 = datetime.ToGMT(); | 185 CPDFSDK_DateTime dt2 = datetime.ToGMT(); |
187 int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)
dt1.dt.day; | 186 int d1 = |
188 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int
)dt1.dt.second; | 187 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day; |
189 int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)
dt2.dt.day; | 188 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | |
190 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int
)dt2.dt.second; | 189 (int)dt1.dt.second; |
191 | 190 int d3 = |
192 if (d1 <= d3) return TRUE; | 191 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day; |
193 if (d2 <= d4) return TRUE; | 192 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | |
194 return FALSE; | 193 (int)dt2.dt.second; |
195 } | 194 |
196 | 195 if (d1 <= d3) |
197 CPDFSDK_DateTime::operator time_t() | 196 return TRUE; |
198 { | 197 if (d2 <= d4) |
199 struct tm newtime; | 198 return TRUE; |
200 | 199 return FALSE; |
201 newtime.tm_year = dt.year - 1900; | 200 } |
202 newtime.tm_mon = dt.month - 1; | 201 |
203 newtime.tm_mday = dt.day; | 202 CPDFSDK_DateTime::operator time_t() { |
204 newtime.tm_hour = dt.hour; | 203 struct tm newtime; |
205 newtime.tm_min = dt.minute; | 204 |
206 newtime.tm_sec = dt.second; | 205 newtime.tm_year = dt.year - 1900; |
207 | 206 newtime.tm_mon = dt.month - 1; |
208 return mktime(&newtime); | 207 newtime.tm_mday = dt.day; |
209 } | 208 newtime.tm_hour = dt.hour; |
210 | 209 newtime.tm_min = dt.minute; |
211 CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(const CFX_ByteString&
dtStr) | 210 newtime.tm_sec = dt.second; |
212 { | 211 |
213 int strLength = dtStr.GetLength(); | 212 return mktime(&newtime); |
214 if (strLength > 0) | 213 } |
215 { | 214 |
216 int i = 0; | 215 CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString( |
217 int j, k; | 216 const CFX_ByteString& dtStr) { |
218 FX_CHAR ch; | 217 int strLength = dtStr.GetLength(); |
219 while (i < strLength) | 218 if (strLength > 0) { |
220 { | 219 int i = 0; |
221 ch = dtStr[i]; | 220 int j, k; |
222 if (ch >= '0' && ch <= '9') break; | 221 FX_CHAR ch; |
223 i ++; | 222 while (i < strLength) { |
224 } | 223 ch = dtStr[i]; |
225 if (i >= strLength) return *this; | 224 if (ch >= '0' && ch <= '9') |
226 | 225 break; |
227 j = 0; | 226 i++; |
228 k = 0; | 227 } |
229 while (i < strLength && j < 4) | 228 if (i >= strLength) |
230 { | 229 return *this; |
231 ch = dtStr[i]; | 230 |
232 k = k * 10 + ch - '0'; | 231 j = 0; |
233 j ++; | 232 k = 0; |
234 if (ch < '0' || ch > '9') break; | 233 while (i < strLength && j < 4) { |
235 i ++; | 234 ch = dtStr[i]; |
236 } | 235 k = k * 10 + ch - '0'; |
237 dt.year = (FX_SHORT)k; | 236 j++; |
238 if (i >= strLength || j < 4) return *this; | 237 if (ch < '0' || ch > '9') |
239 | 238 break; |
240 j = 0; | 239 i++; |
241 k = 0; | 240 } |
242 while (i < strLength && j < 2) | 241 dt.year = (FX_SHORT)k; |
243 { | 242 if (i >= strLength || j < 4) |
244 ch = dtStr[i]; | 243 return *this; |
245 k = k * 10 + ch - '0'; | 244 |
246 j ++; | 245 j = 0; |
247 if (ch < '0' || ch > '9') break; | 246 k = 0; |
248 i ++; | 247 while (i < strLength && j < 2) { |
249 } | 248 ch = dtStr[i]; |
250 dt.month = (FX_BYTE)k; | 249 k = k * 10 + ch - '0'; |
251 if (i >= strLength || j < 2) return *this; | 250 j++; |
252 | 251 if (ch < '0' || ch > '9') |
253 j = 0; | 252 break; |
254 k = 0; | 253 i++; |
255 while (i < strLength && j < 2) | 254 } |
256 { | 255 dt.month = (FX_BYTE)k; |
257 ch = dtStr[i]; | 256 if (i >= strLength || j < 2) |
258 k = k * 10 + ch - '0'; | 257 return *this; |
259 j ++; | 258 |
260 if (ch < '0' || ch > '9') break; | 259 j = 0; |
261 i ++; | 260 k = 0; |
262 } | 261 while (i < strLength && j < 2) { |
263 dt.day = (FX_BYTE)k; | 262 ch = dtStr[i]; |
264 if (i >= strLength || j < 2) return *this; | 263 k = k * 10 + ch - '0'; |
265 | 264 j++; |
266 j = 0; | 265 if (ch < '0' || ch > '9') |
267 k = 0; | 266 break; |
268 while (i < strLength && j < 2) | 267 i++; |
269 { | 268 } |
270 ch = dtStr[i]; | 269 dt.day = (FX_BYTE)k; |
271 k = k * 10 + ch - '0'; | 270 if (i >= strLength || j < 2) |
272 j ++; | 271 return *this; |
273 if (ch < '0' || ch > '9') break; | 272 |
274 i ++; | 273 j = 0; |
275 } | 274 k = 0; |
276 dt.hour = (FX_BYTE)k; | 275 while (i < strLength && j < 2) { |
277 if (i >= strLength || j < 2) return *this; | 276 ch = dtStr[i]; |
278 | 277 k = k * 10 + ch - '0'; |
279 j = 0; | 278 j++; |
280 k = 0; | 279 if (ch < '0' || ch > '9') |
281 while (i < strLength && j < 2) | 280 break; |
282 { | 281 i++; |
283 ch = dtStr[i]; | 282 } |
284 k = k * 10 + ch - '0'; | 283 dt.hour = (FX_BYTE)k; |
285 j ++; | 284 if (i >= strLength || j < 2) |
286 if (ch < '0' || ch > '9') break; | 285 return *this; |
287 i ++; | 286 |
288 } | 287 j = 0; |
289 dt.minute = (FX_BYTE)k; | 288 k = 0; |
290 if (i >= strLength || j < 2) return *this; | 289 while (i < strLength && j < 2) { |
291 | 290 ch = dtStr[i]; |
292 j = 0; | 291 k = k * 10 + ch - '0'; |
293 k = 0; | 292 j++; |
294 while (i < strLength && j < 2) | 293 if (ch < '0' || ch > '9') |
295 { | 294 break; |
296 ch = dtStr[i]; | 295 i++; |
297 k = k * 10 + ch - '0'; | 296 } |
298 j ++; | 297 dt.minute = (FX_BYTE)k; |
299 if (ch < '0' || ch > '9') break; | 298 if (i >= strLength || j < 2) |
300 i ++; | 299 return *this; |
301 } | 300 |
302 dt.second = (FX_BYTE)k; | 301 j = 0; |
303 if (i >= strLength || j < 2) return *this; | 302 k = 0; |
304 | 303 while (i < strLength && j < 2) { |
305 ch = dtStr[i ++]; | 304 ch = dtStr[i]; |
306 if (ch != '-' && ch != '+') return *this; | 305 k = k * 10 + ch - '0'; |
307 if (ch == '-') | 306 j++; |
308 dt.tzHour = -1; | 307 if (ch < '0' || ch > '9') |
309 else | 308 break; |
310 dt.tzHour = 1; | 309 i++; |
311 j = 0; | 310 } |
312 k = 0; | 311 dt.second = (FX_BYTE)k; |
313 while (i < strLength && j < 2) | 312 if (i >= strLength || j < 2) |
314 { | 313 return *this; |
315 ch = dtStr[i]; | 314 |
316 k = k * 10 + ch - '0'; | 315 ch = dtStr[i++]; |
317 j ++; | 316 if (ch != '-' && ch != '+') |
318 if (ch < '0' || ch > '9') break; | 317 return *this; |
319 i ++; | 318 if (ch == '-') |
320 } | 319 dt.tzHour = -1; |
321 dt.tzHour *= (FX_CHAR)k; | 320 else |
322 if (i >= strLength || j < 2) return *this; | 321 dt.tzHour = 1; |
323 | 322 j = 0; |
324 ch = dtStr[i ++]; | 323 k = 0; |
325 if (ch != '\'') return *this; | 324 while (i < strLength && j < 2) { |
326 j = 0; | 325 ch = dtStr[i]; |
327 k = 0; | 326 k = k * 10 + ch - '0'; |
328 while (i < strLength && j < 2) | 327 j++; |
329 { | 328 if (ch < '0' || ch > '9') |
330 ch = dtStr[i]; | 329 break; |
331 k = k * 10 + ch - '0'; | 330 i++; |
332 j ++; | 331 } |
333 if (ch < '0' || ch > '9') break; | 332 dt.tzHour *= (FX_CHAR)k; |
334 i ++; | 333 if (i >= strLength || j < 2) |
335 } | 334 return *this; |
336 dt.tzMinute = (FX_BYTE)k; | 335 |
337 if (i >= strLength || j < 2) return *this; | 336 ch = dtStr[i++]; |
338 } | 337 if (ch != '\'') |
339 | 338 return *this; |
340 return *this; | 339 j = 0; |
341 } | 340 k = 0; |
342 | 341 while (i < strLength && j < 2) { |
343 CFX_ByteString CPDFSDK_DateTime::ToCommonDateTimeString() | 342 ch = dtStr[i]; |
344 { | 343 k = k * 10 + ch - '0'; |
345 CFX_ByteString str1; | 344 j++; |
346 str1.Format("%04d-%02d-%02d %02d:%02d:%02d ", dt.year, dt.month, dt.day,
dt.hour, dt.minute, dt.second); | 345 if (ch < '0' || ch > '9') |
347 if (dt.tzHour < 0) | 346 break; |
348 str1 += "-"; | 347 i++; |
349 else | 348 } |
350 str1 += "+"; | 349 dt.tzMinute = (FX_BYTE)k; |
351 CFX_ByteString str2; | 350 if (i >= strLength || j < 2) |
352 str2.Format("%02d:%02d", abs(dt.tzHour), dt.tzMinute); | 351 return *this; |
353 return str1 + str2; | 352 } |
354 } | 353 |
355 | 354 return *this; |
356 CFX_ByteString CPDFSDK_DateTime::ToPDFDateTimeString() | 355 } |
357 { | 356 |
358 CFX_ByteString dtStr; | 357 CFX_ByteString CPDFSDK_DateTime::ToCommonDateTimeString() { |
359 char tempStr[32]; | 358 CFX_ByteString str1; |
360 sprintf(tempStr, "D:%04d%02d%02d%02d%02d%02d", dt.year, dt.month, dt.day
, dt.hour, dt.minute, dt.second); | 359 str1.Format("%04d-%02d-%02d %02d:%02d:%02d ", |
361 dtStr = CFX_ByteString(tempStr); | 360 dt.year, |
362 if (dt.tzHour < 0) | 361 dt.month, |
363 dtStr += CFX_ByteString("-"); | 362 dt.day, |
364 else | 363 dt.hour, |
365 dtStr += CFX_ByteString("+"); | 364 dt.minute, |
366 sprintf(tempStr, "%02d'%02d'", abs(dt.tzHour), dt.tzMinute); | 365 dt.second); |
367 dtStr += CFX_ByteString(tempStr); | 366 if (dt.tzHour < 0) |
368 return dtStr; | 367 str1 += "-"; |
369 } | 368 else |
370 | 369 str1 += "+"; |
371 void CPDFSDK_DateTime::ToSystemTime(FX_SYSTEMTIME& st) | 370 CFX_ByteString str2; |
372 { | 371 str2.Format("%02d:%02d", abs(dt.tzHour), dt.tzMinute); |
373 CPDFSDK_DateTime dt = *this; | 372 return str1 + str2; |
374 time_t t = (time_t)dt; | 373 } |
375 struct tm* pTime = localtime(&t); | 374 |
376 if(pTime){ | 375 CFX_ByteString CPDFSDK_DateTime::ToPDFDateTimeString() { |
377 st.wYear = (FX_WORD)pTime->tm_year + 1900; | 376 CFX_ByteString dtStr; |
378 st.wMonth = (FX_WORD)pTime->tm_mon + 1; | 377 char tempStr[32]; |
379 st.wDay = (FX_WORD)pTime->tm_mday; | 378 sprintf(tempStr, |
380 st.wDayOfWeek = (FX_WORD)pTime->tm_wday; | 379 "D:%04d%02d%02d%02d%02d%02d", |
381 st.wHour = (FX_WORD)pTime->tm_hour; | 380 dt.year, |
382 st.wMinute = (FX_WORD)pTime->tm_min; | 381 dt.month, |
383 st.wSecond = (FX_WORD)pTime->tm_sec; | 382 dt.day, |
384 st.wMilliseconds = 0; | 383 dt.hour, |
385 } | 384 dt.minute, |
386 } | 385 dt.second); |
387 | 386 dtStr = CFX_ByteString(tempStr); |
388 CPDFSDK_DateTime CPDFSDK_DateTime::ToGMT() | 387 if (dt.tzHour < 0) |
389 { | 388 dtStr += CFX_ByteString("-"); |
390 CPDFSDK_DateTime dt = *this; | 389 else |
391 dt.AddSeconds(-_gAfxGetTimeZoneInSeconds(dt.dt.tzHour, dt.dt.tzMinute)); | 390 dtStr += CFX_ByteString("+"); |
392 dt.dt.tzHour = 0; | 391 sprintf(tempStr, "%02d'%02d'", abs(dt.tzHour), dt.tzMinute); |
393 dt.dt.tzMinute = 0; | 392 dtStr += CFX_ByteString(tempStr); |
394 return dt; | 393 return dtStr; |
395 } | 394 } |
396 | 395 |
397 CPDFSDK_DateTime& CPDFSDK_DateTime::AddDays(short days) | 396 void CPDFSDK_DateTime::ToSystemTime(FX_SYSTEMTIME& st) { |
398 { | 397 CPDFSDK_DateTime dt = *this; |
399 if (days == 0) return *this; | 398 time_t t = (time_t)dt; |
400 | 399 struct tm* pTime = localtime(&t); |
401 FX_SHORT y = dt.year, yy; | 400 if (pTime) { |
402 FX_BYTE m = dt.month; | 401 st.wYear = (FX_WORD)pTime->tm_year + 1900; |
403 FX_BYTE d = dt.day; | 402 st.wMonth = (FX_WORD)pTime->tm_mon + 1; |
404 int mdays, ydays, ldays; | 403 st.wDay = (FX_WORD)pTime->tm_mday; |
405 | 404 st.wDayOfWeek = (FX_WORD)pTime->tm_wday; |
406 ldays = days; | 405 st.wHour = (FX_WORD)pTime->tm_hour; |
407 if (ldays > 0) | 406 st.wMinute = (FX_WORD)pTime->tm_min; |
408 { | 407 st.wSecond = (FX_WORD)pTime->tm_sec; |
409 yy = y; | 408 st.wMilliseconds = 0; |
410 if (((FX_WORD)m * 100 + d) > 300) yy ++; | 409 } |
411 ydays = _gAfxGetYearDays(yy); | 410 } |
412 while (ldays >= ydays) | 411 |
413 { | 412 CPDFSDK_DateTime CPDFSDK_DateTime::ToGMT() { |
414 y ++; | 413 CPDFSDK_DateTime dt = *this; |
415 ldays -= ydays; | 414 dt.AddSeconds(-_gAfxGetTimeZoneInSeconds(dt.dt.tzHour, dt.dt.tzMinute)); |
416 yy ++; | 415 dt.dt.tzHour = 0; |
417 mdays = _gAfxGetMonthDays(y, m); | 416 dt.dt.tzMinute = 0; |
418 if (d > mdays) | 417 return dt; |
419 { | 418 } |
420 m ++; | 419 |
421 d -= mdays; | 420 CPDFSDK_DateTime& CPDFSDK_DateTime::AddDays(short days) { |
422 } | 421 if (days == 0) |
423 ydays = _gAfxGetYearDays(yy); | 422 return *this; |
424 } | 423 |
425 mdays = _gAfxGetMonthDays(y, m) - d + 1; | 424 FX_SHORT y = dt.year, yy; |
426 while (ldays >= mdays) | 425 FX_BYTE m = dt.month; |
427 { | 426 FX_BYTE d = dt.day; |
428 ldays -= mdays; | 427 int mdays, ydays, ldays; |
429 m ++; | 428 |
430 d = 1; | 429 ldays = days; |
431 mdays = _gAfxGetMonthDays(y, m); | 430 if (ldays > 0) { |
432 } | 431 yy = y; |
433 d += ldays; | 432 if (((FX_WORD)m * 100 + d) > 300) |
434 } | 433 yy++; |
435 else | 434 ydays = _gAfxGetYearDays(yy); |
436 { | 435 while (ldays >= ydays) { |
437 ldays *= -1; | 436 y++; |
438 yy = y; | 437 ldays -= ydays; |
439 if (((FX_WORD)m * 100 + d) < 300) yy --; | 438 yy++; |
440 ydays = _gAfxGetYearDays(yy); | 439 mdays = _gAfxGetMonthDays(y, m); |
441 while (ldays >= ydays) | 440 if (d > mdays) { |
442 { | 441 m++; |
443 y --; | 442 d -= mdays; |
444 ldays -= ydays; | 443 } |
445 yy --; | 444 ydays = _gAfxGetYearDays(yy); |
446 mdays = _gAfxGetMonthDays(y, m); | 445 } |
447 if (d > mdays) | 446 mdays = _gAfxGetMonthDays(y, m) - d + 1; |
448 { | 447 while (ldays >= mdays) { |
449 m ++; | 448 ldays -= mdays; |
450 d -= mdays; | 449 m++; |
451 } | 450 d = 1; |
452 ydays = _gAfxGetYearDays(yy); | 451 mdays = _gAfxGetMonthDays(y, m); |
453 } | 452 } |
454 while (ldays >= d) | 453 d += ldays; |
455 { | 454 } else { |
456 ldays -= d; | 455 ldays *= -1; |
457 m --; | 456 yy = y; |
458 mdays = _gAfxGetMonthDays(y, m); | 457 if (((FX_WORD)m * 100 + d) < 300) |
459 d = mdays; | 458 yy--; |
460 } | 459 ydays = _gAfxGetYearDays(yy); |
461 d -= ldays; | 460 while (ldays >= ydays) { |
462 } | 461 y--; |
463 | 462 ldays -= ydays; |
464 dt.year = y; | 463 yy--; |
465 dt.month = m; | 464 mdays = _gAfxGetMonthDays(y, m); |
466 dt.day = d; | 465 if (d > mdays) { |
467 | 466 m++; |
468 return *this; | 467 d -= mdays; |
469 } | 468 } |
470 | 469 ydays = _gAfxGetYearDays(yy); |
471 CPDFSDK_DateTime& CPDFSDK_DateTime::AddSeconds(int seconds) | 470 } |
472 { | 471 while (ldays >= d) { |
473 if (seconds == 0) return *this; | 472 ldays -= d; |
474 | 473 m--; |
475 int n; | 474 mdays = _gAfxGetMonthDays(y, m); |
476 int days; | 475 d = mdays; |
477 | 476 } |
478 n = dt.hour * 3600 + dt.minute * 60 + dt.second + seconds; | 477 d -= ldays; |
479 if (n < 0) | 478 } |
480 { | 479 |
481 days = (n - 86399) / 86400; | 480 dt.year = y; |
482 n -= days * 86400; | 481 dt.month = m; |
483 } | 482 dt.day = d; |
484 else | 483 |
485 { | 484 return *this; |
486 days = n / 86400; | 485 } |
487 n %= 86400; | 486 |
488 } | 487 CPDFSDK_DateTime& CPDFSDK_DateTime::AddSeconds(int seconds) { |
489 dt.hour = (FX_BYTE)(n / 3600); | 488 if (seconds == 0) |
490 dt.hour %= 24; | 489 return *this; |
491 n %= 3600; | 490 |
492 dt.minute = (FX_BYTE)(n / 60); | 491 int n; |
493 dt.second = (FX_BYTE)(n % 60); | 492 int days; |
494 if (days != 0) AddDays(days); | 493 |
495 | 494 n = dt.hour * 3600 + dt.minute * 60 + dt.second + seconds; |
496 return *this; | 495 if (n < 0) { |
497 } | 496 days = (n - 86399) / 86400; |
498 | 497 n -= days * 86400; |
| 498 } else { |
| 499 days = n / 86400; |
| 500 n %= 86400; |
| 501 } |
| 502 dt.hour = (FX_BYTE)(n / 3600); |
| 503 dt.hour %= 24; |
| 504 n %= 3600; |
| 505 dt.minute = (FX_BYTE)(n / 60); |
| 506 dt.second = (FX_BYTE)(n % 60); |
| 507 if (days != 0) |
| 508 AddDays(days); |
| 509 |
| 510 return *this; |
| 511 } |
499 | 512 |
500 //--------------------------------------------------------------------------- | 513 //--------------------------------------------------------------------------- |
501 //» » » » » » » » CPDFSDK_Annot» | 514 //» » » » » » » » CPDFSDK_Annot |
502 //--------------------------------------------------------------------------- | 515 //--------------------------------------------------------------------------- |
503 CPDFSDK_Annot::CPDFSDK_Annot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView) : | 516 CPDFSDK_Annot::CPDFSDK_Annot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView) |
504 m_pAnnot(pAnnot), | 517 : m_pAnnot(pAnnot), |
505 m_pPageView(pPageView), | 518 m_pPageView(pPageView), |
506 m_bSelected(FALSE), | 519 m_bSelected(FALSE), |
507 m_nTabOrder(-1) | 520 m_nTabOrder(-1) { |
508 { | 521 } |
509 } | 522 |
510 | 523 CPDFSDK_Annot::~CPDFSDK_Annot() { |
511 CPDFSDK_Annot::~CPDFSDK_Annot() | 524 m_pAnnot = NULL; |
512 { | 525 m_pPageView = NULL; |
513 m_pAnnot = NULL; | 526 } |
514 m_pPageView = NULL; | 527 |
515 } | 528 CPDF_Annot* CPDFSDK_Annot::GetPDFAnnot() { |
516 | 529 return m_pAnnot; |
517 CPDF_Annot* CPDFSDK_Annot::GetPDFAnnot() | 530 } |
518 { | 531 |
519 return m_pAnnot; | 532 FX_DWORD CPDFSDK_Annot::GetFlags() { |
520 } | 533 ASSERT(m_pAnnot != NULL); |
521 | 534 |
522 FX_DWORD CPDFSDK_Annot::GetFlags() | 535 return m_pAnnot->GetFlags(); |
523 { | 536 } |
524 ASSERT(m_pAnnot != NULL); | 537 |
525 | 538 void CPDFSDK_Annot::SetPage(CPDFSDK_PageView* pPageView) { |
526 return m_pAnnot->GetFlags(); | 539 m_pPageView = pPageView; |
527 } | 540 } |
528 | 541 |
529 void CPDFSDK_Annot::SetPage(CPDFSDK_PageView* pPageView) | 542 CPDFSDK_PageView* CPDFSDK_Annot::GetPageView() { |
530 { | 543 return m_pPageView; |
531 m_pPageView = pPageView; | 544 } |
532 } | 545 |
533 | 546 FX_BOOL CPDFSDK_Annot::IsSelected() { |
534 CPDFSDK_PageView* CPDFSDK_Annot::GetPageView() | 547 return m_bSelected; |
535 { | 548 } |
536 return m_pPageView; | 549 |
537 } | 550 void CPDFSDK_Annot::SetSelected(FX_BOOL bSelected) { |
538 | 551 m_bSelected = bSelected; |
539 FX_BOOL CPDFSDK_Annot::IsSelected() | 552 } |
540 { | 553 |
541 return m_bSelected; | 554 // Tab Order |
542 } | 555 int CPDFSDK_Annot::GetTabOrder() { |
543 | 556 return m_nTabOrder; |
544 void CPDFSDK_Annot::SetSelected(FX_BOOL bSelected) | 557 } |
545 { | 558 |
546 m_bSelected = bSelected; | 559 void CPDFSDK_Annot::SetTabOrder(int iTabOrder) { |
547 } | 560 m_nTabOrder = iTabOrder; |
548 | 561 } |
549 // Tab Order | 562 |
550 int CPDFSDK_Annot::GetTabOrder() | 563 CPDF_Dictionary* CPDFSDK_Annot::GetAnnotDict() const { |
551 { | 564 ASSERT(m_pAnnot != NULL); |
552 return m_nTabOrder; | 565 |
553 } | 566 return m_pAnnot->m_pAnnotDict; |
554 | 567 } |
555 void CPDFSDK_Annot::SetTabOrder(int iTabOrder) | 568 |
556 { | 569 void CPDFSDK_Annot::SetRect(const CPDF_Rect& rect) { |
557 m_nTabOrder = iTabOrder; | 570 ASSERT(m_pAnnot != NULL); |
558 } | 571 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
559 | 572 ASSERT(rect.right - rect.left >= GetMinWidth()); |
560 CPDF_Dictionary* CPDFSDK_Annot::GetAnnotDict() const | 573 ASSERT(rect.top - rect.bottom >= GetMinHeight()); |
561 { | 574 |
562 ASSERT(m_pAnnot != NULL); | 575 m_pAnnot->m_pAnnotDict->SetAtRect("Rect", rect); |
563 | 576 } |
564 return m_pAnnot->m_pAnnotDict; | 577 |
565 } | 578 CPDF_Rect CPDFSDK_Annot::GetRect() const { |
566 | 579 ASSERT(m_pAnnot != NULL); |
567 void CPDFSDK_Annot::SetRect(const CPDF_Rect& rect) | 580 |
568 { | 581 CPDF_Rect rect; |
569 ASSERT(m_pAnnot != NULL); | 582 m_pAnnot->GetRect(rect); |
570 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 583 |
571 ASSERT(rect.right - rect.left >= GetMinWidth()); | 584 return rect; |
572 ASSERT(rect.top - rect.bottom >= GetMinHeight()); | 585 } |
573 | 586 |
574 m_pAnnot->m_pAnnotDict->SetAtRect("Rect", rect); | 587 CFX_ByteString CPDFSDK_Annot::GetType() const { |
575 } | 588 ASSERT(m_pAnnot != NULL); |
576 | 589 |
577 CPDF_Rect CPDFSDK_Annot::GetRect() const | 590 return m_pAnnot->GetSubType(); |
578 { | 591 } |
579 ASSERT(m_pAnnot != NULL); | 592 |
580 | 593 CFX_ByteString CPDFSDK_Annot::GetSubType() const { |
581 CPDF_Rect rect; | 594 return ""; |
582 m_pAnnot->GetRect(rect); | 595 } |
583 | 596 |
584 return rect; | 597 void CPDFSDK_Annot::DrawAppearance(CFX_RenderDevice* pDevice, |
585 } | 598 const CPDF_Matrix* pUser2Device, |
586 | 599 CPDF_Annot::AppearanceMode mode, |
587 CFX_ByteString CPDFSDK_Annot::GetType() const | 600 const CPDF_RenderOptions* pOptions) { |
588 { | 601 ASSERT(m_pPageView != NULL); |
589 ASSERT(m_pAnnot != NULL); | 602 ASSERT(m_pAnnot != NULL); |
590 | 603 |
591 return m_pAnnot->GetSubType(); | 604 m_pAnnot->DrawAppearance( |
592 } | 605 m_pPageView->GetPDFPage(), pDevice, pUser2Device, mode, pOptions); |
593 | 606 } |
594 CFX_ByteString CPDFSDK_Annot::GetSubType() const | 607 |
595 { | 608 FX_BOOL CPDFSDK_Annot::IsAppearanceValid() { |
596 return ""; | 609 ASSERT(m_pAnnot != NULL); |
597 } | 610 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
598 | 611 |
599 void CPDFSDK_Annot::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix*
pUser2Device, | 612 return m_pAnnot->m_pAnnotDict->GetDict("AP") != NULL; |
600 CPDF_Annot::A
ppearanceMode mode, const CPDF_RenderOptions* pOptions) | 613 } |
601 { | 614 |
602 ASSERT(m_pPageView != NULL); | 615 FX_BOOL CPDFSDK_Annot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) { |
603 ASSERT(m_pAnnot != NULL); | 616 ASSERT(m_pAnnot != NULL); |
604 | 617 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
605 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Devic
e, mode, pOptions); | 618 |
606 } | 619 CPDF_Dictionary* pAP = m_pAnnot->m_pAnnotDict->GetDict("AP"); |
607 | 620 if (pAP == NULL) |
608 FX_BOOL CPDFSDK_Annot::IsAppearanceValid() | 621 return FALSE; |
609 { | 622 |
610 ASSERT(m_pAnnot != NULL); | 623 // Choose the right sub-ap |
611 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 624 const FX_CHAR* ap_entry = "N"; |
612 | 625 if (mode == CPDF_Annot::Down) |
613 return m_pAnnot->m_pAnnotDict->GetDict("AP") != NULL; | 626 ap_entry = "D"; |
614 } | 627 else if (mode == CPDF_Annot::Rollover) |
615 | 628 ap_entry = "R"; |
616 FX_BOOL CPDFSDK_Annot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) | 629 if (!pAP->KeyExist(ap_entry)) |
617 { | 630 ap_entry = "N"; |
618 ASSERT(m_pAnnot != NULL); | 631 |
619 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 632 // Get the AP stream or subdirectory |
620 | 633 CPDF_Object* psub = pAP->GetElementValue(ap_entry); |
621 CPDF_Dictionary* pAP = m_pAnnot->m_pAnnotDict->GetDict("AP"); | 634 if (psub == NULL) |
622 if (pAP == NULL) return FALSE; | 635 return FALSE; |
623 | 636 |
624 // Choose the right sub-ap | 637 return TRUE; |
625 const FX_CHAR* ap_entry = "N"; | 638 } |
626 if (mode == CPDF_Annot::Down) | 639 |
627 ap_entry = "D"; | 640 void CPDFSDK_Annot::DrawBorder(CFX_RenderDevice* pDevice, |
628 else if (mode == CPDF_Annot::Rollover) | 641 const CPDF_Matrix* pUser2Device, |
629 ap_entry = "R"; | 642 const CPDF_RenderOptions* pOptions) { |
630 if (!pAP->KeyExist(ap_entry)) | 643 ASSERT(m_pAnnot != NULL); |
631 ap_entry = "N"; | 644 m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions); |
632 | 645 } |
633 // Get the AP stream or subdirectory | 646 |
634 CPDF_Object* psub = pAP->GetElementValue(ap_entry); | 647 void CPDFSDK_Annot::ClearCachedAP() { |
635 if (psub == NULL) return FALSE; | 648 ASSERT(m_pAnnot != NULL); |
636 | 649 m_pAnnot->ClearCachedAP(); |
637 return TRUE; | 650 } |
638 } | 651 |
639 | 652 void CPDFSDK_Annot::SetContents(const CFX_WideString& sContents) { |
640 void CPDFSDK_Annot::DrawBorder(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUs
er2Device, | 653 ASSERT(m_pAnnot != NULL); |
641 const CPDF_RenderOptions* pOp
tions) | 654 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
642 { | 655 |
643 ASSERT(m_pAnnot != NULL); | 656 if (sContents.IsEmpty()) |
644 m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions); | 657 m_pAnnot->m_pAnnotDict->RemoveAt("Contents"); |
645 } | 658 else |
646 | 659 m_pAnnot->m_pAnnotDict->SetAtString("Contents", PDF_EncodeText(sContents)); |
647 void CPDFSDK_Annot::ClearCachedAP() | 660 } |
648 { | 661 |
649 ASSERT(m_pAnnot != NULL); | 662 CFX_WideString CPDFSDK_Annot::GetContents() const { |
650 m_pAnnot->ClearCachedAP(); | 663 ASSERT(m_pAnnot != NULL); |
651 } | 664 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
652 | 665 |
653 void CPDFSDK_Annot::SetContents(const CFX_WideString& sContents) | 666 return m_pAnnot->m_pAnnotDict->GetUnicodeText("Contents"); |
654 { | 667 } |
655 ASSERT(m_pAnnot != NULL); | 668 |
656 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 669 void CPDFSDK_Annot::SetAnnotName(const CFX_WideString& sName) { |
657 | 670 ASSERT(m_pAnnot != NULL); |
658 if (sContents.IsEmpty()) | 671 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
659 m_pAnnot->m_pAnnotDict->RemoveAt("Contents"); | 672 |
660 else | 673 if (sName.IsEmpty()) |
661 m_pAnnot->m_pAnnotDict->SetAtString("Contents", PDF_EncodeText(s
Contents)); | 674 m_pAnnot->m_pAnnotDict->RemoveAt("NM"); |
662 } | 675 else |
663 | 676 m_pAnnot->m_pAnnotDict->SetAtString("NM", PDF_EncodeText(sName)); |
664 CFX_WideString CPDFSDK_Annot::GetContents() const | 677 } |
665 { | 678 |
666 ASSERT(m_pAnnot != NULL); | 679 CFX_WideString CPDFSDK_Annot::GetAnnotName() const { |
667 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 680 ASSERT(m_pAnnot != NULL); |
668 | 681 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
669 return m_pAnnot->m_pAnnotDict->GetUnicodeText("Contents"); | 682 |
670 } | 683 return m_pAnnot->m_pAnnotDict->GetUnicodeText("NM"); |
671 | 684 } |
672 void CPDFSDK_Annot::SetAnnotName(const CFX_WideString& sName) | 685 |
673 { | 686 void CPDFSDK_Annot::SetModifiedDate(const FX_SYSTEMTIME& st) { |
674 ASSERT(m_pAnnot != NULL); | 687 ASSERT(m_pAnnot != NULL); |
675 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 688 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
676 | 689 |
677 if (sName.IsEmpty()) | 690 CPDFSDK_DateTime dt(st); |
678 m_pAnnot->m_pAnnotDict->RemoveAt("NM"); | 691 CFX_ByteString str = dt.ToPDFDateTimeString(); |
679 else | 692 |
680 m_pAnnot->m_pAnnotDict->SetAtString("NM", PDF_EncodeText(sName))
; | 693 if (str.IsEmpty()) |
681 } | 694 m_pAnnot->m_pAnnotDict->RemoveAt("M"); |
682 | 695 else |
683 CFX_WideString CPDFSDK_Annot::GetAnnotName() const | 696 m_pAnnot->m_pAnnotDict->SetAtString("M", str); |
684 { | 697 } |
685 ASSERT(m_pAnnot != NULL); | 698 |
686 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 699 FX_SYSTEMTIME CPDFSDK_Annot::GetModifiedDate() const { |
687 | 700 ASSERT(m_pAnnot != NULL); |
688 return m_pAnnot->m_pAnnotDict->GetUnicodeText("NM"); | 701 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
689 } | 702 |
690 | 703 FX_SYSTEMTIME systime; |
691 void CPDFSDK_Annot::SetModifiedDate(const FX_SYSTEMTIME& st) | 704 CFX_ByteString str = m_pAnnot->m_pAnnotDict->GetString("M"); |
692 { | 705 |
693 ASSERT(m_pAnnot != NULL); | 706 CPDFSDK_DateTime dt(str); |
694 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 707 dt.ToSystemTime(systime); |
695 | 708 |
696 CPDFSDK_DateTime dt(st); | 709 return systime; |
697 CFX_ByteString str = dt.ToPDFDateTimeString(); | 710 } |
698 | 711 |
699 if (str.IsEmpty()) | 712 void CPDFSDK_Annot::SetFlags(int nFlags) { |
700 m_pAnnot->m_pAnnotDict->RemoveAt("M"); | 713 ASSERT(m_pAnnot != NULL); |
701 else | 714 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
702 m_pAnnot->m_pAnnotDict->SetAtString("M", str); | 715 |
703 } | 716 m_pAnnot->m_pAnnotDict->SetAtInteger("F", nFlags); |
704 | 717 } |
705 FX_SYSTEMTIME CPDFSDK_Annot::GetModifiedDate() const | 718 |
706 { | 719 int CPDFSDK_Annot::GetFlags() const { |
707 ASSERT(m_pAnnot != NULL); | 720 ASSERT(m_pAnnot != NULL); |
708 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 721 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
709 | 722 |
710 FX_SYSTEMTIME systime; | 723 return m_pAnnot->m_pAnnotDict->GetInteger("F"); |
711 CFX_ByteString str = m_pAnnot->m_pAnnotDict->GetString("M"); | 724 } |
712 | 725 |
713 CPDFSDK_DateTime dt(str); | 726 void CPDFSDK_Annot::SetAppState(const CFX_ByteString& str) { |
714 dt.ToSystemTime(systime); | 727 ASSERT(m_pAnnot != NULL); |
715 | 728 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
716 return systime; | 729 |
717 } | 730 if (str.IsEmpty()) |
718 | 731 m_pAnnot->m_pAnnotDict->RemoveAt("AS"); |
719 void CPDFSDK_Annot::SetFlags(int nFlags) | 732 else |
720 { | 733 m_pAnnot->m_pAnnotDict->SetAtString("AS", str); |
721 ASSERT(m_pAnnot != NULL); | 734 } |
722 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 735 |
723 | 736 CFX_ByteString CPDFSDK_Annot::GetAppState() const { |
724 m_pAnnot->m_pAnnotDict->SetAtInteger("F", nFlags); | 737 ASSERT(m_pAnnot != NULL); |
725 } | 738 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
726 | 739 |
727 int CPDFSDK_Annot::GetFlags() const | 740 return m_pAnnot->m_pAnnotDict->GetString("AS"); |
728 { | 741 } |
729 ASSERT(m_pAnnot != NULL); | 742 |
730 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 743 void CPDFSDK_Annot::SetStructParent(int key) { |
731 | 744 ASSERT(m_pAnnot != NULL); |
732 return m_pAnnot->m_pAnnotDict->GetInteger("F"); | 745 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
733 } | 746 |
734 | 747 m_pAnnot->m_pAnnotDict->SetAtInteger("StructParent", key); |
735 void CPDFSDK_Annot::SetAppState(const CFX_ByteString& str) | 748 } |
736 { | 749 |
737 ASSERT(m_pAnnot != NULL); | 750 int CPDFSDK_Annot::GetStructParent() const { |
738 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 751 ASSERT(m_pAnnot != NULL); |
739 | 752 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
740 if (str.IsEmpty()) | 753 |
741 m_pAnnot->m_pAnnotDict->RemoveAt("AS"); | 754 return m_pAnnot->m_pAnnotDict->GetInteger("StructParent"); |
742 else | 755 } |
743 m_pAnnot->m_pAnnotDict->SetAtString("AS", str); | 756 |
744 } | 757 // border |
745 | 758 void CPDFSDK_Annot::SetBorderWidth(int nWidth) { |
746 CFX_ByteString CPDFSDK_Annot::GetAppState() const | 759 ASSERT(m_pAnnot != NULL); |
747 { | 760 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
748 ASSERT(m_pAnnot != NULL); | 761 |
749 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 762 CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border"); |
750 | 763 |
751 return m_pAnnot->m_pAnnotDict->GetString("AS"); | 764 if (pBorder) { |
752 } | 765 pBorder->SetAt(2, FX_NEW CPDF_Number(nWidth)); |
753 | 766 } else { |
754 void CPDFSDK_Annot::SetStructParent(int key) | 767 CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS"); |
755 { | 768 |
756 ASSERT(m_pAnnot != NULL); | 769 if (!pBSDict) { |
757 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 770 pBSDict = FX_NEW CPDF_Dictionary; |
758 | 771 m_pAnnot->m_pAnnotDict->SetAt("BS", pBSDict); |
759 m_pAnnot->m_pAnnotDict->SetAtInteger("StructParent", key); | 772 } |
760 } | 773 |
761 | 774 pBSDict->SetAtInteger("W", nWidth); |
762 int CPDFSDK_Annot::GetStructParent() const | 775 } |
763 { | 776 } |
764 ASSERT(m_pAnnot != NULL); | 777 |
765 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 778 int CPDFSDK_Annot::GetBorderWidth() const { |
766 | 779 ASSERT(m_pAnnot != NULL); |
767 return m_pAnnot->m_pAnnotDict->GetInteger("StructParent"); | 780 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
768 } | 781 |
769 | 782 CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border"); |
770 //border | 783 |
771 void CPDFSDK_Annot::SetBorderWidth(int nWidth) | 784 if (pBorder) { |
772 { | 785 return pBorder->GetInteger(2); |
773 ASSERT(m_pAnnot != NULL); | 786 } else { |
774 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 787 CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS"); |
775 | 788 |
776 CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border"); | 789 if (pBSDict) { |
777 | 790 return pBSDict->GetInteger("W", 1); |
778 if (pBorder) | 791 } |
779 { | 792 } |
780 pBorder->SetAt(2, FX_NEW CPDF_Number(nWidth)); | 793 return 1; |
781 } | 794 } |
782 else | 795 |
783 { | 796 void CPDFSDK_Annot::SetBorderStyle(int nStyle) { |
784 CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS")
; | 797 ASSERT(m_pAnnot != NULL); |
785 | 798 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
786 if (!pBSDict) | 799 |
787 { | 800 CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS"); |
788 pBSDict = FX_NEW CPDF_Dictionary; | 801 if (!pBSDict) { |
789 m_pAnnot->m_pAnnotDict->SetAt("BS", pBSDict); | 802 pBSDict = FX_NEW CPDF_Dictionary; |
790 } | 803 m_pAnnot->m_pAnnotDict->SetAt("BS", pBSDict); |
791 | 804 } |
792 pBSDict->SetAtInteger("W", nWidth); | 805 |
793 } | 806 switch (nStyle) { |
794 } | 807 case BBS_SOLID: |
795 | 808 pBSDict->SetAtName("S", "S"); |
796 int CPDFSDK_Annot::GetBorderWidth() const | 809 break; |
797 { | 810 case BBS_DASH: |
798 ASSERT(m_pAnnot != NULL); | 811 pBSDict->SetAtName("S", "D"); |
799 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 812 break; |
800 | 813 case BBS_BEVELED: |
801 CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border"); | 814 pBSDict->SetAtName("S", "B"); |
802 | 815 break; |
803 if (pBorder) | 816 case BBS_INSET: |
804 { | 817 pBSDict->SetAtName("S", "I"); |
805 return pBorder->GetInteger(2); | 818 break; |
806 } | 819 case BBS_UNDERLINE: |
807 else | 820 pBSDict->SetAtName("S", "U"); |
808 { | 821 break; |
809 CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS")
; | 822 } |
810 | 823 } |
811 if (pBSDict) | 824 |
812 { | 825 int CPDFSDK_Annot::GetBorderStyle() const { |
813 return pBSDict->GetInteger("W", 1); | 826 ASSERT(m_pAnnot != NULL); |
814 } | 827 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
815 } | 828 |
816 return 1; | 829 CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS"); |
817 } | 830 if (pBSDict) { |
818 | 831 CFX_ByteString sBorderStyle = pBSDict->GetString("S", "S"); |
819 void CPDFSDK_Annot::SetBorderStyle(int nStyle) | 832 if (sBorderStyle == "S") |
820 { | 833 return BBS_SOLID; |
821 ASSERT(m_pAnnot != NULL); | 834 if (sBorderStyle == "D") |
822 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 835 return BBS_DASH; |
823 | 836 if (sBorderStyle == "B") |
824 CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS"); | 837 return BBS_BEVELED; |
825 if (!pBSDict) | 838 if (sBorderStyle == "I") |
826 { | 839 return BBS_INSET; |
827 pBSDict = FX_NEW CPDF_Dictionary; | 840 if (sBorderStyle == "U") |
828 m_pAnnot->m_pAnnotDict->SetAt("BS", pBSDict); | 841 return BBS_UNDERLINE; |
829 } | 842 } |
830 | 843 |
831 switch (nStyle) | 844 CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border"); |
832 { | 845 if (pBorder) { |
833 case BBS_SOLID: | 846 if (pBorder->GetCount() >= 4) { |
834 pBSDict->SetAtName("S", "S"); | 847 CPDF_Array* pDP = pBorder->GetArray(3); |
835 break; | 848 if (pDP && pDP->GetCount() > 0) |
836 case BBS_DASH: | 849 return BBS_DASH; |
837 pBSDict->SetAtName("S", "D"); | 850 } |
838 break; | 851 } |
839 case BBS_BEVELED: | 852 |
840 pBSDict->SetAtName("S", "B"); | 853 return BBS_SOLID; |
841 break; | 854 } |
842 case BBS_INSET: | 855 |
843 pBSDict->SetAtName("S", "I"); | 856 void CPDFSDK_Annot::SetBorderDash(const CFX_IntArray& array) { |
844 break; | 857 ASSERT(m_pAnnot != NULL); |
845 case BBS_UNDERLINE: | 858 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
846 pBSDict->SetAtName("S", "U"); | 859 |
847 break; | 860 CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS"); |
848 } | 861 if (!pBSDict) { |
849 } | 862 pBSDict = FX_NEW CPDF_Dictionary; |
850 | 863 m_pAnnot->m_pAnnotDict->SetAt("BS", pBSDict); |
851 int CPDFSDK_Annot::GetBorderStyle() const | 864 } |
852 { | 865 |
853 ASSERT(m_pAnnot != NULL); | 866 CPDF_Array* pArray = FX_NEW CPDF_Array; |
854 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 867 for (int i = 0, sz = array.GetSize(); i < sz; i++) { |
855 | 868 pArray->AddInteger(array[i]); |
856 CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS"); | 869 } |
857 if (pBSDict) | 870 |
858 { | 871 pBSDict->SetAt("D", pArray); |
859 CFX_ByteString sBorderStyle = pBSDict->GetString("S", "S"); | 872 } |
860 if (sBorderStyle == "S") return BBS_SOLID; | 873 |
861 if (sBorderStyle == "D") return BBS_DASH; | 874 void CPDFSDK_Annot::GetBorderDash(CFX_IntArray& array) const { |
862 if (sBorderStyle == "B") return BBS_BEVELED; | 875 ASSERT(m_pAnnot != NULL); |
863 if (sBorderStyle == "I") return BBS_INSET; | 876 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
864 if (sBorderStyle == "U") return BBS_UNDERLINE; | 877 |
865 } | 878 CPDF_Array* pDash = NULL; |
866 | 879 |
867 CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border"); | 880 CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border"); |
868 if (pBorder) | 881 if (pBorder) { |
869 { | 882 pDash = pBorder->GetArray(3); |
870 if (pBorder->GetCount() >= 4) | 883 } else { |
871 { | 884 CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS"); |
872 CPDF_Array *pDP = pBorder->GetArray(3); | 885 if (pBSDict) { |
873 if (pDP && pDP->GetCount() > 0) | 886 pDash = pBSDict->GetArray("D"); |
874 return BBS_DASH; | 887 } |
875 } | 888 } |
876 } | 889 |
877 | 890 if (pDash) { |
878 return BBS_SOLID; | 891 for (int i = 0, sz = pDash->GetCount(); i < sz; i++) { |
879 } | 892 array.Add(pDash->GetInteger(i)); |
880 | 893 } |
881 void CPDFSDK_Annot::SetBorderDash(const CFX_IntArray& array) | 894 } |
882 { | 895 } |
883 ASSERT(m_pAnnot != NULL); | 896 |
884 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 897 void CPDFSDK_Annot::SetColor(FX_COLORREF color) { |
885 | 898 ASSERT(m_pAnnot != NULL); |
886 CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS"); | 899 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
887 if (!pBSDict) | 900 |
888 { | 901 CPDF_Array* pArray = FX_NEW CPDF_Array; |
889 pBSDict = FX_NEW CPDF_Dictionary; | 902 pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f); |
890 m_pAnnot->m_pAnnotDict->SetAt("BS", pBSDict); | 903 pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f); |
891 } | 904 pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f); |
892 | 905 m_pAnnot->m_pAnnotDict->SetAt("C", pArray); |
893 CPDF_Array* pArray = FX_NEW CPDF_Array; | 906 } |
894 for (int i=0,sz=array.GetSize(); i<sz; i++) | 907 |
895 { | 908 void CPDFSDK_Annot::RemoveColor() { |
896 pArray->AddInteger(array[i]); | 909 ASSERT(m_pAnnot != NULL); |
897 } | 910 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
898 | 911 |
899 pBSDict->SetAt("D", pArray); | 912 m_pAnnot->m_pAnnotDict->RemoveAt("C"); |
900 } | 913 } |
901 | 914 |
902 void CPDFSDK_Annot::GetBorderDash(CFX_IntArray& array) const | 915 FX_BOOL CPDFSDK_Annot::GetColor(FX_COLORREF& color) const { |
903 { | 916 ASSERT(m_pAnnot != NULL); |
904 ASSERT(m_pAnnot != NULL); | 917 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
905 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 918 |
906 | 919 if (CPDF_Array* pEntry = m_pAnnot->m_pAnnotDict->GetArray("C")) { |
907 CPDF_Array* pDash = NULL; | 920 int nCount = pEntry->GetCount(); |
908 | 921 if (nCount == 1) { |
909 CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border"); | 922 FX_FLOAT g = pEntry->GetNumber(0) * 255; |
910 if (pBorder) | 923 |
911 { | 924 color = FXSYS_RGB((int)g, (int)g, (int)g); |
912 pDash = pBorder->GetArray(3); | 925 |
913 } | 926 return TRUE; |
914 else | 927 } else if (nCount == 3) { |
915 { | 928 FX_FLOAT r = pEntry->GetNumber(0) * 255; |
916 CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS")
; | 929 FX_FLOAT g = pEntry->GetNumber(1) * 255; |
917 if (pBSDict) | 930 FX_FLOAT b = pEntry->GetNumber(2) * 255; |
918 { | 931 |
919 pDash = pBSDict->GetArray("D"); | 932 color = FXSYS_RGB((int)r, (int)g, (int)b); |
920 } | 933 |
921 } | 934 return TRUE; |
922 | 935 } else if (nCount == 4) { |
923 if (pDash) | 936 FX_FLOAT c = pEntry->GetNumber(0); |
924 { | 937 FX_FLOAT m = pEntry->GetNumber(1); |
925 for (int i=0,sz=pDash->GetCount(); i<sz; i++) | 938 FX_FLOAT y = pEntry->GetNumber(2); |
926 { | 939 FX_FLOAT k = pEntry->GetNumber(3); |
927 array.Add(pDash->GetInteger(i)); | 940 |
928 } | 941 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k); |
929 } | 942 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k); |
930 } | 943 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k); |
931 | 944 |
932 void CPDFSDK_Annot::SetColor(FX_COLORREF color) | 945 color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255)); |
933 { | 946 |
934 ASSERT(m_pAnnot != NULL); | 947 return TRUE; |
935 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 948 } |
936 | 949 } |
937 CPDF_Array* pArray = FX_NEW CPDF_Array; | 950 |
938 pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f); | 951 return FALSE; |
939 pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f); | 952 } |
940 pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f); | 953 |
941 m_pAnnot->m_pAnnotDict->SetAt("C", pArray); | 954 void CPDFSDK_Annot::WriteAppearance(const CFX_ByteString& sAPType, |
942 } | 955 const CPDF_Rect& rcBBox, |
943 | 956 const CPDF_Matrix& matrix, |
944 void CPDFSDK_Annot::RemoveColor() | 957 const CFX_ByteString& sContents, |
945 { | 958 const CFX_ByteString& sAPState) { |
946 ASSERT(m_pAnnot != NULL); | 959 ASSERT(m_pAnnot != NULL); |
947 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 960 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
948 | 961 |
949 m_pAnnot->m_pAnnotDict->RemoveAt("C") ; | 962 CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP"); |
950 } | 963 |
951 | 964 if (!pAPDict) { |
952 FX_BOOL CPDFSDK_Annot::GetColor(FX_COLORREF& color) const | 965 pAPDict = FX_NEW CPDF_Dictionary; |
953 { | 966 m_pAnnot->m_pAnnotDict->SetAt("AP", pAPDict); |
954 ASSERT(m_pAnnot != NULL); | 967 } |
955 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 968 |
956 | 969 CPDF_Stream* pStream = NULL; |
957 if (CPDF_Array* pEntry = m_pAnnot->m_pAnnotDict->GetArray("C")) | 970 CPDF_Dictionary* pParentDict = NULL; |
958 { | 971 |
959 int nCount = pEntry->GetCount(); | 972 if (sAPState.IsEmpty()) { |
960 if (nCount == 1) | 973 pParentDict = pAPDict; |
961 { | 974 pStream = pAPDict->GetStream(sAPType); |
962 FX_FLOAT g = pEntry->GetNumber(0) * 255; | 975 } else { |
963 | 976 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDict(sAPType); |
964 color = FXSYS_RGB((int)g, (int)g, (int)g); | 977 if (!pAPTypeDict) { |
965 | 978 pAPTypeDict = FX_NEW CPDF_Dictionary; |
966 return TRUE; | 979 pAPDict->SetAt(sAPType, pAPTypeDict); |
967 } | 980 } |
968 else if (nCount == 3) | 981 |
969 { | 982 pParentDict = pAPTypeDict; |
970 FX_FLOAT r = pEntry->GetNumber(0) * 255; | 983 pStream = pAPTypeDict->GetStream(sAPState); |
971 FX_FLOAT g = pEntry->GetNumber(1) * 255; | 984 } |
972 FX_FLOAT b = pEntry->GetNumber(2) * 255; | 985 |
973 | 986 if (!pStream) { |
974 color = FXSYS_RGB((int)r, (int)g, (int)b); | 987 ASSERT(m_pPageView != NULL); |
975 | 988 CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
976 return TRUE; | 989 ASSERT(pDoc != NULL); |
977 } | 990 |
978 else if (nCount == 4) | 991 pStream = FX_NEW CPDF_Stream(NULL, 0, NULL); |
979 { | 992 FX_INT32 objnum = pDoc->AddIndirectObject(pStream); |
980 FX_FLOAT c = pEntry->GetNumber(0); | 993 // pAPDict->SetAtReference(sAPType, pDoc, objnum); |
981 FX_FLOAT m = pEntry->GetNumber(1); | 994 ASSERT(pParentDict != NULL); |
982 FX_FLOAT y = pEntry->GetNumber(2); | 995 pParentDict->SetAtReference(sAPType, pDoc, objnum); |
983 FX_FLOAT k = pEntry->GetNumber(3); | 996 } |
984 | 997 |
985 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k); | 998 CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
986 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k); | 999 |
987 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k); | 1000 if (!pStreamDict) { |
988 | 1001 pStreamDict = FX_NEW CPDF_Dictionary; |
989 color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(
b * 255)); | 1002 pStreamDict->SetAtName("Type", "XObject"); |
990 | 1003 pStreamDict->SetAtName("Subtype", "Form"); |
991 return TRUE; | 1004 pStreamDict->SetAtInteger("FormType", 1); |
992 } | 1005 pStream->InitStream(NULL, 0, pStreamDict); |
993 } | 1006 } |
994 | 1007 |
995 return FALSE; | 1008 if (pStreamDict) { |
996 } | 1009 pStreamDict->SetAtMatrix("Matrix", matrix); |
997 | 1010 pStreamDict->SetAtRect("BBox", rcBBox); |
998 | 1011 } |
999 void CPDFSDK_Annot::WriteAppearance(const CFX_ByteString& sAPType, const CPDF_Re
ct& rcBBox, | 1012 |
1000 const CPDF_Matri
x& matrix, const CFX_ByteString& sContents, | 1013 pStream->SetData( |
1001 const CFX_ByteSt
ring& sAPState) | 1014 (FX_BYTE*)(FX_LPCSTR) sContents, sContents.GetLength(), FALSE, FALSE); |
1002 { | 1015 } |
1003 ASSERT(m_pAnnot != NULL); | 1016 |
1004 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 1017 #define BA_ANNOT_MINWIDTH 1 |
1005 | 1018 #define BA_ANNOT_MINHEIGHT 1 |
1006 CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP"); | 1019 |
1007 | 1020 FX_FLOAT CPDFSDK_Annot::GetMinWidth() const { |
1008 if (!pAPDict) | 1021 return BA_ANNOT_MINWIDTH; |
1009 { | 1022 } |
1010 pAPDict = FX_NEW CPDF_Dictionary; | 1023 |
1011 m_pAnnot->m_pAnnotDict->SetAt("AP", pAPDict); | 1024 FX_FLOAT CPDFSDK_Annot::GetMinHeight() const { |
1012 } | 1025 return BA_ANNOT_MINHEIGHT; |
1013 | 1026 } |
1014 CPDF_Stream* pStream = NULL; | 1027 |
1015 CPDF_Dictionary* pParentDict = NULL; | 1028 FX_BOOL CPDFSDK_Annot::CreateFormFiller() { |
1016 | 1029 return TRUE; |
1017 if (sAPState.IsEmpty()) | 1030 } |
1018 { | 1031 FX_BOOL CPDFSDK_Annot::IsVisible() const { |
1019 pParentDict = pAPDict; | 1032 int nFlags = GetFlags(); |
1020 pStream = pAPDict->GetStream(sAPType); | 1033 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || |
1021 } | 1034 (nFlags & ANNOTFLAG_NOVIEW)); |
1022 else | 1035 } |
1023 { | 1036 |
1024 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDict(sAPType); | 1037 CPDF_Action CPDFSDK_Annot::GetAction() const { |
1025 if (!pAPTypeDict) | 1038 ASSERT(m_pAnnot != NULL); |
1026 { | 1039 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
1027 pAPTypeDict = FX_NEW CPDF_Dictionary; | 1040 |
1028 pAPDict->SetAt(sAPType, pAPTypeDict); | 1041 return m_pAnnot->m_pAnnotDict->GetDict("A"); |
1029 } | 1042 } |
1030 | 1043 |
1031 pParentDict = pAPTypeDict; | 1044 void CPDFSDK_Annot::SetAction(const CPDF_Action& action) { |
1032 pStream = pAPTypeDict->GetStream(sAPState); | 1045 ASSERT(m_pAnnot != NULL); |
1033 } | 1046 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
1034 | 1047 |
1035 if (!pStream) | 1048 ASSERT(action != NULL); |
1036 { | 1049 |
1037 ASSERT(m_pPageView != NULL); | 1050 if ((CPDF_Action&)action != m_pAnnot->m_pAnnotDict->GetDict("A")) { |
1038 CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); | 1051 CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
1039 ASSERT(pDoc != NULL); | 1052 ASSERT(pDoc != NULL); |
1040 | 1053 |
1041 pStream = FX_NEW CPDF_Stream(NULL, 0, NULL); | 1054 if (action.m_pDict && (action.m_pDict->GetObjNum() == 0)) |
1042 FX_INT32 objnum = pDoc->AddIndirectObject(pStream); | 1055 pDoc->AddIndirectObject(action.m_pDict); |
1043 //pAPDict->SetAtReference(sAPType, pDoc, objnum); | 1056 m_pAnnot->m_pAnnotDict->SetAtReference( |
1044 ASSERT(pParentDict != NULL); | 1057 "A", pDoc, action.m_pDict->GetObjNum()); |
1045 pParentDict->SetAtReference(sAPType, pDoc, objnum); | 1058 } |
1046 } | 1059 } |
1047 | 1060 |
1048 CPDF_Dictionary * pStreamDict = pStream->GetDict(); | 1061 void CPDFSDK_Annot::RemoveAction() { |
1049 | 1062 ASSERT(m_pAnnot != NULL); |
1050 if (!pStreamDict) | 1063 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
1051 { | 1064 |
1052 pStreamDict = FX_NEW CPDF_Dictionary; | 1065 m_pAnnot->m_pAnnotDict->RemoveAt("A"); |
1053 pStreamDict->SetAtName("Type", "XObject"); | 1066 } |
1054 pStreamDict->SetAtName("Subtype", "Form"); | 1067 |
1055 pStreamDict->SetAtInteger("FormType", 1); | 1068 CPDF_AAction CPDFSDK_Annot::GetAAction() const { |
1056 pStream->InitStream(NULL,0,pStreamDict); | 1069 ASSERT(m_pAnnot != NULL); |
1057 } | 1070 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
1058 | 1071 |
1059 if (pStreamDict) | 1072 return m_pAnnot->m_pAnnotDict->GetDict("AA"); |
1060 { | 1073 } |
1061 pStreamDict->SetAtMatrix("Matrix",matrix); | 1074 |
1062 pStreamDict->SetAtRect("BBox", rcBBox); | 1075 void CPDFSDK_Annot::SetAAction(const CPDF_AAction& aa) { |
1063 } | 1076 ASSERT(m_pAnnot != NULL); |
1064 | 1077 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
1065 pStream->SetData((FX_BYTE*)(FX_LPCSTR)sContents, sContents.GetLength(),
FALSE, FALSE); | 1078 ASSERT(aa != NULL); |
1066 } | 1079 |
1067 | 1080 if ((CPDF_AAction&)aa != m_pAnnot->m_pAnnotDict->GetDict("AA")) |
1068 #define BA_ANNOT_MINWIDTH 1 | 1081 m_pAnnot->m_pAnnotDict->SetAt("AA", (CPDF_AAction&)aa); |
1069 #define BA_ANNOT_MINHEIGHT 1 | 1082 } |
1070 | 1083 |
1071 FX_FLOAT CPDFSDK_Annot::GetMinWidth() const | 1084 void CPDFSDK_Annot::RemoveAAction() { |
1072 { | 1085 ASSERT(m_pAnnot != NULL); |
1073 return BA_ANNOT_MINWIDTH; | 1086 ASSERT(m_pAnnot->m_pAnnotDict != NULL); |
1074 } | 1087 |
1075 | 1088 m_pAnnot->m_pAnnotDict->RemoveAt("AA"); |
1076 FX_FLOAT CPDFSDK_Annot::GetMinHeight() const | 1089 } |
1077 { | 1090 |
1078 return BA_ANNOT_MINHEIGHT; | 1091 CPDF_Action CPDFSDK_Annot::GetAAction(CPDF_AAction::AActionType eAAT) { |
1079 } | 1092 CPDF_AAction AAction = GetAAction(); |
1080 | 1093 |
1081 FX_BOOL CPDFSDK_Annot::CreateFormFiller() | 1094 if (AAction.ActionExist(eAAT)) { |
1082 { | 1095 return AAction.GetAction(eAAT); |
1083 return TRUE; | 1096 } else if (eAAT == CPDF_AAction::ButtonUp) { |
1084 } | 1097 return GetAction(); |
1085 FX_BOOL CPDFSDK_Annot::IsVisible() const | 1098 } |
1086 { | 1099 |
1087 int nFlags = GetFlags(); | 1100 return NULL; |
1088 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) |
| (nFlags & ANNOTFLAG_NOVIEW)); | 1101 } |
1089 } | 1102 |
1090 | 1103 void CPDFSDK_Annot::Annot_OnDraw(CFX_RenderDevice* pDevice, |
1091 CPDF_Action CPDFSDK_Annot::GetAction() const | 1104 CPDF_Matrix* pUser2Device, |
1092 { | 1105 CPDF_RenderOptions* pOptions) { |
1093 ASSERT(m_pAnnot != NULL); | 1106 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal); |
1094 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 1107 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), |
1095 | 1108 pDevice, |
1096 return m_pAnnot->m_pAnnotDict->GetDict("A"); | 1109 pUser2Device, |
1097 } | 1110 CPDF_Annot::Normal, |
1098 | 1111 NULL); |
1099 void CPDFSDK_Annot::SetAction(const CPDF_Action& action) | 1112 |
1100 { | 1113 return; |
1101 ASSERT(m_pAnnot != NULL); | 1114 } |
1102 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | 1115 |
1103 | 1116 CPDF_Page* CPDFSDK_Annot::GetPDFPage() { |
1104 ASSERT(action != NULL); | 1117 if (m_pPageView) |
1105 | 1118 return m_pPageView->GetPDFPage(); |
1106 if ((CPDF_Action&)action != m_pAnnot->m_pAnnotDict->GetDict("A")) | 1119 return NULL; |
1107 { | 1120 } |
1108 CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); | |
1109 ASSERT(pDoc != NULL); | |
1110 | |
1111 if (action.m_pDict && (action.m_pDict->GetObjNum() == 0)) | |
1112 pDoc->AddIndirectObject(action.m_pDict); | |
1113 m_pAnnot->m_pAnnotDict->SetAtReference("A", pDoc, action.m_pDict
->GetObjNum()); | |
1114 } | |
1115 } | |
1116 | |
1117 void CPDFSDK_Annot::RemoveAction() | |
1118 { | |
1119 ASSERT(m_pAnnot != NULL); | |
1120 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | |
1121 | |
1122 m_pAnnot->m_pAnnotDict->RemoveAt("A"); | |
1123 } | |
1124 | |
1125 CPDF_AAction CPDFSDK_Annot::GetAAction() const | |
1126 { | |
1127 ASSERT(m_pAnnot != NULL); | |
1128 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | |
1129 | |
1130 return m_pAnnot->m_pAnnotDict->GetDict("AA"); | |
1131 } | |
1132 | |
1133 void CPDFSDK_Annot::SetAAction(const CPDF_AAction& aa) | |
1134 { | |
1135 ASSERT(m_pAnnot != NULL); | |
1136 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | |
1137 ASSERT(aa != NULL); | |
1138 | |
1139 if ((CPDF_AAction&)aa != m_pAnnot->m_pAnnotDict->GetDict("AA")) | |
1140 m_pAnnot->m_pAnnotDict->SetAt("AA", (CPDF_AAction&)aa); | |
1141 } | |
1142 | |
1143 void CPDFSDK_Annot::RemoveAAction() | |
1144 { | |
1145 ASSERT(m_pAnnot != NULL); | |
1146 ASSERT(m_pAnnot->m_pAnnotDict != NULL); | |
1147 | |
1148 m_pAnnot->m_pAnnotDict->RemoveAt("AA"); | |
1149 } | |
1150 | |
1151 CPDF_Action CPDFSDK_Annot::GetAAction(CPDF_AAction::AActionType eAAT) | |
1152 { | |
1153 CPDF_AAction AAction = GetAAction(); | |
1154 | |
1155 if (AAction.ActionExist(eAAT)) | |
1156 { | |
1157 return AAction.GetAction(eAAT); | |
1158 } | |
1159 else if (eAAT == CPDF_AAction::ButtonUp) | |
1160 { | |
1161 return GetAction(); | |
1162 } | |
1163 | |
1164 return NULL; | |
1165 } | |
1166 | |
1167 void CPDFSDK_Annot::Annot_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2
Device, CPDF_RenderOptions* pOptions) | |
1168 { | |
1169 | |
1170 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal); | |
1171 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Devic
e, CPDF_Annot::Normal, NULL); | |
1172 | |
1173 return ; | |
1174 } | |
1175 | |
1176 CPDF_Page* CPDFSDK_Annot::GetPDFPage() | |
1177 { | |
1178 if(m_pPageView) | |
1179 return m_pPageView->GetPDFPage(); | |
1180 return NULL; | |
1181 } | |
1182 | |
OLD | NEW |