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/fwl/cfwl_edit.cpp | 3 +- xfa/fwl/theme/cfwl_carettp.cpp | 5 +- xfa/fwl/theme/cfwl_checkboxtp.cpp | 20 +++---- xfa/fwl/theme/cfwl_comboboxtp.cpp | 6 +-- xfa/fwl/theme/cfwl_edittp.cpp | 21 +++----- xfa/fwl/theme/cfwl_listboxtp.cpp | 3 +- xfa/fwl/theme/cfwl_monthcalendartp.cpp | 66 ++++++++++------------- xfa/fwl/theme/cfwl_pushbuttontp.cpp | 6 +-- xfa/fwl/theme/cfwl_scrollbartp.cpp | 29 +++++------ xfa/fwl/theme/cfwl_widgettp.cpp | 42 ++++++--------- xfa/fxfa/cxfa_fffield.cpp | 7 ++- xfa/fxfa/cxfa_ffline.cpp | 3 +- xfa/fxfa/cxfa_ffpushbutton.cpp | 7 +-- xfa/fxfa/cxfa_ffwidget.cpp | 54 ++++++++++--------- xfa/fxgraphics/cxfa_color.cpp | 60 ++++++++++----------- xfa/fxgraphics/cxfa_color.h | 41 +++++++++------ xfa/fxgraphics/cxfa_graphics.cpp | 95 ++++++++++++++-------------------- xfa/fxgraphics/cxfa_graphics.h | 10 ++-- 18 files changed, 208 insertions(+), 270 deletions(-) (limited to 'xfa') diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp index cf0df76583..18fbd33b39 100644 --- a/xfa/fwl/cfwl_edit.cpp +++ b/xfa/fwl/cfwl_edit.cpp @@ -190,7 +190,6 @@ void CFWL_Edit::DrawSpellCheck(CXFA_Graphics* pGraphics, if (pMatrix) pGraphics->ConcatMatrix(const_cast(pMatrix)); - CXFA_Color crLine(0xFFFF0000); CFWL_EventCheckWord checkWordEvent(this); CFX_ByteString sLatinWord; CXFA_Path pathSpell; @@ -233,7 +232,7 @@ void CFWL_Edit::DrawSpellCheck(CXFA_Graphics* pGraphics, mt.Concat(*pMatrix); } pGraphics->SetClipRect(rtClip); - pGraphics->SetStrokeColor(&crLine); + pGraphics->SetStrokeColor(CXFA_Color(0xFFFF0000)); pGraphics->SetLineWidth(0); pGraphics->StrokePath(&pathSpell, nullptr); } diff --git a/xfa/fwl/theme/cfwl_carettp.cpp b/xfa/fwl/theme/cfwl_carettp.cpp index 64eef9ffc9..37dfad5146 100644 --- a/xfa/fwl/theme/cfwl_carettp.cpp +++ b/xfa/fwl/theme/cfwl_carettp.cpp @@ -43,10 +43,9 @@ void CFWL_CaretTP::DrawCaretBK(CXFA_Graphics* pGraphics, CFX_RectF rect = *pRect; path.AddRectangle(rect.left, rect.top, rect.width, rect.height); if (crFill) { - pGraphics->SetFillColor(crFill); + pGraphics->SetFillColor(*crFill); } else { - CXFA_Color crFilltemp(ArgbEncode(255, 0, 0, 0)); - pGraphics->SetFillColor(&crFilltemp); + pGraphics->SetFillColor(CXFA_Color(ArgbEncode(255, 0, 0, 0))); } pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); } diff --git a/xfa/fwl/theme/cfwl_checkboxtp.cpp b/xfa/fwl/theme/cfwl_checkboxtp.cpp index 334c1912a3..e783098347 100644 --- a/xfa/fwl/theme/cfwl_checkboxtp.cpp +++ b/xfa/fwl/theme/cfwl_checkboxtp.cpp @@ -64,12 +64,10 @@ void CFWL_CheckBoxTP::DrawSignCheck(CXFA_Graphics* pGraphics, InitCheckPath(pRtSign->width); CFX_Matrix mt; - mt.SetIdentity(); mt.Translate(pRtSign->left, pRtSign->top); mt.Concat(*pMatrix); - CXFA_Color crFill(argbFill); pGraphics->SaveGraphState(); - pGraphics->SetFillColor(&crFill); + pGraphics->SetFillColor(CXFA_Color(argbFill)); pGraphics->FillPath(m_pCheckPath.get(), FXFILL_WINDING, &mt); pGraphics->RestoreGraphState(); } @@ -80,9 +78,8 @@ void CFWL_CheckBoxTP::DrawSignCircle(CXFA_Graphics* pGraphics, CFX_Matrix* pMatrix) { CXFA_Path path; path.AddEllipse(*pRtSign); - CXFA_Color crFill(argbFill); pGraphics->SaveGraphState(); - pGraphics->SetFillColor(&crFill); + pGraphics->SetFillColor(CXFA_Color(argbFill)); pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); pGraphics->RestoreGraphState(); } @@ -98,9 +95,8 @@ void CFWL_CheckBoxTP::DrawSignCross(CXFA_Graphics* pGraphics, path.AddLine(CFX_PointF(pRtSign->left, fBottom), CFX_PointF(fRight, pRtSign->top)); - CXFA_Color crFill(argbFill); pGraphics->SaveGraphState(); - pGraphics->SetStrokeColor(&crFill); + pGraphics->SetStrokeColor(CXFA_Color(argbFill)); pGraphics->SetLineWidth(1.0f); pGraphics->StrokePath(&path, pMatrix); pGraphics->RestoreGraphState(); @@ -120,9 +116,8 @@ void CFWL_CheckBoxTP::DrawSignDiamond(CXFA_Graphics* pGraphics, path.LineTo(CFX_PointF(pRtSign->right(), pRtSign->top + fHeight / 2)); path.LineTo(CFX_PointF(pRtSign->left + fWidth / 2, pRtSign->top)); - CXFA_Color crFill(argbFill); pGraphics->SaveGraphState(); - pGraphics->SetFillColor(&crFill); + pGraphics->SetFillColor(CXFA_Color(argbFill)); pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); pGraphics->RestoreGraphState(); } @@ -134,9 +129,8 @@ void CFWL_CheckBoxTP::DrawSignSquare(CXFA_Graphics* pGraphics, CXFA_Path path; path.AddRectangle(pRtSign->left, pRtSign->top, pRtSign->width, pRtSign->height); - CXFA_Color crFill(argbFill); pGraphics->SaveGraphState(); - pGraphics->SetFillColor(&crFill); + pGraphics->SetFillColor(CXFA_Color(argbFill)); pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); pGraphics->RestoreGraphState(); } @@ -170,10 +164,8 @@ void CFWL_CheckBoxTP::DrawSignStar(CXFA_Graphics* pGraphics, path.LineTo(points[nNext]); } - - CXFA_Color crFill(argbFill); pGraphics->SaveGraphState(); - pGraphics->SetFillColor(&crFill); + pGraphics->SetFillColor(CXFA_Color(argbFill)); pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); pGraphics->RestoreGraphState(); } diff --git a/xfa/fwl/theme/cfwl_comboboxtp.cpp b/xfa/fwl/theme/cfwl_comboboxtp.cpp index d8852ffe52..86888c0487 100644 --- a/xfa/fwl/theme/cfwl_comboboxtp.cpp +++ b/xfa/fwl/theme/cfwl_comboboxtp.cpp @@ -42,8 +42,7 @@ void CFWL_ComboBoxTP::DrawBackground(CFWL_ThemeBackground* pParams) { argb_color = 0xFFFFFFFF; } pParams->m_pGraphics->SaveGraphState(); - CXFA_Color cr(argb_color); - pParams->m_pGraphics->SetFillColor(&cr); + pParams->m_pGraphics->SetFillColor(CXFA_Color(argb_color)); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, &pParams->m_matrix); pParams->m_pGraphics->RestoreGraphState(); break; @@ -67,8 +66,7 @@ void CFWL_ComboBoxTP::DrawStrethHandler(CFWL_ThemeBackground* pParams, CXFA_Path path; path.AddRectangle(pParams->m_rtPart.left, pParams->m_rtPart.top, pParams->m_rtPart.width - 1, pParams->m_rtPart.height); - CXFA_Color cr(ArgbEncode(0xff, 0xff, 0, 0)); - pParams->m_pGraphics->SetFillColor(&cr); + pParams->m_pGraphics->SetFillColor(CXFA_Color(ArgbEncode(0xff, 0xff, 0, 0))); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, &pParams->m_matrix); } diff --git a/xfa/fwl/theme/cfwl_edittp.cpp b/xfa/fwl/theme/cfwl_edittp.cpp index 19486fef16..0300deaba4 100644 --- a/xfa/fwl/theme/cfwl_edittp.cpp +++ b/xfa/fwl/theme/cfwl_edittp.cpp @@ -30,8 +30,7 @@ void CFWL_EditTP::DrawBackground(CFWL_ThemeBackground* pParams) { fWidth = edge.GetThickness(); } } - CXFA_Color crLine(cr); - pParams->m_pGraphics->SetStrokeColor(&crLine); + pParams->m_pGraphics->SetStrokeColor(CXFA_Color(cr)); pParams->m_pGraphics->SetLineWidth(fWidth); pParams->m_pGraphics->StrokePath(pParams->m_pPath, &pParams->m_matrix); return; @@ -46,8 +45,7 @@ void CFWL_EditTP::DrawBackground(CFWL_ThemeBackground* pParams) { if (pParams->m_pPath) { CXFA_Graphics* pGraphics = pParams->m_pGraphics; pGraphics->SaveGraphState(); - CXFA_Color crSelected(FWLTHEME_COLOR_BKSelected); - pGraphics->SetFillColor(&crSelected); + pGraphics->SetFillColor(CXFA_Color(FWLTHEME_COLOR_BKSelected)); pGraphics->FillPath(pParams->m_pPath, FXFILL_WINDING, &pParams->m_matrix); pGraphics->RestoreGraphState(); @@ -58,14 +56,14 @@ void CFWL_EditTP::DrawBackground(CFWL_ThemeBackground* pParams) { CXFA_Color cr(FWLTHEME_COLOR_Background); if (!pParams->m_bStaticBackground) { if (pParams->m_dwStates & CFWL_PartState_Disabled) - cr.Set(FWLTHEME_COLOR_EDGERB1); + cr = CXFA_Color(FWLTHEME_COLOR_EDGERB1); else if (pParams->m_dwStates & CFWL_PartState_ReadOnly) - cr.Set(ArgbEncode(255, 236, 233, 216)); + cr = CXFA_Color(ArgbEncode(255, 236, 233, 216)); else - cr.Set(0xFFFFFFFF); + cr = CXFA_Color(0xFFFFFFFF); } pParams->m_pGraphics->SaveGraphState(); - pParams->m_pGraphics->SetFillColor(&cr); + pParams->m_pGraphics->SetFillColor(cr); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, &pParams->m_matrix); pParams->m_pGraphics->RestoreGraphState(); @@ -73,11 +71,8 @@ void CFWL_EditTP::DrawBackground(CFWL_ThemeBackground* pParams) { break; } case CFWL_Part::CombTextLine: { - FX_ARGB cr = 0xFF000000; - float fWidth = 1.0f; - CXFA_Color crLine(cr); - pParams->m_pGraphics->SetStrokeColor(&crLine); - pParams->m_pGraphics->SetLineWidth(fWidth); + pParams->m_pGraphics->SetStrokeColor(CXFA_Color(0xFF000000)); + pParams->m_pGraphics->SetLineWidth(1.0f); pParams->m_pGraphics->StrokePath(pParams->m_pPath, &pParams->m_matrix); break; } diff --git a/xfa/fwl/theme/cfwl_listboxtp.cpp b/xfa/fwl/theme/cfwl_listboxtp.cpp index caa764f953..8ea90198a3 100644 --- a/xfa/fwl/theme/cfwl_listboxtp.cpp +++ b/xfa/fwl/theme/cfwl_listboxtp.cpp @@ -66,8 +66,7 @@ void CFWL_ListBoxTP::DrawListBoxItem(CXFA_Graphics* pGraphics, CFX_Matrix* pMatrix) { if (dwStates & CFWL_PartState_Selected) { pGraphics->SaveGraphState(); - CXFA_Color crFill(FWLTHEME_COLOR_BKSelected); - pGraphics->SetFillColor(&crFill); + pGraphics->SetFillColor(CXFA_Color(FWLTHEME_COLOR_BKSelected)); CFX_RectF rt(*prtItem); CXFA_Path path; #if (_FX_OS_ == _FX_MACOSX_) diff --git a/xfa/fwl/theme/cfwl_monthcalendartp.cpp b/xfa/fwl/theme/cfwl_monthcalendartp.cpp index 8b73bac668..975ca013f7 100644 --- a/xfa/fwl/theme/cfwl_monthcalendartp.cpp +++ b/xfa/fwl/theme/cfwl_monthcalendartp.cpp @@ -108,9 +108,7 @@ void CFWL_MonthCalendarTP::DrawTotalBK(CFWL_ThemeBackground* pParams, CFX_RectF rtTotal(pParams->m_rtPart); path.AddRectangle(rtTotal.left, rtTotal.top, rtTotal.width, rtTotal.height); pParams->m_pGraphics->SaveGraphState(); - - CXFA_Color clrBK(m_pThemeData->clrBK); - pParams->m_pGraphics->SetFillColor(&clrBK); + pParams->m_pGraphics->SetFillColor(CXFA_Color(m_pThemeData->clrBK)); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); pParams->m_pGraphics->RestoreGraphState(); } @@ -121,9 +119,7 @@ void CFWL_MonthCalendarTP::DrawHeadBk(CFWL_ThemeBackground* pParams, CFX_RectF rtHead = pParams->m_rtPart; path.AddRectangle(rtHead.left, rtHead.top, rtHead.width, rtHead.height); pParams->m_pGraphics->SaveGraphState(); - - CXFA_Color clrHeadBK(m_pThemeData->clrBK); - pParams->m_pGraphics->SetFillColor(&clrHeadBK); + pParams->m_pGraphics->SetFillColor(CXFA_Color(m_pThemeData->clrBK)); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); pParams->m_pGraphics->RestoreGraphState(); } @@ -134,17 +130,16 @@ void CFWL_MonthCalendarTP::DrawLButton(CFWL_ThemeBackground* pParams, CFX_RectF rtLBtn = pParams->m_rtPart; path.AddRectangle(rtLBtn.left, rtLBtn.top, rtLBtn.width, rtLBtn.height); pParams->m_pGraphics->SaveGraphState(); - - CXFA_Color clrLBtnEdge(ArgbEncode(0xff, 205, 219, 243)); - pParams->m_pGraphics->SetStrokeColor(&clrLBtnEdge); + pParams->m_pGraphics->SetStrokeColor( + CXFA_Color(ArgbEncode(0xff, 205, 219, 243))); pParams->m_pGraphics->StrokePath(&path, pMatrix); if (pParams->m_dwStates & CFWL_PartState_Pressed) { - CXFA_Color clrLBtnFill(ArgbEncode(0xff, 174, 198, 242)); - pParams->m_pGraphics->SetFillColor(&clrLBtnFill); + pParams->m_pGraphics->SetFillColor( + CXFA_Color(ArgbEncode(0xff, 174, 198, 242))); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); } else { - CXFA_Color clrLBtnFill(ArgbEncode(0xff, 227, 235, 249)); - pParams->m_pGraphics->SetFillColor(&clrLBtnFill); + pParams->m_pGraphics->SetFillColor( + CXFA_Color(ArgbEncode(0xff, 227, 235, 249))); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); } @@ -156,8 +151,8 @@ void CFWL_MonthCalendarTP::DrawLButton(CFWL_ThemeBackground* pParams, path.LineTo(CFX_PointF(rtLBtn.left + rtLBtn.Width() / 3 * 2, rtLBtn.bottom() - rtLBtn.height / 4)); - CXFA_Color clrFlag(ArgbEncode(0xff, 50, 104, 205)); - pParams->m_pGraphics->SetStrokeColor(&clrFlag); + pParams->m_pGraphics->SetStrokeColor( + CXFA_Color(ArgbEncode(0xff, 50, 104, 205))); pParams->m_pGraphics->StrokePath(&path, pMatrix); pParams->m_pGraphics->RestoreGraphState(); } @@ -168,17 +163,16 @@ void CFWL_MonthCalendarTP::DrawRButton(CFWL_ThemeBackground* pParams, CFX_RectF rtRBtn = pParams->m_rtPart; path.AddRectangle(rtRBtn.left, rtRBtn.top, rtRBtn.width, rtRBtn.height); pParams->m_pGraphics->SaveGraphState(); - - CXFA_Color clrRBtnEdge(ArgbEncode(0xff, 205, 219, 243)); - pParams->m_pGraphics->SetStrokeColor(&clrRBtnEdge); + pParams->m_pGraphics->SetStrokeColor( + CXFA_Color(ArgbEncode(0xff, 205, 219, 243))); pParams->m_pGraphics->StrokePath(&path, pMatrix); if (pParams->m_dwStates & CFWL_PartState_Pressed) { - CXFA_Color clrRBtnFill(ArgbEncode(0xff, 174, 198, 242)); - pParams->m_pGraphics->SetFillColor(&clrRBtnFill); + pParams->m_pGraphics->SetFillColor( + CXFA_Color(ArgbEncode(0xff, 174, 198, 242))); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); } else { - CXFA_Color clrRBtnFill(ArgbEncode(0xff, 227, 235, 249)); - pParams->m_pGraphics->SetFillColor(&clrRBtnFill); + pParams->m_pGraphics->SetFillColor( + CXFA_Color(ArgbEncode(0xff, 227, 235, 249))); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); } @@ -190,8 +184,8 @@ void CFWL_MonthCalendarTP::DrawRButton(CFWL_ThemeBackground* pParams, path.LineTo(CFX_PointF(rtRBtn.left + rtRBtn.Width() / 3, rtRBtn.bottom() - rtRBtn.height / 4)); - CXFA_Color clrFlag(ArgbEncode(0xff, 50, 104, 205)); - pParams->m_pGraphics->SetStrokeColor(&clrFlag); + pParams->m_pGraphics->SetStrokeColor( + CXFA_Color(ArgbEncode(0xff, 50, 104, 205))); pParams->m_pGraphics->StrokePath(&path, pMatrix); pParams->m_pGraphics->RestoreGraphState(); } @@ -203,9 +197,7 @@ void CFWL_MonthCalendarTP::DrawHSeperator(CFWL_ThemeBackground* pParams, path.MoveTo(CFX_PointF(rtHSep.left, rtHSep.top + rtHSep.height / 2)); path.LineTo(CFX_PointF(rtHSep.right(), rtHSep.top + rtHSep.height / 2)); pParams->m_pGraphics->SaveGraphState(); - - CXFA_Color clrHSep(m_pThemeData->clrSeperator); - pParams->m_pGraphics->SetStrokeColor(&clrHSep); + pParams->m_pGraphics->SetStrokeColor(CXFA_Color(m_pThemeData->clrSeperator)); pParams->m_pGraphics->StrokePath(&path, pMatrix); pParams->m_pGraphics->RestoreGraphState(); } @@ -217,9 +209,7 @@ void CFWL_MonthCalendarTP::DrawWeekNumSep(CFWL_ThemeBackground* pParams, path.MoveTo(rtWeekSep.TopLeft()); path.LineTo(rtWeekSep.BottomLeft()); pParams->m_pGraphics->SaveGraphState(); - - CXFA_Color clrHSep(m_pThemeData->clrSeperator); - pParams->m_pGraphics->SetStrokeColor(&clrHSep); + pParams->m_pGraphics->SetStrokeColor(CXFA_Color(m_pThemeData->clrSeperator)); pParams->m_pGraphics->StrokePath(&path, pMatrix); pParams->m_pGraphics->RestoreGraphState(); } @@ -232,16 +222,16 @@ void CFWL_MonthCalendarTP::DrawDatesInBK(CFWL_ThemeBackground* pParams, CFX_RectF rtSelDay = pParams->m_rtPart; path.AddRectangle(rtSelDay.left, rtSelDay.top, rtSelDay.width, rtSelDay.height); - CXFA_Color clrSelDayBK(m_pThemeData->clrDatesSelectedBK); - pParams->m_pGraphics->SetFillColor(&clrSelDayBK); + pParams->m_pGraphics->SetFillColor( + CXFA_Color(m_pThemeData->clrDatesSelectedBK)); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); } else if (pParams->m_dwStates & CFWL_PartState_Hovered) { CXFA_Path path; CFX_RectF rtSelDay = pParams->m_rtPart; path.AddRectangle(rtSelDay.left, rtSelDay.top, rtSelDay.width, rtSelDay.height); - CXFA_Color clrSelDayBK(m_pThemeData->clrDatesHoverBK); - pParams->m_pGraphics->SetFillColor(&clrSelDayBK); + pParams->m_pGraphics->SetFillColor( + CXFA_Color(m_pThemeData->clrDatesHoverBK)); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); } pParams->m_pGraphics->RestoreGraphState(); @@ -254,8 +244,8 @@ void CFWL_MonthCalendarTP::DrawDatesInCircle(CFWL_ThemeBackground* pParams, path.AddRectangle(rtSelDay.left, rtSelDay.top, rtSelDay.width, rtSelDay.height); pParams->m_pGraphics->SaveGraphState(); - CXFA_Color clrSelDayBK(m_pThemeData->clrDatesCircle); - pParams->m_pGraphics->SetStrokeColor(&clrSelDayBK); + pParams->m_pGraphics->SetStrokeColor( + CXFA_Color(m_pThemeData->clrDatesCircle)); pParams->m_pGraphics->StrokePath(&path, pMatrix); pParams->m_pGraphics->RestoreGraphState(); } @@ -267,8 +257,8 @@ void CFWL_MonthCalendarTP::DrawTodayCircle(CFWL_ThemeBackground* pParams, path.AddRectangle(rtTodayCircle.left, rtTodayCircle.top, rtTodayCircle.width, rtTodayCircle.height); pParams->m_pGraphics->SaveGraphState(); - CXFA_Color clrTodayCircle(m_pThemeData->clrDatesCircle); - pParams->m_pGraphics->SetStrokeColor(&clrTodayCircle); + pParams->m_pGraphics->SetStrokeColor( + CXFA_Color(m_pThemeData->clrDatesCircle)); pParams->m_pGraphics->StrokePath(&path, pMatrix); pParams->m_pGraphics->RestoreGraphState(); } diff --git a/xfa/fwl/theme/cfwl_pushbuttontp.cpp b/xfa/fwl/theme/cfwl_pushbuttontp.cpp index d0f5760f44..c8152f8d9b 100644 --- a/xfa/fwl/theme/cfwl_pushbuttontp.cpp +++ b/xfa/fwl/theme/cfwl_pushbuttontp.cpp @@ -67,16 +67,14 @@ void CFWL_PushButtonTP::DrawBackground(CFWL_ThemeBackground* pParams) { m_pThemeData->clrEnd[iColor], &fillPath, FXFILL_ALTERNATE, &pParams->m_matrix); - CXFA_Color crStroke(m_pThemeData->clrBorder[iColor]); - pGraphics->SetStrokeColor(&crStroke); + pGraphics->SetStrokeColor(CXFA_Color(m_pThemeData->clrBorder[iColor])); pGraphics->StrokePath(&strokePath, &pParams->m_matrix); fillPath.Clear(); fillPath.AddRectangle(rtInner.left, rtInner.top, rtInner.width, rtInner.height); - CXFA_Color crFill(m_pThemeData->clrFill[iColor]); - pGraphics->SetFillColor(&crFill); + pGraphics->SetFillColor(CXFA_Color(m_pThemeData->clrFill[iColor])); pGraphics->FillPath(&fillPath, FXFILL_WINDING, &pParams->m_matrix); if (pParams->m_dwStates & CFWL_PartState_Focused) { rtInner.Inflate(1, 1, 0, 0); diff --git a/xfa/fwl/theme/cfwl_scrollbartp.cpp b/xfa/fwl/theme/cfwl_scrollbartp.cpp index 2975888ac2..5deec8d6d6 100644 --- a/xfa/fwl/theme/cfwl_scrollbartp.cpp +++ b/xfa/fwl/theme/cfwl_scrollbartp.cpp @@ -92,10 +92,9 @@ void CFWL_ScrollBarTP::DrawThumbBtn(CXFA_Graphics* pGraphics, m_pThemeData->clrBtnBK[eState - 1][0], m_pThemeData->clrBtnBK[eState - 1][1], &path, FXFILL_WINDING, pMatrix); - CXFA_Color rcStroke; - rcStroke.Set(m_pThemeData->clrBtnBorder[eState - 1]); pGraphics->SaveGraphState(); - pGraphics->SetStrokeColor(&rcStroke); + pGraphics->SetStrokeColor( + CXFA_Color(m_pThemeData->clrBtnBorder[eState - 1])); pGraphics->StrokePath(&path, pMatrix); pGraphics->RestoreGraphState(); } else { @@ -108,10 +107,9 @@ void CFWL_ScrollBarTP::DrawThumbBtn(CXFA_Graphics* pGraphics, m_pThemeData->clrBtnBK[eState - 1][0], m_pThemeData->clrBtnBK[eState - 1][1], &path, FXFILL_WINDING, pMatrix); - CXFA_Color rcStroke; - rcStroke.Set(m_pThemeData->clrBtnBorder[eState - 1]); pGraphics->SaveGraphState(); - pGraphics->SetStrokeColor(&rcStroke); + pGraphics->SetStrokeColor( + CXFA_Color(m_pThemeData->clrBtnBorder[eState - 1])); pGraphics->StrokePath(&path, pMatrix); pGraphics->RestoreGraphState(); } @@ -140,9 +138,9 @@ void CFWL_ScrollBarTP::DrawPaw(CXFA_Graphics* pGraphics, path.MoveTo(CFX_PointF(fX, fY + 2)); path.LineTo(CFX_PointF(fX + fPawLen, fY + 2)); - CXFA_Color clrLight(m_pThemeData->clrPawColorLight[eState - 1]); pGraphics->SetLineWidth(1); - pGraphics->SetStrokeColor(&clrLight); + pGraphics->SetStrokeColor( + CXFA_Color(m_pThemeData->clrPawColorLight[eState - 1])); pGraphics->StrokePath(&path); fX++; @@ -156,9 +154,9 @@ void CFWL_ScrollBarTP::DrawPaw(CXFA_Graphics* pGraphics, path.MoveTo(CFX_PointF(fX, fY + 3)); path.LineTo(CFX_PointF(fX + fPawLen, fY + 3)); - CXFA_Color clrDark(m_pThemeData->clrPawColorDark[eState - 1]); pGraphics->SetLineWidth(1); - pGraphics->SetStrokeColor(&clrDark); + pGraphics->SetStrokeColor( + CXFA_Color(m_pThemeData->clrPawColorDark[eState - 1])); pGraphics->StrokePath(&path, pMatrix); } else { float fPawLen = kPawLength; @@ -177,9 +175,9 @@ void CFWL_ScrollBarTP::DrawPaw(CXFA_Graphics* pGraphics, path.MoveTo(CFX_PointF(fX + 2, fY)); path.LineTo(CFX_PointF(fX + 2, fY + fPawLen)); - CXFA_Color clrLight(m_pThemeData->clrPawColorLight[eState - 1]); pGraphics->SetLineWidth(1); - pGraphics->SetStrokeColor(&clrLight); + pGraphics->SetStrokeColor( + CXFA_Color(m_pThemeData->clrPawColorLight[eState - 1])); pGraphics->StrokePath(&path, pMatrix); fY++; @@ -193,9 +191,9 @@ void CFWL_ScrollBarTP::DrawPaw(CXFA_Graphics* pGraphics, path.MoveTo(CFX_PointF(fX + 3, fY)); path.LineTo(CFX_PointF(fX + 3, fY + fPawLen)); - CXFA_Color clrDark(m_pThemeData->clrPawColorDark[eState - 1]); pGraphics->SetLineWidth(1); - pGraphics->SetStrokeColor(&clrDark); + pGraphics->SetStrokeColor( + CXFA_Color(m_pThemeData->clrPawColorDark[eState - 1])); pGraphics->StrokePath(&path, pMatrix); } } @@ -210,7 +208,6 @@ void CFWL_ScrollBarTP::DrawTrack(CXFA_Graphics* pGraphics, return; pGraphics->SaveGraphState(); - CXFA_Color colorLine(ArgbEncode(255, 238, 237, 229)); CXFA_Path path; float fRight = pRect->right(); float fBottom = pRect->bottom(); @@ -221,7 +218,7 @@ void CFWL_ScrollBarTP::DrawTrack(CXFA_Graphics* pGraphics, path.AddRectangle(pRect->left, pRect->top, pRect->width, 1); path.AddRectangle(pRect->left, fBottom - 1, pRect->width, 1); } - pGraphics->SetFillColor(&colorLine); + pGraphics->SetFillColor(CXFA_Color(ArgbEncode(255, 238, 237, 229))); pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); path.Clear(); path.AddRectangle(pRect->left + 1, pRect->top, pRect->width - 2, diff --git a/xfa/fwl/theme/cfwl_widgettp.cpp b/xfa/fwl/theme/cfwl_widgettp.cpp index fe63780c39..48d4118ed9 100644 --- a/xfa/fwl/theme/cfwl_widgettp.cpp +++ b/xfa/fwl/theme/cfwl_widgettp.cpp @@ -98,17 +98,15 @@ void CFWL_WidgetTP::FinalizeTTO() { void CFWL_WidgetTP::DrawBorder(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!pRect) + if (!pGraphics || !pRect) return; + CXFA_Path path; path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height); path.AddRectangle(pRect->left + 1, pRect->top + 1, pRect->width - 2, pRect->height - 2); pGraphics->SaveGraphState(); - CXFA_Color crFill(ArgbEncode(255, 0, 0, 0)); - pGraphics->SetFillColor(&crFill); + pGraphics->SetFillColor(CXFA_Color(ArgbEncode(255, 0, 0, 0))); pGraphics->FillPath(&path, FXFILL_ALTERNATE, pMatrix); pGraphics->RestoreGraphState(); } @@ -123,15 +121,13 @@ void CFWL_WidgetTP::FillSoildRect(CXFA_Graphics* pGraphics, FX_ARGB fillColor, const CFX_RectF* pRect, CFX_Matrix* pMatrix) { - if (!pGraphics) + if (!pGraphics || !pRect) return; - if (!pRect) - return; - pGraphics->SaveGraphState(); - CXFA_Color crFill(fillColor); - pGraphics->SetFillColor(&crFill); + CXFA_Path path; path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height); + pGraphics->SaveGraphState(); + pGraphics->SetFillColor(CXFA_Color(fillColor)); pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); pGraphics->RestoreGraphState(); } @@ -153,8 +149,7 @@ void CFWL_WidgetTP::DrawAxialShading(CXFA_Graphics* pGraphics, CFX_PointF endPoint(fx2, fy2); CXFA_Shading shading(begPoint, endPoint, false, false, beginColor, endColor); pGraphics->SaveGraphState(); - CXFA_Color color1(&shading); - pGraphics->SetFillColor(&color1); + pGraphics->SetFillColor(CXFA_Color(&shading)); pGraphics->FillPath(path, fillMode, pMatrix); pGraphics->RestoreGraphState(); } @@ -162,17 +157,15 @@ void CFWL_WidgetTP::DrawAxialShading(CXFA_Graphics* pGraphics, void CFWL_WidgetTP::DrawFocus(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!pRect) + if (!pGraphics || !pRect) return; - pGraphics->SaveGraphState(); - CXFA_Color cr(0xFF000000); - pGraphics->SetStrokeColor(&cr); + float DashPattern[2] = {1, 1}; - pGraphics->SetLineDash(0.0f, DashPattern, 2); CXFA_Path path; path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height); + pGraphics->SaveGraphState(); + pGraphics->SetStrokeColor(CXFA_Color(0xFF000000)); + pGraphics->SetLineDash(0.0f, DashPattern, 2); pGraphics->StrokePath(&path, pMatrix); pGraphics->RestoreGraphState(); } @@ -227,8 +220,7 @@ void CFWL_WidgetTP::DrawArrow(CXFA_Graphics* pGraphics, break; } } - CXFA_Color cr(argSign); - pGraphics->SetFillColor(&cr); + pGraphics->SetFillColor(CXFA_Color(argSign)); pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); } @@ -236,9 +228,9 @@ void CFWL_WidgetTP::DrawBtn(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, FWLTHEME_STATE eState, CFX_Matrix* pMatrix) { - CXFA_Path path; InitializeArrowColorData(); + CXFA_Path path; float fRight = pRect->right(); float fBottom = pRect->bottom(); path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height); @@ -247,9 +239,7 @@ void CFWL_WidgetTP::DrawBtn(CXFA_Graphics* pGraphics, m_pColorData->clrEnd[eState - 1], &path, FXFILL_WINDING, pMatrix); - CXFA_Color rcStroke; - rcStroke.Set(m_pColorData->clrBorder[eState - 1]); - pGraphics->SetStrokeColor(&rcStroke); + pGraphics->SetStrokeColor(CXFA_Color(m_pColorData->clrBorder[eState - 1])); pGraphics->StrokePath(&path, pMatrix); } 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, diff --git a/xfa/fxgraphics/cxfa_color.cpp b/xfa/fxgraphics/cxfa_color.cpp index 79c0e5f794..731d144c41 100644 --- a/xfa/fxgraphics/cxfa_color.cpp +++ b/xfa/fxgraphics/cxfa_color.cpp @@ -6,41 +6,41 @@ #include "xfa/fxgraphics/cxfa_color.h" -CXFA_Color::CXFA_Color() : m_type(FX_COLOR_None) {} +CXFA_Color::CXFA_Color() : m_type(Invalid) {} -CXFA_Color::CXFA_Color(const FX_ARGB argb) { - Set(argb); +CXFA_Color::CXFA_Color(const FX_ARGB argb) : m_type(Solid), m_argb(argb) { + m_pointer.pattern = nullptr; } -CXFA_Color::CXFA_Color(CXFA_Pattern* pattern, const FX_ARGB argb) { - Set(pattern, argb); +CXFA_Color::CXFA_Color(CXFA_Pattern* pattern, const FX_ARGB argb) + : m_type(Pattern), m_argb(argb) { + m_pointer.pattern = pattern; } -CXFA_Color::CXFA_Color(CXFA_Shading* shading) { - Set(shading); +CXFA_Color::CXFA_Color(CXFA_Shading* shading) : m_type(Shading), m_argb(0) { + m_pointer.shading = shading; } -CXFA_Color::~CXFA_Color() { - m_type = FX_COLOR_None; -} - -void CXFA_Color::Set(const FX_ARGB argb) { - m_type = FX_COLOR_Solid; - m_info.argb = argb; - m_info.pattern = nullptr; -} - -void CXFA_Color::Set(CXFA_Pattern* pattern, const FX_ARGB argb) { - if (!pattern) - return; - m_type = FX_COLOR_Pattern; - m_info.argb = argb; - m_info.pattern = pattern; -} - -void CXFA_Color::Set(CXFA_Shading* shading) { - if (!shading) - return; - m_type = FX_COLOR_Shading; - m_shading = shading; +CXFA_Color::~CXFA_Color() {} + +CXFA_Color& CXFA_Color::operator=(const CXFA_Color& that) { + if (this != &that) { + m_type = that.m_type; + switch (m_type) { + case Solid: + m_argb = that.m_argb; + m_pointer.pattern = nullptr; + break; + case Pattern: + m_argb = that.m_argb; + m_pointer.pattern = that.m_pointer.pattern; + break; + case Shading: + m_argb = 0; + m_pointer.shading = that.m_pointer.shading; + default: + break; + } + } + return *this; } diff --git a/xfa/fxgraphics/cxfa_color.h b/xfa/fxgraphics/cxfa_color.h index f5bba27586..4ae790507b 100644 --- a/xfa/fxgraphics/cxfa_color.h +++ b/xfa/fxgraphics/cxfa_color.h @@ -8,36 +8,43 @@ #define XFA_FXGRAPHICS_CXFA_COLOR_H_ #include "core/fxge/fx_dib.h" -#include "xfa/fxgraphics/cxfa_graphics.h" class CXFA_Pattern; class CXFA_Shading; -enum { FX_COLOR_None = 0, FX_COLOR_Solid, FX_COLOR_Pattern, FX_COLOR_Shading }; - class CXFA_Color { public: + enum Type { Invalid, Solid, Pattern, Shading }; + CXFA_Color(); explicit CXFA_Color(const FX_ARGB argb); explicit CXFA_Color(CXFA_Shading* shading); CXFA_Color(CXFA_Pattern* pattern, const FX_ARGB argb); - virtual ~CXFA_Color(); - - void Set(const FX_ARGB argb); - void Set(CXFA_Pattern* pattern, const FX_ARGB argb); - void Set(CXFA_Shading* shading); + ~CXFA_Color(); + + Type GetType() const { return m_type; } + FX_ARGB GetArgb() const { + ASSERT(m_type == Solid || m_type == Pattern); + return m_argb; + } + CXFA_Pattern* GetPattern() const { + ASSERT(m_type == Pattern); + return m_pointer.pattern; + } + CXFA_Shading* GetShading() const { + ASSERT(m_type == Shading); + return m_pointer.shading; + } + + CXFA_Color& operator=(const CXFA_Color& that); private: - friend class CXFA_Graphics; - - int32_t m_type; + Type m_type; + FX_ARGB m_argb; union { - struct { - FX_ARGB argb; - CXFA_Pattern* pattern; - } m_info; - CXFA_Shading* m_shading; - }; + CXFA_Pattern* pattern; + CXFA_Shading* shading; + } m_pointer; }; #endif // XFA_FXGRAPHICS_CXFA_COLOR_H_ diff --git a/xfa/fxgraphics/cxfa_graphics.cpp b/xfa/fxgraphics/cxfa_graphics.cpp index 8648abb81d..981c288b46 100644 --- a/xfa/fxgraphics/cxfa_graphics.cpp +++ b/xfa/fxgraphics/cxfa_graphics.cpp @@ -165,20 +165,14 @@ void CXFA_Graphics::SetLineWidth(float lineWidth, bool isActOnDash) { } } -void CXFA_Graphics::SetStrokeColor(CXFA_Color* color) { - if (!color) - return; - if (m_type == FX_CONTEXT_Device && m_renderDevice) { +void CXFA_Graphics::SetStrokeColor(const CXFA_Color& color) { + if (m_type == FX_CONTEXT_Device && m_renderDevice) m_info.strokeColor = color; - } } -void CXFA_Graphics::SetFillColor(CXFA_Color* color) { - if (!color) - return; - if (m_type == FX_CONTEXT_Device && m_renderDevice) { +void CXFA_Graphics::SetFillColor(const CXFA_Color& color) { + if (m_type == FX_CONTEXT_Device && m_renderDevice) m_info.fillColor = color; - } } void CXFA_Graphics::StrokePath(CXFA_Path* path, CFX_Matrix* matrix) { @@ -273,44 +267,33 @@ void CXFA_Graphics::RenderDeviceSetLineDash(FX_DashStyle dashStyle) { void CXFA_Graphics::RenderDeviceStrokePath(CXFA_Path* path, CFX_Matrix* matrix) { - if (!m_info.strokeColor) + if (m_info.strokeColor.GetType() != CXFA_Color::Solid) return; - CFX_Matrix m(m_info.CTM.a, m_info.CTM.b, m_info.CTM.c, m_info.CTM.d, - m_info.CTM.e, m_info.CTM.f); - if (matrix) { + + CFX_Matrix m = m_info.CTM; + if (matrix) m.Concat(*matrix); - } - switch (m_info.strokeColor->m_type) { - case FX_COLOR_Solid: { - m_renderDevice->DrawPath(path->GetPathData(), &m, &m_info.graphState, 0x0, - m_info.strokeColor->m_info.argb, 0); - return; - } - default: - return; - } + + m_renderDevice->DrawPath(path->GetPathData(), &m, &m_info.graphState, 0x0, + m_info.strokeColor.GetArgb(), 0); } void CXFA_Graphics::RenderDeviceFillPath(CXFA_Path* path, FX_FillMode fillMode, CFX_Matrix* matrix) { - if (!m_info.fillColor) - return; - CFX_Matrix m(m_info.CTM.a, m_info.CTM.b, m_info.CTM.c, m_info.CTM.d, - m_info.CTM.e, m_info.CTM.f); - if (matrix) { + CFX_Matrix m = m_info.CTM; + if (matrix) m.Concat(*matrix); - } - switch (m_info.fillColor->m_type) { - case FX_COLOR_Solid: { + + switch (m_info.fillColor.GetType()) { + case CXFA_Color::Solid: m_renderDevice->DrawPath(path->GetPathData(), &m, &m_info.graphState, - m_info.fillColor->m_info.argb, 0x0, fillMode); + m_info.fillColor.GetArgb(), 0x0, fillMode); return; - } - case FX_COLOR_Pattern: + case CXFA_Color::Pattern: FillPathWithPattern(path, fillMode, &m); return; - case FX_COLOR_Shading: + case CXFA_Color::Shading: FillPathWithShading(path, fillMode, &m); return; default: @@ -347,7 +330,7 @@ void CXFA_Graphics::RenderDeviceStretchImage( void CXFA_Graphics::FillPathWithPattern(CXFA_Path* path, FX_FillMode fillMode, CFX_Matrix* matrix) { - CXFA_Pattern* pattern = m_info.fillColor->m_info.pattern; + CXFA_Pattern* pattern = m_info.fillColor.GetPattern(); CFX_RetainPtr bitmap = m_renderDevice->GetBitmap(); int32_t width = bitmap->GetWidth(); int32_t height = bitmap->GetHeight(); @@ -355,7 +338,7 @@ void CXFA_Graphics::FillPathWithPattern(CXFA_Path* path, bmp->Create(width, height, FXDIB_Argb); m_renderDevice->GetDIBits(bmp, 0, 0); - FX_HatchStyle hatchStyle = m_info.fillColor->m_info.pattern->m_hatchStyle; + FX_HatchStyle hatchStyle = m_info.fillColor.GetPattern()->m_hatchStyle; const FX_HATCHDATA& data = hatchBitmapData[static_cast(hatchStyle)]; auto mask = pdfium::MakeRetain(); @@ -369,12 +352,10 @@ void CXFA_Graphics::FillPathWithPattern(CXFA_Path* path, FXSYS_round(rectf.right), FXSYS_round(rectf.bottom)); CFX_DefaultRenderDevice device; device.Attach(bmp, false, nullptr, false); - device.FillRect(&rect, m_info.fillColor->m_info.pattern->m_backArgb); + device.FillRect(&rect, m_info.fillColor.GetPattern()->m_backArgb); for (int32_t j = rect.bottom; j < rect.top; j += mask->GetHeight()) { - for (int32_t i = rect.left; i < rect.right; i += mask->GetWidth()) { - device.SetBitMask(mask, i, j, - m_info.fillColor->m_info.pattern->m_foreArgb); - } + for (int32_t i = rect.left; i < rect.right; i += mask->GetWidth()) + device.SetBitMask(mask, i, j, m_info.fillColor.GetPattern()->m_foreArgb); } CFX_RenderDevice::StateRestorer restorer(m_renderDevice); m_renderDevice->SetClip_PathFill(path->GetPathData(), matrix, fillMode); @@ -387,16 +368,16 @@ void CXFA_Graphics::FillPathWithShading(CXFA_Path* path, CFX_RetainPtr bitmap = m_renderDevice->GetBitmap(); int32_t width = bitmap->GetWidth(); int32_t height = bitmap->GetHeight(); - float start_x = m_info.fillColor->m_shading->m_beginPoint.x; - float start_y = m_info.fillColor->m_shading->m_beginPoint.y; - float end_x = m_info.fillColor->m_shading->m_endPoint.x; - float end_y = m_info.fillColor->m_shading->m_endPoint.y; + 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; auto bmp = pdfium::MakeRetain(); bmp->Create(width, height, FXDIB_Argb); m_renderDevice->GetDIBits(bmp, 0, 0); int32_t pitch = bmp->GetPitch(); bool result = false; - switch (m_info.fillColor->m_shading->m_type) { + switch (m_info.fillColor.GetShading()->m_type) { case FX_SHADING_Axial: { float x_span = end_x - start_x; float y_span = end_y - start_y; @@ -409,26 +390,26 @@ void CXFA_Graphics::FillPathWithShading(CXFA_Path* path, float scale = (((x - start_x) * x_span) + ((y - start_y) * y_span)) / axis_len_square; if (scale < 0) { - if (!m_info.fillColor->m_shading->m_isExtendedBegin) { + if (!m_info.fillColor.GetShading()->m_isExtendedBegin) { continue; } scale = 0; } else if (scale > 1.0f) { - if (!m_info.fillColor->m_shading->m_isExtendedEnd) { + if (!m_info.fillColor.GetShading()->m_isExtendedEnd) { continue; } scale = 1.0f; } int32_t index = (int32_t)(scale * (FX_SHADING_Steps - 1)); - dib_buf[column] = m_info.fillColor->m_shading->m_argbArray[index]; + dib_buf[column] = m_info.fillColor.GetShading()->m_argbArray[index]; } } result = true; break; } case FX_SHADING_Radial: { - float start_r = m_info.fillColor->m_shading->m_beginRadius; - float end_r = m_info.fillColor->m_shading->m_endRadius; + float start_r = m_info.fillColor.GetShading()->m_beginRadius; + float end_r = m_info.fillColor.GetShading()->m_endRadius; 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)); @@ -459,7 +440,7 @@ void CXFA_Graphics::FillPathWithShading(CXFA_Path* path, s2 = (-b - root) / (2 * a); s1 = (-b + root) / (2 * a); } - if (s2 <= 1.0f || m_info.fillColor->m_shading->m_isExtendedEnd) { + if (s2 <= 1.0f || m_info.fillColor.GetShading()->m_isExtendedEnd) { s = (s2); } else { s = (s1); @@ -469,19 +450,19 @@ void CXFA_Graphics::FillPathWithShading(CXFA_Path* path, } } if (s < 0) { - if (!m_info.fillColor->m_shading->m_isExtendedBegin) { + if (!m_info.fillColor.GetShading()->m_isExtendedBegin) { continue; } s = 0; } if (s > 1.0f) { - if (!m_info.fillColor->m_shading->m_isExtendedEnd) { + if (!m_info.fillColor.GetShading()->m_isExtendedEnd) { continue; } s = 1.0f; } int index = (int32_t)(s * (FX_SHADING_Steps - 1)); - dib_buf[column] = m_info.fillColor->m_shading->m_argbArray[index]; + dib_buf[column] = m_info.fillColor.GetShading()->m_argbArray[index]; } } result = true; diff --git a/xfa/fxgraphics/cxfa_graphics.h b/xfa/fxgraphics/cxfa_graphics.h index 5492d4d3be..8069c8ecbd 100644 --- a/xfa/fxgraphics/cxfa_graphics.h +++ b/xfa/fxgraphics/cxfa_graphics.h @@ -16,8 +16,8 @@ #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/fx_dib.h" #include "core/fxge/fx_font.h" +#include "xfa/fxgraphics/cxfa_color.h" -class CXFA_Color; class CXFA_Path; using FX_FillMode = int32_t; @@ -57,8 +57,8 @@ class CXFA_Graphics { void SetLineDash(float dashPhase, float* dashArray, int32_t dashCount); void SetLineDash(FX_DashStyle dashStyle); void SetLineWidth(float lineWidth, bool isActOnDash = false); - void SetStrokeColor(CXFA_Color* color); - void SetFillColor(CXFA_Color* color); + void SetStrokeColor(const CXFA_Color& color); + void SetFillColor(const CXFA_Color& color); void SetClipRect(const CFX_RectF& rect); void StrokePath(CXFA_Path* path, CFX_Matrix* matrix = nullptr); void FillPath(CXFA_Path* path, @@ -81,8 +81,8 @@ class CXFA_Graphics { CFX_GraphStateData graphState; CFX_Matrix CTM; bool isActOnDash; - CXFA_Color* strokeColor; - CXFA_Color* fillColor; + CXFA_Color strokeColor; + CXFA_Color fillColor; } m_info; void RenderDeviceSetLineDash(FX_DashStyle dashStyle); -- cgit v1.2.3