Use NOTREACHED() in CGdiDeviceDriver::GetDeviceCaps().

GetDeviceCaps() should always receive a valid |caps_id|. Add a
NOTREACHED() for the default case in CGdiDeviceDriver::GetDeviceCaps(),
and fix the method's overrides to avoid potentially triggering it.
Fix a bunch of nits along the way.

Change-Id: I2d8a298f63ba4919ec5d95bfcbf28cbcd8316f58
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/56591
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index 9744857..6177089 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -300,8 +300,8 @@
 
 class CFX_Win32FallbackFontInfo final : public CFX_FolderFontInfo {
  public:
-  CFX_Win32FallbackFontInfo() {}
-  ~CFX_Win32FallbackFontInfo() override {}
+  CFX_Win32FallbackFontInfo() = default;
+  ~CFX_Win32FallbackFontInfo() override = default;
 
   // CFX_FolderFontInfo:
   void* MapFont(int weight,
@@ -704,9 +704,8 @@
   return pdfium::MakeUnique<CWin32Platform>();
 }
 
-CGdiDeviceDriver::CGdiDeviceDriver(HDC hDC, int device_class) {
-  m_hDC = hDC;
-  m_DeviceClass = device_class;
+CGdiDeviceDriver::CGdiDeviceDriver(HDC hDC, int device_class)
+    : m_hDC(hDC), m_DeviceClass(device_class) {
   auto* pPlatform =
       static_cast<CWin32Platform*>(CFX_GEModule::Get()->GetPlatform());
   SetStretchBltMode(hDC, pPlatform->m_bHalfTone ? HALFTONE : COLORONCOLOR);
@@ -734,7 +733,7 @@
   }
 }
 
-CGdiDeviceDriver::~CGdiDeviceDriver() {}
+CGdiDeviceDriver::~CGdiDeviceDriver() = default;
 
 int CGdiDeviceDriver::GetDeviceCaps(int caps_id) const {
   switch (caps_id) {
@@ -748,8 +747,10 @@
       return m_nBitsPerPixel;
     case FXDC_RENDER_CAPS:
       return m_RenderCaps;
+    default:
+      NOTREACHED();
+      return 0;
   }
-  return 0;
 }
 
 void CGdiDeviceDriver::SaveState() {
@@ -1139,7 +1140,13 @@
   }
 }
 
-CGdiDisplayDriver::~CGdiDisplayDriver() {}
+CGdiDisplayDriver::~CGdiDisplayDriver() = default;
+
+int CGdiDisplayDriver::GetDeviceCaps(int caps_id) const {
+  if (caps_id == FXDC_HORZ_SIZE || caps_id == FXDC_VERT_SIZE)
+    return 0;
+  return CGdiDeviceDriver::GetDeviceCaps(caps_id);
+}
 
 bool CGdiDisplayDriver::GetDIBits(const RetainPtr<CFX_DIBitmap>& pBitmap,
                                   int left,
diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp
index 8746ebe..6968e88 100644
--- a/core/fxge/win32/fx_win32_print.cpp
+++ b/core/fxge/win32/fx_win32_print.cpp
@@ -59,7 +59,7 @@
       m_HorzSize(::GetDeviceCaps(m_hDC, HORZSIZE)),
       m_VertSize(::GetDeviceCaps(m_hDC, VERTSIZE)) {}
 
-CGdiPrinterDriver::~CGdiPrinterDriver() {}
+CGdiPrinterDriver::~CGdiPrinterDriver() = default;
 
 int CGdiPrinterDriver::GetDeviceCaps(int caps_id) const {
   if (caps_id == FXDC_HORZ_SIZE)
@@ -361,7 +361,7 @@
   HRGN hRgn = ::CreateRectRgn(0, 0, 1, 1);
   int ret = ::GetClipRgn(hDC, hRgn);
   if (ret == 1) {
-    ret = ::GetRegionData(hRgn, 0, NULL);
+    ret = ::GetRegionData(hRgn, 0, nullptr);
     if (ret) {
       RGNDATA* pData = reinterpret_cast<RGNDATA*>(FX_Alloc(uint8_t, ret));
       ret = ::GetRegionData(hRgn, ret, pData);
diff --git a/core/fxge/win32/win32_int.h b/core/fxge/win32/win32_int.h
index 144ee59..02c2e63 100644
--- a/core/fxge/win32/win32_int.h
+++ b/core/fxge/win32/win32_int.h
@@ -76,7 +76,7 @@
   CGdiDeviceDriver(HDC hDC, int device_class);
   ~CGdiDeviceDriver() override;
 
-  // RenderDeviceDriverIface
+  // RenderDeviceDriverIface:
   int GetDeviceCaps(int caps_id) const override;
   void SaveState() override;
   void RestoreState(bool bKeepSaved) override;
@@ -121,12 +121,12 @@
                           int dest_height,
                           uint32_t bitmap_color);
 
-  HDC m_hDC;
+  const HDC m_hDC;
   bool m_bMetafileDCType;
   int m_Width;
   int m_Height;
   int m_nBitsPerPixel;
-  int m_DeviceClass;
+  const int m_DeviceClass;
   int m_RenderCaps;
 };
 
@@ -136,6 +136,8 @@
   ~CGdiDisplayDriver() override;
 
  private:
+  // CGdiDisplayDriver:
+  int GetDeviceCaps(int caps_id) const override;
   bool GetDIBits(const RetainPtr<CFX_DIBitmap>& pBitmap,
                  int left,
                  int top) override;
@@ -177,6 +179,7 @@
   ~CGdiPrinterDriver() override;
 
  private:
+  // CGdiPrinterDriver:
   int GetDeviceCaps(int caps_id) const override;
   bool SetDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
                  uint32_t color,
@@ -220,7 +223,7 @@
   ~CPSPrinterDriver() override;
 
  private:
-  // RenderDeviceDriverIface
+  // RenderDeviceDriverIface:
   int GetDeviceCaps(int caps_id) const override;
   bool StartRendering() override;
   void EndRendering() override;
@@ -285,7 +288,7 @@
   ~CTextOnlyPrinterDriver() override;
 
  private:
-  // RenderDeviceDriverIface
+  // RenderDeviceDriverIface:
   int GetDeviceCaps(int caps_id) const override;
   void SaveState() override {}
   void RestoreState(bool bKeepSaved) override {}