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