Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Unified Diff: core/fpdfdoc/cpvt_generateap.cpp

Issue 2219683002: Generate default AP stream for square annotation. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fpdfdoc/cpvt_generateap.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfdoc/cpvt_generateap.cpp
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 6da25b61f7ab8131212680778215409c0ca4d28b..53b0c4b36e4a04c73d812f901c81f8290fa24885 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -452,10 +452,10 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
return true;
}
-CFX_ByteString GetColorStringWithDefault(CPDF_Dictionary* pAnnotDict,
+CFX_ByteString GetColorStringWithDefault(CPDF_Array* pColor,
Lei Zhang 2016/08/05 02:01:05 What prompted this change? Seemed fine before.
jaepark 2016/08/05 02:49:37 For Square annotation, stroke color is in "C" fiel
Lei Zhang 2016/08/05 17:27:29 Another option is to change this to: enum class C
jaepark 2016/08/05 19:02:19 Acknowledged.
const CPVT_Color& crDefaultColor,
PaintOperation nOperation) {
- if (CPDF_Array* pColor = pAnnotDict->GetArrayBy("C")) {
+ if (pColor) {
CPVT_Color color = CPVT_Color::ParseColor(*pColor);
return CPVT_GenerateAP::GenerateColorAP(color, nOperation);
}
@@ -463,6 +463,40 @@ CFX_ByteString GetColorStringWithDefault(CPDF_Dictionary* pAnnotDict,
return CPVT_GenerateAP::GenerateColorAP(crDefaultColor, nOperation);
}
+FX_FLOAT GetBorderWidth(const CPDF_Dictionary& pAnnotDict) {
+ if (CPDF_Dictionary* pBorderStyleDict = pAnnotDict.GetDictBy("BS")) {
+ if (pBorderStyleDict->KeyExist("W"))
+ return pBorderStyleDict->GetNumberBy("W");
Lei Zhang 2016/08/05 02:01:05 Do you care if this or line 473 returns 0? If a ma
jaepark 2016/08/05 02:49:37 It can be 0, in which case the border will not be
Lei Zhang 2016/08/05 15:50:09 Why don't we generate a test PDF and find out?
jaepark 2016/08/05 19:02:19 Figured out that if the border width is 0 or negat
+ }
+
+ if (CPDF_Array* pBorderArray = pAnnotDict.GetArrayBy("Border"))
+ return pBorderArray->GetNumberAt(2);
+
+ return 1;
+}
+
+CFX_ByteString GetDashArrayInString(const CPDF_Dictionary& pAnnotDict) {
Lei Zhang 2016/08/05 02:01:05 just GetDashArrayString?
jaepark 2016/08/05 02:49:38 Done.
+ CPDF_Array* pDashArray = nullptr;
+
+ if (CPDF_Dictionary* pBorderStyleDict = pAnnotDict.GetDictBy("BS")) {
+ if (pBorderStyleDict->GetStringBy("S") == "D")
+ pDashArray = pBorderStyleDict->GetArrayBy("D");
+ } else if (CPDF_Array* pBorderArray = pAnnotDict.GetArrayBy("Border")) {
+ if (pBorderArray->GetCount() == 4)
+ pDashArray = pBorderArray->GetArrayAt(3);
+ }
+
+ CFX_ByteTextBuf sDashStream;
+ if (pDashArray) {
+ sDashStream << "[" << pDashArray->GetNumberAt(0);
Lei Zhang 2016/08/05 02:01:05 If |pDashArray| is empty, you would get "[ 0 ]", i
jaepark 2016/08/05 02:49:37 I changed it to return empty string when |pDashArr
+ if (pDashArray->GetCount() == 2)
+ sDashStream << " " << pDashArray->GetNumberAt(1);
+ sDashStream << "]";
+ }
+
+ return sDashStream.MakeString();
+}
+
CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict,
const CFX_ByteString& sExtGSDictName,
const CFX_ByteString& sBlendMode) {
@@ -572,8 +606,9 @@ bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc,
CFX_ByteString sExtGSDictName = "GS";
sAppStream << "/" << sExtGSDictName << " gs ";
- sAppStream << GetColorStringWithDefault(
- pAnnotDict, CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), PaintOperation::FILL);
+ sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
+ CPVT_Color(CPVT_Color::kRGB, 1, 1, 0),
+ PaintOperation::FILL);
CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
rect.Normalize();
@@ -601,7 +636,7 @@ bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
CFX_ByteString sExtGSDictName = "GS";
sAppStream << "/" << sExtGSDictName << " gs ";
- sAppStream << GetColorStringWithDefault(pAnnotDict,
+ sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
PaintOperation::STROKE);
@@ -619,6 +654,54 @@ bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
return true;
}
+bool CPVT_GenerateAP::GenerateSquareAP(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 ";
+
+ bool isFillRect = pAnnotDict->GetArrayBy("IC") &&
Lei Zhang 2016/08/05 02:01:05 bIsFillRect for consistency.
Lei Zhang 2016/08/05 02:01:05 Can we save the pointer instead of calling pAnnotD
jaepark 2016/08/05 02:49:38 Done.
jaepark 2016/08/05 02:49:38 Done.
+ (pAnnotDict->GetArrayBy("IC")->GetCount() > 0);
+
+ sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
+ CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
+ PaintOperation::STROKE);
+
+ sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("IC"),
+ CPVT_Color(CPVT_Color::kTransparent),
+ PaintOperation::FILL);
+
+ FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict);
+ sAppStream << fBorderWidth << " w ";
+
+ CFX_ByteString sDashArray = GetDashArrayInString(*pAnnotDict);
+ if (!sDashArray.IsEmpty())
+ sAppStream << sDashArray << " 0 d ";
+
+ CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
+ rect.Normalize();
+
+ // Deflating rect because stroking a path entails painting all points whose
+ // perpendicular distance from the path in user space is less than or equal go
+ // half the line width.
+ rect.Deflate(fBorderWidth / 2, fBorderWidth / 2);
+
+ sAppStream << rect.left << " " << rect.top << " m " << rect.right << " "
+ << rect.top << " l " << rect.right << " " << rect.bottom << " l "
+ << rect.left << " " << rect.bottom << " l "
+ << (isFillRect ? "b" : "s") << "\n";
+
+ CPDF_Dictionary* pExtGStateDict =
+ GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
+ GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
+ return true;
+}
+
bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict) {
// If AP dictionary exists, we use the appearance defined in the
@@ -630,7 +713,7 @@ bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc,
CFX_ByteString sExtGSDictName = "GS";
sAppStream << "/" << sExtGSDictName << " gs ";
- sAppStream << GetColorStringWithDefault(pAnnotDict,
+ sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
PaintOperation::STROKE);
@@ -681,7 +764,7 @@ bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc,
CFX_ByteString sExtGSDictName = "GS";
sAppStream << "/" << sExtGSDictName << " gs ";
- sAppStream << GetColorStringWithDefault(pAnnotDict,
+ sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
PaintOperation::STROKE);
« no previous file with comments | « core/fpdfdoc/cpvt_generateap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698