summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/javascript/Field.cpp12
-rw-r--r--fpdfsdk/javascript/PublicMethods.cpp14
-rw-r--r--fpdfsdk/javascript/color.cpp130
-rw-r--r--fpdfsdk/javascript/color.h12
4 files changed, 80 insertions, 88 deletions
diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp
index b6c32b5208..155e7cea43 100644
--- a/fpdfsdk/javascript/Field.cpp
+++ b/fpdfsdk/javascript/Field.cpp
@@ -1229,7 +1229,6 @@ bool Field::set_file_select(CJS_Runtime* pRuntime,
bool Field::get_fill_color(CJS_Runtime* pRuntime,
CJS_Value* vp,
WideString* sError) {
- CJS_Array crArray;
std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
if (FieldArray.empty())
return false;
@@ -1264,8 +1263,7 @@ bool Field::get_fill_color(CJS_Runtime* pRuntime,
return false;
}
- color::ConvertPWLColorToArray(pRuntime, color, &crArray);
- vp->Set(pRuntime, crArray);
+ vp->Set(pRuntime, color::ConvertPWLColorToArray(pRuntime, color));
return true;
}
@@ -1963,9 +1961,7 @@ bool Field::get_stroke_color(CJS_Runtime* pRuntime,
return false;
}
- CJS_Array crArray;
- color::ConvertPWLColorToArray(pRuntime, color, &crArray);
- vp->Set(pRuntime, crArray);
+ vp->Set(pRuntime, color::ConvertPWLColorToArray(pRuntime, color));
return true;
}
@@ -2073,9 +2069,7 @@ bool Field::get_text_color(CJS_Runtime* pRuntime,
if (iColorType == CFX_Color::kTransparent)
crRet = CFX_Color(CFX_Color::kTransparent);
- CJS_Array crArray;
- color::ConvertPWLColorToArray(pRuntime, crRet, &crArray);
- vp->Set(pRuntime, crArray);
+ vp->Set(pRuntime, color::ConvertPWLColorToArray(pRuntime, crRet));
return true;
}
diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp
index 2e7387e9d2..5e428007ad 100644
--- a/fpdfsdk/javascript/PublicMethods.cpp
+++ b/fpdfsdk/javascript/PublicMethods.cpp
@@ -924,16 +924,12 @@ bool CJS_PublicMethods::AFNumber_Format(CJS_Runtime* pRuntime,
CJS_Value vProp(pRuntime);
fTarget->get_text_color(pRuntime, &vProp, &sError);
- CJS_Array aProp = vProp.ToArray(pRuntime);
- CFX_Color crProp;
- CFX_Color crColor;
- color::ConvertArrayToPWLColor(pRuntime, aProp, &crProp);
- color::ConvertArrayToPWLColor(pRuntime, arColor, &crColor);
-
+ CFX_Color crProp =
+ color::ConvertArrayToPWLColor(pRuntime, vProp.ToArray(pRuntime));
+ CFX_Color crColor = color::ConvertArrayToPWLColor(pRuntime, arColor);
if (crColor != crProp) {
- CJS_Value vProp2(pRuntime, arColor);
-
- fTarget->set_text_color(pRuntime, vProp2, &sError);
+ fTarget->set_text_color(pRuntime, CJS_Value(pRuntime, arColor),
+ &sError);
}
}
}
diff --git a/fpdfsdk/javascript/color.cpp b/fpdfsdk/javascript/color.cpp
index 09a6a09e80..2eccdae11e 100644
--- a/fpdfsdk/javascript/color.cpp
+++ b/fpdfsdk/javascript/color.cpp
@@ -38,82 +38,90 @@ JSMethodSpec CJS_Color::MethodSpecs[] = {{"convert", convert_static},
IMPLEMENT_JS_CLASS(CJS_Color, color, color)
-color::color(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {
- m_crTransparent = CFX_Color(CFX_Color::kTransparent);
- m_crBlack = CFX_Color(CFX_Color::kGray, 0);
- m_crWhite = CFX_Color(CFX_Color::kGray, 1);
- m_crRed = CFX_Color(CFX_Color::kRGB, 1, 0, 0);
- m_crGreen = CFX_Color(CFX_Color::kRGB, 0, 1, 0);
- m_crBlue = CFX_Color(CFX_Color::kRGB, 0, 0, 1);
- m_crCyan = CFX_Color(CFX_Color::kCMYK, 1, 0, 0, 0);
- m_crMagenta = CFX_Color(CFX_Color::kCMYK, 0, 1, 0, 0);
- m_crYellow = CFX_Color(CFX_Color::kCMYK, 0, 0, 1, 0);
- m_crDKGray = CFX_Color(CFX_Color::kGray, 0.25);
- m_crGray = CFX_Color(CFX_Color::kGray, 0.5);
- m_crLTGray = CFX_Color(CFX_Color::kGray, 0.75);
-}
-
-color::~color() {}
-
-void color::ConvertPWLColorToArray(CJS_Runtime* pRuntime,
- const CFX_Color& color,
- CJS_Array* array) {
+// static
+CJS_Array color::ConvertPWLColorToArray(CJS_Runtime* pRuntime,
+ const CFX_Color& color) {
+ CJS_Array array;
switch (color.nColorType) {
case CFX_Color::kTransparent:
- array->SetElement(pRuntime, 0, CJS_Value(pRuntime, "T"));
+ array.SetElement(pRuntime, 0, CJS_Value(pRuntime, "T"));
break;
case CFX_Color::kGray:
- array->SetElement(pRuntime, 0, CJS_Value(pRuntime, "G"));
- array->SetElement(pRuntime, 1, CJS_Value(pRuntime, color.fColor1));
+ array.SetElement(pRuntime, 0, CJS_Value(pRuntime, "G"));
+ array.SetElement(pRuntime, 1, CJS_Value(pRuntime, color.fColor1));
break;
case CFX_Color::kRGB:
- array->SetElement(pRuntime, 0, CJS_Value(pRuntime, "RGB"));
- array->SetElement(pRuntime, 1, CJS_Value(pRuntime, color.fColor1));
- array->SetElement(pRuntime, 2, CJS_Value(pRuntime, color.fColor2));
- array->SetElement(pRuntime, 3, CJS_Value(pRuntime, color.fColor3));
+ array.SetElement(pRuntime, 0, CJS_Value(pRuntime, "RGB"));
+ array.SetElement(pRuntime, 1, CJS_Value(pRuntime, color.fColor1));
+ array.SetElement(pRuntime, 2, CJS_Value(pRuntime, color.fColor2));
+ array.SetElement(pRuntime, 3, CJS_Value(pRuntime, color.fColor3));
break;
case CFX_Color::kCMYK:
- array->SetElement(pRuntime, 0, CJS_Value(pRuntime, "CMYK"));
- array->SetElement(pRuntime, 1, CJS_Value(pRuntime, color.fColor1));
- array->SetElement(pRuntime, 2, CJS_Value(pRuntime, color.fColor2));
- array->SetElement(pRuntime, 3, CJS_Value(pRuntime, color.fColor3));
- array->SetElement(pRuntime, 4, CJS_Value(pRuntime, color.fColor4));
+ array.SetElement(pRuntime, 0, CJS_Value(pRuntime, "CMYK"));
+ array.SetElement(pRuntime, 1, CJS_Value(pRuntime, color.fColor1));
+ array.SetElement(pRuntime, 2, CJS_Value(pRuntime, color.fColor2));
+ array.SetElement(pRuntime, 3, CJS_Value(pRuntime, color.fColor3));
+ array.SetElement(pRuntime, 4, CJS_Value(pRuntime, color.fColor4));
break;
}
+ return array;
}
-void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime,
- const CJS_Array& array,
- CFX_Color* color) {
+// static
+CFX_Color color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime,
+ const CJS_Array& array) {
int nArrayLen = array.GetLength(pRuntime);
if (nArrayLen < 1)
- return;
+ return CFX_Color();
- float d1 = 0;
- float d2 = 0;
- float d3 = 0;
- float d4 = 0;
+ ByteString sSpace = array.GetElement(pRuntime, 0).ToByteString(pRuntime);
+ if (sSpace == "T")
+ return CFX_Color(CFX_Color::kTransparent);
+ float d1 = 0;
if (nArrayLen > 1)
d1 = array.GetElement(pRuntime, 1).ToFloat(pRuntime);
+
+ if (sSpace == "G")
+ return CFX_Color(CFX_Color::kGray, d1);
+
+ float d2 = 0;
+ float d3 = 0;
if (nArrayLen > 2)
d2 = array.GetElement(pRuntime, 2).ToFloat(pRuntime);
if (nArrayLen > 3)
d3 = array.GetElement(pRuntime, 3).ToFloat(pRuntime);
+
+ if (sSpace == "RGB")
+ return CFX_Color(CFX_Color::kRGB, d1, d2, d3);
+
+ float d4 = 0;
if (nArrayLen > 4)
d4 = array.GetElement(pRuntime, 4).ToFloat(pRuntime);
- ByteString sSpace = array.GetElement(pRuntime, 0).ToByteString(pRuntime);
- if (sSpace == "T")
- *color = CFX_Color(CFX_Color::kTransparent);
- else if (sSpace == "G")
- *color = CFX_Color(CFX_Color::kGray, d1);
- else if (sSpace == "RGB")
- *color = CFX_Color(CFX_Color::kRGB, d1, d2, d3);
- else if (sSpace == "CMYK")
- *color = CFX_Color(CFX_Color::kCMYK, d1, d2, d3, d4);
+ if (sSpace == "CMYK")
+ return CFX_Color(CFX_Color::kCMYK, d1, d2, d3, d4);
+
+ return CFX_Color();
+}
+
+color::color(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {
+ m_crTransparent = CFX_Color(CFX_Color::kTransparent);
+ m_crBlack = CFX_Color(CFX_Color::kGray, 0);
+ m_crWhite = CFX_Color(CFX_Color::kGray, 1);
+ m_crRed = CFX_Color(CFX_Color::kRGB, 1, 0, 0);
+ m_crGreen = CFX_Color(CFX_Color::kRGB, 0, 1, 0);
+ m_crBlue = CFX_Color(CFX_Color::kRGB, 0, 0, 1);
+ m_crCyan = CFX_Color(CFX_Color::kCMYK, 1, 0, 0, 0);
+ m_crMagenta = CFX_Color(CFX_Color::kCMYK, 0, 1, 0, 0);
+ m_crYellow = CFX_Color(CFX_Color::kCMYK, 0, 0, 1, 0);
+ m_crDKGray = CFX_Color(CFX_Color::kGray, 0.25);
+ m_crGray = CFX_Color(CFX_Color::kGray, 0.5);
+ m_crLTGray = CFX_Color(CFX_Color::kGray, 0.75);
}
+color::~color() {}
+
bool color::get_transparent(CJS_Runtime* pRuntime,
CJS_Value* vp,
WideString* sError) {
@@ -253,9 +261,7 @@ bool color::set_light_gray(CJS_Runtime* pRuntime,
bool color::GetPropertyHelper(CJS_Runtime* pRuntime,
CJS_Value* vp,
CFX_Color* var) {
- CJS_Array array;
- ConvertPWLColorToArray(pRuntime, *var, &array);
- vp->Set(pRuntime, array);
+ vp->Set(pRuntime, ConvertPWLColorToArray(pRuntime, *var));
return true;
}
@@ -265,7 +271,7 @@ bool color::SetPropertyHelper(CJS_Runtime* pRuntime,
if (!vp.IsArrayObject())
return false;
- ConvertArrayToPWLColor(pRuntime, vp.ToArray(pRuntime), var);
+ *var = ConvertArrayToPWLColor(pRuntime, vp.ToArray(pRuntime));
return true;
}
@@ -280,8 +286,6 @@ bool color::convert(CJS_Runtime* pRuntime,
if (!params[0].IsArrayObject())
return false;
- CFX_Color crSource;
- ConvertArrayToPWLColor(pRuntime, params[0].ToArray(pRuntime), &crSource);
ByteString sDestSpace = params[1].ToByteString(pRuntime);
int nColorType = CFX_Color::kTransparent;
@@ -294,10 +298,10 @@ bool color::convert(CJS_Runtime* pRuntime,
else if (sDestSpace == "CMYK")
nColorType = CFX_Color::kCMYK;
- CJS_Array aDest;
- CFX_Color crDest = crSource.ConvertColorType(nColorType);
- ConvertPWLColorToArray(pRuntime, crDest, &aDest);
- vRet = CJS_Value(pRuntime, aDest);
+ CFX_Color color =
+ ConvertArrayToPWLColor(pRuntime, params[0].ToArray(pRuntime));
+ vRet = CJS_Value(pRuntime, ConvertPWLColorToArray(
+ pRuntime, color.ConvertColorType(nColorType)));
return true;
}
@@ -311,10 +315,10 @@ bool color::equal(CJS_Runtime* pRuntime,
if (!params[0].IsArrayObject() || !params[1].IsArrayObject())
return false;
- CFX_Color color1;
- CFX_Color color2;
- ConvertArrayToPWLColor(pRuntime, params[0].ToArray(pRuntime), &color1);
- ConvertArrayToPWLColor(pRuntime, params[1].ToArray(pRuntime), &color2);
+ CFX_Color color1 =
+ ConvertArrayToPWLColor(pRuntime, params[0].ToArray(pRuntime));
+ CFX_Color color2 =
+ ConvertArrayToPWLColor(pRuntime, params[1].ToArray(pRuntime));
color1 = color1.ConvertColorType(color2.nColorType);
vRet = CJS_Value(pRuntime, color1 == color2);
diff --git a/fpdfsdk/javascript/color.h b/fpdfsdk/javascript/color.h
index 08da346377..851f05b124 100644
--- a/fpdfsdk/javascript/color.h
+++ b/fpdfsdk/javascript/color.h
@@ -14,6 +14,11 @@
class color : public CJS_EmbedObj {
public:
+ static CJS_Array ConvertPWLColorToArray(CJS_Runtime* pRuntime,
+ const CFX_Color& color);
+ static CFX_Color ConvertArrayToPWLColor(CJS_Runtime* pRuntime,
+ const CJS_Array& array);
+
explicit color(CJS_Object* pJSObject);
~color() override;
@@ -80,13 +85,6 @@ class color : public CJS_EmbedObj {
CJS_Value& vRet,
WideString& sError);
- static void ConvertPWLColorToArray(CJS_Runtime* pRuntime,
- const CFX_Color& color,
- CJS_Array* array);
- static void ConvertArrayToPWLColor(CJS_Runtime* pRuntime,
- const CJS_Array& array,
- CFX_Color* color);
-
private:
bool GetPropertyHelper(CJS_Runtime* pRuntime, CJS_Value* vp, CFX_Color* val);
bool SetPropertyHelper(CJS_Runtime* pRuntime,