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_apsettings.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_apsettings.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/fpdfapi/parser/cpdf_stream.h"
15#include "core/fpdfdoc/cpdf_formcontrol.h"
16
18 : m_pDict(std::move(pDict)) {}
19
20CPDF_ApSettings::CPDF_ApSettings(const CPDF_ApSettings& that) = default;
21
23
24bool CPDF_ApSettings::HasMKEntry(const ByteString& csEntry) const {
25 return m_pDict && m_pDict->KeyExist(csEntry);
26}
27
29 return m_pDict ? m_pDict->GetIntegerFor("R") : 0;
30}
31
33 const ByteString& csEntry) const {
34 if (!m_pDict)
36
37 RetainPtr<const CPDF_Array> pEntry = m_pDict->GetArrayFor(csEntry);
38 if (!pEntry)
40
41 const size_t dwCount = pEntry->size();
42 if (dwCount == 1) {
43 const float g = pEntry->GetFloatAt(0) * 255;
44 return {CFX_Color::Type::kGray, ArgbEncode(255, (int)g, (int)g, (int)g)};
45 }
46 if (dwCount == 3) {
47 float r = pEntry->GetFloatAt(0) * 255;
48 float g = pEntry->GetFloatAt(1) * 255;
49 float b = pEntry->GetFloatAt(2) * 255;
50 return {CFX_Color::Type::kRGB, ArgbEncode(255, (int)r, (int)g, (int)b)};
51 }
52 if (dwCount == 4) {
53 float c = pEntry->GetFloatAt(0);
54 float m = pEntry->GetFloatAt(1);
55 float y = pEntry->GetFloatAt(2);
56 float k = pEntry->GetFloatAt(3);
57 float r = (1.0f - std::min(1.0f, c + k)) * 255;
58 float g = (1.0f - std::min(1.0f, m + k)) * 255;
59 float b = (1.0f - std::min(1.0f, y + k)) * 255;
60 return {CFX_Color::Type::kCMYK, ArgbEncode(255, (int)r, (int)g, (int)b)};
61 }
63}
64
66 int index,
67 const ByteString& csEntry) const {
68 if (!m_pDict)
69 return 0;
70
71 RetainPtr<const CPDF_Array> pEntry = m_pDict->GetArrayFor(csEntry);
72 return pEntry ? pEntry->GetFloatAt(index) : 0;
73}
74
75CFX_Color CPDF_ApSettings::GetOriginalColor(const ByteString& csEntry) const {
76 if (!m_pDict)
77 return CFX_Color();
78
79 RetainPtr<const CPDF_Array> pEntry = m_pDict->GetArrayFor(csEntry);
80 if (!pEntry)
81 return CFX_Color();
82
83 size_t dwCount = pEntry->size();
84 if (dwCount == 1) {
85 return CFX_Color(CFX_Color::Type::kGray, pEntry->GetFloatAt(0));
86 }
87 if (dwCount == 3) {
88 return CFX_Color(CFX_Color::Type::kRGB, pEntry->GetFloatAt(0),
89 pEntry->GetFloatAt(1), pEntry->GetFloatAt(2));
90 }
91 if (dwCount == 4) {
92 return CFX_Color(CFX_Color::Type::kCMYK, pEntry->GetFloatAt(0),
93 pEntry->GetFloatAt(1), pEntry->GetFloatAt(2),
94 pEntry->GetFloatAt(3));
95 }
96 return CFX_Color();
97}
98
99WideString CPDF_ApSettings::GetCaption(const ByteString& csEntry) const {
100 return m_pDict ? m_pDict->GetUnicodeTextFor(csEntry) : WideString();
101}
102
104 const ByteString& csEntry) const {
105 return m_pDict ? m_pDict->GetMutableStreamFor(csEntry) : nullptr;
106}
107
109 return CPDF_IconFit(m_pDict ? m_pDict->GetDictFor("IF") : nullptr);
110}
111
113 return m_pDict ? m_pDict->GetIntegerFor("TP", TEXTPOS_CAPTION)
115}
CFX_Color GetOriginalColor(const ByteString &csEntry) const
bool HasMKEntry(const ByteString &csEntry) const
int GetRotation() const
RetainPtr< CPDF_Stream > GetIcon(const ByteString &csEntry) const
CPDF_ApSettings(const CPDF_ApSettings &that)
CPDF_IconFit GetIconFit() const
WideString GetCaption(const ByteString &csEntry) const
float GetOriginalColorComponent(int index, const ByteString &csEntry) const
CFX_Color::TypeAndARGB GetColorARGB(const ByteString &csEntry) const
CPDF_ApSettings(RetainPtr< CPDF_Dictionary > pDict)
int GetTextPosition() const
#define TEXTPOS_CAPTION
constexpr FX_ARGB ArgbEncode(uint32_t a, uint32_t r, uint32_t g, uint32_t b)
Definition fx_dib.h:118
TypeAndARGB(CFX_Color::Type type_in, FX_ARGB argb_in)
Definition cfx_color.h:17
constexpr CFX_Color(Type type=CFX_Color::Type::kTransparent, float color1=0.0f, float color2=0.0f, float color3=0.0f, float color4=0.0f)
Definition cfx_color.h:27