OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fpdfapi/fpdf_page/cpdf_colorstate.h" | 7 #include "core/fpdfapi/fpdf_page/cpdf_colorstate.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_page/cpdf_pattern.h" | 9 #include "core/fpdfapi/fpdf_page/cpdf_pattern.h" |
10 #include "core/fpdfapi/fpdf_page/cpdf_tilingpattern.h" | 10 #include "core/fpdfapi/fpdf_page/cpdf_tilingpattern.h" |
11 #include "core/fxge/include/fx_dib.h" | 11 #include "core/fxge/include/fx_dib.h" |
12 | 12 |
| 13 CPDF_ColorState::CPDF_ColorState() {} |
| 14 |
| 15 CPDF_ColorState::CPDF_ColorState(const CPDF_ColorState& that) |
| 16 : m_Ref(that.m_Ref) {} |
| 17 |
| 18 CPDF_ColorState::~CPDF_ColorState() {} |
| 19 |
| 20 void CPDF_ColorState::Emplace() { |
| 21 m_Ref.Emplace(); |
| 22 } |
| 23 |
| 24 void CPDF_ColorState::SetDefault() { |
| 25 m_Ref.GetPrivateCopy()->Default(); |
| 26 } |
| 27 |
| 28 uint32_t CPDF_ColorState::GetFillRGB() const { |
| 29 return m_Ref.GetObject()->m_FillRGB; |
| 30 } |
| 31 |
| 32 void CPDF_ColorState::SetFillRGB(uint32_t rgb) { |
| 33 m_Ref.GetPrivateCopy()->m_FillRGB = rgb; |
| 34 } |
| 35 |
| 36 uint32_t CPDF_ColorState::GetStrokeRGB() const { |
| 37 return m_Ref.GetObject()->m_StrokeRGB; |
| 38 } |
| 39 |
| 40 void CPDF_ColorState::SetStrokeRGB(uint32_t rgb) { |
| 41 m_Ref.GetPrivateCopy()->m_StrokeRGB = rgb; |
| 42 } |
| 43 |
| 44 const CPDF_Color* CPDF_ColorState::GetFillColor() const { |
| 45 const CPDF_ColorStateData* pData = m_Ref.GetObject(); |
| 46 return pData ? &pData->m_FillColor : nullptr; |
| 47 } |
| 48 |
| 49 CPDF_Color* CPDF_ColorState::GetMutableFillColor() { |
| 50 return &m_Ref.GetPrivateCopy()->m_FillColor; |
| 51 } |
| 52 |
| 53 bool CPDF_ColorState::HasFillColor() const { |
| 54 const CPDF_Color* pColor = GetFillColor(); |
| 55 return pColor && !pColor->IsNull(); |
| 56 } |
| 57 |
| 58 const CPDF_Color* CPDF_ColorState::GetStrokeColor() const { |
| 59 const CPDF_ColorStateData* pData = m_Ref.GetObject(); |
| 60 return pData ? &pData->m_StrokeColor : nullptr; |
| 61 } |
| 62 |
| 63 CPDF_Color* CPDF_ColorState::GetMutableStrokeColor() { |
| 64 return &m_Ref.GetPrivateCopy()->m_StrokeColor; |
| 65 } |
| 66 |
| 67 bool CPDF_ColorState::HasStrokeColor() const { |
| 68 const CPDF_Color* pColor = GetStrokeColor(); |
| 69 return pColor && !pColor->IsNull(); |
| 70 } |
| 71 |
13 void CPDF_ColorState::SetFillColor(CPDF_ColorSpace* pCS, | 72 void CPDF_ColorState::SetFillColor(CPDF_ColorSpace* pCS, |
14 FX_FLOAT* pValue, | 73 FX_FLOAT* pValue, |
15 uint32_t nValues) { | 74 uint32_t nValues) { |
16 CPDF_ColorStateData* pData = GetPrivateCopy(); | 75 CPDF_ColorStateData* pData = m_Ref.GetPrivateCopy(); |
17 SetColor(pData->m_FillColor, pData->m_FillRGB, pCS, pValue, nValues); | 76 SetColor(pData->m_FillColor, pData->m_FillRGB, pCS, pValue, nValues); |
18 } | 77 } |
19 | 78 |
20 void CPDF_ColorState::SetStrokeColor(CPDF_ColorSpace* pCS, | 79 void CPDF_ColorState::SetStrokeColor(CPDF_ColorSpace* pCS, |
21 FX_FLOAT* pValue, | 80 FX_FLOAT* pValue, |
22 uint32_t nValues) { | 81 uint32_t nValues) { |
23 CPDF_ColorStateData* pData = GetPrivateCopy(); | 82 CPDF_ColorStateData* pData = m_Ref.GetPrivateCopy(); |
24 SetColor(pData->m_StrokeColor, pData->m_StrokeRGB, pCS, pValue, nValues); | 83 SetColor(pData->m_StrokeColor, pData->m_StrokeRGB, pCS, pValue, nValues); |
25 } | 84 } |
26 | 85 |
27 void CPDF_ColorState::SetColor(CPDF_Color& color, | |
28 uint32_t& rgb, | |
29 CPDF_ColorSpace* pCS, | |
30 FX_FLOAT* pValue, | |
31 uint32_t nValues) { | |
32 if (pCS) { | |
33 color.SetColorSpace(pCS); | |
34 } else if (color.IsNull()) { | |
35 color.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); | |
36 } | |
37 if (color.GetColorSpace()->CountComponents() > nValues) | |
38 return; | |
39 | |
40 color.SetValue(pValue); | |
41 int R, G, B; | |
42 rgb = color.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1; | |
43 } | |
44 | |
45 void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern, | 86 void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern, |
46 FX_FLOAT* pValue, | 87 FX_FLOAT* pValue, |
47 uint32_t nValues) { | 88 uint32_t nValues) { |
48 CPDF_ColorStateData* pData = GetPrivateCopy(); | 89 CPDF_ColorStateData* pData = m_Ref.GetPrivateCopy(); |
49 pData->m_FillColor.SetValue(pPattern, pValue, nValues); | 90 pData->m_FillColor.SetValue(pPattern, pValue, nValues); |
50 int R, G, B; | 91 int R, G, B; |
51 FX_BOOL ret = pData->m_FillColor.GetRGB(R, G, B); | 92 FX_BOOL ret = pData->m_FillColor.GetRGB(R, G, B); |
52 if (CPDF_TilingPattern* pTilingPattern = pPattern->AsTilingPattern()) { | 93 if (CPDF_TilingPattern* pTilingPattern = pPattern->AsTilingPattern()) { |
53 if (!ret && pTilingPattern->colored()) { | 94 if (!ret && pTilingPattern->colored()) { |
54 pData->m_FillRGB = 0x00BFBFBF; | 95 pData->m_FillRGB = 0x00BFBFBF; |
55 return; | 96 return; |
56 } | 97 } |
57 } | 98 } |
58 pData->m_FillRGB = ret ? FXSYS_RGB(R, G, B) : (uint32_t)-1; | 99 pData->m_FillRGB = ret ? FXSYS_RGB(R, G, B) : (uint32_t)-1; |
59 } | 100 } |
60 | 101 |
61 void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern, | 102 void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern, |
62 FX_FLOAT* pValue, | 103 FX_FLOAT* pValue, |
63 uint32_t nValues) { | 104 uint32_t nValues) { |
64 CPDF_ColorStateData* pData = GetPrivateCopy(); | 105 CPDF_ColorStateData* pData = m_Ref.GetPrivateCopy(); |
65 pData->m_StrokeColor.SetValue(pPattern, pValue, nValues); | 106 pData->m_StrokeColor.SetValue(pPattern, pValue, nValues); |
66 int R, G, B; | 107 int R, G, B; |
67 FX_BOOL ret = pData->m_StrokeColor.GetRGB(R, G, B); | 108 FX_BOOL ret = pData->m_StrokeColor.GetRGB(R, G, B); |
68 if (CPDF_TilingPattern* pTilingPattern = pPattern->AsTilingPattern()) { | 109 if (CPDF_TilingPattern* pTilingPattern = pPattern->AsTilingPattern()) { |
69 if (!ret && pTilingPattern->colored()) { | 110 if (!ret && pTilingPattern->colored()) { |
70 pData->m_StrokeRGB = 0x00BFBFBF; | 111 pData->m_StrokeRGB = 0x00BFBFBF; |
71 return; | 112 return; |
72 } | 113 } |
73 } | 114 } |
74 pData->m_StrokeRGB = | 115 pData->m_StrokeRGB = |
75 pData->m_StrokeColor.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1; | 116 pData->m_StrokeColor.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1; |
76 } | 117 } |
| 118 |
| 119 void CPDF_ColorState::SetColor(CPDF_Color& color, |
| 120 uint32_t& rgb, |
| 121 CPDF_ColorSpace* pCS, |
| 122 FX_FLOAT* pValue, |
| 123 uint32_t nValues) { |
| 124 if (pCS) |
| 125 color.SetColorSpace(pCS); |
| 126 else if (color.IsNull()) |
| 127 color.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); |
| 128 |
| 129 if (color.GetColorSpace()->CountComponents() > nValues) |
| 130 return; |
| 131 |
| 132 color.SetValue(pValue); |
| 133 int R; |
| 134 int G; |
| 135 int B; |
| 136 rgb = color.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1; |
| 137 } |
OLD | NEW |