diff options
author | tsepez <tsepez@chromium.org> | 2016-08-29 14:07:28 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-29 14:07:28 -0700 |
commit | adbd32950006075fc04ff2cbb01bf3a099f0e010 (patch) | |
tree | 62ad8839a0190a8cf5e2b0823276e4ba2dbd99a2 /core/fpdfapi/fpdf_page | |
parent | dda2c0dc502b50d4de66b80305441bfb612ec6c1 (diff) | |
download | pdfium-adbd32950006075fc04ff2cbb01bf3a099f0e010.tar.xz |
Revert "Use ->() in CPDF_ColorState"
This reverts commit 91ddd3f7501429222f648b986a99f3959a398889.
Reason for revert: may introduce sublte bugs, more thought required.
TBR=dsinclair@chromium.org
Review-Url: https://codereview.chromium.org/2294553002
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, 162 insertions, 153 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp new file mode 100644 index 0000000000..a46dea3bb8 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp @@ -0,0 +1,80 @@ +// 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 b412947183..128d67558d 100644 --- a/core/fpdfapi/fpdf_page/cpdf_colorstate.h +++ b/core/fpdfapi/fpdf_page/cpdf_colorstate.h @@ -9,8 +9,40 @@ #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 3a771ffaf0..9dbcdec267 100644 --- a/core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp @@ -6,79 +6,15 @@ #include "core/fpdfapi/fpdf_page/cpdf_colorstatedata.h" -#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) { +CPDF_ColorStateData::CPDF_ColorStateData(const CPDF_ColorStateData& src) { 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::SetDefault() { - m_FillRGB = 0; - m_StrokeRGB = 0; +void CPDF_ColorStateData::Default() { + m_FillRGB = 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 1b8413f3f1..6a992ad0b1 100644 --- a/core/fpdfapi/fpdf_page/cpdf_colorstatedata.h +++ b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.h @@ -10,49 +10,17 @@ #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 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); + void Default(); - private: - void SetColor(CPDF_Color& color, - uint32_t& rgb, - CPDF_ColorSpace* pCS, - FX_FLOAT* pValue, - uint32_t nValues); - - uint32_t m_FillRGB; - uint32_t m_StrokeRGB; CPDF_Color m_FillColor; + uint32_t m_FillRGB; CPDF_Color m_StrokeColor; + uint32_t m_StrokeRGB; }; #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 d1eabb6908..fc054caf21 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()->SetDefault(); + m_ColorState.New()->Default(); } 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 5dc8480423..5d5b75b60e 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -6,7 +6,6 @@ #include "core/fpdfapi/fpdf_page/pageint.h" -#include <algorithm> #include <memory> #include <utility> #include <vector> @@ -693,7 +692,7 @@ void CPDF_StreamContentParser::Handle_SetColorSpace_Fill() { return; m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->GetFillColor()->SetColorSpace(pCS); + m_pCurStates->m_ColorState->m_FillColor.SetColorSpace(pCS); } void CPDF_StreamContentParser::Handle_SetColorSpace_Stroke() { @@ -702,7 +701,7 @@ void CPDF_StreamContentParser::Handle_SetColorSpace_Stroke() { return; m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->GetStrokeColor()->SetColorSpace(pCS); + m_pCurStates->m_ColorState->m_StrokeColor.SetColorSpace(pCS); } void CPDF_StreamContentParser::Handle_SetDash() { @@ -846,16 +845,14 @@ void CPDF_StreamContentParser::Handle_EOFillPath() { void CPDF_StreamContentParser::Handle_SetGray_Fill() { FX_FLOAT value = GetNumber(0); - m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->SetFillColor( - CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY), &value, 1); + CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY); + m_pCurStates->m_ColorState.SetFillColor(pCS, &value, 1); } void CPDF_StreamContentParser::Handle_SetGray_Stroke() { FX_FLOAT value = GetNumber(0); - m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->SetStrokeColor( - CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY), &value, 1); + CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY); + m_pCurStates->m_ColorState.SetStrokeColor(pCS, &value, 1); } void CPDF_StreamContentParser::Handle_SetExtendGraphState() { @@ -903,12 +900,11 @@ 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); - - m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->SetFillColor( - CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK), values, 4); + } + CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK); + m_pCurStates->m_ColorState.SetFillColor(pCS, values, 4); } void CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke() { @@ -916,12 +912,11 @@ 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); - - m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->SetStrokeColor( - CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK), values, 4); + } + CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK); + m_pCurStates->m_ColorState.SetStrokeColor(pCS, values, 4); } void CPDF_StreamContentParser::Handle_LineTo() { @@ -986,12 +981,11 @@ 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); - - m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->SetFillColor( - CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), values, 3); + } + CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB); + m_pCurStates->m_ColorState.SetFillColor(pCS, values, 3); } void CPDF_StreamContentParser::Handle_SetRGBColor_Stroke() { @@ -999,12 +993,11 @@ 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); - - m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->SetStrokeColor( - CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), values, 3); + } + CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB); + m_pCurStates->m_ColorState.SetStrokeColor(pCS, values, 3); } void CPDF_StreamContentParser::Handle_SetRenderIntent() {} @@ -1020,22 +1013,26 @@ void CPDF_StreamContentParser::Handle_StrokePath() { void CPDF_StreamContentParser::Handle_SetColor_Fill() { FX_FLOAT values[4]; - uint32_t nargs = std::min(m_ParamCount, 4u); - for (uint32_t i = 0; i < nargs; i++) + int nargs = m_ParamCount; + if (nargs > 4) { + nargs = 4; + } + for (int i = 0; i < nargs; i++) { values[i] = GetNumber(nargs - i - 1); - - m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->SetFillColor(nullptr, values, nargs); + } + m_pCurStates->m_ColorState.SetFillColor(nullptr, values, nargs); } void CPDF_StreamContentParser::Handle_SetColor_Stroke() { FX_FLOAT values[4]; - uint32_t nargs = std::min(m_ParamCount, 4u); - for (uint32_t i = 0; i < nargs; i++) + int nargs = m_ParamCount; + if (nargs > 4) { + nargs = 4; + } + for (int i = 0; i < nargs; i++) { values[i] = GetNumber(nargs - i - 1); - - m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->SetStrokeColor(nullptr, values, nargs); + } + m_pCurStates->m_ColorState.SetStrokeColor(nullptr, values, nargs); } void CPDF_StreamContentParser::Handle_SetColorPS_Fill() { @@ -1057,12 +1054,10 @@ void CPDF_StreamContentParser::Handle_SetColorPS_Fill() { if (nvalues != nargs) { CPDF_Pattern* pPattern = FindPattern(GetString(0), false); if (pPattern) { - m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->SetFillPattern(pPattern, values, nvalues); + m_pCurStates->m_ColorState.SetFillPattern(pPattern, values, nvalues); } } else { - m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->SetFillColor(nullptr, values, nvalues); + m_pCurStates->m_ColorState.SetFillColor(nullptr, values, nvalues); } FX_Free(values); } @@ -1087,12 +1082,10 @@ void CPDF_StreamContentParser::Handle_SetColorPS_Stroke() { if (nvalues != nargs) { CPDF_Pattern* pPattern = FindPattern(GetString(0), false); if (pPattern) { - m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->SetStrokePattern(pPattern, values, nvalues); + m_pCurStates->m_ColorState.SetStrokePattern(pPattern, values, nvalues); } } else { - m_pCurStates->m_ColorState.MakePrivateCopy(); - m_pCurStates->m_ColorState->SetStrokeColor(nullptr, values, nvalues); + 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 756ae020aa..e19c9a4a61 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->SetDefault(); + m_pParser->GetCurStates()->m_ColorState->Default(); } if (m_CurrentOffset >= m_Size) { m_InternalStage = STAGE_CHECKCLIP; |