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_colorstate.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/fpdfapi/page/cpdf_colorstate.h"
8
9#include <utility>
10
11#include "core/fpdfapi/page/cpdf_colorspace.h"
12#include "core/fpdfapi/page/cpdf_pattern.h"
13#include "core/fpdfapi/page/cpdf_tilingpattern.h"
14#include "core/fxge/dib/fx_dib.h"
15#include "third_party/base/check.h"
16
18
19CPDF_ColorState::CPDF_ColorState(const CPDF_ColorState& that) = default;
20
22
24 m_Ref.Emplace();
25}
26
28 m_Ref.GetPrivateCopy()->SetDefault();
29}
30
31FX_COLORREF CPDF_ColorState::GetFillColorRef() const {
32 return m_Ref.GetObject()->m_FillColorRef;
33}
34
35void CPDF_ColorState::SetFillColorRef(FX_COLORREF colorref) {
36 if (!m_Ref || GetFillColorRef() != colorref) {
37 m_Ref.GetPrivateCopy()->m_FillColorRef = colorref;
38 }
39}
40
41FX_COLORREF CPDF_ColorState::GetStrokeColorRef() const {
42 return m_Ref.GetObject()->m_StrokeColorRef;
43}
44
45void CPDF_ColorState::SetStrokeColorRef(FX_COLORREF colorref) {
46 if (!m_Ref || GetStrokeColorRef() != colorref) {
47 m_Ref.GetPrivateCopy()->m_StrokeColorRef = colorref;
48 }
49}
50
52 const ColorData* pData = m_Ref.GetObject();
53 return pData ? &pData->m_FillColor : nullptr;
54}
55
57 return &m_Ref.GetPrivateCopy()->m_FillColor;
58}
59
61 const CPDF_Color* pColor = GetFillColor();
62 return pColor && !pColor->IsNull();
63}
64
66 const ColorData* pData = m_Ref.GetObject();
67 return pData ? &pData->m_StrokeColor : nullptr;
68}
69
71 return &m_Ref.GetPrivateCopy()->m_StrokeColor;
72}
73
75 const CPDF_Color* pColor = GetStrokeColor();
76 return pColor && !pColor->IsNull();
77}
78
80 std::vector<float> values) {
81 ColorData* pData = m_Ref.GetPrivateCopy();
82 SetColor(std::move(colorspace), std::move(values), &pData->m_FillColor,
83 &pData->m_FillColorRef);
84}
85
87 std::vector<float> values) {
88 ColorData* pData = m_Ref.GetPrivateCopy();
89 SetColor(std::move(colorspace), std::move(values), &pData->m_StrokeColor,
90 &pData->m_StrokeColorRef);
91}
92
94 pdfium::span<float> values) {
95 ColorData* pData = m_Ref.GetPrivateCopy();
96 SetPattern(std::move(pattern), values, &pData->m_FillColor,
97 &pData->m_FillColorRef);
98}
99
101 pdfium::span<float> values) {
102 ColorData* pData = m_Ref.GetPrivateCopy();
103 SetPattern(std::move(pattern), values, &pData->m_StrokeColor,
104 &pData->m_StrokeColorRef);
105}
106
107void CPDF_ColorState::SetColor(RetainPtr<CPDF_ColorSpace> colorspace,
108 std::vector<float> values,
109 CPDF_Color* color,
110 FX_COLORREF* colorref) {
111 DCHECK(color);
112 DCHECK(colorref);
113
114 if (colorspace) {
115 color->SetColorSpace(std::move(colorspace));
116 } else if (color->IsNull()) {
119 }
120 if (color->CountComponents() > values.size())
121 return;
122
123 if (!color->IsPattern())
124 color->SetValueForNonPattern(std::move(values));
125 int R;
126 int G;
127 int B;
128 *colorref = color->GetRGB(&R, &G, &B) ? FXSYS_BGR(B, G, R) : 0xFFFFFFFF;
129}
130
131void CPDF_ColorState::SetPattern(RetainPtr<CPDF_Pattern> pattern,
132 pdfium::span<float> values,
133 CPDF_Color* color,
134 FX_COLORREF* colorref) {
135 DCHECK(color);
136 DCHECK(colorref);
137 color->SetValueForPattern(pattern, values);
138 int R;
139 int G;
140 int B;
141 if (color->GetRGB(&R, &G, &B)) {
142 *colorref = FXSYS_BGR(B, G, R);
143 return;
144 }
145 CPDF_TilingPattern* tiling = pattern->AsTilingPattern();
146 *colorref = tiling && tiling->colored() ? 0x00BFBFBF : 0xFFFFFFFF;
147}
148
149CPDF_ColorState::ColorData::ColorData() = default;
150
151CPDF_ColorState::ColorData::ColorData(const ColorData& src)
152 : m_FillColorRef(src.m_FillColorRef),
153 m_StrokeColorRef(src.m_StrokeColorRef),
154 m_FillColor(src.m_FillColor),
155 m_StrokeColor(src.m_StrokeColor) {}
156
157CPDF_ColorState::ColorData::~ColorData() = default;
158
159void CPDF_ColorState::ColorData::SetDefault() {
160 m_FillColorRef = 0;
161 m_StrokeColorRef = 0;
162 m_FillColor.SetColorSpace(
163 CPDF_ColorSpace::GetStockCS(CPDF_ColorSpace::Family::kDeviceGray));
164 m_StrokeColor.SetColorSpace(
165 CPDF_ColorSpace::GetStockCS(CPDF_ColorSpace::Family::kDeviceGray));
166}
167
168RetainPtr<CPDF_ColorState::ColorData> CPDF_ColorState::ColorData::Clone()
169 const {
170 return pdfium::MakeRetain<CPDF_ColorState::ColorData>(*this);
171}
static RetainPtr< CPDF_ColorSpace > GetStockCS(Family family)
CPDF_Color * GetMutableFillColor()
FX_COLORREF GetStrokeColorRef() const
FX_COLORREF GetFillColorRef() const
void SetFillColor(RetainPtr< CPDF_ColorSpace > colorspace, std::vector< float > values)
void SetStrokeColor(RetainPtr< CPDF_ColorSpace > colorspace, std::vector< float > values)
CPDF_ColorState(const CPDF_ColorState &that)
CPDF_Color * GetMutableStrokeColor()
void SetStrokeColorRef(FX_COLORREF colorref)
void SetFillPattern(RetainPtr< CPDF_Pattern > pattern, pdfium::span< float > values)
const CPDF_Color * GetStrokeColor() const
void SetStrokePattern(RetainPtr< CPDF_Pattern > pattern, pdfium::span< float > values)
const CPDF_Color * GetFillColor() const
bool HasFillColor() const
bool HasStrokeColor() const
void SetFillColorRef(FX_COLORREF colorref)
void SetValueForPattern(RetainPtr< CPDF_Pattern > pattern, pdfium::span< float > values)
bool IsPattern() const
void SetColorSpace(RetainPtr< CPDF_ColorSpace > colorspace)
bool GetRGB(int *R, int *G, int *B) const
bool IsNull() const
Definition cpdf_color.h:31
uint32_t CountComponents() const
constexpr uint32_t FXSYS_BGR(uint8_t b, uint8_t g, uint8_t r)
Definition fx_dib.h:69