From 02e6f5957a56ea492961aef71b3c16cf42ea5998 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Tue, 2 Aug 2016 11:25:48 -0700 Subject: Splitting fpdfdoc/doc_* part I The first of several CLs to split the core/fpdfdoc/doc_* files up to individual class files. Review-Url: https://codereview.chromium.org/2192823002 --- BUILD.gn | 15 +- core/fpdfdoc/cpdf_aaction.cpp | 24 +++ core/fpdfdoc/cpdf_action.cpp | 137 ++++++++++++++++ core/fpdfdoc/cpdf_actionfields.cpp | 96 +++++++++++ core/fpdfdoc/cpdf_bookmark.cpp | 71 ++++++++ core/fpdfdoc/cpdf_bookmarktree.cpp | 34 ++++ core/fpdfdoc/cpdf_docjsactions.cpp | 40 +++++ core/fpdfdoc/cpdf_link.cpp | 32 ++++ core/fpdfdoc/cpdf_linklist.cpp | 70 ++++++++ core/fpdfdoc/cpdf_metadata.cpp | 32 ++++ core/fpdfdoc/cpdf_viewerpreferences.cpp | 44 +++++ core/fpdfdoc/doc_action.cpp | 271 ------------------------------- core/fpdfdoc/doc_bookmark.cpp | 104 ------------ core/fpdfdoc/doc_link.cpp | 94 ----------- core/fpdfdoc/doc_metadata.cpp | 32 ---- core/fpdfdoc/doc_viewerPreferences.cpp | 44 ----- core/fpdfdoc/include/cpdf_actionfields.h | 2 + pdfium.gyp | 15 +- 18 files changed, 602 insertions(+), 555 deletions(-) create mode 100644 core/fpdfdoc/cpdf_aaction.cpp create mode 100644 core/fpdfdoc/cpdf_action.cpp create mode 100644 core/fpdfdoc/cpdf_actionfields.cpp create mode 100644 core/fpdfdoc/cpdf_bookmark.cpp create mode 100644 core/fpdfdoc/cpdf_bookmarktree.cpp create mode 100644 core/fpdfdoc/cpdf_docjsactions.cpp create mode 100644 core/fpdfdoc/cpdf_link.cpp create mode 100644 core/fpdfdoc/cpdf_linklist.cpp create mode 100644 core/fpdfdoc/cpdf_metadata.cpp create mode 100644 core/fpdfdoc/cpdf_viewerpreferences.cpp delete mode 100644 core/fpdfdoc/doc_action.cpp delete mode 100644 core/fpdfdoc/doc_bookmark.cpp delete mode 100644 core/fpdfdoc/doc_link.cpp delete mode 100644 core/fpdfdoc/doc_metadata.cpp delete mode 100644 core/fpdfdoc/doc_viewerPreferences.cpp diff --git a/BUILD.gn b/BUILD.gn index f7a6007e0c..f482a5b4c9 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -202,11 +202,21 @@ static_library("fpdfdoc") { sources = [ "core/fpdfdoc/clines.cpp", "core/fpdfdoc/clines.h", + "core/fpdfdoc/cpdf_aaction.cpp", + "core/fpdfdoc/cpdf_action.cpp", + "core/fpdfdoc/cpdf_actionfields.cpp", "core/fpdfdoc/cpdf_annot.cpp", "core/fpdfdoc/cpdf_annotlist.cpp", "core/fpdfdoc/cpdf_apsettings.h", + "core/fpdfdoc/cpdf_bookmark.cpp", + "core/fpdfdoc/cpdf_bookmarktree.cpp", + "core/fpdfdoc/cpdf_docjsactions.cpp", + "core/fpdfdoc/cpdf_link.cpp", + "core/fpdfdoc/cpdf_linklist.cpp", + "core/fpdfdoc/cpdf_metadata.cpp", "core/fpdfdoc/cpdf_pagelabel.h", "core/fpdfdoc/cpdf_variabletext.cpp", + "core/fpdfdoc/cpdf_viewerpreferences.cpp", "core/fpdfdoc/cpvt_color.cpp", "core/fpdfdoc/cpvt_color.h", "core/fpdfdoc/cpvt_dash.h", @@ -224,18 +234,13 @@ static_library("fpdfdoc") { "core/fpdfdoc/csection.h", "core/fpdfdoc/ctypeset.cpp", "core/fpdfdoc/ctypeset.h", - "core/fpdfdoc/doc_action.cpp", "core/fpdfdoc/doc_basic.cpp", - "core/fpdfdoc/doc_bookmark.cpp", "core/fpdfdoc/doc_form.cpp", "core/fpdfdoc/doc_formcontrol.cpp", "core/fpdfdoc/doc_formfield.cpp", - "core/fpdfdoc/doc_link.cpp", - "core/fpdfdoc/doc_metadata.cpp", "core/fpdfdoc/doc_ocg.cpp", "core/fpdfdoc/doc_utils.cpp", "core/fpdfdoc/doc_utils.h", - "core/fpdfdoc/doc_viewerPreferences.cpp", "core/fpdfdoc/doc_vt.cpp", "core/fpdfdoc/include/cpdf_aaction.h", "core/fpdfdoc/include/cpdf_action.h", diff --git a/core/fpdfdoc/cpdf_aaction.cpp b/core/fpdfdoc/cpdf_aaction.cpp new file mode 100644 index 0000000000..c2d77cf083 --- /dev/null +++ b/core/fpdfdoc/cpdf_aaction.cpp @@ -0,0 +1,24 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfdoc/include/cpdf_aaction.h" + +namespace { + +const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC", + "PV", "PI", "O", "C", "K", "F", "V", "C", + "WC", "WS", "DS", "WP", "DP", ""}; + +} // namespace + +FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const { + return m_pDict && m_pDict->KeyExist(g_sAATypes[eType]); +} + +CPDF_Action CPDF_AAction::GetAction(AActionType eType) const { + return m_pDict ? CPDF_Action(m_pDict->GetDictBy(g_sAATypes[eType])) + : CPDF_Action(); +} diff --git a/core/fpdfdoc/cpdf_action.cpp b/core/fpdfdoc/cpdf_action.cpp new file mode 100644 index 0000000000..86fc20ef2f --- /dev/null +++ b/core/fpdfdoc/cpdf_action.cpp @@ -0,0 +1,137 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfdoc/include/cpdf_action.h" + +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fpdfdoc/include/cpdf_filespec.h" +#include "core/fpdfdoc/include/cpdf_nametree.h" + +namespace { + +const FX_CHAR* const g_sATypes[] = { + "Unknown", "GoTo", "GoToR", "GoToE", "Launch", + "Thread", "URI", "Sound", "Movie", "Hide", + "Named", "SubmitForm", "ResetForm", "ImportData", "JavaScript", + "SetOCGState", "Rendition", "Trans", "GoTo3DView", nullptr}; + +} // namespace + +CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { + if (!m_pDict) + return CPDF_Dest(); + + CFX_ByteString type = m_pDict->GetStringBy("S"); + if (type != "GoTo" && type != "GoToR") + return CPDF_Dest(); + + CPDF_Object* pDest = m_pDict->GetDirectObjectBy("D"); + if (!pDest) + return CPDF_Dest(); + if (pDest->IsString() || pDest->IsName()) { + CPDF_NameTree name_tree(pDoc, "Dests"); + return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetString())); + } + if (CPDF_Array* pArray = pDest->AsArray()) + return CPDF_Dest(pArray); + + return CPDF_Dest(); +} + +CPDF_Action::ActionType CPDF_Action::GetType() const { + if (!m_pDict) + return Unknown; + + CFX_ByteString csType = m_pDict->GetStringBy("S"); + if (csType.IsEmpty()) + return Unknown; + + for (int i = 0; g_sATypes[i]; ++i) { + if (csType == g_sATypes[i]) + return static_cast(i); + } + return Unknown; +} + +CFX_WideString CPDF_Action::GetFilePath() const { + CFX_ByteString type = m_pDict->GetStringBy("S"); + if (type != "GoToR" && type != "Launch" && type != "SubmitForm" && + type != "ImportData") { + return CFX_WideString(); + } + + CPDF_Object* pFile = m_pDict->GetDirectObjectBy("F"); + CFX_WideString path; + if (!pFile) { + if (type == "Launch") { + CPDF_Dictionary* pWinDict = m_pDict->GetDictBy("Win"); + if (pWinDict) { + return CFX_WideString::FromLocal( + pWinDict->GetStringBy("F").AsStringC()); + } + } + return path; + } + + CPDF_FileSpec filespec(pFile); + filespec.GetFileName(&path); + return path; +} + +CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const { + CFX_ByteString csURI; + if (!m_pDict) + return csURI; + if (m_pDict->GetStringBy("S") != "URI") + return csURI; + + csURI = m_pDict->GetStringBy("URI"); + CPDF_Dictionary* pRoot = pDoc->GetRoot(); + CPDF_Dictionary* pURI = pRoot->GetDictBy("URI"); + if (pURI) { + if (csURI.Find(":", 0) < 1) + csURI = pURI->GetStringBy("Base") + csURI; + } + return csURI; +} + +CFX_WideString CPDF_Action::GetJavaScript() const { + CFX_WideString csJS; + if (!m_pDict) + return csJS; + + CPDF_Object* pJS = m_pDict->GetDirectObjectBy("JS"); + return pJS ? pJS->GetUnicodeText() : csJS; +} + +size_t CPDF_Action::GetSubActionsCount() const { + if (!m_pDict || !m_pDict->KeyExist("Next")) + return 0; + + CPDF_Object* pNext = m_pDict->GetDirectObjectBy("Next"); + if (!pNext) + return 0; + if (pNext->IsDictionary()) + return 1; + if (CPDF_Array* pArray = pNext->AsArray()) + return pArray->GetCount(); + return 0; +} + +CPDF_Action CPDF_Action::GetSubAction(size_t iIndex) const { + if (!m_pDict || !m_pDict->KeyExist("Next")) + return CPDF_Action(); + + CPDF_Object* pNext = m_pDict->GetDirectObjectBy("Next"); + if (CPDF_Dictionary* pDict = ToDictionary(pNext)) { + if (iIndex == 0) + return CPDF_Action(pDict); + } else if (CPDF_Array* pArray = ToArray(pNext)) { + return CPDF_Action(pArray->GetDictAt(iIndex)); + } + return CPDF_Action(); +} diff --git a/core/fpdfdoc/cpdf_actionfields.cpp b/core/fpdfdoc/cpdf_actionfields.cpp new file mode 100644 index 0000000000..1ad1eb4673 --- /dev/null +++ b/core/fpdfdoc/cpdf_actionfields.cpp @@ -0,0 +1,96 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfdoc/include/cpdf_actionfields.h" + +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfdoc/include/cpdf_action.h" + +size_t CPDF_ActionFields::GetFieldsCount() const { + if (!m_pAction) + return 0; + + CPDF_Dictionary* pDict = m_pAction->GetDict(); + if (!pDict) + return 0; + + CFX_ByteString csType = pDict->GetStringBy("S"); + CPDF_Object* pFields = nullptr; + if (csType == "Hide") + pFields = pDict->GetDirectObjectBy("T"); + else + pFields = pDict->GetArrayBy("Fields"); + + if (!pFields) + return 0; + if (pFields->IsDictionary()) + return 1; + if (pFields->IsString()) + return 1; + if (CPDF_Array* pArray = pFields->AsArray()) + return pArray->GetCount(); + return 0; +} + +std::vector CPDF_ActionFields::GetAllFields() const { + std::vector fields; + if (!m_pAction) + return fields; + + CPDF_Dictionary* pDict = m_pAction->GetDict(); + if (!pDict) + return fields; + + CFX_ByteString csType = pDict->GetStringBy("S"); + CPDF_Object* pFields; + if (csType == "Hide") + pFields = pDict->GetDirectObjectBy("T"); + else + pFields = pDict->GetArrayBy("Fields"); + + if (!pFields) + return fields; + + if (pFields->IsDictionary() || pFields->IsString()) { + fields.push_back(pFields); + } else if (CPDF_Array* pArray = pFields->AsArray()) { + for (size_t i = 0; i < pArray->GetCount(); ++i) { + CPDF_Object* pObj = pArray->GetDirectObjectAt(i); + if (pObj) + fields.push_back(pObj); + } + } + return fields; +} + +CPDF_Object* CPDF_ActionFields::GetField(size_t iIndex) const { + if (!m_pAction) + return nullptr; + + CPDF_Dictionary* pDict = m_pAction->GetDict(); + if (!pDict) + return nullptr; + + CFX_ByteString csType = pDict->GetStringBy("S"); + CPDF_Object* pFields = nullptr; + if (csType == "Hide") + pFields = pDict->GetDirectObjectBy("T"); + else + pFields = pDict->GetArrayBy("Fields"); + + if (!pFields) + return nullptr; + + CPDF_Object* pFindObj = nullptr; + if (pFields->IsDictionary() || pFields->IsString()) { + if (iIndex == 0) + pFindObj = pFields; + } else if (CPDF_Array* pArray = pFields->AsArray()) { + pFindObj = pArray->GetDirectObjectAt(iIndex); + } + return pFindObj; +} diff --git a/core/fpdfdoc/cpdf_bookmark.cpp b/core/fpdfdoc/cpdf_bookmark.cpp new file mode 100644 index 0000000000..c9a2199750 --- /dev/null +++ b/core/fpdfdoc/cpdf_bookmark.cpp @@ -0,0 +1,71 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfdoc/include/cpdf_bookmark.h" + +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" +#include "core/fpdfdoc/include/cpdf_nametree.h" +#include "core/fxge/include/fx_dib.h" + +uint32_t CPDF_Bookmark::GetColorRef() const { + if (!m_pDict) + return FXSYS_RGB(0, 0, 0); + + CPDF_Array* pColor = m_pDict->GetArrayBy("C"); + if (!pColor) + return FXSYS_RGB(0, 0, 0); + + int r = FXSYS_round(pColor->GetNumberAt(0) * 255); + int g = FXSYS_round(pColor->GetNumberAt(1) * 255); + int b = FXSYS_round(pColor->GetNumberAt(2) * 255); + return FXSYS_RGB(r, g, b); +} + +uint32_t CPDF_Bookmark::GetFontStyle() const { + return m_pDict ? m_pDict->GetIntegerBy("F") : 0; +} + +CFX_WideString CPDF_Bookmark::GetTitle() const { + if (!m_pDict) + return CFX_WideString(); + + CPDF_String* pString = ToString(m_pDict->GetDirectObjectBy("Title")); + if (!pString) + return CFX_WideString(); + + CFX_WideString title = pString->GetUnicodeText(); + int len = title.GetLength(); + if (!len) + return CFX_WideString(); + + std::unique_ptr buf(new FX_WCHAR[len]); + for (int i = 0; i < len; i++) { + FX_WCHAR w = title[i]; + buf[i] = w > 0x20 ? w : 0x20; + } + return CFX_WideString(buf.get(), len); +} + +CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const { + if (!m_pDict) + return CPDF_Dest(); + + CPDF_Object* pDest = m_pDict->GetDirectObjectBy("Dest"); + if (!pDest) + return CPDF_Dest(); + if (pDest->IsString() || pDest->IsName()) { + CPDF_NameTree name_tree(pDocument, "Dests"); + return CPDF_Dest(name_tree.LookupNamedDest(pDocument, pDest->GetString())); + } + if (CPDF_Array* pArray = pDest->AsArray()) + return CPDF_Dest(pArray); + return CPDF_Dest(); +} + +CPDF_Action CPDF_Bookmark::GetAction() const { + return m_pDict ? CPDF_Action(m_pDict->GetDictBy("A")) : CPDF_Action(); +} diff --git a/core/fpdfdoc/cpdf_bookmarktree.cpp b/core/fpdfdoc/cpdf_bookmarktree.cpp new file mode 100644 index 0000000000..5ebb317a06 --- /dev/null +++ b/core/fpdfdoc/cpdf_bookmarktree.cpp @@ -0,0 +1,34 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfdoc/include/cpdf_bookmarktree.h" + +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" + +CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild( + const CPDF_Bookmark& parent) const { + CPDF_Dictionary* pParentDict = parent.GetDict(); + if (pParentDict) + return CPDF_Bookmark(pParentDict->GetDictBy("First")); + + CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); + if (!pRoot) + return CPDF_Bookmark(); + + CPDF_Dictionary* pOutlines = pRoot->GetDictBy("Outlines"); + return pOutlines ? CPDF_Bookmark(pOutlines->GetDictBy("First")) + : CPDF_Bookmark(); +} + +CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling( + const CPDF_Bookmark& bookmark) const { + CPDF_Dictionary* pDict = bookmark.GetDict(); + if (!pDict) + return CPDF_Bookmark(); + + CPDF_Dictionary* pNext = pDict->GetDictBy("Next"); + return pNext == pDict ? CPDF_Bookmark() : CPDF_Bookmark(pNext); +} diff --git a/core/fpdfdoc/cpdf_docjsactions.cpp b/core/fpdfdoc/cpdf_docjsactions.cpp new file mode 100644 index 0000000000..897cdac610 --- /dev/null +++ b/core/fpdfdoc/cpdf_docjsactions.cpp @@ -0,0 +1,40 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfdoc/include/cpdf_docjsactions.h" + +#include "core/fpdfdoc/include/cpdf_nametree.h" + +CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) : m_pDocument(pDoc) {} + +int CPDF_DocJSActions::CountJSActions() const { + ASSERT(m_pDocument); + CPDF_NameTree name_tree(m_pDocument, "JavaScript"); + return name_tree.GetCount(); +} + +CPDF_Action CPDF_DocJSActions::GetJSAction(int index, + CFX_ByteString& csName) const { + ASSERT(m_pDocument); + CPDF_NameTree name_tree(m_pDocument, "JavaScript"); + CPDF_Object* pAction = name_tree.LookupValue(index, csName); + return ToDictionary(pAction) ? CPDF_Action(pAction->GetDict()) + : CPDF_Action(); +} + +CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const { + ASSERT(m_pDocument); + CPDF_NameTree name_tree(m_pDocument, "JavaScript"); + CPDF_Object* pAction = name_tree.LookupValue(csName); + return ToDictionary(pAction) ? CPDF_Action(pAction->GetDict()) + : CPDF_Action(); +} + +int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { + ASSERT(m_pDocument); + CPDF_NameTree name_tree(m_pDocument, "JavaScript"); + return name_tree.GetIndex(csName); +} diff --git a/core/fpdfdoc/cpdf_link.cpp b/core/fpdfdoc/cpdf_link.cpp new file mode 100644 index 0000000000..4859881198 --- /dev/null +++ b/core/fpdfdoc/cpdf_link.cpp @@ -0,0 +1,32 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfdoc/include/cpdf_link.h" + +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfdoc/include/cpdf_nametree.h" + +CFX_FloatRect CPDF_Link::GetRect() { + return m_pDict->GetRectBy("Rect"); +} + +CPDF_Dest CPDF_Link::GetDest(CPDF_Document* pDoc) { + CPDF_Object* pDest = m_pDict->GetDirectObjectBy("Dest"); + if (!pDest) + return CPDF_Dest(); + + if (pDest->IsString() || pDest->IsName()) { + CPDF_NameTree name_tree(pDoc, "Dests"); + return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetString())); + } + if (CPDF_Array* pArray = pDest->AsArray()) + return CPDF_Dest(pArray); + return CPDF_Dest(); +} + +CPDF_Action CPDF_Link::GetAction() { + return CPDF_Action(m_pDict->GetDictBy("A")); +} diff --git a/core/fpdfdoc/cpdf_linklist.cpp b/core/fpdfdoc/cpdf_linklist.cpp new file mode 100644 index 0000000000..5ef8f39da6 --- /dev/null +++ b/core/fpdfdoc/cpdf_linklist.cpp @@ -0,0 +1,70 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfdoc/include/cpdf_linklist.h" + +#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" + +CPDF_LinkList::CPDF_LinkList() {} + +CPDF_LinkList::~CPDF_LinkList() {} + +const std::vector* CPDF_LinkList::GetPageLinks( + CPDF_Page* pPage) { + uint32_t objnum = pPage->m_pFormDict->GetObjNum(); + if (objnum == 0) + return nullptr; + + auto it = m_PageMap.find(objnum); + if (it != m_PageMap.end()) + return &it->second; + + // std::map::operator[] forces the creation of a map entry. + std::vector& page_link_list = m_PageMap[objnum]; + LoadPageLinks(pPage, &page_link_list); + return &page_link_list; +} + +CPDF_Link CPDF_LinkList::GetLinkAtPoint(CPDF_Page* pPage, + FX_FLOAT pdf_x, + FX_FLOAT pdf_y, + int* z_order) { + const std::vector* pPageLinkList = GetPageLinks(pPage); + if (!pPageLinkList) + return CPDF_Link(); + + for (size_t i = pPageLinkList->size(); i > 0; --i) { + size_t annot_index = i - 1; + CPDF_Dictionary* pAnnot = (*pPageLinkList)[annot_index]; + if (!pAnnot) + continue; + + CPDF_Link link(pAnnot); + CFX_FloatRect rect = link.GetRect(); + if (!rect.Contains(pdf_x, pdf_y)) + continue; + + if (z_order) + *z_order = annot_index; + return link; + } + return CPDF_Link(); +} + +void CPDF_LinkList::LoadPageLinks(CPDF_Page* pPage, + std::vector* pList) { + CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArrayBy("Annots"); + if (!pAnnotList) + return; + + for (size_t i = 0; i < pAnnotList->GetCount(); ++i) { + CPDF_Dictionary* pAnnot = pAnnotList->GetDictAt(i); + bool add_link = (pAnnot && pAnnot->GetStringBy("Subtype") == "Link"); + // Add non-links as nullptrs to preserve z-order. + pList->push_back(add_link ? pAnnot : nullptr); + } +} diff --git a/core/fpdfdoc/cpdf_metadata.cpp b/core/fpdfdoc/cpdf_metadata.cpp new file mode 100644 index 0000000000..b53da07652 --- /dev/null +++ b/core/fpdfdoc/cpdf_metadata.cpp @@ -0,0 +1,32 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfdoc/include/cpdf_metadata.h" + +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" +#include "core/fxcrt/include/fx_xml.h" + +CPDF_Metadata::CPDF_Metadata(CPDF_Document* pDoc) { + CPDF_Dictionary* pRoot = pDoc->GetRoot(); + if (!pRoot) + return; + + CPDF_Stream* pStream = pRoot->GetStreamBy("Metadata"); + if (!pStream) + return; + + CPDF_StreamAcc acc; + acc.LoadAllData(pStream, FALSE); + m_pXmlElement.reset(CXML_Element::Parse(acc.GetData(), acc.GetSize())); +} + +CPDF_Metadata::~CPDF_Metadata() {} + +const CXML_Element* CPDF_Metadata::GetRoot() const { + return m_pXmlElement.get(); +} diff --git a/core/fpdfdoc/cpdf_viewerpreferences.cpp b/core/fpdfdoc/cpdf_viewerpreferences.cpp new file mode 100644 index 0000000000..4951e5ff5d --- /dev/null +++ b/core/fpdfdoc/cpdf_viewerpreferences.cpp @@ -0,0 +1,44 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfdoc/include/cpdf_viewerpreferences.h" + +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" + +CPDF_ViewerPreferences::CPDF_ViewerPreferences(CPDF_Document* pDoc) + : m_pDoc(pDoc) {} + +CPDF_ViewerPreferences::~CPDF_ViewerPreferences() {} + +FX_BOOL CPDF_ViewerPreferences::IsDirectionR2L() const { + CPDF_Dictionary* pDict = GetViewerPreferences(); + return pDict ? pDict->GetStringBy("Direction") == "R2L" : FALSE; +} + +FX_BOOL CPDF_ViewerPreferences::PrintScaling() const { + CPDF_Dictionary* pDict = GetViewerPreferences(); + return pDict ? pDict->GetStringBy("PrintScaling") != "None" : TRUE; +} + +int32_t CPDF_ViewerPreferences::NumCopies() const { + CPDF_Dictionary* pDict = GetViewerPreferences(); + return pDict ? pDict->GetIntegerBy("NumCopies") : 1; +} + +CPDF_Array* CPDF_ViewerPreferences::PrintPageRange() const { + CPDF_Dictionary* pDict = GetViewerPreferences(); + return pDict ? pDict->GetArrayBy("PrintPageRange") : nullptr; +} + +CFX_ByteString CPDF_ViewerPreferences::Duplex() const { + CPDF_Dictionary* pDict = GetViewerPreferences(); + return pDict ? pDict->GetStringBy("Duplex") : CFX_ByteString("None"); +} + +CPDF_Dictionary* CPDF_ViewerPreferences::GetViewerPreferences() const { + CPDF_Dictionary* pDict = m_pDoc->GetRoot(); + return pDict ? pDict->GetDictBy("ViewerPreferences") : nullptr; +} diff --git a/core/fpdfdoc/doc_action.cpp b/core/fpdfdoc/doc_action.cpp deleted file mode 100644 index 30d4006b54..0000000000 --- a/core/fpdfdoc/doc_action.cpp +++ /dev/null @@ -1,271 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fpdfdoc/include/cpdf_action.h" - -#include - -#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" -#include "core/fpdfdoc/include/cpdf_aaction.h" -#include "core/fpdfdoc/include/cpdf_actionfields.h" -#include "core/fpdfdoc/include/cpdf_docjsactions.h" -#include "core/fpdfdoc/include/cpdf_filespec.h" -#include "core/fpdfdoc/include/cpdf_nametree.h" - -namespace { - -const FX_CHAR* const g_sATypes[] = { - "Unknown", "GoTo", "GoToR", "GoToE", "Launch", - "Thread", "URI", "Sound", "Movie", "Hide", - "Named", "SubmitForm", "ResetForm", "ImportData", "JavaScript", - "SetOCGState", "Rendition", "Trans", "GoTo3DView", nullptr}; - -const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC", - "PV", "PI", "O", "C", "K", "F", "V", "C", - "WC", "WS", "DS", "WP", "DP", ""}; - -} // namespace - -CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { - if (!m_pDict) { - return CPDF_Dest(); - } - CFX_ByteString type = m_pDict->GetStringBy("S"); - if (type != "GoTo" && type != "GoToR") { - return CPDF_Dest(); - } - CPDF_Object* pDest = m_pDict->GetDirectObjectBy("D"); - if (!pDest) { - return CPDF_Dest(); - } - if (pDest->IsString() || pDest->IsName()) { - CPDF_NameTree name_tree(pDoc, "Dests"); - return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetString())); - } - if (CPDF_Array* pArray = pDest->AsArray()) - return CPDF_Dest(pArray); - return CPDF_Dest(); -} - -CPDF_Action::ActionType CPDF_Action::GetType() const { - if (!m_pDict) - return Unknown; - - CFX_ByteString csType = m_pDict->GetStringBy("S"); - if (csType.IsEmpty()) - return Unknown; - - for (int i = 0; g_sATypes[i]; ++i) { - if (csType == g_sATypes[i]) - return static_cast(i); - } - return Unknown; -} - -CFX_WideString CPDF_Action::GetFilePath() const { - CFX_ByteString type = m_pDict->GetStringBy("S"); - if (type != "GoToR" && type != "Launch" && type != "SubmitForm" && - type != "ImportData") { - return CFX_WideString(); - } - CPDF_Object* pFile = m_pDict->GetDirectObjectBy("F"); - CFX_WideString path; - if (!pFile) { - if (type == "Launch") { - CPDF_Dictionary* pWinDict = m_pDict->GetDictBy("Win"); - if (pWinDict) { - return CFX_WideString::FromLocal( - pWinDict->GetStringBy("F").AsStringC()); - } - } - return path; - } - CPDF_FileSpec filespec(pFile); - filespec.GetFileName(&path); - return path; -} -CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const { - CFX_ByteString csURI; - if (!m_pDict) { - return csURI; - } - if (m_pDict->GetStringBy("S") != "URI") { - return csURI; - } - csURI = m_pDict->GetStringBy("URI"); - CPDF_Dictionary* pRoot = pDoc->GetRoot(); - CPDF_Dictionary* pURI = pRoot->GetDictBy("URI"); - if (pURI) { - if (csURI.Find(":", 0) < 1) { - csURI = pURI->GetStringBy("Base") + csURI; - } - } - return csURI; -} -size_t CPDF_ActionFields::GetFieldsCount() const { - if (!m_pAction) { - return 0; - } - CPDF_Dictionary* pDict = m_pAction->GetDict(); - if (!pDict) { - return 0; - } - CFX_ByteString csType = pDict->GetStringBy("S"); - CPDF_Object* pFields = nullptr; - if (csType == "Hide") { - pFields = pDict->GetDirectObjectBy("T"); - } else { - pFields = pDict->GetArrayBy("Fields"); - } - if (!pFields) - return 0; - if (pFields->IsDictionary()) - return 1; - if (pFields->IsString()) - return 1; - if (CPDF_Array* pArray = pFields->AsArray()) - return pArray->GetCount(); - return 0; -} - -std::vector CPDF_ActionFields::GetAllFields() const { - std::vector fields; - if (!m_pAction) - return fields; - - CPDF_Dictionary* pDict = m_pAction->GetDict(); - if (!pDict) - return fields; - - CFX_ByteString csType = pDict->GetStringBy("S"); - CPDF_Object* pFields; - if (csType == "Hide") - pFields = pDict->GetDirectObjectBy("T"); - else - pFields = pDict->GetArrayBy("Fields"); - if (!pFields) - return fields; - - if (pFields->IsDictionary() || pFields->IsString()) { - fields.push_back(pFields); - } else if (CPDF_Array* pArray = pFields->AsArray()) { - for (size_t i = 0; i < pArray->GetCount(); ++i) { - CPDF_Object* pObj = pArray->GetDirectObjectAt(i); - if (pObj) { - fields.push_back(pObj); - } - } - } - return fields; -} - -CPDF_Object* CPDF_ActionFields::GetField(size_t iIndex) const { - if (!m_pAction) { - return nullptr; - } - CPDF_Dictionary* pDict = m_pAction->GetDict(); - if (!pDict) { - return nullptr; - } - CFX_ByteString csType = pDict->GetStringBy("S"); - CPDF_Object* pFields = nullptr; - if (csType == "Hide") { - pFields = pDict->GetDirectObjectBy("T"); - } else { - pFields = pDict->GetArrayBy("Fields"); - } - if (!pFields) { - return nullptr; - } - CPDF_Object* pFindObj = nullptr; - if (pFields->IsDictionary() || pFields->IsString()) { - if (iIndex == 0) - pFindObj = pFields; - } else if (CPDF_Array* pArray = pFields->AsArray()) { - pFindObj = pArray->GetDirectObjectAt(iIndex); - } - return pFindObj; -} - -CFX_WideString CPDF_Action::GetJavaScript() const { - CFX_WideString csJS; - if (!m_pDict) { - return csJS; - } - CPDF_Object* pJS = m_pDict->GetDirectObjectBy("JS"); - return pJS ? pJS->GetUnicodeText() : csJS; -} - -size_t CPDF_Action::GetSubActionsCount() const { - if (!m_pDict || !m_pDict->KeyExist("Next")) - return 0; - - CPDF_Object* pNext = m_pDict->GetDirectObjectBy("Next"); - if (!pNext) - return 0; - if (pNext->IsDictionary()) - return 1; - if (CPDF_Array* pArray = pNext->AsArray()) - return pArray->GetCount(); - return 0; -} -CPDF_Action CPDF_Action::GetSubAction(size_t iIndex) const { - if (!m_pDict || !m_pDict->KeyExist("Next")) { - return CPDF_Action(); - } - CPDF_Object* pNext = m_pDict->GetDirectObjectBy("Next"); - if (CPDF_Dictionary* pDict = ToDictionary(pNext)) { - if (iIndex == 0) - return CPDF_Action(pDict); - } else if (CPDF_Array* pArray = ToArray(pNext)) { - return CPDF_Action(pArray->GetDictAt(iIndex)); - } - return CPDF_Action(); -} - -FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const { - return m_pDict && m_pDict->KeyExist(g_sAATypes[eType]); -} - -CPDF_Action CPDF_AAction::GetAction(AActionType eType) const { - if (!m_pDict) - return CPDF_Action(); - - return CPDF_Action(m_pDict->GetDictBy(g_sAATypes[eType])); -} - -CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) : m_pDocument(pDoc) {} - -int CPDF_DocJSActions::CountJSActions() const { - ASSERT(m_pDocument); - CPDF_NameTree name_tree(m_pDocument, "JavaScript"); - return name_tree.GetCount(); -} -CPDF_Action CPDF_DocJSActions::GetJSAction(int index, - CFX_ByteString& csName) const { - ASSERT(m_pDocument); - CPDF_NameTree name_tree(m_pDocument, "JavaScript"); - CPDF_Object* pAction = name_tree.LookupValue(index, csName); - if (!ToDictionary(pAction)) { - return CPDF_Action(); - } - return CPDF_Action(pAction->GetDict()); -} -CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const { - ASSERT(m_pDocument); - CPDF_NameTree name_tree(m_pDocument, "JavaScript"); - CPDF_Object* pAction = name_tree.LookupValue(csName); - if (!ToDictionary(pAction)) { - return CPDF_Action(); - } - return CPDF_Action(pAction->GetDict()); -} -int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { - ASSERT(m_pDocument); - CPDF_NameTree name_tree(m_pDocument, "JavaScript"); - return name_tree.GetIndex(csName); -} diff --git a/core/fpdfdoc/doc_bookmark.cpp b/core/fpdfdoc/doc_bookmark.cpp deleted file mode 100644 index 8a0054e98c..0000000000 --- a/core/fpdfdoc/doc_bookmark.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fpdfdoc/include/cpdf_bookmark.h" - -#include -#include - -#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" -#include "core/fpdfdoc/include/cpdf_bookmarktree.h" -#include "core/fpdfdoc/include/cpdf_nametree.h" -#include "core/fxge/include/fx_dib.h" - -CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild( - const CPDF_Bookmark& parent) const { - CPDF_Dictionary* pParentDict = parent.GetDict(); - if (pParentDict) - return CPDF_Bookmark(pParentDict->GetDictBy("First")); - - CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); - if (!pRoot) - return CPDF_Bookmark(); - - CPDF_Dictionary* pOutlines = pRoot->GetDictBy("Outlines"); - if (!pOutlines) - return CPDF_Bookmark(); - - return CPDF_Bookmark(pOutlines->GetDictBy("First")); -} - -CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling( - const CPDF_Bookmark& bookmark) const { - CPDF_Dictionary* pDict = bookmark.GetDict(); - if (!pDict) - return CPDF_Bookmark(); - - CPDF_Dictionary* pNext = pDict->GetDictBy("Next"); - return pNext == pDict ? CPDF_Bookmark() : CPDF_Bookmark(pNext); -} - -uint32_t CPDF_Bookmark::GetColorRef() const { - if (!m_pDict) - return FXSYS_RGB(0, 0, 0); - - CPDF_Array* pColor = m_pDict->GetArrayBy("C"); - if (!pColor) - return FXSYS_RGB(0, 0, 0); - - int r = FXSYS_round(pColor->GetNumberAt(0) * 255); - int g = FXSYS_round(pColor->GetNumberAt(1) * 255); - int b = FXSYS_round(pColor->GetNumberAt(2) * 255); - return FXSYS_RGB(r, g, b); -} - -uint32_t CPDF_Bookmark::GetFontStyle() const { - return m_pDict ? m_pDict->GetIntegerBy("F") : 0; -} - -CFX_WideString CPDF_Bookmark::GetTitle() const { - if (!m_pDict) { - return CFX_WideString(); - } - CPDF_String* pString = ToString(m_pDict->GetDirectObjectBy("Title")); - if (!pString) - return CFX_WideString(); - - CFX_WideString title = pString->GetUnicodeText(); - int len = title.GetLength(); - if (!len) { - return CFX_WideString(); - } - std::unique_ptr buf(new FX_WCHAR[len]); - for (int i = 0; i < len; i++) { - FX_WCHAR w = title[i]; - buf[i] = w > 0x20 ? w : 0x20; - } - return CFX_WideString(buf.get(), len); -} -CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const { - if (!m_pDict) - return CPDF_Dest(); - - CPDF_Object* pDest = m_pDict->GetDirectObjectBy("Dest"); - if (!pDest) - return CPDF_Dest(); - if (pDest->IsString() || pDest->IsName()) { - CPDF_NameTree name_tree(pDocument, "Dests"); - return CPDF_Dest(name_tree.LookupNamedDest(pDocument, pDest->GetString())); - } - if (CPDF_Array* pArray = pDest->AsArray()) - return CPDF_Dest(pArray); - return CPDF_Dest(); -} -CPDF_Action CPDF_Bookmark::GetAction() const { - if (!m_pDict) { - return CPDF_Action(); - } - return CPDF_Action(m_pDict->GetDictBy("A")); -} diff --git a/core/fpdfdoc/doc_link.cpp b/core/fpdfdoc/doc_link.cpp deleted file mode 100644 index aa4e761f6d..0000000000 --- a/core/fpdfdoc/doc_link.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fpdfdoc/include/cpdf_link.h" - -#include - -#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" -#include "core/fpdfdoc/include/cpdf_linklist.h" -#include "core/fpdfdoc/include/cpdf_nametree.h" - -CPDF_LinkList::CPDF_LinkList() {} - -CPDF_LinkList::~CPDF_LinkList() {} - -const std::vector* CPDF_LinkList::GetPageLinks( - CPDF_Page* pPage) { - uint32_t objnum = pPage->m_pFormDict->GetObjNum(); - if (objnum == 0) - return nullptr; - - auto it = m_PageMap.find(objnum); - if (it != m_PageMap.end()) - return &it->second; - - // std::map::operator[] forces the creation of a map entry. - std::vector& page_link_list = m_PageMap[objnum]; - LoadPageLinks(pPage, &page_link_list); - return &page_link_list; -} - -CPDF_Link CPDF_LinkList::GetLinkAtPoint(CPDF_Page* pPage, - FX_FLOAT pdf_x, - FX_FLOAT pdf_y, - int* z_order) { - const std::vector* pPageLinkList = GetPageLinks(pPage); - if (!pPageLinkList) - return CPDF_Link(); - - for (size_t i = pPageLinkList->size(); i > 0; --i) { - size_t annot_index = i - 1; - CPDF_Dictionary* pAnnot = (*pPageLinkList)[annot_index]; - if (!pAnnot) - continue; - - CPDF_Link link(pAnnot); - CFX_FloatRect rect = link.GetRect(); - if (!rect.Contains(pdf_x, pdf_y)) - continue; - - if (z_order) - *z_order = annot_index; - return link; - } - return CPDF_Link(); -} - -void CPDF_LinkList::LoadPageLinks(CPDF_Page* pPage, - std::vector* pList) { - CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArrayBy("Annots"); - if (!pAnnotList) - return; - - for (size_t i = 0; i < pAnnotList->GetCount(); ++i) { - CPDF_Dictionary* pAnnot = pAnnotList->GetDictAt(i); - bool add_link = (pAnnot && pAnnot->GetStringBy("Subtype") == "Link"); - // Add non-links as nullptrs to preserve z-order. - pList->push_back(add_link ? pAnnot : nullptr); - } -} - -CFX_FloatRect CPDF_Link::GetRect() { - return m_pDict->GetRectBy("Rect"); -} -CPDF_Dest CPDF_Link::GetDest(CPDF_Document* pDoc) { - CPDF_Object* pDest = m_pDict->GetDirectObjectBy("Dest"); - if (!pDest) - return CPDF_Dest(); - - if (pDest->IsString() || pDest->IsName()) { - CPDF_NameTree name_tree(pDoc, "Dests"); - return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetString())); - } - if (CPDF_Array* pArray = pDest->AsArray()) - return CPDF_Dest(pArray); - return CPDF_Dest(); -} -CPDF_Action CPDF_Link::GetAction() { - return CPDF_Action(m_pDict->GetDictBy("A")); -} diff --git a/core/fpdfdoc/doc_metadata.cpp b/core/fpdfdoc/doc_metadata.cpp deleted file mode 100644 index 6273a62bef..0000000000 --- a/core/fpdfdoc/doc_metadata.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fpdfdoc/include/cpdf_metadata.h" - -#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" -#include "core/fxcrt/include/fx_xml.h" - -CPDF_Metadata::CPDF_Metadata(CPDF_Document* pDoc) { - CPDF_Dictionary* pRoot = pDoc->GetRoot(); - if (!pRoot) - return; - - CPDF_Stream* pStream = pRoot->GetStreamBy("Metadata"); - if (!pStream) - return; - - CPDF_StreamAcc acc; - acc.LoadAllData(pStream, FALSE); - m_pXmlElement.reset(CXML_Element::Parse(acc.GetData(), acc.GetSize())); -} - -CPDF_Metadata::~CPDF_Metadata() {} - -const CXML_Element* CPDF_Metadata::GetRoot() const { - return m_pXmlElement.get(); -} diff --git a/core/fpdfdoc/doc_viewerPreferences.cpp b/core/fpdfdoc/doc_viewerPreferences.cpp deleted file mode 100644 index 3fe638d4f5..0000000000 --- a/core/fpdfdoc/doc_viewerPreferences.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fpdfdoc/include/cpdf_viewerpreferences.h" - -#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" - -CPDF_ViewerPreferences::CPDF_ViewerPreferences(CPDF_Document* pDoc) - : m_pDoc(pDoc) {} - -CPDF_ViewerPreferences::~CPDF_ViewerPreferences() {} - -FX_BOOL CPDF_ViewerPreferences::IsDirectionR2L() const { - CPDF_Dictionary* pDict = GetViewerPreferences(); - return pDict ? pDict->GetStringBy("Direction") == "R2L" : FALSE; -} - -FX_BOOL CPDF_ViewerPreferences::PrintScaling() const { - CPDF_Dictionary* pDict = GetViewerPreferences(); - return pDict ? pDict->GetStringBy("PrintScaling") != "None" : TRUE; -} - -int32_t CPDF_ViewerPreferences::NumCopies() const { - CPDF_Dictionary* pDict = GetViewerPreferences(); - return pDict ? pDict->GetIntegerBy("NumCopies") : 1; -} - -CPDF_Array* CPDF_ViewerPreferences::PrintPageRange() const { - CPDF_Dictionary* pDict = GetViewerPreferences(); - return pDict ? pDict->GetArrayBy("PrintPageRange") : nullptr; -} - -CFX_ByteString CPDF_ViewerPreferences::Duplex() const { - CPDF_Dictionary* pDict = GetViewerPreferences(); - return pDict ? pDict->GetStringBy("Duplex") : CFX_ByteString("None"); -} - -CPDF_Dictionary* CPDF_ViewerPreferences::GetViewerPreferences() const { - CPDF_Dictionary* pDict = m_pDoc->GetRoot(); - return pDict ? pDict->GetDictBy("ViewerPreferences") : nullptr; -} diff --git a/core/fpdfdoc/include/cpdf_actionfields.h b/core/fpdfdoc/include/cpdf_actionfields.h index ad7962b761..0f38e1d469 100644 --- a/core/fpdfdoc/include/cpdf_actionfields.h +++ b/core/fpdfdoc/include/cpdf_actionfields.h @@ -7,6 +7,8 @@ #ifndef CORE_FPDFDOC_INCLUDE_CPDF_ACTIONFIELDS_H_ #define CORE_FPDFDOC_INCLUDE_CPDF_ACTIONFIELDS_H_ +#include + #include class CPDF_Action; diff --git a/pdfium.gyp b/pdfium.gyp index fe2d176318..d0d23b97d7 100644 --- a/pdfium.gyp +++ b/pdfium.gyp @@ -184,11 +184,21 @@ 'sources': [ 'core/fpdfdoc/clines.cpp', 'core/fpdfdoc/clines.h', + 'core/fpdfdoc/cpdf_aaction.cpp', + 'core/fpdfdoc/cpdf_action.cpp', + 'core/fpdfdoc/cpdf_actionfields.cpp', 'core/fpdfdoc/cpdf_apsettings.h', 'core/fpdfdoc/cpdf_annot.cpp', 'core/fpdfdoc/cpdf_annotlist.cpp', + 'core/fpdfdoc/cpdf_bookmark.cpp', + 'core/fpdfdoc/cpdf_bookmarktree.cpp', + 'core/fpdfdoc/cpdf_docjsactions.cpp', + 'core/fpdfdoc/cpdf_link.cpp', + 'core/fpdfdoc/cpdf_linklist.cpp', + 'core/fpdfdoc/cpdf_metadata.cpp', 'core/fpdfdoc/cpdf_pagelabel.h', 'core/fpdfdoc/cpdf_variabletext.cpp', + 'core/fpdfdoc/cpdf_viewerpreferences.cpp', 'core/fpdfdoc/cpvt_color.cpp', 'core/fpdfdoc/cpvt_color.h', 'core/fpdfdoc/cpvt_dash.h', @@ -206,18 +216,13 @@ 'core/fpdfdoc/csection.h', 'core/fpdfdoc/ctypeset.cpp', 'core/fpdfdoc/ctypeset.h', - 'core/fpdfdoc/doc_action.cpp', 'core/fpdfdoc/doc_basic.cpp', - 'core/fpdfdoc/doc_bookmark.cpp', 'core/fpdfdoc/doc_form.cpp', 'core/fpdfdoc/doc_formcontrol.cpp', 'core/fpdfdoc/doc_formfield.cpp', - 'core/fpdfdoc/doc_link.cpp', - 'core/fpdfdoc/doc_metadata.cpp', 'core/fpdfdoc/doc_ocg.cpp', 'core/fpdfdoc/doc_utils.cpp', 'core/fpdfdoc/doc_utils.h', - 'core/fpdfdoc/doc_viewerPreferences.cpp', 'core/fpdfdoc/doc_vt.cpp', 'core/fpdfdoc/include/cpdf_aaction.h', 'core/fpdfdoc/include/cpdf_action.h', -- cgit v1.2.3