• 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_iconfit.h"
8 
9 #include "core/fpdfapi/parser/cpdf_array.h"
10 #include "core/fpdfapi/parser/cpdf_dictionary.h"
11 #include "core/fxcrt/fx_string.h"
12 
CPDF_IconFit(const CPDF_Dictionary * pDict)13 CPDF_IconFit::CPDF_IconFit(const CPDF_Dictionary* pDict) : m_pDict(pDict) {}
14 
15 CPDF_IconFit::CPDF_IconFit(const CPDF_IconFit& that) = default;
16 
~CPDF_IconFit()17 CPDF_IconFit::~CPDF_IconFit() {}
18 
GetScaleMethod()19 CPDF_IconFit::ScaleMethod CPDF_IconFit::GetScaleMethod() {
20   if (!m_pDict)
21     return Always;
22 
23   ByteString csSW = m_pDict->GetStringFor("SW", "A");
24   if (csSW == "B")
25     return Bigger;
26   if (csSW == "S")
27     return Smaller;
28   if (csSW == "N")
29     return Never;
30   return Always;
31 }
32 
IsProportionalScale()33 bool CPDF_IconFit::IsProportionalScale() {
34   return m_pDict ? m_pDict->GetStringFor("S", "P") != "A" : true;
35 }
36 
GetIconPosition(float & fLeft,float & fBottom)37 void CPDF_IconFit::GetIconPosition(float& fLeft, float& fBottom) {
38   fLeft = fBottom = 0.5;
39   if (!m_pDict)
40     return;
41 
42   CPDF_Array* pA = m_pDict->GetArrayFor("A");
43   if (pA) {
44     uint32_t dwCount = pA->GetCount();
45     if (dwCount > 0)
46       fLeft = pA->GetNumberAt(0);
47     if (dwCount > 1)
48       fBottom = pA->GetNumberAt(1);
49   }
50 }
51 
GetFittingBounds()52 bool CPDF_IconFit::GetFittingBounds() {
53   return m_pDict ? m_pDict->GetBooleanFor("FB") : false;
54 }
55