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/fpdfdoc/fpdf_doc.h" | 7 #include "../../include/fpdfdoc/fpdf_doc.h" |
8 #include "doc_utils.h" | 8 #include "doc_utils.h" |
9 | 9 |
10 static const int FPDFDOC_UTILS_MAXRECURSION = 32; | 10 static const int FPDFDOC_UTILS_MAXRECURSION = 32; |
11 | 11 |
12 CFX_WideString GetFullName(CPDF_Dictionary* pFieldDict) | 12 CFX_WideString GetFullName(CPDF_Dictionary* pFieldDict) { |
13 { | 13 CFX_WideString full_name; |
14 CFX_WideString full_name; | 14 CPDF_Dictionary* pLevel = pFieldDict; |
15 CPDF_Dictionary* pLevel = pFieldDict; | 15 while (pLevel) { |
16 while (pLevel) { | 16 CFX_WideString short_name = pLevel->GetUnicodeText("T"); |
17 CFX_WideString short_name = pLevel->GetUnicodeText("T"); | 17 if (short_name != L"") { |
18 if (short_name != L"") { | 18 if (full_name == L"") { |
19 if (full_name == L"") { | 19 full_name = short_name; |
20 full_name = short_name; | 20 } else { |
21 } else { | 21 full_name = short_name + L"." + full_name; |
22 full_name = short_name + L"." + full_name; | 22 } |
23 } | 23 } |
| 24 pLevel = pLevel->GetDict("Parent"); |
| 25 } |
| 26 return full_name; |
| 27 } |
| 28 FX_BOOL CPDF_DefaultAppearance::HasFont() { |
| 29 if (m_csDA.IsEmpty()) { |
| 30 return FALSE; |
| 31 } |
| 32 CPDF_SimpleParser syntax(m_csDA); |
| 33 return syntax.FindTagParam("Tf", 2); |
| 34 } |
| 35 CFX_ByteString CPDF_DefaultAppearance::GetFontString() { |
| 36 CFX_ByteString csFont; |
| 37 if (m_csDA.IsEmpty()) { |
| 38 return csFont; |
| 39 } |
| 40 CPDF_SimpleParser syntax(m_csDA); |
| 41 if (syntax.FindTagParam("Tf", 2)) { |
| 42 csFont += (CFX_ByteString)syntax.GetWord(); |
| 43 csFont += " "; |
| 44 csFont += (CFX_ByteString)syntax.GetWord(); |
| 45 csFont += " "; |
| 46 csFont += (CFX_ByteString)syntax.GetWord(); |
| 47 } |
| 48 return csFont; |
| 49 } |
| 50 void CPDF_DefaultAppearance::GetFont(CFX_ByteString& csFontNameTag, |
| 51 FX_FLOAT& fFontSize) { |
| 52 csFontNameTag = ""; |
| 53 fFontSize = 0; |
| 54 if (m_csDA.IsEmpty()) { |
| 55 return; |
| 56 } |
| 57 CPDF_SimpleParser syntax(m_csDA); |
| 58 if (syntax.FindTagParam("Tf", 2)) { |
| 59 csFontNameTag = (CFX_ByteString)syntax.GetWord(); |
| 60 csFontNameTag.Delete(0, 1); |
| 61 fFontSize = FX_atof((CFX_ByteString)syntax.GetWord()); |
| 62 } |
| 63 csFontNameTag = PDF_NameDecode(csFontNameTag); |
| 64 } |
| 65 FX_BOOL CPDF_DefaultAppearance::HasColor(FX_BOOL bStrokingOperation) { |
| 66 if (m_csDA.IsEmpty()) { |
| 67 return FALSE; |
| 68 } |
| 69 CPDF_SimpleParser syntax(m_csDA); |
| 70 if (syntax.FindTagParam(bStrokingOperation ? "G" : "g", 1)) { |
| 71 return TRUE; |
| 72 } |
| 73 syntax.SetPos(0); |
| 74 if (syntax.FindTagParam(bStrokingOperation ? "RG" : "rg", 3)) { |
| 75 return TRUE; |
| 76 } |
| 77 syntax.SetPos(0); |
| 78 return syntax.FindTagParam(bStrokingOperation ? "K" : "k", 4); |
| 79 } |
| 80 CFX_ByteString CPDF_DefaultAppearance::GetColorString( |
| 81 FX_BOOL bStrokingOperation) { |
| 82 CFX_ByteString csColor; |
| 83 if (m_csDA.IsEmpty()) { |
| 84 return csColor; |
| 85 } |
| 86 CPDF_SimpleParser syntax(m_csDA); |
| 87 if (syntax.FindTagParam(bStrokingOperation ? "G" : "g", 1)) { |
| 88 csColor += (CFX_ByteString)syntax.GetWord(); |
| 89 csColor += " "; |
| 90 csColor += (CFX_ByteString)syntax.GetWord(); |
| 91 return csColor; |
| 92 } |
| 93 syntax.SetPos(0); |
| 94 if (syntax.FindTagParam(bStrokingOperation ? "RG" : "rg", 3)) { |
| 95 csColor += (CFX_ByteString)syntax.GetWord(); |
| 96 csColor += " "; |
| 97 csColor += (CFX_ByteString)syntax.GetWord(); |
| 98 csColor += " "; |
| 99 csColor += (CFX_ByteString)syntax.GetWord(); |
| 100 csColor += " "; |
| 101 csColor += (CFX_ByteString)syntax.GetWord(); |
| 102 return csColor; |
| 103 } |
| 104 syntax.SetPos(0); |
| 105 if (syntax.FindTagParam(bStrokingOperation ? "K" : "k", 4)) { |
| 106 csColor += (CFX_ByteString)syntax.GetWord(); |
| 107 csColor += " "; |
| 108 csColor += (CFX_ByteString)syntax.GetWord(); |
| 109 csColor += " "; |
| 110 csColor += (CFX_ByteString)syntax.GetWord(); |
| 111 csColor += " "; |
| 112 csColor += (CFX_ByteString)syntax.GetWord(); |
| 113 csColor += " "; |
| 114 csColor += (CFX_ByteString)syntax.GetWord(); |
| 115 } |
| 116 return csColor; |
| 117 } |
| 118 void CPDF_DefaultAppearance::GetColor(int& iColorType, |
| 119 FX_FLOAT fc[4], |
| 120 FX_BOOL bStrokingOperation) { |
| 121 iColorType = COLORTYPE_TRANSPARENT; |
| 122 for (int c = 0; c < 4; c++) { |
| 123 fc[c] = 0; |
| 124 } |
| 125 if (m_csDA.IsEmpty()) { |
| 126 return; |
| 127 } |
| 128 CPDF_SimpleParser syntax(m_csDA); |
| 129 if (syntax.FindTagParam(bStrokingOperation ? "G" : "g", 1)) { |
| 130 iColorType = COLORTYPE_GRAY; |
| 131 fc[0] = FX_atof((CFX_ByteString)syntax.GetWord()); |
| 132 return; |
| 133 } |
| 134 syntax.SetPos(0); |
| 135 if (syntax.FindTagParam(bStrokingOperation ? "RG" : "rg", 3)) { |
| 136 iColorType = COLORTYPE_RGB; |
| 137 fc[0] = FX_atof((CFX_ByteString)syntax.GetWord()); |
| 138 fc[1] = FX_atof((CFX_ByteString)syntax.GetWord()); |
| 139 fc[2] = FX_atof((CFX_ByteString)syntax.GetWord()); |
| 140 return; |
| 141 } |
| 142 syntax.SetPos(0); |
| 143 if (syntax.FindTagParam(bStrokingOperation ? "K" : "k", 4)) { |
| 144 iColorType = COLORTYPE_CMYK; |
| 145 fc[0] = FX_atof((CFX_ByteString)syntax.GetWord()); |
| 146 fc[1] = FX_atof((CFX_ByteString)syntax.GetWord()); |
| 147 fc[2] = FX_atof((CFX_ByteString)syntax.GetWord()); |
| 148 fc[3] = FX_atof((CFX_ByteString)syntax.GetWord()); |
| 149 } |
| 150 } |
| 151 void CPDF_DefaultAppearance::GetColor(FX_ARGB& color, |
| 152 int& iColorType, |
| 153 FX_BOOL bStrokingOperation) { |
| 154 color = 0; |
| 155 iColorType = COLORTYPE_TRANSPARENT; |
| 156 if (m_csDA.IsEmpty()) { |
| 157 return; |
| 158 } |
| 159 CPDF_SimpleParser syntax(m_csDA); |
| 160 if (syntax.FindTagParam(bStrokingOperation ? "G" : "g", 1)) { |
| 161 iColorType = COLORTYPE_GRAY; |
| 162 FX_FLOAT g = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f; |
| 163 color = ArgbEncode(255, (int)g, (int)g, (int)g); |
| 164 return; |
| 165 } |
| 166 syntax.SetPos(0); |
| 167 if (syntax.FindTagParam(bStrokingOperation ? "RG" : "rg", 3)) { |
| 168 iColorType = COLORTYPE_RGB; |
| 169 FX_FLOAT r = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f; |
| 170 FX_FLOAT g = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f; |
| 171 FX_FLOAT b = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f; |
| 172 color = ArgbEncode(255, (int)r, (int)g, (int)b); |
| 173 return; |
| 174 } |
| 175 syntax.SetPos(0); |
| 176 if (syntax.FindTagParam(bStrokingOperation ? "K" : "k", 4)) { |
| 177 iColorType = COLORTYPE_CMYK; |
| 178 FX_FLOAT c = FX_atof((CFX_ByteString)syntax.GetWord()); |
| 179 FX_FLOAT m = FX_atof((CFX_ByteString)syntax.GetWord()); |
| 180 FX_FLOAT y = FX_atof((CFX_ByteString)syntax.GetWord()); |
| 181 FX_FLOAT k = FX_atof((CFX_ByteString)syntax.GetWord()); |
| 182 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k); |
| 183 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k); |
| 184 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k); |
| 185 color = ArgbEncode(255, (int)(r * 255 + 0.5f), (int)(g * 255 + 0.5f), |
| 186 (int)(b * 255 + 0.5f)); |
| 187 } |
| 188 } |
| 189 FX_BOOL CPDF_DefaultAppearance::HasTextMatrix() { |
| 190 if (m_csDA.IsEmpty()) { |
| 191 return FALSE; |
| 192 } |
| 193 CPDF_SimpleParser syntax(m_csDA); |
| 194 return syntax.FindTagParam("Tm", 6); |
| 195 } |
| 196 CFX_ByteString CPDF_DefaultAppearance::GetTextMatrixString() { |
| 197 CFX_ByteString csTM; |
| 198 if (m_csDA.IsEmpty()) { |
| 199 return csTM; |
| 200 } |
| 201 CPDF_SimpleParser syntax(m_csDA); |
| 202 if (syntax.FindTagParam("Tm", 6)) { |
| 203 for (int i = 0; i < 6; i++) { |
| 204 csTM += (CFX_ByteString)syntax.GetWord(); |
| 205 csTM += " "; |
| 206 } |
| 207 csTM += (CFX_ByteString)syntax.GetWord(); |
| 208 } |
| 209 return csTM; |
| 210 } |
| 211 CFX_AffineMatrix CPDF_DefaultAppearance::GetTextMatrix() { |
| 212 CFX_AffineMatrix tm; |
| 213 if (m_csDA.IsEmpty()) { |
| 214 return tm; |
| 215 } |
| 216 CPDF_SimpleParser syntax(m_csDA); |
| 217 if (syntax.FindTagParam("Tm", 6)) { |
| 218 FX_FLOAT f[6]; |
| 219 for (int i = 0; i < 6; i++) { |
| 220 f[i] = FX_atof((CFX_ByteString)syntax.GetWord()); |
| 221 } |
| 222 tm.Set(f[0], f[1], f[2], f[3], f[4], f[5]); |
| 223 } |
| 224 return tm; |
| 225 } |
| 226 void InitInterFormDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { |
| 227 if (pDocument == NULL) { |
| 228 return; |
| 229 } |
| 230 if (pFormDict == NULL) { |
| 231 pFormDict = CPDF_Dictionary::Create(); |
| 232 if (pFormDict == NULL) { |
| 233 return; |
| 234 } |
| 235 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pFormDict); |
| 236 CPDF_Dictionary* pRoot = pDocument->GetRoot(); |
| 237 pRoot->SetAtReference("AcroForm", pDocument, dwObjNum); |
| 238 } |
| 239 CFX_ByteString csDA; |
| 240 if (!pFormDict->KeyExist("DR")) { |
| 241 CPDF_Font* pFont = NULL; |
| 242 CFX_ByteString csBaseName, csDefault; |
| 243 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); |
| 244 pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); |
| 245 if (pFont != NULL) { |
| 246 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); |
| 247 csDefault = csBaseName; |
| 248 } |
| 249 if (charSet != 0) { |
| 250 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet, NULL); |
| 251 if (pFont == NULL || csFontName != "Helvetica") { |
| 252 pFont = CPDF_InterForm::AddNativeFont(pDocument); |
| 253 if (pFont != NULL) { |
| 254 csBaseName = ""; |
| 255 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); |
| 256 csDefault = csBaseName; |
24 } | 257 } |
25 pLevel = pLevel->GetDict("Parent"); | 258 } |
26 } | 259 } |
27 return full_name; | 260 if (pFont != NULL) { |
28 } | 261 csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf"; |
29 FX_BOOL CPDF_DefaultAppearance::HasFont() | 262 } |
30 { | 263 } |
31 if (m_csDA.IsEmpty()) { | 264 if (!csDA.IsEmpty()) { |
32 return FALSE; | 265 csDA += " "; |
33 } | 266 } |
34 CPDF_SimpleParser syntax(m_csDA); | 267 csDA += "0 g"; |
35 return syntax.FindTagParam("Tf", 2); | 268 if (!pFormDict->KeyExist("DA")) { |
36 } | 269 pFormDict->SetAtString("DA", csDA); |
37 CFX_ByteString CPDF_DefaultAppearance::GetFontString() | 270 } |
38 { | 271 } |
39 CFX_ByteString csFont; | 272 FX_DWORD CountInterFormFonts(CPDF_Dictionary* pFormDict) { |
40 if (m_csDA.IsEmpty()) { | 273 if (pFormDict == NULL) { |
41 return csFont; | 274 return 0; |
42 } | 275 } |
43 CPDF_SimpleParser syntax(m_csDA); | 276 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
44 if (syntax.FindTagParam("Tf", 2)) { | 277 if (pDR == NULL) { |
45 csFont += (CFX_ByteString)syntax.GetWord(); | 278 return 0; |
46 csFont += " "; | 279 } |
47 csFont += (CFX_ByteString)syntax.GetWord(); | 280 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
48 csFont += " "; | 281 if (pFonts == NULL) { |
49 csFont += (CFX_ByteString)syntax.GetWord(); | 282 return 0; |
50 } | 283 } |
51 return csFont; | 284 FX_DWORD dwCount = 0; |
52 } | 285 FX_POSITION pos = pFonts->GetStartPos(); |
53 void CPDF_DefaultAppearance::GetFont(CFX_ByteString& csFontNameTag, FX_FLOAT& fF
ontSize) | 286 while (pos) { |
54 { | 287 CPDF_Object* pObj = NULL; |
55 csFontNameTag = ""; | 288 CFX_ByteString csKey; |
56 fFontSize = 0; | 289 pObj = pFonts->GetNextElement(pos, csKey); |
57 if (m_csDA.IsEmpty()) { | 290 if (pObj == NULL) { |
58 return; | 291 continue; |
59 } | 292 } |
60 CPDF_SimpleParser syntax(m_csDA); | 293 CPDF_Object* pDirect = pObj->GetDirect(); |
61 if (syntax.FindTagParam("Tf", 2)) { | 294 if (pDirect != NULL && pDirect->GetType() == PDFOBJ_DICTIONARY) { |
62 csFontNameTag = (CFX_ByteString)syntax.GetWord(); | 295 if (((CPDF_Dictionary*)pDirect)->GetString("Type") == "Font") { |
63 csFontNameTag.Delete(0, 1); | 296 dwCount++; |
64 fFontSize = FX_atof((CFX_ByteString)syntax.GetWord()); | 297 } |
65 } | 298 } |
66 csFontNameTag = PDF_NameDecode(csFontNameTag); | 299 } |
67 } | 300 return dwCount; |
68 FX_BOOL CPDF_DefaultAppearance::HasColor(FX_BOOL bStrokingOperation) | 301 } |
69 { | 302 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, |
70 if (m_csDA.IsEmpty()) { | 303 CPDF_Document* pDocument, |
71 return FALSE; | 304 FX_DWORD index, |
72 } | 305 CFX_ByteString& csNameTag) { |
73 CPDF_SimpleParser syntax(m_csDA); | 306 if (pFormDict == NULL) { |
74 if (syntax.FindTagParam(bStrokingOperation ? "G" : "g", 1)) { | 307 return NULL; |
75 return TRUE; | 308 } |
76 } | 309 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
77 syntax.SetPos(0); | 310 if (pDR == NULL) { |
78 if (syntax.FindTagParam(bStrokingOperation ? "RG" : "rg", 3)) { | 311 return NULL; |
79 return TRUE; | 312 } |
80 } | 313 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
81 syntax.SetPos(0); | 314 if (pFonts == NULL) { |
82 return syntax.FindTagParam(bStrokingOperation ? "K" : "k", 4); | 315 return NULL; |
83 } | 316 } |
84 CFX_ByteString CPDF_DefaultAppearance::GetColorString(FX_BOOL bStrokingOperation
) | 317 FX_DWORD dwCount = 0; |
85 { | 318 FX_POSITION pos = pFonts->GetStartPos(); |
86 CFX_ByteString csColor; | 319 while (pos) { |
87 if (m_csDA.IsEmpty()) { | 320 CPDF_Object* pObj = NULL; |
88 return csColor; | 321 CFX_ByteString csKey; |
89 } | 322 pObj = pFonts->GetNextElement(pos, csKey); |
90 CPDF_SimpleParser syntax(m_csDA); | 323 if (pObj == NULL) { |
91 if (syntax.FindTagParam(bStrokingOperation ? "G" : "g", 1)) { | 324 continue; |
92 csColor += (CFX_ByteString)syntax.GetWord(); | 325 } |
93 csColor += " "; | 326 CPDF_Object* pDirect = pObj->GetDirect(); |
94 csColor += (CFX_ByteString)syntax.GetWord(); | 327 if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) { |
95 return csColor; | 328 continue; |
96 } | 329 } |
97 syntax.SetPos(0); | 330 CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect; |
98 if (syntax.FindTagParam(bStrokingOperation ? "RG" : "rg", 3)) { | 331 if (pElement->GetString("Type") != "Font") { |
99 csColor += (CFX_ByteString)syntax.GetWord(); | 332 continue; |
100 csColor += " "; | 333 } |
101 csColor += (CFX_ByteString)syntax.GetWord(); | 334 if (dwCount == index) { |
102 csColor += " "; | 335 csNameTag = csKey; |
103 csColor += (CFX_ByteString)syntax.GetWord(); | 336 return pDocument->LoadFont(pElement); |
104 csColor += " "; | 337 } |
105 csColor += (CFX_ByteString)syntax.GetWord(); | 338 dwCount++; |
106 return csColor; | 339 } |
107 } | 340 return NULL; |
108 syntax.SetPos(0); | 341 } |
109 if (syntax.FindTagParam(bStrokingOperation ? "K" : "k", 4)) { | 342 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, |
110 csColor += (CFX_ByteString)syntax.GetWord(); | 343 CPDF_Document* pDocument, |
111 csColor += " "; | 344 CFX_ByteString csNameTag) { |
112 csColor += (CFX_ByteString)syntax.GetWord(); | 345 CFX_ByteString csAlias = PDF_NameDecode(csNameTag); |
113 csColor += " "; | 346 if (pFormDict == NULL || csAlias.IsEmpty()) { |
114 csColor += (CFX_ByteString)syntax.GetWord(); | 347 return NULL; |
115 csColor += " "; | 348 } |
116 csColor += (CFX_ByteString)syntax.GetWord(); | 349 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
117 csColor += " "; | 350 if (pDR == NULL) { |
118 csColor += (CFX_ByteString)syntax.GetWord(); | 351 return NULL; |
119 } | 352 } |
120 return csColor; | 353 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
121 } | 354 if (pFonts == NULL) { |
122 void CPDF_DefaultAppearance::GetColor(int& iColorType, FX_FLOAT fc[4], FX_BOOL b
StrokingOperation) | 355 return NULL; |
123 { | 356 } |
124 iColorType = COLORTYPE_TRANSPARENT; | 357 CPDF_Dictionary* pElement = pFonts->GetDict(csAlias); |
125 for (int c = 0; c < 4; c ++) { | 358 if (pElement == NULL) { |
126 fc[c] = 0; | 359 return NULL; |
127 } | 360 } |
128 if (m_csDA.IsEmpty()) { | 361 if (pElement->GetString("Type") == "Font") { |
129 return; | 362 return pDocument->LoadFont(pElement); |
130 } | 363 } |
131 CPDF_SimpleParser syntax(m_csDA); | 364 return NULL; |
132 if (syntax.FindTagParam(bStrokingOperation ? "G" : "g", 1)) { | 365 } |
133 iColorType = COLORTYPE_GRAY; | 366 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, |
134 fc[0] = FX_atof((CFX_ByteString)syntax.GetWord()); | 367 CPDF_Document* pDocument, |
135 return; | 368 CFX_ByteString csFontName, |
136 } | 369 CFX_ByteString& csNameTag) { |
137 syntax.SetPos(0); | 370 if (pFormDict == NULL || csFontName.IsEmpty()) { |
138 if (syntax.FindTagParam(bStrokingOperation ? "RG" : "rg", 3)) { | 371 return NULL; |
139 iColorType = COLORTYPE_RGB; | 372 } |
140 fc[0] = FX_atof((CFX_ByteString)syntax.GetWord()); | 373 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
141 fc[1] = FX_atof((CFX_ByteString)syntax.GetWord()); | 374 if (pDR == NULL) { |
142 fc[2] = FX_atof((CFX_ByteString)syntax.GetWord()); | 375 return NULL; |
143 return; | 376 } |
144 } | 377 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
145 syntax.SetPos(0); | 378 if (pFonts == NULL) { |
146 if (syntax.FindTagParam(bStrokingOperation ? "K" : "k", 4)) { | 379 return NULL; |
147 iColorType = COLORTYPE_CMYK; | 380 } |
148 fc[0] = FX_atof((CFX_ByteString)syntax.GetWord()); | 381 FX_POSITION pos = pFonts->GetStartPos(); |
149 fc[1] = FX_atof((CFX_ByteString)syntax.GetWord()); | 382 while (pos) { |
150 fc[2] = FX_atof((CFX_ByteString)syntax.GetWord()); | 383 CPDF_Object* pObj = NULL; |
151 fc[3] = FX_atof((CFX_ByteString)syntax.GetWord()); | 384 CFX_ByteString csKey; |
152 } | 385 pObj = pFonts->GetNextElement(pos, csKey); |
153 } | 386 if (pObj == NULL) { |
154 void CPDF_DefaultAppearance::GetColor(FX_ARGB& color, int& iColorType, FX_BOOL b
StrokingOperation) | 387 continue; |
155 { | 388 } |
156 color = 0; | 389 CPDF_Object* pDirect = pObj->GetDirect(); |
157 iColorType = COLORTYPE_TRANSPARENT; | 390 if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) { |
158 if (m_csDA.IsEmpty()) { | 391 continue; |
159 return; | 392 } |
160 } | 393 CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect; |
161 CPDF_SimpleParser syntax(m_csDA); | 394 if (pElement->GetString("Type") != "Font") { |
162 if (syntax.FindTagParam(bStrokingOperation ? "G" : "g", 1)) { | 395 continue; |
163 iColorType = COLORTYPE_GRAY; | 396 } |
164 FX_FLOAT g = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f; | 397 CPDF_Font* pFind = pDocument->LoadFont(pElement); |
165 color = ArgbEncode(255, (int)g, (int)g, (int)g); | 398 if (pFind == NULL) { |
166 return; | 399 continue; |
167 } | 400 } |
168 syntax.SetPos(0); | 401 CFX_ByteString csBaseFont; |
169 if (syntax.FindTagParam(bStrokingOperation ? "RG" : "rg", 3)) { | 402 csBaseFont = pFind->GetBaseFont(); |
170 iColorType = COLORTYPE_RGB; | 403 csBaseFont.Remove(' '); |
171 FX_FLOAT r = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f; | 404 if (csBaseFont == csFontName) { |
172 FX_FLOAT g = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f; | 405 csNameTag = csKey; |
173 FX_FLOAT b = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f; | 406 return pFind; |
174 color = ArgbEncode(255, (int)r, (int)g, (int)b); | 407 } |
175 return; | 408 } |
176 } | 409 return NULL; |
177 syntax.SetPos(0); | 410 } |
178 if (syntax.FindTagParam(bStrokingOperation ? "K" : "k", 4)) { | 411 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, |
179 iColorType = COLORTYPE_CMYK; | 412 CPDF_Document* pDocument, |
180 FX_FLOAT c = FX_atof((CFX_ByteString)syntax.GetWord()); | 413 uint8_t charSet, |
181 FX_FLOAT m = FX_atof((CFX_ByteString)syntax.GetWord()); | 414 CFX_ByteString& csNameTag) { |
182 FX_FLOAT y = FX_atof((CFX_ByteString)syntax.GetWord()); | 415 if (pFormDict == NULL) { |
183 FX_FLOAT k = FX_atof((CFX_ByteString)syntax.GetWord()); | 416 return NULL; |
184 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k); | 417 } |
185 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k); | 418 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
186 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k); | 419 if (pDR == NULL) { |
187 color = ArgbEncode(255, (int)(r * 255 + 0.5f), (int)(g * 255 + 0.5f), (i
nt)(b * 255 + 0.5f)); | 420 return NULL; |
188 } | 421 } |
189 } | 422 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
190 FX_BOOL CPDF_DefaultAppearance::HasTextMatrix() | 423 if (pFonts == NULL) { |
191 { | 424 return NULL; |
192 if (m_csDA.IsEmpty()) { | 425 } |
193 return FALSE; | 426 FX_POSITION pos = pFonts->GetStartPos(); |
194 } | 427 while (pos) { |
195 CPDF_SimpleParser syntax(m_csDA); | 428 CPDF_Object* pObj = NULL; |
196 return syntax.FindTagParam("Tm", 6); | 429 CFX_ByteString csKey; |
197 } | 430 pObj = pFonts->GetNextElement(pos, csKey); |
198 CFX_ByteString CPDF_DefaultAppearance::GetTextMatrixString() | 431 if (pObj == NULL) { |
199 { | 432 continue; |
200 CFX_ByteString csTM; | 433 } |
201 if (m_csDA.IsEmpty()) { | 434 CPDF_Object* pDirect = pObj->GetDirect(); |
202 return csTM; | 435 if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) { |
203 } | 436 continue; |
204 CPDF_SimpleParser syntax(m_csDA); | 437 } |
205 if (syntax.FindTagParam("Tm", 6)) { | 438 CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect; |
206 for (int i = 0; i < 6; i ++) { | 439 if (pElement->GetString("Type") != "Font") { |
207 csTM += (CFX_ByteString)syntax.GetWord(); | 440 continue; |
208 csTM += " "; | 441 } |
209 } | 442 CPDF_Font* pFind = pDocument->LoadFont(pElement); |
210 csTM += (CFX_ByteString)syntax.GetWord(); | 443 if (pFind == NULL) { |
211 } | 444 continue; |
212 return csTM; | 445 } |
213 } | 446 CFX_SubstFont* pSubst = (CFX_SubstFont*)pFind->GetSubstFont(); |
214 CFX_AffineMatrix CPDF_DefaultAppearance::GetTextMatrix() | 447 if (pSubst == NULL) { |
215 { | 448 continue; |
216 CFX_AffineMatrix tm; | 449 } |
217 if (m_csDA.IsEmpty()) { | 450 if (pSubst->m_Charset == (int)charSet) { |
218 return tm; | 451 csNameTag = csKey; |
219 } | 452 return pFind; |
220 CPDF_SimpleParser syntax(m_csDA); | 453 } |
221 if (syntax.FindTagParam("Tm", 6)) { | 454 } |
222 FX_FLOAT f[6]; | 455 return NULL; |
223 for (int i = 0; i < 6; i ++) { | 456 } |
224 f[i] = FX_atof((CFX_ByteString)syntax.GetWord()); | 457 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, |
225 } | 458 CPDF_Document* pDocument, |
226 tm.Set(f[0], f[1], f[2], f[3], f[4], f[5]); | 459 CFX_ByteString& csNameTag) { |
227 } | 460 csNameTag = ""; |
228 return tm; | 461 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); |
229 } | 462 CFX_SubstFont* pSubst; |
230 void InitInterFormDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) | 463 CPDF_Font* pFont = GetDefaultInterFormFont(pFormDict, pDocument); |
231 { | 464 if (pFont != NULL) { |
232 if (pDocument == NULL) { | 465 pSubst = (CFX_SubstFont*)pFont->GetSubstFont(); |
233 return; | 466 if (pSubst != NULL && pSubst->m_Charset == (int)charSet) { |
234 } | 467 FindInterFormFont(pFormDict, pFont, csNameTag); |
235 if (pFormDict == NULL) { | 468 return pFont; |
236 pFormDict = CPDF_Dictionary::Create(); | 469 } |
237 if (pFormDict == NULL) { | 470 } |
238 return; | 471 return GetNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); |
239 } | 472 } |
240 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pFormDict); | 473 FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, |
241 CPDF_Dictionary* pRoot = pDocument->GetRoot(); | 474 const CPDF_Font* pFont, |
242 pRoot->SetAtReference("AcroForm", pDocument, dwObjNum); | 475 CFX_ByteString& csNameTag) { |
243 } | 476 if (pFormDict == NULL || pFont == NULL) { |
244 CFX_ByteString csDA; | 477 return FALSE; |
245 if (!pFormDict->KeyExist("DR")) { | 478 } |
246 CPDF_Font* pFont = NULL; | 479 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
247 CFX_ByteString csBaseName, csDefault; | 480 if (pDR == NULL) { |
248 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); | 481 return FALSE; |
249 pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); | 482 } |
250 if (pFont != NULL) { | 483 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
251 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); | 484 if (pFonts == NULL) { |
252 csDefault = csBaseName; | 485 return FALSE; |
253 } | 486 } |
254 if (charSet != 0) { | 487 FX_POSITION pos = pFonts->GetStartPos(); |
255 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet, N
ULL); | 488 while (pos) { |
256 if (pFont == NULL || csFontName != "Helvetica") { | 489 CPDF_Object* pObj = NULL; |
257 pFont = CPDF_InterForm::AddNativeFont(pDocument); | 490 CFX_ByteString csKey; |
258 if (pFont != NULL) { | 491 pObj = pFonts->GetNextElement(pos, csKey); |
259 csBaseName = ""; | 492 if (pObj == NULL) { |
260 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); | 493 continue; |
261 csDefault = csBaseName; | 494 } |
262 } | 495 CPDF_Object* pDirect = pObj->GetDirect(); |
263 } | 496 if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) { |
264 } | 497 continue; |
265 if (pFont != NULL) { | 498 } |
266 csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf"; | 499 CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect; |
267 } | 500 if (pElement->GetString("Type") != "Font") { |
268 } | 501 continue; |
269 if (!csDA.IsEmpty()) { | 502 } |
270 csDA += " "; | 503 if (pFont->GetFontDict() == pElement) { |
271 } | 504 csNameTag = csKey; |
272 csDA += "0 g"; | 505 return TRUE; |
273 if (!pFormDict->KeyExist("DA")) { | 506 } |
274 pFormDict->SetAtString("DA", csDA); | 507 } |
275 } | 508 return FALSE; |
276 } | 509 } |
277 FX_DWORD CountInterFormFonts(CPDF_Dictionary* pFormDict) | 510 FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, |
278 { | 511 CPDF_Document* pDocument, |
279 if (pFormDict == NULL) { | 512 CFX_ByteString csFontName, |
280 return 0; | 513 CPDF_Font*& pFont, |
281 } | 514 CFX_ByteString& csNameTag) { |
282 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | 515 if (pFormDict == NULL) { |
| 516 return FALSE; |
| 517 } |
| 518 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
| 519 if (pDR == NULL) { |
| 520 return FALSE; |
| 521 } |
| 522 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
| 523 if (pFonts == NULL) { |
| 524 return FALSE; |
| 525 } |
| 526 if (csFontName.GetLength() > 0) { |
| 527 csFontName.Remove(' '); |
| 528 } |
| 529 FX_POSITION pos = pFonts->GetStartPos(); |
| 530 while (pos) { |
| 531 CPDF_Object* pObj = NULL; |
| 532 CFX_ByteString csKey, csTmp; |
| 533 pObj = pFonts->GetNextElement(pos, csKey); |
| 534 if (pObj == NULL) { |
| 535 continue; |
| 536 } |
| 537 CPDF_Object* pDirect = pObj->GetDirect(); |
| 538 if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) { |
| 539 continue; |
| 540 } |
| 541 CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect; |
| 542 if (pElement->GetString("Type") != "Font") { |
| 543 continue; |
| 544 } |
| 545 pFont = pDocument->LoadFont(pElement); |
| 546 if (pFont == NULL) { |
| 547 continue; |
| 548 } |
| 549 CFX_ByteString csBaseFont; |
| 550 csBaseFont = pFont->GetBaseFont(); |
| 551 csBaseFont.Remove(' '); |
| 552 if (csBaseFont == csFontName) { |
| 553 csNameTag = csKey; |
| 554 return TRUE; |
| 555 } |
| 556 } |
| 557 return FALSE; |
| 558 } |
| 559 void AddInterFormFont(CPDF_Dictionary*& pFormDict, |
| 560 CPDF_Document* pDocument, |
| 561 const CPDF_Font* pFont, |
| 562 CFX_ByteString& csNameTag) { |
| 563 if (pFont == NULL) { |
| 564 return; |
| 565 } |
| 566 if (pFormDict == NULL) { |
| 567 InitInterFormDict(pFormDict, pDocument); |
| 568 } |
| 569 CFX_ByteString csTag; |
| 570 if (FindInterFormFont(pFormDict, pFont, csTag)) { |
| 571 csNameTag = csTag; |
| 572 return; |
| 573 } |
| 574 if (pFormDict == NULL) { |
| 575 InitInterFormDict(pFormDict, pDocument); |
| 576 } |
| 577 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
| 578 if (pDR == NULL) { |
| 579 pDR = CPDF_Dictionary::Create(); |
283 if (pDR == NULL) { | 580 if (pDR == NULL) { |
284 return 0; | 581 return; |
285 } | 582 } |
286 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | 583 pFormDict->SetAt("DR", pDR); |
287 if (pFonts == NULL) { | 584 } |
288 return 0; | 585 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
289 } | 586 if (pFonts == NULL) { |
290 FX_DWORD dwCount = 0; | 587 pFonts = CPDF_Dictionary::Create(); |
291 FX_POSITION pos = pFonts->GetStartPos(); | 588 pDR->SetAt("Font", pFonts); |
292 while (pos) { | 589 } |
293 CPDF_Object* pObj = NULL; | 590 if (csNameTag.IsEmpty()) { |
294 CFX_ByteString csKey; | 591 csNameTag = pFont->GetBaseFont(); |
295 pObj = pFonts->GetNextElement(pos, csKey); | 592 } |
296 if (pObj == NULL) { | 593 csNameTag.Remove(' '); |
297 continue; | 594 csNameTag = |
298 } | 595 CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, csNameTag); |
299 CPDF_Object* pDirect = pObj->GetDirect(); | 596 pFonts->SetAtReference(csNameTag, pDocument, pFont->GetFontDict()); |
300 if (pDirect != NULL && pDirect->GetType() == PDFOBJ_DICTIONARY) { | 597 } |
301 if (((CPDF_Dictionary*)pDirect)->GetString("Type") == "Font") { | 598 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, |
302 dwCount ++; | 599 CPDF_Document* pDocument, |
303 } | 600 uint8_t charSet, |
304 } | 601 CFX_ByteString& csNameTag) { |
305 } | 602 if (pFormDict == NULL) { |
306 return dwCount; | 603 InitInterFormDict(pFormDict, pDocument); |
307 } | 604 } |
308 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument
, FX_DWORD index, CFX_ByteString& csNameTag) | 605 CFX_ByteString csTemp; |
309 { | 606 CPDF_Font* pFont = |
310 if (pFormDict == NULL) { | 607 GetNativeInterFormFont(pFormDict, pDocument, charSet, csTemp); |
311 return NULL; | 608 if (pFont != NULL) { |
312 } | 609 csNameTag = csTemp; |
313 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | |
314 if (pDR == NULL) { | |
315 return NULL; | |
316 } | |
317 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | |
318 if (pFonts == NULL) { | |
319 return NULL; | |
320 } | |
321 FX_DWORD dwCount = 0; | |
322 FX_POSITION pos = pFonts->GetStartPos(); | |
323 while (pos) { | |
324 CPDF_Object* pObj = NULL; | |
325 CFX_ByteString csKey; | |
326 pObj = pFonts->GetNextElement(pos, csKey); | |
327 if (pObj == NULL) { | |
328 continue; | |
329 } | |
330 CPDF_Object* pDirect = pObj->GetDirect(); | |
331 if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) { | |
332 continue; | |
333 } | |
334 CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect; | |
335 if (pElement->GetString("Type") != "Font") { | |
336 continue; | |
337 } | |
338 if (dwCount == index) { | |
339 csNameTag = csKey; | |
340 return pDocument->LoadFont(pElement); | |
341 } | |
342 dwCount ++; | |
343 } | |
344 return NULL; | |
345 } | |
346 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument
, CFX_ByteString csNameTag) | |
347 { | |
348 CFX_ByteString csAlias = PDF_NameDecode(csNameTag); | |
349 if (pFormDict == NULL || csAlias.IsEmpty()) { | |
350 return NULL; | |
351 } | |
352 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | |
353 if (pDR == NULL) { | |
354 return NULL; | |
355 } | |
356 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | |
357 if (pFonts == NULL) { | |
358 return NULL; | |
359 } | |
360 CPDF_Dictionary* pElement = pFonts->GetDict(csAlias); | |
361 if (pElement == NULL) { | |
362 return NULL; | |
363 } | |
364 if (pElement->GetString("Type") == "Font") { | |
365 return pDocument->LoadFont(pElement); | |
366 } | |
367 return NULL; | |
368 } | |
369 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument
, CFX_ByteString csFontName, CFX_ByteString& csNameTag) | |
370 { | |
371 if (pFormDict == NULL || csFontName.IsEmpty()) { | |
372 return NULL; | |
373 } | |
374 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | |
375 if (pDR == NULL) { | |
376 return NULL; | |
377 } | |
378 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | |
379 if (pFonts == NULL) { | |
380 return NULL; | |
381 } | |
382 FX_POSITION pos = pFonts->GetStartPos(); | |
383 while (pos) { | |
384 CPDF_Object* pObj = NULL; | |
385 CFX_ByteString csKey; | |
386 pObj = pFonts->GetNextElement(pos, csKey); | |
387 if (pObj == NULL) { | |
388 continue; | |
389 } | |
390 CPDF_Object* pDirect = pObj->GetDirect(); | |
391 if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) { | |
392 continue; | |
393 } | |
394 CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect; | |
395 if (pElement->GetString("Type") != "Font") { | |
396 continue; | |
397 } | |
398 CPDF_Font* pFind = pDocument->LoadFont(pElement); | |
399 if (pFind == NULL) { | |
400 continue; | |
401 } | |
402 CFX_ByteString csBaseFont; | |
403 csBaseFont = pFind->GetBaseFont(); | |
404 csBaseFont.Remove(' '); | |
405 if (csBaseFont == csFontName) { | |
406 csNameTag = csKey; | |
407 return pFind; | |
408 } | |
409 } | |
410 return NULL; | |
411 } | |
412 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDo
cument, uint8_t charSet, CFX_ByteString& csNameTag) | |
413 { | |
414 if (pFormDict == NULL) { | |
415 return NULL; | |
416 } | |
417 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | |
418 if (pDR == NULL) { | |
419 return NULL; | |
420 } | |
421 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | |
422 if (pFonts == NULL) { | |
423 return NULL; | |
424 } | |
425 FX_POSITION pos = pFonts->GetStartPos(); | |
426 while (pos) { | |
427 CPDF_Object* pObj = NULL; | |
428 CFX_ByteString csKey; | |
429 pObj = pFonts->GetNextElement(pos, csKey); | |
430 if (pObj == NULL) { | |
431 continue; | |
432 } | |
433 CPDF_Object* pDirect = pObj->GetDirect(); | |
434 if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) { | |
435 continue; | |
436 } | |
437 CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect; | |
438 if (pElement->GetString("Type") != "Font") { | |
439 continue; | |
440 } | |
441 CPDF_Font* pFind = pDocument->LoadFont(pElement); | |
442 if (pFind == NULL) { | |
443 continue; | |
444 } | |
445 CFX_SubstFont* pSubst = (CFX_SubstFont*)pFind->GetSubstFont(); | |
446 if (pSubst == NULL) { | |
447 continue; | |
448 } | |
449 if (pSubst->m_Charset == (int)charSet) { | |
450 csNameTag = csKey; | |
451 return pFind; | |
452 } | |
453 } | |
454 return NULL; | |
455 } | |
456 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDo
cument, CFX_ByteString& csNameTag) | |
457 { | |
458 csNameTag = ""; | |
459 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); | |
460 CFX_SubstFont* pSubst; | |
461 CPDF_Font* pFont = GetDefaultInterFormFont(pFormDict, pDocument); | |
462 if (pFont != NULL) { | |
463 pSubst = (CFX_SubstFont*)pFont->GetSubstFont(); | |
464 if (pSubst != NULL && pSubst->m_Charset == (int)charSet) { | |
465 FindInterFormFont(pFormDict, pFont, csNameTag); | |
466 return pFont; | |
467 } | |
468 } | |
469 return GetNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); | |
470 } | |
471 FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont, CF
X_ByteString& csNameTag) | |
472 { | |
473 if (pFormDict == NULL || pFont == NULL) { | |
474 return FALSE; | |
475 } | |
476 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | |
477 if (pDR == NULL) { | |
478 return FALSE; | |
479 } | |
480 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | |
481 if (pFonts == NULL) { | |
482 return FALSE; | |
483 } | |
484 FX_POSITION pos = pFonts->GetStartPos(); | |
485 while (pos) { | |
486 CPDF_Object* pObj = NULL; | |
487 CFX_ByteString csKey; | |
488 pObj = pFonts->GetNextElement(pos, csKey); | |
489 if (pObj == NULL) { | |
490 continue; | |
491 } | |
492 CPDF_Object* pDirect = pObj->GetDirect(); | |
493 if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) { | |
494 continue; | |
495 } | |
496 CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect; | |
497 if (pElement->GetString("Type") != "Font") { | |
498 continue; | |
499 } | |
500 if (pFont->GetFontDict() == pElement) { | |
501 csNameTag = csKey; | |
502 return TRUE; | |
503 } | |
504 } | |
505 return FALSE; | |
506 } | |
507 FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument,
CFX_ByteString csFontName, CPDF_Font*& pFont, CFX_ByteString& csNameTag) | |
508 { | |
509 if (pFormDict == NULL) { | |
510 return FALSE; | |
511 } | |
512 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | |
513 if (pDR == NULL) { | |
514 return FALSE; | |
515 } | |
516 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | |
517 if (pFonts == NULL) { | |
518 return FALSE; | |
519 } | |
520 if (csFontName.GetLength() > 0) { | |
521 csFontName.Remove(' '); | |
522 } | |
523 FX_POSITION pos = pFonts->GetStartPos(); | |
524 while (pos) { | |
525 CPDF_Object* pObj = NULL; | |
526 CFX_ByteString csKey, csTmp; | |
527 pObj = pFonts->GetNextElement(pos, csKey); | |
528 if (pObj == NULL) { | |
529 continue; | |
530 } | |
531 CPDF_Object* pDirect = pObj->GetDirect(); | |
532 if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) { | |
533 continue; | |
534 } | |
535 CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect; | |
536 if (pElement->GetString("Type") != "Font") { | |
537 continue; | |
538 } | |
539 pFont = pDocument->LoadFont(pElement); | |
540 if (pFont == NULL) { | |
541 continue; | |
542 } | |
543 CFX_ByteString csBaseFont; | |
544 csBaseFont = pFont->GetBaseFont(); | |
545 csBaseFont.Remove(' '); | |
546 if (csBaseFont == csFontName) { | |
547 csNameTag = csKey; | |
548 return TRUE; | |
549 } | |
550 } | |
551 return FALSE; | |
552 } | |
553 void AddInterFormFont(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument, con
st CPDF_Font* pFont, CFX_ByteString& csNameTag) | |
554 { | |
555 if (pFont == NULL) { | |
556 return; | |
557 } | |
558 if (pFormDict == NULL) { | |
559 InitInterFormDict(pFormDict, pDocument); | |
560 } | |
561 CFX_ByteString csTag; | |
562 if (FindInterFormFont(pFormDict, pFont, csTag)) { | |
563 csNameTag = csTag; | |
564 return; | |
565 } | |
566 if (pFormDict == NULL) { | |
567 InitInterFormDict(pFormDict, pDocument); | |
568 } | |
569 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | |
570 if (pDR == NULL) { | |
571 pDR = CPDF_Dictionary::Create(); | |
572 if (pDR == NULL) { | |
573 return; | |
574 } | |
575 pFormDict->SetAt("DR", pDR); | |
576 } | |
577 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | |
578 if (pFonts == NULL) { | |
579 pFonts = CPDF_Dictionary::Create(); | |
580 pDR->SetAt("Font", pFonts); | |
581 } | |
582 if (csNameTag.IsEmpty()) { | |
583 csNameTag = pFont->GetBaseFont(); | |
584 } | |
585 csNameTag.Remove(' '); | |
586 csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, csNameTa
g); | |
587 pFonts->SetAtReference(csNameTag, pDocument, pFont->GetFontDict()); | |
588 } | |
589 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, CPDF_Document* pD
ocument, uint8_t charSet, CFX_ByteString& csNameTag) | |
590 { | |
591 if (pFormDict == NULL) { | |
592 InitInterFormDict(pFormDict, pDocument); | |
593 } | |
594 CFX_ByteString csTemp; | |
595 CPDF_Font* pFont = GetNativeInterFormFont(pFormDict, pDocument, charSet, csT
emp); | |
596 if (pFont != NULL) { | |
597 csNameTag = csTemp; | |
598 return pFont; | |
599 } | |
600 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet); | |
601 if (!csFontName.IsEmpty()) { | |
602 if (FindInterFormFont(pFormDict, pDocument, csFontName, pFont, csNameTag
)) { | |
603 return pFont; | |
604 } | |
605 } | |
606 pFont = CPDF_InterForm::AddNativeFont(charSet, pDocument); | |
607 if (pFont != NULL) { | |
608 AddInterFormFont(pFormDict, pDocument, pFont, csNameTag); | |
609 } | |
610 return pFont; | 610 return pFont; |
611 } | 611 } |
612 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, CPDF_Document* pD
ocument, CFX_ByteString& csNameTag) | 612 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet); |
613 { | 613 if (!csFontName.IsEmpty()) { |
614 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); | 614 if (FindInterFormFont(pFormDict, pDocument, csFontName, pFont, csNameTag)) { |
615 return AddNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); | 615 return pFont; |
616 } | 616 } |
617 void RemoveInterFormFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont) | 617 } |
618 { | 618 pFont = CPDF_InterForm::AddNativeFont(charSet, pDocument); |
619 if (pFormDict == NULL || pFont == NULL) { | 619 if (pFont != NULL) { |
620 return; | 620 AddInterFormFont(pFormDict, pDocument, pFont, csNameTag); |
621 } | 621 } |
622 CFX_ByteString csTag; | 622 return pFont; |
623 if (!FindInterFormFont(pFormDict, pFont, csTag)) { | 623 } |
624 return; | 624 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, |
625 } | 625 CPDF_Document* pDocument, |
626 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | 626 CFX_ByteString& csNameTag) { |
627 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | 627 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); |
628 pFonts->RemoveAt(csTag); | 628 return AddNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); |
629 } | 629 } |
630 void RemoveInterFormFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) | 630 void RemoveInterFormFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont) { |
631 { | 631 if (pFormDict == NULL || pFont == NULL) { |
632 if (pFormDict == NULL || csNameTag.IsEmpty()) { | 632 return; |
633 return; | 633 } |
634 } | 634 CFX_ByteString csTag; |
635 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | 635 if (!FindInterFormFont(pFormDict, pFont, csTag)) { |
636 if (pDR == NULL) { | 636 return; |
637 return; | 637 } |
638 } | 638 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
639 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | 639 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
640 if (pFonts == NULL) { | 640 pFonts->RemoveAt(csTag); |
641 return; | 641 } |
642 } | 642 void RemoveInterFormFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) { |
643 pFonts->RemoveAt(csNameTag); | 643 if (pFormDict == NULL || csNameTag.IsEmpty()) { |
644 } | 644 return; |
645 CPDF_Font* GetDefaultInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pD
ocument) | 645 } |
646 { | 646 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
647 if (pFormDict == NULL) { | 647 if (pDR == NULL) { |
648 return NULL; | 648 return; |
649 } | 649 } |
650 CPDF_DefaultAppearance cDA = pFormDict->GetString("DA"); | 650 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
651 CFX_ByteString csFontNameTag; | 651 if (pFonts == NULL) { |
652 FX_FLOAT fFontSize; | 652 return; |
653 cDA.GetFont(csFontNameTag, fFontSize); | 653 } |
654 return GetInterFormFont(pFormDict, pDocument, csFontNameTag); | 654 pFonts->RemoveAt(csNameTag); |
655 } | 655 } |
656 CPDF_IconFit::ScaleMethod CPDF_IconFit::GetScaleMethod() | 656 CPDF_Font* GetDefaultInterFormFont(CPDF_Dictionary* pFormDict, |
657 { | 657 CPDF_Document* pDocument) { |
658 if (!m_pDict) { | 658 if (pFormDict == NULL) { |
659 return Always; | 659 return NULL; |
660 } | 660 } |
661 CFX_ByteString csSW = m_pDict->GetString("SW", "A"); | 661 CPDF_DefaultAppearance cDA = pFormDict->GetString("DA"); |
662 if (csSW == "B") { | 662 CFX_ByteString csFontNameTag; |
663 return Bigger; | 663 FX_FLOAT fFontSize; |
664 } | 664 cDA.GetFont(csFontNameTag, fFontSize); |
665 if (csSW == "S") { | 665 return GetInterFormFont(pFormDict, pDocument, csFontNameTag); |
666 return Smaller; | 666 } |
667 } | 667 CPDF_IconFit::ScaleMethod CPDF_IconFit::GetScaleMethod() { |
668 if (csSW == "N") { | 668 if (!m_pDict) { |
669 return Never; | |
670 } | |
671 return Always; | 669 return Always; |
672 } | 670 } |
673 FX_BOOL CPDF_IconFit::IsProportionalScale() | 671 CFX_ByteString csSW = m_pDict->GetString("SW", "A"); |
674 { | 672 if (csSW == "B") { |
675 if (m_pDict == NULL) { | 673 return Bigger; |
676 return TRUE; | 674 } |
677 } | 675 if (csSW == "S") { |
678 return m_pDict->GetString("S", "P") != "A"; | 676 return Smaller; |
679 } | 677 } |
680 void CPDF_IconFit::GetIconPosition(FX_FLOAT& fLeft, FX_FLOAT& fBottom) | 678 if (csSW == "N") { |
681 { | 679 return Never; |
682 fLeft = fBottom = 0.5; | 680 } |
683 if (m_pDict == NULL) { | 681 return Always; |
684 return; | 682 } |
685 } | 683 FX_BOOL CPDF_IconFit::IsProportionalScale() { |
686 CPDF_Array* pA = m_pDict->GetArray("A"); | 684 if (m_pDict == NULL) { |
687 if (pA != NULL) { | 685 return TRUE; |
688 FX_DWORD dwCount = pA->GetCount(); | 686 } |
689 if (dwCount > 0) { | 687 return m_pDict->GetString("S", "P") != "A"; |
690 fLeft = pA->GetNumber(0); | 688 } |
691 } | 689 void CPDF_IconFit::GetIconPosition(FX_FLOAT& fLeft, FX_FLOAT& fBottom) { |
692 if (dwCount > 1) { | 690 fLeft = fBottom = 0.5; |
693 fBottom = pA->GetNumber(1); | 691 if (m_pDict == NULL) { |
694 } | 692 return; |
695 } | 693 } |
696 } | 694 CPDF_Array* pA = m_pDict->GetArray("A"); |
697 FX_BOOL CPDF_IconFit::GetFittingBounds() | 695 if (pA != NULL) { |
698 { | 696 FX_DWORD dwCount = pA->GetCount(); |
699 if (m_pDict == NULL) { | 697 if (dwCount > 0) { |
700 return FALSE; | 698 fLeft = pA->GetNumber(0); |
701 } | 699 } |
702 return m_pDict->GetBoolean("FB"); | 700 if (dwCount > 1) { |
703 } | 701 fBottom = pA->GetNumber(1); |
704 void SaveCheckedFieldStatus(CPDF_FormField* pField, CFX_ByteArray& statusArray) | 702 } |
705 { | 703 } |
706 int iCount = pField->CountControls(); | 704 } |
707 for (int i = 0; i < iCount; i ++) { | 705 FX_BOOL CPDF_IconFit::GetFittingBounds() { |
708 CPDF_FormControl* pControl = pField->GetControl(i); | 706 if (m_pDict == NULL) { |
709 if (pControl == NULL) { | 707 return FALSE; |
710 continue; | 708 } |
711 } | 709 return m_pDict->GetBoolean("FB"); |
712 statusArray.Add(pControl->IsChecked() ? 1 : 0); | 710 } |
713 } | 711 void SaveCheckedFieldStatus(CPDF_FormField* pField, |
714 } | 712 CFX_ByteArray& statusArray) { |
715 CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, const FX_CHAR* name,
int nLevel) | 713 int iCount = pField->CountControls(); |
716 { | 714 for (int i = 0; i < iCount; i++) { |
717 if (nLevel > FPDFDOC_UTILS_MAXRECURSION) { | 715 CPDF_FormControl* pControl = pField->GetControl(i); |
718 return NULL; | 716 if (pControl == NULL) { |
719 } | 717 continue; |
720 if (pFieldDict == NULL) { | 718 } |
721 return NULL; | 719 statusArray.Add(pControl->IsChecked() ? 1 : 0); |
722 } | 720 } |
723 CPDF_Object* pAttr = pFieldDict->GetElementValue(name); | 721 } |
724 if (pAttr) { | 722 CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, |
725 return pAttr; | 723 const FX_CHAR* name, |
726 } | 724 int nLevel) { |
727 CPDF_Dictionary* pParent = pFieldDict->GetDict("Parent"); | 725 if (nLevel > FPDFDOC_UTILS_MAXRECURSION) { |
728 if (pParent == NULL) { | 726 return NULL; |
729 return NULL; | 727 } |
730 } | 728 if (pFieldDict == NULL) { |
731 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); | 729 return NULL; |
732 } | 730 } |
| 731 CPDF_Object* pAttr = pFieldDict->GetElementValue(name); |
| 732 if (pAttr) { |
| 733 return pAttr; |
| 734 } |
| 735 CPDF_Dictionary* pParent = pFieldDict->GetDict("Parent"); |
| 736 if (pParent == NULL) { |
| 737 return NULL; |
| 738 } |
| 739 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); |
| 740 } |
OLD | NEW |