From 574015e0ad53c592fe8a923390b31edeb30c41fe Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 16 Aug 2017 15:09:00 -0700 Subject: Tidy CXFA_Color class and argument passing. Remove friendship. De-virtualize. Nest enum inside class. Make copy-assignable and pass by const ref. Make pack better on 64-bits. Change-Id: I1ae3b6d03756fa5780e9023795db6648e8b8299a Reviewed-on: https://pdfium-review.googlesource.com/11290 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- xfa/fxfa/cxfa_fffield.cpp | 7 +++--- xfa/fxfa/cxfa_ffline.cpp | 3 +-- xfa/fxfa/cxfa_ffpushbutton.cpp | 7 ++---- xfa/fxfa/cxfa_ffwidget.cpp | 54 ++++++++++++++++++++---------------------- 4 files changed, 32 insertions(+), 39 deletions(-) (limited to 'xfa/fxfa') diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp index e009ed6caa..c1c2c11d6f 100644 --- a/xfa/fxfa/cxfa_fffield.cpp +++ b/xfa/fxfa/cxfa_fffield.cpp @@ -92,8 +92,8 @@ void CXFA_FFField::DrawHighlight(CXFA_Graphics* pGS, } CXFA_FFDoc* pDoc = GetDoc(); - CXFA_Color crHighlight(pDoc->GetDocEnvironment()->GetHighlightColor(pDoc)); - pGS->SetFillColor(&crHighlight); + pGS->SetFillColor( + CXFA_Color(pDoc->GetDocEnvironment()->GetHighlightColor(pDoc))); CXFA_Path path; if (bEllipse) path.AddEllipse(m_rtUI); @@ -107,8 +107,7 @@ void CXFA_FFField::DrawFocus(CXFA_Graphics* pGS, CFX_Matrix* pMatrix) { if (!(m_dwStatus & XFA_WidgetStatus_Focused)) return; - CXFA_Color cr(0xFF000000); - pGS->SetStrokeColor(&cr); + pGS->SetStrokeColor(CXFA_Color(0xFF000000)); float DashPattern[2] = {1, 1}; pGS->SetLineDash(0.0f, DashPattern, 2); diff --git a/xfa/fxfa/cxfa_ffline.cpp b/xfa/fxfa/cxfa_ffline.cpp index e371034d79..130ce9b28b 100644 --- a/xfa/fxfa/cxfa_ffline.cpp +++ b/xfa/fxfa/cxfa_ffline.cpp @@ -88,11 +88,10 @@ void CXFA_FFLine::RenderWidget(CXFA_Graphics* pGS, else linePath.AddLine(rtLine.TopLeft(), rtLine.BottomRight()); - CXFA_Color color(lineColor); pGS->SaveGraphState(); pGS->SetLineWidth(fLineWidth, true); XFA_StrokeTypeSetLineDash(pGS, iStrokeType, iCap); - pGS->SetStrokeColor(&color); + pGS->SetStrokeColor(CXFA_Color(lineColor)); pGS->SetLineCap(XFA_LineCapToFXGE(iCap)); pGS->StrokePath(&linePath, &mtRotate); pGS->RestoreGraphState(); diff --git a/xfa/fxfa/cxfa_ffpushbutton.cpp b/xfa/fxfa/cxfa_ffpushbutton.cpp index 17c1b9f8c8..91b6f3ff27 100644 --- a/xfa/fxfa/cxfa_ffpushbutton.cpp +++ b/xfa/fxfa/cxfa_ffpushbutton.cpp @@ -212,11 +212,9 @@ void CXFA_FFPushButton::OnDrawWidget(CXFA_Graphics* pGraphics, CFX_RectF rtFill(0, 0, m_pNormalWidget->GetWidgetRect().Size()); float fLineWith = GetLineWidth(); rtFill.Deflate(fLineWith, fLineWith); - CXFA_Color cr(FXARGB_MAKE(128, 128, 255, 255)); - pGraphics->SetFillColor(&cr); - CXFA_Path path; path.AddRectangle(rtFill.left, rtFill.top, rtFill.width, rtFill.height); + pGraphics->SetFillColor(CXFA_Color(FXARGB_MAKE(128, 128, 255, 255))); pGraphics->FillPath(&path, FXFILL_WINDING, (CFX_Matrix*)pMatrix); } return; @@ -226,8 +224,7 @@ void CXFA_FFPushButton::OnDrawWidget(CXFA_Graphics* pGraphics, if ((m_pNormalWidget->GetStates() & FWL_STATE_PSB_Pressed) && (m_pNormalWidget->GetStates() & FWL_STATE_PSB_Hovered)) { float fLineWidth = GetLineWidth(); - CXFA_Color cr(FXARGB_MAKE(255, 128, 255, 255)); - pGraphics->SetStrokeColor(&cr); + pGraphics->SetStrokeColor(CXFA_Color(FXARGB_MAKE(255, 128, 255, 255))); pGraphics->SetLineWidth(fLineWidth); CXFA_Path path; diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp index 8dc767e5ee..c0eb0a3a0d 100644 --- a/xfa/fxfa/cxfa_ffwidget.cpp +++ b/xfa/fxfa/cxfa_ffwidget.cpp @@ -1541,10 +1541,10 @@ static void XFA_BOX_Fill_Radial(CXFA_Box box, rtFill.Height() * rtFill.Height()) / 2, true, true, crStart, crEnd); - CXFA_Color cr(&shading); - pGS->SetFillColor(&cr); + pGS->SetFillColor(CXFA_Color(&shading)); pGS->FillPath(&fillPath, FXFILL_WINDING, pMatrix); } + static void XFA_BOX_Fill_Pattern(CXFA_Box box, CXFA_Graphics* pGS, CXFA_Path& fillPath, @@ -1576,10 +1576,10 @@ static void XFA_BOX_Fill_Pattern(CXFA_Box box, } CXFA_Pattern pattern(iHatch, crEnd, crStart); - CXFA_Color cr(&pattern, 0x0); - pGS->SetFillColor(&cr); + pGS->SetFillColor(CXFA_Color(&pattern, 0x0)); pGS->FillPath(&fillPath, FXFILL_WINDING, pMatrix); } + static void XFA_BOX_Fill_Linear(CXFA_Box box, CXFA_Graphics* pGS, CXFA_Path& fillPath, @@ -1612,10 +1612,10 @@ static void XFA_BOX_Fill_Linear(CXFA_Box box, break; } CXFA_Shading shading(ptStart, ptEnd, false, false, crStart, crEnd); - CXFA_Color cr(&shading); - pGS->SetFillColor(&cr); + pGS->SetFillColor(CXFA_Color(&shading)); pGS->FillPath(&fillPath, FXFILL_WINDING, pMatrix); } + static void XFA_BOX_Fill(CXFA_Box box, const std::vector& strokes, CXFA_Graphics* pGS, @@ -1655,8 +1655,7 @@ static void XFA_BOX_Fill(CXFA_Box box, } else { cr = fill.GetColor(); } - CXFA_Color fillColor(cr); - pGS->SetFillColor(&fillColor); + pGS->SetFillColor(CXFA_Color(cr)); pGS->FillPath(&fillPath, FXFILL_WINDING, pMatrix); } break; } @@ -1681,11 +1680,11 @@ static void XFA_BOX_StrokePath(CXFA_Stroke stroke, pGS->SetLineCap(CFX_GraphStateData::LineCapButt); XFA_StrokeTypeSetLineDash(pGS, stroke.GetStrokeType(), XFA_ATTRIBUTEENUM_Butt); - CXFA_Color fxColor(stroke.GetColor()); - pGS->SetStrokeColor(&fxColor); + pGS->SetStrokeColor(CXFA_Color(stroke.GetColor())); pGS->StrokePath(pPath, pMatrix); pGS->RestoreGraphState(); } + static void XFA_BOX_StrokeArc(CXFA_Box box, CXFA_Graphics* pGS, CFX_RectF rtWidget, @@ -1748,41 +1747,36 @@ static void XFA_BOX_StrokeArc(CXFA_Box box, arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), 3.0f * FX_PI / 4.0f, FX_PI); - CXFA_Color cr(0xFF808080); - pGS->SetStrokeColor(&cr); + pGS->SetStrokeColor(CXFA_Color(0xFF808080)); pGS->StrokePath(&arcPath, pMatrix); arcPath.Clear(); arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), -1.0f * FX_PI / 4.0f, FX_PI); - cr.Set(0xFFFFFFFF); - pGS->SetStrokeColor(&cr); + pGS->SetStrokeColor(CXFA_Color(0xFFFFFFFF)); pGS->StrokePath(&arcPath, pMatrix); rtWidget.Deflate(fHalf, fHalf); arcPath.Clear(); arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), 3.0f * FX_PI / 4.0f, FX_PI); - cr.Set(0xFF404040); - pGS->SetStrokeColor(&cr); + pGS->SetStrokeColor(CXFA_Color(0xFF404040)); pGS->StrokePath(&arcPath, pMatrix); arcPath.Clear(); arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), -1.0f * FX_PI / 4.0f, FX_PI); - cr.Set(0xFFC0C0C0); - pGS->SetStrokeColor(&cr); + pGS->SetStrokeColor(CXFA_Color(0xFFC0C0C0)); pGS->StrokePath(&arcPath, pMatrix); pGS->RestoreGraphState(); } + static void XFA_Draw3DRect(CXFA_Graphics* pGraphic, const CFX_RectF& rt, float fLineWidth, CFX_Matrix* pMatrix, FX_ARGB argbTopLeft, FX_ARGB argbBottomRight) { - CXFA_Color crLT(argbTopLeft); - pGraphic->SetFillColor(&crLT); float fBottom = rt.bottom(); float fRight = rt.right(); CXFA_Path pathLT; @@ -1793,11 +1787,9 @@ static void XFA_Draw3DRect(CXFA_Graphics* pGraphic, pathLT.LineTo(CFX_PointF(rt.left + fLineWidth, rt.top + fLineWidth)); pathLT.LineTo(CFX_PointF(rt.left + fLineWidth, fBottom - fLineWidth)); pathLT.LineTo(CFX_PointF(rt.left, fBottom)); + pGraphic->SetFillColor(CXFA_Color(argbTopLeft)); pGraphic->FillPath(&pathLT, FXFILL_WINDING, pMatrix); - CXFA_Color crRB(argbBottomRight); - pGraphic->SetFillColor(&crRB); - CXFA_Path pathRB; pathRB.MoveTo(CFX_PointF(fRight, rt.top)); pathRB.LineTo(CFX_PointF(fRight, fBottom)); @@ -1806,8 +1798,10 @@ static void XFA_Draw3DRect(CXFA_Graphics* pGraphic, pathRB.LineTo(CFX_PointF(fRight - fLineWidth, fBottom - fLineWidth)); pathRB.LineTo(CFX_PointF(fRight - fLineWidth, rt.top + fLineWidth)); pathRB.LineTo(CFX_PointF(fRight, rt.top)); + pGraphic->SetFillColor(CXFA_Color(argbBottomRight)); pGraphic->FillPath(&pathRB, FXFILL_WINDING, pMatrix); } + static void XFA_BOX_Stroke_3DRect_Lowered(CXFA_Graphics* pGS, CFX_RectF rt, float fThickness, @@ -1815,14 +1809,15 @@ static void XFA_BOX_Stroke_3DRect_Lowered(CXFA_Graphics* pGS, float fHalfWidth = fThickness / 2.0f; CFX_RectF rtInner(rt); rtInner.Deflate(fHalfWidth, fHalfWidth); - CXFA_Color cr(0xFF000000); - pGS->SetFillColor(&cr); + CXFA_Path path; path.AddRectangle(rt.left, rt.top, rt.width, rt.height); path.AddRectangle(rtInner.left, rtInner.top, rtInner.width, rtInner.height); + pGS->SetFillColor(CXFA_Color(0xFF000000)); pGS->FillPath(&path, FXFILL_ALTERNATE, pMatrix); XFA_Draw3DRect(pGS, rtInner, fHalfWidth, pMatrix, 0xFF808080, 0xFFC0C0C0); } + static void XFA_BOX_Stroke_3DRect_Raised(CXFA_Graphics* pGS, CFX_RectF rt, float fThickness, @@ -1830,24 +1825,27 @@ static void XFA_BOX_Stroke_3DRect_Raised(CXFA_Graphics* pGS, float fHalfWidth = fThickness / 2.0f; CFX_RectF rtInner(rt); rtInner.Deflate(fHalfWidth, fHalfWidth); - CXFA_Color cr(0xFF000000); - pGS->SetFillColor(&cr); + CXFA_Path path; path.AddRectangle(rt.left, rt.top, rt.width, rt.height); path.AddRectangle(rtInner.left, rtInner.top, rtInner.width, rtInner.height); + pGS->SetFillColor(CXFA_Color(0xFF000000)); pGS->FillPath(&path, FXFILL_ALTERNATE, pMatrix); XFA_Draw3DRect(pGS, rtInner, fHalfWidth, pMatrix, 0xFFFFFFFF, 0xFF808080); } + static void XFA_BOX_Stroke_3DRect_Etched(CXFA_Graphics* pGS, CFX_RectF rt, float fThickness, CFX_Matrix* pMatrix) { - float fHalfWidth = fThickness / 2.0f; XFA_Draw3DRect(pGS, rt, fThickness, pMatrix, 0xFF808080, 0xFFFFFFFF); + + float fHalfWidth = fThickness / 2.0f; CFX_RectF rtInner(rt); rtInner.Deflate(fHalfWidth, fHalfWidth); XFA_Draw3DRect(pGS, rtInner, fHalfWidth, pMatrix, 0xFFFFFFFF, 0xFF808080); } + static void XFA_BOX_Stroke_3DRect_Embossed(CXFA_Graphics* pGS, CFX_RectF rt, float fThickness, -- cgit v1.2.3