Chromium Code Reviews| Index: core/fpdfdoc/cpvt_generateap.cpp |
| diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp |
| index 56b661271702cb5e3f6ad2c75f6ccad1b58d056a..6d43b03ae935288b04fa2f5da8967d7b29193ffe 100644 |
| --- a/core/fpdfdoc/cpvt_generateap.cpp |
| +++ b/core/fpdfdoc/cpvt_generateap.cpp |
| @@ -443,6 +443,23 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, |
| return true; |
| } |
| +CPDF_Dictionary* GenerateExtGStateDict(CFX_ByteString sName, |
| + FX_FLOAT fCAForStroke, |
| + FX_FLOAT fCAForNonStroke, |
| + CFX_ByteString sBlendMode) { |
| + CPDF_Dictionary* pGSDict = new CPDF_Dictionary; |
| + pGSDict->SetAtString("Type", "ExtGState"); |
| + pGSDict->SetAtNumber("CA", fCAForStroke); |
| + pGSDict->SetAtNumber("ca", fCAForNonStroke); |
| + pGSDict->SetAtBoolean("AIS", false); |
| + pGSDict->SetAtString("BM", sBlendMode); |
| + |
| + CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary; |
| + pExtGStateDict->SetAt(sName, pGSDict); |
| + |
| + return pExtGStateDict; |
| +} |
| + |
| } // namespace |
| bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { |
| @@ -501,7 +518,8 @@ bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, |
| return false; |
| CFX_ByteTextBuf sAppStream; |
| - sAppStream << "/GS gs "; |
| + CFX_ByteString sExtGSDictName = "GS"; |
| + sAppStream << "/" << sExtGSDictName << " gs "; |
| if (pAnnotDict->KeyExist("C")) { |
| CPDF_Array* pColor = pAnnotDict->GetArrayBy("C"); |
| @@ -536,18 +554,71 @@ bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, |
| pStreamDict->SetAtMatrix("Matrix", CFX_Matrix()); |
| pStreamDict->SetAtRect("BBox", rect); |
| - CPDF_Dictionary* pGSDict = new CPDF_Dictionary; |
| - pGSDict->SetAtString("Type", "ExtGState"); |
| - pGSDict->SetAtNumber("ca", 1); |
| - pGSDict->SetAtNumber("CA", 1); |
| - pGSDict->SetAtBoolean("AIS", false); |
| - pGSDict->SetAtString("BM", "Multiply"); |
| + CPDF_Dictionary* pResourceDict = new CPDF_Dictionary; |
| + FX_FLOAT fCAForStroke = |
| + pAnnotDict->KeyExist("CA") ? pAnnotDict->GetNumberBy("CA") : 1.0; |
| + FX_FLOAT fCAForNonStroke = |
| + pAnnotDict->KeyExist("ca") ? pAnnotDict->GetNumberBy("ca") : 1.0; |
|
jaepark
2016/08/01 23:10:52
Although I think this is correct implementation, o
Lei Zhang
2016/08/01 23:16:24
Have you considered adding more tests to exercise
|
| + pResourceDict->SetAt("ExtGState", |
| + GenerateExtGStateDict(sExtGSDictName, fCAForStroke, |
| + fCAForNonStroke, "Multiply")); |
| - CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary; |
| - pExtGStateDict->SetAt("GS", pGSDict); |
| + pStreamDict->SetAt("Resources", pResourceDict); |
| + return true; |
| +} |
| + |
| +bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, |
| + CPDF_Dictionary* pAnnotDict) { |
| + // If AP dictionary exists, we use the appearance defined in the |
| + // existing AP dictionary. |
| + if (pAnnotDict->KeyExist("AP")) |
| + return false; |
| + |
| + CFX_ByteTextBuf sAppStream; |
| + CFX_ByteString sExtGSDictName = "GS"; |
| + sAppStream << "/" << sExtGSDictName << " gs "; |
| + |
| + if (pAnnotDict->KeyExist("C")) { |
| + CPDF_Array* pColor = pAnnotDict->GetArrayBy("C"); |
| + CPVT_Color color = CPVT_Color::ParseColor(*pColor); |
| + sAppStream << CPVT_GenerateAP::GenerateColorAP(color, FALSE); |
| + } else { |
| + // Defaults to 0x000000 color for underline. |
| + sAppStream << "0 0 0 RG\n"; |
| + } |
| + |
| + CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); |
| + rect.Normalize(); |
| + |
| + FX_FLOAT fLineWidth = 1.0; |
| + sAppStream << fLineWidth << " w " << rect.left << " " |
| + << rect.bottom + fLineWidth << " m " << rect.right << " " |
| + << rect.bottom + fLineWidth << " l S\n"; |
| + |
| + CPDF_Dictionary* pAPDict = new CPDF_Dictionary; |
| + pAnnotDict->SetAt("AP", pAPDict); |
| + |
| + CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); |
| + int32_t objnum = pDoc->AddIndirectObject(pNormalStream); |
| + pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum); |
| + |
| + pNormalStream->SetData(reinterpret_cast<uint8_t*>(sAppStream.GetBuffer()), |
| + sAppStream.GetSize(), FALSE, FALSE); |
| + |
| + CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); |
| + pStreamDict->SetAtInteger("FormType", 1); |
| + pStreamDict->SetAtString("Subtype", "Form"); |
| + pStreamDict->SetAtMatrix("Matrix", CFX_Matrix()); |
| + pStreamDict->SetAtRect("BBox", rect); |
| CPDF_Dictionary* pResourceDict = new CPDF_Dictionary; |
| - pResourceDict->SetAt("ExtGState", pExtGStateDict); |
| + FX_FLOAT fCAForStroke = |
| + pAnnotDict->KeyExist("CA") ? pAnnotDict->GetNumberBy("CA") : 1.0; |
| + FX_FLOAT fCAForNonStroke = |
| + pAnnotDict->KeyExist("ca") ? pAnnotDict->GetNumberBy("ca") : 1.0; |
| + pResourceDict->SetAt("ExtGState", |
| + GenerateExtGStateDict(sExtGSDictName, fCAForStroke, |
| + fCAForNonStroke, "Normal")); |
| pStreamDict->SetAt("Resources", pResourceDict); |
| return true; |