Chromium Code Reviews| Index: core/fpdfdoc/cpvt_generateap.cpp |
| diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp |
| index 12ba4ef29519e28f47546e285e845481b029733a..f7a922f53f2032de8de8672c7c9af5988c43159b 100644 |
| --- a/core/fpdfdoc/cpvt_generateap.cpp |
| +++ b/core/fpdfdoc/cpvt_generateap.cpp |
| @@ -509,6 +509,47 @@ 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: "); |
| + swValue += pAnnotDict.GetUnicodeTextBy("T"); |
| + swValue += L'\n'; |
| + swValue += pAnnotDict.GetUnicodeTextBy("Contents"); |
| + CPVT_FontMap map(pDoc, nullptr, pDefFont, |
| + sFontName.Right(sFontName.GetLength() - 1)); |
| + |
| + CPDF_VariableText vt; |
| + CPDF_VariableText::Provider prd(&map); |
| + vt.SetProvider(&prd); |
| + CFX_FloatRect rect = pAnnotDict.GetRectBy("Rect"); |
| + vt.SetPlateRect(rect); |
| + vt.SetFontSize(12); |
| + vt.SetAutoReturn(TRUE); |
| + vt.SetMultiLine(TRUE); |
| + |
| + vt.Initialize(); |
| + vt.SetText(swValue.c_str()); |
| + vt.RearrangeAll(); |
| + CFX_FloatRect rcContent = vt.GetContentRect(); |
| + CFX_FloatPoint ptOffset = |
| + CFX_FloatPoint(0.0f, (rcContent.Height() - rect.Height()) / 2.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 +569,39 @@ CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict, |
| return pExtGStateDict; |
| } |
| -// Takes ownership of |pExtGStateDict|. |
| +CPDF_Dictionary* GenerateResourceFontDict(CPDF_Document* pDoc, |
|
dsinclair
2016/08/24 14:00:20
std::unique_ptr?
jaepark
2016/08/24 18:37:48
This is a dictionary that should be set as a key o
|
| + 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"); |
|
dsinclair
2016/08/24 14:00:20
Are these settings spec, or just created? If creat
jaepark
2016/08/24 18:37:48
These are just created. I referred to line 69~77 o
|
| + 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, |
|
dsinclair
2016/08/24 14:00:20
Pass in a std::unique_ptr to show the transfer? (a
jaepark
2016/08/24 18:37:48
Same as above. CPDF_Dictionary takes a raw pointer
|
| + 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 +620,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 +808,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 +837,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 +894,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 +919,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 +948,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"; |
| + |
| + 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 +1033,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 +1084,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 +1113,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; |
| } |