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_colorstatedata.h" | 7 #include "core/fpdfapi/fpdf_page/cpdf_colorstatedata.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_page/cpdf_tilingpattern.h" | 9 CPDF_ColorStateData::CPDF_ColorStateData(const CPDF_ColorStateData& src) { |
10 #include "core/fxge/include/fx_dib.h" | |
11 | |
12 CPDF_ColorStateData::CPDF_ColorStateData(const CPDF_ColorStateData& src) | |
13 : m_FillRGB(src.m_FillRGB), m_StrokeRGB(src.m_StrokeRGB) { | |
14 m_FillColor.Copy(&src.m_FillColor); | 10 m_FillColor.Copy(&src.m_FillColor); |
| 11 m_FillRGB = src.m_FillRGB; |
15 m_StrokeColor.Copy(&src.m_StrokeColor); | 12 m_StrokeColor.Copy(&src.m_StrokeColor); |
| 13 m_StrokeRGB = src.m_StrokeRGB; |
16 } | 14 } |
17 | 15 |
18 void CPDF_ColorStateData::SetDefault() { | 16 void CPDF_ColorStateData::Default() { |
19 m_FillRGB = 0; | 17 m_FillRGB = m_StrokeRGB = 0; |
20 m_StrokeRGB = 0; | |
21 m_FillColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); | 18 m_FillColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); |
22 m_StrokeColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); | 19 m_StrokeColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); |
23 } | 20 } |
24 | |
25 void CPDF_ColorStateData::SetFillColor(CPDF_ColorSpace* pCS, | |
26 FX_FLOAT* pValue, | |
27 uint32_t nValues) { | |
28 SetColor(m_FillColor, m_FillRGB, pCS, pValue, nValues); | |
29 } | |
30 | |
31 void CPDF_ColorStateData::SetStrokeColor(CPDF_ColorSpace* pCS, | |
32 FX_FLOAT* pValue, | |
33 uint32_t nValues) { | |
34 SetColor(m_StrokeColor, m_StrokeRGB, pCS, pValue, nValues); | |
35 } | |
36 | |
37 void CPDF_ColorStateData::SetFillPattern(CPDF_Pattern* pPattern, | |
38 FX_FLOAT* pValue, | |
39 uint32_t nValues) { | |
40 m_FillColor.SetValue(pPattern, pValue, nValues); | |
41 int R, G, B; | |
42 FX_BOOL ret = m_FillColor.GetRGB(R, G, B); | |
43 if (CPDF_TilingPattern* pTilingPattern = pPattern->AsTilingPattern()) { | |
44 if (!ret && pTilingPattern->colored()) { | |
45 m_FillRGB = 0x00BFBFBF; | |
46 return; | |
47 } | |
48 } | |
49 m_FillRGB = ret ? FXSYS_RGB(R, G, B) : (uint32_t)-1; | |
50 } | |
51 | |
52 void CPDF_ColorStateData::SetStrokePattern(CPDF_Pattern* pPattern, | |
53 FX_FLOAT* pValue, | |
54 uint32_t nValues) { | |
55 m_StrokeColor.SetValue(pPattern, pValue, nValues); | |
56 int R, G, B; | |
57 FX_BOOL ret = m_StrokeColor.GetRGB(R, G, B); | |
58 if (CPDF_TilingPattern* pTilingPattern = pPattern->AsTilingPattern()) { | |
59 if (!ret && pTilingPattern->colored()) { | |
60 m_StrokeRGB = 0x00BFBFBF; | |
61 return; | |
62 } | |
63 } | |
64 m_StrokeRGB = | |
65 m_StrokeColor.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1; | |
66 } | |
67 | |
68 void CPDF_ColorStateData::SetColor(CPDF_Color& color, | |
69 uint32_t& rgb, | |
70 CPDF_ColorSpace* pCS, | |
71 FX_FLOAT* pValue, | |
72 uint32_t nValues) { | |
73 if (pCS) { | |
74 color.SetColorSpace(pCS); | |
75 } else if (color.IsNull()) { | |
76 color.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); | |
77 } | |
78 if (color.GetColorSpace()->CountComponents() > nValues) | |
79 return; | |
80 | |
81 color.SetValue(pValue); | |
82 int R, G, B; | |
83 rgb = color.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1; | |
84 } | |
OLD | NEW |