Simplify CFGAS_GEGraphics::SetLineDash()
- Remove the phase parameter, which is always 0.
- Switch to using move semantics.
- Rename some variables to follow Google C++ style.
Change-Id: I14b90454a4dee19762f613f5c1589b63acaffb02
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/124812
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Tom Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fgas/graphics/cfgas_gegraphics.cpp b/xfa/fgas/graphics/cfgas_gegraphics.cpp
index 128b6b4..fdc2b79 100644
--- a/xfa/fgas/graphics/cfgas_gegraphics.cpp
+++ b/xfa/fgas/graphics/cfgas_gegraphics.cpp
@@ -140,14 +140,15 @@
m_info.graphState.m_LineCap = lineCap;
}
-void CFGAS_GEGraphics::SetLineDash(float dashPhase,
- pdfium::span<const float> dashArray) {
- DCHECK(!dashArray.empty());
- float scale = m_info.isActOnDash ? m_info.graphState.m_LineWidth : 1.0;
- m_info.graphState.m_DashPhase = dashPhase;
- m_info.graphState.m_DashArray.resize(dashArray.size());
- for (size_t i = 0; i < dashArray.size(); ++i)
- m_info.graphState.m_DashArray[i] = dashArray[i] * scale;
+void CFGAS_GEGraphics::SetLineDash(std::vector<float> dash_array) {
+ // For `dash_array` to be empty, call SetSolidLineDash() instead.
+ CHECK(!dash_array.empty());
+ const float scale = m_info.isActOnDash ? m_info.graphState.m_LineWidth : 1.0;
+ for (float& f : dash_array) {
+ f *= scale;
+ }
+ m_info.graphState.m_DashArray = std::move(dash_array);
+ m_info.graphState.m_DashPhase = 0;
}
void CFGAS_GEGraphics::SetSolidLineDash() {
diff --git a/xfa/fgas/graphics/cfgas_gegraphics.h b/xfa/fgas/graphics/cfgas_gegraphics.h
index f97bd9f..6dfd1d0 100644
--- a/xfa/fgas/graphics/cfgas_gegraphics.h
+++ b/xfa/fgas/graphics/cfgas_gegraphics.h
@@ -13,7 +13,6 @@
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_memory.h"
#include "core/fxcrt/retain_ptr.h"
-#include "core/fxcrt/span.h"
#include "core/fxcrt/unowned_ptr.h"
#include "core/fxge/cfx_fillrenderoptions.h"
#include "core/fxge/cfx_graphstatedata.h"
@@ -44,7 +43,8 @@
CFX_RenderDevice* GetRenderDevice();
void SetLineCap(CFX_GraphStateData::LineCap lineCap);
- void SetLineDash(float dashPhase, pdfium::span<const float> dashArray);
+ // Dash phase is always set to 0.
+ void SetLineDash(std::vector<float> dash_array);
void SetSolidLineDash();
void SetLineWidth(float lineWidth);
void EnableActOnDash();
diff --git a/xfa/fwl/theme/cfwl_widgettp.cpp b/xfa/fwl/theme/cfwl_widgettp.cpp
index 6dd8804..253b62a 100644
--- a/xfa/fwl/theme/cfwl_widgettp.cpp
+++ b/xfa/fwl/theme/cfwl_widgettp.cpp
@@ -128,8 +128,7 @@
CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
pGraphics->SetStrokeColor(CFGAS_GEColor(0xFF000000));
- static constexpr float kDashPattern[2] = {1, 1};
- pGraphics->SetLineDash(0.0f, kDashPattern);
+ pGraphics->SetLineDash({1, 1});
pGraphics->StrokePath(path, matrix);
}
diff --git a/xfa/fxfa/parser/cxfa_stroke.cpp b/xfa/fxfa/parser/cxfa_stroke.cpp
index 2fb0306..1729830 100644
--- a/xfa/fxfa/parser/cxfa_stroke.cpp
+++ b/xfa/fxfa/parser/cxfa_stroke.cpp
@@ -9,6 +9,7 @@
#include <math.h>
#include <utility>
+#include <vector>
#include "fxjs/xfa/cjx_object.h"
#include "xfa/fgas/graphics/cfgas_gecolor.h"
@@ -25,38 +26,38 @@
XFA_AttributeValue iCapType) {
switch (iStrokeType) {
case XFA_AttributeValue::DashDot: {
- float dashArray[] = {4, 1, 2, 1};
+ std::vector<float> dash_array = {4, 1, 2, 1};
if (iCapType != XFA_AttributeValue::Butt) {
- dashArray[1] = 2;
- dashArray[3] = 2;
+ dash_array[1] = 2;
+ dash_array[3] = 2;
}
- pGraphics->SetLineDash(0, dashArray);
+ pGraphics->SetLineDash(std::move(dash_array));
break;
}
case XFA_AttributeValue::DashDotDot: {
- float dashArray[] = {4, 1, 2, 1, 2, 1};
+ std::vector<float> dash_array = {4, 1, 2, 1, 2, 1};
if (iCapType != XFA_AttributeValue::Butt) {
- dashArray[1] = 2;
- dashArray[3] = 2;
- dashArray[5] = 2;
+ dash_array[1] = 2;
+ dash_array[3] = 2;
+ dash_array[5] = 2;
}
- pGraphics->SetLineDash(0, dashArray);
+ pGraphics->SetLineDash(std::move(dash_array));
break;
}
case XFA_AttributeValue::Dashed: {
- float dashArray[] = {5, 1};
- if (iCapType != XFA_AttributeValue::Butt)
- dashArray[1] = 2;
-
- pGraphics->SetLineDash(0, dashArray);
+ std::vector<float> dash_array = {5, 1};
+ if (iCapType != XFA_AttributeValue::Butt) {
+ dash_array[1] = 2;
+ }
+ pGraphics->SetLineDash(std::move(dash_array));
break;
}
case XFA_AttributeValue::Dotted: {
- float dashArray[] = {2, 1};
- if (iCapType != XFA_AttributeValue::Butt)
- dashArray[1] = 2;
-
- pGraphics->SetLineDash(0, dashArray);
+ std::vector<float> dash_array = {2, 1};
+ if (iCapType != XFA_AttributeValue::Butt) {
+ dash_array[1] = 2;
+ }
+ pGraphics->SetLineDash(std::move(dash_array));
break;
}
default: