• 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 
13 namespace {
14 
15 constexpr float kDefaultPosition = 0.5f;
16 
17 }  // namespace
18 
CPDF_IconFit(const CPDF_Dictionary * pDict)19 CPDF_IconFit::CPDF_IconFit(const CPDF_Dictionary* pDict) : m_pDict(pDict) {}
20 
21 CPDF_IconFit::CPDF_IconFit(const CPDF_IconFit& that) = default;
22 
23 CPDF_IconFit::~CPDF_IconFit() = default;
24 
GetScaleMethod() const25 CPDF_IconFit::ScaleMethod CPDF_IconFit::GetScaleMethod() const {
26   if (!m_pDict)
27     return Always;
28 
29   ByteString csSW = m_pDict->GetStringFor("SW", "A");
30   if (csSW == "B")
31     return Bigger;
32   if (csSW == "S")
33     return Smaller;
34   if (csSW == "N")
35     return Never;
36   return Always;
37 }
38 
IsProportionalScale() const39 bool CPDF_IconFit::IsProportionalScale() const {
40   return !m_pDict || m_pDict->GetStringFor("S", "P") != "A";
41 }
42 
GetIconBottomLeftPosition() const43 CFX_PointF CPDF_IconFit::GetIconBottomLeftPosition() const {
44   float fLeft = kDefaultPosition;
45   float fBottom = kDefaultPosition;
46   if (!m_pDict)
47     return {fLeft, fBottom};
48 
49   const CPDF_Array* pA = m_pDict->GetArrayFor("A");
50   if (!pA)
51     return {fLeft, fBottom};
52 
53   size_t dwCount = pA->size();
54   if (dwCount > 0)
55     fLeft = pA->GetNumberAt(0);
56   if (dwCount > 1)
57     fBottom = pA->GetNumberAt(1);
58   return {fLeft, fBottom};
59 }
60 
GetFittingBounds() const61 bool CPDF_IconFit::GetFittingBounds() const {
62   return m_pDict && m_pDict->GetBooleanFor("FB", false);
63 }
64 
GetIconPosition() const65 CFX_PointF CPDF_IconFit::GetIconPosition() const {
66   if (!m_pDict)
67     return CFX_PointF();
68 
69   const CPDF_Array* pA = m_pDict->GetArrayFor("A");
70   if (!pA)
71     return CFX_PointF();
72 
73   size_t dwCount = pA->size();
74   return {dwCount > 0 ? pA->GetNumberAt(0) : 0.0f,
75           dwCount > 1 ? pA->GetNumberAt(1) : 0.0f};
76 }
77