Merge to XFA: Switch most min/max macros to std::min/max.

Fix lint errors along the way.

R=tsepez@chromium.org
TBR=tsepez@chromium.org

Review URL: https://codereview.chromium.org/1567343002 .

(cherry picked from commit 9adfbb0920a258e916003b1ee9515e97879db82a)

Review URL: https://codereview.chromium.org/1577503002 .
diff --git a/core/include/fxcrt/fx_basic.h b/core/include/fxcrt/fx_basic.h
index 4aa823e..4e7c8c8 100644
--- a/core/include/fxcrt/fx_basic.h
+++ b/core/include/fxcrt/fx_basic.h
@@ -7,6 +7,8 @@
 #ifndef CORE_INCLUDE_FXCRT_FX_BASIC_H_
 #define CORE_INCLUDE_FXCRT_FX_BASIC_H_
 
+#include <algorithm>
+
 #include "fx_memory.h"
 #include "fx_stream.h"
 #include "fx_string.h"
@@ -1096,7 +1098,7 @@
       return;
     }
     while (nCount > 0) {
-      int32_t temp_count = FX_MIN(nCount, FX_DATALIST_LENGTH);
+      int32_t temp_count = std::min(nCount, FX_DATALIST_LENGTH);
       DataList list;
       list.data = FX_Alloc2D(uint8_t, temp_count, unit);
       list.start = nStart;
diff --git a/core/include/fxcrt/fx_system.h b/core/include/fxcrt/fx_system.h
index e0412a0..2fbab98 100644
--- a/core/include/fxcrt/fx_system.h
+++ b/core/include/fxcrt/fx_system.h
@@ -110,7 +110,6 @@
 #endif
 #endif
 
-#define FX_MAX(a, b) (((a) > (b)) ? (a) : (b))
 #define FX_MIN(a, b) (((a) < (b)) ? (a) : (b))
 #define FX_PI 3.1415926535897932384626433832795f
 
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
index 168cbf3..87b9e02 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
@@ -8,6 +8,8 @@
 
 #include <limits.h>
 
+#include <algorithm>
+
 #include "core/include/fpdfapi/fpdf_page.h"
 #include "core/include/fpdfapi/fpdf_module.h"
 #include "core/include/fxcodec/fx_codec.h"
@@ -41,6 +43,24 @@
   return 4;
 }
 
+void ReverseRGB(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels) {
+  if (pDestBuf == pSrcBuf) {
+    for (int i = 0; i < pixels; i++) {
+      uint8_t temp = pDestBuf[2];
+      pDestBuf[2] = pDestBuf[0];
+      pDestBuf[0] = temp;
+      pDestBuf += 3;
+    }
+  } else {
+    for (int i = 0; i < pixels; i++) {
+      *pDestBuf++ = pSrcBuf[2];
+      *pDestBuf++ = pSrcBuf[1];
+      *pDestBuf++ = pSrcBuf[0];
+      pSrcBuf += 3;
+    }
+  }
+}
+
 }  // namespace
 
 CPDF_DeviceCS::CPDF_DeviceCS(CPDF_Document* pDoc, int family)
@@ -82,9 +102,9 @@
       AdobeCMYK_to_sRGB(pBuf[0], pBuf[1], pBuf[2], pBuf[3], R, G, B);
     } else {
       FX_FLOAT k = pBuf[3];
-      R = 1.0f - FX_MIN(1.0f, pBuf[0] + k);
-      G = 1.0f - FX_MIN(1.0f, pBuf[1] + k);
-      B = 1.0f - FX_MIN(1.0f, pBuf[2] + k);
+      R = 1.0f - std::min(1.0f, pBuf[0] + k);
+      G = 1.0f - std::min(1.0f, pBuf[1] + k);
+      B = 1.0f - std::min(1.0f, pBuf[2] + k);
     }
   } else {
     ASSERT(m_Family == PDFCS_PATTERN);
@@ -148,22 +168,7 @@
   }
   return FALSE;
 }
-static void ReverseRGB(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels) {
-  if (pDestBuf == pSrcBuf)
-    for (int i = 0; i < pixels; i++) {
-      uint8_t temp = pDestBuf[2];
-      pDestBuf[2] = pDestBuf[0];
-      pDestBuf[0] = temp;
-      pDestBuf += 3;
-    }
-  else
-    for (int i = 0; i < pixels; i++) {
-      *pDestBuf++ = pSrcBuf[2];
-      *pDestBuf++ = pSrcBuf[1];
-      *pDestBuf++ = pSrcBuf[0];
-      pSrcBuf += 3;
-    }
-}
+
 void CPDF_DeviceCS::TranslateImageLine(uint8_t* pDestBuf,
                                        const uint8_t* pSrcBuf,
                                        int pixels,
@@ -196,9 +201,9 @@
                            pDestBuf[2], pDestBuf[1], pDestBuf[0]);
       } else {
         uint8_t k = pSrcBuf[3];
-        pDestBuf[2] = 255 - FX_MIN(255, pSrcBuf[0] + k);
-        pDestBuf[1] = 255 - FX_MIN(255, pSrcBuf[1] + k);
-        pDestBuf[0] = 255 - FX_MIN(255, pSrcBuf[2] + k);
+        pDestBuf[2] = 255 - std::min(255, pSrcBuf[0] + k);
+        pDestBuf[1] = 255 - std::min(255, pSrcBuf[1] + k);
+        pDestBuf[0] = 255 - std::min(255, pSrcBuf[2] + k);
       }
       pSrcBuf += 4;
       pDestBuf += 3;
@@ -1012,11 +1017,13 @@
 }
 class CPDF_SeparationCS : public CPDF_ColorSpace {
  public:
-  CPDF_SeparationCS(CPDF_Document* pDoc)
+  explicit CPDF_SeparationCS(CPDF_Document* pDoc)
       : CPDF_ColorSpace(pDoc, PDFCS_SEPARATION, 1),
         m_pAltCS(nullptr),
         m_pFunc(nullptr) {}
   ~CPDF_SeparationCS() override;
+
+  // CPDF_ColorSpace:
   void GetDefaultValue(int iComponent,
                        FX_FLOAT& value,
                        FX_FLOAT& min,
@@ -1109,11 +1116,13 @@
 }
 class CPDF_DeviceNCS : public CPDF_ColorSpace {
  public:
-  CPDF_DeviceNCS(CPDF_Document* pDoc)
+  explicit CPDF_DeviceNCS(CPDF_Document* pDoc)
       : CPDF_ColorSpace(pDoc, PDFCS_DEVICEN, 0),
         m_pAltCS(nullptr),
         m_pFunc(nullptr) {}
   ~CPDF_DeviceNCS() override;
+
+  // CPDF_ColorSpace:
   void GetDefaultValue(int iComponent,
                        FX_FLOAT& value,
                        FX_FLOAT& min,
@@ -1183,10 +1192,11 @@
     m_pAltCS->EnableStdConversion(bEnabled);
   }
 }
+
 CPDF_ColorSpace* CPDF_ColorSpace::GetStockCS(int family) {
   return CPDF_ModuleMgr::Get()->GetPageModule()->GetStockCS(family);
-  ;
 }
+
 CPDF_ColorSpace* _CSFromName(const CFX_ByteString& name) {
   if (name == "DeviceRGB" || name == "RGB") {
     return CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB);
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
index c74aea9..f690c20 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
@@ -6,6 +6,7 @@
 
 #include "render_int.h"
 
+#include <algorithm>
 #include <memory>
 #include <vector>
 
@@ -573,8 +574,8 @@
         for (FX_DWORD i = 0; i < m_nComponents; i++) {
           int min_num = pArray->GetInteger(i * 2);
           int max_num = pArray->GetInteger(i * 2 + 1);
-          pCompData[i].m_ColorKeyMin = FX_MAX(min_num, 0);
-          pCompData[i].m_ColorKeyMax = FX_MIN(max_num, max_data);
+          pCompData[i].m_ColorKeyMin = std::max(min_num, 0);
+          pCompData[i].m_ColorKeyMax = std::min(max_num, max_data);
         }
       }
       bColorKey = TRUE;
diff --git a/core/src/fpdfdoc/doc_formcontrol.cpp b/core/src/fpdfdoc/doc_formcontrol.cpp
index bd339e3..6c3d1ec 100644
--- a/core/src/fpdfdoc/doc_formcontrol.cpp
+++ b/core/src/fpdfdoc/doc_formcontrol.cpp
@@ -4,6 +4,8 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
+#include <algorithm>
+
 #include "core/include/fpdfdoc/fpdf_doc.h"
 
 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField,
@@ -353,9 +355,9 @@
     FX_FLOAT m = pEntry->GetNumber(1);
     FX_FLOAT y = pEntry->GetNumber(2);
     FX_FLOAT k = pEntry->GetNumber(3);
-    FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
-    FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
-    FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
+    FX_FLOAT r = 1.0f - std::min(1.0f, c + k);
+    FX_FLOAT g = 1.0f - std::min(1.0f, m + k);
+    FX_FLOAT b = 1.0f - std::min(1.0f, y + k);
     color = ArgbEncode(255, (int)(r * 255), (int)(g * 255), (int)(b * 255));
   }
   return color;
diff --git a/core/src/fpdfdoc/doc_utils.cpp b/core/src/fpdfdoc/doc_utils.cpp
index 8983673..4856cb5 100644
--- a/core/src/fpdfdoc/doc_utils.cpp
+++ b/core/src/fpdfdoc/doc_utils.cpp
@@ -4,6 +4,8 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
+#include <algorithm>
+
 #include "core/include/fpdfdoc/fpdf_doc.h"
 #include "doc_utils.h"
 
@@ -179,9 +181,9 @@
     FX_FLOAT m = FX_atof((CFX_ByteString)syntax.GetWord());
     FX_FLOAT y = FX_atof((CFX_ByteString)syntax.GetWord());
     FX_FLOAT k = FX_atof((CFX_ByteString)syntax.GetWord());
-    FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
-    FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
-    FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
+    FX_FLOAT r = 1.0f - std::min(1.0f, c + k);
+    FX_FLOAT g = 1.0f - std::min(1.0f, m + k);
+    FX_FLOAT b = 1.0f - std::min(1.0f, y + k);
     color = ArgbEncode(255, (int)(r * 255 + 0.5f), (int)(g * 255 + 0.5f),
                        (int)(b * 255 + 0.5f));
   }
diff --git a/core/src/fpdfdoc/doc_vt.cpp b/core/src/fpdfdoc/doc_vt.cpp
index 8df687e..e5c9ad8 100644
--- a/core/src/fpdfdoc/doc_vt.cpp
+++ b/core/src/fpdfdoc/doc_vt.cpp
@@ -4,6 +4,8 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
+#include <algorithm>
+
 #include "core/include/fpdfdoc/fpdf_doc.h"
 #include "core/include/fpdfdoc/fpdf_vt.h"
 #include "pdf_vt.h"
@@ -72,7 +74,7 @@
                                  const CPVT_WordInfo& wordinfo) {
   CPVT_WordInfo* pWord = new CPVT_WordInfo(wordinfo);
   int32_t nWordIndex =
-      FPDF_MAX(FPDF_MIN(place.nWordIndex, m_WordArray.GetSize()), 0);
+      std::max(std::min(place.nWordIndex, m_WordArray.GetSize()), 0);
   if (nWordIndex == m_WordArray.GetSize()) {
     m_WordArray.Add(pWord);
   } else {
@@ -356,17 +358,17 @@
         if (w == 0) {
           pLine->m_LineInfo.fLineX = x;
         }
-        if (w != m_pSection->m_WordArray.GetSize() - 1)
+        if (w != m_pSection->m_WordArray.GetSize() - 1) {
           pWord->fWordTail =
               (fNodeWidth - (fWordWidth + fNextWidth) * PVT_HALF > 0
                    ? fNodeWidth - (fWordWidth + fNextWidth) * PVT_HALF
                    : 0);
-        else {
+        } else {
           pWord->fWordTail = 0;
         }
         x += fWordWidth;
-        fLineAscent = FPDF_MAX(fLineAscent, fWordAscent);
-        fLineDescent = FPDF_MIN(fLineDescent, fWordDescent);
+        fLineAscent = std::max(fLineAscent, fWordAscent);
+        fLineDescent = std::min(fLineDescent, fWordDescent);
       }
     }
     pLine->m_LineInfo.nBeginWordIndex = 0;
@@ -582,7 +584,7 @@
   int32_t nCharIndex = 0;
   CPVT_LineInfo line;
   FX_FLOAT fWordWidth = 0;
-  FX_FLOAT fTypesetWidth = FPDF_MAX(
+  FX_FLOAT fTypesetWidth = std::max(
       m_pVT->GetPlateWidth() - m_pVT->GetLineIndent(m_pSection->m_SecInfo),
       0.0f);
   int32_t nTotalWords = m_pSection->m_WordArray.GetSize();
@@ -598,15 +600,15 @@
       if (pWord) {
         if (bTypeset) {
           fLineAscent =
-              FPDF_MAX(fLineAscent, m_pVT->GetWordAscent(*pWord, TRUE));
+              std::max(fLineAscent, m_pVT->GetWordAscent(*pWord, TRUE));
           fLineDescent =
-              FPDF_MIN(fLineDescent, m_pVT->GetWordDescent(*pWord, TRUE));
+              std::min(fLineDescent, m_pVT->GetWordDescent(*pWord, TRUE));
           fWordWidth = m_pVT->GetWordWidth(*pWord);
         } else {
           fLineAscent =
-              FPDF_MAX(fLineAscent, m_pVT->GetWordAscent(*pWord, fFontSize));
+              std::max(fLineAscent, m_pVT->GetWordAscent(*pWord, fFontSize));
           fLineDescent =
-              FPDF_MIN(fLineDescent, m_pVT->GetWordDescent(*pWord, fFontSize));
+              std::min(fLineDescent, m_pVT->GetWordDescent(*pWord, fFontSize));
           fWordWidth = m_pVT->GetWordWidth(
               pWord->nFontIndex, pWord->Word, m_pVT->m_wSubWord,
               m_pVT->m_fCharSpace, m_pVT->m_nHorzScale, fFontSize,
@@ -662,7 +664,7 @@
         }
         fMaxY += (fLineAscent + m_pVT->GetLineLeading(m_pSection->m_SecInfo));
         fMaxY += (-fLineDescent);
-        fMaxX = FPDF_MAX(fLineWidth, fMaxX);
+        fMaxX = std::max(fLineWidth, fMaxX);
         nLineHead = i;
         fLineWidth = 0.0f;
         fLineAscent = 0.0f;
@@ -688,7 +690,7 @@
       }
       fMaxY += (fLineAscent + m_pVT->GetLineLeading(m_pSection->m_SecInfo));
       fMaxY += (-fLineDescent);
-      fMaxX = FPDF_MAX(fLineWidth, fMaxX);
+      fMaxX = std::max(fLineWidth, fMaxX);
     }
   } else {
     if (bTypeset) {
@@ -720,7 +722,7 @@
   FX_FLOAT fMinX = 0.0f, fMinY = 0.0f, fMaxX = 0.0f, fMaxY = 0.0f;
   FX_FLOAT fPosX = 0.0f, fPosY = 0.0f;
   FX_FLOAT fLineIndent = m_pVT->GetLineIndent(m_pSection->m_SecInfo);
-  FX_FLOAT fTypesetWidth = FPDF_MAX(m_pVT->GetPlateWidth() - fLineIndent, 0.0f);
+  FX_FLOAT fTypesetWidth = std::max(m_pVT->GetPlateWidth() - fLineIndent, 0.0f);
   switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) {
     default:
     case 0:
@@ -1259,7 +1261,7 @@
     return place;
   }
   int32_t nSecIndex =
-      FPDF_MAX(FPDF_MIN(place.nSecIndex, m_SectionArray.GetSize()), 0);
+      std::max(std::min(place.nSecIndex, m_SectionArray.GetSize()), 0);
   CSection* pSection = new CSection(this);
   pSection->m_SecInfo = secinfo;
   pSection->SecPlace.nSecIndex = nSecIndex;
@@ -1287,7 +1289,7 @@
   }
   CPVT_WordPlace newplace = place;
   newplace.nSecIndex =
-      FPDF_MAX(FPDF_MIN(newplace.nSecIndex, m_SectionArray.GetSize() - 1), 0);
+      std::max(std::min(newplace.nSecIndex, m_SectionArray.GetSize() - 1), 0);
   if (CSection* pSection = m_SectionArray.GetAt(newplace.nSecIndex)) {
     return pSection->AddWord(newplace, wordinfo);
   }
@@ -1332,7 +1334,7 @@
   return FALSE;
 }
 CPDF_Rect CPDF_VariableText::GetContentRect() const {
-  return InToOut(CPDF_EditContainer::GetContentRect());
+  return InToOut(CPVT_FloatRect(CPDF_EditContainer::GetContentRect()));
 }
 FX_FLOAT CPDF_VariableText::GetWordFontSize(const CPVT_WordInfo& WordInfo,
                                             FX_BOOL bFactFontSize) {
@@ -1576,7 +1578,7 @@
   for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) {
     if (CSection* pSection = m_SectionArray.GetAt(s)) {
       CPVT_Size size = pSection->GetSectionSize(fFontSize);
-      szTotal.x = FPDF_MAX(size.x, szTotal.x);
+      szTotal.x = std::max(size.x, szTotal.x);
       szTotal.y += size.y;
       if (IsFloatBigger(szTotal.x, GetPlateWidth()) ||
           IsFloatBigger(szTotal.y, GetPlateHeight())) {
@@ -1617,10 +1619,10 @@
       if (s == 0) {
         rcRet = rcSec;
       } else {
-        rcRet.left = FPDF_MIN(rcSec.left, rcRet.left);
-        rcRet.top = FPDF_MIN(rcSec.top, rcRet.top);
-        rcRet.right = FPDF_MAX(rcSec.right, rcRet.right);
-        rcRet.bottom = FPDF_MAX(rcSec.bottom, rcRet.bottom);
+        rcRet.left = std::min(rcSec.left, rcRet.left);
+        rcRet.top = std::min(rcSec.top, rcRet.top);
+        rcRet.right = std::max(rcSec.right, rcRet.right);
+        rcRet.bottom = std::max(rcSec.bottom, rcRet.bottom);
       }
       fPosY += rcSec.Height();
     }
diff --git a/core/src/fpdfdoc/pdf_vt.h b/core/src/fpdfdoc/pdf_vt.h
index 2cd673f..286fad5 100644
--- a/core/src/fpdfdoc/pdf_vt.h
+++ b/core/src/fpdfdoc/pdf_vt.h
@@ -22,14 +22,7 @@
 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
-template <class T>
-T FPDF_MIN(const T& i, const T& j) {
-  return ((i < j) ? i : j);
-}
-template <class T>
-T FPDF_MAX(const T& i, const T& j) {
-  return ((i > j) ? i : j);
-}
+
 class CPVT_Size {
  public:
   CPVT_Size() : x(0.0f), y(0.0f) {}
@@ -51,7 +44,7 @@
     right = other_right;
     bottom = other_bottom;
   }
-  CPVT_FloatRect(const CPDF_Rect& rect) {
+  explicit CPVT_FloatRect(const CPDF_Rect& rect) {
     left = rect.left;
     top = rect.top;
     right = rect.right;
@@ -246,7 +239,7 @@
   friend class CTypeset;
 
  public:
-  CSection(CPDF_VariableText* pVT);
+  explicit CSection(CPDF_VariableText* pVT);
   virtual ~CSection();
   void ResetAll();
   void ResetLineArray();
@@ -285,7 +278,7 @@
 };
 class CTypeset {
  public:
-  CTypeset(CSection* pSection);
+  explicit CTypeset(CSection* pSection);
   virtual ~CTypeset();
   CPVT_Size GetEditSize(FX_FLOAT fFontSize);
   CPVT_FloatRect Typeset();
@@ -307,37 +300,37 @@
   virtual const CPDF_Rect& GetPlateRect() const { return m_rcPlate; }
   virtual void SetContentRect(const CPVT_FloatRect& rect) {
     m_rcContent = rect;
-  };
+  }
   virtual CPDF_Rect GetContentRect() const { return m_rcContent; }
   FX_FLOAT GetPlateWidth() const { return m_rcPlate.right - m_rcPlate.left; }
   FX_FLOAT GetPlateHeight() const { return m_rcPlate.top - m_rcPlate.bottom; }
   CPVT_Size GetPlateSize() const {
     return CPVT_Size(GetPlateWidth(), GetPlateHeight());
-  };
+  }
   CPDF_Point GetBTPoint() const {
     return CPDF_Point(m_rcPlate.left, m_rcPlate.top);
-  };
+  }
   CPDF_Point GetETPoint() const {
     return CPDF_Point(m_rcPlate.right, m_rcPlate.bottom);
-  };
+  }
   inline CPDF_Point InToOut(const CPDF_Point& point) const {
     return CPDF_Point(point.x + GetBTPoint().x, GetBTPoint().y - point.y);
-  };
+  }
   inline CPDF_Point OutToIn(const CPDF_Point& point) const {
     return CPDF_Point(point.x - GetBTPoint().x, GetBTPoint().y - point.y);
-  };
+  }
   inline CPDF_Rect InToOut(const CPVT_FloatRect& rect) const {
     CPDF_Point ptLeftTop = InToOut(CPDF_Point(rect.left, rect.top));
     CPDF_Point ptRightBottom = InToOut(CPDF_Point(rect.right, rect.bottom));
     return CPDF_Rect(ptLeftTop.x, ptRightBottom.y, ptRightBottom.x,
                      ptLeftTop.y);
-  };
+  }
   inline CPVT_FloatRect OutToIn(const CPDF_Rect& rect) const {
     CPDF_Point ptLeftTop = OutToIn(CPDF_Point(rect.left, rect.top));
     CPDF_Point ptRightBottom = OutToIn(CPDF_Point(rect.right, rect.bottom));
     return CPVT_FloatRect(ptLeftTop.x, ptLeftTop.y, ptRightBottom.x,
                           ptRightBottom.y);
-  };
+  }
 
  private:
   CPDF_Rect m_rcPlate;
@@ -539,7 +532,7 @@
 
 class CPDF_VariableText_Iterator : public IPDF_VariableText_Iterator {
  public:
-  CPDF_VariableText_Iterator(CPDF_VariableText* pVT);
+  explicit CPDF_VariableText_Iterator(CPDF_VariableText* pVT);
   ~CPDF_VariableText_Iterator() override;
 
   // IPDF_VariableText_Iterator
diff --git a/core/src/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp
index cf6cde1..f527f48 100644
--- a/core/src/fpdftext/fpdf_text_int.cpp
+++ b/core/src/fpdftext/fpdf_text_int.cpp
@@ -161,9 +161,9 @@
       PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(i);
       if (charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED) {
         bNormal = TRUE;
-      } else if (charinfo.m_Unicode == 0 || IsControlChar(charinfo))
+      } else if (charinfo.m_Unicode == 0 || IsControlChar(charinfo)) {
         bNormal = FALSE;
-      else {
+      } else {
         bNormal = TRUE;
       }
       if (bNormal) {
@@ -1807,10 +1807,10 @@
       }
       preChar = (PAGECHAR_INFO)m_charList[size - 1];
     }
-    if (FPDFTEXT_CHAR_PIECE == preChar.m_Flag)
-      if (0xAD == preChar.m_Unicode || 0x2D == preChar.m_Unicode) {
-        return TRUE;
-      }
+    if (FPDFTEXT_CHAR_PIECE == preChar.m_Flag &&
+        (0xAD == preChar.m_Unicode || 0x2D == preChar.m_Unicode)) {
+      return TRUE;
+    }
   }
   return FALSE;
 }
@@ -1920,17 +1920,14 @@
       }
     }
   }
-  if (bNewline) {
-    if (IsHyphen(curChar)) {
-      return 3;
-    }
-    return 2;
-  }
+  if (bNewline)
+    return IsHyphen(curChar) ? 3 : 2;
+
   int32_t nChars = pObj->CountChars();
-  if (nChars == 1 && (0x2D == curChar || 0xAD == curChar))
-    if (IsHyphen(curChar)) {
-      return 3;
-    }
+  if (nChars == 1 && (0x2D == curChar || 0xAD == curChar) &&
+      IsHyphen(curChar)) {
+    return 3;
+  }
   CFX_WideString PrevStr =
       m_pPreTextObj->GetFont()->UnicodeFromCharCode(PrevItem.m_CharCode);
   FX_WCHAR preChar = PrevStr.GetAt(PrevStr.GetLength() - 1);
@@ -1956,7 +1953,7 @@
     threshold *= 1.5;
   }
   if (FXSYS_fabs(last_pos + last_width - x) > threshold && curChar != L' ' &&
-      preChar != L' ')
+      preChar != L' ') {
     if (curChar != L' ' && preChar != L' ') {
       if ((x - last_pos - last_width) > threshold ||
           (last_pos - x - last_width) > threshold) {
@@ -1970,6 +1967,7 @@
         return 1;
       }
     }
+  }
   return 0;
 }
 FX_BOOL CPDF_TextPage::IsSameTextObject(CPDF_TextObject* pTextObj1,
@@ -2023,8 +2021,8 @@
           GetCharWidth(itemPer.m_CharCode, pTextObj2->GetFont()) *
               pTextObj2->GetFontSize() / 1000 * 0.9 ||
       FXSYS_fabs(pTextObj1->GetPosY() - pTextObj2->GetPosY()) >
-          FX_MAX(FX_MAX(rcPreObj.Height(), rcPreObj.Width()),
-                 pTextObj2->GetFontSize()) /
+          std::max(std::max(rcPreObj.Height(), rcPreObj.Width()),
+                   pTextObj2->GetFontSize()) /
               8) {
     return FALSE;
   }
diff --git a/core/src/fxcodec/codec/fx_codec_png.cpp b/core/src/fxcodec/codec/fx_codec_png.cpp
index 6401081..3acfc19 100644
--- a/core/src/fxcodec/codec/fx_codec_png.cpp
+++ b/core/src/fxcodec/codec/fx_codec_png.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "core/include/fxcodec/fx_codec.h"

 #include "core/include/fxge/fx_dib.h"

 #include "codec_int.h"

@@ -62,24 +64,24 @@
 #endif

 #if defined(PNG_TEXT_SUPPORTED)

     int i;

-    FX_DWORD len;

+    FX_STRSIZE len;

     const FX_CHAR* buf;

     int num_text;

     png_textp text = NULL;

     png_get_text(png_ptr, info_ptr, &text, &num_text);

     for (i = 0; i < num_text; i++) {

-      len = (FX_DWORD)FXSYS_strlen(text[i].key);

+      len = FXSYS_strlen(text[i].key);

       buf = "Time";

-      if (!FXSYS_memcmp(buf, text[i].key, FX_MIN(len, FXSYS_strlen(buf)))) {

+      if (!FXSYS_memcmp(buf, text[i].key, std::min(len, FXSYS_strlen(buf)))) {

         if (!bTime) {

           FXSYS_memset(pAttribute->m_strTime, 0, sizeof(pAttribute->m_strTime));

           FXSYS_memcpy(

               pAttribute->m_strTime, text[i].text,

-              FX_MIN(sizeof(pAttribute->m_strTime) - 1, text[i].text_length));

+              std::min(sizeof(pAttribute->m_strTime) - 1, text[i].text_length));

         }

       } else {

         buf = "Author";

-        if (!FXSYS_memcmp(buf, text[i].key, FX_MIN(len, FXSYS_strlen(buf)))) {

+        if (!FXSYS_memcmp(buf, text[i].key, std::min(len, FXSYS_strlen(buf)))) {

           pAttribute->m_strAuthor.Empty();

           pAttribute->m_strAuthor.Load((uint8_t*)text[i].text,

                                        (FX_STRSIZE)text[i].text_length);

diff --git a/core/src/fxcodec/lbmp/fx_bmp.cpp b/core/src/fxcodec/lbmp/fx_bmp.cpp
index 98bcefd..0047758 100644
--- a/core/src/fxcodec/lbmp/fx_bmp.cpp
+++ b/core/src/fxcodec/lbmp/fx_bmp.cpp
@@ -5,6 +5,16 @@
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

 #include "fx_bmp.h"

+

+#include <algorithm>

+

+namespace {

+

+const size_t kBmpCoreHeaderSize = 12;

+const size_t kBmpInfoHeaderSize = 40;

+

+}  // namespace

+

 FX_DWORD _GetDWord_LSBFirst(uint8_t* p) {

   return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);

 }

@@ -80,10 +90,12 @@
     bmp_ptr->img_ifh_size =

         _GetDWord_LSBFirst(bmp_ptr->next_in + bmp_ptr->skip_size);

     bmp_ptr->pal_type = 0;

-    ASSERT(sizeof(BmpCoreHeader) == 12);

-    ASSERT(sizeof(BmpInfoHeader) == 40);

+    static_assert(sizeof(BmpCoreHeader) == kBmpCoreHeaderSize,

+                  "BmpCoreHeader has wrong size");

+    static_assert(sizeof(BmpInfoHeader) == kBmpInfoHeaderSize,

+                  "BmpInfoHeader has wrong size");

     switch (bmp_ptr->img_ifh_size) {

-      case FX_MIN(12, sizeof(BmpCoreHeader)): {

+      case kBmpCoreHeaderSize: {

         bmp_ptr->pal_type = 1;

         BmpCoreHeaderPtr bmp_core_header_ptr = NULL;

         if (_bmp_read_data(bmp_ptr, (uint8_t**)&bmp_core_header_ptr,

@@ -100,7 +112,7 @@
         bmp_ptr->compress_flag = BMP_RGB;

         bmp_ptr->imgTB_flag = FALSE;

       } break;

-      case FX_MIN(40, sizeof(BmpInfoHeader)): {

+      case kBmpInfoHeaderSize: {

         BmpInfoHeaderPtr bmp_info_header_ptr = NULL;

         if (_bmp_read_data(bmp_ptr, (uint8_t**)&bmp_info_header_ptr,

                            bmp_ptr->img_ifh_size) == NULL) {

@@ -127,7 +139,8 @@
         }

       } break;

       default: {

-        if (bmp_ptr->img_ifh_size > FX_MIN(40, sizeof(BmpInfoHeader))) {

+        if (bmp_ptr->img_ifh_size >

+            std::min(kBmpInfoHeaderSize, sizeof(BmpInfoHeader))) {

           BmpInfoHeaderPtr bmp_info_header_ptr = NULL;

           if (_bmp_read_data(bmp_ptr, (uint8_t**)&bmp_info_header_ptr,

                              bmp_ptr->img_ifh_size) == NULL) {

diff --git a/core/src/fxcrt/extension.h b/core/src/fxcrt/extension.h
index 638ffef..6e799eb 100644
--- a/core/src/fxcrt/extension.h
+++ b/core/src/fxcrt/extension.h
@@ -7,6 +7,8 @@
 #ifndef CORE_SRC_FXCRT_EXTENSION_H_
 #define CORE_SRC_FXCRT_EXTENSION_H_
 
+#include <algorithm>
+
 #include "core/include/fxcrt/fx_basic.h"
 #include "core/include/fxcrt/fx_safe_types.h"
 
@@ -67,39 +69,21 @@
 
 class CFX_CRTFileStream final : public IFX_FileStream {
  public:
-  CFX_CRTFileStream(IFXCRT_FileAccess* pFA) : m_pFile(pFA), m_dwCount(1) {}
-  ~CFX_CRTFileStream() override {
-    if (m_pFile) {
-      m_pFile->Release();
-    }
-  }
-  virtual IFX_FileStream* Retain() override {
-    m_dwCount++;
-    return this;
-  }
-  virtual void Release() override {
-    FX_DWORD nCount = --m_dwCount;
-    if (!nCount) {
-      delete this;
-    }
-  }
-  virtual FX_FILESIZE GetSize() override { return m_pFile->GetSize(); }
-  virtual FX_BOOL IsEOF() override { return GetPosition() >= GetSize(); }
-  virtual FX_FILESIZE GetPosition() override { return m_pFile->GetPosition(); }
-  virtual FX_BOOL ReadBlock(void* buffer,
-                            FX_FILESIZE offset,
-                            size_t size) override {
-    return (FX_BOOL)m_pFile->ReadPos(buffer, size, offset);
-  }
-  virtual size_t ReadBlock(void* buffer, size_t size) override {
-    return m_pFile->Read(buffer, size);
-  }
-  virtual FX_BOOL WriteBlock(const void* buffer,
-                             FX_FILESIZE offset,
-                             size_t size) override {
-    return (FX_BOOL)m_pFile->WritePos(buffer, size, offset);
-  }
-  virtual FX_BOOL Flush() override { return m_pFile->Flush(); }
+  explicit CFX_CRTFileStream(IFXCRT_FileAccess* pFA);
+  ~CFX_CRTFileStream() override;
+
+  // IFX_FileStream:
+  IFX_FileStream* Retain() override;
+  void Release() override;
+  FX_FILESIZE GetSize() override;
+  FX_BOOL IsEOF() override;
+  FX_FILESIZE GetPosition() override;
+  FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
+  size_t ReadBlock(void* buffer, size_t size) override;
+  FX_BOOL WriteBlock(const void* buffer,
+                     FX_FILESIZE offset,
+                     size_t size) override;
+  FX_BOOL Flush() override;
 
  protected:
   IFXCRT_FileAccess* m_pFile;
@@ -111,7 +95,7 @@
 #define FX_MEMSTREAM_TakeOver 0x02
 class CFX_MemoryStream final : public IFX_MemoryStream {
  public:
-  CFX_MemoryStream(FX_BOOL bConsecutive)
+  explicit CFX_MemoryStream(FX_BOOL bConsecutive)
       : m_dwCount(1),
         m_nTotalSize(0),
         m_nCurSize(0),
@@ -190,7 +174,7 @@
     if (m_nCurPos >= m_nCurSize) {
       return 0;
     }
-    size_t nRead = FX_MIN(size, m_nCurSize - m_nCurPos);
+    size_t nRead = std::min(size, m_nCurSize - m_nCurPos);
     if (!ReadBlock(buffer, (int32_t)m_nCurPos, nRead)) {
       return 0;
     }
@@ -262,12 +246,13 @@
   void EstimateSize(size_t nInitSize, size_t nGrowSize) override {
     if (m_dwFlags & FX_MEMSTREAM_Consecutive) {
       if (m_Blocks.GetSize() < 1) {
-        uint8_t* pBlock = FX_Alloc(uint8_t, FX_MAX(nInitSize, 4096));
+        uint8_t* pBlock =
+            FX_Alloc(uint8_t, std::max(nInitSize, static_cast<size_t>(4096)));
         m_Blocks.Add(pBlock);
       }
-      m_nGrowSize = FX_MAX(nGrowSize, 4096);
+      m_nGrowSize = std::max(nGrowSize, static_cast<size_t>(4096));
     } else if (m_Blocks.GetSize() < 1) {
-      m_nGrowSize = FX_MAX(nGrowSize, 4096);
+      m_nGrowSize = std::max(nGrowSize, static_cast<size_t>(4096));
     }
   }
   uint8_t* GetBuffer() const override {
diff --git a/core/src/fxcrt/fx_basic_buffer.cpp b/core/src/fxcrt/fx_basic_buffer.cpp
index e5c6c6d..4ef86bb 100644
--- a/core/src/fxcrt/fx_basic_buffer.cpp
+++ b/core/src/fxcrt/fx_basic_buffer.cpp
@@ -4,6 +4,8 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
+#include <algorithm>
+
 #include "core/include/fxcrt/fx_basic.h"
 
 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf);
@@ -401,7 +403,7 @@
   uint8_t* buffer = (uint8_t*)pBuf;
   FX_STRSIZE temp_size = (FX_STRSIZE)size;
   while (temp_size > 0) {
-    FX_STRSIZE buf_size = FX_MIN(m_BufSize - m_Length, (FX_STRSIZE)temp_size);
+    FX_STRSIZE buf_size = std::min(m_BufSize - m_Length, (FX_STRSIZE)temp_size);
     FXSYS_memcpy(m_pBuffer + m_Length, buffer, buf_size);
     m_Length += buf_size;
     if (m_Length == m_BufSize) {
diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp
index dd26f59..2370c87 100644
--- a/core/src/fxcrt/fx_basic_wstring.cpp
+++ b/core/src/fxcrt/fx_basic_wstring.cpp
@@ -5,6 +5,8 @@
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
 #include <stddef.h>  // For offsetof().
+
+#include <algorithm>
 #include <cctype>
 
 #include "core/include/fxcrt/fx_basic.h"
@@ -639,7 +641,7 @@
       pOldData->Release();
     }
     lpszStart = m_pData->m_String;
-    lpszEnd = m_pData->m_String + FX_MAX(m_pData->m_nDataLength, nNewLength);
+    lpszEnd = m_pData->m_String + std::max(m_pData->m_nDataLength, nNewLength);
     {
       while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) !=
                  NULL &&
@@ -758,9 +760,7 @@
         nMaxLen += 2;
       } else if (*lpsz == '*') {
         nWidth = va_arg(argList, int);
-      } else if (*lpsz == '-' || *lpsz == '+' || *lpsz == '0' || *lpsz == ' ')
-        ;
-      else {
+      } else if (*lpsz != '-' && *lpsz != '+' && *lpsz != '0' && *lpsz != ' ') {
         break;
       }
     }
diff --git a/core/src/fxcrt/fx_extension.cpp b/core/src/fxcrt/fx_extension.cpp
index 4669ac4..8a6987b 100644
--- a/core/src/fxcrt/fx_extension.cpp
+++ b/core/src/fxcrt/fx_extension.cpp
@@ -14,6 +14,59 @@
 #include <ctime>
 #endif
 
+CFX_CRTFileStream::CFX_CRTFileStream(IFXCRT_FileAccess* pFA)
+    : m_pFile(pFA), m_dwCount(1) {}
+
+CFX_CRTFileStream::~CFX_CRTFileStream() {
+  if (m_pFile) {
+    m_pFile->Release();
+  }
+}
+
+IFX_FileStream* CFX_CRTFileStream::Retain() {
+  m_dwCount++;
+  return this;
+}
+
+void CFX_CRTFileStream::Release() {
+  FX_DWORD nCount = --m_dwCount;
+  if (!nCount) {
+    delete this;
+  }
+}
+
+FX_FILESIZE CFX_CRTFileStream::GetSize() {
+  return m_pFile->GetSize();
+}
+
+FX_BOOL CFX_CRTFileStream::IsEOF() {
+  return GetPosition() >= GetSize();
+}
+
+FX_FILESIZE CFX_CRTFileStream::GetPosition() {
+  return m_pFile->GetPosition();
+}
+
+FX_BOOL CFX_CRTFileStream::ReadBlock(void* buffer,
+                                     FX_FILESIZE offset,
+                                     size_t size) {
+  return (FX_BOOL)m_pFile->ReadPos(buffer, size, offset);
+}
+
+size_t CFX_CRTFileStream::ReadBlock(void* buffer, size_t size) {
+  return m_pFile->Read(buffer, size);
+}
+
+FX_BOOL CFX_CRTFileStream::WriteBlock(const void* buffer,
+                                      FX_FILESIZE offset,
+                                      size_t size) {
+  return (FX_BOOL)m_pFile->WritePos(buffer, size, offset);
+}
+
+FX_BOOL CFX_CRTFileStream::Flush() {
+  return m_pFile->Flush();
+}
+
 #ifdef PDF_ENABLE_XFA
 IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath) {
   if (wsPath.GetLength() == 0)
diff --git a/core/src/fxcrt/xml_int.h b/core/src/fxcrt/xml_int.h
index b11a64b..a837327 100644
--- a/core/src/fxcrt/xml_int.h
+++ b/core/src/fxcrt/xml_int.h
@@ -7,6 +7,8 @@
 #ifndef CORE_SRC_FXCRT_XML_INT_H_
 #define CORE_SRC_FXCRT_XML_INT_H_
 
+#include <algorithm>
+
 #include "core/include/fxcrt/fx_stream.h"
 
 class CFX_UTF8Decoder;
@@ -43,10 +45,9 @@
   size_t m_dwCurPos;
 };
 
-#define FX_XMLDATASTREAM_BufferSize (32 * 1024)
 class CXML_DataStmAcc : public IFX_BufferRead {
  public:
-  CXML_DataStmAcc(IFX_FileRead* pFileRead)
+  explicit CXML_DataStmAcc(IFX_FileRead* pFileRead)
       : m_pFileRead(pFileRead), m_pBuffer(NULL), m_nStart(0), m_dwSize(0) {
     FXSYS_assert(m_pFileRead);
   }
@@ -69,7 +70,9 @@
     if (m_nStart >= nLength) {
       return FALSE;
     }
-    m_dwSize = (size_t)FX_MIN(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart);
+    static const FX_FILESIZE FX_XMLDATASTREAM_BufferSize = 32 * 1024;
+    m_dwSize = static_cast<size_t>(
+        std::min(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart));
     if (!m_pBuffer) {
       m_pBuffer = FX_Alloc(uint8_t, m_dwSize);
     }
diff --git a/core/src/fxge/agg/src/fx_agg_driver.cpp b/core/src/fxge/agg/src/fx_agg_driver.cpp
index ed2e8e4..6828531 100644
--- a/core/src/fxge/agg/src/fx_agg_driver.cpp
+++ b/core/src/fxge/agg/src/fx_agg_driver.cpp
@@ -6,6 +6,8 @@
 
 #include "core/src/fxge/agg/include/fx_agg_driver.h"
 
+#include <algorithm>
+
 #include "core/include/fxcodec/fx_codec.h"
 #include "core/include/fxge/fx_ge.h"
 #include "core/src/fxge/dib/dib_int.h"
@@ -19,20 +21,15 @@
 #include "third_party/agg23/agg_renderer_scanline.h"
 #include "third_party/agg23/agg_scanline_u.h"
 
-void _HardClip(FX_FLOAT& x, FX_FLOAT& y) {
-  if (x > 50000) {
-    x = 50000;
-  }
-  if (x < -50000) {
-    x = -50000;
-  }
-  if (y > 50000) {
-    y = 50000;
-  }
-  if (y < -50000) {
-    y = -50000;
-  }
+namespace {
+
+void HardClip(FX_FLOAT& x, FX_FLOAT& y) {
+  x = std::max(std::min(x, 50000.0f), -50000.0f);
+  y = std::max(std::min(y, 50000.0f), -50000.0f);
 }
+
+}  // namespace
+
 void CAgg_PathData::BuildPath(const CFX_PathData* pPathData,
                               const CFX_Matrix* pObject2Device) {
   int nPoints = pPathData->GetPointCount();
@@ -42,7 +39,7 @@
     if (pObject2Device) {
       pObject2Device->Transform(x, y);
     }
-    _HardClip(x, y);
+    HardClip(x, y);
     int point_type = pPoints[i].m_Flag & FXPT_TYPE;
     if (point_type == FXPT_MOVETO) {
       m_PathData.move_to(x, y);
@@ -73,6 +70,7 @@
   }
 }
 namespace agg {
+
 template <class BaseRenderer>
 class renderer_scanline_aa_offset {
  public:
@@ -109,7 +107,9 @@
   color_type m_color;
   unsigned m_left, m_top;
 };
-}
+
+}  // namespace agg
+
 static void RasterizeStroke(agg::rasterizer_scanline_aa& rasterizer,
                             agg::path_storage& path_data,
                             const CFX_Matrix* pObject2Device,
@@ -1257,8 +1257,8 @@
     }
     CFX_Matrix matrix1, matrix2;
     if (pObject2Device) {
-      matrix1.a =
-          FX_MAX(FXSYS_fabs(pObject2Device->a), FXSYS_fabs(pObject2Device->b));
+      matrix1.a = std::max(FXSYS_fabs(pObject2Device->a),
+                           FXSYS_fabs(pObject2Device->b));
       matrix1.d = matrix1.a;
       matrix2.Set(pObject2Device->a / matrix1.a, pObject2Device->b / matrix1.a,
                   pObject2Device->c / matrix1.d, pObject2Device->d / matrix1.d,
diff --git a/core/src/fxge/android/fpf_skiafont.cpp b/core/src/fxge/android/fpf_skiafont.cpp
index ba202ac..222b28e 100644
--- a/core/src/fxge/android/fpf_skiafont.cpp
+++ b/core/src/fxge/android/fpf_skiafont.cpp
@@ -5,6 +5,9 @@
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
 #include "fx_fpf.h"
+
+#include <algorithm>
+
 #if _FX_OS_ == _FX_ANDROID_
 #include "fpf_skiafont.h"
 #include "fpf_skiafontmgr.h"
@@ -106,8 +109,8 @@
     rtBBox.right = FPF_EM_ADJUST(x_ppem, cbox.xMax);
     rtBBox.top = FPF_EM_ADJUST(y_ppem, cbox.yMax);
     rtBBox.bottom = FPF_EM_ADJUST(y_ppem, cbox.yMin);
-    rtBBox.top = FX_MIN(rtBBox.top, GetAscent());
-    rtBBox.bottom = FX_MAX(rtBBox.bottom, GetDescent());
+    rtBBox.top = std::min(rtBBox.top, GetAscent());
+    rtBBox.bottom = std::max(rtBBox.bottom, GetDescent());
     FXFT_Done_Glyph(glyph);
     return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0;
   }
diff --git a/fpdfsdk/include/fxedit/fxet_edit.h b/fpdfsdk/include/fxedit/fxet_edit.h
index 1ecb704..d1df381 100644
--- a/fpdfsdk/include/fxedit/fxet_edit.h
+++ b/fpdfsdk/include/fxedit/fxet_edit.h
@@ -8,19 +8,10 @@
 #define FPDFSDK_INCLUDE_FXEDIT_FXET_EDIT_H_
 
 #include "core/include/fpdfdoc/fpdf_vt.h"
-#include "fx_edit.h"
+#include "fpdfsdk/include/fxedit/fx_edit.h"
 
-class CFX_Edit_Page;
-struct CFX_Edit_LineRect;
-class CFX_Edit_LineRectArray;
-class CFX_Edit_RectArray;
-class CFX_Edit_Refresh;
-class CFX_Edit_Select;
 class CFX_Edit;
 class CFX_Edit_Iterator;
-class CFX_Edit_Refresh;
-class CFX_Edit_UndoItem;
-class CFX_Edit_Undo;
 class CFX_Edit_Provider;
 
 #define FX_EDIT_IsFloatZero(f) (f < 0.0001 && f > -0.0001)
@@ -29,18 +20,6 @@
 #define FX_EDIT_IsFloatSmaller(fa, fb) \
   (fa < fb && !FX_EDIT_IsFloatEqual(fa, fb))
 
-template <class T>
-T FX_EDIT_MIN(const T& i, const T& j) {
-  return ((i < j) ? i : j);
-}
-template <class T>
-T FX_EDIT_MAX(const T& i, const T& j) {
-  return ((i > j) ? i : j);
-}
-
-#define FX_EDIT_PI 3.14159265358979f
-#define FX_EDIT_ITALIC_ANGEL 10 * FX_EDIT_PI / 180.0f
-
 /* ------------------------- CFX_Edit_Refresh ---------------------------- */
 
 enum REFRESH_PLAN_E { RP_ANALYSE, RP_NOANALYSE, RP_OPTIONAL };
@@ -195,7 +174,7 @@
     Set(begin, end);
   }
 
-  CFX_Edit_Select(const CPVT_WordRange& range) {
+  explicit CFX_Edit_Select(const CPVT_WordRange& range) {
     Set(range.BeginPos, range.EndPos);
   }
 
@@ -230,7 +209,7 @@
 
 class CFX_Edit_Undo {
  public:
-  CFX_Edit_Undo(int32_t nBufsize = 10000);
+  explicit CFX_Edit_Undo(int32_t nBufsize);
   virtual ~CFX_Edit_Undo();
 
   void Undo();
@@ -285,7 +264,7 @@
 
 class CFX_Edit_GroupUndoItem : public IFX_Edit_UndoItem {
  public:
-  CFX_Edit_GroupUndoItem(const CFX_WideString& sTitle);
+  explicit CFX_Edit_GroupUndoItem(const CFX_WideString& sTitle);
   ~CFX_Edit_GroupUndoItem() override;
 
   void Undo() override;
@@ -542,7 +521,7 @@
   friend class CFXEU_InsertText;
 
  public:
-  CFX_Edit(IPDF_VariableText* pVT);
+  explicit CFX_Edit(IPDF_VariableText* pVT);
   ~CFX_Edit() override;
 
   // IFX_Edit
@@ -813,7 +792,7 @@
 
 class CFX_Edit_Provider : public IPDF_VariableText_Provider {
  public:
-  CFX_Edit_Provider(IFX_Edit_FontMap* pFontMap);
+  explicit CFX_Edit_Provider(IFX_Edit_FontMap* pFontMap);
   ~CFX_Edit_Provider() override;
 
   IFX_Edit_FontMap* GetFontMap();
diff --git a/fpdfsdk/src/fpdf_flatten.cpp b/fpdfsdk/src/fpdf_flatten.cpp
index 2a0c2d9..50d5036 100644
--- a/fpdfsdk/src/fpdf_flatten.cpp
+++ b/fpdfsdk/src/fpdf_flatten.cpp
@@ -6,6 +6,8 @@
 
 #include "public/fpdf_flatten.h"
 
+#include <algorithm>
+
 #include "fpdfsdk/include/fsdk_define.h"
 
 typedef CFX_ArrayTemplate<CPDF_Dictionary*> CPDF_ObjectArray;
@@ -300,8 +302,8 @@
   FX_FLOAT x4 = matrix.a * rcStream.right + matrix.c * rcStream.top + matrix.e;
   FX_FLOAT y4 = matrix.b * rcStream.right + matrix.d * rcStream.top + matrix.f;
 
-  FX_FLOAT left = FX_MIN(FX_MIN(x1, x2), FX_MIN(x3, x4));
-  FX_FLOAT bottom = FX_MIN(FX_MIN(y1, y2), FX_MIN(y3, y4));
+  FX_FLOAT left = std::min(std::min(x1, x2), std::min(x3, x4));
+  FX_FLOAT bottom = std::min(std::min(y1, y2), std::min(y3, y4));
 
   fa = (rcAnnot.right - rcAnnot.left) / fStreamWidth;
   fd = (rcAnnot.top - rcAnnot.bottom) / fStreamHeight;
diff --git a/fpdfsdk/src/fsdk_baseannot.cpp b/fpdfsdk/src/fsdk_baseannot.cpp
index 629f35a..30e7022 100644
--- a/fpdfsdk/src/fsdk_baseannot.cpp
+++ b/fpdfsdk/src/fsdk_baseannot.cpp
@@ -4,6 +4,8 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
+#include <algorithm>
+
 #include "core/include/fxcrt/fx_ext.h"
 #include "fpdfsdk/include/fsdk_baseannot.h"
 #include "fpdfsdk/include/fsdk_define.h"
@@ -819,9 +821,9 @@
       FX_FLOAT y = pEntry->GetNumber(2);
       FX_FLOAT k = pEntry->GetNumber(3);
 
-      FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
-      FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
-      FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
+      FX_FLOAT r = 1.0f - std::min(1.0f, c + k);
+      FX_FLOAT g = 1.0f - std::min(1.0f, m + k);
+      FX_FLOAT b = 1.0f - std::min(1.0f, y + k);
 
       color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255));
 
diff --git a/fpdfsdk/src/fxedit/fxet_edit.cpp b/fpdfsdk/src/fxedit/fxet_edit.cpp
index c7abbf4..0e66b0e 100644
--- a/fpdfsdk/src/fxedit/fxet_edit.cpp
+++ b/fpdfsdk/src/fxedit/fxet_edit.cpp
@@ -6,6 +6,8 @@
 
 #include "fpdfsdk/include/fxedit/fxet_edit.h"
 
+#include <algorithm>
+
 #include "core/include/fpdfapi/fpdf_resource.h"
 
 #define FX_EDIT_UNDO_MAXITEM 10000
@@ -176,8 +178,7 @@
   CPDF_Rect rcResult;
   FX_FLOAT fWidthDiff;
 
-  int32_t szMax =
-      FX_EDIT_MAX(m_OldLineRects.GetSize(), m_NewLineRects.GetSize());
+  int32_t szMax = std::max(m_OldLineRects.GetSize(), m_NewLineRects.GetSize());
   int32_t i = 0;
 
   while (i < szMax) {
@@ -1726,7 +1727,7 @@
 
 void CFX_Edit::SelectAll() {
   if (m_pVT->IsValid()) {
-    m_SelState = GetWholeWordRange();
+    m_SelState = CFX_Edit_Select(GetWholeWordRange());
     SetCaret(m_SelState.EndPos);
 
     ScrollToCaret();
diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp
index 6db31de..d2f7fb0 100644
--- a/fpdfsdk/src/javascript/PublicMethods.cpp
+++ b/fpdfsdk/src/javascript/PublicMethods.cpp
@@ -6,6 +6,8 @@
 
 #include "PublicMethods.h"
 
+#include <algorithm>
+
 #include "Field.h"
 #include "JS_Context.h"
 #include "JS_Define.h"
@@ -142,10 +144,10 @@
     return dValue1 * dValue2;
   }
   if (FXSYS_wcsicmp(sFuction, L"MIN") == 0) {
-    return FX_MIN(dValue1, dValue2);
+    return std::min(dValue1, dValue2);
   }
   if (FXSYS_wcsicmp(sFuction, L"MAX") == 0) {
-    return FX_MAX(dValue1, dValue2);
+    return std::max(dValue1, dValue2);
   }
   return dValue1;
 }
diff --git a/fpdfsdk/src/pdfwindow/PWL_Utils.cpp b/fpdfsdk/src/pdfwindow/PWL_Utils.cpp
index 3b0f3be..27ba8bc 100644
--- a/fpdfsdk/src/pdfwindow/PWL_Utils.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_Utils.cpp
@@ -4,8 +4,11 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#include "fpdfsdk/include/pdfwindow/PWL_Icon.h"
 #include "fpdfsdk/include/pdfwindow/PWL_Utils.h"
+
+#include <algorithm>
+
+#include "fpdfsdk/include/pdfwindow/PWL_Icon.h"
 #include "fpdfsdk/include/pdfwindow/PWL_Wnd.h"
 
 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
@@ -1256,7 +1259,7 @@
   if (dC < 0 || dC > 1 || dM < 0 || dM > 1 || dY < 0 || dY > 1 || dK < 0 ||
       dK > 1)
     return;
-  dGray = 1.0f - FX_MIN(1.0f, 0.3f * dC + 0.59f * dM + 0.11f * dY + dK);
+  dGray = 1.0f - std::min(1.0f, 0.3f * dC + 0.59f * dM + 0.11f * dY + dK);
 }
 
 void CPWL_Utils::ConvertGRAY2CMYK(FX_FLOAT dGray,
@@ -1302,9 +1305,9 @@
   if (dC < 0 || dC > 1 || dM < 0 || dM > 1 || dY < 0 || dY > 1 || dK < 0 ||
       dK > 1)
     return;
-  dR = 1.0f - FX_MIN(1.0f, dC + dK);
-  dG = 1.0f - FX_MIN(1.0f, dM + dK);
-  dB = 1.0f - FX_MIN(1.0f, dY + dK);
+  dR = 1.0f - std::min(1.0f, dC + dK);
+  dG = 1.0f - std::min(1.0f, dM + dK);
+  dB = 1.0f - std::min(1.0f, dY + dK);
 }
 
 void CPWL_Utils::ConvertRGB2CMYK(FX_FLOAT dR,
@@ -1320,7 +1323,7 @@
   dC = 1.0f - dR;
   dM = 1.0f - dG;
   dY = 1.0f - dB;
-  dK = FX_MIN(dC, FX_MIN(dM, dY));
+  dK = std::min(dC, std::min(dM, dY));
 }
 
 void CPWL_Utils::PWLColorToARGB(const CPWL_Color& color,
diff --git a/xfa/src/fdp/src/css/fde_csscache.cpp b/xfa/src/fdp/src/css/fde_csscache.cpp
index fd33019..3d3b040 100644
--- a/xfa/src/fdp/src/css/fde_csscache.cpp
+++ b/xfa/src/fdp/src/css/fde_csscache.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "fde_csscache.h"

 _FDE_CSSCACHEITEM::_FDE_CSSCACHEITEM(IFDE_CSSStyleSheet* p)

@@ -34,8 +36,9 @@
                                             IFDE_CSSStyleSheet* pStyleSheet) {

   FXSYS_assert(pStyleSheet != NULL);

   if (m_pFixedStore == NULL) {

-    m_pFixedStore = FX_CreateAllocator(

-        FX_ALLOCTYPE_Fixed, FX_MAX(10, m_iMaxItems), sizeof(FDE_CSSCACHEITEM));

+    m_pFixedStore =

+        FX_CreateAllocator(FX_ALLOCTYPE_Fixed, std::max(10, m_iMaxItems),

+                           sizeof(FDE_CSSCACHEITEM));

     FXSYS_assert(m_pFixedStore != NULL);

   }

   auto it = m_Stylesheets.find(szKey);

diff --git a/xfa/src/fdp/src/fde/fde_gedevice.cpp b/xfa/src/fdp/src/fde/fde_gedevice.cpp
index 08f05e7..f4e46d0 100644
--- a/xfa/src/fdp/src/fde/fde_gedevice.cpp
+++ b/xfa/src/fdp/src/fde/fde_gedevice.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "fde_gedevice.h"

 #include "fde_geobject.h"

@@ -541,7 +543,7 @@
   FX_FLOAT fLength = fDiagonal.Length();

   FX_FLOAT fTotalX = fLength / FXSYS_cos(fTheta);

   FX_FLOAT fTotalY = fLength / FXSYS_cos(FX_PI / 2 - fTheta);

-  FX_FLOAT fSteps = FX_MAX(fTotalX, fTotalY);

+  FX_FLOAT fSteps = std::max(fTotalX, fTotalY);

   FX_FLOAT dx = fTotalX / fSteps;

   FX_FLOAT dy = fTotalY / fSteps;

   FX_ARGB cr0, cr1;

diff --git a/xfa/src/fdp/src/tto/fde_textout.cpp b/xfa/src/fdp/src/tto/fde_textout.cpp
index b9a8e80..90f21f1 100644
--- a/xfa/src/fdp/src/tto/fde_textout.cpp
+++ b/xfa/src/fdp/src/tto/fde_textout.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "fde_textout.h"

 IFDE_TextOut* IFDE_TextOut::Create() {

@@ -270,11 +272,11 @@
     rect.top += fStartPos;

     rect.left += fInc;

     rect.width = fHeight;

-    rect.height = FX_MIN(fWidth, rect.Height());

+    rect.height = std::min(fWidth, rect.Height());

   } else {

     rect.left += fStartPos;

     rect.top += fInc;

-    rect.width = FX_MIN(fWidth, rect.Width());

+    rect.width = std::min(fWidth, rect.Width());

     rect.height = fHeight;

     if (m_dwStyles & FDE_TTOSTYLE_LastLineHeight) {

       rect.height -= m_fLineSpace - m_fFontSize;

@@ -313,7 +315,7 @@
   for (int32_t i = 0; i < iCount; i++) {

     const CFX_TxtPiece* pPiece = m_pTxtBreak->GetBreakPiece(i);

     fLineWidth += (FX_FLOAT)pPiece->m_iWidth / 20000.0f;

-    fStartPos = FX_MIN(fStartPos, (FX_FLOAT)pPiece->m_iStartPos / 20000.0f);

+    fStartPos = std::min(fStartPos, (FX_FLOAT)pPiece->m_iStartPos / 20000.0f);

   }

   m_pTxtBreak->ClearBreakPieces();

   if (dwBreakStatus == FX_TXTBREAK_ParagraphBreak) {

@@ -322,7 +324,7 @@
   if (!bLineWrap && dwBreakStatus == FX_TXTBREAK_LineBreak) {

     fWidth += fLineWidth;

   } else {

-    fWidth = FX_MAX(fWidth, fLineWidth);

+    fWidth = std::max(fWidth, fLineWidth);

     fHeight += fLineStep;

   }

   m_iTotalLines++;

diff --git a/xfa/src/fdp/src/xml/fde_xml.cpp b/xfa/src/fdp/src/xml/fde_xml.cpp
index aa21722..8725cb7 100644
--- a/xfa/src/fdp/src/xml/fde_xml.cpp
+++ b/xfa/src/fdp/src/xml/fde_xml.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "fde_xml.h"

 #ifdef __cplusplus

@@ -1484,7 +1486,7 @@
   int32_t iStreamLength = pStream->GetLength();

   FXSYS_assert(iStreamLength > 0);

   m_pStream = pStream;

-  m_iXMLPlaneSize = FX_MIN(iXMLPlaneSize, iStreamLength);

+  m_iXMLPlaneSize = std::min(iXMLPlaneSize, iStreamLength);

   uint8_t bom[4];

   m_iCurrentPos = m_pStream->GetBOM(bom);

   FXSYS_assert(m_pBuffer == NULL);

@@ -2002,7 +2004,7 @@
   int32_t iStreamLength = pStream->GetLength();

   FXSYS_assert(iStreamLength > 0);

   m_pStream = pStream;

-  m_iXMLPlaneSize = FX_MIN(iXMLPlaneSize, iStreamLength);

+  m_iXMLPlaneSize = std::min(iXMLPlaneSize, iStreamLength);

   m_iTextDataSize = iTextDataSize;

   uint8_t bom[4];

   m_iCurrentPos = m_pStream->GetBOM(bom);

diff --git a/xfa/src/fee/src/fee/fde_txtedtbuf.cpp b/xfa/src/fee/src/fee/fde_txtedtbuf.cpp
index 0019207..bdef8d2 100644
--- a/xfa/src/fee/src/fee/fde_txtedtbuf.cpp
+++ b/xfa/src/fee/src/fee/fde_txtedtbuf.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "xfa/src/fee/include/ifde_txtedtbuf.h"

 #include "xfa/src/fee/include/ifde_txtedtengine.h"

@@ -269,7 +271,7 @@
     if (lpChunk->nUsed != m_nChunkSize) {

       cp.nChunkIndex--;

       int32_t nFree = m_nChunkSize - lpChunk->nUsed;

-      int32_t nCopy = FX_MIN(nLengthTemp, nFree);

+      int32_t nCopy = std::min(nLengthTemp, nFree);

       FXSYS_memcpy(lpChunk->wChars + lpChunk->nUsed, lpText,

                    nCopy * sizeof(FX_WCHAR));

       lpText += nCopy;

@@ -282,7 +284,7 @@
     FDE_LPCHUNKHEADER lpChunk = (FDE_LPCHUNKHEADER)m_pAllocator->Alloc(

         sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR));

     FXSYS_assert(lpChunk);

-    int32_t nCopy = FX_MIN(nLengthTemp, m_nChunkSize);

+    int32_t nCopy = std::min(nLengthTemp, m_nChunkSize);

     FXSYS_memcpy(lpChunk->wChars, lpText, nCopy * sizeof(FX_WCHAR));

     lpText += nCopy;

     nLengthTemp -= nCopy;

@@ -302,7 +304,7 @@
   int32_t nFirstPart = cpEnd.nCharIndex + 1;

   int32_t nMovePart = lpChunk->nUsed - nFirstPart;

   if (nMovePart != 0) {

-    int32_t nDelete = FX_MIN(nFirstPart, nLength);

+    int32_t nDelete = std::min(nFirstPart, nLength);

     FXSYS_memmove(lpChunk->wChars + nFirstPart - nDelete,

                   lpChunk->wChars + nFirstPart, nMovePart * sizeof(FX_WCHAR));

     lpChunk->nUsed -= nDelete;

@@ -311,7 +313,7 @@
   }

   while (nLength > 0) {

     lpChunk = (FDE_LPCHUNKHEADER)m_Chunks[cpEnd.nChunkIndex];

-    int32_t nDeleted = FX_MIN(lpChunk->nUsed, nLength);

+    int32_t nDeleted = std::min(lpChunk->nUsed, nLength);

     lpChunk->nUsed -= nDeleted;

     if (lpChunk->nUsed == 0) {

       m_pAllocator->Free(lpChunk);

diff --git a/xfa/src/fee/src/fee/fde_txtedtengine.cpp b/xfa/src/fee/src/fee/fde_txtedtengine.cpp
index 51f41d1..7d87f2c 100644
--- a/xfa/src/fee/src/fee/fde_txtedtengine.cpp
+++ b/xfa/src/fee/src/fee/fde_txtedtengine.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "xfa/src/fee/include/ifde_txtedtengine.h"

 #include "xfa/src/fee/include/ifde_txtedtbuf.h"

@@ -122,7 +124,7 @@
       uint8_t bom[4];

       int32_t nPos = pStream->GetBOM(bom);

       pStream->Seek(FX_STREAMSEEK_Begin, nPos);

-      int32_t nPlateSize = FX_MIN(nStreamLength, m_pTxtBuf->GetChunkSize());

+      int32_t nPlateSize = std::min(nStreamLength, m_pTxtBuf->GetChunkSize());

       FX_WCHAR* lpwstr = FX_Alloc(FX_WCHAR, nPlateSize);

       FX_BOOL bEos = false;

       while (!bEos) {

@@ -389,7 +391,7 @@
       break;

   }

   if (bShift && m_nAnchorPos != -1 && (m_nAnchorPos != m_nCaret)) {

-    AddSelRange(FX_MIN(m_nAnchorPos, m_nCaret),

+    AddSelRange(std::min(m_nAnchorPos, m_nCaret),

                 FXSYS_abs(m_nAnchorPos - m_nCaret));

     m_Param.pEventSink->On_SelChanged(this);

   }

diff --git a/xfa/src/fee/src/fee/fde_txtedtpage.cpp b/xfa/src/fee/src/fee/fde_txtedtpage.cpp
index 2c59223..fbeccbe 100644
--- a/xfa/src/fee/src/fee/fde_txtedtpage.cpp
+++ b/xfa/src/fee/src/fee/fde_txtedtpage.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "xfa/src/fee/include/ifde_txtedtbuf.h"

 #include "xfa/src/fee/include/ifde_txtedtengine.h"

@@ -395,8 +397,8 @@
   pBreak->ClearBreakPieces();

   int32_t nPageLineCount = m_pEditEngine->GetPageLineCount();

   int32_t nStartLine = nPageLineCount * m_nPageIndex;

-  int32_t nEndLine = FX_MIN((nStartLine + nPageLineCount - 1),

-                            (m_pEditEngine->GetLineCount() - 1));

+  int32_t nEndLine = std::min((nStartLine + nPageLineCount - 1),

+                              (m_pEditEngine->GetLineCount() - 1));

   int32_t nPageStart, nPageEnd, nTemp, nBgnParag, nStartLineInParag, nEndParag,

       nEndLineInParag;

   nBgnParag = m_pEditEngine->Line2Parag(0, 0, nStartLine, nStartLineInParag);

diff --git a/xfa/src/fgas/src/crt/fx_memory.cpp b/xfa/src/fgas/src/crt/fx_memory.cpp
index a450119..0f17dc8 100644
--- a/xfa/src/fgas/src/crt/fx_memory.cpp
+++ b/xfa/src/fgas/src/crt/fx_memory.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/fgas/src/fgas_base.h"

 #include "fx_memory.h"

 #define FX_4BYTEALIGN(size) (((size) + 3) / 4 * 4)

@@ -59,7 +61,7 @@
 FX_LPSTATICSTORECHUNK CFX_StaticStore::FindChunk(size_t size) {

   FXSYS_assert(size != 0);

   if (m_pLastChunk == NULL || m_pLastChunk->iFreeSize < size) {

-    return AllocChunk(FX_MAX(m_iDefChunkSize, size));

+    return AllocChunk(std::max(m_iDefChunkSize, size));

   }

   return m_pLastChunk;

 }

@@ -242,7 +244,7 @@
     pChunk = pChunk->pNextChunk;

   }

   if (pChunk == NULL) {

-    pChunk = AllocChunk(FX_MAX(m_iDefChunkSize, size));

+    pChunk = AllocChunk(std::max(m_iDefChunkSize, size));

     pBlock = pChunk->FirstBlock();

   }

   FXSYS_assert(pChunk != NULL && pBlock != NULL);

diff --git a/xfa/src/fgas/src/crt/fx_stream.cpp b/xfa/src/fgas/src/crt/fx_stream.cpp
index 9bb5978..fb8c3c7 100644
--- a/xfa/src/fgas/src/crt/fx_stream.cpp
+++ b/xfa/src/fgas/src/crt/fx_stream.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/fgas/src/fgas_base.h"

 #include "fx_stream.h"

 IFX_Stream* IFX_Stream::CreateStream(IFX_BufferRead* pBufferRead,

@@ -204,7 +206,7 @@
     return 0;

   }

   int32_t iPosition = FXSYS_ftell(m_hFile);

-  int32_t iLen = FX_MIN((m_iLength - iPosition) / 2, iMaxLength);

+  int32_t iLen = std::min((m_iLength - iPosition) / 2, iMaxLength);

   if (iLen <= 0) {

     return 0;

   }

@@ -415,7 +417,7 @@
   const uint8_t* pBufferTmp = m_pBufferRead->GetBlockBuffer();

   FX_DWORD dwOffsetTmp = m_iPosition - dwBlockOffset;

   FX_DWORD dwCopySize =

-      FX_MIN(iBufferSize, (int32_t)(dwBlockSize - dwOffsetTmp));

+      std::min(iBufferSize, (int32_t)(dwBlockSize - dwOffsetTmp));

   FXSYS_memcpy(pBuffer, pBufferTmp + dwOffsetTmp, dwCopySize);

   dwOffsetTmp = dwCopySize;

   iBufferSize -= dwCopySize;

@@ -426,7 +428,7 @@
     dwBlockOffset = m_pBufferRead->GetBlockOffset();

     dwBlockSize = m_pBufferRead->GetBlockSize();

     pBufferTmp = m_pBufferRead->GetBlockBuffer();

-    dwCopySize = FX_MIN((FX_DWORD)iBufferSize, dwBlockSize);

+    dwCopySize = std::min((FX_DWORD)iBufferSize, dwBlockSize);

     FXSYS_memcpy(pBuffer + dwOffsetTmp, pBufferTmp, dwCopySize);

     dwOffsetTmp += dwCopySize;

     iBufferSize -= dwCopySize;

@@ -562,7 +564,7 @@
 int32_t CFX_BufferStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) {

   FXSYS_assert(m_pData != NULL);

   FXSYS_assert(pBuffer != NULL && iBufferSize > 0);

-  int32_t iLen = FX_MIN(m_iLength - m_iPosition, iBufferSize);

+  int32_t iLen = std::min(m_iLength - m_iPosition, iBufferSize);

   if (iLen <= 0) {

     return 0;

   }

@@ -575,7 +577,7 @@
                                         FX_BOOL& bEOS) {

   FXSYS_assert(m_pData != NULL);

   FXSYS_assert(pStr != NULL && iMaxLength > 0);

-  int32_t iLen = FX_MIN((m_iLength - m_iPosition) / 2, iMaxLength);

+  int32_t iLen = std::min((m_iLength - m_iPosition) / 2, iMaxLength);

   if (iLen <= 0) {

     return 0;

   }

@@ -592,7 +594,7 @@
                                        int32_t iBufferSize) {

   FXSYS_assert(m_pData != NULL && (m_dwAccess & FX_STREAMACCESS_Write) != 0);

   FXSYS_assert(pBuffer != NULL && iBufferSize > 0);

-  int32_t iLen = FX_MIN(m_iTotalSize - m_iPosition, iBufferSize);

+  int32_t iLen = std::min(m_iTotalSize - m_iPosition, iBufferSize);

   if (iLen <= 0) {

     return 0;

   }

@@ -607,7 +609,7 @@
                                          int32_t iLength) {

   FXSYS_assert(m_pData != NULL && (m_dwAccess & FX_STREAMACCESS_Write) != 0);

   FXSYS_assert(pStr != NULL && iLength > 0);

-  int32_t iLen = FX_MIN((m_iTotalSize - m_iPosition) / 2, iLength);

+  int32_t iLen = std::min((m_iTotalSize - m_iPosition) / 2, iLength);

   if (iLen <= 0) {

     return 0;

   }

@@ -688,7 +690,7 @@
     }

   }

 #endif

-  m_pStreamImp->Seek(FX_STREAMSEEK_Begin, FX_MAX(m_wBOMLength, iPosition));

+  m_pStreamImp->Seek(FX_STREAMSEEK_Begin, std::max(m_wBOMLength, iPosition));

 }

 void CFX_TextStream::Release() {

   if (--m_iRefCount < 1) {

@@ -747,7 +749,7 @@
     return 0;

   }

   *(FX_DWORD*)bom = m_dwBOM;

-  return (int32_t)m_wBOMLength;

+  return m_wBOMLength;

 }

 FX_WORD CFX_TextStream::SetCodePage(FX_WORD wCodePage) {

   if (m_wBOMLength > 0) {

@@ -788,7 +790,7 @@
   } else {

     int32_t pos = m_pStreamImp->GetPosition();

     int32_t iBytes = pByteSize == NULL ? iMaxLength : *pByteSize;

-    iBytes = FX_MIN(iBytes, m_pStreamImp->GetLength() - pos);

+    iBytes = std::min(iBytes, m_pStreamImp->GetLength() - pos);

     if (iBytes > 0) {

       if (m_pBuf == NULL) {

         m_pBuf = FX_Alloc(uint8_t, iBytes);

@@ -1024,7 +1026,7 @@
   if (m_pStreamImp == NULL) {

     return -1;

   }

-  int32_t iLen = FX_MIN(m_iStart + m_iLength - m_iPosition, iBufferSize);

+  int32_t iLen = std::min(m_iStart + m_iLength - m_iPosition, iBufferSize);

   if (iLen <= 0) {

     return 0;

   }

@@ -1048,9 +1050,9 @@
   int32_t iEnd = m_iStart + m_iLength;

   int32_t iLen = iEnd - m_iPosition;

   if (pByteSize != NULL) {

-    iLen = FX_MIN(iLen, *pByteSize);

+    iLen = std::min(iLen, *pByteSize);

   }

-  iLen = FX_MIN(iEnd / 2, iMaxLength);

+  iLen = std::min(iEnd / 2, iMaxLength);

   if (iLen <= 0) {

     return 0;

   }

@@ -1076,7 +1078,7 @@
   }

   int32_t iLen = iBufferSize;

   if (m_eStreamType == FX_STREAMTYPE_Stream) {

-    iLen = FX_MIN(m_iStart + m_iTotalSize - m_iPosition, iBufferSize);

+    iLen = std::min(m_iStart + m_iTotalSize - m_iPosition, iBufferSize);

     if (iLen <= 0) {

       return 0;

     }

@@ -1104,7 +1106,7 @@
   }

   int32_t iLen = iLength;

   if (m_eStreamType == FX_STREAMTYPE_Stream) {

-    iLen = FX_MIN((m_iStart + m_iTotalSize - m_iPosition) / 2, iLength);

+    iLen = std::min((m_iStart + m_iTotalSize - m_iPosition) / 2, iLength);

     if (iLen <= 0) {

       return 0;

     }

@@ -1322,7 +1324,7 @@
   }

   const uint8_t* pBuffer = m_pBufferRead->GetBlockBuffer();

   FX_FILESIZE dwOffset = offset - dwBlockOffset;

-  size_t dwCopySize = FX_MIN(size, dwBlockSize - dwOffset);

+  size_t dwCopySize = std::min(size, dwBlockSize - dwOffset);

   FXSYS_memcpy(buffer, pBuffer + dwOffset, dwCopySize);

   offset = dwCopySize;

   size -= dwCopySize;

@@ -1333,7 +1335,7 @@
     dwBlockOffset = m_pBufferRead->GetBlockOffset();

     dwBlockSize = m_pBufferRead->GetBlockSize();

     pBuffer = m_pBufferRead->GetBlockBuffer();

-    dwCopySize = FX_MIN(size, dwBlockSize);

+    dwCopySize = std::min(size, dwBlockSize);

     FXSYS_memcpy(((uint8_t*)buffer) + offset, pBuffer, dwCopySize);

     offset += dwCopySize;

     size -= dwCopySize;

@@ -1415,7 +1417,7 @@
   }

   const uint8_t* pBuffer = m_pBufferRead->GetBlockBuffer();

   FX_DWORD dwOffset = offset - dwBlockOffset;

-  FX_DWORD dwCopySize = FX_MIN(size, dwBlockSize - dwOffset);

+  FX_DWORD dwCopySize = std::min(size, dwBlockSize - dwOffset);

   FXSYS_memcpy(buffer, pBuffer + dwOffset, dwCopySize);

   offset = dwCopySize;

   size -= dwCopySize;

@@ -1426,7 +1428,7 @@
     dwBlockOffset = m_pBufferRead->GetBlockOffset();

     dwBlockSize = m_pBufferRead->GetBlockSize();

     pBuffer = m_pBufferRead->GetBlockBuffer();

-    dwCopySize = FX_MIN(size, dwBlockSize);

+    dwCopySize = std::min(size, dwBlockSize);

     FXSYS_memcpy(((uint8_t*)buffer) + offset, pBuffer, dwCopySize);

     offset += dwCopySize;

     size -= dwCopySize;

diff --git a/xfa/src/fgas/src/crt/fx_stream.h b/xfa/src/fgas/src/crt/fx_stream.h
index bb13758..8edd7e2 100644
--- a/xfa/src/fgas/src/crt/fx_stream.h
+++ b/xfa/src/fgas/src/crt/fx_stream.h
@@ -252,7 +252,7 @@
 

  protected:

   FX_WORD m_wCodePage;

-  FX_WORD m_wBOMLength;

+  int32_t m_wBOMLength;

   FX_DWORD m_dwBOM;

   uint8_t* m_pBuf;

   int32_t m_iBufSize;

diff --git a/xfa/src/fgas/src/crt/fx_system.cpp b/xfa/src/fgas/src/crt/fx_system.cpp
index 0de8e0e..861d117 100644
--- a/xfa/src/fgas/src/crt/fx_system.cpp
+++ b/xfa/src/fgas/src/crt/fx_system.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/fgas/src/fgas_base.h"

 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \

     _FX_OS_ == _FX_WIN64_

@@ -155,7 +157,7 @@
   if (iUrlLen == 0) {

     return TRUE;

   }

-  for (int32_t i = FX_MIN(5, iUrlLen) - 1; i >= 0; --i)

+  for (int32_t i = std::min(5, iUrlLen) - 1; i >= 0; --i)

     if (wsUrl.GetAt(i) == ':') {

       return FALSE;

     }

diff --git a/xfa/src/fgas/src/crt/fx_utils.cpp b/xfa/src/fgas/src/crt/fx_utils.cpp
index 9d89e24..7cc4de7 100644
--- a/xfa/src/fgas/src/crt/fx_utils.cpp
+++ b/xfa/src/fgas/src/crt/fx_utils.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/fgas/include/fx_utl.h"

 #include "xfa/src/fgas/src/fgas_base.h"

 #include "fx_utils.h"

@@ -241,7 +243,8 @@
   uint8_t* pSrcChunk = (uint8_t*)src.GetAt(iSrcStart);

   int32_t iDstChunkSize = m_iChunkSize - (iDstStart % m_iChunkSize);

   int32_t iSrcChunkSize = src.m_iChunkSize - (iSrcStart % src.m_iChunkSize);

-  int32_t iCopySize = FX_MIN(iSrcCount, FX_MIN(iSrcChunkSize, iDstChunkSize));

+  int32_t iCopySize =

+      std::min(iSrcCount, std::min(iSrcChunkSize, iDstChunkSize));

   int32_t iCopyBytes = iCopySize * m_iBlockSize;

   while (iSrcCount > 0) {

     FXSYS_assert(pDstChunk != NULL && pSrcChunk != NULL);

@@ -263,7 +266,7 @@
     } else {

       pDstChunk += iCopyBytes;

     }

-    iCopySize = FX_MIN(iSrcCount, FX_MIN(iSrcChunkSize, iDstChunkSize));

+    iCopySize = std::min(iSrcCount, std::min(iSrcChunkSize, iDstChunkSize));

     iCopyBytes = iCopySize * m_iBlockSize;

   }

 }

diff --git a/xfa/src/fgas/src/layout/fx_rtfbreak.cpp b/xfa/src/fgas/src/layout/fx_rtfbreak.cpp
index 8683bcf..26d2731 100644
--- a/xfa/src/fgas/src/layout/fx_rtfbreak.cpp
+++ b/xfa/src/fgas/src/layout/fx_rtfbreak.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/fgas/include/fx_lbk.h"

 #include "xfa/src/fgas/src/fgas_base.h"

 #include "xfa/src/fgas/src/layout/fx_unicode.h"

@@ -389,7 +391,7 @@
       (this->*g_FX_RTFBreak_lpfAppendChar[dwType >> FX_CHARTYPEBITS])(

           pCurChar, iRotation);

   m_dwCharType = dwType;

-  return FX_MAX(dwRet1, dwRet2);

+  return std::max(dwRet1, dwRet2);

 }

 FX_DWORD CFX_RTFBreak::AppendChar_CharCode(FX_WCHAR wch) {

   FXSYS_assert(m_pFont != NULL && m_pCurLine != NULL);

@@ -1151,7 +1153,7 @@
     pBreakPiece = rtfPieces.GetPtrAt(i);

     int32_t iFontHeight = FXSYS_round(pBreakPiece->m_iFontHeight *

                                       pBreakPiece->m_iVerticalScale / 100.0f);

-    iMax = FX_MAX(pBreakPiece->m_iFontSize, iFontHeight);

+    iMax = std::max(pBreakPiece->m_iFontSize, iFontHeight);

     if (i == 0) {

       iLineHeight = iMax;

     } else if (iLineHeight < iMax) {

@@ -1441,7 +1443,7 @@
   if (bCharBBox) {

     bCharBBox = pFont->GetBBox(bbox);

   }

-  FX_FLOAT fLeft = FX_MAX(0, bbox.left * fScale);

+  FX_FLOAT fLeft = std::max(0.0f, bbox.left * fScale);

   FX_FLOAT fHeight = FXSYS_fabs(bbox.height * fScale);

   rtArray.RemoveAll();

   rtArray.SetSize(iLength);

@@ -1506,13 +1508,13 @@
         rtBBoxF.left = rect.top + (rect.height - fHeight) / 2.0f;

         rtBBoxF.height = fCharWidth;

         rtBBoxF.width = fHeight;

-        rtBBoxF.left = FX_MAX(rtBBoxF.left, 0);

+        rtBBoxF.left = std::max(rtBBoxF.left, 0.0f);

       } else {

         rtBBoxF.left = rect.left + fRTLeft;

         rtBBoxF.top = rect.top + (rect.height - fHeight) / 2.0f;

         rtBBoxF.width = fCharWidth;

         rtBBoxF.height = fHeight;

-        rtBBoxF.top = FX_MAX(rtBBoxF.top, 0);

+        rtBBoxF.top = std::max(rtBBoxF.top, 0.0f);

       }

       rtArray.SetAt(i, rtBBoxF);

       continue;

diff --git a/xfa/src/fgas/src/layout/fx_textbreak.cpp b/xfa/src/fgas/src/layout/fx_textbreak.cpp
index 754e10d..a9ce859 100644
--- a/xfa/src/fgas/src/layout/fx_textbreak.cpp
+++ b/xfa/src/fgas/src/layout/fx_textbreak.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "core/include/fxcrt/fx_arb.h"

 #include "xfa/src/fgas/include/fx_lbk.h"

 #include "xfa/src/fgas/src/fgas_base.h"

@@ -605,7 +607,7 @@
   FX_DWORD dwRet2 =

       (this->*g_FX_TxtBreak_lpfAppendChar[dwType >> FX_CHARTYPEBITS])(

           pCurChar, iRotation);

-  return FX_MAX(dwRet1, dwRet2);

+  return std::max(dwRet1, dwRet2);

 }

 void CFX_TxtBreak::EndBreak_UpdateArabicShapes() {

   FXSYS_assert(m_bArabicShapes);

@@ -1572,7 +1574,7 @@
   if (bCharBBox) {

     bCharBBox = pFont->GetBBox(bbox);

   }

-  FX_FLOAT fLeft = FX_MAX(0, bbox.left * fScale);

+  FX_FLOAT fLeft = std::max(0.0f, bbox.left * fScale);

   FX_FLOAT fHeight = FXSYS_fabs(bbox.height * fScale);

   rtArray.RemoveAll();

   rtArray.SetSize(iLength);

@@ -1642,13 +1644,13 @@
         rtBBoxF.left = rect.top + (rect.height - fHeight) / 2.0f;

         rtBBoxF.height = fCharWidth;

         rtBBoxF.width = fHeight;

-        rtBBoxF.left = FX_MAX(rtBBoxF.left, 0);

+        rtBBoxF.left = std::max(rtBBoxF.left, 0.0f);

       } else {

         rtBBoxF.left = rect.left + fRTLeft;

         rtBBoxF.top = rect.top + (rect.height - fHeight) / 2.0f;

         rtBBoxF.width = fCharWidth;

         rtBBoxF.height = fHeight;

-        rtBBoxF.top = FX_MAX(rtBBoxF.top, 0);

+        rtBBoxF.top = std::max(rtBBoxF.top, 0.0f);

       }

       rtArray.SetAt(i, rtBBoxF);

       continue;

diff --git a/xfa/src/fgas/src/localization/fx_locale.cpp b/xfa/src/fgas/src/localization/fx_locale.cpp
index d9424c3..4962910 100644
--- a/xfa/src/fgas/src/localization/fx_locale.cpp
+++ b/xfa/src/fgas/src/localization/fx_locale.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "core/include/fxcrt/fx_xml.h"

 #include "xfa/src/fgas/src/fgas_base.h"

 #include "fx_localeimp.h"

@@ -4579,7 +4581,7 @@
                                                            uint64_t b[],

                                                            uint8_t bl) {

   int8_t retVal = 0;

-  for (int i = FX_MAX(al - 1, bl - 1); i >= 0; i--) {

+  for (int i = std::max(al - 1, bl - 1); i >= 0; i--) {

     uint64_t l = (i >= al ? 0 : a[i]), r = (i >= bl ? 0 : b[i]);

     retVal += (l > r ? 1 : (l < r ? -1 : 0));

     if (retVal) {

@@ -4680,13 +4682,13 @@
         fxmath_decimal_helper_dec_any(right, al);

         break;

       case 0:

-        for (i = 0; i < FX_MIN(al, cl); i++) {

+        for (i = 0; i < std::min(al, cl); i++) {

           c[i] = cur[i];

         }

         return;

     }

   }

-  for (i = 0; i < FX_MIN(al, cl); i++) {

+  for (i = 0; i < std::min(al, cl); i++) {

     c[i] = left[i];

   }

 }

@@ -4956,8 +4958,8 @@
   int8_t retVal = 0;

   if (FXMATH_DECIMAL_FLAGS2SCALE(lhs.m_uFlags) !=

       FXMATH_DECIMAL_FLAGS2SCALE(rhs.m_uFlags)) {

-    uint8_t scale = FX_MIN(FXMATH_DECIMAL_FLAGS2SCALE(lhs.m_uFlags),

-                           FXMATH_DECIMAL_FLAGS2SCALE(rhs.m_uFlags));

+    uint8_t scale = std::min(FXMATH_DECIMAL_FLAGS2SCALE(lhs.m_uFlags),

+                             FXMATH_DECIMAL_FLAGS2SCALE(rhs.m_uFlags));

     lhs.SetScale(scale);

     rhs.SetScale(scale);

   }

@@ -4975,8 +4977,8 @@
   CFX_Decimal lhs = *this, rhs = val;

   if (FXMATH_DECIMAL_FLAGS2SCALE(lhs.m_uFlags) !=

       FXMATH_DECIMAL_FLAGS2SCALE(rhs.m_uFlags)) {

-    uint8_t scale = FX_MAX(FXMATH_DECIMAL_FLAGS2SCALE(lhs.m_uFlags),

-                           FXMATH_DECIMAL_FLAGS2SCALE(rhs.m_uFlags));

+    uint8_t scale = std::max(FXMATH_DECIMAL_FLAGS2SCALE(lhs.m_uFlags),

+                             FXMATH_DECIMAL_FLAGS2SCALE(rhs.m_uFlags));

     lhs.SetScale(scale);

     rhs.SetScale(scale);

   }

diff --git a/xfa/src/fgas/src/xml/fx_sax_imp.cpp b/xfa/src/fgas/src/xml/fx_sax_imp.cpp
index dce9647..6b3cc77 100644
--- a/xfa/src/fgas/src/xml/fx_sax_imp.cpp
+++ b/xfa/src/fgas/src/xml/fx_sax_imp.cpp
@@ -4,8 +4,17 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/fgas/src/fgas_base.h"

 #include "fx_sax_imp.h"

+

+namespace {

+

+const FX_DWORD kSaxFileBufSize = 32768;

+

+}  // namespace

+

 IFX_SAXReader* FX_SAXReader_Create() {

   return new CFX_SAXReader;

 }

@@ -31,7 +40,7 @@
   if (dwLen == 0) {

     return FALSE;

   }

-  m_dwBufSize = FX_MIN(dwLen, FX_SAXFILE_BUFSIZE);

+  m_dwBufSize = std::min(dwLen, kSaxFileBufSize);

   m_pBuf = FX_Alloc(uint8_t, m_dwBufSize);

   if (!pFile->ReadBlock(m_pBuf, dwStart, m_dwBufSize)) {

     return FALSE;

@@ -49,7 +58,7 @@
   if (dwSize == 0) {

     return FALSE;

   }

-  m_dwBufSize = FX_MIN(dwSize, FX_SAXFILE_BUFSIZE);

+  m_dwBufSize = std::min(dwSize, kSaxFileBufSize);

   if (!m_pFile->ReadBlock(m_pBuf, m_dwCur, m_dwBufSize)) {

     return FALSE;

   }

diff --git a/xfa/src/fgas/src/xml/fx_sax_imp.h b/xfa/src/fgas/src/xml/fx_sax_imp.h
index 7d04f14..71be388 100644
--- a/xfa/src/fgas/src/xml/fx_sax_imp.h
+++ b/xfa/src/fgas/src/xml/fx_sax_imp.h
@@ -6,7 +6,7 @@
 

 #ifndef _FX_SAX_IMP_

 #define _FX_SAX_IMP_

-#define FX_SAXFILE_BUFSIZE 32768

+

 class CFX_SAXFile {

  public:

   CFX_SAXFile();

diff --git a/xfa/src/fwl/src/basewidget/fwl_checkboximp.cpp b/xfa/src/fwl/src/basewidget/fwl_checkboximp.cpp
index 3df1f21..3fa2119 100644
--- a/xfa/src/fwl/src/basewidget/fwl_checkboximp.cpp
+++ b/xfa/src/fwl/src/basewidget/fwl_checkboximp.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "xfa/src/fwl/src/core/include/fwl_targetimp.h"

 #include "xfa/src/fwl/src/core/include/fwl_noteimp.h"

@@ -245,8 +247,8 @@
     CalcTextRect(wsCaption, m_pProperties->m_pThemeProvider, m_dwTTOStyles,

                  m_iTTOAlign, rtFocus);

     if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) == 0) {

-      FX_FLOAT fWidth = FX_MAX(m_rtCaption.width, rtFocus.width);

-      FX_FLOAT fHeight = FX_MIN(m_rtCaption.height, rtFocus.height);

+      FX_FLOAT fWidth = std::max(m_rtCaption.width, rtFocus.width);

+      FX_FLOAT fHeight = std::min(m_rtCaption.height, rtFocus.height);

       FX_FLOAT fLeft = m_rtCaption.left;

       FX_FLOAT fTop = m_rtCaption.top;

       if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) ==

diff --git a/xfa/src/fwl/src/basewidget/fwl_editimp.cpp b/xfa/src/fwl/src/basewidget/fwl_editimp.cpp
index 9b652a7..06e185e 100644
--- a/xfa/src/fwl/src/basewidget/fwl_editimp.cpp
+++ b/xfa/src/fwl/src/basewidget/fwl_editimp.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "xfa/src/fwl/src/core/include/fwl_threadimp.h"

 #include "xfa/src/fwl/src/core/include/fwl_appimp.h"

@@ -887,11 +889,11 @@
     fContentHeight1 = page1->GetContentsBox().height;

   }

   if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HSelfAdaption) {

-    rtTemp.width = FX_MAX(m_pProperties->m_rtWidget.width, fContentWidth1);

+    rtTemp.width = std::max(m_pProperties->m_rtWidget.width, fContentWidth1);

     m_pProperties->m_rtWidget.width = fContentWidth1;

   }

   if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VSelfAdaption) {

-    rtTemp.height = FX_MAX(m_pProperties->m_rtWidget.height, fContentHeight1);

+    rtTemp.height = std::max(m_pProperties->m_rtWidget.height, fContentHeight1);

     m_pProperties->m_rtWidget.height = fContentHeight1;

   }

   CFWL_EvtEdtTextChanged event;

@@ -1062,8 +1064,8 @@
       if (nCharEnd < nPageCharStart || nCharStart > nPageCharEnd) {

         continue;

       }

-      int32_t nBgn = FX_MAX(nCharStart, nPageCharStart);

-      int32_t nEnd = FX_MIN(nCharEnd, nPageCharEnd);

+      int32_t nBgn = std::max(nCharStart, nPageCharStart);

+      int32_t nEnd = std::min(nCharEnd, nPageCharEnd);

       pPage->CalcRangeRectArray(nBgn - nPageCharStart, nEnd - nBgn + 1,

                                 rectArr);

     }

@@ -1926,8 +1928,8 @@
   }

   FX_BOOL bShift = pMsg->m_dwFlags & FWL_KEYFLAG_Shift;

   if (bShift && m_pOwner->m_nSelStart != nIndex) {

-    int32_t iStart = FX_MIN(m_pOwner->m_nSelStart, nIndex);

-    int32_t iEnd = FX_MAX(m_pOwner->m_nSelStart, nIndex);

+    int32_t iStart = std::min(m_pOwner->m_nSelStart, nIndex);

+    int32_t iEnd = std::max(m_pOwner->m_nSelStart, nIndex);

     m_pOwner->m_pEdtEngine->AddSelRange(iStart, iEnd - iStart);

     bRepaint = TRUE;

   } else {

@@ -1985,7 +1987,7 @@
       m_pOwner->m_nSelStart = nLen;

     }

     m_pOwner->m_pEdtEngine->AddSelRange(

-        FX_MIN(m_pOwner->m_nSelStart, nIndex),

+        std::min(m_pOwner->m_nSelStart, nIndex),

         FXSYS_abs(nIndex - m_pOwner->m_nSelStart));

   }

 }

diff --git a/xfa/src/fwl/src/core/fwl_widgetimp.cpp b/xfa/src/fwl/src/core/fwl_widgetimp.cpp
index 88db9b3..3872def 100644
--- a/xfa/src/fwl/src/core/fwl_widgetimp.cpp
+++ b/xfa/src/fwl/src/core/fwl_widgetimp.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "xfa/src/fwl/src/core/include/fwl_targetimp.h"

 #include "xfa/src/fwl/src/core/include/fwl_noteimp.h"

@@ -769,7 +771,7 @@
   } else if (rtPopup.height < fMinHeight) {

     fPopHeight = fMinHeight;

   }

-  FX_FLOAT fWidth = FX_MAX(rtAnchor.width, rtPopup.width);

+  FX_FLOAT fWidth = std::max(rtAnchor.width, rtPopup.width);

   FX_FLOAT fBottom = rtAnchor.bottom() + fPopHeight;

   TransformTo(NULL, fx, fy);

   if (fBottom + fy > fScreenHeight) {

diff --git a/xfa/src/fwl/src/theme/widgettp.cpp b/xfa/src/fwl/src/theme/widgettp.cpp
index 7eaf6e8..e1351b5 100644
--- a/xfa/src/fwl/src/theme/widgettp.cpp
+++ b/xfa/src/fwl/src/theme/widgettp.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 static void FWL_SetChildThemeID(IFWL_Widget* pParent, FX_DWORD dwThemeID) {

   IFWL_WidgetMgr* pWidgetMgr = FWL_GetWidgetMgr();

@@ -528,7 +530,7 @@
   CFX_Path path;

   path.Create();

   FX_FLOAT fBtn =

-      FX_MIN(pRect->width, pRect->height) / FWLTHEME_ARROW_Denominator;

+      std::min(pRect->width, pRect->height) / FWLTHEME_ARROW_Denominator;

   rtArrow.left = pRect->left + (pRect->width - fBtn) / 2;

   rtArrow.top = pRect->top + (pRect->height - fBtn) / 2;

   rtArrow.width = fBtn;

diff --git a/xfa/src/fxbarcode/BC_TwoDimWriter.cpp b/xfa/src/fxbarcode/BC_TwoDimWriter.cpp
index d6d6614..b270378 100644
--- a/xfa/src/fxbarcode/BC_TwoDimWriter.cpp
+++ b/xfa/src/fxbarcode/BC_TwoDimWriter.cpp
@@ -4,10 +4,14 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

+#include "third_party/base/numerics/safe_math.h"

 #include "xfa/src/fxbarcode/barcode.h"

 #include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h"

 #include "xfa/src/fxbarcode/BC_Writer.h"

 #include "xfa/src/fxbarcode/BC_TwoDimWriter.h"

+

 CBC_TwoDimWriter::CBC_TwoDimWriter() {

   m_iCorrectLevel = 1;

   m_bFixedSize = TRUE;

@@ -92,18 +96,18 @@
                                     int32_t& e) {

   int32_t inputWidth = codeWidth;

   int32_t inputHeight = codeHeight;

-  int32_t tempWidth = inputWidth + (1 << 1);

-  int32_t tempHeight = inputHeight + (1 << 1);

-  FX_FLOAT moduleHSize = (FX_FLOAT)FX_MIN(m_ModuleWidth, m_ModuleHeight);

-  if (moduleHSize > 8) {

-    moduleHSize = 8;

-  } else if (moduleHSize < 1) {

-    moduleHSize = 1;

-  }

-  int32_t outputWidth = (int32_t)FX_MAX(tempWidth * moduleHSize, tempWidth);

-  int32_t outputHeight = (int32_t)FX_MAX(tempHeight * moduleHSize, tempHeight);

-  int32_t multiX = 1;

-  int32_t multiY = 1;

+  int32_t tempWidth = inputWidth + 2;

+  int32_t tempHeight = inputHeight + 2;

+  FX_FLOAT moduleHSize = std::min(m_ModuleWidth, m_ModuleHeight);

+  moduleHSize = std::min(moduleHSize, 8.0f);

+  moduleHSize = std::max(moduleHSize, 1.0f);

+  pdfium::base::CheckedNumeric<int32_t> scaledWidth = tempWidth;

+  pdfium::base::CheckedNumeric<int32_t> scaledHeight = tempHeight;

+  scaledWidth *= moduleHSize;

+  scaledHeight *= moduleHSize;

+

+  int32_t outputWidth = scaledWidth.ValueOrDie();

+  int32_t outputHeight = scaledHeight.ValueOrDie();

   if (m_bFixedSize) {

     if (m_Width < outputWidth || m_Height < outputHeight) {

       e = BCExceptionBitmapSizeError;

@@ -117,10 +121,10 @@
           outputHeight * ceil((FX_FLOAT)m_Height / (FX_FLOAT)outputHeight));

     }

   }

-  multiX = (int32_t)ceil((FX_FLOAT)outputWidth / (FX_FLOAT)tempWidth);

-  multiY = (int32_t)ceil((FX_FLOAT)outputHeight / (FX_FLOAT)tempHeight);

+  int32_t multiX = (int32_t)ceil((FX_FLOAT)outputWidth / (FX_FLOAT)tempWidth);

+  int32_t multiY = (int32_t)ceil((FX_FLOAT)outputHeight / (FX_FLOAT)tempHeight);

   if (m_bFixedSize) {

-    multiX = FX_MIN(multiX, multiY);

+    multiX = std::min(multiX, multiY);

     multiY = multiX;

   }

   int32_t leftPadding = (outputWidth - (inputWidth * multiX)) / 2;

diff --git a/xfa/src/fxbarcode/common/BC_CommonByteArray.cpp b/xfa/src/fxbarcode/common/BC_CommonByteArray.cpp
index 967a184..c36ff34 100644
--- a/xfa/src/fxbarcode/common/BC_CommonByteArray.cpp
+++ b/xfa/src/fxbarcode/common/BC_CommonByteArray.cpp
@@ -20,6 +20,8 @@
  * limitations under the License.

  */

 

+#include <algorithm>

+

 #include "xfa/src/fxbarcode/barcode.h"

 #include "BC_CommonByteArray.h"

 CBC_CommonByteArray::CBC_CommonByteArray() {

@@ -61,7 +63,7 @@
 }

 void CBC_CommonByteArray::AppendByte(int32_t value) {

   if (m_size == 0 || m_index >= m_size) {

-    int32_t newSize = FX_MAX(32, m_size << 1);

+    int32_t newSize = std::max(32, m_size << 1);

     Reserve(newSize);

   }

   m_bytes[m_index] = (uint8_t)value;

diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp
index c930f0e..27c29af 100644
--- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp
+++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp
@@ -20,6 +20,8 @@
  * limitations under the License.

  */

 

+#include <algorithm>

+

 #include "xfa/src/fxbarcode/barcode.h"

 #include "xfa/src/fxbarcode/BC_ResultPoint.h"

 #include "xfa/src/fxbarcode/common/BC_WhiteRectangleDetector.h"

@@ -166,7 +168,7 @@
                    correctedTopRight.get(), dimensionTop, dimensionRight, e));

     BC_EXCEPTION_CHECK_ReturnValue(e, NULL);

   } else {

-    int32_t dimension = FX_MIN(dimensionRight, dimensionTop);

+    int32_t dimension = std::min(dimensionRight, dimensionTop);

     correctedTopRight = CBC_AutoPtr<CBC_ResultPoint>(

         CorrectTopRight(bottomLeft, bottomRight, topLeft, topRight, dimension));

     if (correctedTopRight.get() == NULL) {

@@ -176,12 +178,12 @@
       topRight = NULL;

     }

     int32_t dimensionCorrected =

-        FX_MAX(CBC_AutoPtr<CBC_ResultPointsAndTransitions>(

-                   TransitionsBetween(topLeft, correctedTopRight.get()))

-                   ->GetTransitions(),

-               CBC_AutoPtr<CBC_ResultPointsAndTransitions>(

-                   TransitionsBetween(bottomRight, correctedTopRight.get()))

-                   ->GetTransitions());

+        std::max(CBC_AutoPtr<CBC_ResultPointsAndTransitions>(

+                     TransitionsBetween(topLeft, correctedTopRight.get()))

+                     ->GetTransitions(),

+                 CBC_AutoPtr<CBC_ResultPointsAndTransitions>(

+                     TransitionsBetween(bottomRight, correctedTopRight.get()))

+                     ->GetTransitions());

     dimensionCorrected++;

     if ((dimensionCorrected & 0x01) == 1) {

       dimensionCorrected++;

diff --git a/xfa/src/fxbarcode/oned/BC_OneDReader.cpp b/xfa/src/fxbarcode/oned/BC_OneDReader.cpp
index 61448d2..b89f764 100644
--- a/xfa/src/fxbarcode/oned/BC_OneDReader.cpp
+++ b/xfa/src/fxbarcode/oned/BC_OneDReader.cpp
@@ -20,6 +20,8 @@
  * limitations under the License.

  */

 

+#include <algorithm>

+

 #include "xfa/src/fxbarcode/barcode.h"

 #include "xfa/src/fxbarcode/BC_Reader.h"

 #include "xfa/src/fxbarcode/BC_BinaryBitmap.h"

@@ -48,7 +50,7 @@
   CBC_CommonBitArray* row = NULL;

   int32_t middle = height >> 1;

   FX_BOOL tryHarder = FALSE;

-  int32_t rowStep = FX_MAX(1, height >> (tryHarder ? 8 : 5));

+  int32_t rowStep = std::max(1, height >> (tryHarder ? 8 : 5));

   int32_t maxLines;

   if (tryHarder) {

     maxLines = height;

diff --git a/xfa/src/fxbarcode/oned/BC_OneDimWriter.cpp b/xfa/src/fxbarcode/oned/BC_OneDimWriter.cpp
index 8f4b226..159f27f 100644
--- a/xfa/src/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/xfa/src/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -22,6 +22,7 @@
 

 #include "BC_OneDimWriter.h"

 

+#include <algorithm>

 #include <memory>

 

 #include "xfa/src/fxbarcode/BC_Writer.h"

@@ -391,7 +392,8 @@
     m_outputHScale = (FX_FLOAT)m_Width / (FX_FLOAT)codeLength;

   }

   if (!isDevice) {

-    m_outputHScale = FX_MAX(m_outputHScale, m_ModuleWidth);

+    m_outputHScale =

+        std::max(m_outputHScale, static_cast<FX_FLOAT>(m_ModuleWidth));

   }

   FX_FLOAT dataLengthScale = 1.0;

   if (m_iDataLenth > 0 && contents.GetLength() != 0) {

@@ -407,7 +409,7 @@
   int32_t outputHeight = 1;

   if (!isDevice) {

     if (m_Height == 0) {

-      outputHeight = FX_MAX(20, m_ModuleHeight);

+      outputHeight = std::max(20, m_ModuleHeight);

     } else {

       outputHeight = m_Height;

     }

diff --git a/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp b/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp
index a2177fd..c75ddd4 100644
--- a/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp
+++ b/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp
@@ -20,6 +20,8 @@
  * limitations under the License.

  */

 

+#include <algorithm>

+

 #include "xfa/src/fxbarcode/barcode.h"

 #include "xfa/src/fxbarcode/BC_Reader.h"

 #include "xfa/src/fxbarcode/common/BC_CommonBitArray.h"

@@ -140,7 +142,7 @@
       if (counterPosition == patternLength - 1) {

         if (ArrayContains(STARTEND_ENCODING, ToNarrowWidePattern(&counters))) {

           FX_BOOL btemp3 =

-              row->IsRange(FX_MAX(0, patternStart - (i - patternStart) / 2),

+              row->IsRange(std::max(0, patternStart - (i - patternStart) / 2),

                            patternStart, FALSE, e);

           BC_EXCEPTION_CHECK_ReturnValue(e, NULL);

           if (btemp3) {

diff --git a/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp b/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp
index 601baa2..cbc7a5a 100644
--- a/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp
+++ b/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp
@@ -20,6 +20,8 @@
  * limitations under the License.

  */

 

+#include <algorithm>

+

 #include "xfa/src/fxbarcode/barcode.h"

 #include "xfa/src/fxbarcode/BC_Reader.h"

 #include "xfa/src/fxbarcode/common/BC_CommonBitArray.h"

@@ -115,7 +117,7 @@
         }

         if (bestMatch >= 0) {

           FX_BOOL btemp2 =

-              row->IsRange(FX_MAX(0, patternStart - (i - patternStart) / 2),

+              row->IsRange(std::max(0, patternStart - (i - patternStart) / 2),

                            patternStart, FALSE, e);

           BC_EXCEPTION_CHECK_ReturnValue(e, NULL);

           if (btemp2) {

@@ -338,8 +340,8 @@
     nextStart++;

   }

   FX_BOOL boolT1 = row->IsRange(

-      nextStart, FX_MIN(width, nextStart + (nextStart - lastStart) / 2), FALSE,

-      e);

+      nextStart, std::min(width, nextStart + (nextStart - lastStart) / 2),

+      FALSE, e);

   BC_EXCEPTION_CHECK_ReturnValue(e, "");

   if (!boolT1) {

     e = BCExceptionNotFound;

diff --git a/xfa/src/fxbarcode/oned/BC_OnedCode39Reader.cpp b/xfa/src/fxbarcode/oned/BC_OnedCode39Reader.cpp
index a5b77ed..18d1e96 100644
--- a/xfa/src/fxbarcode/oned/BC_OnedCode39Reader.cpp
+++ b/xfa/src/fxbarcode/oned/BC_OnedCode39Reader.cpp
@@ -20,6 +20,8 @@
  * limitations under the License.

  */

 

+#include <algorithm>

+

 #include "xfa/src/fxbarcode/barcode.h"

 #include "xfa/src/fxbarcode/BC_Reader.h"

 #include "xfa/src/fxbarcode/common/BC_CommonBitArray.h"

@@ -144,7 +146,7 @@
       if (counterPosition == patternLength - 1) {

         if (ToNarrowWidePattern(&counters) == ASTERISK_ENCODING) {

           FX_BOOL bT1 =

-              row->IsRange(FX_MAX(0, patternStart - (i - patternStart) / 2),

+              row->IsRange(std::max(0, patternStart - (i - patternStart) / 2),

                            patternStart, FALSE, e);

           BC_EXCEPTION_CHECK_ReturnValue(e, NULL);

           if (bT1) {

diff --git a/xfa/src/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/xfa/src/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
index 2610db9..2e16c03 100644
--- a/xfa/src/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
+++ b/xfa/src/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
@@ -20,6 +20,8 @@
  * limitations under the License.

  */

 

+#include <algorithm>

+

 #include "xfa/src/fxbarcode/barcode.h"

 #include "xfa/src/fxbarcode/BC_UtilCodingConvert.h"

 #include "xfa/src/fxbarcode/common/BC_CommonByteArray.h"

@@ -876,8 +878,8 @@
         GenerateECBytes(dataBytes, numEcBytesInBlosk, e);

     BC_EXCEPTION_CHECK_ReturnVoid(e);

     blocks.Add(new CBC_QRCoderBlockPair(dataBytes, ecBytes));

-    maxNumDataBytes = FX_MAX(maxNumDataBytes, dataBytes->Size());

-    maxNumEcBytes = FX_MAX(maxNumEcBytes, ecBytes->Size());

+    maxNumDataBytes = std::max(maxNumDataBytes, dataBytes->Size());

+    maxNumEcBytes = std::max(maxNumEcBytes, ecBytes->Size());

     dataBytesOffset += numDataBytesInBlock;

   }

   if (numDataBytes != dataBytesOffset) {

diff --git a/xfa/src/fxbarcode/qrcode/BC_QRDetector.cpp b/xfa/src/fxbarcode/qrcode/BC_QRDetector.cpp
index 1b79911..2280e9a 100644
--- a/xfa/src/fxbarcode/qrcode/BC_QRDetector.cpp
+++ b/xfa/src/fxbarcode/qrcode/BC_QRDetector.cpp
@@ -20,6 +20,8 @@
  * limitations under the License.

  */

 

+#include <algorithm>

+

 #include "xfa/src/fxbarcode/barcode.h"

 #include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h"

 #include "xfa/src/fxbarcode/BC_ResultPoint.h"

@@ -255,16 +257,16 @@
     FX_FLOAT allowanceFactor,

     int32_t& e) {

   int32_t allowance = (int32_t)(allowanceFactor * overallEstModuleSize);

-  int32_t alignmentAreaLeftX = FX_MAX(0, estAlignmentX - allowance);

+  int32_t alignmentAreaLeftX = std::max(0, estAlignmentX - allowance);

   int32_t alignmentAreaRightX =

-      FX_MIN(m_image->GetWidth() - 1, estAlignmentX + allowance);

+      std::min(m_image->GetWidth() - 1, estAlignmentX + allowance);

   if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3) {

     e = BCExceptionRead;

     BC_EXCEPTION_CHECK_ReturnValue(e, NULL);

   }

-  int32_t alignmentAreaTopY = FX_MAX(0, estAlignmentY - allowance);

+  int32_t alignmentAreaTopY = std::max(0, estAlignmentY - allowance);

   int32_t alignmentAreaBottomY =

-      FX_MIN(m_image->GetHeight() - 1, estAlignmentY + allowance);

+      std::min(m_image->GetHeight() - 1, estAlignmentY + allowance);

   CBC_QRAlignmentPatternFinder alignmentFinder(

       m_image, alignmentAreaLeftX, alignmentAreaTopY,

       alignmentAreaRightX - alignmentAreaLeftX,

diff --git a/xfa/src/fxfa/src/app/xfa_ffapp.cpp b/xfa/src/fxfa/src/app/xfa_ffapp.cpp
index 0ce79e0..fb37fb7 100644
--- a/xfa/src/fxfa/src/app/xfa_ffapp.cpp
+++ b/xfa/src/fxfa/src/app/xfa_ffapp.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "xfa/src/fxfa/src/common/xfa_common.h"

 #include "xfa_ffdochandler.h"

@@ -47,7 +49,7 @@
   while (index < iCount) {

     CPDF_StreamAcc& acc = m_Data[index];

     FX_DWORD dwSize = acc.GetSize();

-    FX_DWORD dwRead = FX_MIN(size, dwSize - offset);

+    size_t dwRead = std::min(size, static_cast<size_t>(dwSize - offset));

     FXSYS_memcpy(buffer, acc.GetData() + offset, dwRead);

     size -= dwRead;

     if (size == 0) {

diff --git a/xfa/src/fxfa/src/app/xfa_ffwidget.cpp b/xfa/src/fxfa/src/app/xfa_ffwidget.cpp
index 5804730..08194ba 100644
--- a/xfa/src/fxfa/src/app/xfa_ffwidget.cpp
+++ b/xfa/src/fxfa/src/app/xfa_ffwidget.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "xfa/src/fxfa/src/common/xfa_common.h"

 #include "xfa_ffapp.h"

@@ -776,7 +778,7 @@
     case XFA_ATTRIBUTEENUM_Fit: {

       FX_FLOAT f1 = rtImage.height / rtFit.height;

       FX_FLOAT f2 = rtImage.width / rtFit.width;

-      f1 = FX_MIN(f1, f2);

+      f1 = std::min(f1, f2);

       rtFit.height = rtFit.height * f1;

       rtFit.width = rtFit.width * f1;

     } break;

@@ -1116,7 +1118,7 @@
   a = rtDraw.width / 2.0f;

   b = rtDraw.height / 2.0f;

   if (box.IsCircular() || (dwFlags & XFA_DRAWBOX_ForceRound) != 0) {

-    a = b = FX_MIN(a, b);

+    a = b = std::min(a, b);

   }

   CFX_PointF center = rtDraw.Center();

   rtDraw.left = center.x - a;

@@ -1655,7 +1657,7 @@
   a = rtWidget.width / 2.0f;

   b = rtWidget.height / 2.0f;

   if (dwFlags & XFA_DRAWBOX_ForceRound) {

-    a = b = FX_MIN(a, b);

+    a = b = std::min(a, b);

   }

   CFX_PointF center = rtWidget.Center();

   rtWidget.left = center.x - a;

diff --git a/xfa/src/fxfa/src/app/xfa_ffwidgetacc.cpp b/xfa/src/fxfa/src/app/xfa_ffwidgetacc.cpp
index 92b6fe9..717408d 100644
--- a/xfa/src/fxfa/src/app/xfa_ffwidgetacc.cpp
+++ b/xfa/src/fxfa/src/app/xfa_ffwidgetacc.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "xfa/src/fxfa/src/common/xfa_common.h"

 #include "xfa_ffwidget.h"

@@ -825,12 +827,12 @@
       case XFA_ATTRIBUTEENUM_Right:

       case XFA_ATTRIBUTEENUM_Inline: {

         size.x += szCap.x;

-        size.y = FX_MAX(size.y, szCap.y);

+        size.y = std::max(size.y, szCap.y);

       } break;

       case XFA_ATTRIBUTEENUM_Top:

       case XFA_ATTRIBUTEENUM_Bottom: {

         size.y += szCap.y;

-        size.x = FX_MAX(size.x, szCap.x);

+        size.x = std::max(size.x, szCap.x);

       }

       default:

         break;

@@ -859,10 +861,10 @@
     size.x = fVal;

   } else {

     if (this->GetMinWidth(fMin)) {

-      size.x = FX_MAX(size.x, fMin);

+      size.x = std::max(size.x, fMin);

     }

     if (this->GetMaxWidth(fMax) && fMax > 0) {

-      size.x = FX_MIN(size.x, fMax);

+      size.x = std::min(size.x, fMax);

     }

   }

   fVal = 0, fMin = 0, fMax = 0;

@@ -870,10 +872,10 @@
     size.y = fVal;

   } else {

     if (this->GetMinHeight(fMin)) {

-      size.y = FX_MAX(size.y, fMin);

+      size.y = std::max(size.y, fMin);

     }

     if (this->GetMaxHeight(fMax) && fMax > 0) {

-      size.y = FX_MIN(size.y, fMax);

+      size.y = std::min(size.y, fMax);

     }

   }

   return TRUE;

@@ -944,7 +946,7 @@
         case XFA_ATTRIBUTEENUM_Left:

         case XFA_ATTRIBUTEENUM_Right:

         case XFA_ATTRIBUTEENUM_Inline: {

-          size.y = FX_MAX(size.y, szCap.y);

+          size.y = std::max(size.y, szCap.y);

         } break;

         case XFA_ATTRIBUTEENUM_Top:

         case XFA_ATTRIBUTEENUM_Bottom: {

@@ -1071,10 +1073,10 @@
   }

   FX_FLOAT fMin = 0, fMax = 0;

   if (this->GetMinWidth(fMin)) {

-    fWidthCalc = FX_MAX(fWidthCalc, fMin);

+    fWidthCalc = std::max(fWidthCalc, fMin);

   }

   if (this->GetMaxWidth(fMax) && fMax > 0) {

-    fWidthCalc = FX_MIN(fWidthCalc, fMax);

+    fWidthCalc = std::min(fWidthCalc, fMax);

   }

   return fWidthCalc;

 }

@@ -1098,10 +1100,10 @@
   }

   FX_FLOAT fMin = 0, fMax = 0;

   if (this->GetMinHeight(fMin)) {

-    fHeightCalc = FX_MAX(fHeightCalc, fMin);

+    fHeightCalc = std::max(fHeightCalc, fMin);

   }

   if (this->GetMaxHeight(fMax) && fMax > 0) {

-    fHeightCalc = FX_MIN(fHeightCalc, fMax);

+    fHeightCalc = std::min(fHeightCalc, fMax);

   }

   return fHeightCalc;

 }

diff --git a/xfa/src/fxfa/src/app/xfa_fontmgr.cpp b/xfa/src/fxfa/src/app/xfa_fontmgr.cpp
index 5be4c8b..ad5120e 100644
--- a/xfa/src/fxfa/src/app/xfa_fontmgr.cpp
+++ b/xfa/src/fxfa/src/app/xfa_fontmgr.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "xfa/src/fxfa/src/common/xfa_common.h"

 #include "xfa_fontmgr.h"

@@ -1983,7 +1985,7 @@
     }

     if (bBoldFont) {

       iDifferLength =

-          FX_MIN(iDifferLength - 4, bsDRName.GetLength() - iBoldIndex - 4);

+          std::min(iDifferLength - 4, bsDRName.GetLength() - iBoldIndex - 4);

     }

     FX_BOOL bItalicFont = TRUE;

     if (bsDRName.Find("Italic") > 0) {

diff --git a/xfa/src/fxfa/src/app/xfa_textlayout.cpp b/xfa/src/fxfa/src/app/xfa_textlayout.cpp
index 45eac17..83fd9dd 100644
--- a/xfa/src/fxfa/src/app/xfa_textlayout.cpp
+++ b/xfa/src/fxfa/src/app/xfa_textlayout.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "xfa/src/fxfa/src/common/xfa_common.h"

 #include "xfa_textlayout.h"

@@ -511,7 +513,7 @@
     if (fLineHeight < 0.1f) {

       fLineHeight = fFontSize;

     } else {

-      fLineHeight = FX_MIN(fLineHeight, fFontSize);

+      fLineHeight = std::min(fLineHeight, fFontSize);

     }

   } else if (fLineHeight < 0.1f) {

     fLineHeight = GetFontSize(pTextProvider, pStyle) * 1.2f;

@@ -1704,7 +1706,7 @@
         }

       }

       m_pTabstopContext->m_fLeft =

-          FX_MIN(fLeft, m_pTabstopContext->m_fTabWidth);

+          std::min(fLeft, m_pTabstopContext->m_fTabWidth);

       m_pTabstopContext->m_bTabstops = FALSE;

       m_pTabstopContext->m_fTabWidth = 0;

     }

@@ -1772,7 +1774,7 @@
       } else if (fBaseLine < -fBaseLineTemp) {

         fBaseLine = -fBaseLineTemp;

       }

-      fLineStep = FX_MAX(fLineStep, fLineHeight);

+      fLineStep = std::max(fLineStep, fLineHeight);

       if (pUserData != NULL && pUserData->m_pLinkData != NULL) {

         pUserData->m_pLinkData->AddRef();

         pTP->pLinkData = pUserData->m_pLinkData;

@@ -1786,7 +1788,7 @@
       FX_FLOAT& fTop = pTP->rtPiece.top;

       FX_FLOAT fBaseLineTemp = fTop;

       fTop = fLinePos + fLineStep - pTP->rtPiece.height - fBaseLineTemp;

-      fTop = FX_MAX(0, fTop);

+      fTop = std::max(0.0f, fTop);

     }

     fLinePos += fLineStep + fBaseLine;

   } else {

@@ -1809,11 +1811,11 @@
           fLineHeight = fLineHeightTmp;

         }

       }

-      fLineStep = FX_MAX(fLineStep, fLineHeight);

+      fLineStep = std::max(fLineStep, fLineHeight);

       fLineWidth += pPiece->m_iWidth / 20000.0f;

     }

     fLinePos += fLineStep;

-    m_fMaxWidth = FX_MAX(m_fMaxWidth, fLineWidth);

+    m_fMaxWidth = std::max(m_fMaxWidth, fLineWidth);

     if (m_pLoader && m_pLoader->m_bSaveLineHeight) {

       FX_FLOAT fHeight = fLinePos - m_pLoader->m_fLastPos;

       m_pLoader->m_fLastPos = fLinePos;

diff --git a/xfa/src/fxfa/src/parser/xfa_layout_itemlayout.cpp b/xfa/src/fxfa/src/parser/xfa_layout_itemlayout.cpp
index 7d12a28..3b99106 100644
--- a/xfa/src/fxfa/src/parser/xfa_layout_itemlayout.cpp
+++ b/xfa/src/fxfa/src/parser/xfa_layout_itemlayout.cpp
@@ -4,6 +4,8 @@
 

 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

 

+#include <algorithm>

+

 #include "xfa/src/foxitlib.h"

 #include "xfa/src/fxfa/src/common/xfa_utils.h"

 #include "xfa/src/fxfa/src/common/xfa_object.h"

@@ -1277,8 +1279,8 @@
       fColSpanWidth += rgSpecifiedColumnWidths[nCurrentColIdx + i];

     }

     if (nColSpan != nOriginalColSpan) {

-      fColSpanWidth =

-          bMetWholeRowCell ? 0 : FX_MAX(fColSpanWidth, pLayoutChild->m_sSize.y);

+      fColSpanWidth = bMetWholeRowCell ? 0 : std::max(fColSpanWidth,

+                                                      pLayoutChild->m_sSize.y);

     }

     if (nOriginalColSpan == -1) {

       bMetWholeRowCell = TRUE;