Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_iconfit.cpp
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
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 <algorithm>
10#include <utility>
11
12#include "core/fpdfapi/parser/cpdf_array.h"
13#include "core/fpdfapi/parser/cpdf_dictionary.h"
14#include "core/fxcrt/fx_string.h"
15
16namespace {
17
18constexpr float kDefaultPosition = 0.5f;
19
20} // namespace
21
22CPDF_IconFit::CPDF_IconFit(RetainPtr<const CPDF_Dictionary> pDict)
23 : m_pDict(std::move(pDict)) {}
24
25CPDF_IconFit::CPDF_IconFit(const CPDF_IconFit& that) = default;
26
27CPDF_IconFit::~CPDF_IconFit() = default;
28
30 if (!m_pDict)
32
33 ByteString csSW = m_pDict->GetByteStringFor("SW", "A");
34 if (csSW == "B")
36 if (csSW == "S")
38 if (csSW == "N")
41}
42
44 return !m_pDict || m_pDict->GetByteStringFor("S", "P") != "A";
45}
46
48 float fLeft = kDefaultPosition;
49 float fBottom = kDefaultPosition;
50 if (!m_pDict)
51 return {fLeft, fBottom};
52
53 RetainPtr<const CPDF_Array> pA = m_pDict->GetArrayFor("A");
54 if (!pA)
55 return {fLeft, fBottom};
56
57 size_t dwCount = pA->size();
58 if (dwCount > 0)
59 fLeft = pA->GetFloatAt(0);
60 if (dwCount > 1)
61 fBottom = pA->GetFloatAt(1);
62 return {fLeft, fBottom};
63}
64
66 return m_pDict && m_pDict->GetBooleanFor("FB", false);
67}
68
69CFX_PointF CPDF_IconFit::GetIconPosition() const {
70 if (!m_pDict)
71 return CFX_PointF();
72
73 RetainPtr<const CPDF_Array> pA = m_pDict->GetArrayFor("A");
74 if (!pA)
75 return CFX_PointF();
76
77 size_t dwCount = pA->size();
78 return {dwCount > 0 ? pA->GetFloatAt(0) : 0.0f,
79 dwCount > 1 ? pA->GetFloatAt(1) : 0.0f};
80}
81
82CFX_VectorF CPDF_IconFit::GetScale(const CFX_SizeF& image_size,
83 const CFX_FloatRect& rcPlate) const {
84 float fHScale = 1.0f;
85 float fVScale = 1.0f;
86 const float fPlateWidth = rcPlate.Width();
87 const float fPlateHeight = rcPlate.Height();
88 const float fImageWidth = image_size.width;
89 const float fImageHeight = image_size.height;
90 switch (GetScaleMethod()) {
92 fHScale = fPlateWidth / std::max(fImageWidth, 1.0f);
93 fVScale = fPlateHeight / std::max(fImageHeight, 1.0f);
94 break;
96 if (fPlateWidth < fImageWidth)
97 fHScale = fPlateWidth / std::max(fImageWidth, 1.0f);
98 if (fPlateHeight < fImageHeight)
99 fVScale = fPlateHeight / std::max(fImageHeight, 1.0f);
100 break;
102 if (fPlateWidth > fImageWidth)
103 fHScale = fPlateWidth / std::max(fImageWidth, 1.0f);
104 if (fPlateHeight > fImageHeight)
105 fVScale = fPlateHeight / std::max(fImageHeight, 1.0f);
106 break;
108 break;
109 }
110
112 float min_scale = std::min(fHScale, fVScale);
113 fHScale = min_scale;
114 fVScale = min_scale;
115 }
116 return {fHScale, fVScale};
117}
118
119CFX_VectorF CPDF_IconFit::GetImageOffset(const CFX_SizeF& image_size,
120 const CFX_VectorF& scale,
121 const CFX_FloatRect& rcPlate) const {
122 const CFX_PointF icon_position = GetIconPosition();
123 const float fImageFactWidth = image_size.width * scale.x;
124 const float fImageFactHeight = image_size.height * scale.y;
125 return {(rcPlate.Width() - fImageFactWidth) * icon_position.x,
126 (rcPlate.Height() - fImageFactHeight) * icon_position.y};
127}
float Width() const
float Height() const
ScaleMethod GetScaleMethod() const
bool GetFittingBounds() const
CFX_VectorF GetImageOffset(const CFX_SizeF &image_size, const CFX_VectorF &scale, const CFX_FloatRect &rcPlate) const
CFX_PointF GetIconBottomLeftPosition() const
bool IsProportionalScale() const
CFX_VectorF GetScale(const CFX_SizeF &image_size, const CFX_FloatRect &rcPlate) const
CPDF_IconFit(RetainPtr< const CPDF_Dictionary > pDict)
CPDF_IconFit(const CPDF_IconFit &that)
bool operator==(const char *ptr) const