• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "core/fpdfdoc/cpdf_viewerpreferences.h"
8 
9 #include "core/fpdfapi/parser/cpdf_document.h"
10 #include "core/fpdfapi/parser/cpdf_name.h"
11 
CPDF_ViewerPreferences(CPDF_Document * pDoc)12 CPDF_ViewerPreferences::CPDF_ViewerPreferences(CPDF_Document* pDoc)
13     : m_pDoc(pDoc) {}
14 
~CPDF_ViewerPreferences()15 CPDF_ViewerPreferences::~CPDF_ViewerPreferences() {}
16 
IsDirectionR2L() const17 bool CPDF_ViewerPreferences::IsDirectionR2L() const {
18   CPDF_Dictionary* pDict = GetViewerPreferences();
19   return pDict ? pDict->GetStringFor("Direction") == "R2L" : false;
20 }
21 
PrintScaling() const22 bool CPDF_ViewerPreferences::PrintScaling() const {
23   CPDF_Dictionary* pDict = GetViewerPreferences();
24   return pDict ? pDict->GetStringFor("PrintScaling") != "None" : true;
25 }
26 
NumCopies() const27 int32_t CPDF_ViewerPreferences::NumCopies() const {
28   CPDF_Dictionary* pDict = GetViewerPreferences();
29   return pDict ? pDict->GetIntegerFor("NumCopies") : 1;
30 }
31 
PrintPageRange() const32 CPDF_Array* CPDF_ViewerPreferences::PrintPageRange() const {
33   CPDF_Dictionary* pDict = GetViewerPreferences();
34   return pDict ? pDict->GetArrayFor("PrintPageRange") : nullptr;
35 }
36 
Duplex() const37 ByteString CPDF_ViewerPreferences::Duplex() const {
38   CPDF_Dictionary* pDict = GetViewerPreferences();
39   return pDict ? pDict->GetStringFor("Duplex") : ByteString("None");
40 }
41 
GenericName(const ByteString & bsKey,ByteString * bsVal) const42 bool CPDF_ViewerPreferences::GenericName(const ByteString& bsKey,
43                                          ByteString* bsVal) const {
44   ASSERT(bsVal);
45   CPDF_Dictionary* pDict = GetViewerPreferences();
46   if (!pDict)
47     return false;
48 
49   const CPDF_Name* pName = ToName(pDict->GetObjectFor(bsKey));
50   if (!pName)
51     return false;
52 
53   *bsVal = pName->GetString();
54   return true;
55 }
56 
GetViewerPreferences() const57 CPDF_Dictionary* CPDF_ViewerPreferences::GetViewerPreferences() const {
58   const CPDF_Dictionary* pDict = m_pDoc->GetRoot();
59   return pDict ? pDict->GetDictFor("ViewerPreferences") : nullptr;
60 }
61