aboutsummaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/cxfa_box.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxfa/parser/cxfa_box.cpp')
-rw-r--r--xfa/fxfa/parser/cxfa_box.cpp118
1 files changed, 59 insertions, 59 deletions
diff --git a/xfa/fxfa/parser/cxfa_box.cpp b/xfa/fxfa/parser/cxfa_box.cpp
index 5ba01d366..761c7c813 100644
--- a/xfa/fxfa/parser/cxfa_box.cpp
+++ b/xfa/fxfa/parser/cxfa_box.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,10 +6,18 @@
#include "xfa/fxfa/parser/cxfa_box.h"
+#include <math.h>
+
#include <algorithm>
#include <utility>
#include "fxjs/xfa/cjx_object.h"
+#include "third_party/base/notreached.h"
+#include "third_party/base/numerics/safe_conversions.h"
+#include "xfa/fgas/graphics/cfgas_gegraphics.h"
+#include "xfa/fgas/graphics/cfgas_gepath.h"
+#include "xfa/fgas/graphics/cfgas_gepattern.h"
+#include "xfa/fgas/graphics/cfgas_geshading.h"
#include "xfa/fxfa/parser/cxfa_corner.h"
#include "xfa/fxfa/parser/cxfa_edge.h"
#include "xfa/fxfa/parser/cxfa_fill.h"
@@ -17,10 +25,6 @@
#include "xfa/fxfa/parser/cxfa_measurement.h"
#include "xfa/fxfa/parser/cxfa_node.h"
#include "xfa/fxfa/parser/cxfa_rectangle.h"
-#include "xfa/fxgraphics/cxfa_gepath.h"
-#include "xfa/fxgraphics/cxfa_gepattern.h"
-#include "xfa/fxgraphics/cxfa_geshading.h"
-#include "xfa/fxgraphics/cxfa_graphics.h"
namespace {
@@ -59,12 +63,12 @@ CXFA_Rectangle* ToRectangle(CXFA_Box* box) {
CXFA_Box::CXFA_Box(CXFA_Document* pDoc,
XFA_PacketType ePacket,
- uint32_t validPackets,
+ Mask<XFA_XDPPACKET> validPackets,
XFA_ObjectType oType,
XFA_Element eType,
pdfium::span<const PropertyData> properties,
pdfium::span<const AttributeData> attributes,
- std::unique_ptr<CJX_Object> js_node)
+ CJX_Object* js_node)
: CXFA_Node(pDoc,
ePacket,
validPackets,
@@ -72,7 +76,7 @@ CXFA_Box::CXFA_Box(CXFA_Document* pDoc,
eType,
properties,
attributes,
- std::move(js_node)) {}
+ js_node) {}
CXFA_Box::~CXFA_Box() = default;
@@ -86,15 +90,17 @@ XFA_AttributeValue CXFA_Box::GetPresence() {
.value_or(XFA_AttributeValue::Visible);
}
-int32_t CXFA_Box::CountEdges() {
+size_t CXFA_Box::CountEdges() {
return CountChildren(XFA_Element::Edge, false);
}
-CXFA_Edge* CXFA_Box::GetEdgeIfExists(int32_t nIndex) {
- if (nIndex == 0)
- return JSObject()->GetOrCreateProperty<CXFA_Edge>(nIndex,
- XFA_Element::Edge);
- return JSObject()->GetProperty<CXFA_Edge>(nIndex, XFA_Element::Edge);
+CXFA_Edge* CXFA_Box::GetEdgeIfExists(size_t nIndex) {
+ if (nIndex == 0) {
+ return JSObject()->GetOrCreateProperty<CXFA_Edge>(
+ pdfium::base::checked_cast<int32_t>(nIndex), XFA_Element::Edge);
+ }
+ return JSObject()->GetProperty<CXFA_Edge>(
+ pdfium::base::checked_cast<int32_t>(nIndex), XFA_Element::Edge);
}
std::vector<CXFA_Stroke*> CXFA_Box::GetStrokes() {
@@ -105,11 +111,11 @@ bool CXFA_Box::IsCircular() {
return JSObject()->GetBoolean(XFA_Attribute::Circular);
}
-Optional<int32_t> CXFA_Box::GetStartAngle() {
+absl::optional<int32_t> CXFA_Box::GetStartAngle() {
return JSObject()->TryInteger(XFA_Attribute::StartAngle, false);
}
-Optional<int32_t> CXFA_Box::GetSweepAngle() {
+absl::optional<int32_t> CXFA_Box::GetSweepAngle() {
return JSObject()->TryInteger(XFA_Attribute::SweepAngle, false);
}
@@ -178,7 +184,7 @@ std::vector<CXFA_Stroke*> CXFA_Box::GetStrokesInternal(bool bNull) {
return strokes;
}
-void CXFA_Box::Draw(CXFA_Graphics* pGS,
+void CXFA_Box::Draw(CFGAS_GEGraphics* pGS,
const CFX_RectF& rtWidget,
const CFX_Matrix& matrix,
bool forceRound) {
@@ -206,7 +212,7 @@ void CXFA_Box::Draw(CXFA_Graphics* pGS,
}
void CXFA_Box::DrawFill(const std::vector<CXFA_Stroke*>& strokes,
- CXFA_Graphics* pGS,
+ CFGAS_GEGraphics* pGS,
CFX_RectF rtWidget,
const CFX_Matrix& matrix,
bool forceRound) {
@@ -214,13 +220,12 @@ void CXFA_Box::DrawFill(const std::vector<CXFA_Stroke*>& strokes,
if (!fill || !fill->IsVisible())
return;
- pGS->SaveGraphState();
-
- CXFA_GEPath fillPath;
+ CFGAS_GEPath fillPath;
XFA_Element type = GetElementType();
+ CFGAS_GEGraphics::StateRestorer restorer(pGS);
if (type == XFA_Element::Arc || forceRound) {
CXFA_Edge* edge = GetEdgeIfExists(0);
- float fThickness = std::fmax(0.0, edge ? edge->GetThickness() : 0);
+ float fThickness = fmax(0.0, edge ? edge->GetThickness() : 0);
float fHalf = fThickness / 2;
XFA_AttributeValue iHand = GetHand();
if (iHand == XFA_AttributeValue::Left)
@@ -235,17 +240,14 @@ void CXFA_Box::DrawFill(const std::vector<CXFA_Stroke*>& strokes,
NOTREACHED();
}
fillPath.Close();
-
- fill->Draw(pGS, &fillPath, rtWidget, matrix);
- pGS->RestoreGraphState();
+ fill->Draw(pGS, fillPath, rtWidget, matrix);
}
void CXFA_Box::GetPathArcOrRounded(CFX_RectF rtDraw,
bool forceRound,
- CXFA_GEPath* fillPath) {
- float a, b;
- a = rtDraw.width / 2.0f;
- b = rtDraw.height / 2.0f;
+ CFGAS_GEPath* fillPath) {
+ float a = rtDraw.width / 2.0f;
+ float b = rtDraw.height / 2.0f;
if (IsCircular() || forceRound)
a = b = std::min(a, b);
@@ -254,19 +256,19 @@ void CXFA_Box::GetPathArcOrRounded(CFX_RectF rtDraw,
rtDraw.top = center.y - b;
rtDraw.width = a + a;
rtDraw.height = b + b;
- Optional<int32_t> startAngle = GetStartAngle();
- Optional<int32_t> sweepAngle = GetSweepAngle();
- if (!startAngle && !sweepAngle) {
+ absl::optional<int32_t> startAngle = GetStartAngle();
+ absl::optional<int32_t> sweepAngle = GetSweepAngle();
+ if (!startAngle.has_value() && !sweepAngle.has_value()) {
fillPath->AddEllipse(rtDraw);
return;
}
fillPath->AddArc(rtDraw.TopLeft(), rtDraw.Size(),
- -startAngle.value_or(0) * FX_PI / 180.0f,
- -sweepAngle.value_or(360) * FX_PI / 180.0f);
+ -startAngle.value_or(0) * FXSYS_PI / 180.0f,
+ -sweepAngle.value_or(360) * FXSYS_PI / 180.0f);
}
-void CXFA_Box::StrokeArcOrRounded(CXFA_Graphics* pGS,
+void CXFA_Box::StrokeArcOrRounded(CFGAS_GEGraphics* pGS,
CFX_RectF rtWidget,
const CFX_Matrix& matrix,
bool forceRound) {
@@ -299,18 +301,17 @@ void CXFA_Box::StrokeArcOrRounded(CXFA_Graphics* pGS,
if (fHalf < 0.001f)
return;
- CXFA_GEPath arcPath;
+ CFGAS_GEPath arcPath;
GetPathArcOrRounded(rtWidget, forceRound, &arcPath);
if (edge)
- edge->Stroke(&arcPath, pGS, matrix);
+ edge->Stroke(pGS, arcPath, matrix);
return;
}
- pGS->SaveGraphState();
+ CFGAS_GEGraphics::StateRestorer restorer(pGS);
pGS->SetLineWidth(fHalf);
- float a, b;
- a = rtWidget.width / 2.0f;
- b = rtWidget.height / 2.0f;
+ float a = rtWidget.width / 2.0f;
+ float b = rtWidget.height / 2.0f;
if (forceRound) {
a = std::min(a, b);
b = a;
@@ -322,30 +323,29 @@ void CXFA_Box::StrokeArcOrRounded(CXFA_Graphics* pGS,
rtWidget.width = a + a;
rtWidget.height = b + b;
- CXFA_GEPath arcPath;
- arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), 3.0f * FX_PI / 4.0f,
- FX_PI);
+ CFGAS_GEPath arcPath;
+ arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), 3.0f * FXSYS_PI / 4.0f,
+ FXSYS_PI);
- pGS->SetStrokeColor(CXFA_GEColor(0xFF808080));
- pGS->StrokePath(&arcPath, &matrix);
+ pGS->SetStrokeColor(CFGAS_GEColor(0xFF808080));
+ pGS->StrokePath(arcPath, matrix);
arcPath.Clear();
- arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), -1.0f * FX_PI / 4.0f,
- FX_PI);
+ arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), -1.0f * FXSYS_PI / 4.0f,
+ FXSYS_PI);
- pGS->SetStrokeColor(CXFA_GEColor(0xFFFFFFFF));
- pGS->StrokePath(&arcPath, &matrix);
+ pGS->SetStrokeColor(CFGAS_GEColor(0xFFFFFFFF));
+ pGS->StrokePath(arcPath, matrix);
rtWidget.Deflate(fHalf, fHalf);
arcPath.Clear();
- arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), 3.0f * FX_PI / 4.0f,
- FX_PI);
+ arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), 3.0f * FXSYS_PI / 4.0f,
+ FXSYS_PI);
- pGS->SetStrokeColor(CXFA_GEColor(0xFF404040));
- pGS->StrokePath(&arcPath, &matrix);
+ pGS->SetStrokeColor(CFGAS_GEColor(0xFF404040));
+ pGS->StrokePath(arcPath, matrix);
arcPath.Clear();
- arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), -1.0f * FX_PI / 4.0f,
- FX_PI);
+ arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), -1.0f * FXSYS_PI / 4.0f,
+ FXSYS_PI);
- pGS->SetStrokeColor(CXFA_GEColor(0xFFC0C0C0));
- pGS->StrokePath(&arcPath, &matrix);
- pGS->RestoreGraphState();
+ pGS->SetStrokeColor(CFGAS_GEColor(0xFFC0C0C0));
+ pGS->StrokePath(arcPath, matrix);
}