Replace defined(OS_WIN) with BUILDFLAG(IS_WIN).

Bug: chromium:1234043
Change-Id: I5d2bccc92b5d3d3417d73377f3457646b95be90f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/89052
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp
index fbcfc2d..19261b5 100644
--- a/core/fpdfapi/font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -139,7 +139,7 @@
 // Boundary value to avoid integer overflow when adding 1/64th of the value.
 constexpr int kMaxRectTop = 2114445437;
 
-#if !defined(OS_WIN)
+#if !BUILDFLAG(IS_WIN)
 
 bool IsValidEmbeddedCharcodeFromUnicodeCharset(CIDSet charset) {
   switch (charset) {
@@ -187,7 +187,7 @@
   return 0;
 }
 
-#endif  // !defined(OS_WIN)
+#endif  // !BUILDFLAG(IS_WIN)
 
 void FT_UseCIDCharmap(FXFT_FaceRec* face, CIDCoding coding) {
   int encoding;
@@ -324,7 +324,7 @@
   if (m_pCID2UnicodeMap && m_pCID2UnicodeMap->IsLoaded() && m_pCMap->IsLoaded())
     return m_pCID2UnicodeMap->UnicodeFromCID(CIDFromCharCode(charcode));
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   wchar_t unicode;
   int charsize = 1;
   if (charcode > 255) {
@@ -376,7 +376,7 @@
     return static_cast<uint32_t>(unicode);
   if (m_pCMap->GetCoding() == CIDCoding::kCID)
     return 0;
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   uint8_t buffer[32];
   size_t ret = FX_WideCharToMultiByte(
       kCharsetCodePages[static_cast<size_t>(m_pCMap->GetCoding())],
diff --git a/core/fpdfapi/page/cpdf_docpagedata.cpp b/core/fpdfapi/page/cpdf_docpagedata.cpp
index 889f760..fe713cc 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.cpp
+++ b/core/fpdfapi/page/cpdf_docpagedata.cpp
@@ -62,7 +62,7 @@
     pWidthArray1->AppendNew<CPDF_Number>(w);
 }
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 void InsertWidthArray(HDC hDC, int start, int end, CPDF_Array* pWidthArray) {
   std::vector<int> widths(end - start + 1);
   GetCharWidth(hDC, start, end, widths.data());
@@ -80,7 +80,7 @@
   }
   return result;
 }
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
 
 void InsertWidthArray1(CFX_Font* pFont,
                        CFX_UnicodeEncoding* pEncoding,
@@ -549,7 +549,7 @@
   return GetFont(pBaseDict);
 }
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 RetainPtr<CPDF_Font> CPDF_DocPageData::AddWindowsFont(LOGFONTA* pLogFont) {
   pLogFont->lfHeight = -1000;
   pLogFont->lfWidth = 0;
@@ -631,7 +631,7 @@
   DeleteDC(hDC);
   return GetFont(pBaseDict);
 }
-#endif  //  defined(OS_WIN)
+#endif  //  BUILDFLAG(IS_WIN)
 
 size_t CPDF_DocPageData::CalculateEncodingDict(FX_Charset charset,
                                                CPDF_Dictionary* pBaseDict) {
diff --git a/core/fpdfapi/page/cpdf_docpagedata.h b/core/fpdfapi/page/cpdf_docpagedata.h
index 5421aad..bd521a4 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.h
+++ b/core/fpdfapi/page/cpdf_docpagedata.h
@@ -59,7 +59,7 @@
                                        const CPDF_FontEncoding* pEncoding);
   RetainPtr<CPDF_Font> GetStandardFont(const ByteString& fontName,
                                        const CPDF_FontEncoding* pEncoding);
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   RetainPtr<CPDF_Font> AddWindowsFont(LOGFONTA* pLogFont);
 #endif
 
diff --git a/core/fpdfapi/render/cpdf_docrenderdata.cpp b/core/fpdfapi/render/cpdf_docrenderdata.cpp
index 186a784..12609d3 100644
--- a/core/fpdfapi/render/cpdf_docrenderdata.cpp
+++ b/core/fpdfapi/render/cpdf_docrenderdata.cpp
@@ -20,7 +20,7 @@
 #include "core/fpdfapi/parser/cpdf_document.h"
 #include "core/fpdfapi/render/cpdf_type3cache.h"
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #include "core/fxge/win32/cfx_psfonttracker.h"
 #endif
 
@@ -65,7 +65,7 @@
   return pFunc;
 }
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 CFX_PSFontTracker* CPDF_DocRenderData::GetPSFontTracker() {
   if (!m_PSFontTracker)
     m_PSFontTracker = std::make_unique<CFX_PSFontTracker>();
diff --git a/core/fpdfapi/render/cpdf_docrenderdata.h b/core/fpdfapi/render/cpdf_docrenderdata.h
index 081d166..6a500c6 100644
--- a/core/fpdfapi/render/cpdf_docrenderdata.h
+++ b/core/fpdfapi/render/cpdf_docrenderdata.h
@@ -14,7 +14,7 @@
 #include "core/fxcrt/observed_ptr.h"
 #include "core/fxcrt/retain_ptr.h"
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #include <memory>
 #endif
 
@@ -24,7 +24,7 @@
 class CPDF_Type3Cache;
 class CPDF_Type3Font;
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 class CFX_PSFontTracker;
 #endif
 
@@ -41,7 +41,7 @@
   RetainPtr<CPDF_Type3Cache> GetCachedType3(CPDF_Type3Font* pFont);
   RetainPtr<CPDF_TransferFunc> GetTransferFunc(const CPDF_Object* pObj);
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   CFX_PSFontTracker* GetPSFontTracker();
 #endif
 
@@ -55,7 +55,7 @@
   std::map<const CPDF_Object*, ObservedPtr<CPDF_TransferFunc>>
       m_TransferFuncMap;
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   std::unique_ptr<CFX_PSFontTracker> m_PSFontTracker;
 #endif
 };
diff --git a/core/fpdfapi/render/fpdf_progressive_render_embeddertest.cpp b/core/fpdfapi/render/fpdf_progressive_render_embeddertest.cpp
index c121bdd..13c3567 100644
--- a/core/fpdfapi/render/fpdf_progressive_render_embeddertest.cpp
+++ b/core/fpdfapi/render/fpdf_progressive_render_embeddertest.cpp
@@ -454,13 +454,13 @@
       "b39d9f68ff71963d82c43eb20caa8f4d";
 #endif  // defined(OS_APPLE)
 #else
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   static constexpr char kContentWithInkChecksum[] =
       "1933e4ab19b9108ddcecd1a6abb20c85";
 #else
   static constexpr char kContentWithInkChecksum[] =
       "797bce7dc6c50ee86b095405df9fe5aa";
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
 #endif  // defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
 
   ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
diff --git a/core/fpdfdoc/cpdf_filespec.cpp b/core/fpdfdoc/cpdf_filespec.cpp
index 5194d2f..e0688bf 100644
--- a/core/fpdfdoc/cpdf_filespec.cpp
+++ b/core/fpdfdoc/cpdf_filespec.cpp
@@ -21,7 +21,7 @@
 
 namespace {
 
-#if defined(OS_APPLE) || defined(OS_WIN)
+#if defined(OS_APPLE) || BUILDFLAG(IS_WIN)
 WideString ChangeSlashToPlatform(const wchar_t* str) {
   WideString result;
   while (*str) {
@@ -51,7 +51,7 @@
   }
   return result;
 }
-#endif  // defined(OS_APPLE) || defined(OS_WIN)
+#endif  // defined(OS_APPLE) || BUILDFLAG(IS_WIN)
 
 }  // namespace
 
@@ -74,7 +74,7 @@
   if (filepath.First(sizeof("/Mac") - 1) == WideStringView(L"/Mac"))
     return ChangeSlashToPlatform(filepath.c_str() + 1);
   return ChangeSlashToPlatform(filepath.c_str());
-#elif defined(OS_WIN)
+#elif BUILDFLAG(IS_WIN)
 
   if (filepath[0] != L'/')
     return ChangeSlashToPlatform(filepath.c_str());
@@ -175,7 +175,7 @@
   if (filepath.GetLength() <= 1)
     return WideString();
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   if (filepath[1] == L':') {
     WideString result(L'/');
     result += filepath[0];
diff --git a/core/fpdfdoc/cpdf_filespec_unittest.cpp b/core/fpdfdoc/cpdf_filespec_unittest.cpp
index 16a3b94..0f23a41 100644
--- a/core/fpdfdoc/cpdf_filespec_unittest.cpp
+++ b/core/fpdfdoc/cpdf_filespec_unittest.cpp
@@ -24,7 +24,7 @@
     {L"", L""},
     // only file name.
     {L"test.pdf", L"test.pdf"},
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
     // With drive identifier.
     {L"r:\\pdfdocs\\spec.pdf", L"/r/pdfdocs/spec.pdf"},
     // Relative path.
@@ -62,7 +62,7 @@
   {
     // String object.
     static const pdfium::NullTermWstrFuncTestData test_data = {
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
       L"/C/docs/test.pdf",
       L"C:\\docs\\test.pdf"
 #elif defined(OS_APPLE)
@@ -80,7 +80,7 @@
   {
     // Dictionary object.
     static const pdfium::NullTermWstrFuncTestData test_data[] = {
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
       {L"/C/docs/test.pdf", L"C:\\docs\\test.pdf"},
       {L"/D/docs/test.pdf", L"D:\\docs\\test.pdf"},
       {L"/E/docs/test.pdf", L"E:\\docs\\test.pdf"},
@@ -138,7 +138,7 @@
 
 TEST(cpdf_filespec, SetFileName) {
   static const pdfium::NullTermWstrFuncTestData test_data = {
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
     L"C:\\docs\\test.pdf",
     L"/C/docs/test.pdf"
 #elif defined(OS_APPLE)
diff --git a/core/fpdfdoc/cpdf_interactiveform.cpp b/core/fpdfdoc/cpdf_interactiveform.cpp
index 357b623..c60468b 100644
--- a/core/fpdfdoc/cpdf_interactiveform.cpp
+++ b/core/fpdfdoc/cpdf_interactiveform.cpp
@@ -39,7 +39,7 @@
 
 const int nMaxRecursion = 32;
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 struct PDF_FONTDATA {
   bool bFind;
   LOGFONTA lf;
@@ -81,11 +81,11 @@
 
   return fd.bFind;
 }
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
 
 ByteString GetNativeFontName(FX_Charset charSet, void* pLogFont) {
   ByteString csFontName;
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   LOGFONTA lf = {};
   if (charSet == FX_Charset::kANSI) {
     csFontName = CFX_Font::kDefaultAnsiFontName;
@@ -158,7 +158,7 @@
                                    CPDF_Document* pDocument) {
   DCHECK(pDocument);
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   LOGFONTA lf;
   ByteString csFontName = GetNativeFontName(charSet, &lf);
   if (!csFontName.IsEmpty()) {
diff --git a/core/fxcodec/fax/faxmodule.cpp b/core/fxcodec/fax/faxmodule.cpp
index 607f564..8feafcd 100644
--- a/core/fxcodec/fax/faxmodule.cpp
+++ b/core/fxcodec/fax/faxmodule.cpp
@@ -627,7 +627,7 @@
   return bitpos;
 }
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 namespace {
 const uint8_t BlackRunTerminator[128] = {
     0x37, 10, 0x02, 3,  0x03, 2,  0x02, 2,  0x03, 3,  0x03, 4,  0x02, 4,
@@ -817,6 +817,6 @@
   encoder.Encode(dest_buf, dest_size);
 }
 
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
 
 }  // namespace fxcodec
diff --git a/core/fxcodec/fax/faxmodule.h b/core/fxcodec/fax/faxmodule.h
index d9a3122..2ce2a3f 100644
--- a/core/fxcodec/fax/faxmodule.h
+++ b/core/fxcodec/fax/faxmodule.h
@@ -41,14 +41,14 @@
                          int pitch,
                          uint8_t* dest_buf);
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   static void FaxEncode(const uint8_t* src_buf,
                         int width,
                         int height,
                         int pitch,
                         std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf,
                         uint32_t* dest_size);
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
 
   FaxModule() = delete;
   FaxModule(const FaxModule&) = delete;
diff --git a/core/fxcodec/jpeg/jpeg_common.h b/core/fxcodec/jpeg/jpeg_common.h
index 33b8a96..f2133f1 100644
--- a/core/fxcodec/jpeg/jpeg_common.h
+++ b/core/fxcodec/jpeg/jpeg_common.h
@@ -14,7 +14,7 @@
 
 #include "build/build_config.h"
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 // windows.h must come before the third_party/libjpeg_turbo includes.
 #include <windows.h>
 #endif
diff --git a/core/fxcodec/jpeg/jpegmodule.cpp b/core/fxcodec/jpeg/jpegmodule.cpp
index 22d5adc..1d00698 100644
--- a/core/fxcodec/jpeg/jpegmodule.cpp
+++ b/core/fxcodec/jpeg/jpegmodule.cpp
@@ -51,13 +51,13 @@
   cinfo->src->bytes_in_buffer -= num;
 }
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 static void dest_do_nothing(j_compress_ptr cinfo) {}
 
 static boolean dest_empty(j_compress_ptr cinfo) {
   return false;
 }
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
 
 }  // extern "C"
 
@@ -407,7 +407,7 @@
   return info;
 }
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 bool JpegModule::JpegEncode(const RetainPtr<CFX_DIBBase>& pSource,
                             uint8_t** dest_buf,
                             size_t* dest_size) {
@@ -506,6 +506,6 @@
 
   return true;
 }
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
 
 }  // namespace fxcodec
diff --git a/core/fxcodec/jpeg/jpegmodule.h b/core/fxcodec/jpeg/jpegmodule.h
index c2a3f1b..587942d 100644
--- a/core/fxcodec/jpeg/jpegmodule.h
+++ b/core/fxcodec/jpeg/jpegmodule.h
@@ -15,7 +15,7 @@
 #include "third_party/abseil-cpp/absl/types/optional.h"
 #include "third_party/base/span.h"
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #include "core/fxcrt/retain_ptr.h"
 #endif
 
@@ -45,11 +45,11 @@
   static absl::optional<ImageInfo> LoadInfo(
       pdfium::span<const uint8_t> src_span);
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   static bool JpegEncode(const RetainPtr<CFX_DIBBase>& pSource,
                          uint8_t** dest_buf,
                          size_t* dest_size);
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
 
   JpegModule() = delete;
   JpegModule(const JpegModule&) = delete;
diff --git a/core/fxcrt/cfx_datetime.cpp b/core/fxcrt/cfx_datetime.cpp
index 1b51ada..e919275 100644
--- a/core/fxcrt/cfx_datetime.cpp
+++ b/core/fxcrt/cfx_datetime.cpp
@@ -99,7 +99,7 @@
 // static
 CFX_DateTime CFX_DateTime::Now() {
   FXUT_SYSTEMTIME utLocal;
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   ::GetLocalTime((LPSYSTEMTIME)&utLocal);
 #else
   timeval curTime;
@@ -115,7 +115,7 @@
   utLocal.wMinute = st.tm_min;
   utLocal.wSecond = st.tm_sec;
   utLocal.wMillisecond = curTime.tv_usec / 1000;
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
 
   return CFX_DateTime(utLocal.wYear, static_cast<uint8_t>(utLocal.wMonth),
                       static_cast<uint8_t>(utLocal.wDay),
diff --git a/core/fxcrt/cfx_fileaccess_windows.h b/core/fxcrt/cfx_fileaccess_windows.h
index 077a77e..8a2d8a2 100644
--- a/core/fxcrt/cfx_fileaccess_windows.h
+++ b/core/fxcrt/cfx_fileaccess_windows.h
@@ -14,7 +14,7 @@
 #include "core/fxcrt/fileaccess_iface.h"
 #include "core/fxcrt/fx_types.h"
 
-#if !defined(OS_WIN)
+#if !BUILDFLAG(IS_WIN)
 #error "Included on the wrong platform"
 #endif
 
diff --git a/core/fxcrt/fx_codepage.cpp b/core/fxcrt/fx_codepage.cpp
index 22a1ede..feddd86 100644
--- a/core/fxcrt/fx_codepage.cpp
+++ b/core/fxcrt/fx_codepage.cpp
@@ -13,7 +13,7 @@
 #include "build/build_config.h"
 #include "third_party/base/numerics/safe_math.h"
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #include <windows.h>
 #endif
 
@@ -216,7 +216,7 @@
 };
 
 FX_CodePage FX_GetACP() {
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   return static_cast<FX_CodePage>(GetACP());
 #else
   return FX_CodePage::kDefANSI;
@@ -293,7 +293,7 @@
 size_t FX_WideCharToMultiByte(FX_CodePage codepage,
                               WideStringView wstr,
                               pdfium::span<char> buf) {
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   int input_len = pdfium::base::checked_cast<int>(wstr.GetLength());
   int output_len = pdfium::base::checked_cast<int>(buf.size());
   return WideCharToMultiByte(static_cast<UINT>(codepage), 0,
@@ -315,7 +315,7 @@
 size_t FX_MultiByteToWideChar(FX_CodePage codepage,
                               ByteStringView bstr,
                               pdfium::span<wchar_t> buf) {
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   const int input_len = pdfium::base::checked_cast<int>(bstr.GetLength());
   const int output_len = pdfium::base::checked_cast<int>(buf.size());
   return MultiByteToWideChar(static_cast<UINT>(codepage), 0,
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index 43d4afd..644e214 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -41,7 +41,7 @@
   }
 }
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 static_assert(sizeof(FX_RECT) == sizeof(RECT), "FX_RECT vs. RECT mismatch");
 static_assert(offsetof(FX_RECT, left) == offsetof(RECT, left),
               "FX_RECT vs. RECT mismatch");
diff --git a/core/fxcrt/fx_folder_posix.cpp b/core/fxcrt/fx_folder_posix.cpp
index e1b9968..39e89a1 100644
--- a/core/fxcrt/fx_folder_posix.cpp
+++ b/core/fxcrt/fx_folder_posix.cpp
@@ -12,7 +12,7 @@
 #include "core/fxcrt/unowned_ptr.h"
 #include "third_party/base/ptr_util.h"
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #error "built on wrong platform"
 #endif
 
diff --git a/core/fxcrt/fx_folder_windows.cpp b/core/fxcrt/fx_folder_windows.cpp
index 4136f64..20de118 100644
--- a/core/fxcrt/fx_folder_windows.cpp
+++ b/core/fxcrt/fx_folder_windows.cpp
@@ -11,7 +11,7 @@
 #include "build/build_config.h"
 #include "third_party/base/ptr_util.h"
 
-#if !defined(OS_WIN)
+#if !BUILDFLAG(IS_WIN)
 #error "built on wrong platform"
 #endif
 
diff --git a/core/fxcrt/fx_random.cpp b/core/fxcrt/fx_random.cpp
index ce796d9..94d60ff 100644
--- a/core/fxcrt/fx_random.cpp
+++ b/core/fxcrt/fx_random.cpp
@@ -17,7 +17,7 @@
 #define MT_Upper_Mask 0x80000000
 #define MT_Lower_Mask 0x7fffffff
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #include <wincrypt.h>
 #else
 #include <sys/time.h>
@@ -34,7 +34,7 @@
 bool g_bHaveGlobalSeed = false;
 uint32_t g_nGlobalSeed = 0;
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 bool GenerateSeedFromCryptoRandom(uint32_t* pSeed) {
   HCRYPTPROV hCP = 0;
   if (!::CryptAcquireContext(&hCP, nullptr, nullptr, PROV_RSA_FULL, 0) ||
@@ -51,7 +51,7 @@
   char c;
   uintptr_t p = reinterpret_cast<uintptr_t>(&c);
   uint32_t seed = ~static_cast<uint32_t>(p >> 3);
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   SYSTEMTIME st;
   GetSystemTime(&st);
   seed ^= static_cast<uint32_t>(st.wSecond) * 1000000;
@@ -69,7 +69,7 @@
 
 void* ContextFromNextGlobalSeed() {
   if (!g_bHaveGlobalSeed) {
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
     if (!GenerateSeedFromCryptoRandom(&g_nGlobalSeed))
       g_nGlobalSeed = GenerateSeedFromEnvironment();
 #else
diff --git a/core/fxcrt/fx_system.cpp b/core/fxcrt/fx_system.cpp
index d8e02c9..ca2f74b 100644
--- a/core/fxcrt/fx_system.cpp
+++ b/core/fxcrt/fx_system.cpp
@@ -15,7 +15,7 @@
 
 namespace {
 
-#if !defined(OS_WIN)
+#if !BUILDFLAG(IS_WIN)
 uint32_t g_last_error = 0;
 #endif
 
@@ -125,7 +125,7 @@
   return FXSYS_IntToStr<int64_t, uint64_t, char*>(value, str, radix);
 }
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 
 size_t FXSYS_wcsftime(wchar_t* strDest,
                       size_t maxsize,
@@ -145,7 +145,7 @@
   return wcsftime(strDest, maxsize, format, timeptr);
 }
 
-#else   // defined(OS_WIN)
+#else   // BUILDFLAG(IS_WIN)
 
 char* FXSYS_strlwr(char* str) {
   if (!str) {
@@ -227,7 +227,7 @@
 uint32_t FXSYS_GetLastError() {
   return g_last_error;
 }
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
 
 float FXSYS_sqrt2(float a, float b) {
   return sqrtf(a * a + b * b);
diff --git a/core/fxcrt/fx_system.h b/core/fxcrt/fx_system.h
index 03ce86b..cdb6867 100644
--- a/core/fxcrt/fx_system.h
+++ b/core/fxcrt/fx_system.h
@@ -25,9 +25,9 @@
 #error Cannot compile v8 with wasm.
 #endif  // PDF_ENABLE_V8
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #include <windows.h>
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
 
 #ifdef __cplusplus
 extern "C" {
@@ -51,7 +51,7 @@
 #define FXSYS_sprintf DO_NOT_USE_SPRINTF_DIE_DIE_DIE
 #define FXSYS_vsprintf DO_NOT_USE_VSPRINTF_DIE_DIE_DIE
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #define FXSYS_itoa _itoa
 #define FXSYS_strlwr _strlwr
 #define FXSYS_strupr _strupr
@@ -65,7 +65,7 @@
                       const struct tm* timeptr);
 #define FXSYS_SetLastError SetLastError
 #define FXSYS_GetLastError GetLastError
-#else  // defined(OS_WIN)
+#else  // BUILDFLAG(IS_WIN)
 char* FXSYS_itoa(int value, char* str, int radix);
 char* FXSYS_strlwr(char* str);
 char* FXSYS_strupr(char* str);
@@ -76,7 +76,7 @@
 #define FXSYS_wcsftime wcsftime
 void FXSYS_SetLastError(uint32_t err);
 uint32_t FXSYS_GetLastError();
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
 
 int32_t FXSYS_atoi(const char* str);
 uint32_t FXSYS_atoui(const char* str);
diff --git a/core/fxcrt/fx_system_unittest.cpp b/core/fxcrt/fx_system_unittest.cpp
index 6e109b6..1f33377 100644
--- a/core/fxcrt/fx_system_unittest.cpp
+++ b/core/fxcrt/fx_system_unittest.cpp
@@ -15,7 +15,7 @@
 // Unit test covering cases where PDFium replaces well-known library
 // functionality on any given platformn.
 
-#if !defined(OS_WIN)
+#if !BUILDFLAG(IS_WIN)
 
 namespace {
 
@@ -263,7 +263,7 @@
       "111111111111111111111111111111111111111111111111111111111111111");
 }
 
-#endif  // !defined(OS_WIN)
+#endif  // !BUILDFLAG(IS_WIN)
 
 TEST(fxcrt, FXSYS_wcsftime) {
   struct tm good_time = {};
diff --git a/core/fxcrt/fx_types.h b/core/fxcrt/fx_types.h
index b62131c..bbee34e 100644
--- a/core/fxcrt/fx_types.h
+++ b/core/fxcrt/fx_types.h
@@ -11,12 +11,12 @@
 
 // PDFium file sizes match the platform. The value must be signed to support -1
 // error returns.
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #include <stdint.h>
 #define FX_FILESIZE int64_t
 #else
 #include <sys/types.h>  // For off_t.
 #define FX_FILESIZE off_t
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
 
 #endif  // CORE_FXCRT_FX_TYPES_H_
diff --git a/core/fxcrt/widestring_unittest.cpp b/core/fxcrt/widestring_unittest.cpp
index a1c331e..c5ecc59 100644
--- a/core/fxcrt/widestring_unittest.cpp
+++ b/core/fxcrt/widestring_unittest.cpp
@@ -1224,7 +1224,7 @@
 
 TEST(WideString, ToDefANSI) {
   EXPECT_EQ("", WideString().ToDefANSI());
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   const char* kResult =
       "x"
       "?"
@@ -1276,7 +1276,7 @@
 
 TEST(WideString, FromDefANSI) {
   EXPECT_EQ(L"", WideString::FromDefANSI(ByteStringView()));
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   const wchar_t* kResult =
       L"x"
       L"\u20ac"
diff --git a/core/fxge/cfx_folderfontinfo.cpp b/core/fxge/cfx_folderfontinfo.cpp
index 7e69136..8df44f5 100644
--- a/core/fxge/cfx_folderfontinfo.cpp
+++ b/core/fxge/cfx_folderfontinfo.cpp
@@ -180,7 +180,7 @@
     }
 
     ByteString fullpath = path;
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
     fullpath += "\\";
 #else
     fullpath += "/";
diff --git a/core/fxge/cfx_font.cpp b/core/fxge/cfx_font.cpp
index a298301..771851c 100644
--- a/core/fxge/cfx_font.cpp
+++ b/core/fxge/cfx_font.cpp
@@ -231,7 +231,7 @@
     {static_cast<int>(FX_Charset::kShiftJIS), "MS Gothic"},
     {static_cast<int>(FX_Charset::kHangul), "Batang"},
     {static_cast<int>(FX_Charset::kMSWin_Cyrillic), "Arial"},
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
     {static_cast<int>(FX_Charset::kMSWin_EasternEuropean), "Tahoma"},
 #else
     {static_cast<int>(FX_Charset::kMSWin_EasternEuropean), "Arial"},
@@ -344,7 +344,7 @@
   return true;
 }
 
-#if !defined(OS_WIN)
+#if !BUILDFLAG(IS_WIN)
 void CFX_Font::SetFace(RetainPtr<CFX_Face> face) {
   ClearGlyphCache();
   m_ObjectTag = 0;
@@ -354,7 +354,7 @@
 void CFX_Font::SetSubstFont(std::unique_ptr<CFX_SubstFont> subst) {
   m_pSubstFont = std::move(subst);
 }
-#endif  // !defined(OS_WIN)
+#endif  // !BUILDFLAG(IS_WIN)
 #endif  // PDF_ENABLE_XFA
 
 CFX_Font::~CFX_Font() {
diff --git a/core/fxge/cfx_font.h b/core/fxge/cfx_font.h
index dd9a995..a45fc3b 100644
--- a/core/fxge/cfx_font.h
+++ b/core/fxge/cfx_font.h
@@ -89,11 +89,11 @@
 #if defined(PDF_ENABLE_XFA)
   bool LoadFile(RetainPtr<IFX_SeekableReadStream> pFile, int nFaceIndex);
 
-#if !defined(OS_WIN)
+#if !BUILDFLAG(IS_WIN)
   void SetFace(RetainPtr<CFX_Face> face);
   void SetFontSpan(pdfium::span<uint8_t> pSpan) { m_FontData = pSpan; }
   void SetSubstFont(std::unique_ptr<CFX_SubstFont> subst);
-#endif  // !defined(OS_WIN)
+#endif  // !BUILDFLAG(IS_WIN)
 #endif  // defined(PDF_ENABLE_XFA)
 
   const CFX_GlyphBitmap* LoadGlyphBitmap(
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index 510f54d..56b393e 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -694,7 +694,7 @@
   return false;
 }
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 absl::optional<ByteString> CFX_FontMapper::InstalledFontNameStartingWith(
     const ByteString& name) const {
   for (const auto& thisname : m_InstalledTTFonts) {
@@ -712,7 +712,7 @@
   }
   return absl::nullopt;
 }
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
 
 #ifdef PDF_ENABLE_XFA
 std::unique_ptr<uint8_t, FxFreeDeleter> CFX_FontMapper::RawBytesForIndex(
diff --git a/core/fxge/cfx_fontmapper.h b/core/fxge/cfx_fontmapper.h
index 956232e..183e59c 100644
--- a/core/fxge/cfx_fontmapper.h
+++ b/core/fxge/cfx_fontmapper.h
@@ -75,12 +75,12 @@
   bool HasInstalledFont(ByteStringView name) const;
   bool HasLocalizedFont(ByteStringView name) const;
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   absl::optional<ByteString> InstalledFontNameStartingWith(
       const ByteString& name) const;
   absl::optional<ByteString> LocalizedFontNameStartingWith(
       const ByteString& name) const;
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
 
 #ifdef PDF_ENABLE_XFA
   std::unique_ptr<uint8_t, FxFreeDeleter> RawBytesForIndex(
diff --git a/core/fxge/cfx_glyphcache.cpp b/core/fxge/cfx_glyphcache.cpp
index 253b1ab..82fa8d4 100644
--- a/core/fxge/cfx_glyphcache.cpp
+++ b/core/fxge/cfx_glyphcache.cpp
@@ -30,7 +30,7 @@
 #include "third_party/skia/include/core/SkStream.h"  // nogncheck
 #include "third_party/skia/include/core/SkTypeface.h"  // nogncheck
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #include "third_party/skia/include/core/SkFontMgr.h"  // nogncheck
 #include "third_party/skia/include/ports/SkFontMgr_empty.h"  // nogncheck
 #endif
@@ -317,14 +317,14 @@
     m_pTypeface = SkTypeface::MakeFromStream(
         std::make_unique<SkMemoryStream>(span.data(), span.size()));
   }
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   if (!m_pTypeface) {
     sk_sp<SkFontMgr> customMgr(SkFontMgr_New_Custom_Empty());
     pdfium::span<const uint8_t> span = pFont->GetFontSpan();
     m_pTypeface = customMgr->makeFromStream(
         std::make_unique<SkMemoryStream>(span.data(), span.size()));
   }
-#endif  // defined(OS_WIN)
+#endif  // BUILDFLAG(IS_WIN)
   return m_pTypeface.get();
 }
 #endif  // defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
diff --git a/core/fxge/dib/fx_dib.cpp b/core/fxge/dib/fx_dib.cpp
index ed275cc..c59ab3e 100644
--- a/core/fxge/dib/fx_dib.cpp
+++ b/core/fxge/dib/fx_dib.cpp
@@ -11,11 +11,11 @@
 
 #include "build/build_config.h"
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #include <windows.h>
 #endif
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 static_assert(sizeof(FX_COLORREF) == sizeof(COLORREF),
               "FX_COLORREF vs. COLORREF mismatch");
 #endif