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

Unified Diff: core/fpdfdoc/cpvt_generateap.cpp

Issue 2273893002: Display content of the annotation when mouse hover. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Display content of the annotation when mouse hover. 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
Index: core/fpdfdoc/cpvt_generateap.cpp
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 12ba4ef29519e28f47546e285e845481b029733a..a70c0a61e36e9cbabc1a145365921c5409ba178f 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -509,6 +509,44 @@ CFX_ByteString GetDashPatternString(const CPDF_Dictionary& pAnnotDict) {
return sDashStream.MakeString();
}
+CFX_ByteString GetPopupContentsString(CPDF_Document* pDoc,
+ const CPDF_Dictionary& pAnnotDict,
+ CPDF_Font* pDefFont,
+ const CFX_ByteString& sFontName) {
+ CFX_WideString swValue(L"Author: ");
jaepark 2016/08/29 21:19:24 I've deleted this line because "T" field stands fo
+ swValue += pAnnotDict.GetUnicodeTextBy("T");
Lei Zhang 2016/08/27 02:16:53 Do you care if GetUnicodeTextBy() returns an empty
jaepark 2016/08/29 21:19:24 if GetUnicodeTextBy() returns empty string, we wil
+ swValue += L'\n';
+ swValue += pAnnotDict.GetUnicodeTextBy("Contents");
Lei Zhang 2016/08/27 02:16:53 Similarly, if there's no content, do you still wan
jaepark 2016/08/29 21:19:24 If there is no content, PopupAnnot should not be c
+ CPVT_FontMap map(pDoc, nullptr, pDefFont, sFontName);
+
+ CPDF_VariableText vt;
+ CPDF_VariableText::Provider prd(&map);
+ vt.SetProvider(&prd);
Lei Zhang 2016/08/27 02:16:53 The objects are destroyed in the reverse order of
jaepark 2016/08/29 21:19:24 Done.
+ CFX_FloatRect rect = pAnnotDict.GetRectBy("Rect");
Lei Zhang 2016/08/27 02:16:53 Drop the variable and merge with the next line?
jaepark 2016/08/29 21:19:24 Done.
+ vt.SetPlateRect(rect);
+ vt.SetFontSize(12);
+ vt.SetAutoReturn(TRUE);
+ vt.SetMultiLine(TRUE);
+
+ vt.Initialize();
+ vt.SetText(swValue.c_str());
+ vt.RearrangeAll();
+ CFX_FloatPoint ptOffset(3.0f, -3.0f);
+ CFX_ByteString sContent = CPVT_GenerateAP::GenerateEditAP(
+ &map, vt.GetIterator(), ptOffset, FALSE, 0);
+
+ if (sContent.IsEmpty())
+ return CFX_ByteString();
+
+ CFX_ByteTextBuf sAppStream;
+ sAppStream << "BT\n"
+ << CPVT_GenerateAP::GenerateColorAP(
+ CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::FILL)
+ << sContent << "ET\n"
+ << "Q\n";
+ return sAppStream.MakeString();
+}
+
CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict,
const CFX_ByteString& sExtGSDictName,
const CFX_ByteString& sBlendMode) {
@@ -528,11 +566,39 @@ CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict,
return pExtGStateDict;
}
-// Takes ownership of |pExtGStateDict|.
+CPDF_Dictionary* GenerateResourceFontDict(CPDF_Document* pDoc,
+ const CFX_ByteString& sFontDictName) {
+ CPDF_Dictionary* pFontDict = new CPDF_Dictionary;
+ pFontDict->SetAtName("Type", "Font");
+ pFontDict->SetAtName("Subtype", "Type1");
+ pFontDict->SetAtName("BaseFont", "Helvetica");
+ pFontDict->SetAtName("Encoding", "WinAnsiEncoding");
+ pDoc->AddIndirectObject(pFontDict);
+
+ CPDF_Dictionary* pResourceFontDict = new CPDF_Dictionary;
+ pResourceFontDict->SetAtReference(sFontDictName, pDoc, pFontDict);
+
+ return pResourceFontDict;
+}
+
+// Takes ownership of |pExtGStateDict| and |pResourceFontDict|.
+CPDF_Dictionary* GenerateResourceDict(CPDF_Dictionary* pExtGStateDict,
+ CPDF_Dictionary* pResourceFontDict) {
+ CPDF_Dictionary* pResourceDict = new CPDF_Dictionary;
+ if (pExtGStateDict)
+ pResourceDict->SetAt("ExtGState", pExtGStateDict);
+
+ if (pResourceFontDict)
+ pResourceDict->SetAt("Font", pResourceFontDict);
+
+ return pResourceDict;
+}
+
+// Takes ownership of |pResourceDict|.
void GenerateAndSetAPDict(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict,
const CFX_ByteTextBuf& sAppStream,
- CPDF_Dictionary* pExtGStateDict) {
+ CPDF_Dictionary* pResourceDict) {
CPDF_Dictionary* pAPDict = new CPDF_Dictionary;
pAnnotDict->SetAt("AP", pAPDict);
@@ -551,9 +617,6 @@ void GenerateAndSetAPDict(CPDF_Document* pDoc,
CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
pStreamDict->SetAtRect("BBox", rect);
- CPDF_Dictionary* pResourceDict = new CPDF_Dictionary;
- pResourceDict->SetAt("ExtGState", pExtGStateDict);
-
pStreamDict->SetAt("Resources", pResourceDict);
}
@@ -742,7 +805,9 @@ bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
- GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
+ CPDF_Dictionary* pResourceDict =
+ GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
return true;
}
@@ -769,7 +834,9 @@ bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply");
- GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
+ CPDF_Dictionary* pResourceDict =
+ GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
return true;
}
@@ -824,7 +891,9 @@ bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
- GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
+ CPDF_Dictionary* pResourceDict =
+ GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
return true;
}
@@ -847,8 +916,9 @@ bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
- GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
-
+ CPDF_Dictionary* pResourceDict =
+ GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
return true;
}
@@ -875,7 +945,44 @@ bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
- GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
+ CPDF_Dictionary* pResourceDict =
+ GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
+ return true;
+}
+
+bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc,
+ CPDF_Dictionary* pAnnotDict) {
+ CFX_ByteTextBuf sAppStream;
+ CFX_ByteString sExtGSDictName = "GS";
+ sAppStream << "/" << sExtGSDictName << " gs\n";
+
+ sAppStream << GenerateColorAP(CPVT_Color(CPVT_Color::kRGB, 1, 1, 0),
+ PaintOperation::FILL);
+ sAppStream << GenerateColorAP(CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
+ PaintOperation::STROKE);
+
+ CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
+ rect.Normalize();
+
+ sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " "
+ << rect.Height() << " re "
+ << "b\n";
Lei Zhang 2016/08/27 02:16:53 merge into previous line? i.e. << " re b\n";
jaepark 2016/08/29 21:19:24 Done.
+
+ CFX_ByteString sFontName = "FONT";
+ CPDF_Dictionary* pExtGStateDict =
+ GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
+ CPDF_Dictionary* pResourceFontDict =
+ GenerateResourceFontDict(pDoc, sFontName);
+ CPDF_Dictionary* pResourceDict =
+ GenerateResourceDict(pResourceFontDict, pExtGStateDict);
+
+ CPDF_Font* pDefFont = pDoc->LoadFont(pResourceFontDict);
+ if (!pDefFont)
+ return false;
+
+ sAppStream << GetPopupContentsString(pDoc, *pAnnotDict, pDefFont, sFontName);
+ GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
return true;
}
@@ -923,7 +1030,9 @@ bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
- GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
+ CPDF_Dictionary* pResourceDict =
+ GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
return true;
}
@@ -972,7 +1081,9 @@ bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
- GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
+ CPDF_Dictionary* pResourceDict =
+ GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
return true;
}
@@ -999,7 +1110,9 @@ bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
- GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
+ CPDF_Dictionary* pResourceDict =
+ GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698