diff options
Diffstat (limited to 'core/fpdfapi/page/cpdf_streamcontentparser.cpp')
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.cpp | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 9cd05cbb2d..5d1f5efd49 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -832,6 +832,23 @@ CPDF_ImageObject* CPDF_StreamContentParser::AddImageObject( return pRet; } +std::vector<float> CPDF_StreamContentParser::GetColors() const { + ASSERT(m_ParamCount > 0); + std::vector<float> values(m_ParamCount); + for (size_t i = 0; i < m_ParamCount; ++i) + values[i] = GetNumber(m_ParamCount - i - 1); + return values; +} + +std::vector<float> CPDF_StreamContentParser::GetNamedColors() const { + ASSERT(m_ParamCount > 0); + const uint32_t nvalues = m_ParamCount - 1; + std::vector<float> values(nvalues); + for (size_t i = 0; i < nvalues; ++i) + values[i] = GetNumber(m_ParamCount - i - 1); + return values; +} + void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary() {} void CPDF_StreamContentParser::Handle_EndImage() {} @@ -1049,57 +1066,40 @@ void CPDF_StreamContentParser::Handle_SetColor_Stroke() { void CPDF_StreamContentParser::Handle_SetColorPS_Fill() { CPDF_Object* pLastParam = GetObject(0); - if (!pLastParam) { + if (!pLastParam) + return; + + if (!pLastParam->IsName()) { + std::vector<float> values = GetColors(); + m_pCurStates->m_ColorState.SetFillColor(nullptr, values.data(), + values.size()); return; } - uint32_t nargs = m_ParamCount; - uint32_t nvalues = nargs; - if (pLastParam->IsName()) - nvalues--; - float* values = nullptr; - if (nvalues) { - values = FX_Alloc(float, nvalues); - for (uint32_t i = 0; i < nvalues; i++) { - values[i] = GetNumber(nargs - i - 1); - } - } - if (nvalues != nargs) { - CPDF_Pattern* pPattern = FindPattern(GetString(0), false); - if (pPattern) { - m_pCurStates->m_ColorState.SetFillPattern(pPattern, values, nvalues); - } - } else { - m_pCurStates->m_ColorState.SetFillColor(nullptr, values, nvalues); - } - FX_Free(values); + + // A valid |pLastParam| implies |m_ParamCount| > 0, so GetNamedColors() call + // below is safe. + CPDF_Pattern* pPattern = FindPattern(GetString(0), false); + if (pPattern) + m_pCurStates->m_ColorState.SetFillPattern(pPattern, GetNamedColors()); } void CPDF_StreamContentParser::Handle_SetColorPS_Stroke() { CPDF_Object* pLastParam = GetObject(0); - if (!pLastParam) { + if (!pLastParam) + return; + + if (!pLastParam->IsName()) { + std::vector<float> values = GetColors(); + m_pCurStates->m_ColorState.SetStrokeColor(nullptr, values.data(), + values.size()); return; } - int nargs = m_ParamCount; - int nvalues = nargs; - if (pLastParam->IsName()) - nvalues--; - - float* values = nullptr; - if (nvalues) { - values = FX_Alloc(float, nvalues); - for (int i = 0; i < nvalues; i++) { - values[i] = GetNumber(nargs - i - 1); - } - } - if (nvalues != nargs) { - CPDF_Pattern* pPattern = FindPattern(GetString(0), false); - if (pPattern) { - m_pCurStates->m_ColorState.SetStrokePattern(pPattern, values, nvalues); - } - } else { - m_pCurStates->m_ColorState.SetStrokeColor(nullptr, values, nvalues); - } - FX_Free(values); + + // A valid |pLastParam| implies |m_ParamCount| > 0, so GetNamedColors() call + // below is safe. + CPDF_Pattern* pPattern = FindPattern(GetString(0), false); + if (pPattern) + m_pCurStates->m_ColorState.SetStrokePattern(pPattern, GetNamedColors()); } void CPDF_StreamContentParser::Handle_ShadeFill() { |