summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page/cpdf_streamcontentparser.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-04-12 21:23:15 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-12 21:23:15 +0000
commit008b928ea39904374bc0dc8888e27bc48c812bda (patch)
tree5525b4c893aa2eae0f188747d64b6ead68225993 /core/fpdfapi/page/cpdf_streamcontentparser.cpp
parent1638179e85863b5045fcea2282fd3e0622aeac13 (diff)
downloadpdfium-008b928ea39904374bc0dc8888e27bc48c812bda.tar.xz
Rename one CPDF_Color::SetValue() variant.
Rename it to SetValueForPattern() and combine the components parameters into a std::vector. Fix the callers to use std::vector as well. Change-Id: Ib3426e0ffdb164f0fbb10d462ad251bf91165925 Reviewed-on: https://pdfium-review.googlesource.com/30450 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'core/fpdfapi/page/cpdf_streamcontentparser.cpp')
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp86
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() {