| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fpdfdoc/cpvt_generateap.h" | 7 #include "core/fpdfdoc/cpvt_generateap.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 CPDF_Dictionary* pAnnotDict) { | 486 CPDF_Dictionary* pAnnotDict) { |
| 487 return GenerateWidgetAP(pDoc, pAnnotDict, 2); | 487 return GenerateWidgetAP(pDoc, pAnnotDict, 2); |
| 488 } | 488 } |
| 489 | 489 |
| 490 // Static. | 490 // Static. |
| 491 bool CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, | 491 bool CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, |
| 492 CPDF_Dictionary* pAnnotDict) { | 492 CPDF_Dictionary* pAnnotDict) { |
| 493 return GenerateWidgetAP(pDoc, pAnnotDict, 0); | 493 return GenerateWidgetAP(pDoc, pAnnotDict, 0); |
| 494 } | 494 } |
| 495 | 495 |
| 496 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, |
| 497 CPDF_Dictionary* pAnnotDict) { |
| 498 // If AP dictionary exists, we use the appearance defined in the |
| 499 // existing AP dictionary. |
| 500 if (pAnnotDict->KeyExist("AP")) |
| 501 return false; |
| 502 |
| 503 CFX_ByteTextBuf sAppStream; |
| 504 sAppStream << "/GS gs "; |
| 505 |
| 506 if (pAnnotDict->KeyExist("C")) { |
| 507 CPDF_Array* pColor = pAnnotDict->GetArrayBy("C"); |
| 508 CPVT_Color color = CPVT_Color::ParseColor(*pColor); |
| 509 sAppStream << CPVT_GenerateAP::GenerateColorAP(color, TRUE); |
| 510 } else { |
| 511 // Defaults to 0xFFFF00 color for highlight. |
| 512 sAppStream << "1 1 0 rg \n"; |
| 513 } |
| 514 |
| 515 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); |
| 516 rect.Normalize(); |
| 517 |
| 518 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " |
| 519 << rect.top << " l " << rect.right << " " << rect.bottom << " l " |
| 520 << rect.left << " " << rect.bottom << " l " |
| 521 << "h f\n"; |
| 522 |
| 523 CPDF_Dictionary* pAPDict = new CPDF_Dictionary; |
| 524 pAnnotDict->SetAt("AP", pAPDict); |
| 525 |
| 526 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); |
| 527 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); |
| 528 pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum); |
| 529 |
| 530 pNormalStream->SetData(reinterpret_cast<uint8_t*>(sAppStream.GetBuffer()), |
| 531 sAppStream.GetSize(), FALSE, FALSE); |
| 532 |
| 533 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); |
| 534 pStreamDict->SetAtInteger("FormType", 1); |
| 535 pStreamDict->SetAtString("Subtype", "Form"); |
| 536 pStreamDict->SetAtMatrix("Matrix", CFX_Matrix()); |
| 537 pStreamDict->SetAtRect("BBox", rect); |
| 538 |
| 539 CPDF_Dictionary* pGSDict = new CPDF_Dictionary; |
| 540 pGSDict->SetAtString("Type", "ExtGState"); |
| 541 pGSDict->SetAtNumber("ca", 1); |
| 542 pGSDict->SetAtNumber("CA", 1); |
| 543 pGSDict->SetAtBoolean("AIS", false); |
| 544 pGSDict->SetAtString("BM", "Multiply"); |
| 545 |
| 546 CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary; |
| 547 pExtGStateDict->SetAt("GS", pGSDict); |
| 548 |
| 549 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary; |
| 550 pResourceDict->SetAt("ExtGState", pExtGStateDict); |
| 551 |
| 552 pStreamDict->SetAt("Resources", pResourceDict); |
| 553 return true; |
| 554 } |
| 555 |
| 496 // Static. | 556 // Static. |
| 497 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( | 557 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( |
| 498 IPVT_FontMap* pFontMap, | 558 IPVT_FontMap* pFontMap, |
| 499 CPDF_VariableText::Iterator* pIterator, | 559 CPDF_VariableText::Iterator* pIterator, |
| 500 const CFX_FloatPoint& ptOffset, | 560 const CFX_FloatPoint& ptOffset, |
| 501 FX_BOOL bContinuous, | 561 FX_BOOL bContinuous, |
| 502 uint16_t SubWord) { | 562 uint16_t SubWord) { |
| 503 CFX_ByteTextBuf sEditStream; | 563 CFX_ByteTextBuf sEditStream; |
| 504 CFX_ByteTextBuf sLineStream; | 564 CFX_ByteTextBuf sLineStream; |
| 505 CFX_ByteTextBuf sWords; | 565 CFX_ByteTextBuf sWords; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 int32_t nFontIndex, | 811 int32_t nFontIndex, |
| 752 FX_FLOAT fFontSize) { | 812 FX_FLOAT fFontSize) { |
| 753 CFX_ByteTextBuf sRet; | 813 CFX_ByteTextBuf sRet; |
| 754 if (pFontMap) { | 814 if (pFontMap) { |
| 755 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 815 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
| 756 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 816 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
| 757 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 817 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
| 758 } | 818 } |
| 759 return sRet.MakeString(); | 819 return sRet.MakeString(); |
| 760 } | 820 } |
| OLD | NEW |