Change parameter type for CFX_RenderDevice::SetClip_PathFill(). To avoid bitwise operations, use a struct CFX_FillRenderOptions |fill_options| as the input of fill rendering options for CFX_RenderDevice::SetClip_PathFill() instead of the integer parameter |fill_mode|. This CL also updates the parameter types for the following functions: CXFA_Graphics::FillPathWithPattern() and CXFA_Graphics::FillPathWithShading(), since |fillMode| is no longer needed after CFX_RenderDevice::SetClip_PathFill()'s parameter type change. Bug: pdfium:1531 Change-Id: I074803941a0f814695b329323f09dc90de691eb8 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/71230 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Hui Yingst <nigi@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp index dbc5258..35685b4 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -516,10 +516,12 @@ if (pPathData->GetPoints().empty()) { CFX_PathData EmptyPath; EmptyPath.AppendRect(-1, -1, 0, 0); - m_pDevice->SetClip_PathFill(&EmptyPath, nullptr, FXFILL_WINDING); + m_pDevice->SetClip_PathFill(&EmptyPath, nullptr, + CFX_FillRenderOptions::WindingOptions()); } else { - m_pDevice->SetClip_PathFill(pPathData, &mtObj2Device, - ClipPath.GetClipType(i)); + m_pDevice->SetClip_PathFill( + pPathData, &mtObj2Device, + CFX_FillRenderOptions(GetFillType(ClipPath.GetClipType(i)))); } } @@ -544,10 +546,10 @@ if (!pTextClippingPath) continue; - int fill_mode = FXFILL_WINDING; + CFX_FillRenderOptions fill_options(CFX_FillRenderOptions::WindingOptions()); if (m_Options.GetOptions().bNoTextSmooth) - fill_mode |= FXFILL_NOPATHSMOOTH; - m_pDevice->SetClip_PathFill(pTextClippingPath.get(), nullptr, fill_mode); + fill_options.aliased_path = true; + m_pDevice->SetClip_PathFill(pTextClippingPath.get(), nullptr, fill_options); pTextClippingPath.reset(); } } @@ -573,12 +575,12 @@ &path_matrix, path_obj->m_GraphState.GetObject()); } - int fill_mode = path_obj->filltype(); + CFX_FillRenderOptions fill_options(GetFillType(path_obj->filltype())); if (m_Options.GetOptions().bNoPathSmooth) { - fill_mode |= FXFILL_NOPATHSMOOTH; + fill_options.aliased_path = true; } return m_pDevice->SetClip_PathFill(path_obj->path().GetObject(), &path_matrix, - fill_mode); + fill_options); } bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp index 7e194cf..80f70bb 100644 --- a/core/fxge/cfx_renderdevice.cpp +++ b/core/fxge/cfx_renderdevice.cpp
@@ -468,11 +468,13 @@ m_pDeviceDriver->SetBaseClip(rect); } -bool CFX_RenderDevice::SetClip_PathFill(const CFX_PathData* pPathData, - const CFX_Matrix* pObject2Device, - int fill_mode) { - if (!m_pDeviceDriver->SetClip_PathFill(pPathData, pObject2Device, - fill_mode)) { +bool CFX_RenderDevice::SetClip_PathFill( + const CFX_PathData* pPathData, + const CFX_Matrix* pObject2Device, + const CFX_FillRenderOptions& fill_options) { + if (!m_pDeviceDriver->SetClip_PathFill( + pPathData, pObject2Device, + GetIntegerFlagsFromFillOptions(fill_options))) { return false; } UpdateClipBox(); @@ -494,7 +496,8 @@ bool CFX_RenderDevice::SetClip_Rect(const FX_RECT& rect) { CFX_PathData path; path.AppendRect(rect.left, rect.bottom, rect.right, rect.top); - if (!SetClip_PathFill(&path, nullptr, FXFILL_WINDING)) + if (!SetClip_PathFill(&path, nullptr, + CFX_FillRenderOptions::WindingOptions())) return false; UpdateClipBox();
diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h index 554d0b1..393a93d 100644 --- a/core/fxge/cfx_renderdevice.h +++ b/core/fxge/cfx_renderdevice.h
@@ -73,7 +73,7 @@ void SetBaseClip(const FX_RECT& rect); bool SetClip_PathFill(const CFX_PathData* pPathData, const CFX_Matrix* pObject2Device, - int fill_mode); + const CFX_FillRenderOptions& fill_options); bool SetClip_PathStroke(const CFX_PathData* pPathData, const CFX_Matrix* pObject2Device, const CFX_GraphStateData* pGraphState);
diff --git a/core/fxge/win32/fx_win32_device_embeddertest.cpp b/core/fxge/win32/fx_win32_device_embeddertest.cpp index 3d91a96..bca965f 100644 --- a/core/fxge/win32/fx_win32_device_embeddertest.cpp +++ b/core/fxge/win32/fx_win32_device_embeddertest.cpp
@@ -8,6 +8,7 @@ #include <memory> +#include "core/fxge/cfx_fillrenderoptions.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -49,8 +50,8 @@ path_data.AppendLine(p2, p3); path_data.AppendLine(p3, p1); path_data.ClosePath(); - EXPECT_TRUE( - m_driver->SetClip_PathFill(&path_data, &kIdentityMatrix, FXFILL_WINDING)); + EXPECT_TRUE(m_driver->SetClip_PathFill( + &path_data, &kIdentityMatrix, CFX_FillRenderOptions::WindingOptions())); } TEST_F(CFX_WindowsRenderDeviceTest, SimpleClipRect) { @@ -58,8 +59,8 @@ path_data.AppendRect(0.0f, 100.0f, 200.0f, 0.0f); path_data.ClosePath(); - EXPECT_TRUE( - m_driver->SetClip_PathFill(&path_data, &kIdentityMatrix, FXFILL_WINDING)); + EXPECT_TRUE(m_driver->SetClip_PathFill( + &path_data, &kIdentityMatrix, CFX_FillRenderOptions::WindingOptions())); } TEST_F(CFX_WindowsRenderDeviceTest, GargantuanClipRect) { @@ -72,8 +73,8 @@ // for a clip path should allow IntersectClipRect() to return success; // however they do not because the GDI API IntersectClipRect() errors out and // affect subsequent imaging. crbug.com/1019026 - EXPECT_FALSE( - m_driver->SetClip_PathFill(&path_data, &kIdentityMatrix, FXFILL_WINDING)); + EXPECT_FALSE(m_driver->SetClip_PathFill( + &path_data, &kIdentityMatrix, CFX_FillRenderOptions::WindingOptions())); } TEST_F(CFX_WindowsRenderDeviceTest, GargantuanClipRectWithBaseClip) { @@ -86,6 +87,6 @@ path_data.ClosePath(); // Use of a reasonable base clip ensures that we avoid getting an error back // from GDI API IntersectClipRect(). - EXPECT_TRUE( - m_driver->SetClip_PathFill(&path_data, &kIdentityMatrix, FXFILL_WINDING)); + EXPECT_TRUE(m_driver->SetClip_PathFill( + &path_data, &kIdentityMatrix, CFX_FillRenderOptions::WindingOptions())); }
diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp index 9f578e9..7f7367f 100644 --- a/xfa/fxfa/cxfa_ffwidget.cpp +++ b/xfa/fxfa/cxfa_ffwidget.cpp
@@ -14,6 +14,7 @@ #include "core/fxcodec/fx_codec.h" #include "core/fxcodec/progressive_decoder.h" #include "core/fxcrt/maybe_owned.h" +#include "core/fxge/cfx_fillrenderoptions.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/dib/cfx_dibitmap.h" @@ -134,7 +135,8 @@ CFX_RenderDevice::StateRestorer restorer(pRenderDevice); CFX_PathData path; path.AppendRect(rtImage.left, rtImage.bottom(), rtImage.right(), rtImage.top); - pRenderDevice->SetClip_PathFill(&path, &matrix, FXFILL_WINDING); + pRenderDevice->SetClip_PathFill(&path, &matrix, + CFX_FillRenderOptions::WindingOptions()); CFX_Matrix mtImage(1, 0, 0, -1, 0, 1); mtImage.Concat(
diff --git a/xfa/fxgraphics/cxfa_graphics.cpp b/xfa/fxgraphics/cxfa_graphics.cpp index 15c2974..f9818c5 100644 --- a/xfa/fxgraphics/cxfa_graphics.cpp +++ b/xfa/fxgraphics/cxfa_graphics.cpp
@@ -233,19 +233,20 @@ m_info.fillColor.GetArgb(), 0x0, fill_options); return; case CXFA_GEColor::Pattern: - FillPathWithPattern(path, fillMode, m); + FillPathWithPattern(path, fill_options, m); return; case CXFA_GEColor::Shading: - FillPathWithShading(path, fillMode, m); + FillPathWithShading(path, fill_options, m); return; default: return; } } -void CXFA_Graphics::FillPathWithPattern(const CXFA_GEPath* path, - FX_FillMode fillMode, - const CFX_Matrix& matrix) { +void CXFA_Graphics::FillPathWithPattern( + const CXFA_GEPath* path, + const CFX_FillRenderOptions& fill_options, + const CFX_Matrix& matrix) { RetainPtr<CFX_DIBitmap> bitmap = m_renderDevice->GetBitmap(); int32_t width = bitmap->GetWidth(); int32_t height = bitmap->GetHeight(); @@ -272,13 +273,14 @@ 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); + m_renderDevice->SetClip_PathFill(path->GetPathData(), &matrix, fill_options); SetDIBitsWithMatrix(bmp, CFX_Matrix()); } -void CXFA_Graphics::FillPathWithShading(const CXFA_GEPath* path, - FX_FillMode fillMode, - const CFX_Matrix& matrix) { +void CXFA_Graphics::FillPathWithShading( + const CXFA_GEPath* path, + const CFX_FillRenderOptions& fill_options, + const CFX_Matrix& matrix) { RetainPtr<CFX_DIBitmap> bitmap = m_renderDevice->GetBitmap(); int32_t width = bitmap->GetWidth(); int32_t height = bitmap->GetHeight(); @@ -389,7 +391,8 @@ } if (result) { CFX_RenderDevice::StateRestorer restorer(m_renderDevice); - m_renderDevice->SetClip_PathFill(path->GetPathData(), &matrix, fillMode); + m_renderDevice->SetClip_PathFill(path->GetPathData(), &matrix, + fill_options); SetDIBitsWithMatrix(bmp, matrix); } }
diff --git a/xfa/fxgraphics/cxfa_graphics.h b/xfa/fxgraphics/cxfa_graphics.h index 1fdfe94..7135150 100644 --- a/xfa/fxgraphics/cxfa_graphics.h +++ b/xfa/fxgraphics/cxfa_graphics.h
@@ -16,6 +16,8 @@ using FX_FillMode = int32_t; +struct CFX_FillRenderOptions; + enum class FX_HatchStyle { Horizontal = 0, Vertical = 1, @@ -74,10 +76,10 @@ FX_FillMode fillMode, const CFX_Matrix* matrix); void FillPathWithPattern(const CXFA_GEPath* path, - FX_FillMode fillMode, + const CFX_FillRenderOptions& fill_options, const CFX_Matrix& matrix); void FillPathWithShading(const CXFA_GEPath* path, - FX_FillMode fillMode, + const CFX_FillRenderOptions& fill_options, const CFX_Matrix& matrix); void SetDIBitsWithMatrix(const RetainPtr<CFX_DIBBase>& source, const CFX_Matrix& matrix);