summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-08-20 19:10:17 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-20 19:10:17 +0000
commit9273e0674ecf87929696ca89cbf16371edabc315 (patch)
tree1b26f0c638a7252e8b1dfc961c6ec09d50fb546b
parentf6144d4ab76e6357bd8d228ddf542ef4fb3fa3b0 (diff)
downloadpdfium-9273e0674ecf87929696ca89cbf16371edabc315.tar.xz
Clean up CXFA_Graphics::SetLineDash().
Fix some nits in CXFA_FFField as well. Change-Id: I6d0d4569322a01192cdd4bf9d98325ff86642abe Reviewed-on: https://pdfium-review.googlesource.com/40651 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
-rw-r--r--xfa/fwl/theme/cfwl_widgettp.cpp4
-rw-r--r--xfa/fxfa/cxfa_fffield.cpp22
-rw-r--r--xfa/fxfa/parser/cxfa_stroke.cpp8
-rw-r--r--xfa/fxgraphics/cxfa_graphics.cpp26
-rw-r--r--xfa/fxgraphics/cxfa_graphics.h2
5 files changed, 26 insertions, 36 deletions
diff --git a/xfa/fwl/theme/cfwl_widgettp.cpp b/xfa/fwl/theme/cfwl_widgettp.cpp
index 0f67b89715..49365ac9ac 100644
--- a/xfa/fwl/theme/cfwl_widgettp.cpp
+++ b/xfa/fwl/theme/cfwl_widgettp.cpp
@@ -143,12 +143,12 @@ void CFWL_WidgetTP::DrawFocus(CXFA_Graphics* pGraphics,
if (!pGraphics || !pRect)
return;
- float DashPattern[2] = {1, 1};
CXFA_GEPath path;
path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height);
pGraphics->SaveGraphState();
pGraphics->SetStrokeColor(CXFA_GEColor(0xFF000000));
- pGraphics->SetLineDash(0.0f, DashPattern, 2);
+ static constexpr float kDashPattern[2] = {1, 1};
+ pGraphics->SetLineDash(0.0f, kDashPattern, FX_ArraySize(kDashPattern));
pGraphics->StrokePath(&path, pMatrix);
pGraphics->RestoreGraphState();
}
diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp
index ff28e574e8..aee5a8a9ac 100644
--- a/xfa/fxfa/cxfa_fffield.cpp
+++ b/xfa/fxfa/cxfa_fffield.cpp
@@ -108,8 +108,8 @@ void CXFA_FFField::DrawFocus(CXFA_Graphics* pGS, CFX_Matrix* pMatrix) {
pGS->SetStrokeColor(CXFA_GEColor(0xFF000000));
- float DashPattern[2] = {1, 1};
- pGS->SetLineDash(0.0f, DashPattern, 2);
+ static constexpr float kDashPattern[2] = {1, 1};
+ pGS->SetLineDash(0.0f, kDashPattern, FX_ArraySize(kDashPattern));
pGS->SetLineWidth(0);
CXFA_GEPath path;
@@ -348,12 +348,10 @@ void CXFA_FFField::SetFWLRect() {
return;
CFX_RectF rtUi = m_rtUI;
- if (rtUi.width < 1.0)
- rtUi.width = 1.0;
+ rtUi.width = std::max(rtUi.width, 1.0f);
if (!GetDoc()->GetXFADoc()->IsInteractive()) {
float fFontSize = m_pNode->GetFontSize();
- if (rtUi.height < fFontSize)
- rtUi.height = fFontSize;
+ rtUi.height = std::max(rtUi.height, fFontSize);
}
m_pNormalWidget->SetWidgetRect(rtUi);
}
@@ -587,10 +585,8 @@ void CXFA_FFField::LayoutCaption() {
if (!pCapTextLayout)
return;
- float fHeight =
- pCapTextLayout->Layout(CFX_SizeF(m_rtCaption.width, m_rtCaption.height));
- if (m_rtCaption.height < fHeight)
- m_rtCaption.height = fHeight;
+ float fHeight = pCapTextLayout->Layout(m_rtCaption.Size());
+ m_rtCaption.height = std::max(m_rtCaption.height, fHeight);
}
void CXFA_FFField::RenderCaption(CXFA_Graphics* pGS, CFX_Matrix* pMatrix) {
@@ -603,7 +599,7 @@ void CXFA_FFField::RenderCaption(CXFA_Graphics* pGS, CFX_Matrix* pMatrix) {
return;
if (!pCapTextLayout->IsLoaded())
- pCapTextLayout->Layout(CFX_SizeF(m_rtCaption.width, m_rtCaption.height));
+ pCapTextLayout->Layout(m_rtCaption.Size());
CFX_RectF rtClip = m_rtCaption;
rtClip.Intersect(GetRectWithoutRotate());
@@ -675,9 +671,7 @@ int32_t CXFA_FFField::CalculateNode(CXFA_Node* pNode) {
case XFA_AttributeEnum::Warning: {
if (version <= XFA_VERSION_204) {
CXFA_Script* script = calc->GetScriptIfExists();
- if (!script)
- return 1;
- if (script->GetExpression().IsEmpty())
+ if (!script || script->GetExpression().IsEmpty())
return 1;
}
diff --git a/xfa/fxfa/parser/cxfa_stroke.cpp b/xfa/fxfa/parser/cxfa_stroke.cpp
index 9d5916a8a3..a19dd3ce3b 100644
--- a/xfa/fxfa/parser/cxfa_stroke.cpp
+++ b/xfa/fxfa/parser/cxfa_stroke.cpp
@@ -26,7 +26,7 @@ void XFA_StrokeTypeSetLineDash(CXFA_Graphics* pGraphics,
dashArray[1] = 2;
dashArray[3] = 2;
}
- pGraphics->SetLineDash(0, dashArray, 4);
+ pGraphics->SetLineDash(0, dashArray, FX_ArraySize(dashArray));
break;
}
case XFA_AttributeEnum::DashDotDot: {
@@ -36,7 +36,7 @@ void XFA_StrokeTypeSetLineDash(CXFA_Graphics* pGraphics,
dashArray[3] = 2;
dashArray[5] = 2;
}
- pGraphics->SetLineDash(0, dashArray, 6);
+ pGraphics->SetLineDash(0, dashArray, FX_ArraySize(dashArray));
break;
}
case XFA_AttributeEnum::Dashed: {
@@ -44,7 +44,7 @@ void XFA_StrokeTypeSetLineDash(CXFA_Graphics* pGraphics,
if (iCapType != XFA_AttributeEnum::Butt)
dashArray[1] = 2;
- pGraphics->SetLineDash(0, dashArray, 2);
+ pGraphics->SetLineDash(0, dashArray, FX_ArraySize(dashArray));
break;
}
case XFA_AttributeEnum::Dotted: {
@@ -52,7 +52,7 @@ void XFA_StrokeTypeSetLineDash(CXFA_Graphics* pGraphics,
if (iCapType != XFA_AttributeEnum::Butt)
dashArray[1] = 2;
- pGraphics->SetLineDash(0, dashArray, 2);
+ pGraphics->SetLineDash(0, dashArray, FX_ArraySize(dashArray));
break;
}
default:
diff --git a/xfa/fxgraphics/cxfa_graphics.cpp b/xfa/fxgraphics/cxfa_graphics.cpp
index ae1e04acca..47e4b6b98f 100644
--- a/xfa/fxgraphics/cxfa_graphics.cpp
+++ b/xfa/fxgraphics/cxfa_graphics.cpp
@@ -135,23 +135,19 @@ void CXFA_Graphics::SetLineCap(CFX_GraphStateData::LineCap lineCap) {
}
void CXFA_Graphics::SetLineDash(float dashPhase,
- float* dashArray,
- int32_t dashCount) {
- if (dashCount > 0 && !dashArray)
+ const float* dashArray,
+ size_t dashCount) {
+ ASSERT(dashArray);
+ ASSERT(dashCount);
+
+ if (m_type != FX_CONTEXT_Device || !m_renderDevice)
return;
- dashCount = dashCount < 0 ? 0 : dashCount;
- if (m_type == FX_CONTEXT_Device && m_renderDevice) {
- float scale = 1.0;
- if (m_info.isActOnDash) {
- scale = m_info.graphState.m_LineWidth;
- }
- m_info.graphState.m_DashPhase = dashPhase;
- m_info.graphState.SetDashCount(dashCount);
- for (int32_t i = 0; i < dashCount; i++) {
- m_info.graphState.m_DashArray[i] = dashArray[i] * scale;
- }
- }
+ float scale = m_info.isActOnDash ? m_info.graphState.m_LineWidth : 1.0;
+ m_info.graphState.m_DashPhase = dashPhase;
+ m_info.graphState.SetDashCount(dashCount);
+ for (size_t i = 0; i < dashCount; i++)
+ m_info.graphState.m_DashArray[i] = dashArray[i] * scale;
}
void CXFA_Graphics::SetSolidLineDash() {
diff --git a/xfa/fxgraphics/cxfa_graphics.h b/xfa/fxgraphics/cxfa_graphics.h
index 886bc45532..3eba53123e 100644
--- a/xfa/fxgraphics/cxfa_graphics.h
+++ b/xfa/fxgraphics/cxfa_graphics.h
@@ -45,7 +45,7 @@ class CXFA_Graphics {
CFX_RenderDevice* GetRenderDevice();
void SetLineCap(CFX_GraphStateData::LineCap lineCap);
- void SetLineDash(float dashPhase, float* dashArray, int32_t dashCount);
+ void SetLineDash(float dashPhase, const float* dashArray, size_t dashCount);
void SetSolidLineDash();
void SetLineWidth(float lineWidth);
void EnableActOnDash();