diff options
author | tsepez <tsepez@chromium.org> | 2016-08-29 12:52:56 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-29 12:52:56 -0700 |
commit | 91ddd3f7501429222f648b986a99f3959a398889 (patch) | |
tree | b6a712b9caf63f1e344a6475281226394e1e07c2 /core/fpdfapi/fpdf_page | |
parent | c37d7d452d6a37c997c8709576dd71406ecff618 (diff) | |
download | pdfium-91ddd3f7501429222f648b986a99f3959a398889.tar.xz |
Use ->() in CPDF_ColorState
Move methods to CPDF_ColorStateData.
Move MakePrivateCopy() methods to call sites.
Remove now-empty cpdf_colorstate.cpp file.
Review-Url: https://codereview.chromium.org/2291763002
Diffstat (limited to 'core/fpdfapi/fpdf_page')
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_colorstate.cpp | 80 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_colorstate.h | 32 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp | 74 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_colorstatedata.h | 38 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 87 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 2 |
7 files changed, 153 insertions, 162 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp deleted file mode 100644 index a46dea3bb8..0000000000 --- a/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fpdfapi/fpdf_page/cpdf_colorstate.h" - -#include "core/fpdfapi/fpdf_page/cpdf_pattern.h" -#include "core/fpdfapi/fpdf_page/cpdf_tilingpattern.h" -#include "core/fxge/include/fx_dib.h" - -void CPDF_ColorState::SetFillColor(CPDF_ColorSpace* pCS, - FX_FLOAT* pValue, - uint32_t nValues) { - MakePrivateCopy(); - CPDF_ColorStateData* pData = GetObject(); - SetColor(pData->m_FillColor, pData->m_FillRGB, pCS, pValue, nValues); -} - -void CPDF_ColorState::SetStrokeColor(CPDF_ColorSpace* pCS, - FX_FLOAT* pValue, - uint32_t nValues) { - MakePrivateCopy(); - CPDF_ColorStateData* pData = GetObject(); - SetColor(pData->m_StrokeColor, pData->m_StrokeRGB, pCS, pValue, nValues); -} - -void CPDF_ColorState::SetColor(CPDF_Color& color, - uint32_t& rgb, - CPDF_ColorSpace* pCS, - FX_FLOAT* pValue, - uint32_t nValues) { - if (pCS) { - color.SetColorSpace(pCS); - } else if (color.IsNull()) { - color.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); - } - if (color.GetColorSpace()->CountComponents() > nValues) - return; - - color.SetValue(pValue); - int R, G, B; - rgb = color.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1; -} - -void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern, - FX_FLOAT* pValue, - uint32_t nValues) { - MakePrivateCopy(); - CPDF_ColorStateData* pData = GetObject(); - pData->m_FillColor.SetValue(pPattern, pValue, nValues); - int R, G, B; - FX_BOOL ret = pData->m_FillColor.GetRGB(R, G, B); - if (CPDF_TilingPattern* pTilingPattern = pPattern->AsTilingPattern()) { - if (!ret && pTilingPattern->colored()) { - pData->m_FillRGB = 0x00BFBFBF; - return; - } - } - pData->m_FillRGB = ret ? FXSYS_RGB(R, G, B) : (uint32_t)-1; -} - -void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern, - FX_FLOAT* pValue, - uint32_t nValues) { - MakePrivateCopy(); - CPDF_ColorStateData* pData = GetObject(); - pData->m_StrokeColor.SetValue(pPattern, pValue, nValues); - int R, G, B; - FX_BOOL ret = pData->m_StrokeColor.GetRGB(R, G, B); - if (CPDF_TilingPattern* pTilingPattern = pPattern->AsTilingPattern()) { - if (!ret && pTilingPattern->colored()) { - pData->m_StrokeRGB = 0x00BFBFBF; - return; - } - } - pData->m_StrokeRGB = - pData->m_StrokeColor.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1; -} diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstate.h b/core/fpdfapi/fpdf_page/cpdf_colorstate.h index 128d67558d..b412947183 100644 --- a/core/fpdfapi/fpdf_page/cpdf_colorstate.h +++ b/core/fpdfapi/fpdf_page/cpdf_colorstate.h @@ -9,40 +9,8 @@ #include "core/fpdfapi/fpdf_page/cpdf_colorstatedata.h" #include "core/fxcrt/include/cfx_count_ref.h" -#include "core/fxcrt/include/fx_basic.h" -#include "core/fxcrt/include/fx_system.h" - -class CPDF_Color; -class CPDF_ColorSpace; -class CPDF_Pattern; class CPDF_ColorState : public CFX_CountRef<CPDF_ColorStateData> { - public: - const CPDF_Color* GetFillColor() const { - const CPDF_ColorStateData* pData = GetObject(); - return pData ? &pData->m_FillColor : nullptr; - } - - const CPDF_Color* GetStrokeColor() const { - const CPDF_ColorStateData* pData = GetObject(); - return pData ? &pData->m_StrokeColor : nullptr; - } - - void SetFillColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, uint32_t nValues); - void SetStrokeColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, uint32_t nValues); - void SetFillPattern(CPDF_Pattern* pattern, - FX_FLOAT* pValue, - uint32_t nValues); - void SetStrokePattern(CPDF_Pattern* pattern, - FX_FLOAT* pValue, - uint32_t nValues); - - private: - void SetColor(CPDF_Color& color, - uint32_t& rgb, - CPDF_ColorSpace* pCS, - FX_FLOAT* pValue, - uint32_t nValues); }; #endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATE_H_ diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp index 9dbcdec267..3a771ffaf0 100644 --- a/core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp @@ -6,15 +6,79 @@ #include "core/fpdfapi/fpdf_page/cpdf_colorstatedata.h" -CPDF_ColorStateData::CPDF_ColorStateData(const CPDF_ColorStateData& src) { +#include "core/fpdfapi/fpdf_page/cpdf_tilingpattern.h" +#include "core/fxge/include/fx_dib.h" + +CPDF_ColorStateData::CPDF_ColorStateData(const CPDF_ColorStateData& src) + : m_FillRGB(src.m_FillRGB), m_StrokeRGB(src.m_StrokeRGB) { m_FillColor.Copy(&src.m_FillColor); - m_FillRGB = src.m_FillRGB; m_StrokeColor.Copy(&src.m_StrokeColor); - m_StrokeRGB = src.m_StrokeRGB; } -void CPDF_ColorStateData::Default() { - m_FillRGB = m_StrokeRGB = 0; +void CPDF_ColorStateData::SetDefault() { + m_FillRGB = 0; + m_StrokeRGB = 0; m_FillColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); m_StrokeColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); } + +void CPDF_ColorStateData::SetFillColor(CPDF_ColorSpace* pCS, + FX_FLOAT* pValue, + uint32_t nValues) { + SetColor(m_FillColor, m_FillRGB, pCS, pValue, nValues); +} + +void CPDF_ColorStateData::SetStrokeColor(CPDF_ColorSpace* pCS, + FX_FLOAT* pValue, + uint32_t nValues) { + SetColor(m_StrokeColor, m_StrokeRGB, pCS, pValue, nValues); +} + +void CPDF_ColorStateData::SetFillPattern(CPDF_Pattern* pPattern, + FX_FLOAT* pValue, + uint32_t nValues) { + m_FillColor.SetValue(pPattern, pValue, nValues); + int R, G, B; + FX_BOOL ret = m_FillColor.GetRGB(R, G, B); + if (CPDF_TilingPattern* pTilingPattern = pPattern->AsTilingPattern()) { + if (!ret && pTilingPattern->colored()) { + m_FillRGB = 0x00BFBFBF; + return; + } + } + m_FillRGB = ret ? FXSYS_RGB(R, G, B) : (uint32_t)-1; +} + +void CPDF_ColorStateData::SetStrokePattern(CPDF_Pattern* pPattern, + FX_FLOAT* pValue, + uint32_t nValues) { + m_StrokeColor.SetValue(pPattern, pValue, nValues); + int R, G, B; + FX_BOOL ret = m_StrokeColor.GetRGB(R, G, B); + if (CPDF_TilingPattern* pTilingPattern = pPattern->AsTilingPattern()) { + if (!ret && pTilingPattern->colored()) { + m_StrokeRGB = 0x00BFBFBF; + return; + } + } + m_StrokeRGB = + m_StrokeColor.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1; +} + +void CPDF_ColorStateData::SetColor(CPDF_Color& color, + uint32_t& rgb, + CPDF_ColorSpace* pCS, + FX_FLOAT* pValue, + uint32_t nValues) { + if (pCS) { + color.SetColorSpace(pCS); + } else if (color.IsNull()) { + color.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); + } + if (color.GetColorSpace()->CountComponents() > nValues) + return; + + color.SetValue(pValue); + int R, G, B; + rgb = color.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1; +} diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstatedata.h b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.h index 6a992ad0b1..1b8413f3f1 100644 --- a/core/fpdfapi/fpdf_page/cpdf_colorstatedata.h +++ b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.h @@ -10,17 +10,49 @@ #include "core/fpdfapi/fpdf_page/include/cpdf_color.h" #include "core/fxcrt/include/fx_system.h" +class CPDF_Color; +class CPDF_ColorSpace; +class CPDF_Pattern; + class CPDF_ColorStateData { public: CPDF_ColorStateData() : m_FillRGB(0), m_StrokeRGB(0) {} CPDF_ColorStateData(const CPDF_ColorStateData& src); - void Default(); + void SetDefault(); + + uint32_t GetFillRGB() const { return m_FillRGB; } + void SetFillRGB(uint32_t rgb) { m_FillRGB = rgb; } + + uint32_t GetStrokeRGB() const { return m_StrokeRGB; } + void SetStrokeRGB(uint32_t rgb) { m_StrokeRGB = rgb; } + + CPDF_Color* GetFillColor() { return &m_FillColor; } + const CPDF_Color* GetFillColor() const { return &m_FillColor; } + void SetFillColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, uint32_t nValues); + + CPDF_Color* GetStrokeColor() { return &m_StrokeColor; } + const CPDF_Color* GetStrokeColor() const { return &m_StrokeColor; } + void SetStrokeColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, uint32_t nValues); + + void SetFillPattern(CPDF_Pattern* pattern, + FX_FLOAT* pValue, + uint32_t nValues); + void SetStrokePattern(CPDF_Pattern* pattern, + FX_FLOAT* pValue, + uint32_t nValues); + + private: + void SetColor(CPDF_Color& color, + uint32_t& rgb, + CPDF_ColorSpace* pCS, + FX_FLOAT* pValue, + uint32_t nValues); - CPDF_Color m_FillColor; uint32_t m_FillRGB; - CPDF_Color m_StrokeColor; uint32_t m_StrokeRGB; + CPDF_Color m_FillColor; + CPDF_Color m_StrokeColor; }; #endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATEDATA_H_ diff --git a/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp b/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp index fc054caf21..d1eabb6908 100644 --- a/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp @@ -11,7 +11,7 @@ CPDF_GraphicStates::CPDF_GraphicStates() {} CPDF_GraphicStates::~CPDF_GraphicStates() {} void CPDF_GraphicStates::DefaultStates() { - m_ColorState.New()->Default(); + m_ColorState.New()->SetDefault(); } void CPDF_GraphicStates::CopyStates(const CPDF_GraphicStates& src) { diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 5d5b75b60e..5dc8480423 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -6,6 +6,7 @@ #include "core/fpdfapi/fpdf_page/pageint.h" +#include <algorithm> #include <memory> #include <utility> #include <vector> @@ -692,7 +693,7 @@ void CPDF_StreamContentParser::Handle_SetColorSpace_Fill() { return; m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->m_FillColor.SetColorSpace(pCS); + m_pCurStates->m_ColorState->GetFillColor()->SetColorSpace(pCS); } void CPDF_StreamContentParser::Handle_SetColorSpace_Stroke() { @@ -701,7 +702,7 @@ void CPDF_StreamContentParser::Handle_SetColorSpace_Stroke() { return; m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->m_StrokeColor.SetColorSpace(pCS); + m_pCurStates->m_ColorState->GetStrokeColor()->SetColorSpace(pCS); } void CPDF_StreamContentParser::Handle_SetDash() { @@ -845,14 +846,16 @@ void CPDF_StreamContentParser::Handle_EOFillPath() { void CPDF_StreamContentParser::Handle_SetGray_Fill() { FX_FLOAT value = GetNumber(0); - CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY); - m_pCurStates->m_ColorState.SetFillColor(pCS, &value, 1); + m_pCurStates->m_ColorState.MakePrivateCopy(); + m_pCurStates->m_ColorState->SetFillColor( + CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY), &value, 1); } void CPDF_StreamContentParser::Handle_SetGray_Stroke() { FX_FLOAT value = GetNumber(0); - CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY); - m_pCurStates->m_ColorState.SetStrokeColor(pCS, &value, 1); + m_pCurStates->m_ColorState.MakePrivateCopy(); + m_pCurStates->m_ColorState->SetStrokeColor( + CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY), &value, 1); } void CPDF_StreamContentParser::Handle_SetExtendGraphState() { @@ -900,11 +903,12 @@ void CPDF_StreamContentParser::Handle_SetCMYKColor_Fill() { return; FX_FLOAT values[4]; - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) values[i] = GetNumber(3 - i); - } - CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK); - m_pCurStates->m_ColorState.SetFillColor(pCS, values, 4); + + m_pCurStates->m_ColorState.MakePrivateCopy(); + m_pCurStates->m_ColorState->SetFillColor( + CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK), values, 4); } void CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke() { @@ -912,11 +916,12 @@ void CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke() { return; FX_FLOAT values[4]; - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) values[i] = GetNumber(3 - i); - } - CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK); - m_pCurStates->m_ColorState.SetStrokeColor(pCS, values, 4); + + m_pCurStates->m_ColorState.MakePrivateCopy(); + m_pCurStates->m_ColorState->SetStrokeColor( + CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK), values, 4); } void CPDF_StreamContentParser::Handle_LineTo() { @@ -981,11 +986,12 @@ void CPDF_StreamContentParser::Handle_SetRGBColor_Fill() { return; FX_FLOAT values[3]; - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) values[i] = GetNumber(2 - i); - } - CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB); - m_pCurStates->m_ColorState.SetFillColor(pCS, values, 3); + + m_pCurStates->m_ColorState.MakePrivateCopy(); + m_pCurStates->m_ColorState->SetFillColor( + CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), values, 3); } void CPDF_StreamContentParser::Handle_SetRGBColor_Stroke() { @@ -993,11 +999,12 @@ void CPDF_StreamContentParser::Handle_SetRGBColor_Stroke() { return; FX_FLOAT values[3]; - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) values[i] = GetNumber(2 - i); - } - CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB); - m_pCurStates->m_ColorState.SetStrokeColor(pCS, values, 3); + + m_pCurStates->m_ColorState.MakePrivateCopy(); + m_pCurStates->m_ColorState->SetStrokeColor( + CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), values, 3); } void CPDF_StreamContentParser::Handle_SetRenderIntent() {} @@ -1013,26 +1020,22 @@ void CPDF_StreamContentParser::Handle_StrokePath() { void CPDF_StreamContentParser::Handle_SetColor_Fill() { FX_FLOAT values[4]; - int nargs = m_ParamCount; - if (nargs > 4) { - nargs = 4; - } - for (int i = 0; i < nargs; i++) { + uint32_t nargs = std::min(m_ParamCount, 4u); + for (uint32_t i = 0; i < nargs; i++) values[i] = GetNumber(nargs - i - 1); - } - m_pCurStates->m_ColorState.SetFillColor(nullptr, values, nargs); + + m_pCurStates->m_ColorState.MakePrivateCopy(); + m_pCurStates->m_ColorState->SetFillColor(nullptr, values, nargs); } void CPDF_StreamContentParser::Handle_SetColor_Stroke() { FX_FLOAT values[4]; - int nargs = m_ParamCount; - if (nargs > 4) { - nargs = 4; - } - for (int i = 0; i < nargs; i++) { + uint32_t nargs = std::min(m_ParamCount, 4u); + for (uint32_t i = 0; i < nargs; i++) values[i] = GetNumber(nargs - i - 1); - } - m_pCurStates->m_ColorState.SetStrokeColor(nullptr, values, nargs); + + m_pCurStates->m_ColorState.MakePrivateCopy(); + m_pCurStates->m_ColorState->SetStrokeColor(nullptr, values, nargs); } void CPDF_StreamContentParser::Handle_SetColorPS_Fill() { @@ -1054,10 +1057,12 @@ void CPDF_StreamContentParser::Handle_SetColorPS_Fill() { if (nvalues != nargs) { CPDF_Pattern* pPattern = FindPattern(GetString(0), false); if (pPattern) { - m_pCurStates->m_ColorState.SetFillPattern(pPattern, values, nvalues); + m_pCurStates->m_ColorState.MakePrivateCopy(); + m_pCurStates->m_ColorState->SetFillPattern(pPattern, values, nvalues); } } else { - m_pCurStates->m_ColorState.SetFillColor(nullptr, values, nvalues); + m_pCurStates->m_ColorState.MakePrivateCopy(); + m_pCurStates->m_ColorState->SetFillColor(nullptr, values, nvalues); } FX_Free(values); } @@ -1082,10 +1087,12 @@ void CPDF_StreamContentParser::Handle_SetColorPS_Stroke() { if (nvalues != nargs) { CPDF_Pattern* pPattern = FindPattern(GetString(0), false); if (pPattern) { - m_pCurStates->m_ColorState.SetStrokePattern(pPattern, values, nvalues); + m_pCurStates->m_ColorState.MakePrivateCopy(); + m_pCurStates->m_ColorState->SetStrokePattern(pPattern, values, nvalues); } } else { - m_pCurStates->m_ColorState.SetStrokeColor(nullptr, values, nvalues); + m_pCurStates->m_ColorState.MakePrivateCopy(); + m_pCurStates->m_ColorState->SetStrokeColor(nullptr, values, nvalues); } FX_Free(values); } diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index e19c9a4a61..756ae020aa 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -776,7 +776,7 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause) { nullptr, nullptr, m_pObjectHolder, m_pObjectHolder->m_pResources, &m_pObjectHolder->m_BBox, nullptr, 0)); m_pParser->GetCurStates()->m_ColorState.MakePrivateCopy(); - m_pParser->GetCurStates()->m_ColorState->Default(); + m_pParser->GetCurStates()->m_ColorState->SetDefault(); } if (m_CurrentOffset >= m_Size) { m_InternalStage = STAGE_CHECKCLIP; |