Break friendship between CFGAS_GEGraphics and CFGAS_GEShading
-- remove superfluous const from scalar arguments in constructors.
-- remove members that are only needed at init time.
Change-Id: I57bf99aaabb6c9587ca65da0767bbad6b5b08b6c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/80651
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fgas/graphics/cfgas_gegraphics.cpp b/xfa/fgas/graphics/cfgas_gegraphics.cpp
index 3f01872..845b219 100644
--- a/xfa/fgas/graphics/cfgas_gegraphics.cpp
+++ b/xfa/fgas/graphics/cfgas_gegraphics.cpp
@@ -277,16 +277,16 @@
RetainPtr<CFX_DIBitmap> bitmap = m_renderDevice->GetBitmap();
int32_t width = bitmap->GetWidth();
int32_t height = bitmap->GetHeight();
- float start_x = m_info.fillColor.GetShading()->m_beginPoint.x;
- float start_y = m_info.fillColor.GetShading()->m_beginPoint.y;
- float end_x = m_info.fillColor.GetShading()->m_endPoint.x;
- float end_y = m_info.fillColor.GetShading()->m_endPoint.y;
+ float start_x = m_info.fillColor.GetShading()->GetBeginPoint().x;
+ float start_y = m_info.fillColor.GetShading()->GetBeginPoint().y;
+ float end_x = m_info.fillColor.GetShading()->GetEndPoint().x;
+ float end_y = m_info.fillColor.GetShading()->GetEndPoint().y;
auto bmp = pdfium::MakeRetain<CFX_DIBitmap>();
bmp->Create(width, height, FXDIB_Format::kArgb);
m_renderDevice->GetDIBits(bmp, 0, 0);
int32_t pitch = bmp->GetPitch();
bool result = false;
- switch (m_info.fillColor.GetShading()->m_type) {
+ switch (m_info.fillColor.GetShading()->GetType()) {
case CFGAS_GEShading::Type::kAxial: {
float x_span = end_x - start_x;
float y_span = end_y - start_y;
@@ -302,26 +302,26 @@
scale = (((x - start_x) * x_span) + ((y - start_y) * y_span)) /
axis_len_square;
if (std::isnan(scale) || scale < 0.0f) {
- if (!m_info.fillColor.GetShading()->m_isExtendedBegin)
+ if (!m_info.fillColor.GetShading()->IsExtendedBegin())
continue;
scale = 0.0f;
} else if (scale > 1.0f) {
- if (!m_info.fillColor.GetShading()->m_isExtendedEnd)
+ if (!m_info.fillColor.GetShading()->IsExtendedEnd())
continue;
scale = 1.0f;
}
}
int32_t index =
static_cast<int32_t>(scale * (CFGAS_GEShading::kSteps - 1));
- dib_buf[column] = m_info.fillColor.GetShading()->m_argbArray[index];
+ dib_buf[column] = m_info.fillColor.GetShading()->GetArgb(index);
}
}
result = true;
break;
}
case CFGAS_GEShading::Type::kRadial: {
- float start_r = m_info.fillColor.GetShading()->m_beginRadius;
- float end_r = m_info.fillColor.GetShading()->m_endRadius;
+ float start_r = m_info.fillColor.GetShading()->GetBeginRadius();
+ float end_r = m_info.fillColor.GetShading()->GetEndRadius();
float a = ((start_x - end_x) * (start_x - end_x)) +
((start_y - end_y) * (start_y - end_y)) -
((start_r - end_r) * (start_r - end_r));
@@ -353,7 +353,7 @@
s2 = (-b - root) / (2 * a);
s1 = (-b + root) / (2 * a);
}
- if (s2 <= 1.0f || m_info.fillColor.GetShading()->m_isExtendedEnd) {
+ if (s2 <= 1.0f || m_info.fillColor.GetShading()->IsExtendedEnd()) {
s = (s2);
} else {
s = (s1);
@@ -363,17 +363,17 @@
}
}
if (std::isnan(s) || s < 0.0f) {
- if (!m_info.fillColor.GetShading()->m_isExtendedBegin)
+ if (!m_info.fillColor.GetShading()->IsExtendedBegin())
continue;
s = 0.0f;
}
if (s > 1.0f) {
- if (!m_info.fillColor.GetShading()->m_isExtendedEnd)
+ if (!m_info.fillColor.GetShading()->IsExtendedEnd())
continue;
s = 1.0f;
}
int index = static_cast<int32_t>(s * (CFGAS_GEShading::kSteps - 1));
- dib_buf[column] = m_info.fillColor.GetShading()->m_argbArray[index];
+ dib_buf[column] = m_info.fillColor.GetShading()->GetArgb(index);
}
}
result = true;
diff --git a/xfa/fgas/graphics/cfgas_geshading.cpp b/xfa/fgas/graphics/cfgas_geshading.cpp
index 13b68ea..1e3c7b1 100644
--- a/xfa/fgas/graphics/cfgas_geshading.cpp
+++ b/xfa/fgas/graphics/cfgas_geshading.cpp
@@ -10,54 +10,50 @@
const CFX_PointF& endPoint,
bool isExtendedBegin,
bool isExtendedEnd,
- const FX_ARGB beginArgb,
- const FX_ARGB endArgb)
+ FX_ARGB beginArgb,
+ FX_ARGB endArgb)
: m_type(Type::kAxial),
m_beginPoint(beginPoint),
m_endPoint(endPoint),
m_beginRadius(0),
m_endRadius(0),
m_isExtendedBegin(isExtendedBegin),
- m_isExtendedEnd(isExtendedEnd),
- m_beginArgb(beginArgb),
- m_endArgb(endArgb) {
- InitArgbArray();
+ m_isExtendedEnd(isExtendedEnd) {
+ InitArgbArray(beginArgb, endArgb);
}
CFGAS_GEShading::CFGAS_GEShading(const CFX_PointF& beginPoint,
const CFX_PointF& endPoint,
- const float beginRadius,
- const float endRadius,
+ float beginRadius,
+ float endRadius,
bool isExtendedBegin,
bool isExtendedEnd,
- const FX_ARGB beginArgb,
- const FX_ARGB endArgb)
+ FX_ARGB beginArgb,
+ FX_ARGB endArgb)
: m_type(Type::kRadial),
m_beginPoint(beginPoint),
m_endPoint(endPoint),
m_beginRadius(beginRadius),
m_endRadius(endRadius),
m_isExtendedBegin(isExtendedBegin),
- m_isExtendedEnd(isExtendedEnd),
- m_beginArgb(beginArgb),
- m_endArgb(endArgb) {
- InitArgbArray();
+ m_isExtendedEnd(isExtendedEnd) {
+ InitArgbArray(beginArgb, endArgb);
}
CFGAS_GEShading::~CFGAS_GEShading() = default;
-void CFGAS_GEShading::InitArgbArray() {
+void CFGAS_GEShading::InitArgbArray(FX_ARGB beginArgb, FX_ARGB endArgb) {
int32_t a1;
int32_t r1;
int32_t g1;
int32_t b1;
- std::tie(a1, r1, g1, b1) = ArgbDecode(m_beginArgb);
+ std::tie(a1, r1, g1, b1) = ArgbDecode(beginArgb);
int32_t a2;
int32_t r2;
int32_t g2;
int32_t b2;
- std::tie(a2, r2, g2, b2) = ArgbDecode(m_endArgb);
+ std::tie(a2, r2, g2, b2) = ArgbDecode(endArgb);
float f = static_cast<float>(kSteps - 1);
float aScale = 1.0 * (a2 - a1) / f;
diff --git a/xfa/fgas/graphics/cfgas_geshading.h b/xfa/fgas/graphics/cfgas_geshading.h
index 73aee05..eaa86a1 100644
--- a/xfa/fgas/graphics/cfgas_geshading.h
+++ b/xfa/fgas/graphics/cfgas_geshading.h
@@ -13,33 +13,41 @@
class CFGAS_GEShading final {
public:
+ enum class Type { kAxial = 1, kRadial };
+
+ static constexpr size_t kSteps = 256;
+
// Axial shading.
CFGAS_GEShading(const CFX_PointF& beginPoint,
const CFX_PointF& endPoint,
bool isExtendedBegin,
bool isExtendedEnd,
- const FX_ARGB beginArgb,
- const FX_ARGB endArgb);
+ FX_ARGB beginArgb,
+ FX_ARGB endArgb);
// Radial shading.
CFGAS_GEShading(const CFX_PointF& beginPoint,
const CFX_PointF& endPoint,
- const float beginRadius,
- const float endRadius,
+ float beginRadius,
+ float endRadius,
bool isExtendedBegin,
bool isExtendedEnd,
- const FX_ARGB beginArgb,
- const FX_ARGB endArgb);
+ FX_ARGB beginArgb,
+ FX_ARGB endArgb);
~CFGAS_GEShading();
+ Type GetType() const { return m_type; }
+ CFX_PointF GetBeginPoint() const { return m_beginPoint; }
+ CFX_PointF GetEndPoint() const { return m_endPoint; }
+ float GetBeginRadius() const { return m_beginRadius; }
+ float GetEndRadius() const { return m_endRadius; }
+ bool IsExtendedBegin() const { return m_isExtendedBegin; }
+ bool IsExtendedEnd() const { return m_isExtendedEnd; }
+ FX_ARGB GetArgb(size_t index) const { return m_argbArray[index]; }
+
private:
- friend class CFGAS_GEGraphics;
-
- enum class Type { kAxial = 1, kRadial };
- static constexpr size_t kSteps = 256;
-
- void InitArgbArray();
+ void InitArgbArray(FX_ARGB beginArgb, FX_ARGB endArgb);
const Type m_type;
const CFX_PointF m_beginPoint;
@@ -48,8 +56,6 @@
const float m_endRadius;
const bool m_isExtendedBegin;
const bool m_isExtendedEnd;
- const FX_ARGB m_beginArgb;
- const FX_ARGB m_endArgb;
FX_ARGB m_argbArray[kSteps];
};