Consolidate XFA color printing code to CFGAS_GEColor::ColorToString()
Move similar code in 3 files into a common place. Remove some unneeded
const keywords along the way.
Change-Id: If45d59a3170a6443415264fce6bf51ea159cb1ec
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/121570
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Tom Sepez <tsepez@google.com>
diff --git a/fxjs/BUILD.gn b/fxjs/BUILD.gn
index e3f62ff..0e9e23c 100644
--- a/fxjs/BUILD.gn
+++ b/fxjs/BUILD.gn
@@ -213,6 +213,7 @@
deps += [
":gc",
"../xfa/fgas/crt",
+ "../xfa/fgas/graphics",
"../xfa/fxfa/formcalc",
]
}
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index e61183e..6d77a81 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -31,6 +31,7 @@
#include "v8/include/v8-object.h"
#include "v8/include/v8-primitive.h"
#include "xfa/fgas/crt/cfgas_decimal.h"
+#include "xfa/fgas/graphics/cfgas_gecolor.h"
#include "xfa/fxfa/cxfa_ffnotify.h"
#include "xfa/fxfa/cxfa_ffwidget.h"
#include "xfa/fxfa/parser/cxfa_border.h"
@@ -99,10 +100,8 @@
}
v8::Local<v8::String> ColorToV8String(v8::Isolate* isolate, FX_ARGB color) {
- FX_BGR_STRUCT<uint8_t> bgr = ArgbToBGRStruct(color);
return fxv8::NewStringHelper(
- isolate, ByteString::Format("%d,%d,%d", bgr.red, bgr.green, bgr.blue)
- .AsStringView());
+ isolate, CFGAS_GEColor::ColorToString(color).AsStringView());
}
} // namespace
diff --git a/xfa/fgas/graphics/cfgas_gecolor.cpp b/xfa/fgas/graphics/cfgas_gecolor.cpp
index 861d2c3..685118e 100644
--- a/xfa/fgas/graphics/cfgas_gecolor.cpp
+++ b/xfa/fgas/graphics/cfgas_gecolor.cpp
@@ -6,10 +6,9 @@
#include "xfa/fgas/graphics/cfgas_gecolor.h"
-CFGAS_GEColor::CFGAS_GEColor(const FX_ARGB argb)
- : m_type(Solid), m_argb(argb) {}
+CFGAS_GEColor::CFGAS_GEColor(FX_ARGB argb) : m_type(Solid), m_argb(argb) {}
-CFGAS_GEColor::CFGAS_GEColor(CFGAS_GEPattern* pattern, const FX_ARGB argb)
+CFGAS_GEColor::CFGAS_GEColor(CFGAS_GEPattern* pattern, FX_ARGB argb)
: m_type(Pattern), m_argb(argb), m_pPattern(pattern) {}
CFGAS_GEColor::CFGAS_GEColor(CFGAS_GEShading* shading)
@@ -20,3 +19,9 @@
CFGAS_GEColor::~CFGAS_GEColor() = default;
CFGAS_GEColor& CFGAS_GEColor::operator=(const CFGAS_GEColor& that) = default;
+
+// static
+ByteString CFGAS_GEColor::ColorToString(FX_ARGB argb) {
+ FX_BGR_STRUCT<uint8_t> bgr = ArgbToBGRStruct(argb);
+ return ByteString::Format("%d,%d,%d", bgr.red, bgr.green, bgr.blue);
+}
diff --git a/xfa/fgas/graphics/cfgas_gecolor.h b/xfa/fgas/graphics/cfgas_gecolor.h
index e3b2445..6ccebc4 100644
--- a/xfa/fgas/graphics/cfgas_gecolor.h
+++ b/xfa/fgas/graphics/cfgas_gecolor.h
@@ -7,6 +7,7 @@
#ifndef XFA_FGAS_GRAPHICS_CFGAS_GECOLOR_H_
#define XFA_FGAS_GRAPHICS_CFGAS_GECOLOR_H_
+#include "core/fxcrt/bytestring.h"
#include "core/fxcrt/check.h"
#include "core/fxcrt/check_op.h"
#include "core/fxcrt/unowned_ptr.h"
@@ -19,9 +20,9 @@
public:
enum Type { Invalid, Solid, Pattern, Shading };
- explicit CFGAS_GEColor(const FX_ARGB argb);
+ explicit CFGAS_GEColor(FX_ARGB argb);
explicit CFGAS_GEColor(CFGAS_GEShading* shading);
- CFGAS_GEColor(CFGAS_GEPattern* pattern, const FX_ARGB argb);
+ CFGAS_GEColor(CFGAS_GEPattern* pattern, FX_ARGB argb);
CFGAS_GEColor(const CFGAS_GEColor& that);
~CFGAS_GEColor();
@@ -41,6 +42,8 @@
CFGAS_GEColor& operator=(const CFGAS_GEColor& that);
+ static ByteString ColorToString(FX_ARGB argb);
+
private:
Type m_type = Invalid;
FX_ARGB m_argb = 0;
diff --git a/xfa/fxfa/parser/cxfa_color.cpp b/xfa/fxfa/parser/cxfa_color.cpp
index e848838..4c1dfe8 100644
--- a/xfa/fxfa/parser/cxfa_color.cpp
+++ b/xfa/fxfa/parser/cxfa_color.cpp
@@ -8,6 +8,7 @@
#include "core/fxcrt/fx_extension.h"
#include "fxjs/xfa/cjx_node.h"
+#include "xfa/fgas/graphics/cfgas_gecolor.h"
#include "xfa/fxfa/parser/cxfa_document.h"
namespace {
@@ -110,8 +111,7 @@
}
void CXFA_Color::SetValue(FX_ARGB color) {
- FX_BGR_STRUCT<uint8_t> bgr = ArgbToBGRStruct(color);
- JSObject()->SetCData(
- XFA_Attribute::Value,
- WideString::Format(L"%d,%d,%d", bgr.red, bgr.green, bgr.blue));
+ JSObject()->SetCData(XFA_Attribute::Value,
+ WideString::FromASCII(
+ CFGAS_GEColor::ColorToString(color).AsStringView()));
}
diff --git a/xfa/fxfa/parser/cxfa_stroke.cpp b/xfa/fxfa/parser/cxfa_stroke.cpp
index 6bba800..2fb0306 100644
--- a/xfa/fxfa/parser/cxfa_stroke.cpp
+++ b/xfa/fxfa/parser/cxfa_stroke.cpp
@@ -11,6 +11,7 @@
#include <utility>
#include "fxjs/xfa/cjx_object.h"
+#include "xfa/fgas/graphics/cfgas_gecolor.h"
#include "xfa/fgas/graphics/cfgas_gegraphics.h"
#include "xfa/fxfa/cxfa_ffwidget.h"
#include "xfa/fxfa/parser/cxfa_color.h"
@@ -125,10 +126,9 @@
if (!pNode)
return;
- FX_BGR_STRUCT<uint8_t> bgr = ArgbToBGRStruct(argb);
pNode->JSObject()->SetCData(
XFA_Attribute::Value,
- WideString::Format(L"%d,%d,%d", bgr.red, bgr.green, bgr.blue));
+ WideString::FromASCII(CFGAS_GEColor::ColorToString(argb).AsStringView()));
}
XFA_AttributeValue CXFA_Stroke::GetJoinType() {