Make StrokeSameStyle a nested enum class -- define values so as to make it clearer it is a bitmask. -- use Mask<> template since it is a bitmask. Change-Id: I12018410e78b598efc65555be694968d583759e4 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/84350 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fxfa/parser/cxfa_rectangle.cpp b/xfa/fxfa/parser/cxfa_rectangle.cpp index 22b8816..f9b2874 100644 --- a/xfa/fxfa/parser/cxfa_rectangle.cpp +++ b/xfa/fxfa/parser/cxfa_rectangle.cpp
@@ -74,7 +74,7 @@ CXFA_Stroke* stroke1 = strokes[0]; for (int32_t i = 1; i < 8; i++) { CXFA_Stroke* stroke2 = strokes[i]; - if (!stroke1->SameStyles(stroke2, 0)) { + if (!stroke1->SameStyles(stroke2, {})) { bSameStyles = false; break; } @@ -85,8 +85,9 @@ stroke1 = strokes[0]; for (int32_t i = 2; i < 8; i += 2) { CXFA_Stroke* stroke2 = strokes[i]; - if (!stroke1->SameStyles(stroke2, XFA_STROKE_SAMESTYLE_NoPresence | - XFA_STROKE_SAMESTYLE_Corner)) { + if (!stroke1->SameStyles(stroke2, + {CXFA_Stroke::SameStyleOption::kNoPresence, + CXFA_Stroke::SameStyleOption::kCorner})) { bSameStyles = false; break; } @@ -306,7 +307,7 @@ CXFA_Stroke* stroke1 = strokes[0]; for (int32_t i = 1; i < 8; i++) { CXFA_Stroke* stroke2 = strokes[i]; - if (!stroke1->SameStyles(stroke2, 0)) { + if (!stroke1->SameStyles(stroke2, {})) { bSameStyles = false; break; } @@ -317,8 +318,9 @@ bClose = true; for (int32_t i = 2; i < 8; i += 2) { CXFA_Stroke* stroke2 = strokes[i]; - if (!stroke1->SameStyles(stroke2, XFA_STROKE_SAMESTYLE_NoPresence | - XFA_STROKE_SAMESTYLE_Corner)) { + if (!stroke1->SameStyles(stroke2, + {CXFA_Stroke::SameStyleOption::kNoPresence, + CXFA_Stroke::SameStyleOption::kCorner})) { bSameStyles = false; break; } @@ -349,7 +351,7 @@ } GetPath(strokes, rtWidget, path, i, bStart, !bSameStyles); - bStart = !stroke->SameStyles(strokes[(i + 1) % 8], 0); + bStart = !stroke->SameStyles(strokes[(i + 1) % 8], {}); if (bStart) { if (stroke) stroke->Stroke(pGS, path, matrix); @@ -479,9 +481,9 @@ CXFA_Stroke* strokeBefore = strokes[(nIndex + 1 * 8 - 1) % 8]; CXFA_Stroke* strokeAfter = strokes[nIndex + 1]; if (stroke->IsInverted()) { - if (!stroke->SameStyles(strokeBefore, 0)) + if (!stroke->SameStyles(strokeBefore, {})) halfBefore = strokeBefore->GetThickness() / 2; - if (!stroke->SameStyles(strokeAfter, 0)) + if (!stroke->SameStyles(strokeAfter, {})) halfAfter = strokeAfter->GetThickness() / 2; } } else {
diff --git a/xfa/fxfa/parser/cxfa_stroke.cpp b/xfa/fxfa/parser/cxfa_stroke.cpp index 7f2564f..175bc2d 100644 --- a/xfa/fxfa/parser/cxfa_stroke.cpp +++ b/xfa/fxfa/parser/cxfa_stroke.cpp
@@ -149,12 +149,13 @@ .ToUnit(XFA_Unit::Pt); } -bool CXFA_Stroke::SameStyles(CXFA_Stroke* stroke, uint32_t dwFlags) { +bool CXFA_Stroke::SameStyles(CXFA_Stroke* stroke, + Mask<SameStyleOption> dwFlags) { if (this == stroke) return true; if (fabs(GetThickness() - stroke->GetThickness()) >= 0.01f) return false; - if ((dwFlags & XFA_STROKE_SAMESTYLE_NoPresence) == 0 && + if (!(dwFlags & SameStyleOption::kNoPresence) && IsVisible() != stroke->IsVisible()) { return false; } @@ -162,7 +163,7 @@ return false; if (GetColor() != stroke->GetColor()) return false; - if ((dwFlags & XFA_STROKE_SAMESTYLE_Corner) != 0 && + if ((dwFlags & CXFA_Stroke::SameStyleOption::kCorner) && fabs(GetRadius() - stroke->GetRadius()) >= 0.01f) { return false; }
diff --git a/xfa/fxfa/parser/cxfa_stroke.h b/xfa/fxfa/parser/cxfa_stroke.h index 28637e5..33e1b55 100644 --- a/xfa/fxfa/parser/cxfa_stroke.h +++ b/xfa/fxfa/parser/cxfa_stroke.h
@@ -7,15 +7,11 @@ #ifndef XFA_FXFA_PARSER_CXFA_STROKE_H_ #define XFA_FXFA_PARSER_CXFA_STROKE_H_ +#include "core/fxcrt/mask.h" #include "core/fxge/dib/fx_dib.h" #include "xfa/fxfa/fxfa_basic.h" #include "xfa/fxfa/parser/cxfa_node.h" -enum StrokeSameStyle { - XFA_STROKE_SAMESTYLE_NoPresence = 1, - XFA_STROKE_SAMESTYLE_Corner = 2 -}; - class CFGAS_GEGraphics; class CFGAS_GEPath; class CXFA_Node; @@ -26,6 +22,10 @@ class CXFA_Stroke : public CXFA_Node { public: + enum class SameStyleOption { + kNoPresence = 1 << 0, + kCorner = 1 << 1, + }; CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED; ~CXFA_Stroke() override; @@ -45,7 +45,7 @@ FX_ARGB GetColor(); void SetColor(FX_ARGB argb); - bool SameStyles(CXFA_Stroke* stroke, uint32_t dwFlags); + bool SameStyles(CXFA_Stroke* stroke, Mask<SameStyleOption> dwFlags); void Stroke(CFGAS_GEGraphics* pGS, const CFGAS_GEPath& pPath,