Chromium Code Reviews| 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 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField, | 8 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField, |
| 9 CPDF_Dictionary* pWidgetDict) { | 9 CPDF_Dictionary* pWidgetDict) { |
| 10 m_pField = pField; | 10 m_pField = pField; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 CFX_ByteString csH = m_pWidgetDict->GetString("H", "I"); | 181 CFX_ByteString csH = m_pWidgetDict->GetString("H", "I"); |
| 182 int i = 0; | 182 int i = 0; |
| 183 while (g_sHighlightingMode[i][0] != '\0') { | 183 while (g_sHighlightingMode[i][0] != '\0') { |
| 184 if (csH.Equal(g_sHighlightingMode[i])) { | 184 if (csH.Equal(g_sHighlightingMode[i])) { |
| 185 return (HighlightingMode)i; | 185 return (HighlightingMode)i; |
| 186 } | 186 } |
| 187 i++; | 187 i++; |
| 188 } | 188 } |
| 189 return Invert; | 189 return Invert; |
| 190 } | 190 } |
| 191 CPDF_ApSettings CPDF_FormControl::GetMK(FX_BOOL bCreate) { | 191 |
|
Tom Sepez
2015/11/10 17:28:04
Confirmed bCreate is always passed as FALSE.
Lei Zhang
2015/11/11 02:27:56
Acknowledged.
| |
| 192 if (!m_pWidgetDict) { | 192 CPDF_ApSettings CPDF_FormControl::GetMK() { |
| 193 return NULL; | 193 return CPDF_ApSettings(m_pWidgetDict ? m_pWidgetDict->GetDict(FX_BSTRC("MK")) |
| 194 } | 194 : nullptr); |
| 195 CPDF_ApSettings mk = m_pWidgetDict->GetDict(FX_BSTRC("MK")); | |
| 196 if (!mk && bCreate) { | |
| 197 mk = CPDF_Dictionary::Create(); | |
| 198 if (mk == NULL) { | |
| 199 return NULL; | |
| 200 } | |
| 201 m_pWidgetDict->SetAt(FX_BSTRC("MK"), mk); | |
| 202 } | |
| 203 return mk; | |
| 204 } | 195 } |
| 196 | |
| 205 FX_BOOL CPDF_FormControl::HasMKEntry(CFX_ByteString csEntry) { | 197 FX_BOOL CPDF_FormControl::HasMKEntry(CFX_ByteString csEntry) { |
| 206 CPDF_ApSettings mk = GetMK(FALSE); | 198 CPDF_ApSettings mk = GetMK(); |
|
Tom Sepez
2015/11/10 17:28:04
nit: how about just return GetMK().GetRotation();
Lei Zhang
2015/11/11 02:27:55
Done.
| |
| 207 return mk.HasMKEntry(csEntry); | 199 return mk.HasMKEntry(csEntry); |
| 208 } | 200 } |
| 209 int CPDF_FormControl::GetRotation() { | 201 int CPDF_FormControl::GetRotation() { |
| 210 CPDF_ApSettings mk = GetMK(FALSE); | 202 CPDF_ApSettings mk = GetMK(); |
| 211 return mk.GetRotation(); | 203 return mk.GetRotation(); |
| 212 } | 204 } |
| 213 FX_ARGB CPDF_FormControl::GetColor(int& iColorType, CFX_ByteString csEntry) { | 205 FX_ARGB CPDF_FormControl::GetColor(int& iColorType, CFX_ByteString csEntry) { |
| 214 CPDF_ApSettings mk = GetMK(FALSE); | 206 CPDF_ApSettings mk = GetMK(); |
| 215 return mk.GetColor(iColorType, csEntry); | 207 return mk.GetColor(iColorType, csEntry); |
| 216 } | 208 } |
| 217 FX_FLOAT CPDF_FormControl::GetOriginalColor(int index, CFX_ByteString csEntry) { | 209 FX_FLOAT CPDF_FormControl::GetOriginalColor(int index, CFX_ByteString csEntry) { |
| 218 CPDF_ApSettings mk = GetMK(FALSE); | 210 CPDF_ApSettings mk = GetMK(); |
| 219 return mk.GetOriginalColor(index, csEntry); | 211 return mk.GetOriginalColor(index, csEntry); |
| 220 } | 212 } |
| 221 void CPDF_FormControl::GetOriginalColor(int& iColorType, | 213 void CPDF_FormControl::GetOriginalColor(int& iColorType, |
| 222 FX_FLOAT fc[4], | 214 FX_FLOAT fc[4], |
| 223 CFX_ByteString csEntry) { | 215 CFX_ByteString csEntry) { |
| 224 CPDF_ApSettings mk = GetMK(FALSE); | 216 CPDF_ApSettings mk = GetMK(); |
| 225 mk.GetOriginalColor(iColorType, fc, csEntry); | 217 mk.GetOriginalColor(iColorType, fc, csEntry); |
| 226 } | 218 } |
| 227 CFX_WideString CPDF_FormControl::GetCaption(CFX_ByteString csEntry) { | 219 CFX_WideString CPDF_FormControl::GetCaption(CFX_ByteString csEntry) { |
| 228 CPDF_ApSettings mk = GetMK(FALSE); | 220 CPDF_ApSettings mk = GetMK(); |
| 229 return mk.GetCaption(csEntry); | 221 return mk.GetCaption(csEntry); |
| 230 } | 222 } |
| 231 CPDF_Stream* CPDF_FormControl::GetIcon(CFX_ByteString csEntry) { | 223 CPDF_Stream* CPDF_FormControl::GetIcon(CFX_ByteString csEntry) { |
| 232 CPDF_ApSettings mk = GetMK(FALSE); | 224 CPDF_ApSettings mk = GetMK(); |
| 233 return mk.GetIcon(csEntry); | 225 return mk.GetIcon(csEntry); |
| 234 } | 226 } |
| 235 CPDF_IconFit CPDF_FormControl::GetIconFit() { | 227 CPDF_IconFit CPDF_FormControl::GetIconFit() { |
| 236 CPDF_ApSettings mk = GetMK(FALSE); | 228 CPDF_ApSettings mk = GetMK(); |
| 237 return mk.GetIconFit(); | 229 return mk.GetIconFit(); |
| 238 } | 230 } |
| 239 int CPDF_FormControl::GetTextPosition() { | 231 int CPDF_FormControl::GetTextPosition() { |
| 240 CPDF_ApSettings mk = GetMK(FALSE); | 232 CPDF_ApSettings mk = GetMK(); |
| 241 return mk.GetTextPosition(); | 233 return mk.GetTextPosition(); |
| 242 } | 234 } |
| 243 CPDF_Action CPDF_FormControl::GetAction() { | 235 CPDF_Action CPDF_FormControl::GetAction() { |
| 244 if (!m_pWidgetDict) { | 236 if (!m_pWidgetDict) { |
| 245 return CPDF_Action(); | 237 return CPDF_Action(); |
| 246 } | 238 } |
| 247 if (m_pWidgetDict->KeyExist("A")) { | 239 if (m_pWidgetDict->KeyExist("A")) { |
| 248 return CPDF_Action(m_pWidgetDict->GetDict("A")); | 240 return CPDF_Action(m_pWidgetDict->GetDict("A")); |
| 249 } | 241 } |
| 250 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "A"); | 242 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "A"); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 } | 315 } |
| 324 if (m_pWidgetDict->KeyExist("Q")) { | 316 if (m_pWidgetDict->KeyExist("Q")) { |
| 325 return m_pWidgetDict->GetInteger("Q", 0); | 317 return m_pWidgetDict->GetInteger("Q", 0); |
| 326 } | 318 } |
| 327 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q"); | 319 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q"); |
| 328 if (pObj == NULL) { | 320 if (pObj == NULL) { |
| 329 return m_pField->m_pForm->GetFormAlignment(); | 321 return m_pField->m_pForm->GetFormAlignment(); |
| 330 } | 322 } |
| 331 return pObj->GetInteger(); | 323 return pObj->GetInteger(); |
| 332 } | 324 } |
| 333 FX_BOOL CPDF_ApSettings::HasMKEntry(const CFX_ByteStringC& csEntry) { | 325 |
| 334 if (m_pDict == NULL) { | 326 CPDF_ApSettings::CPDF_ApSettings(CPDF_Dictionary* pDict) : m_pDict(pDict) {} |
| 335 return FALSE; | 327 |
| 336 } | 328 FX_BOOL CPDF_ApSettings::HasMKEntry(const CFX_ByteStringC& csEntry) const { |
|
Tom Sepez
2015/11/10 17:28:04
can this be just bool?
Lei Zhang
2015/11/11 02:27:55
Done.
| |
| 337 return m_pDict->KeyExist(csEntry); | 329 return m_pDict ? m_pDict->KeyExist(csEntry) : FALSE; |
|
Tom Sepez
2015/11/10 17:28:04
nit: just return m_pDict && m_pDict->KeyExit(csEnt
Lei Zhang
2015/11/11 02:27:55
Done.
| |
| 338 } | 330 } |
| 339 int CPDF_ApSettings::GetRotation() { | 331 |
| 340 if (m_pDict == NULL) { | 332 int CPDF_ApSettings::GetRotation() const { |
| 333 return m_pDict ? m_pDict->GetInteger(FX_BSTRC("R")) : 0; | |
| 334 } | |
| 335 | |
| 336 FX_ARGB CPDF_ApSettings::GetColor(int& iColorType, | |
| 337 const CFX_ByteStringC& csEntry) const { | |
| 338 iColorType = COLORTYPE_TRANSPARENT; | |
| 339 if (!m_pDict) | |
| 341 return 0; | 340 return 0; |
| 342 } | 341 |
| 343 return m_pDict->GetInteger(FX_BSTRC("R")); | 342 CPDF_Array* pEntry = m_pDict->GetArray(csEntry); |
| 344 } | 343 if (!pEntry) |
| 345 FX_ARGB CPDF_ApSettings::GetColor(int& iColorType, | |
| 346 const CFX_ByteStringC& csEntry) { | |
| 347 iColorType = COLORTYPE_TRANSPARENT; | |
| 348 if (m_pDict == NULL) { | |
| 349 return 0; | 344 return 0; |
| 350 } | 345 |
| 351 FX_ARGB color = 0; | 346 FX_ARGB color = 0; |
| 352 CPDF_Array* pEntry = m_pDict->GetArray(csEntry); | |
| 353 if (pEntry == NULL) { | |
| 354 return color; | |
| 355 } | |
| 356 FX_DWORD dwCount = pEntry->GetCount(); | 347 FX_DWORD dwCount = pEntry->GetCount(); |
| 357 if (dwCount == 1) { | 348 if (dwCount == 1) { |
| 358 iColorType = COLORTYPE_GRAY; | 349 iColorType = COLORTYPE_GRAY; |
| 359 FX_FLOAT g = pEntry->GetNumber(0) * 255; | 350 FX_FLOAT g = pEntry->GetNumber(0) * 255; |
| 360 color = ArgbEncode(255, (int)g, (int)g, (int)g); | 351 color = ArgbEncode(255, (int)g, (int)g, (int)g); |
| 361 } else if (dwCount == 3) { | 352 } else if (dwCount == 3) { |
| 362 iColorType = COLORTYPE_RGB; | 353 iColorType = COLORTYPE_RGB; |
| 363 FX_FLOAT r = pEntry->GetNumber(0) * 255; | 354 FX_FLOAT r = pEntry->GetNumber(0) * 255; |
| 364 FX_FLOAT g = pEntry->GetNumber(1) * 255; | 355 FX_FLOAT g = pEntry->GetNumber(1) * 255; |
| 365 FX_FLOAT b = pEntry->GetNumber(2) * 255; | 356 FX_FLOAT b = pEntry->GetNumber(2) * 255; |
| 366 color = ArgbEncode(255, (int)r, (int)g, (int)b); | 357 color = ArgbEncode(255, (int)r, (int)g, (int)b); |
| 367 } else if (dwCount == 4) { | 358 } else if (dwCount == 4) { |
| 368 iColorType = COLORTYPE_CMYK; | 359 iColorType = COLORTYPE_CMYK; |
| 369 FX_FLOAT c = pEntry->GetNumber(0); | 360 FX_FLOAT c = pEntry->GetNumber(0); |
| 370 FX_FLOAT m = pEntry->GetNumber(1); | 361 FX_FLOAT m = pEntry->GetNumber(1); |
| 371 FX_FLOAT y = pEntry->GetNumber(2); | 362 FX_FLOAT y = pEntry->GetNumber(2); |
| 372 FX_FLOAT k = pEntry->GetNumber(3); | 363 FX_FLOAT k = pEntry->GetNumber(3); |
| 373 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k); | 364 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k); |
| 374 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k); | 365 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k); |
| 375 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k); | 366 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k); |
| 376 color = ArgbEncode(255, (int)(r * 255), (int)(g * 255), (int)(b * 255)); | 367 color = ArgbEncode(255, (int)(r * 255), (int)(g * 255), (int)(b * 255)); |
| 377 } | 368 } |
| 378 return color; | 369 return color; |
| 379 } | 370 } |
| 380 FX_FLOAT CPDF_ApSettings::GetOriginalColor(int index, | 371 |
| 381 const CFX_ByteStringC& csEntry) { | 372 FX_FLOAT CPDF_ApSettings::GetOriginalColor( |
| 382 if (m_pDict == NULL) { | 373 int index, |
| 374 const CFX_ByteStringC& csEntry) const { | |
| 375 if (!m_pDict) | |
| 383 return 0; | 376 return 0; |
| 384 } | 377 |
| 385 CPDF_Array* pEntry = m_pDict->GetArray(csEntry); | 378 CPDF_Array* pEntry = m_pDict->GetArray(csEntry); |
| 386 if (pEntry != NULL) { | 379 return pEntry ? pEntry->GetNumber(index) : 0; |
| 387 return pEntry->GetNumber(index); | |
| 388 } | |
| 389 return 0; | |
| 390 } | 380 } |
| 381 | |
| 391 void CPDF_ApSettings::GetOriginalColor(int& iColorType, | 382 void CPDF_ApSettings::GetOriginalColor(int& iColorType, |
| 392 FX_FLOAT fc[4], | 383 FX_FLOAT fc[4], |
| 393 const CFX_ByteStringC& csEntry) { | 384 const CFX_ByteStringC& csEntry) const { |
| 394 iColorType = COLORTYPE_TRANSPARENT; | 385 iColorType = COLORTYPE_TRANSPARENT; |
| 395 for (int i = 0; i < 4; i++) { | 386 for (int i = 0; i < 4; i++) { |
| 396 fc[i] = 0; | 387 fc[i] = 0; |
| 397 } | 388 } |
| 398 if (m_pDict == NULL) { | 389 if (m_pDict == NULL) { |
| 399 return; | 390 return; |
| 400 } | 391 } |
| 401 CPDF_Array* pEntry = m_pDict->GetArray(csEntry); | 392 CPDF_Array* pEntry = m_pDict->GetArray(csEntry); |
| 402 if (pEntry == NULL) { | 393 if (pEntry == NULL) { |
| 403 return; | 394 return; |
| 404 } | 395 } |
| 405 FX_DWORD dwCount = pEntry->GetCount(); | 396 FX_DWORD dwCount = pEntry->GetCount(); |
| 406 if (dwCount == 1) { | 397 if (dwCount == 1) { |
| 407 iColorType = COLORTYPE_GRAY; | 398 iColorType = COLORTYPE_GRAY; |
| 408 fc[0] = pEntry->GetNumber(0); | 399 fc[0] = pEntry->GetNumber(0); |
| 409 } else if (dwCount == 3) { | 400 } else if (dwCount == 3) { |
| 410 iColorType = COLORTYPE_RGB; | 401 iColorType = COLORTYPE_RGB; |
| 411 fc[0] = pEntry->GetNumber(0); | 402 fc[0] = pEntry->GetNumber(0); |
| 412 fc[1] = pEntry->GetNumber(1); | 403 fc[1] = pEntry->GetNumber(1); |
| 413 fc[2] = pEntry->GetNumber(2); | 404 fc[2] = pEntry->GetNumber(2); |
| 414 } else if (dwCount == 4) { | 405 } else if (dwCount == 4) { |
| 415 iColorType = COLORTYPE_CMYK; | 406 iColorType = COLORTYPE_CMYK; |
| 416 fc[0] = pEntry->GetNumber(0); | 407 fc[0] = pEntry->GetNumber(0); |
| 417 fc[1] = pEntry->GetNumber(1); | 408 fc[1] = pEntry->GetNumber(1); |
| 418 fc[2] = pEntry->GetNumber(2); | 409 fc[2] = pEntry->GetNumber(2); |
| 419 fc[3] = pEntry->GetNumber(3); | 410 fc[3] = pEntry->GetNumber(3); |
| 420 } | 411 } |
| 421 } | 412 } |
| 422 CFX_WideString CPDF_ApSettings::GetCaption(const CFX_ByteStringC& csEntry) { | 413 |
| 423 CFX_WideString csCaption; | 414 CFX_WideString CPDF_ApSettings::GetCaption( |
| 424 if (m_pDict == NULL) { | 415 const CFX_ByteStringC& csEntry) const { |
| 425 return csCaption; | 416 return m_pDict ? m_pDict->GetUnicodeText(csEntry) : CFX_WideString(); |
| 426 } | |
| 427 return m_pDict->GetUnicodeText(csEntry); | |
| 428 } | 417 } |
| 429 CPDF_Stream* CPDF_ApSettings::GetIcon(const CFX_ByteStringC& csEntry) { | 418 |
| 430 if (m_pDict == NULL) { | 419 CPDF_Stream* CPDF_ApSettings::GetIcon(const CFX_ByteStringC& csEntry) const { |
| 431 return NULL; | 420 return m_pDict ? m_pDict->GetStream(csEntry) : nullptr; |
| 432 } | |
| 433 return m_pDict->GetStream(csEntry); | |
| 434 } | 421 } |
| 435 CPDF_IconFit CPDF_ApSettings::GetIconFit() { | 422 |
| 436 if (m_pDict == NULL) { | 423 CPDF_IconFit CPDF_ApSettings::GetIconFit() const { |
| 437 return NULL; | 424 return m_pDict ? m_pDict->GetDict(FX_BSTRC("IF")) : nullptr; |
| 438 } | |
| 439 return m_pDict->GetDict(FX_BSTRC("IF")); | |
| 440 } | 425 } |
| 441 int CPDF_ApSettings::GetTextPosition() { | 426 |
| 442 if (m_pDict == NULL) { | 427 int CPDF_ApSettings::GetTextPosition() const { |
| 443 return TEXTPOS_CAPTION; | 428 return m_pDict ? m_pDict->GetInteger(FX_BSTRC("TP"), TEXTPOS_CAPTION) |
| 444 } | 429 : TEXTPOS_CAPTION; |
| 445 return m_pDict->GetInteger(FX_BSTRC("TP"), TEXTPOS_CAPTION); | |
| 446 } | 430 } |
| OLD | NEW |