summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/cpvt_generateap.cpp
diff options
context:
space:
mode:
authorjaepark <jaepark@google.com>2016-08-22 17:54:56 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-22 17:54:56 -0700
commitc38de1116bbee807e4461fe8a08e4c152c0fce15 (patch)
tree3a5f8f4a71ad59b1b424357ddab8ecbd1f00ba85 /core/fpdfdoc/cpvt_generateap.cpp
parent7da24e66c6e78a7675697ecec641e3802ff722ca (diff)
downloadpdfium-c38de1116bbee807e4461fe8a08e4c152c0fce15.tar.xz
Generate default AP stream for text annotation.
This patch generates a default AP stream for text annotation. The AP stream only draws a symbol, which represents the presence of text annotation at the point. Also, roll DEPS for testing/corpus to afbac94 to test text annotations. BUG=62625 Review-Url: https://codereview.chromium.org/2270493002
Diffstat (limited to 'core/fpdfdoc/cpvt_generateap.cpp')
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index da3c052b85..12ba4ef295 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -563,6 +563,56 @@ CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) {
return bIsFillRect ? "f" : "n";
}
+CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) {
+ CFX_ByteTextBuf sAppStream;
+ sAppStream << CPVT_GenerateAP::GenerateColorAP(
+ CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), PaintOperation::FILL);
+ sAppStream << CPVT_GenerateAP::GenerateColorAP(
+ CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::STROKE);
+
+ const FX_FLOAT fBorderWidth = 1;
+ sAppStream << fBorderWidth << " w\n";
+
+ const FX_FLOAT fHalfWidth = fBorderWidth / 2;
+ const FX_FLOAT fTipDelta = 4;
+
+ CFX_FloatRect outerRect1 = rect;
+ outerRect1.Deflate(fHalfWidth, fHalfWidth);
+ outerRect1.bottom += fTipDelta;
+
+ CFX_FloatRect outerRect2 = outerRect1;
+ outerRect2.left += fTipDelta;
+ outerRect2.right = outerRect2.left + fTipDelta;
+ outerRect2.top = outerRect2.bottom - fTipDelta;
+ FX_FLOAT outerRect2Middle = (outerRect2.left + outerRect2.right) / 2;
+
+ // Draw outer boxes.
+ sAppStream << outerRect1.left << " " << outerRect1.bottom << " m\n"
+ << outerRect1.left << " " << outerRect1.top << " l\n"
+ << outerRect1.right << " " << outerRect1.top << " l\n"
+ << outerRect1.right << " " << outerRect1.bottom << " l\n"
+ << outerRect2.right << " " << outerRect2.bottom << " l\n"
+ << outerRect2Middle << " " << outerRect2.top << " l\n"
+ << outerRect2.left << " " << outerRect2.bottom << " l\n"
+ << outerRect1.left << " " << outerRect1.bottom << " l\n";
+
+ // Draw inner lines.
+ CFX_FloatRect lineRect = outerRect1;
+ const FX_FLOAT fXDelta = 2;
+ const FX_FLOAT fYDelta = (lineRect.top - lineRect.bottom) / 4;
+
+ lineRect.left += fXDelta;
+ lineRect.right -= fXDelta;
+ for (int i = 0; i < 3; ++i) {
+ lineRect.top -= fYDelta;
+ sAppStream << lineRect.left << " " << lineRect.top << " m\n"
+ << lineRect.right << " " << lineRect.top << " l\n";
+ }
+ sAppStream << "B*\n";
+
+ return sAppStream.MakeString();
+}
+
bool ShouldGenerateAPForAnnotation(CPDF_Dictionary* pAnnotDict) {
// If AP dictionary exists, we use the appearance defined in the
// existing AP dictionary.
@@ -778,6 +828,30 @@ bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc,
return true;
}
+bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc,
+ CPDF_Dictionary* pAnnotDict) {
+ if (!ShouldGenerateAPForAnnotation(pAnnotDict))
+ return false;
+
+ CFX_ByteTextBuf sAppStream;
+ CFX_ByteString sExtGSDictName = "GS";
+ sAppStream << "/" << sExtGSDictName << " gs ";
+
+ CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
+ const FX_FLOAT fNoteLength = 20;
+ CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength,
+ rect.bottom + fNoteLength);
+ pAnnotDict->SetAtRect("Rect", noteRect);
+
+ sAppStream << GenerateTextSymbolAP(noteRect);
+
+ 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 (!ShouldGenerateAPForAnnotation(pAnnotDict))