Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: core/fpdfdoc/cpdf_apsettings.cpp

Issue 2190983002: Splitting fpdfdoc/doc_* part III. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@fpdf_doc_IV
Patch Set: Rebase to master Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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_apsettings.h"
8
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
11 #include "core/fpdfdoc/include/cpdf_formcontrol.h"
12
13 CPDF_ApSettings::CPDF_ApSettings(CPDF_Dictionary* pDict) : m_pDict(pDict) {}
14
15 bool CPDF_ApSettings::HasMKEntry(const CFX_ByteString& csEntry) const {
16 return m_pDict && m_pDict->KeyExist(csEntry);
17 }
18
19 int CPDF_ApSettings::GetRotation() const {
20 return m_pDict ? m_pDict->GetIntegerBy("R") : 0;
21 }
22
23 FX_ARGB CPDF_ApSettings::GetColor(int& iColorType,
24 const CFX_ByteString& csEntry) const {
25 iColorType = COLORTYPE_TRANSPARENT;
26 if (!m_pDict)
27 return 0;
28
29 CPDF_Array* pEntry = m_pDict->GetArrayBy(csEntry);
30 if (!pEntry)
31 return 0;
32
33 FX_ARGB color = 0;
34 size_t dwCount = pEntry->GetCount();
35 if (dwCount == 1) {
36 iColorType = COLORTYPE_GRAY;
37 FX_FLOAT g = pEntry->GetNumberAt(0) * 255;
38 return ArgbEncode(255, (int)g, (int)g, (int)g);
39 }
40 if (dwCount == 3) {
41 iColorType = COLORTYPE_RGB;
42 FX_FLOAT r = pEntry->GetNumberAt(0) * 255;
43 FX_FLOAT g = pEntry->GetNumberAt(1) * 255;
44 FX_FLOAT b = pEntry->GetNumberAt(2) * 255;
45 return ArgbEncode(255, (int)r, (int)g, (int)b);
46 }
47 if (dwCount == 4) {
48 iColorType = COLORTYPE_CMYK;
49 FX_FLOAT c = pEntry->GetNumberAt(0);
50 FX_FLOAT m = pEntry->GetNumberAt(1);
51 FX_FLOAT y = pEntry->GetNumberAt(2);
52 FX_FLOAT k = pEntry->GetNumberAt(3);
53 FX_FLOAT r = 1.0f - std::min(1.0f, c + k);
54 FX_FLOAT g = 1.0f - std::min(1.0f, m + k);
55 FX_FLOAT b = 1.0f - std::min(1.0f, y + k);
56 return ArgbEncode(255, (int)(r * 255), (int)(g * 255), (int)(b * 255));
57 }
58 return color;
59 }
60
61 FX_FLOAT CPDF_ApSettings::GetOriginalColor(
62 int index,
63 const CFX_ByteString& csEntry) const {
64 if (!m_pDict)
65 return 0;
66
67 CPDF_Array* pEntry = m_pDict->GetArrayBy(csEntry);
68 return pEntry ? pEntry->GetNumberAt(index) : 0;
69 }
70
71 void CPDF_ApSettings::GetOriginalColor(int& iColorType,
72 FX_FLOAT fc[4],
73 const CFX_ByteString& csEntry) const {
74 iColorType = COLORTYPE_TRANSPARENT;
75 for (int i = 0; i < 4; i++)
76 fc[i] = 0;
77
78 if (!m_pDict)
79 return;
80
81 CPDF_Array* pEntry = m_pDict->GetArrayBy(csEntry);
82 if (!pEntry)
83 return;
84
85 size_t dwCount = pEntry->GetCount();
86 if (dwCount == 1) {
87 iColorType = COLORTYPE_GRAY;
88 fc[0] = pEntry->GetNumberAt(0);
89 } else if (dwCount == 3) {
90 iColorType = COLORTYPE_RGB;
91 fc[0] = pEntry->GetNumberAt(0);
92 fc[1] = pEntry->GetNumberAt(1);
93 fc[2] = pEntry->GetNumberAt(2);
94 } else if (dwCount == 4) {
95 iColorType = COLORTYPE_CMYK;
96 fc[0] = pEntry->GetNumberAt(0);
97 fc[1] = pEntry->GetNumberAt(1);
98 fc[2] = pEntry->GetNumberAt(2);
99 fc[3] = pEntry->GetNumberAt(3);
100 }
101 }
102
103 CFX_WideString CPDF_ApSettings::GetCaption(
104 const CFX_ByteString& csEntry) const {
105 return m_pDict ? m_pDict->GetUnicodeTextBy(csEntry) : CFX_WideString();
106 }
107
108 CPDF_Stream* CPDF_ApSettings::GetIcon(const CFX_ByteString& csEntry) const {
109 return m_pDict ? m_pDict->GetStreamBy(csEntry) : nullptr;
110 }
111
112 CPDF_IconFit CPDF_ApSettings::GetIconFit() const {
113 return CPDF_IconFit(m_pDict ? m_pDict->GetDictBy("IF") : nullptr);
114 }
115
116 int CPDF_ApSettings::GetTextPosition() const {
117 return m_pDict ? m_pDict->GetIntegerBy("TP", TEXTPOS_CAPTION)
118 : TEXTPOS_CAPTION;
119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698