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

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: Generate default AP stream for square annotation. 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..20d71e453d6ad1551edec990592b3d5e4b159df3 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,
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,47 @@ 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");
+ }
+
+ if (CPDF_Array* pBorderArray = pAnnotDict.GetArrayBy("Border")) {
+ if (pBorderArray->GetCount() > 2)
+ return pBorderArray->GetNumberAt(2);
+ }
+
+ return 1;
+}
+
+CFX_ByteString GetDashPatternString(const CPDF_Dictionary& pAnnotDict) {
+ 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")) {
Lei Zhang 2016/08/05 22:14:45 In GetBorderWidth() above, it checks the "BS" dict
jaepark 2016/08/05 23:07:39 Done.
+ if (pBorderArray->GetCount() == 4)
+ pDashArray = pBorderArray->GetArrayAt(3);
+ }
+
+ if (!pDashArray)
+ return CFX_ByteString();
+
+ size_t pDashArrayCount = pDashArray->GetCount();
+ if (pDashArrayCount == 0 || pDashArrayCount > 10)
+ return CFX_ByteString();
+
+ CFX_ByteTextBuf sDashStream;
+ sDashStream << "[";
+ for (size_t i = 0; i < pDashArrayCount; ++i)
+ sDashStream << pDashArray->GetNumberAt(i) << " ";
+ sDashStream << "] 0 d\n";
+
+ return sDashStream.MakeString();
+}
+
CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict,
const CFX_ByteString& sExtGSDictName,
const CFX_ByteString& sBlendMode) {
@@ -511,6 +552,17 @@ void GenerateAndSetAPDict(CPDF_Document* pDoc,
pStreamDict->SetAt("Resources", pResourceDict);
}
+CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) {
Lei Zhang 2016/08/05 22:14:45 If you want it to be more compact: if (bIsStrokeR
jaepark 2016/08/05 23:07:39 Done.
+ if (bIsStrokeRect && bIsFillRect)
+ return "b";
+ else if (bIsStrokeRect)
Lei Zhang 2016/08/05 22:14:45 no else after return
jaepark 2016/08/05 23:07:39 Done.
+ return "s";
+ else if (bIsFillRect)
+ return "f";
+ else
+ return "n";
+}
+
} // namespace
bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
@@ -572,8 +624,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 +654,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 +672,52 @@ 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 ";
+
+ CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC");
+ sAppStream << GetColorStringWithDefault(pInteriorColor,
+ CPVT_Color(CPVT_Color::kTransparent),
+ PaintOperation::FILL);
+
+ sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
+ CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
+ PaintOperation::STROKE);
+
+ FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict);
+ sAppStream << fBorderWidth << " w ";
Lei Zhang 2016/08/05 22:14:45 So we write into the AP stream, even if the width
jaepark 2016/08/05 23:07:39 Whether to stroke or not depends on the paint oper
Lei Zhang 2016/08/06 00:10:37 I'm just want to make sure we render correctly if
jaepark 2016/08/08 17:17:27 On 2016/08/06 00:10:37, Lei Zhang wrote:
+
+ sAppStream << GetDashPatternString(*pAnnotDict);
+
+ 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);
+
+ bool bIsStrokeRect = fBorderWidth > 0;
+ bool bIsFillRect = pInteriorColor && (pInteriorColor->GetCount() > 0);
+
+ sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " "
+ << rect.Height() << " re "
+ << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\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 +729,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 +780,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