diff options
author | jaepark <jaepark@google.com> | 2016-08-09 15:19:35 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-09 15:19:35 -0700 |
commit | 39ba18a64283ef3fc3c4aedf537a09835f90862e (patch) | |
tree | 3b4a6f729f11ea8da02990cdbdf62ec1896eff76 /core/fpdfdoc/cpvt_generateap.cpp | |
parent | e76203dbefd1df075a063ee019c3908513f6bee5 (diff) | |
download | pdfium-39ba18a64283ef3fc3c4aedf537a09835f90862e.tar.xz |
Generate default AP stream for ink annotation.
This patch generates a default AP stream for ink annotation so that ink
annotations without AP stream can be displayed.
Also, roll DEPS for testing/corpus to 4119f8e to test ink annotations.
BUG=62625
Review-Url: https://codereview.chromium.org/2232553002
Diffstat (limited to 'core/fpdfdoc/cpvt_generateap.cpp')
-rw-r--r-- | core/fpdfdoc/cpvt_generateap.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp index 5cf96f211f..f15869b130 100644 --- a/core/fpdfdoc/cpvt_generateap.cpp +++ b/core/fpdfdoc/cpvt_generateap.cpp @@ -718,6 +718,62 @@ bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, return true; } +bool CPVT_GenerateAP::GenerateInkAP(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; + + FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); + bool bIsStroke = fBorderWidth > 0; + + if (!bIsStroke) + return false; + + CPDF_Array* pInkList = pAnnotDict->GetArrayBy("InkList"); + if (!pInkList || pInkList->IsEmpty()) + return false; + + CFX_ByteTextBuf sAppStream; + CFX_ByteString sExtGSDictName = "GS"; + sAppStream << "/" << sExtGSDictName << " gs "; + + sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), + CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), + PaintOperation::STROKE); + + sAppStream << fBorderWidth << " w "; + sAppStream << GetDashPatternString(*pAnnotDict); + + // Set inflated rect as a new rect because paths near the border with large + // width should not be clipped to the original rect. + CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); + rect.Inflate(fBorderWidth / 2, fBorderWidth / 2); + pAnnotDict->SetAtRect("Rect", rect); + + for (size_t i = 0; i < pInkList->GetCount(); i++) { + CPDF_Array* pInkCoordList = pInkList->GetArrayAt(i); + if (!pInkCoordList || pInkCoordList->GetCount() < 2) + continue; + + sAppStream << pInkCoordList->GetNumberAt(0) << " " + << pInkCoordList->GetNumberAt(1) << " m "; + + for (size_t j = 0; j < pInkCoordList->GetCount() - 1; j += 2) { + sAppStream << pInkCoordList->GetNumberAt(j) << " " + << pInkCoordList->GetNumberAt(j + 1) << " l "; + } + + sAppStream << "S\n"; + } + + CPDF_Dictionary* pExtGStateDict = + GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); + GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); + return true; +} + bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { // If AP dictionary exists, we use the appearance defined in the |