• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 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_windowsrenderdevice.h"
6 
7 #include <windows.h>
8 
9 #include <memory>
10 
11 #include "core/fxge/cfx_fillrenderoptions.h"
12 #include "core/fxge/cfx_path.h"
13 #include "core/fxge/win32/cfx_psfonttracker.h"
14 #include "testing/embedder_test.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 
17 namespace {
18 
19 constexpr CFX_Matrix kIdentityMatrix;
20 
21 }  // namespace
22 
23 class CFX_WindowsRenderDeviceTest : public EmbedderTest {
24  public:
SetUp()25   void SetUp() override {
26     EmbedderTest::SetUp();
27 
28     // Get a device context with Windows GDI.
29     m_hDC = CreateCompatibleDC(nullptr);
30     ASSERT_TRUE(m_hDC);
31     m_driver = std::make_unique<CFX_WindowsRenderDevice>(
32         m_hDC, &m_PSFontTracker, /*encoder_iface=*/nullptr);
33     m_driver->SaveState();
34   }
35 
TearDown()36   void TearDown() override {
37     m_driver->RestoreState(false);
38     m_driver.reset();
39     DeleteDC(m_hDC);
40     EmbedderTest::TearDown();
41   }
42 
43  protected:
44   HDC m_hDC;
45   CFX_PSFontTracker m_PSFontTracker;
46   std::unique_ptr<CFX_WindowsRenderDevice> m_driver;
47 };
48 
TEST_F(CFX_WindowsRenderDeviceTest,SimpleClipTriangle)49 TEST_F(CFX_WindowsRenderDeviceTest, SimpleClipTriangle) {
50   CFX_Path path_data;
51   CFX_PointF p1(0.0f, 0.0f);
52   CFX_PointF p2(0.0f, 100.0f);
53   CFX_PointF p3(100.0f, 100.0f);
54 
55   path_data.AppendLine(p1, p2);
56   path_data.AppendLine(p2, p3);
57   path_data.AppendLine(p3, p1);
58   path_data.ClosePath();
59   EXPECT_TRUE(m_driver->SetClip_PathFill(
60       path_data, &kIdentityMatrix, CFX_FillRenderOptions::WindingOptions()));
61 }
62 
TEST_F(CFX_WindowsRenderDeviceTest,SimpleClipRect)63 TEST_F(CFX_WindowsRenderDeviceTest, SimpleClipRect) {
64   CFX_Path path_data;
65 
66   path_data.AppendRect(0.0f, 100.0f, 200.0f, 0.0f);
67   path_data.ClosePath();
68   EXPECT_TRUE(m_driver->SetClip_PathFill(
69       path_data, &kIdentityMatrix, CFX_FillRenderOptions::WindingOptions()));
70 }
71 
TEST_F(CFX_WindowsRenderDeviceTest,GargantuanClipRect)72 TEST_F(CFX_WindowsRenderDeviceTest, GargantuanClipRect) {
73   CFX_Path path_data;
74 
75   path_data.AppendRect(-257698020.0f, -257697252.0f, 257698044.0f,
76                        257698812.0f);
77   path_data.ClosePath();
78   // These coordinates for a clip path are valid, just very large. Using these
79   // for a clip path should allow IntersectClipRect() to return success;
80   // however they do not because the GDI API IntersectClipRect() errors out and
81   // affect subsequent imaging.  crbug.com/1019026
82   EXPECT_FALSE(m_driver->SetClip_PathFill(
83       path_data, &kIdentityMatrix, CFX_FillRenderOptions::WindingOptions()));
84 }
85 
TEST_F(CFX_WindowsRenderDeviceTest,GargantuanClipRectWithBaseClip)86 TEST_F(CFX_WindowsRenderDeviceTest, GargantuanClipRectWithBaseClip) {
87   CFX_Path path_data;
88   const FX_RECT kBaseClip(0, 0, 5100, 6600);
89 
90   m_driver->SetBaseClip(kBaseClip);
91   path_data.AppendRect(-257698020.0f, -257697252.0f, 257698044.0f,
92                        257698812.0f);
93   path_data.ClosePath();
94   // Use of a reasonable base clip ensures that we avoid getting an error back
95   // from GDI API IntersectClipRect().
96   EXPECT_TRUE(m_driver->SetClip_PathFill(
97       path_data, &kIdentityMatrix, CFX_FillRenderOptions::WindingOptions()));
98 }
99