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