xref: /aosp_15_r20/external/pdfium/core/fxge/cfx_defaultrenderdevice_unittest.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2023 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "core/fxge/cfx_defaultrenderdevice.h"
6 
7 #include "core/fxcrt/fx_coordinates.h"
8 #include "core/fxcrt/retain_ptr.h"
9 #include "core/fxge/cfx_fillrenderoptions.h"
10 #include "core/fxge/cfx_graphstatedata.h"
11 #include "core/fxge/cfx_path.h"
12 #include "core/fxge/dib/cfx_dibitmap.h"
13 #include "core/fxge/dib/fx_dib.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 
TEST(CFX_DefaultRenderDeviceTest,GetClipBox_Default)16 TEST(CFX_DefaultRenderDeviceTest, GetClipBox_Default) {
17   CFX_DefaultRenderDevice device;
18   ASSERT_TRUE(device.Create(/*width=*/16, /*height=*/16, FXDIB_Format::kArgb,
19                             /*pBackdropBitmap=*/nullptr));
20 
21   EXPECT_EQ(FX_RECT(0, 0, 16, 16), device.GetClipBox());
22 }
23 
TEST(CFX_DefaultRenderDeviceTest,GetClipBox_PathFill)24 TEST(CFX_DefaultRenderDeviceTest, GetClipBox_PathFill) {
25   // Matrix that transposes and translates by 1 unit on each axis.
26   const CFX_Matrix object_to_device(0, 1, 1, 0, 1, -1);
27 
28   // Fill type cannot be none.
29   const CFX_FillRenderOptions fill_options(
30       CFX_FillRenderOptions::FillType::kEvenOdd);
31 
32   CFX_DefaultRenderDevice device;
33   ASSERT_TRUE(device.Create(/*width=*/16, /*height=*/16, FXDIB_Format::kArgb,
34                             /*pBackdropBitmap=*/nullptr));
35 
36   CFX_Path path;
37   path.AppendRect(2, 4, 14, 12);
38   EXPECT_TRUE(device.SetClip_PathFill(path, &object_to_device, fill_options));
39 
40   EXPECT_EQ(FX_RECT(5, 1, 13, 13), device.GetClipBox());
41 }
42 
TEST(CFX_DefaultRenderDeviceTest,GetClipBox_PathStroke)43 TEST(CFX_DefaultRenderDeviceTest, GetClipBox_PathStroke) {
44   // Matrix that transposes and translates by 1 unit on each axis.
45   const CFX_Matrix object_to_device(0, 1, 1, 0, 1, -1);
46 
47   // Default line width is 1.
48   const CFX_GraphStateData graphics_state;
49 
50   CFX_DefaultRenderDevice device;
51   ASSERT_TRUE(device.Create(/*width=*/16, /*height=*/16, FXDIB_Format::kArgb,
52                             /*pBackdropBitmap=*/nullptr));
53 
54   CFX_Path path;
55   path.AppendRect(2, 4, 14, 12);
56   EXPECT_TRUE(
57       device.SetClip_PathStroke(path, &object_to_device, &graphics_state));
58 
59   EXPECT_EQ(FX_RECT(4, 0, 14, 14), device.GetClipBox());
60 }
61 
TEST(CFX_DefaultRenderDeviceTest,GetClipBox_Rect)62 TEST(CFX_DefaultRenderDeviceTest, GetClipBox_Rect) {
63   CFX_DefaultRenderDevice device;
64   ASSERT_TRUE(device.Create(/*width=*/16, /*height=*/16, FXDIB_Format::kArgb,
65                             /*pBackdropBitmap=*/nullptr));
66 
67   EXPECT_TRUE(device.SetClip_Rect({2, 4, 14, 12}));
68 
69   EXPECT_EQ(FX_RECT(2, 4, 14, 12), device.GetClipBox());
70 }
71 
TEST(CFX_DefaultRenderDeviceTest,GetClipBox_Empty)72 TEST(CFX_DefaultRenderDeviceTest, GetClipBox_Empty) {
73   CFX_DefaultRenderDevice device;
74   ASSERT_TRUE(device.Create(/*width=*/16, /*height=*/16, FXDIB_Format::kArgb,
75                             /*pBackdropBitmap=*/nullptr));
76 
77   EXPECT_TRUE(device.SetClip_Rect({2, 8, 14, 8}));
78 
79   EXPECT_TRUE(device.GetClipBox().IsEmpty());
80 }
81